#!/bin/csh -f

set regionNum = $1
set region = $2
set infile = $3
set wrkdir = $4
set outfile = $5
set type = $6
set year = $7
set yr = `printf "%04d" $year`

echo "infile: " $wrkdir/$infile
echo "outfile: " $outfile

if ($type == 'mean') then
  if ($region == 'Glo') then
    ncwa -m REGION_MASK -T gt -M $regionNum -w TAREA -a nlon,nlat \
         -v TEMP,SALT $wrkdir/$infile $outfile 
  else
    ncwa -m REGION_MASK -T eq -M $regionNum -w TAREA -a nlon,nlat \
       -v TEMP,SALT $wrkdir/$infile $outfile
  endif
else
  if ($region == 'Glo') then
    ncwa -m REGION_MASK -T gt -M $regionNum -w TAREA -a nlon,nlat \
         -y rms -v TEMP,SALT $wrkdir/$infile $outfile
  else
    ncwa -m REGION_MASK -T eq -M $regionNum -w TAREA -a nlon,nlat \
         -y rms -v TEMP,SALT $wrkdir/$infile $outfile
  endif
endif


#printf " This file was created as a placeholder" > $outfile

