#! /bin/csh 

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

#> Simple Linux Utility for Resource Management System 
#> (SLURM) - The following specifications are recommended 
#> for executing the runscript on the cluster at the 
#> National Computing Center used primarily by EPA.
#SBATCH -t 10:00:00
#SBATCH -n 1
#SBATCH -c 1
#SBATCH -J hr2day
#SBATCH -p oar
#SBATCH --gid=romo
##SBATCH --account=romo
#SBATCH -o /work/ROMO/2016platform/CAMx_v6.40/2016fc_cb6camx_16j/36US3/post-job/new/hr2day_2016.Y.O3.txt

#> The following commands output information from the SLURM
#> scheduler to the log files for traceability.
   if ( $?SLURM_JOB_ID ) then
      echo Job ID is $SLURM_JOB_ID
      echo Host is $SLURM_SUBMIT_HOST
      #> Switch to the working directory. By default,
      #>   SLURM launches processes from your home directory.
      echo Working directory is $SLURM_SUBMIT_DIR
      cd $SLURM_SUBMIT_DIR
   endif
   echo '>>>>>> start model run at ' `date`

#> Configure the system environment and set up the module 
#> capability
   limit stacksize unlimited
#

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

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

 source /work/ROMO/users/hnf/cmaq_project/config_cmaq.csh

#> Set the model version
 set VRSN = v52
 setenv GRID 36US3
 setenv VERSION v6.40
 setenv PDIR 2016platform
 setenv SCEN 2016fc_cb6camx_16j
 setenv OUTDIR    /work/ROMO/$PDIR/CAMx_${VERSION}/$SCEN/$GRID/POST

 if (! -e $OUTDIR/O3)   mkdir -v $OUTDIR/O3

#foreach month ( 01 )
foreach month ( 01 02 03 04 05 06 07 08 09 10 11 12 )
#> Set the build directory if this was not set above 
#> (this is where the executable is located by default).
 if ( ! $?BINDIR ) then
  setenv BINDIR /work/ROMO/users/hnf/cmaq_project/POST/hr2day/scripts/BLD_hr2day_${VRSN}_${compilerString}
 endif

#> 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.  The v5.2 repo also contains a sample input file.
# setenv REPO_HOME ${CMAQ_REPO}


# =====================================================================
#> BLDOVERLAY Configuration Options
# =====================================================================

#> Projection sphere type used by I/OAPI (use type #20 to match WRF/CMAQ)
 setenv IOAPI_ISPH 20

#> set to use local time (default is GMT)
# setenv USELOCAL N       ###( default N  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 OLAYTYPE HOURLY since hourly observations need to be shifted
#> from local time to GMT)
 setenv TZFILE /work/ROMO/users/hnf/cmaq_project/POST/bldoverlay/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}
 #> define species (format: "Name, units, From_species, Operation")
#>  operations : {SUM, AVG, MIN, MAX, @MAXT, MAXDIF, 8HRMAX, SUM06}
 setenv OZONE "O3" #variable from which the @8HRMAXO3 bases the 8hr max
 setenv SPECIES_1 "O3_8HRMAX,ppbV,O3,8HRMAX"
 setenv SPECIES_2 "O3_AVG,ppbV,O3,AVG"
 setenv SPECIES_3 "O3_SUM,ppbV,O3,SUM"
 setenv SPECIES_4 "O3_MAX,ppbV,O3,MAX"
 setenv SPECIES_5 "O3_MIN,ppbV,O3,MAX"

#> set input and output files
 setenv INFILE $OUTDIR/combine.aconc.2016fc_cb6camx_16j.2016$month.ncf
          #[Add location of input file, e.g. COMBINE_ACONC file.]
 setenv OUTFILE $OUTDIR/O3/O3.LST.Y_24.$SCEN.$month.ncf

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

 end   # loop over months

 exit()


