[9] | 1 | ;+ |
---|
| 2 | ; |
---|
[238] | 3 | ; @file_comments |
---|
[136] | 4 | ; gives Julian day equivalent of a date in yyyymmdd format |
---|
[9] | 5 | ; |
---|
[157] | 6 | ; @categories |
---|
| 7 | ; Calendar |
---|
[9] | 8 | ; |
---|
[231] | 9 | ; @param date {in}{required} {type=string} |
---|
[136] | 10 | ; date in yyyymmdd format |
---|
[9] | 11 | ; |
---|
[137] | 12 | ; @keyword GRADS |
---|
[126] | 13 | ; if 1 <= year <= 49 --> year = 2000 + year |
---|
| 14 | ; if 50 <= year <= 99 --> year = 1900 + year |
---|
[9] | 15 | ; |
---|
[238] | 16 | ; @returns |
---|
[136] | 17 | ; date in Julian day |
---|
[9] | 18 | ; |
---|
[126] | 19 | ; @examples |
---|
[9] | 20 | ; |
---|
[126] | 21 | ; IDL> jday = juldate(19930124) |
---|
| 22 | ; IDL> print, date2jul(19931205) EQ julday(12,5,1993) |
---|
[9] | 23 | ; 1 |
---|
[126] | 24 | ; IDL> print, date2jul(931205,/grads) EQ julday(12,5,1993) |
---|
[9] | 25 | ; 1 |
---|
| 26 | ; |
---|
[238] | 27 | ; @history |
---|
[137] | 28 | ; Sebastien Masson (smasson\@lodyc.jussieu.fr) June 2005 |
---|
[118] | 29 | ; |
---|
[231] | 30 | ; @version |
---|
| 31 | ; $Id$ |
---|
[118] | 32 | ; |
---|
[9] | 33 | ;- |
---|
[231] | 34 | ; |
---|
[9] | 35 | function date2jul, date, GRADS = grads |
---|
[114] | 36 | ; |
---|
| 37 | compile_opt idl2, strictarrsubs |
---|
| 38 | ; |
---|
[9] | 39 | year = long(date) / 10000 |
---|
[69] | 40 | month = long(abs(date)/100) MOD 100 |
---|
| 41 | day = long(abs(date)) MOD 100 |
---|
[9] | 42 | ;------------------------------------------------------------ |
---|
| 43 | if keyword_set(grads) then year = year $ |
---|
| 44 | + 1900 * (year GE 50 AND year LE 99) $ |
---|
| 45 | + 2000 * (year GE 1 AND year LE 49) |
---|
| 46 | ;------------------------------------------------------------ |
---|
[278] | 47 | IF size(date, /type) LE 3 THEN return, julday(month, day, year) |
---|
[238] | 48 | |
---|
[205] | 49 | fraction = date - long(date) |
---|
| 50 | hour = floor(fraction * 24d) |
---|
| 51 | fraction = TEMPORARY(fraction) - hour/24d |
---|
| 52 | minute = floor(fraction*1440d) |
---|
| 53 | second = (TEMPORARY(fraction) - minute/1440d) * 86400d |
---|
[238] | 54 | |
---|
[205] | 55 | return, julday(month, day, year, hour, minute, second) |
---|
| 56 | |
---|
[9] | 57 | end |
---|
| 58 | |
---|