#! /bin/csh -f
#
# Determine if this is a leap year or not.
# Also, determine if last year was a leap year or not.
#
@ yr = 1986
rm -rf list_??? grmean.out namlpre.data
setenv S /Net/elninost4/amishra/RSM/libs/etc
setenv O /Net/water/amishra/RSM_ROMS/MONSOON10km/RCM-CLD2/STAMPEDE/O/$yr/temp
setenv D /Net/water/amishra/RSM_ROMS/MONSOON10km/RCM-CLD2/STAMPEDE/O/$yr

set dayend = 8760
echo `date `>> ${yr}.log
while ($yr <= 1986)

echo "$yr / 4" >> tmp
echo "quit" >> tmp
set leap = `bc -l < tmp`
rm -f tmp
set leaptrue = `echo $leap | cut -c5`
if ($leaptrue == 0) then
   set dayend = 8784
   echo 'yes, '$yr' is a leap year'
endif

@ loop = 1416
while ($loop <= 2160)
##while ($loop <= $dayend)
@ lp1 = $loop
@ lp2 = $lp1 + 3
@ lp3 = $lp2 + 3
@ lp4 = $lp3 + 3
@ lp5 = $lp4 + 3
@ lp6 = $lp5 + 3
@ lp7 = $lp6 + 3
@ lp8 = $lp7 + 3


set FHD=`${S}/incdte  $yr 01 01 00  $lp1 | sed 's/ *//g'`
##set FHD=`${S}/incdte  $yr 01 01 00  $lp1 | sed 's/.*\(6:2\)//g'`
##echo ${#FHD}
set ntim=`echo $FHD | awk '{print substr($0,1,8)}'`
echo $ntim
ncra ${D}/ocean_avg.ft$lp1.nc ${D}/ocean_avg.ft$lp2.nc ${D}/ocean_avg.ft$lp3.nc ${D}/ocean_avg.ft$lp4.nc ${D}/ocean_avg.ft$lp5.nc ${D}/ocean_avg.ft$lp6.nc ${D}/ocean_avg.ft$lp7.nc ${D}/ocean_avg.ft$lp8.nc ${O}/ocean_avg.$ntim.nc


   @ loop = $loop + 24
end
exit
