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