#! /bin/csh -f

cat $0 >! $0.log$1
uname -a >> $0.log$1
date >> $0.log$1

# set nfiles as number of inputs up to 45 files,
# number the files F01, F02, etc.
# setenv F01 ... etc

#source /usr/local/Modules/Modules/init/csh

set epi = 2016ff_cb6camx_16j
set epi2 = monthlysum.LST.Y_24
set GRID = 12US2
set dir = /work/ROMO/2016platform/CAMx_v6.50/$epi/$GRID/POST/monthlysum
set dir2 = /work/ROMO/2016platform/CAMx_v6.50/$epi/$GRID/POST

if (! -e $dir2/yearly)   mkdir -v $dir2/yearly

set nfiles = 12

setenv F01 $dir/$epi2.$epi.$GRID.01.ncf
setenv F02 $dir/$epi2.$epi.$GRID.02.ncf
setenv F03 $dir/$epi2.$epi.$GRID.03.ncf
setenv F04 $dir/$epi2.$epi.$GRID.04.ncf
setenv F05 $dir/$epi2.$epi.$GRID.05.ncf
setenv F06 $dir/$epi2.$epi.$GRID.06.ncf
setenv F07 $dir/$epi2.$epi.$GRID.07.ncf
setenv F08 $dir/$epi2.$epi.$GRID.08.ncf
setenv F09 $dir/$epi2.$epi.$GRID.09.ncf
setenv F10 $dir/$epi2.$epi.$GRID.10.ncf
setenv F11 $dir/$epi2.$epi.$GRID.11.ncf
setenv F12 $dir/$epi2.$epi.$GRID.12.ncf
 
setenv SCENFILE1 /work/ROMO/2016platform/CAMx_v6.50/$epi/$GRID/post-job/new/sum_ext.scr

setenv OUTFILE $dir2/yearly/$epi.$GRID.yearlysum.LST.depn.ncf

if (-e $OUTFILE) then
   rm $OUTFILE
   endif


echo " outfile "                            >! $SCENFILE1
echo " $OUTFILE "                           >> $SCENFILE1
echo " is the sum of infiles "              >> $SCENFILE1
echo " $F01 to $F12 "                       >> $SCENFILE1

setenv EXECUTION_ID "$0.log$1 `date`"

/home/bkx/cmaq/misc/sum_ext.exe.atm >>& $0.log$1 << eof
$nfiles

eof

exit
