1 | ;+ |
---|
2 | ; |
---|
3 | ; look for time serie file with date min =< cmd.date1 and date max => cmd.spec |
---|
4 | ; |
---|
5 | ; @param CMD {in}{required}{type=structure} |
---|
6 | ; command line of window |
---|
7 | ; |
---|
8 | ; @param NCDF_DB {in}{required}{type=string} |
---|
9 | ; <location>:<path> or just <path> |
---|
10 | ; |
---|
11 | ; @param SUFFIX {in}{required}{type=string} |
---|
12 | ; |
---|
13 | ; @param DELTA_T1 {out}{type=integer} |
---|
14 | ; |
---|
15 | ; @param DATE1 {out}{type=string} |
---|
16 | ; [yy..yyy][mm][dd]-[sssss] if <n>s |
---|
17 | ; [yy..yyy][mm][dd] if <n>d |
---|
18 | ; [yy..yyy][mm] if <n>m |
---|
19 | ; [yy..yyy] if <n>y |
---|
20 | ; |
---|
21 | ; @param DATE2 {out}{type=string} |
---|
22 | ; [yy..yyy][mm][dd]-[sssss] if <n>s |
---|
23 | ; [yy..yyy][mm][dd] if <n>d |
---|
24 | ; [yy..yyy][mm] if <n>m |
---|
25 | ; [yy..yyy] if <n>y |
---|
26 | ; |
---|
27 | ; @param TIMAVEF {out}{type=string} |
---|
28 | ; |
---|
29 | ; output : data file date1 and date2 |
---|
30 | ; |
---|
31 | ; @examples |
---|
32 | ; |
---|
33 | ; IDL> cmd={timave:'1m',date1:'199201',spec:'-',exp:'HH',var:'temp_1'} |
---|
34 | ; IDL> ncdf_db='local:./' |
---|
35 | ; IDL> suffix='' |
---|
36 | ; IDL> search_time_file, cmd, ncdf_db, suffix, date1, date2, delta_t1, timavef |
---|
37 | ; IDL> print, date1, date2,delta_t1,timavef |
---|
38 | ; |
---|
39 | ; @uses |
---|
40 | ; <pro>common</pro> |
---|
41 | ; <propost_it>com_eg</propost_it> |
---|
42 | ; |
---|
43 | ; @todo |
---|
44 | ; get rid of spawn |
---|
45 | ; |
---|
46 | ; error handling |
---|
47 | ; realistic examples |
---|
48 | ; |
---|
49 | ; @history |
---|
50 | ; |
---|
51 | ; - fplod 20091210T150954Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
52 | ; |
---|
53 | ; * check parameters |
---|
54 | ; |
---|
55 | ; @version |
---|
56 | ; $Id$ |
---|
57 | ; |
---|
58 | ;- |
---|
59 | PRO search_time_file, cmd, ncdf_db, suffix, date1, date2, delta_t1, timavef |
---|
60 | ; |
---|
61 | compile_opt idl2, strictarrsubs |
---|
62 | ; |
---|
63 | @common |
---|
64 | @com_eg |
---|
65 | ; |
---|
66 | ; Return to caller if errors |
---|
67 | ON_ERROR, 2 |
---|
68 | ; |
---|
69 | usage='search_time_file, cmd, ncdf_db, suffix, date1, date2, delta_t1, timavef' |
---|
70 | ; |
---|
71 | nparam = N_PARAMS() |
---|
72 | IF (nparam LT 7) THEN BEGIN |
---|
73 | ras = report(['Incorrect number of arguments.' $ |
---|
74 | + '!C' $ |
---|
75 | + 'Usage : ' + usage]) |
---|
76 | stop |
---|
77 | ENDIF |
---|
78 | |
---|
79 | arg_type = size(cmd,/type) |
---|
80 | IF (arg_type NE 8) THEN BEGIN |
---|
81 | ras = report(['Incorrect arg type cmd' $ |
---|
82 | + '!C' $ |
---|
83 | + 'Usage : ' + usage]) |
---|
84 | stop |
---|
85 | ENDIF |
---|
86 | arg_struct_tags=TAG_NAMES(cmd) |
---|
87 | tag=WHERE(STRMATCH(arg_struct_tags, 'TIMAVE')) |
---|
88 | IF (tag EQ -1) THEN BEGIN |
---|
89 | ras = report(['Incorrect arg tag TIMAVE cmd' $ |
---|
90 | + '!C' $ |
---|
91 | + 'Usage : ' + usage]) |
---|
92 | stop |
---|
93 | ENDIF |
---|
94 | arg_type = size(cmd.timave,/type) |
---|
95 | IF (arg_type NE 7) THEN BEGIN |
---|
96 | ras = report(['Incorrect arg type cmd.timave' $ |
---|
97 | + '!C' $ |
---|
98 | + 'Usage : ' + usage]) |
---|
99 | stop |
---|
100 | ENDIF |
---|
101 | tag=WHERE(STRMATCH(arg_struct_tags, 'DATE1')) |
---|
102 | IF (tag EQ -1) THEN BEGIN |
---|
103 | ras = report(['Incorrect arg tag DATE1 cmd' $ |
---|
104 | + '!C' $ |
---|
105 | + 'Usage : ' + usage]) |
---|
106 | stop |
---|
107 | ENDIF |
---|
108 | arg_type = size(cmd.date1,/type) |
---|
109 | IF (arg_type NE 7) THEN BEGIN |
---|
110 | ras = report(['Incorrect arg type cmd.date1' $ |
---|
111 | + '!C' $ |
---|
112 | + 'Usage : ' + usage]) |
---|
113 | stop |
---|
114 | ENDIF |
---|
115 | tag=WHERE(STRMATCH(arg_struct_tags, 'SPEC')) |
---|
116 | IF (tag EQ -1) THEN BEGIN |
---|
117 | ras = report(['Incorrect arg tag SPEC cmd' $ |
---|
118 | + '!C' $ |
---|
119 | + 'Usage : ' + usage]) |
---|
120 | stop |
---|
121 | ENDIF |
---|
122 | arg_type = size(cmd.spec,/type) |
---|
123 | IF (arg_type NE 7) THEN BEGIN |
---|
124 | ras = report(['Incorrect arg type cmd.spec' $ |
---|
125 | + '!C' $ |
---|
126 | + 'Usage : ' + usage]) |
---|
127 | stop |
---|
128 | ENDIF |
---|
129 | tag=WHERE(STRMATCH(arg_struct_tags, 'EXP')) |
---|
130 | IF (tag EQ -1) THEN BEGIN |
---|
131 | ras = report(['Incorrect arg tag EXP cmd' $ |
---|
132 | + '!C' $ |
---|
133 | + 'Usage : ' + usage]) |
---|
134 | stop |
---|
135 | ENDIF |
---|
136 | |
---|
137 | arg_type = size(cmd.exp,/type) |
---|
138 | IF (arg_type NE 7) THEN BEGIN |
---|
139 | ras = report(['Incorrect arg type cmd.exp' $ |
---|
140 | + '!C' $ |
---|
141 | + 'Usage : ' + usage]) |
---|
142 | stop |
---|
143 | ENDIF |
---|
144 | |
---|
145 | tag=WHERE(STRMATCH(arg_struct_tags, 'VAR')) |
---|
146 | IF (tag EQ -1) THEN BEGIN |
---|
147 | ras = report(['Incorrect arg tag VAR cmd' $ |
---|
148 | + '!C' $ |
---|
149 | + 'Usage : ' + usage]) |
---|
150 | stop |
---|
151 | ENDIF |
---|
152 | |
---|
153 | arg_type = size(cmd.var,/type) |
---|
154 | IF (arg_type NE 7) THEN BEGIN |
---|
155 | ras = report(['Incorrect arg type cmd.grid' $ |
---|
156 | + '!C' $ |
---|
157 | + 'Usage : ' + usage]) |
---|
158 | stop |
---|
159 | ENDIF |
---|
160 | |
---|
161 | arg_type = size(ncdf_db,/type) |
---|
162 | IF (arg_type NE 7) THEN BEGIN |
---|
163 | ras = report(['Incorrect arg type ncdf_db' $ |
---|
164 | + '!C' $ |
---|
165 | + 'Usage : ' + usage]) |
---|
166 | stop |
---|
167 | ENDIF |
---|
168 | |
---|
169 | arg_type = size(suffix,/type) |
---|
170 | IF (arg_type NE 7) THEN BEGIN |
---|
171 | ras = report(['Incorrect arg type suffix' $ |
---|
172 | + '!C' $ |
---|
173 | + 'Usage : ' + usage]) |
---|
174 | stop |
---|
175 | ENDIF |
---|
176 | |
---|
177 | timavef = cmd.timave |
---|
178 | date1 = cmd.date1 |
---|
179 | date2 = cmd.spec |
---|
180 | |
---|
181 | found = 1 |
---|
182 | delta_t1 = 0 |
---|
183 | suff_var = '' |
---|
184 | |
---|
185 | IF strpos(cmd.timave, 'mm') NE -1 THEN BEGIN |
---|
186 | meanm = 'yes' |
---|
187 | ENDIF ELSE BEGIN |
---|
188 | meanm = 'no' |
---|
189 | ENDELSE |
---|
190 | |
---|
191 | CASE meanm OF |
---|
192 | |
---|
193 | 'no': BEGIN |
---|
194 | |
---|
195 | file_name_root = cmd.exp+'_'+cmd.timave+'_' |
---|
196 | |
---|
197 | ; local or remote DB |
---|
198 | machine = (strsplit(ncdf_db, ':', /EXTRACT))[0] |
---|
199 | CASE machine OF |
---|
200 | 'local': BEGIN |
---|
201 | ; field name added (1 variable) |
---|
202 | variab = '_'+cmd.var |
---|
203 | print, ' Looking for '+(strsplit(ncdf_db, ':', /EXTRACT))[1]+file_name_root+'*'+suffix+'.nc ...' |
---|
204 | spawn, 'ls '+(strsplit(ncdf_db, ':', /EXTRACT))[1]+file_name_root+'*'+suffix+'.nc', line2 |
---|
205 | line = line2 |
---|
206 | END |
---|
207 | ELSE: BEGIN |
---|
208 | spawn, 'grep -i " '+machine+' " '+hom_def+'remote/remote.def', rem_line |
---|
209 | nrem = n_elements(rem_line) |
---|
210 | IF nrem EQ 1 THEN BEGIN |
---|
211 | rem_line = strcompress(strtrim(rem_line[0], 2)) |
---|
212 | argvar = strsplit(rem_line, ' ', /EXTRACT) |
---|
213 | remote_name = argvar[1] |
---|
214 | remote_login = argvar[2] |
---|
215 | print, ' rsh '+remote_login+'@'+remote_name+' ls '+$ |
---|
216 | (strsplit(ncdf_db, ':', /EXTRACT))[1]+file_name_root+'*'+suffix+'.nc' |
---|
217 | print, '' |
---|
218 | spawn, 'rsh '+remote_login+'@'+remote_name+' ls '+$ |
---|
219 | (strsplit(ncdf_db, ':', /EXTRACT))[1]+file_name_root+'*'+suffix+'.nc', line |
---|
220 | ENDIF ELSE print, ' *** search_file : '+machine+' unknown in config/remote' |
---|
221 | END |
---|
222 | ENDCASE |
---|
223 | |
---|
224 | nfiles = n_elements(line) |
---|
225 | |
---|
226 | print, ' -> ', strtrim(string(nfiles), 2), ' file(s) found for date1 '+date1+' and date2 '+date2+':' |
---|
227 | print, ' ', line |
---|
228 | print, ' ' |
---|
229 | |
---|
230 | ; identify right file |
---|
231 | |
---|
232 | il = 0 |
---|
233 | found = 0 |
---|
234 | delta_1 = 0L |
---|
235 | WHILE il LE nfiles-1 AND found EQ 0 DO BEGIN |
---|
236 | file = line[il] |
---|
237 | IF debug_w THEN BEGIN |
---|
238 | print, ' line = ', line |
---|
239 | ENDIF |
---|
240 | ; remove root directory if exists |
---|
241 | IF strpos(file, '/') NE -1 THEN BEGIN |
---|
242 | argvar = strsplit(file, '/', /EXTRACT) |
---|
243 | n = n_elements(argvar) |
---|
244 | file = argvar[n-1] |
---|
245 | ENDIF ELSE BEGIN |
---|
246 | print, ' *** File missing or' |
---|
247 | print, ' *** Wrong definition for database: ', file |
---|
248 | stop |
---|
249 | ENDELSE |
---|
250 | argvar = strsplit(file, '_', /EXTRACT) |
---|
251 | dat1 = argvar[2] |
---|
252 | dat2 = argvar[3] |
---|
253 | |
---|
254 | IF debug_w THEN BEGIN |
---|
255 | print, ' dat1, date1, dat2, date2 ', dat1,' ', date1,' ', dat2,' ', date2 |
---|
256 | ENDIF |
---|
257 | |
---|
258 | IF strpos(dat1, '_') EQ -1 AND strpos(dat2, '_') EQ -1 AND $ |
---|
259 | strpos(dat1, '-') EQ -1 AND strpos(dat2, '-') EQ -1 THEN BEGIN |
---|
260 | IF (long(dat1) LE long(date1) AND long(dat2) GE long(date2)) THEN BEGIN |
---|
261 | found = 1 |
---|
262 | delta_t2 = compute_time(cmd.timave, dat1, date1) |
---|
263 | delta_t1 = delta_t2.count-1 |
---|
264 | ; print, delta_t1 |
---|
265 | date1 = dat1 |
---|
266 | date2 = dat2 |
---|
267 | var_file = strpos(file, cmd.var) |
---|
268 | ENDIF |
---|
269 | ;ELSE stop, '*** The second date in the name of the file should be higher than the first one in terms of absolute numbers... EXIT search_time_file ' |
---|
270 | ENDIF ELSE BEGIN |
---|
271 | found = 1 |
---|
272 | nfiles = 1 |
---|
273 | delta_t1 = 0 |
---|
274 | ENDELSE |
---|
275 | |
---|
276 | il = il+1 |
---|
277 | ENDWHILE |
---|
278 | |
---|
279 | END |
---|
280 | 'yes': BEGIN |
---|
281 | CASE strmid(cmd.timave, strlen(cmd.timave)-2, 1) OF |
---|
282 | 'm': BEGIN ; mean month case |
---|
283 | nmonths = long(strmid(cmd.timave, 0,strlen(cmd.timave)-2)) |
---|
284 | date1 = '01' |
---|
285 | ndate = string(long(12/nmonths), format = '(I2.2)') |
---|
286 | date2 = ndate+'_'+strmid(cmd.date1, 3, strlen(cmd.date1)-3) |
---|
287 | timavef = strmid(cmd.timave, 0,strlen(cmd.timave)-2)+'mm' |
---|
288 | END |
---|
289 | ELSE: |
---|
290 | ENDCASE |
---|
291 | delta_t1 = 0 |
---|
292 | nfiles = 1 |
---|
293 | found = 1 |
---|
294 | END |
---|
295 | ELSE: |
---|
296 | ENDCASE |
---|
297 | |
---|
298 | ; print, date1, date2, delta_t1 |
---|
299 | |
---|
300 | IF nfiles EQ 0 OR found EQ 0 THEN BEGIN |
---|
301 | date1 = '???' |
---|
302 | date2 = '???' |
---|
303 | ENDIF |
---|
304 | |
---|
305 | END |
---|