#! /bin/csh

set ydir = `cat list-tmp`
set nydir = `cat list-tmp | wc -l`

set count = 1
#while ($count <= 1)
while ($count <= $nydir)

if ((($ydir[$count] % 4 == 0) && ($ydir[$count] % 100 != 0))||$ydir[$count] % 400 == 0) then
echo "Leap Year" $ydir[$count]
set tt = 1465
else
echo "Not a leap year" $ydir[$count]
set tt = 1461
endif

if ($ydir[$count] == 2005 ) then
set tt = 1464
endif
if ($ydir[$count] == 2060 ) then
set tt = 1457
endif
echo amit

cat > pmn$ydir[$count].gs << EOF
'reinit'
'open /Net/elninost4/abhardwaj/NHMRSM-POST/RSM/$ydir[$count].ctl'
'set gxout fwrite'
'set fwrite pmn$ydir[$count].grd'
'set undef -9999.0'
mons='JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC'
if ($tt>1464)
days='31 29 31 30 31 30 31 31 30 31 30 31'
else
days='31 28 31 30 31 30 31 31 30 31 30 31'
endif
year=$ydir[$count]

if(year=2060)
days='31 29 31 30 31 30 31 31 30 31 30 30'
endif

if(year=2005)
days='31 28 31 30 31 30 31 31 30 31 30 30'
endif

mon=1
while(mon<=12)
'set y 1 100'
'set x 1 201'
'pmon1=0'
'pmon1=ave(pratesfc,time=00:00Z01'subwrd(mons,mon)''year',time=18:00Z'subwrd(days,mon)''subwrd(mons,mon)''year')+pmon1'
'd pmon1*86400.0'
mon=mon+1
endwhile
'disable fwrite'
'quit'
EOF

/Net/elninost/abhardwaj/tar/grads-2.0.2.oga.2/Classic/bin/grads -blc "run pmn$ydir[$count].gs" >& pmn$ydir[$count].txt &
@ count = $count + 1
end
