[9] | 1 | ;+ |
---|
| 2 | ; |
---|
[238] | 3 | ; @file_comments |
---|
[318] | 4 | ; gives Julian day equivalent of a date given in yyyymmdd format |
---|
| 5 | ; This is the inverse of the function <pro>jul2date</pro>. |
---|
[9] | 6 | ; |
---|
[157] | 7 | ; @categories |
---|
| 8 | ; Calendar |
---|
[9] | 9 | ; |
---|
[318] | 10 | ; @param date {in}{required} {type=long or double, scalar or array} |
---|
[279] | 11 | ; longword integer with yyyymmdd format or double-precision |
---|
| 12 | ; floating-point with yyyymmdd.xx where xx is the fraction of the day |
---|
[495] | 13 | ; (xx=0 at 0am and 5 at 12am) |
---|
[9] | 14 | ; |
---|
[137] | 15 | ; @keyword GRADS |
---|
[126] | 16 | ; if 1 <= year <= 49 --> year = 2000 + year |
---|
| 17 | ; if 50 <= year <= 99 --> year = 1900 + year |
---|
[9] | 18 | ; |
---|
[279] | 19 | ; @keyword MONTH |
---|
| 20 | ; Set this keyword equal to a named variable that will receive a |
---|
| 21 | ; longword integer or longword integer array representing the number of |
---|
[495] | 22 | ; the desired month (1 = January, ..., 12 = December). |
---|
[279] | 23 | ; |
---|
| 24 | ; @keyword DAY |
---|
| 25 | ; Set this keyword equal to a named variable that will receive a |
---|
| 26 | ; longword integer or longword integer array representing the number of |
---|
[495] | 27 | ; the day of the month (1-31). |
---|
[279] | 28 | ; |
---|
| 29 | ; @keyword YEAR |
---|
| 30 | ; Set this keyword equal to a named variable that will receive a |
---|
| 31 | ; longword integer or longword integer array representing the number of |
---|
[495] | 32 | ; the desired year (e.g., 1994). |
---|
[279] | 33 | ; |
---|
| 34 | ; @keyword HOUR |
---|
| 35 | ; Set this keyword equal to a named variable that will receive a |
---|
| 36 | ; longword integer or longword integer array representing the number of |
---|
[495] | 37 | ; the hour of the day (0-23). |
---|
| 38 | ; |
---|
[279] | 39 | ; @keyword MINUTE |
---|
| 40 | ; Set this keyword equal to a named variable that will receive a |
---|
| 41 | ; longword integer or longword integer array representing the number of |
---|
[495] | 42 | ; the minute of the hour (0-59). |
---|
| 43 | ; |
---|
[279] | 44 | ; @keyword SECOND |
---|
| 45 | ; Set this keyword equal to a named variable that will receive a |
---|
| 46 | ; double-precision floating-point value or a double-precision |
---|
| 47 | ; floating-point array representing the number of the second of the |
---|
| 48 | ; minute (0-59). |
---|
| 49 | ; |
---|
[238] | 50 | ; @returns |
---|
[279] | 51 | ; Julian day with the same format (long or double) as the input parameter |
---|
[9] | 52 | ; |
---|
[279] | 53 | ; @restrictions |
---|
| 54 | ; Input param must be longword integer or double-precision floating-point |
---|
[495] | 55 | ; |
---|
[126] | 56 | ; @examples |
---|
[9] | 57 | ; |
---|
[371] | 58 | ; IDL> jday = juldate(19930124) |
---|
| 59 | ; IDL> print, date2jul(19931205) EQ julday(12,5,1993) |
---|
[9] | 60 | ; 1 |
---|
[371] | 61 | ; IDL> print, date2jul(931205,/grads) EQ julday(12,5,1993) |
---|
[9] | 62 | ; 1 |
---|
[371] | 63 | ; IDL> print, date2jul(19931205.5d) EQ julday(12,5,1993,12,0,0) |
---|
[279] | 64 | ; 1 |
---|
[371] | 65 | ; IDL> print, date2jul(19931205.0d) EQ julday(12,5,1993,0,0,0) |
---|
[279] | 66 | ; 1 |
---|
[9] | 67 | ; |
---|
[238] | 68 | ; @history |
---|
[137] | 69 | ; Sebastien Masson (smasson\@lodyc.jussieu.fr) June 2005 |
---|
[118] | 70 | ; |
---|
[231] | 71 | ; @version |
---|
| 72 | ; $Id$ |
---|
[118] | 73 | ; |
---|
[9] | 74 | ;- |
---|
[327] | 75 | FUNCTION date2jul, date, GRADS=grads, MONTH=month, DAY=day, YEAR=year $ |
---|
| 76 | , HOUR=hour, MINUTE=minute, SECOND=second |
---|
[114] | 77 | ; |
---|
| 78 | compile_opt idl2, strictarrsubs |
---|
| 79 | ; |
---|
[325] | 80 | ; check parameters |
---|
[329] | 81 | if (N_PARAMS() EQ 0) then return, report(['ERROR, No input parameter', 'Usage : ' $ |
---|
| 82 | , 'res = date2jul( date[, GRADS = grads][, MONTH = month][, DAY = day]' $ |
---|
| 83 | + '[, YEAR = year][, HOUR = hour][, MINUTE = minute][, SECOND = second] )']) |
---|
[325] | 84 | ; |
---|
[279] | 85 | sztype = size(date, /type) |
---|
| 86 | IF sztype NE 3 AND sztype NE 5 AND sztype LT 13 THEN BEGIN |
---|
| 87 | dummy = report('Beware of input type, date must be long or double') |
---|
| 88 | stop |
---|
| 89 | ENDIF |
---|
| 90 | ; |
---|
| 91 | year = long(date) / 10000 |
---|
| 92 | month = long(abs(date)/100) MOD 100 |
---|
| 93 | day = long(abs(date)) MOD 100 |
---|
[9] | 94 | ;------------------------------------------------------------ |
---|
[279] | 95 | if keyword_set(grads) then $ |
---|
| 96 | year = year + 1900L * (year GE 50 AND year LE 99) $ |
---|
| 97 | + 2000L * (year GE 1 AND year LE 49) |
---|
[9] | 98 | ;------------------------------------------------------------ |
---|
[279] | 99 | IF sztype NE 5 THEN return, julday(month, day, year) |
---|
[238] | 100 | |
---|
[205] | 101 | fraction = date - long(date) |
---|
| 102 | hour = floor(fraction * 24d) |
---|
[279] | 103 | fraction = temporary(fraction) - hour/24d |
---|
[205] | 104 | minute = floor(fraction*1440d) |
---|
[279] | 105 | second = (temporary(fraction) - minute/1440d) * 86400d |
---|
[238] | 106 | |
---|
[205] | 107 | return, julday(month, day, year, hour, minute, second) |
---|
| 108 | |
---|
[9] | 109 | end |
---|