function ymd, longdate ; Given scalar longdate argument, returns array of length 3 ; holding the corresponding year, month, and day. ; B. G. Knapp, 86/09/17 ; 96.01.31, fix bug: array month_days should hold the ; first day of each month, not the last of the ; previous month! if n_elements(longdate) eq 0 then begin print," " print," YMD translates a longdate argument of the form yyyyddd " print," into a floating-point vector of length three giving the " print," corresponding year, month, and day, respectively. The " print," correct calling sequence is illustrated below. " print," " print," y_m_d = YMD(YYYYDDD) " return," " endif month_days = [ [ 0, 31, 59, 90,120,151,181,212,243,273,304,334 ], $ [ 0, 31, 60, 91,121,152,182,213,244,274,305,335 ] ] day = longdate MOD 1000 y = long(longdate/1000) leap = ((y mod 4 eq 0) and (y mod 100 ne 0)) or (y mod 400 eq 0) p = where(month_days(*,leap)+1 le day) m = max(p)+1 d = day-month_days(m-1,leap) return,[y,m,d] ; end FUNCTION date2,date1,days ; Returns the date equivalent to date1 + days, where date is ; a date of the form yyyyddd and days is a positive or negative ; number of days. ; B. G. Knapp, 87/02/06 siz = SIZE(date1) IF siz(1) EQ 0 THEN BEGIN PRINT," " PRINT," DATE2 returns a double precision date of the form " PRINT," YYYYDDD.DD resulting from adding the number of days " PRINT," given by its second argument, to the date (also in the " PRINT," form YYYYDDD.DD) given by its first argument. The " PRINT," calling sequence is illustrated below. " PRINT," " PRINT," newdate = date2(olddate,ndays) " RETURN," " ENDIF y = LONG(date1/1000)+9999L d = LONG(y*365.25D0)+y/400-y/100+ABS(date1) MOD 1000L+days c = LONG(d/36524.25D0) d = d+c-LONG(c/4.) y = LONG(d/365.250001D0) d = ABS(y-9999L)*1000+(d-LONG(y*365.25D0)) d_typ = SIZE(d) IF d_typ(0) EQ 0 THEN BEGIN IF y LT 9999 THEN d = -d ENDIF ELSE BEGIN pick = WHERE(y LT 9999) if pick(0) GE 0 then d(pick) = -d ENDELSE RETURN,d END function UDATE_TO_YMD,UARS_DAY ; ; Given UARS day number, returns array of length 3 holding ; year, month, and day in that order. ; ; B. Knapp, 92.12.29 ; return,long(YMD(DATE2(1991254L,long(UARS_DAY)))) end ;function udate_to_vms, uars_day function uday_to_date, uars_day ; ; Converts integer UARS day to vms time format: dd-mmm-yyyy hh:mm:ss ; UARS day 1 ==> 12-SEP-1991 00:00:00 ; ; Written by Y. R. Wang based on subroutines written by B. Knapp, 93/08/02 ; Subroutines called: ; udate_to_ymd, vms_to_udate ; ; ; Modified by R. Wang, 94/07/20. Use double precision to represent udate. ; ; Modified by M. Henneberry 95.07.18 ; Made into function using one loop and removed possibility of ; 60 seconds being returned form rounding. ; uday_len = n_elements( uars_day ) month_list = ['JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG', $ 'SEP','OCT','NOV','DEC'] vms = strarr( uday_len ) for i = 0l, uday_len - 1 do begin ; compute the exact time: fraction = ( uars_day(i) - fix( uars_day(i) ) ) * 86400.0 hour = fix( fraction / 3600.0 ) min = fix(( fraction - hour * 3600.0 ) /60.0) sec = round( fraction - hour*3600.0 - min*60.0 ) overflow = 0 if( sec eq 60 ) then begin sec = 0 min = min + 1 if( min eq 60 ) then begin min = 0 hour = hour + 1 if( hour eq 24 ) then begin hour = 0 overflow = 1 endif ; hour endif ; min endif ; sec y_m_d = udate_to_ymd( uars_day(i) + overflow ) ; pick up month name from the list: month = month_list(y_m_d(1) - 1) year = strtrim(string(y_m_d(0)),2) date = y_m_d(2) vms(i) = string(date, month, year, hour, min, sec , $ format='(I2.2,"-",A3,"-",I4.4," ",I2.2,":",I2.2,":",I2.2)' ) endfor ;is input a scalar or array? if (size(uars_day))(0) eq 0 then $ return, vms(0) $ else $ return, vms end function UDATE_TO_YMD,UARS_DAY ; ; Given UARS day number, returns array of length 3 holding ; year, month, and day in that order. ; ; B. Knapp, 92.12.29 ; return,long(YMD(DATE2(1991254L,long(UARS_DAY)))) end