1 | ;+ |
---|
2 | ; |
---|
3 | ; @file_comments |
---|
4 | ; gives Julian day equivalent of a date given in yyyymmdd format |
---|
5 | ; This is the inverse of the function <pro>jul2date</pro>. |
---|
6 | ; |
---|
7 | ; @categories |
---|
8 | ; Calendar |
---|
9 | ; |
---|
10 | ; @param date {in}{required} {type=long or double, scalar or array} |
---|
11 | ; longword integer with yyyymmdd format or double-precision |
---|
12 | ; floating-point with yyyymmdd.xx where xx is the fraction of the day |
---|
13 | ; (xx=0 at 0am and 5 at 12am) |
---|
14 | ; |
---|
15 | ; @keyword GRADS |
---|
16 | ; if 1 <= year <= 49 --> year = 2000 + year |
---|
17 | ; if 50 <= year <= 99 --> year = 1900 + year |
---|
18 | ; |
---|
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 |
---|
22 | ; the desired month (1 = January, ..., 12 = December). |
---|
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 |
---|
27 | ; the day of the month (1-31). |
---|
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 |
---|
32 | ; the desired year (e.g., 1994). |
---|
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 |
---|
37 | ; the hour of the day (0-23). |
---|
38 | ; |
---|
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 |
---|
42 | ; the minute of the hour (0-59). |
---|
43 | ; |
---|
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 | ; |
---|
50 | ; @returns |
---|
51 | ; Julian day with the same format (long or double) as the input parameter |
---|
52 | ; |
---|
53 | ; @restrictions |
---|
54 | ; Input param must be longword integer or double-precision floating-point |
---|
55 | ; |
---|
56 | ; @examples |
---|
57 | ; |
---|
58 | ; IDL> jday = juldate(19930124) |
---|
59 | ; IDL> print, date2jul(19931205) EQ julday(12,5,1993) |
---|
60 | ; 1 |
---|
61 | ; IDL> print, date2jul(931205,/grads) EQ julday(12,5,1993) |
---|
62 | ; 1 |
---|
63 | ; IDL> print, date2jul(19931205.5d) EQ julday(12,5,1993,12,0,0) |
---|
64 | ; 1 |
---|
65 | ; IDL> print, date2jul(19931205.0d) EQ julday(12,5,1993,0,0,0) |
---|
66 | ; 1 |
---|
67 | ; |
---|
68 | ; @history |
---|
69 | ; Sebastien Masson (smasson\@lodyc.jussieu.fr) June 2005 |
---|
70 | ; |
---|
71 | ; @version |
---|
72 | ; $Id$ |
---|
73 | ; |
---|
74 | ;- |
---|
75 | function date2jul, date, GRADS = grads, MONTH = month, DAY = day, YEAR = year $ |
---|
76 | , HOUR = hour, MINUTE = minute, SECOND = second |
---|
77 | ; |
---|
78 | compile_opt idl2, strictarrsubs |
---|
79 | ; |
---|
80 | usage="res=date2jul, date, GRADS = grads, MONTH = month, DAY = day, YEAR = year , HOUR = hour, MINUTE = minute, SECOND = second" |
---|
81 | ; |
---|
82 | ; check parameters |
---|
83 | check_param = N_PARAMS() |
---|
84 | if (check_param EQ 0) then begin |
---|
85 | dummy = report(['No input parameter', $ |
---|
86 | 'Usage : ' + usage]) |
---|
87 | stop |
---|
88 | endif |
---|
89 | ; |
---|
90 | ; check arguments |
---|
91 | ; ++ pas sur |
---|
92 | if arg_present(date) then begin |
---|
93 | dummy = report(['No input parameter date', $ |
---|
94 | 'Usage : ' + usage]) |
---|
95 | stop |
---|
96 | endif |
---|
97 | sztype = size(date, /type) |
---|
98 | IF sztype NE 3 AND sztype NE 5 AND sztype LT 13 THEN BEGIN |
---|
99 | dummy = report('Beware of input type, date must be long or double') |
---|
100 | stop |
---|
101 | ENDIF |
---|
102 | ; |
---|
103 | year = long(date) / 10000 |
---|
104 | month = long(abs(date)/100) MOD 100 |
---|
105 | day = long(abs(date)) MOD 100 |
---|
106 | ;------------------------------------------------------------ |
---|
107 | if keyword_set(grads) then $ |
---|
108 | year = year + 1900L * (year GE 50 AND year LE 99) $ |
---|
109 | + 2000L * (year GE 1 AND year LE 49) |
---|
110 | ;------------------------------------------------------------ |
---|
111 | IF sztype NE 5 THEN return, julday(month, day, year) |
---|
112 | |
---|
113 | fraction = date - long(date) |
---|
114 | hour = floor(fraction * 24d) |
---|
115 | fraction = temporary(fraction) - hour/24d |
---|
116 | minute = floor(fraction*1440d) |
---|
117 | second = (temporary(fraction) - minute/1440d) * 86400d |
---|
118 | |
---|
119 | return, julday(month, day, year, hour, minute, second) |
---|
120 | |
---|
121 | end |
---|
122 | |
---|