#!/bin/csh -f
#
limit stacksize  unlimited
# Version @(#)$Id$
# Path    $Source$
# Date    $Date$
#
# This script sets up needed environment variables for processing point source
# emissions in SMOKE and calls the scripts that run the SMOKE programs. 
#
# Script created by : M. Houyoux, CEP Environmental Modeling Center 
#
#*********************************************************************

## Set optional customized SMKMERGE output file names
## setenv SMKMERGE_CUSTOM_OUTPUT  N  # Y define your own output file names from SMKMERGE

## Set Assigns file name
setenv ASSIGNS_FILE $SMKROOT/assigns/ASSIGNS.nctox.cmaq.cb05_soa.us12-nc

## Set source category
setenv SMK_SOURCE    P          # source category to process
setenv MRG_SOURCE    P          # source category to merge

## Set programs to run...

## Time-independent programs
setenv RUN_SMKINVEN  Y          # run inventory import program
setenv RUN_SPCMAT    Y          # run speciation matrix program
setenv RUN_GRDMAT    Y          # run gridding matrix program

## Time-dependent programs
setenv RUN_TEMPORAL  Y          # run temporal allocation program
setenv RUN_ELEVPOINT N          # run elevated/PinG sources selection program
setenv RUN_LAYPOINT  N          # run layer fractions program
setenv RUN_SMKMERGE  Y          # run merge program

## Quality assurance
setenv RUN_SMKREPORT Y          # run emissions reporting program

# Parameters for all sectors
setenv FILL_ANNUAL "N"
setenv FULLSCC_ONLY "Y"
setenv INLINE_MODE "only"
setenv IOAPI_ISPH "20"
#setenv L_TYPE "mwdss"
#setenv M_TYPE "mwdss"
setenv MRG_MARKETPEN_YN "N"
setenv MRG_REPCNY_YN "Y"
setenv MRG_REPSTA_YN "N"
setenv MTMP_OUTPUT_YN "N"
setenv NO_SPC_ZERO_EMIS "Y"
#setenv OUTPUT_FORMAT "$EMF_AQM"
setenv OUTZONE "0"
#setenv PLATFORM "v8"
setenv POLLUTANT_CONVERSION "Y"
setenv RAW_DUP_CHECK "N"
#setenv RENORM_TPROF "Y"
setenv REPORT_DEFAULTS "Y"
setenv RUN_HOLIDAYS "Y"
setenv RUN_PYTHON_ANNUAL "Y"
setenv SMKINVEN_FORMULA "PMC=PM10-PM2_5"
setenv SMKMERGE_CUSTOM_OUTPUT "Y"
setenv SMK_AVEDAY_YN "N"
setenv SMK_DEFAULT_SRGID "100"
setenv SMK_MAXERROR "10000"
setenv SMK_MAXWARNING "10"
setenv SMK_PING_METHOD "0"
setenv SMK_SPECELEV_YN "Y"
#setenv SPC "$EMF_SPC"
setenv SPINUP_MONTH_END "Y"
setenv WEST_HSPHERE "Y"

# Sector-specific parameters
setenv ELEVPOINT_DAILY "Y"
setenv SMK_PROCESS_HAPS "Partial"
setenv NONHAP_TYPE "VOC"
setenv ZIPOUT "Y"
setenv HOURLY_FIRE_YN "Y"
setenv FIRE_PLUME_YN "Y"
setenv CHECK_STACKS_YN "N"
setenv DAY_SPECIFIC_YN "Y"
setenv M_TYPE "all"
setenv L_TYPE "all"
setenv WRITE_ANN_ZERO "Y"
setenv RENORM_TPROF "N"
## For Smkmerge
setenv MRG_SPCMAT_YN        Y   # Y produces speciated output 
setenv MRG_TEMPORAL_YN      Y   # Y produces temporally allocated output
setenv MRG_GRDOUT_YN        Y   # Y produces a gridded output file
setenv MRG_GRDOUT_UNIT      g/hr   # units for the gridded output file
setenv MRG_TOTOUT_UNIT      g/hr # units for the state and county reports
setenv SMK_REPORT_TIME      230000    # hour for reporting daily emissions
## Script settings
setenv SRCABBR           ptfire  # abbreviation for naming log files
setenv QA_TYPE             all  # type of QA to perform [none, all, part1, part2, or custom]
setenv PROMPTFLAG           N   # Y prompts for user input
setenv AUTO_DELETE          Y   # Y automatically deletes I/O API NetCDF output files
setenv AUTO_DELETE_LOG      Y   # Y automatically deletes log files
setenv DEBUGMODE            N   # Y runs program in debugger
setenv DEBUG_EXE            pgdbg # debugger to use when DEBUGMODE = Y

## Assigns file override settings
# setenv SPC_OVERRIDE  cmaq.cb4p25  # chemical mechanism override
# setenv YEAR_OVERRIDE              # base year override
# setenv INVTABLE_OVERRIDE          # inventory table override

##############################################################################

## Run Smkinven, Spcmat, and Grdmat
#
setenv RUN_PART1 Y
source $ASSIGNS_FILE   # Invoke Assigns file

# Reset NHAPEXCLUDE file to exclude all sources
# This is needed for now because the stationary area criteria and non-point 
#    toxics inventories are not consistent and should not be integrated.
setenv NHAPEXCLUDE $GE_DAT/nhapexclude_2017_ptfire_17apr2020_v0.txt

source smk_run.csh     # Run programs
source qa_run.csh      # Run QA for part 1
setenv RUN_PART1 N

## Loop through days to run Temporal
#
setenv RUN_PART2 Y
set cnt = 0
set g_stdate_sav = $G_STDATE
while ( $cnt < $EPI_NDAY )

   @ cnt = $cnt + $NDAYS
   source $ASSIGNS_FILE   # Invoke Assigns file to set new dates
   source smk_run.csh     # Run programs
   source qa_run.csh      # Run QA for part 2
   setenv G_STDATE_ADVANCE $cnt

end
setenv RUN_PART2 N
unsetenv G_STDATE_ADVANCE

## Run Elevpoint
#
setenv RUN_PART3 Y
setenv G_STDATE  $g_stdate_sav
setenv ESDATE `$IOAPIDIR/datshift $G_STDATE 0`
source $ASSIGNS_FILE   # Invoke Assigns file to set new dates
source smk_run.csh     # Run programs
source qa_run.csh      # Run QA for part 3
setenv RUN_PART3 N

## Loop through dats to run Laypoint and Smkmerge
setenv RUN_PART4 Y
set cnt = 0
while ( $cnt < $EPI_NDAY )

   @ cnt = $cnt + $NDAYS
   source $ASSIGNS_FILE   # Invoke Assigns file to set new dates
   source smk_run.csh     # Run programs
   source qa_run.csh      # Run QA for part 4

   setenv G_STDATE_ADVANCE $cnt

end
setenv RUN_PART4 N
unsetenv G_STDATE_ADVANCE

#
## Ending of script
#
exit( 0 )

