#! /bin/csh -f

# Determine if this is a leap year or not.
# Also, determine if last year was a leap year or not.
#
@ yr = 1979
while ($yr <= 1980)
rm -rf list_??? grmean.out namlpre.data

setenv S /Net/elninost4/amishra/RSM/libs/etc
setenv O /Net/water/amishra/RSM_ROMS/FL-DWN/HIS/O/$yr/Daily
setenv D /Net/water/amishra/RSM_ROMS/FL-DWN/HIS/O/$yr
ncra ${D}/ocean_avg.ft14.nc ${D}/ocean_avg.ft17.nc ${D}/ocean_avg.ft20.nc ${D}/ocean_avg.ft23.nc ${O}/ocean_avg.$yr'0101'.nc

### FOR Non-LEAP YEAR
##set dayend = 8759
### FOR LEAP YEAR
##set dayend = 8783
echo `date `>> ${yr}.log




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 = 8783
      echo 'yes, '$yr' is a leap year'
else if ($leaptrue != 0) then
     set dayend = 8759
endif
## Jan 3-743, Feb 744-1415, Mar 1416-2159, Apr 2160-2879, May 2880-3623, Jun 3624-4343
## Jul 4344-5087, Aug 5088-5831, Sep 5832-6551, Oct 6552-7295, Nov 7296-8015, Dec 8016-8759
##@ loop = 2160
##while ($loop <= 8759)
@ loop = 26
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 ntim=`echo $FHD | awk '{print substr($0,1,8)}'`
echo 'Making daily mean file for the day ' $ntim' using fcst hours ' $lp1 'to ' $lp8 >> synopsis_$yr
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
@ yr = $yr + 1
end
exit

