#!/bin/csh -f
#PBS -W group_list=romo
#PBS -A sectors 
#PBS -q romo
#PBS -l walltime=24:00:00
#PBS -l nodes=1:ppn=1


set GRID = 36US3 
set YEAR = 2023
set YY = `echo $YEAR | cut -c3-4`
set NZ = 35


foreach SCEN (   base2023_rxeqemis_isamtest  )

foreach mon (  11 12  )
#foreach mon ( 01 02 03 04 05 06 07 08 09 10 11 12 )

if ($mon == 01) then
set day = {$YEAR}001
set endday = {$YEAR}032
else if ($mon == 02) then
set day = {$YEAR}032
set endday = {$YEAR}060
else if ($mon == 03) then
set day = {$YEAR}060
set endday = {$YEAR}091
else if ($mon == 04) then
set day = {$YEAR}091
set endday = {$YEAR}121
else if ($mon == 05) then
set day = {$YEAR}121
set endday = {$YEAR}152
else if ($mon == 06) then
set day = {$YEAR}152
set endday = {$YEAR}182
else if ($mon == 07) then
set day = {$YEAR}182
set endday = {$YEAR}213
else if ($mon == 08) then
set day = {$YEAR}213
set endday = {$YEAR}244
else if ($mon == 09) then
set day = {$YEAR}244
set endday = {$YEAR}274
else if ($mon == 10) then
set day = {$YEAR}274
set endday = {$YEAR}305
else if ($mon == 11) then
set day = {$YEAR}305
set endday = {$YEAR}335
else if ($mon == 12) then
set day = {$YEAR}335
set endday = {$YEAR}365
else
exit
endif


set day = $day
set enddate = $endday


#Set Directories

set INDIR = /work/ROMO/lrt/cmaq/36US3/output/$SCEN
set POSTDIR = /work/ROMO/lrt/cmaq/36US3/postp/$SCEN
set THISDIR = /work/MOD3EVAL/kbaker/projects/wfsens/combine
mkdir -p $POSTDIR

rm -rf species.temp
touch species.temp
echo "##start   YYYYSTA  000000" >> species.temp
echo "##end     YYYYEND  000000" >> species.temp
echo "##layer         1" >> species.temp
echo "/new species    ,units     ,expression" >> species.temp
echo "O3,ppb,O3[1]*1000" >> species.temp
echo "PM_OCEC,ug/m3,APOCI[1]+APOCJ[1]+AECI[1]+AECJ[1]+APNCOMI[1]+APNCOMJ[1]" >> species.temp

echo "O3_ICBC,ppb,(O3_BCO[2]+O3_ICO[2]+O3_OTH[2])*1000" >> species.temp
echo "O3_ANTH,ppb,(O3_MOBILE[2]+O3_POINT[2])*1000" >> species.temp
echo "O3_NAT,ppb,(O3_BIO[2])*1000" >> species.temp
echo "O3_NONUS,ppb,(O3_NONUS[2])*1000" >> species.temp
echo "O3_WF,ppb,(O3_WF[2])*1000" >> species.temp
echo "O3_RX,ppb,(O3_RX[2])*1000" >> species.temp
echo "O3_AG,ppb,(O3_AG[2])*1000" >> species.temp
echo "O3_OB,ppb,(O3_OB[2])*1000" >> species.temp

echo "PM_ICBC,ppb,(APOCI_BCO[2]+APOCI_ICO[2]+APOCI_OTH[2]+APOCJ_BCO[2]+APOCJ_ICO[2]+APOCJ_OTH[2]+AECI_BCO[2]+AECI_ICO[2]+AECI_OTH[2]+AECJ_BCO[2]+AECJ_ICO[2]+AECJ_OTH[2])" >> species.temp
echo "PM_ANTH,ppb,(APOCI_MOBILE[2]+APOCJ_MOBILE[2]+APOCI_POINT[2]+APOCJ_POINT[2]+AECI_MOBILE[2]+AECJ_MOBILE[2]+AECI_POINT[2]+AECJ_POINT[2])" >> species.temp
echo "PM_NAT,ppb,(APOCI_BIO[2]+APOCJ_BIO[2]+AECI_BIO[2]+AECJ_BIO[2])" >> species.temp
echo "PM_NONUS,ppb,(APOCI_NONUS[2]+APOCJ_NONUS[2]+AECI_NONUS[2]+AECJ_NONUS[2])" >> species.temp
echo "PM_WF,ppb,(APOCI_WF[2]+APOCJ_WF[2]+AECI_WF[2]+AECJ_WF[2])" >> species.temp
echo "PM_RX,ppb,(APOCI_RX[2]+APOCJ_RX[2]+AECI_RX[2]+AECJ_RX[2])" >> species.temp
echo "PM_AG,ppb,(APOCI_AG[2]+APOCJ_AG[2]+AECI_AG[2]+AECJ_AG[2] )" >> species.temp
echo "PM_OB,ppb,(APOCI_OB[2]+APOCJ_OB[2]+AECI_OB[2]+AECJ_OB[2] )" >> species.temp




setenv SPECIES_DEF species.temp
setenv OUTFILE $POSTDIR/combine.$YEAR$mon.$GRID.$SCEN.ncf
rm -f $OUTFILE

while ($day <= $enddate)

set GDAY = (`/home/kbaker/camx/dateconv/j2g $day`)

set YYYY = `echo $GDAY | cut -c1-4`
set YY = `echo $GDAY | cut -c3-4`
set MM = `echo $GDAY | cut -c5-6`
set DD = `echo $GDAY | cut -c7-8`

set G_DAY = $YYYY$MM$DD
set GS_DAY = $YY$MM$DD


setenv INFILE1 $INDIR/CMAQv55_cb6r5_ae7_aq.$GRID.35.${SCEN}.ACONC.${day}
setenv INFILE2 $INDIR/CMAQv55_cb6r5_ae7_aq.$GRID.35.${SCEN}.SA_ACONC.${day}

/work/MOD3EVAL/kbaker/projects/cmaq/v5.5public/POST/combine/scripts/BLD_combine_v55_intel21.4_50000/combine_v55.exe

@ day = $day + 1

end #loop over days
end #loop over scen
end #loop over months

exit

