;+ ; ; @file_comments ; gives Julian day equivalent of a date given in yyyymmdd format ; This is the inverse of the function jul2date. ; ; @categories ; Calendar ; ; @param date {in}{required} {type=long or double, scalar or array} ; longword integer with yyyymmdd format or double-precision ; floating-point with yyyymmdd.xx where xx is the fraction of the day ; (xx=0 at 0am and 5 at 12am) ; ; @keyword GRADS ; if 1 <= year <= 49 --> year = 2000 + year ; if 50 <= year <= 99 --> year = 1900 + year ; ; @keyword MONTH ; Set this keyword equal to a named variable that will receive a ; longword integer or longword integer array representing the number of ; the desired month (1 = January, ..., 12 = December). ; ; @keyword DAY ; Set this keyword equal to a named variable that will receive a ; longword integer or longword integer array representing the number of ; the day of the month (1-31). ; ; @keyword YEAR ; Set this keyword equal to a named variable that will receive a ; longword integer or longword integer array representing the number of ; the desired year (e.g., 1994). ; ; @keyword HOUR ; Set this keyword equal to a named variable that will receive a ; longword integer or longword integer array representing the number of ; the hour of the day (0-23). ; ; @keyword MINUTE ; Set this keyword equal to a named variable that will receive a ; longword integer or longword integer array representing the number of ; the minute of the hour (0-59). ; ; @keyword SECOND ; Set this keyword equal to a named variable that will receive a ; double-precision floating-point value or a double-precision ; floating-point array representing the number of the second of the ; minute (0-59). ; ; @returns ; Julian day with the same format (long or double) as the input parameter ; ; @restrictions ; Input param must be longword integer or double-precision floating-point ; ; @examples ; ; IDL> jday = juldate(19930124) ; IDL> print, date2jul(19931205) EQ julday(12,5,1993) ; 1 ; IDL> print, date2jul(931205,/grads) EQ julday(12,5,1993) ; 1 ; IDL> print, date2jul(19931205.5d) EQ julday(12,5,1993,12,0,0) ; 1 ; IDL> print, date2jul(19931205.0d) EQ julday(12,5,1993,0,0,0) ; 1 ; ; @history ; Sebastien Masson (smasson\@lodyc.jussieu.fr) June 2005 ; ; @version ; $Id$ ; ;- FUNCTION date2jul, date, GRADS=grads, MONTH=month, DAY=day, YEAR=year $ , HOUR=hour, MINUTE=minute, SECOND=second ; compile_opt idl2, strictarrsubs ; ; check parameters if (N_PARAMS() EQ 0) then return, report(['ERROR, No input parameter', 'Usage : ' $ , 'res = date2jul( date[, GRADS = grads][, MONTH = month][, DAY = day]' $ + '[, YEAR = year][, HOUR = hour][, MINUTE = minute][, SECOND = second] )']) ; sztype = size(date, /type) IF sztype NE 3 AND sztype NE 5 AND sztype LT 13 THEN BEGIN dummy = report('Beware of input type, date must be long or double') stop ENDIF ; year = long(date) / 10000 month = long(abs(date)/100) MOD 100 day = long(abs(date)) MOD 100 ;------------------------------------------------------------ if keyword_set(grads) then $ year = year + 1900L * (year GE 50 AND year LE 99) $ + 2000L * (year GE 1 AND year LE 49) ;------------------------------------------------------------ IF sztype NE 5 THEN return, julday(month, day, year) fraction = date - long(date) hour = floor(fraction * 24d) fraction = temporary(fraction) - hour/24d minute = floor(fraction*1440d) second = (temporary(fraction) - minute/1440d) * 86400d return, julday(month, day, year, hour, minute, second) end