#! /bin/csh

set D = /Net/elninoshare/abhardwaj/PR/CCSM4/RSM
set O = /Net/elninoshare/abhardwaj/PR/CCSM4/RSM/netcdf

set yr = 2051

set cnt = 1
while ($cnt <= 1)

if (! -d $O/$yr[$cnt])then
mkdir $O/$yr[$cnt]
else
echo $yr[$cnt] exists
endif

cd $D/$yr[$cnt]
set y1 = `cat $O/list6h`
set n1 = `cat $O/list6h |wc -l`
set nn = `cat $O/list6h | cut -c9-12`

set cnt2 = 1
while ($cnt2 <= $n1)
if(-e $O/$yr[$cnt]/r_pgb$nn[$cnt2].nc) then
echo $O/$yr[$cnt]/r_pgb$nn[$cnt2].nc exists
else
echo $n1 $nn[$cnt2]
rm -f $O/$yr[$cnt]/r_pgb$nn[$cnt2].grb
rm -f $O/$yr[$cnt]/r_pgb$nn[$cnt2].nc
cp  $D/$yr[$cnt]/$y1[$cnt2] $O/$yr[$cnt]/r_pgb$nn[$cnt2].grb

cd $O/$yr[$cnt]
#ncl_convert2nc -u $O/$yr[$cnt]/r_pgb$nn[$cnt2].grb

ncl_convert2nc $O/$yr[$cnt]/r_pgb$nn[$cnt2].grb
endif
rm -f $O/$yr[$cnt]/r_pgb$nn[$cnt2].grb

@ cnt2 = $cnt2 + 1 
end
@ cnt = $cnt + 1
end

