1 | ; $Id$ |
---|
2 | ; |
---|
3 | ; Copyright (c) 1988-1998, Research Systems, Inc. All rights reserved. |
---|
4 | ; Unauthorized reproduction prohibited. |
---|
5 | |
---|
6 | function JULDAY, MONTH, DAY, YEAR, Hour, Minute, Second, NDAYSPM = ndayspm, _extra=ex |
---|
7 | ;+ |
---|
8 | ; NAME: |
---|
9 | ; JULDAY |
---|
10 | ; |
---|
11 | ; PURPOSE: |
---|
12 | ; Calculate the Julian Day Number for a given month, day, and year. |
---|
13 | ; This is the inverse of the library function CALDAT. |
---|
14 | ; See also caldat, the inverse of this function. |
---|
15 | ; CATEGORY: |
---|
16 | ; Misc. |
---|
17 | ; |
---|
18 | ; CALLING SEQUENCE: |
---|
19 | ; Result = JULDAY(Month, Day, Year) |
---|
20 | ; |
---|
21 | ; INPUTS: |
---|
22 | ; MONTH: Number of the desired month (1 = January, ..., 12 = December). |
---|
23 | ; |
---|
24 | ; DAY: Number of day of the month. |
---|
25 | ; |
---|
26 | ; YEAR: Number of the desired year. |
---|
27 | ; |
---|
28 | ; HOUR: Number of the hour of the day. |
---|
29 | ; |
---|
30 | ; MINUTE: Number of the minute of the hour. |
---|
31 | ; |
---|
32 | ; SECOND: |
---|
33 | ; |
---|
34 | ; OPTIONAL INPUT PARAMETERS: |
---|
35 | ; Hour, Minute, Second = optional time of day. |
---|
36 | ; |
---|
37 | ; KEYWORD PARAMETERS: |
---|
38 | ; |
---|
39 | ; NDAYSPM: developpe par eric, ca veut dire: nombre de jours par mois! |
---|
40 | ; par defaut c''est 30, sinon le specifier en donnant |
---|
41 | ; une valeur a ndayspm |
---|
42 | ; pour passer a un calendrier avec un nombre de jours constant par |
---|
43 | ; mois. Utilise en particulier ds julday et caldat |
---|
44 | ; |
---|
45 | ; OUTPUTS: |
---|
46 | ; JULDAY returns the Julian Day Number (which begins at noon) of the |
---|
47 | ; specified calendar date. If the time of day (Hr, Min, Sec), is 0, |
---|
48 | ; the result will be a long integer, otherwise the result is a |
---|
49 | ; double precision floating point number. |
---|
50 | ; |
---|
51 | ; COMMON BLOCKS: |
---|
52 | ; None. |
---|
53 | ; |
---|
54 | ; SIDE EFFECTS: |
---|
55 | ; None. |
---|
56 | ; |
---|
57 | ; RESTRICTIONS: |
---|
58 | ; Accuracy using IEEE double precision numbers is approximately |
---|
59 | ; 1/10000th of a second. |
---|
60 | ; |
---|
61 | ; MODIFICATION HISTORY: |
---|
62 | ; Translated from "Numerical Recipies in C", by William H. Press, |
---|
63 | ; Brian P. Flannery, Saul A. Teukolsky, and William T. Vetterling. |
---|
64 | ; Cambridge University Press, 1988 (second printing). |
---|
65 | ; |
---|
66 | ; AB, September, 1988 |
---|
67 | ; DMS, April, 1995, Added time of day. |
---|
68 | ; |
---|
69 | ; Eric Guilyardi, June 1999 |
---|
70 | ; Added key_work ndayspm for fixed number of days per months |
---|
71 | ;- |
---|
72 | ; |
---|
73 | ON_ERROR, 2 ; Return to caller if errors |
---|
74 | |
---|
75 | MONTHS = ['JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG', $ |
---|
76 | 'SEP','OCT','NOV','DEC'] |
---|
77 | |
---|
78 | IF NOT keyword_set(ndayspm) THEN BEGIN |
---|
79 | |
---|
80 | ; Gregorian Calander was adopted on Oct. 15, 1582 |
---|
81 | GREG = 15L + 31L * (10L + 12L * 1582L) |
---|
82 | |
---|
83 | ; Process the input, if all are missing, use todays date. |
---|
84 | NP = n_params() |
---|
85 | if NP eq 0 then begin |
---|
86 | DATE = systime() |
---|
87 | L_MONTH = long(where(strupcase(strmid(DATE, 4, 3)) eq MONTHS)) |
---|
88 | L_MONTH = L_MONTH[0] + 1 ; Scalarize it... |
---|
89 | L_DAY = long(strmid(DATE, 8, 2)) |
---|
90 | L_YEAR = long(strmid(DATE, 20, 4)) |
---|
91 | endif else if np ge 3 then begin |
---|
92 | L_MONTH = LONG(MONTH) |
---|
93 | L_DAY = LONG(DAY) |
---|
94 | L_YEAR=LONG(YEAR) |
---|
95 | ; |
---|
96 | ;*************************************************** |
---|
97 | ; Change test to allow year 0 for climatological data |
---|
98 | ;******************************************************** |
---|
99 | ; if (L_YEAR eq 0) then message, 'There is no year zero.' |
---|
100 | endif else message, 'Wrong number of parameters.' |
---|
101 | ; |
---|
102 | ;*************************************************** |
---|
103 | ; Change test to allow year 0 for climatological data |
---|
104 | ;******************************************************** |
---|
105 | ; if (L_YEAR lt 0) then L_YEAR = L_YEAR + 1 |
---|
106 | if (L_YEAR le 0) then L_YEAR = L_YEAR + 1 |
---|
107 | if (L_MONTH gt 2) then begin |
---|
108 | JY = L_YEAR |
---|
109 | JM = L_MONTH + 1 |
---|
110 | endif else begin |
---|
111 | JY = L_YEAR - 1 |
---|
112 | JM = L_MONTH + 13 |
---|
113 | endelse |
---|
114 | |
---|
115 | JUL = floor(365.25 * JY) + floor(30.6001 * JM) + L_DAY + 1720995 |
---|
116 | ; Test whether to change to Gregorian Calandar. |
---|
117 | if ((L_DAY + 31L * (L_MONTH + 12L * L_YEAR)) ge GREG) then begin |
---|
118 | JA = long(0.01 * JY) |
---|
119 | JUL = JUL + 2 - JA + long(0.25 * JA) |
---|
120 | endif |
---|
121 | |
---|
122 | if n_elements(Hour) + n_elements(Minute) + n_elements(Second) eq 0 then $ |
---|
123 | return, JUL |
---|
124 | if n_elements(Hour) eq 0 then Hour = 0 |
---|
125 | if n_elements(Minute) eq 0 then Minute = 0 |
---|
126 | if n_elements(Second) eq 0 then Second = 0 |
---|
127 | |
---|
128 | return, JUL + (Hour / 24.0d0 - .5d0) + (Minute/1440.0d0) + (Second / 86400.0d0) |
---|
129 | |
---|
130 | ENDIF ELSE BEGIN |
---|
131 | ; |
---|
132 | ; Fixed number of days per month (default=30) : |
---|
133 | ; |
---|
134 | IF ndayspm EQ 1 THEN ndayspm = 30 |
---|
135 | |
---|
136 | L_MONTH = LONG(MONTH) |
---|
137 | L_DAY = LONG(DAY) |
---|
138 | L_YEAR=LONG(YEAR) |
---|
139 | |
---|
140 | JUL = ((L_YEAR-1)*12. + (L_MONTH-1))* ndayspm + L_DAY |
---|
141 | if n_elements(Hour) + n_elements(Minute) + n_elements(Second) eq 0 then $ |
---|
142 | return, JUL |
---|
143 | if n_elements(Hour) eq 0 then Hour = 0 |
---|
144 | if n_elements(Minute) eq 0 then Minute = 0 |
---|
145 | if n_elements(Second) eq 0 then Second = 0 |
---|
146 | |
---|
147 | return, JUL + (Hour / 24.0d0) + (Minute/1440.0d0) + (Second / 86400.0d0) |
---|
148 | |
---|
149 | ENDELSE |
---|
150 | end |
---|