;********************************************************** ;Procedure finddays ;This subroutine calculate the day and month from ;the Julian Date. ;********************************************************** pro finddays, day, mnum, year ;********************************************************** ;Check if the year is a leap year ;********************************************************** leap_flag=0 ;not a leap year check4=(year) mod 4 ;years divisible by 4 are leap years, unless........... check100=(year) mod 100 ;years also divisible by 100 are not leap years, except....... check400=(year)mod 400 ;years divisible by 400 are leap years. if ( (check4 eq 0 and check100 ne 0) or (check400 eq 0) ) then leap_flag=1 ;leap year ;************************************************************ ;Increment the days ;************************************************************ day=day+1 if (day eq 30 and mnum eq 2 and leap_flag eq 1) then begin mnum=mnum+1 day=1 endif if (day eq 29 and mnum eq 2 and leap_flag eq 0) then begin mnum=mnum+1 day=1 endif if (day ge 31 ) then begin if (mnum eq 9 or mnum eq 4 or mnum eq 6 or mnum eq 11) then begin mnum=mnum+1 day=1 endif else begin if (day eq 32 ) then begin mnum=mnum+1 day=1 if (mnum eq 13 ) then begin mnum=1 year=year+1 endif endif endelse endif return end ;************************************************** ; This procedure takes the number of seconds ; since 1-1-1970 and converts it to the ; standard date and time ;************************************************** pro standard_date_time,sec_time,year,month,day,hour,minute,second ;************************************************** ; sec_time is the number of seconds since 1-1-1970 ;************************************************** ;***************************************************** ;Sum up the complete years in numsecs ;***************************************************** year=1969 enough=0 ;flag that tells the loop to stop numsecs=0 ;initialize numsecs to 0 while (numsecs le sec_time and enough eq 0) do begin ;sum through the years year=year+1 ;leap year rules check4=(year) mod 4 ;1. years divisible by 4 are leap years, unless..... check100=(year) mod 100 ;2. years also divisible by 100 are not leap years, except....... check400=(year) 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) if (numsecs gt sec_time) then begin ;we have gone over sec_time enough=1 ;time to stop the loop numsecs=long(numsecs)-long(31536000)-long(86400) ;subtract back off endif ;print,'found first leap year check ',year,enough endif else $ if (check400 eq 0 ) then begin numsecs=long(numsecs)+long(31536000)+long(86400) if (numsecs gt sec_time) then begin ;we have gone over sec_time enough=1 ;time to stop the loop numsecs=long(numsecs)-long(31536000)-long(86400) ;subtract back off endif ;print,'found second leap year check',year,enough endif else $ begin numsecs=long(numsecs)+long(31536000) if (numsecs gt sec_time) then begin ;we have gone over sec_time enough=1 ;time to stop the loop numsecs=long(numsecs)-long(31536000) ;subtract back off endif ;print,'no leap year',year,enough endelse endwhile ;print,'year ',year, 'numsecs',numsecs,'sec_time',sec_time ;********************************************************** ;Calculate the Julian Date, or fractional days since the first of the year ;********************************************************** jday=(double(sec_time)-double(numsecs))/double(86400) ;print,'Julian Date',double(jday) ;************************************************************** ;Use the Julian Day to calculate the month and day ;********************************************************** day=1 month=1 ;print,fix(jday) for j=1,fix(jday) do begin finddays, day, month, year endfor ;print,'year ',year,'month ',month,'day ',day ;*********************************************************** ;Use the Julian Day to calculate the hour, minute, and second ;************************************************************ real_hour=(jday-fix(jday)) * 24. ;print,real_hour,'hour' real_minute=(real_hour-fix(real_hour)) *60. ;print,real_minute,'min' real_second=(real_minute-fix(real_minute)) * 60. ;print,real_second,'second' hour=fix(real_hour) ;print,hour,'fixed hour' minute=fix(real_minute) ;print,minute,'fixed minute' second=round(real_second) if second eq 60 then begin minute=minute+1 second=0 if minute eq 60 then begin hour=hour+1 minute=0 endif endif ;print,second,'fixed second' ;print,year,month,day,hour,minute,second end