#! /bin/csh

setenv O /Net/elninoshare/abhardwaj/PR/GFDL/RSM/script
setenv I /Net/elninoshare/abhardwaj/PR/GFDL/RSM

set yr = `cat list-20`
set n = `cat list-20 |wc -l`

set cnt = 1
#while ($cnt <= 1)
while ($cnt <= $n)
cd $I/$yr[$cnt]/GFDL_$yr[$cnt]/$yr[$cnt]
ls -v r_pgb.ft* > $O/list-$yr[$cnt]

set y1 = `cat $O/list-$yr[$cnt]`
set n1 = `cat $O/list-$yr[$cnt] |wc -l`
grib2ctl.pl -verf $I/$yr[$cnt]/GFDL_$yr[$cnt]/$yr[$cnt]/r_pgb.ft%f2 > $O/$yr[$cnt].ctl
pwd

sed  s:$I/$yr[$cnt]/GFDL_$yr[$cnt]/$yr[$cnt]/r_pgb.ft00.idx:./$yr[$cnt].idx:g $O/$yr[$cnt].ctl >$O/$yr[$cnt]
#if ( $cnt <= 2 ) then
#sed  -i -e s/'tdef 1000 linear '00Z01jan$yr[$cnt]' 1hr'/'tdef '$n1' linear '00Z01jan$yr[$cnt]' 1hr'/g $O/$yr[$cnt] 
#else
sed  -i -e s/'tdef 997 linear '00Z01jan$yr[$cnt]' 1hr'/'tdef '$n1' linear '00Z01jan$yr[$cnt]' 6hr'/g $O/$yr[$cnt] 
#endif

cd $O   
mv -f $yr[$cnt] $yr[$cnt].ctl
gribmap -i $yr[$cnt].ctl
pwd

@ cnt = $cnt + 1
end

