1 | FUNCTION compute_time, timeave, date1, date2, NEXT = next |
---|
2 | |
---|
3 | @common |
---|
4 | @com_eg |
---|
5 | ; |
---|
6 | ; compute number + array of time intervals in units of timeave between date1 and date2 |
---|
7 | ; if /NEXT, compute next date after date1, using date2 units of timeave |
---|
8 | ; date code [yy..yyy][mm][dd]-[sssss] if <n>s |
---|
9 | ; [yy..yyy][mm][dd] if <n>d |
---|
10 | ; [yy..yyy][mm] if <n>m |
---|
11 | ; [yy..yyy] if <n>y |
---|
12 | |
---|
13 | len1 = strlen(date1) |
---|
14 | IF NOT keyword_set(NEXT) THEN BEGIN |
---|
15 | |
---|
16 | len2 = strlen(date2) |
---|
17 | mean_type = strmid(timeave, strlen(timeave)-1,1) |
---|
18 | CASE mean_type OF |
---|
19 | 'y':BEGIN ; year case |
---|
20 | delta_time = long(strmid(timeave, 0, strlen(timeave)-1)) |
---|
21 | year1 = long(date1) |
---|
22 | year2 = long(date2) |
---|
23 | count = (year2-year1+1)*delta_time |
---|
24 | IF calendar_type LE 1 THEN BEGIN |
---|
25 | time = findgen(count)*360*delta_time+julday(1,1,year1) |
---|
26 | ENDIF ELSE BEGIN |
---|
27 | time = findgen(count)*360*delta_time+ $ |
---|
28 | julday(1,1,year1, ndayspm = calendar_type) |
---|
29 | ENDELSE |
---|
30 | END |
---|
31 | 'm': BEGIN ; month case |
---|
32 | CASE strmid(timeave, strlen(timeave)-2,1) OF |
---|
33 | 'm': BEGIN ; mean month |
---|
34 | delta_time = long(strmid(timeave, 0, strlen(timeave)-2)) |
---|
35 | month1 = long(strmid(date1, 0, 2)) |
---|
36 | month2 = long(strmid(date2, 0, 2)) |
---|
37 | count = (month2-month1+1) |
---|
38 | ; count = (month2-month1+1)/delta_time |
---|
39 | ; time scale for hov |
---|
40 | IF calendar_type LE 1 THEN BEGIN |
---|
41 | time = lindgen(nb_cycles*count)*30*delta_time+ $ |
---|
42 | julday(month1,1,01) |
---|
43 | ENDIF ELSE BEGIN |
---|
44 | time = lindgen(nb_cycles*count)*30*delta_time+ $ |
---|
45 | julday(month1,1,01, ndayspm = calendar_type) |
---|
46 | ENDELSE |
---|
47 | |
---|
48 | END |
---|
49 | ELSE: BEGIN ; month / year |
---|
50 | delta_time = long(strmid(timeave, 0, strlen(timeave)-1)) |
---|
51 | month1 = long(strmid(date1, len1-2, 2)) |
---|
52 | year1 = long(strmid(date1, 0, len1-2)) |
---|
53 | month2 = long(strmid(date2, len2-2, 2)) |
---|
54 | year2 = long(strmid(date2, 0, len2-2)) |
---|
55 | count = 0 |
---|
56 | im = month1 |
---|
57 | iy = year1 |
---|
58 | idate = long(month1+100*year1) |
---|
59 | WHILE idate LE date2 DO BEGIN |
---|
60 | idate = long(im+100*iy) |
---|
61 | count = count + 1 |
---|
62 | im = im + delta_time |
---|
63 | IF im EQ 13 THEN BEGIN |
---|
64 | iy = iy+1 |
---|
65 | im = 1 |
---|
66 | ENDIF |
---|
67 | ENDWHILE |
---|
68 | count = count - 1 |
---|
69 | ; time scale for hov |
---|
70 | IF calendar_type LE 1 THEN BEGIN |
---|
71 | time = lindgen(count)*30*delta_time+ $ |
---|
72 | julday(month1,1,year1) |
---|
73 | ENDIF ELSE BEGIN |
---|
74 | time = lindgen(count)*30*delta_time+ $ |
---|
75 | julday(month1,1,year1, ndayspm = calendar_type) |
---|
76 | ENDELSE |
---|
77 | END |
---|
78 | ENDCASE |
---|
79 | END |
---|
80 | 'd': BEGIN ; day case |
---|
81 | delta_time = long(strmid(timeave, 0, strlen(timeave)-1)) |
---|
82 | day1 = long(strmid(date1, len1-2, 2)) |
---|
83 | month1 = long(strmid(date1, len1-4, 2)) |
---|
84 | year1 = long(strmid(date1, 0, len1-4)) |
---|
85 | day2 = long(strmid(date2, len1-2, 2)) |
---|
86 | month2 = long(strmid(date2, len2-4, 2)) |
---|
87 | year2 = long(strmid(date2, 0, len2-4)) |
---|
88 | count = 0 |
---|
89 | id = day1 |
---|
90 | im = month1 |
---|
91 | iy = year1 |
---|
92 | idate = long(day1+100*month1+10000*year1) |
---|
93 | WHILE idate LE date2 DO BEGIN |
---|
94 | idate = long(id+100*im+10000*iy) |
---|
95 | count = count + 1 |
---|
96 | id = id + delta_time |
---|
97 | idmax = daypm(im, iy) |
---|
98 | IF id GT idmax THEN BEGIN |
---|
99 | im = im + 1 |
---|
100 | id = id - idmax |
---|
101 | ENDIF |
---|
102 | IF im EQ 13 THEN BEGIN |
---|
103 | iy = iy+1 |
---|
104 | im = 1 |
---|
105 | ENDIF |
---|
106 | ENDWHILE |
---|
107 | count = count - 1 |
---|
108 | ; time scale for hov |
---|
109 | IF calendar_type LE 1 THEN BEGIN |
---|
110 | time = lindgen(count)*1*delta_time+ $ |
---|
111 | julday(month1,1,year1) |
---|
112 | ENDIF ELSE BEGIN |
---|
113 | time = lindgen(count)*1*delta_time+ $ |
---|
114 | julday(month1,1,year1, ndayspm = calendar_type) |
---|
115 | ENDELSE |
---|
116 | END |
---|
117 | 's': BEGIN ; seconds case |
---|
118 | delta_time = long(strmid(timeave, 0, strlen(timeave)-1)) |
---|
119 | sec1 = long(strmid(date1, len1-5, 5)) |
---|
120 | day1 = long(strmid(date1, len1-8, 2)) |
---|
121 | month1 = long(strmid(date1, len1-10, 2)) |
---|
122 | year1 = long(strmid(date1, 0, len1-10)) |
---|
123 | sec2 = long(strmid(date2, len1-5, 5)) |
---|
124 | day2 = long(strmid(date2, len1-8, 2)) |
---|
125 | month2 = long(strmid(date2, len2-10, 2)) |
---|
126 | year2 = long(strmid(date2, 0, len2-10)) |
---|
127 | count = 0 |
---|
128 | is = sec1 |
---|
129 | id = day1 |
---|
130 | im = month1 |
---|
131 | iy = year1 |
---|
132 | WHILE is LE sec2 AND id LE day2 AND im LE month2 $ |
---|
133 | AND iy LE year2 DO BEGIN |
---|
134 | count = count + 1 |
---|
135 | is = is + delta_time |
---|
136 | IF is GT 86400 THEN BEGIN |
---|
137 | id = id + 1 |
---|
138 | is = is - 86400 |
---|
139 | ENDIF |
---|
140 | idmax = daypm(im, iy) |
---|
141 | IF id EQ idmax THEN BEGIN |
---|
142 | im = im + 1 |
---|
143 | id = 1 |
---|
144 | ENDIF |
---|
145 | IF im EQ 13 THEN BEGIN |
---|
146 | iy = iy+1 |
---|
147 | im = 1 |
---|
148 | ENDIF |
---|
149 | ENDWHILE |
---|
150 | ; time scale for hov |
---|
151 | IF calendar_type LE 1 THEN BEGIN |
---|
152 | time = sec1/86400.+lindgen(count)*1/86400.*delta_time+ $ |
---|
153 | julday(month1,1,year1) |
---|
154 | ENDIF ELSE BEGIN |
---|
155 | time = sec1/86400.+lindgen(count)*1/86400.*delta_time+ $ |
---|
156 | julday(month1,1,year1, ndayspm = calendar_type) |
---|
157 | ENDELSE |
---|
158 | END |
---|
159 | ELSE: BEGIN |
---|
160 | print, ' **** compute_time not ready for timeave = ', timeave |
---|
161 | count = -1 |
---|
162 | time = 0 |
---|
163 | END |
---|
164 | ENDCASE |
---|
165 | IF date1 EQ date2 THEN count = 1 |
---|
166 | timearr = {count: count, scale: time} |
---|
167 | return, timearr |
---|
168 | |
---|
169 | ENDIF ELSE BEGIN |
---|
170 | ; next date after date1, using date2 units of timeave |
---|
171 | dmax = 30 |
---|
172 | print, ' **** ASSUMES DMAX = 30' |
---|
173 | CASE strmid(timeave, strlen(timeave)-1, 1) OF |
---|
174 | 'd': BEGIN |
---|
175 | ndays = long(strmid(timeave, 0, strlen(timeave)-1)) |
---|
176 | day1 = long(strmid(date1, len1-2, 2)) |
---|
177 | month1 = long(strmid(date1, len1-4, 2)) |
---|
178 | year1 = long(strmid(date1, 0, len1-4)) |
---|
179 | iadd = 1 |
---|
180 | day2 = day1 |
---|
181 | month2 = month1 |
---|
182 | year2 = year1 |
---|
183 | WHILE iadd LE date2 DO BEGIN |
---|
184 | day2 = day2+1 |
---|
185 | IF day2 GT dmax THEN BEGIN |
---|
186 | month2 = month2 + 1 |
---|
187 | day2 = 1 |
---|
188 | IF month2 GT 12 THEN BEGIN |
---|
189 | year2 = year2+1 |
---|
190 | month2 = 1 |
---|
191 | ENDIF |
---|
192 | ENDIF |
---|
193 | iadd = iadd + 1 |
---|
194 | ENDWHILE |
---|
195 | IF year2 GE 10 THEN BEGIN |
---|
196 | nextdate = string(year2) |
---|
197 | ENDIF ELSE BEGIN |
---|
198 | nextdate = string(format = '(I2.2)',year2) |
---|
199 | ENDELSE |
---|
200 | nextdate = nextdate+string(format = '(I2.2)', month2)+string(format = '(I2.2)', day2) |
---|
201 | END |
---|
202 | ELSE: BEGIN |
---|
203 | print, ' **** next time not ready for timeave = ', timeave |
---|
204 | nextdate = -1 |
---|
205 | END |
---|
206 | ENDCASE |
---|
207 | return, nextdate |
---|
208 | ENDELSE |
---|
209 | |
---|
210 | END |
---|