;************************************************************** ; routine to calculate the initial fractional hour and initial ; fractional julian day from the number of seconds since 1970 ;************************************************************** pro ijday_ihrfrac_fm_numsec, num_sec, time_offset, real_hh, jday, yy, mm, dd, hh, mi, ss ;num_sec = basetime ;time_offset = seconds since basetime num_sec=long(num_sec)+long(time_offset[0]) time_offset=time_offset-time_offset[0] yy=1969 sec_count=0D while (sec_count le num_sec) do begin sec_count=double(sec_count)+double(31536000) ;add seconds in a year yy=yy+1 ;check to see if it is a leap year, and if so, add extra day check4=(yy) mod 4 check100=(yy) mod 100 check400=(yy)mod 400 if ( (check4 eq 0 and check100 ne 0) or (check400 eq 0) ) then begin ;leap years sec_count=double(sec_count)+double(86400) ;add extra day ;print,'found leap year check',yy endif endwhile sec_count=double(sec_count)-double(31536000) ;substract off, went over ;check to see if it is a leap year, and if so, subtract extra day check4=(yy) mod 4 check100=(yy) mod 100 check400=(yy)mod 400 if ( (check4 eq 0 and check100 ne 0) or (check400 eq 0) ) then begin ;leap years sec_count=double(sec_count)-double(86400) ;print,'subtracted extra day',yy endif ;************************************************************** ;claculate Julian Date from the remainder of the seconds ;Julian Date is the number of fractional days since Jan 1. ;************************************************************** jday=((double(num_sec-sec_count))+time_offset)/86400. ; ; Find the month, day and year for each ; ddd=make_array(n_elements(jday),/float,value=-9999) mmm=make_array(n_elements(jday),/float,value=-9999) yyy=make_array(n_elements(jday),/float,value=-9999) ; ; Assign values for the first jday value ; dd=1 mm=1 for j=1,fix(jday[0]) do begin dtgincre_day, dd, mm, yy, 1 endfor result=where(jday ge fix(jday[0]) and jday lt fix(jday[0]+1),count) if count ne 0 then begin ddd[result]=dd mmm[result]=mm yyy[result]=yy endif ; ; If the data crosses multiple days, assign value for the next jday ; numjulday=fix(jday[n_elements(jday)-1])-fix(jday[0]) ;number of julian days to loop through jday_1=fix(jday[0]+1) jday_2=fix(jday[0]+2) for k=1,numjulday+1 do begin result_days=where(jday ge jday_1 and jday lt jday_2,count) if count ne 0 then begin dd=1 mm=1 for j=1,jday_1 do begin dtgincre_day, dd, mm, yy, 1 endfor if yy gt yyy[result_days[0]-1] then begin jday=jday-365.0 jday_1=fix(jday[result_days[0]]) jday_2=fix(jday_1+1.0) endif result=where(jday ge jday_1 and jday lt jday_2,count) if count ne 0 then begin ddd[result]=dd mmm[result]=mm yyy[result]=yy endif endif jday_1=jday_1+1.0 jday_2=jday_2+1.0 endfor ; ; Return negative jday values to positive ; result=where(jday lt 0,count) if count gt 0 then jday[result]=jday[result]+365.0 ; ; Rename the arrays ; yy=yyy mm=mmm dd=ddd ; ; Calculate hour min sec ; real_hh=((jday-(float(fix(jday))))*24.) real_mi=((real_hh-(float(fix(real_hh))))*60.) real_sc=((real_mi-(float(fix(real_mi))))*60.) hh=fix(real_hh) mi=fix(real_mi) ;ss=fix(real_sc) ss=round(real_sc) result=where(ss eq 60,count) if count gt 0 then begin mi[result]=mi[result]+1 ss[result]=0 endif result=where(mi eq 60,count) if count gt 0 then begin hh[result]=hh[result]+1 mi[result]=0 endif result=where(hh gt 24,count) if count gt 0 then begin print,'hours are wrong in ijday' stop endif end