#!/usr/bin/env python
# encoding: utf-8

#=============================================================================================

import os
import sys
from datetime import datetime, date, timedelta
import calendar
import gc

from lib_crw import *
from plot_product import plotProduct

#=============================================================================================

if __name__ == '__main__':

    #=========================================================================================
    #=========================================================================================
    # Uncomment a desired product (i.e., a desired three-line set) to plot, while comment out all other sets:

    #productname = 'baa5-max-single'
    #date_start = '20140601'
    #date_end = '20170531'

    #productname = 'baa5-max-single'
    #date_start = '20090601'
    #date_end = '20110531'

    #productname = 'baa5-max-single'
    #date_start = '19970601'
    #date_end = '19990531'

    #productname = 'baa5-max-single'
    #date_start = '20140601'
    #date_end = '20150531'

    #productname = 'baa5-max-single'
    #date_start = '20150601'
    #date_end = '20160531'

    #productname = 'baa5-max-single'
    #date_start = '20160601'
    #date_end = '20170531'

    #productname = 'dhw-max-single'
    #date_start = '20140601'
    #date_end = '20170531'

    #productname = 'dhw-max-single'
    #date_start = '20090601'
    #date_end = '20110531'

    productname = 'dhw-max-single'
    date_start = '19970601'
    date_end = '19990531'

    #-----------------------------------------------------------------------------------------
    # Choose this to mark reef locations:

    #opt_plot_markers=True
    opt_plot_markers=False

    #=========================================================================================
    #=========================================================================================

    # No need to change anyting below this line for plotting the above data files:

    #=========================================================================================
    overwrite = True
    #overwrite = False

    #=========================================================================================
    # Specify and setup the product suite that the specified product belongs to: 

    #-----------------------------------------------------------------------------------------
    consts = Info_constants_crw()

    #=========================================================================================
    date_processing_start = date(int(date_start[0:4]),int(date_start[4:6]),int(date_start[6:8]))
    date_processing_end   = date(int(date_end[0:4]),int(date_end[4:6]),int(date_end[6:8]))

    #-----------------------------------------------------------------------------------------
    daterange = Allpurpose_object()

    if productname.split("-")[2] == "annual":
        daterange.datebegin = date(date_to_be_processed.year,1,1)
        daterange.dateend   = date(date_to_be_processed.year,12,31)
        daterange.date      = daterange.dateend
    elif productname.split("-")[2] == "bleachingyear":
        daterange.datebegin = date(date_to_be_processed.year-1,consts.bleachingyear_start_month,consts.bleachingyear_start_day)
        daterange.dateend   = date(date_to_be_processed.year,consts.bleachingyear_end_month,consts.bleachingyear_end_day)
    elif productname.split("-")[2] == "single":
        daterange.datebegin = date_processing_start 
        daterange.dateend   = date_processing_end
    else:
        raise ValueError("***Error: This product is not set up: ", productname, ". Quit!")

    status = plotProduct(productname, daterange, overwrite, opt_plot_markers)

#=============================================================================================
# The end

