#!/bin/csh
#
#  script computes the number days from Jan. 1, 1969.
#  
#  Error report
#               status=1   ->  Input year less than 1969
#
# INPUTS
set year  = $1      # four digit year
set month = $2      # month number; if 1 and day > 31 then assume day = day of year
set day   = $3      # day number

set cday0 = (0 31 59 90 120 151 181 212 243 273 304 334 365)
set cday1 = (0 31 60 91 121 152 182 213 244 274 305 335 366)

if($year < 1969) exit 1

@ yeardif  = $year - 1969
@ totdays  = $yeardif * 365
@ leapdays = $yeardif / 4
@ totdays  = $totdays + $leapdays

if($month > 1) then
  if(($year % 4 == 0 && $year % 100 != 0) || $year % 400 == 0) then
    @ totdays = $totdays + $cday1[$month] + $day    # leap year
  else
    @ totdays = $totdays + $cday0[$month] + $day    # not leap year
  endif
else
   @ totdays = $totdays + $day
endif

echo $totdays



