#!/bin/csh -f
#SBATCH --time=24:00:00
#SBATCH --ntasks=1
#SBATCH --nodes=1
#SBATCH --nodelist=notch147
#SBATCH --cpus-per-task=1
#SBATCH -p daq-shared-np
#SBATCH -A daq-np
#SBATCH -o smk_nonroad_daily_np
#SBATCH --mail-type=END,FAIL
#SBATCH --mail-user=lexiewilson@utah.gov


limit stacksize unlimited

setenv SECTOR "nonroad_dailyctrl"
setenv SUBOUT01_NAME "nonroad_gas"
setenv SUBOUT02_NAME "nonroad_diesel"

if ($?SLURM_SUBMIT_DIR) then
  cd $SLURM_SUBMIT_DIR
endif

## Definitions for case name, directory structures, etc, that are used
#  by every sector in the case
#  Anything defined in directory_definitions can be overridden here 
#  if desired
source ../directory_definitions_WF13UDAQ_2023fy_17nc.csh
setenv lexscen "N"
echo "lexscen is ${lexscen}"

setenv SMK_SRCGROUP_OUTPUT_YN "N" # set to Y to create inline emissions files for source apportionment
setenv SOURCE_GROUPS "${GE_DAT}/sa/sa_nonroad_sourcegroups_v2_30may2022.csv"

if ($lexscen == "N") then
setenv RUN_MONTHS "7 8"
setenv SPINUP_DURATION "16" #
setenv SPINUP_MONTH_END "Y"
setenv BASE_YEAR "2017"
setenv EPI_STDATE_TIME "${BASE_YEAR}-07-01 00:00:00.0"
setenv EPI_ENDATE_TIME "${BASE_YEAR}-08-01 23:59:00.0"
else
setenv RUN_MONTHS "$repmonth"
setenv SPINUP_DURATION "0"
setenv SPINUP_MONTH_END "Y"
setenv BASE_YEAR "2017"
setenv EPI_STDATE_TIME "$repstdt"
setenv EPI_ENDATE_TIME "$repeddt"
endif


## Months for emissions processing, and spinup duration
#  In the EPA emissions modeling platforms, the only sectors that use
#    SPINUP_DURATION are biogenics and the final sector merge (Mrggrid).
#  Elsewhere, SPINUP_DURATION = 0, and when Mrggrid runs for spinup days,
#    base year emissions are used for the spinup year for all sectors except
#    biogenics.
#  Effective Jan 2019, SPINUP_DURATION now should work for all months.
#  SPINUP_MONTH_END (new for Jan 2019) specifies whether the last $SPINUP_DURATION 
#    days of quarter 2/3/4 should be run at the end of a quarter (Y), or at the start 
#    of the next quarter (N). For example, if runningwith SPINUP_DURATION = 10:
#    When N (old behavior), Q1 will include 10 day spinup and end on 3/21; Q2 will
#    cover 3/22 through 6/20. When Y, Q1 will include 10 day spinup and end on 3/31
#    (including all of March), remaining quarters will function as if spinup = 0.
## Inventory case name, if inventories are coming from a different case (they usually aren't)
#  CASEINPUTS is defined in directory_definitions and optionally overridden here
#setenv INVENTORY_CASE "2011ek_cb6v2_v6_11g"
#setenv CASEINPUTS "$INSTALL_DIR/$INVENTORY_CASE/inputs"

## Inputs for all sectors
setenv AGREF "${GE_DAT}/gridding/agref_us_2017platform_13may2021_nf_v10.txt"
setenv ARTOPNT "${GE_DAT}/artopnt_2002detroit_20aug2019_v2.txt"
setenv ATPRO_HOURLY "${GE_DAT}/temporal/amptpro_general_2011platform_tpro_hourly_6nov2014_06apr2021_nf_v9"
setenv ATPRO_HOURLY_NCF "${GE_DAT}/temporal/Gentpro_TPRO_HOUR_HOURLY_BASH_NH3.agNH3_bash_16j_12US1_smk37_newFIPS.ncf"
setenv ATPRO_MONTHLY "${GE_DAT}/temporal/amptpro_general_2011platform_tpro_monthly_6nov2014_30nov2018_nf_v9"
setenv ATPRO_WEEKLY "${GE_DAT}/temporal/amptpro_general_2011platform_tpro_weekly_6nov2014_09sep2016_v2"
#setenv ATREF "${GE_DAT}/temporal/amptref_general_2017platform_21apr2021_v4"
setenv COSTCY "${GE_DAT}/costcy_for_2017platform_20aug2020_v1.txt"
setenv EFTABLES "${CASEINPUTS}/onroad/eftables/rateperdistance_smoke_aq_cb6_saprc_20210217_2016-20210219_10003_1.csv"
setenv GRIDDESC "${GE_DAT}/gridding/GRIDDESC_udaq_v7.txt"
#setenv GSCNV "${GE_DAT}/speciation/spec_parts/gscnv_Create_CB6R3AE7_Spec_5_2_draft_full_17mar2021_nf_v1.txt"
#setenv GSPROTMP_A "${GE_DAT}/speciation/gspro_cmaq_cb6ae7_2016fj_16j_26may2021.txt"
#setenv GSREFTMP_A "${GE_DAT}/speciation/gsref_cmaq_cb6ae7_2016fj_16j_26may2021.txt"
setenv GSREFTMP_A "${GE_DAT}/speciation/gsref_cmaq_cb6ae7_2017gb_17j_nf_UDAQadd.txt" #LW update
setenv HOLIDAYS "${GE_DAT}/temporal/holidays_13feb2017_v1.txt"
#setenv INVTABLE "${GE_DAT}/invtable_2014platform_integrate_21dec2018_v3.txt"
setenv MGREF "${GE_DAT}/gridding/mgref_onroad_MOVES3_04mar2021_nf_v1.txt"
setenv MRGDATE_FILES "$INSTALL_DIR/smoke4.8.1/scripts/smk_dates/2017/smk_merge_dates_201701.txt"
setenv MTPRO_HOURLY "${GE_DAT}/temporal/mtpro_hourly_MOVES_2014v2_25feb2021_nf_v3"
setenv MTPRO_MONTHLY "${GE_DAT}/temporal/mtpro_monthly_MOVES_03aug2016_v1"
setenv MTPRO_WEEKLY "${GE_DAT}/temporal/mtpro_weekly_MOVES_2014v2_25feb2021_nf_v3"
setenv MTREF "${GE_DAT}/temporal/mtref_onroad_MOVES3_2017NEI_25feb2021_nf_v2"
setenv NAICSDESC "${GE_DAT}/smkreport/naicsdesc_02jan2008_v0.txt"
setenv ORISDESC "${GE_DAT}/smkreport/orisdesc_04dec2006_v0.txt"
setenv PELVCONFIG "${GE_DAT}/point/pelvconfig_elevate_everything_17apr2020_v0.txt"
setenv PSTK "${GE_DAT}/point/pstk_13nov2018_v1.txt"
setenv PTPRO_HOURLY "${GE_DAT}/temporal/amptpro_general_2011platform_tpro_hourly_6nov2014_06apr2021_nf_v9"
setenv PTPRO_MONTHLY "${GE_DAT}/temporal/amptpro_general_2011platform_tpro_monthly_6nov2014_30nov2018_nf_v9"
setenv PTPRO_WEEKLY "${GE_DAT}/temporal/amptpro_general_2011platform_tpro_weekly_6nov2014_09sep2016_v2"
setenv PTREF "${GE_DAT}/temporal/amptref_general_2017platform_24may2021_nf_v6"
#setenv REPCONFIG_GRID "${GE_DAT}/smkreport/repconfig_area_inv_grid_2016beta_07feb2019_v0.txt"
#setenv REPCONFIG_INV "${GE_DAT}/smkreport/repconfig_area_inv_2016beta_07feb2019_v0.txt"
setenv SCCDESC "${GE_DAT}/smkreport/sccdesc_2014platform_13dec2019_v3.txt"
setenv SECTORLIST "$CASESCRIPTS/sectorlist_2023fj_4UDAQ"
setenv SPC "$EMF_SPC"
#setenv SRGDESC "${GE_DAT}/gridding/srgdesc_CONUS12_2017NEI_17dec2019_13may2021_v3.txt"
#setenv SRGPRO "${GE_DAT}/gridding/surrogates/CONUS12_2017NEI_04mar2021/USA_100_NOFILL.txt"
setenv SRGDESC "${GE_DAT}/gridding/srgdesc_wf13udaq_edit.txt"
setenv SRGPRO "${GE_DAT}/WF133_surg/USA_100_NOFILL.txt" 

# Inputs specific to this sector
#setenv ATREF "${GE_DAT}/temporal/amptref_general_2017platform_24may2021_nf_v6_UDAQnonroad_update" #includes changes to assignments - see the SMOKE change log for differences
setenv ATREF "${GE_DAT}/temporal/amptref_general_2017platform_24may2021_nf_v6_UDAQnonroad_update_v2" #includes changes to assignments - see the SMOKE change log for differences; also includes flat monthly profile for Utah SCCs

setenv SUB_SEC_SOURCES "${GE_DAT}/sa/source_groups_nonroad_gas1_diesel2_18feb2021_v0"
setenv GSCNV "${GE_DAT}/speciation/gscnv_CB6R3_AE7_Spec_5_0_MOVES_integration_24mar2020_v0.txt"
setenv GSPROTMP_A "${GE_DAT}/speciation/gspro_nonroad_cmaq_cb6ae7_2016fj_16j_01may2019.txt"
setenv EMISDAY_A "${CASEINPUTS}/nonroad_dailyctrl/FINAL_2023_NWFUDAQ_JUN_NONROAD_CONTROL_LAWNGARDEN_DAILY_2022_Aug_16.csv"
setenv EMISDAY_B "${CASEINPUTS}/nonroad_dailyctrl/FINAL_JUL_2023_NWFUDAQ_NONROAD_CONTROL_LAWNGARDEN_DAILY_2022_Aug_09.csv"
setenv EMISDAY_C "${CASEINPUTS}/nonroad_dailyctrl/FINAL_2023_NWFUDAQ_AUG_NONROAD_CONTROL_LAWNGARDEN_DAILY_2022_Aug_16.csv"

setenv EMISINV_B "${CASEINPUTS}/nonroad_dailyctrl/FINAL_2023_NWFUDAQ_NONROAD_ALL_2022_Aug_24_nowatercraft.csv" #update 
setenv EMISINV_A "${CASEINPUTS}/nonroad_ctrl/2023fj_v2platform_nonroad_from_MOVES_aggSCC_11jun2021_nf_v1_filt.csv"
#setenv REPCONFIG_TEMP "${GE_DAT}/smkreport/repconfig_area_temporal_2016beta_07feb2019_v0.txt"
#setenv REPCONFIG_INV "${GE_DAT}/smkreport/repconfig_area_inv_2016beta_08feb2019_v1.txt"
setenv INVTABLE "${GE_DAT}/invtable_2014platform_MOVES_nonroad_19feb2020_v2.txt"
#setenv REPCONFIG_INV3 "/${GE_DAT}/smkreport/repconfig/repconfig_area_inv_vocprof_2016beta_07feb2019_v0_UDAQ.txt"
#setenv REPCONFIG_TEMP "${GE_DAT}/smkreport/repconfig/repconfig_area_temporal_2016beta_07feb2019_v0_UDAQ.txt"#UDAQrep
setenv GSPRO_COMBO "/${GE_DAT}/speciation/gspro_combo_2010cdc_2010ef_nonpt_20apr2020_nf_v1.txt" #LW added for VOC COMBO profiles
#setenv REPCONFIG_GRID "${GE_DAT}/smkreport/repconfig/repconfig_area_inv_grid_2016beta_07feb2019_v0_UDAQedit.txt"#UDAQrep


#updated smkreports
if ($lexscen == "N") then
setenv REPCONFIG_GRID "${GE_DAT}/smkreport/udaqrep/repconfig_area_inv_grid_udaq.txt"
setenv REPCONFIG_TEMP "${GE_DAT}/smkreport/udaqrep/repconfig_area_temporal_udaq.txt"
setenv REPCONFIG_INV "${GE_DAT}/smkreport/udaqrep/repconfig_area_inv_udaq.txt"
setenv REPCONFIG_INV2 "${GE_DAT}/smkreport/udaqrep/repconfig_area_inv_vocprof_udaq.txt"
else
setenv REPCONFIG_GRID "${GE_DAT}/smkreport/udaqrep/repconfig_area_inv_grid_udaq_scen.txt"
setenv REPCONFIG_TEMP "${GE_DAT}/smkreport/udaqrep/repconfig_area_temporal_udaq_scen.txt"
setenv REPCONFIG_INV "${GE_DAT}/smkreport/udaqrep/repconfig_area_inv_udaq_scen.txt"
setenv REPCONFIG_INV2 "${GE_DAT}/smkreport/udaqrep/repconfig_area_inv_vocprof_udaq_scen.txt"
endif


# 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 "v7.4"
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 SPINUP_MONTH_END "Y"
setenv WEST_HSPHERE "Y"

# Sector-specific parameters
setenv DAY_SPECIFIC_YN "Y" #arday
setenv FILL_ANNUAL "Y"
setenv SMKINVEN_FORMULA "PMC=PM10-PM25TOTAL"
setenv SMK_ARTOPNT_YN "Y"
setenv NONHAP_TYPE "VOC"
setenv SMK_PROCESS_HAPS ""
setenv SMK_SUB_SECTOR_OUTPUT_YN "N"  # "Y"
setenv L_TYPE "all"
setenv M_TYPE "all"

if ($lexscen == "N") then
$RUNSCRIPTS/emf/smk_ar_monthly_emf_ARDAY.csh $REGION_ABBREV $REGION_IOAPI_GRIDNAME -m "$RUN_MONTHS" $SPINUP_DURATION all #added DAY_SPECIFIC_YN block from smk_ar_annual_emf.csh
else
$RUNSCRIPTS/emf/smk_ar_monthly_emf_temporal.csh $REGION_ABBREV $REGION_IOAPI_GRIDNAME -m "$RUN_MONTHS" $SPINUP_DURATION all
endif


#$RUNSCRIPTS/emf/smk_ar_monthly_emf.csh $REGION_ABBREV $REGION_IOAPI_GRIDNAME -m "$RUN_MONTHS" $SPINUP_DURATION all
