;****************************************************************************** ; Function num_sec_ep is passed a date and time and then converts ; it to number of seconds since 1-1-1970. This becomes the value of ; the function ;****************************************************************************** function num_sec_ep, year, month, day, hour, minute, second ;print,'year',year,' month',month,' day',day,' hour',hour,' minute',minute,' second',second ;****************************************************************************** ;Add up all the seconds from 1-1-1970 to the last completed year (or year -1) ;****************************************************************************** numyears=year-1970 ;number of whole years to sum numsecs=0 ;initialize numsecs to 0 for i=1,numyears do begin ;loop throught the number of years ;leap year rules check4=(1969+i) mod 4 ;1.years divisible by 4 are leap years,unless... check100=(1969+i) mod 100 ;2.years also divisible by 100 are not leap ; years, except....... check400=(1969+i)mod 400 ;3.years divisible by 400 are leap years. if (check4 eq 0 and check100 ne 0 ) then begin numsecs=long(numsecs)+long(31536000)+long(86400) ;print,'found first leap year check ',1969+i endif else if (check400 eq 0 ) then begin numsecs=long(numsecs)+long(31536000)+long(86400) ;print,'found second leap year check',1969+i endif else begin numsecs=long(numsecs)+long(31536000) ;print,'no leap year',1969+i endelse endfor ;print,'sum sec years',numsecs ;****************************************************************************** ;sum up the number of days since the first of the year until month-1 ;****************************************************************************** days=fltarr(12) days=[31,28,31,30,31,30,31,31,30,31,30,31] if (month ge 2) then begin sum_day=total(days[0:month-2]) ;print,'sum_day',sum_day sum_day_sec=long(86400)*long(sum_day) ;print,'sum_day_sec',sum_day_sec numsecs=long(numsecs)+long(sum_day_sec) endif ;print,'numsecs',numsecs ;********************************************************** ;another leap year check to add another day if the current year is a leap year ;********************************************************** check4=(year) mod 4 check100=(year) mod 100 check400=(year)mod 400 if ( ( (check4 eq 0 and check100 ne 0) or $ (check400 eq 0)) and month gt 2 ) then begin numsecs=long(numsecs)+long(86400) ;print,'adding extra day for leap year',numsecs endif ;*********************************************************** ;add the day, hour, min, and sec ;*********************************************************** numsecs=long(numsecs)+long(86400)*long(day-1) ;print,'adding days',numsecs,long(day-1),long(86400)*long(day-1) numsecs=long(numsecs)+long(hour)*long(3600) ;print,'adding hour',numsecs,long(hour),long(hour)*long(3600) numsecs=long(numsecs)+long(minute)*long(60) ;print,'adding minu',numsecs,long(minute),long(minute)*long(60) numsecs=long(numsecs)+long(second) ;print,'adding seco',numsecs,long(second) ;print,'numsecs',numsecs return, numsecs end