#! /bin/csh -f

# ====================== HR2DAYv5.3 Run Script ======================
# Usage: run.hr2day.csh >&! hr2day_v53.log &
#
# To report problems or request help with this script/program:
#             http://www.epa.gov/cmaq    (EPA CMAQ Website)
#             http://www.cmascenter.org
# ===================================================================

# ==================================================================
#> Runtime Environment Options
# ==================================================================

#> Choose compiler and set up CMAQ environment with correct 
#> libraries using config.cmaq. Options: intel | gcc | pgi
# setenv compiler intel 

# cd ../../..
# source ./config_cmaq.csh

set cases = (runS20 runS20_2026 runS20_2026_OGNOxRed runS20_2026_0.9NOxred runS20_2026_0.9VOCred)
#foreach ii (1 2 3 )
foreach ii ( 4 5 )

set case = $cases[$ii]


#> Set General Parameters for Configuring the Simulation
 set VRSN      = v53               #> Code Version
 set compilerString = pgi
 setenv IOAPI_ISPH 20
                                                      
#> Define RUNID as any combination of parameters above or others. By default,
#> this information will be collected into this one string, $RUNID, for easy
#> referencing in output binaries and log files as well as in other scripts.
# setenv RUNID  ${VRSN}_${compilerString}_${APPL}
 
#> Set the build directory if this was not set above 
#> (this is where the executable is located by default).
  setenv CMAQ_HOME /models/CMAQ/src/CMAQv5.3
  setenv BINDIR ${CMAQ_HOME}/POST/hr2day/scripts/BLD_hr2day_${VRSN}_${compilerString}

#> Set the name of the executable.
 setenv EXEC hr2day_${VRSN}.exe

#> Set location of CMAQ repo.  This will be used to point to the time zone file
#> needed to run bldoverlay.  
 setenv REPO_HOME ${CMAQ_HOME}/POST/hr2day


# =====================================================================
#> HR2DAY Configuration Options
# =====================================================================

#> set to use local time (default is GMT)
 setenv USELOCAL Y

#> set to use daylight savings time (default is N)
 setenv USEDST N

#> location of time zone data file, tz.csv (this is a required input file
#> when using USELOCAL Y to shift from GMT to local time)
 setenv TZFILE ${REPO_HOME}/inputs/tz.csv

#> partial day calculation (computes value for last day)
 setenv PARTIAL_DAY Y

#> constant hour offset between desired time zone and GMT (default is 0)
 setenv HROFFSET 0

#> starting hour for daily metrics (default is 0)
 setenv START_HOUR 0

#> ending hour for daily metrics (default is 23)
 setenv END_HOUR 23

#> Number of 8hr values to use when computing daily maximum 8hr ozone.
#> Allowed values are 24 (use all 8-hr averages with starting hours 
#> from 0 - 23 hr local time) and 17 (use only the 17 8-hr averages
#> with starting hours from 7 - 23 hr local time)
# setenv HOURS_8HRMAX 24
 setenv HOURS_8HRMAX 17

#> define species (format: "Name, units, From_species, Operation")
#>  operations : {SUM, AVG, MIN, MAX, @MAXT, MAXDIF, 8HRMAX, SUM06}
 setenv SPECIES_1 "O3,ppbV,O3,8HRMAX"
 
#> Optional desired first and last processing date. The program will
#> adjust the requested dates if the desired range is not covered by
#> the input file(s). If these dates are not specified, the processing
#> will be performed for the longest possible time record that can be
#> derived from the model input file(s)
 setenv START_DATE 2016153
 setenv END_DATE 2016233 ## exclude the last day of the year to avoid format messed up due to time-zone shift on the old-new year transition day or set "setenv PARTIAL_DAY Y"

#> set input and output files

 set CASE = $case
 set INPUT_DIR = /disk40/Denver_O3_2023/camx/postproc/1.combine/outputs

#> Set output directory
 setenv POSTDIR   ./output    #> Location where hr2day file will be written
  if ( ! -e $POSTDIR ) then
          mkdir $POSTDIR
  endif

 setenv M3_FILE_1 $INPUT_DIR/camxv720_cb6r5.May-Aug.${CASE}.avrg.4km.O3_NOx.nc
 setenv OUTFILE ${POSTDIR}/Denver_O3.${CASE}.dailyavg.O3.4km.nc

#> Executable call:
 ${BINDIR}/${EXEC}


#CHANGE NAME OA to OC.
#ncrename -v OA,OC $OUTFILE
 end

exit()


