#!/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 = 2016
set YY = `echo $YEAR | cut -c3-4`
set NZ = 35


foreach SCEN (  baseline${YEAR} )

#foreach mon ( 01 02 03 04 05 06  )
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/MOD3EVAL/kbaker/data/cmaq/36US3/output/$SCEN
set POSTDIR = /work/MOD3EVAL/kbaker/data/cmaq/36US3/postp/$SCEN
set THISDIR = /work/MOD3EVAL/kbaker/projects/cfire/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 "PM25,ug/m3,PM25[2]" >> species.temp
echo "FORM,ppb,FORM[1]*1000" >> species.temp
echo "PAN,ppb,PAN[1]*1000" >> 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/CCTM_ACONC_v54_intel21.4_CMAQv54.$GRID.${SCEN}_${G_DAY}.nc
setenv INFILE2 $INDIR/CCTM_AELMO_v54_intel21.4_CMAQv54.$GRID.${SCEN}_${G_DAY}.nc

/home/kappel/showard/bin/combine.exe

@ day = $day + 1

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

exit

