1 | ; $Id$ |
---|
2 | ; |
---|
3 | ; Copyright (c) 1992-1998, Research Systems, Inc. All rights reserved. |
---|
4 | ; Unauthorized reproduction prohibited. |
---|
5 | ; |
---|
6 | |
---|
7 | ;+ |
---|
8 | ; NAME: |
---|
9 | ; CALDAT |
---|
10 | ; |
---|
11 | ; PURPOSE: |
---|
12 | ; Return the calendar date and time given julian date. |
---|
13 | ; This is the inverse of the function JULDAY. |
---|
14 | ; CATEGORY: |
---|
15 | ; Misc. |
---|
16 | ; |
---|
17 | ; CALLING SEQUENCE: |
---|
18 | ; CALDAT, Julian, Month, Day, Year, Hour, Minute, Second |
---|
19 | ; See also: julday, the inverse of this function. |
---|
20 | ; |
---|
21 | ; INPUTS: |
---|
22 | ; JULIAN contains the Julian Day Number (which begins at noon) of the |
---|
23 | ; specified calendar date. It should be a long integer. |
---|
24 | ; |
---|
25 | ; KEYWORD PARAMETERS: |
---|
26 | ; |
---|
27 | ; NDAYSPM: developpe par eric, ca veut dire: nombre de jours par mois! |
---|
28 | ; par defaut c''est 30, sinon le specifier en donnant |
---|
29 | ; une valeur a ndayspm |
---|
30 | ; pour passer a un calendrier avec un nombre de jours constant par |
---|
31 | ; mois. Utilise en particulier ds julday et caldat |
---|
32 | ; |
---|
33 | ; OUTPUTS: |
---|
34 | ; (Trailing parameters may be omitted if not required.) |
---|
35 | ; MONTH: Number of the desired month (1 = January, ..., 12 = December). |
---|
36 | ; |
---|
37 | ; DAY: Number of day of the month. |
---|
38 | ; |
---|
39 | ; YEAR: Number of the desired year. |
---|
40 | ; |
---|
41 | ; HOUR: Hour of the day |
---|
42 | ; Minute: Minute of the day |
---|
43 | ; Second: Second (and fractions) of the day. |
---|
44 | ; |
---|
45 | ; COMMON BLOCKS: |
---|
46 | ; None. |
---|
47 | ; |
---|
48 | ; SIDE EFFECTS: |
---|
49 | ; None. |
---|
50 | ; |
---|
51 | ; RESTRICTIONS: |
---|
52 | ; Accuracy using IEEE double precision numbers is approximately |
---|
53 | ; 1/10000th of a second. |
---|
54 | ; |
---|
55 | ; MODIFICATION HISTORY: |
---|
56 | ; Translated from "Numerical Recipies in C", by William H. Press, |
---|
57 | ; Brian P. Flannery, Saul A. Teukolsky, and William T. Vetterling. |
---|
58 | ; Cambridge University Press, 1988 (second printing). |
---|
59 | ; |
---|
60 | ; DMS, July 1992. |
---|
61 | ; DMS, April 1996, Added HOUR, MINUTE and SECOND keyword |
---|
62 | ; AB, 7 December 1997, Generalized to handle array input. |
---|
63 | ; Eric Guilyardi, June 1999 |
---|
64 | ; Added key_work ndayspm for fixed number of days per months |
---|
65 | ;- |
---|
66 | ; |
---|
67 | |
---|
68 | |
---|
69 | pro caldat_scalar, Julian, Month, Day, Year, Hour, Minute, Second, NDAYSPM = ndayspm |
---|
70 | ; Internal variant of CALDAT that does the actual work on a single |
---|
71 | ; value. |
---|
72 | |
---|
73 | ON_ERROR, 2 ; Return to caller if errors |
---|
74 | |
---|
75 | IF NOT keyword_set(ndayspm) THEN BEGIN |
---|
76 | |
---|
77 | IGREG = 2299161L ;Beginning of Gregorian calendar |
---|
78 | |
---|
79 | IF julian GE 0 THEN jul = long(julian + .5d) $ ;Better be long |
---|
80 | ELSE jul = long(julian - .5d) |
---|
81 | f = julian + .5d - jul |
---|
82 | if f ne 0.0 then begin ;Get hours, minutes, seconds. |
---|
83 | hour = floor(f * 24.) |
---|
84 | f = f - hour / 24.d |
---|
85 | minute = floor(f*1440) |
---|
86 | second = (f - minute/1440.d0) * 86400.0d0 |
---|
87 | endif else begin |
---|
88 | hour = 0L |
---|
89 | minute = 0L |
---|
90 | second = 0L |
---|
91 | endelse |
---|
92 | |
---|
93 | |
---|
94 | if jul ge igreg then begin |
---|
95 | jalpha = long(((jul - 1867216) - 0.25d0) / 36524.25) |
---|
96 | ja = jul + 1 + jalpha - long(0.25d0 * jalpha) |
---|
97 | endif else ja = jul |
---|
98 | |
---|
99 | jb = ja + 1524l |
---|
100 | jc = long(6680.0 + ((jb-2439870)-122.1d0)/365.25) |
---|
101 | jd = long(365 * jc + (0.25 * jc)) |
---|
102 | je = long((jb - jd) / 30.6001) |
---|
103 | |
---|
104 | day = jb - jd - long(30.6001d * je) |
---|
105 | month = je -1 |
---|
106 | if (month gt 12) then month = month - 12 |
---|
107 | year = jc - 4715 |
---|
108 | if month gt 2 then year = year - 1 |
---|
109 | if year le 0 then year = year - 1 |
---|
110 | |
---|
111 | ENDIF ELSE BEGIN |
---|
112 | |
---|
113 | jul = long(julian) |
---|
114 | f = (jul - floor(jul)) |
---|
115 | IF f NE 0.0 THEN BEGIN ;Get hours, minutes, seconds. |
---|
116 | hour = floor(f*24.) |
---|
117 | f = f - hour / 24.d |
---|
118 | minute = floor(f*1440) |
---|
119 | second = (f - minute/1440.d0) * 86400.0d0 |
---|
120 | ENDIF ELSE BEGIN |
---|
121 | hour = 0L |
---|
122 | minute = 0L |
---|
123 | second = 0L |
---|
124 | ENDELSE |
---|
125 | |
---|
126 | IF ndayspm EQ 1 THEN ndayspm = 30 |
---|
127 | |
---|
128 | Z = floor(julian) |
---|
129 | X = Z / ndayspm |
---|
130 | day = Z - X*ndayspm |
---|
131 | year = X / 12 |
---|
132 | month = X - year*12 + 1 |
---|
133 | year = year + 1 |
---|
134 | |
---|
135 | ENDELSE |
---|
136 | |
---|
137 | end |
---|
138 | |
---|
139 | |
---|
140 | |
---|
141 | |
---|
142 | pro caldat, Julian, Month, Day, Year, Hour, Minute, Second, NDAYSPM = ndayspm |
---|
143 | |
---|
144 | ON_ERROR, 2 ; Return to caller if errors |
---|
145 | |
---|
146 | ; Determine shape of input and construct longword output variables of |
---|
147 | ; the same shape. |
---|
148 | |
---|
149 | s = size(julian) |
---|
150 | if (s[0] eq 0) then begin |
---|
151 | ; Julian is scalar. Just call CALDAT_SCALAR and pass our arguments through. |
---|
152 | caldat_scalar, Julian, Month, Day, Year, Hour, Minute, Second, NDAYSPM = ndayspm |
---|
153 | return |
---|
154 | endif |
---|
155 | |
---|
156 | ; It's an array. Construct result variables |
---|
157 | ndim = s[0] ; Number or array dimensions |
---|
158 | n = s[ndim + 2] ; # of elements |
---|
159 | s[ndim + 1] = 3 ; Change the type to LONG |
---|
160 | MONTH = (DAY = (YEAR = (HOUR = (MINUTE = (SECOND = MAKE_ARRAY(SIZE=s)))))) |
---|
161 | |
---|
162 | ; Loop over the input |
---|
163 | for i = 0, n-1 do begin |
---|
164 | caldat_scalar, julian[i], month_tmp, day_tmp, year_tmp, $ |
---|
165 | hour_tmp, minute_tmp, second_tmp, NDAYSPM = ndayspm |
---|
166 | month[i] = month_tmp |
---|
167 | day[i] = day_tmp |
---|
168 | year[i] = year_tmp |
---|
169 | hour[i] = hour_tmp |
---|
170 | minute[i] = minute_tmp |
---|
171 | second[i] = second_tmp |
---|
172 | endfor |
---|
173 | end |
---|