source: trunk/procs/search_time_file.pro @ 2

Last change on this file since 2 was 2, checked in by post_it, 17 years ago

Initial import from ~/POST_IT/

File size: 4.4 KB
Line 
1PRO search_time_file, cmd, ncdf_db, suffix, date1, date2, delta_t1, timavef
2
3; look for time serie file with date min =< cmd.date1 and date max => cmd.spec
4; output : data file date1 and date2
5@common
6@com_eg
7
8   timavef = cmd.timave
9   date1 = cmd.date1
10   date2 = cmd.spec
11
12   found = 1
13   delta_t1 = 0
14   suff_var = ''
15
16   CASE cmd.timave OF
17      '1mm': meanm = 'yes'
18      '3mm': meanm = 'yes'
19      ELSE: meanm = 'no'
20   ENDCASE
21
22   CASE meanm OF
23
24      'no': BEGIN
25
26         file_name_root = cmd.exp+'_'+cmd.timave+'_'
27
28         ; local or remote DB
29         machine = (str_sep(ncdf_db, ':'))[0]
30         CASE machine OF
31            'local': BEGIN
32                                ; field name added (1 variable)
33               variab = '_'+cmd.var
34;               spawn, 'ls '+(str_sep(ncdf_db, ':'))[1]+file_name_root+'*'+suffix+variab+'.nc', line
35                                ; global name (all variables)
36;               spawn, 'dir '+(str_sep(ncdf_db,
37;               ':'))[1]+file_name_root+'*'+suffix+'.nc', line2
38;               print, 'ls
39;               '+(str_sep(ncdf_db,':'))[1]+file_name_root+'*'+suffix+'.nc'
40               print, '    Looking for '+(str_sep(ncdf_db, ':'))[1]+file_name_root+'*'+suffix+'.nc ...'
41               spawn, 'ls '+(str_sep(ncdf_db, ':'))[1]+file_name_root+'*'+suffix+'.nc', line2
42;               line = [line, line2]
43               line = line2
44            END
45            ELSE: BEGIN
46               spawn, 'grep -i " '+machine+' " '+hom_def+'remote/remote.def', rem_line
47               nrem = n_elements(rem_line)
48               IF nrem EQ 1 THEN BEGIN
49                  rem_line = strcompress(strtrim(rem_line[0], 2))
50                  argvar = str_sep(rem_line, ' ')
51                  remote_name = argvar[1]
52                  remote_login = argvar[2]
53                  print, '    rsh '+remote_login+'@'+remote_name+' ls '+$
54                   (str_sep(ncdf_db, ':'))[1]+file_name_root+'*'+suffix+'.nc'
55                  print, ''
56                  spawn, 'rsh '+remote_login+'@'+remote_name+' ls '+$
57                   (str_sep(ncdf_db, ':'))[1]+file_name_root+'*'+suffix+'.nc', line
58               ENDIF ELSE print, ' *** search_file : '+machine+' unknown in config/remote'
59            END
60         ENDCASE
61
62         nfiles = n_elements(line)
63
64         print, '     ->', nfiles, ' file(s) found for date1 '+date1+' and date2 '+date2+':'
65         print, line
66         print, ' '
67
68         il = 0
69         found = 0
70         delta_1 = 0L
71         WHILE il LE nfiles-1 AND found EQ 0 DO BEGIN
72            file = line[il]
73            ; remove root directory if exists
74            IF strpos(file, '/') NE -1 THEN BEGIN
75               argvar = str_sep(file, '/')
76               n = n_elements(argvar)
77               file = argvar[n-1]
78            ENDIF ELSE BEGIN
79               print, '  *** File missing or'
80               print, '  *** Wrong definition for database: ', file
81               stop
82            ENDELSE 
83            argvar = str_sep(file, '_')
84            dat1 = argvar(2)
85            dat2 = argvar(3)
86
87;    print, dat1,' ', date1,' ', dat2,' ', date2
88
89            IF strpos(dat1, '_') EQ -1 AND strpos(dat2, '_') EQ -1 AND $
90             strpos(dat1, '-') EQ -1 AND strpos(dat2, '-') EQ -1 THEN BEGIN
91               IF (long(dat1) LE long(date1) AND long(dat2) GE long(date2))  THEN BEGIN
92                  found = 1
93                  delta_t2 = compute_time(cmd.timave, dat1, date1)
94                  delta_t1 = delta_t2.count-1
95;     print, delta_t1
96                  date1 = dat1
97                  date2 = dat2
98                  var_file = strpos(file, cmd.var)
99               ENDIF
100            ENDIF ELSE BEGIN
101               found = 1
102               nfiles = 1
103               delta_t1 = 0
104            ENDELSE
105
106            il = il+1
107         ENDWHILE
108
109      END
110      'yes': BEGIN
111         CASE strmid(cmd.timave, strlen(cmd.timave)-2, 1) OF
112            'm': BEGIN          ; mean month case
113               nmonths = long(strmid(cmd.timave, 0,strlen(cmd.timave)-2))
114               date1 = '01'
115               ndate = string(long(12/nmonths), format = '(I2.2)')
116               date2 = ndate+'_'+strmid(cmd.date1, 3, strlen(cmd.date1)-3)
117               timavef = strmid(cmd.timave, 0,strlen(cmd.timave)-2)+'mm'
118            END
119            ELSE:
120         ENDCASE
121         delta_t1 = 0
122         nfiles = 1
123         found = 1
124      END
125      ELSE:
126   ENDCASE
127
128;   print, date1, date2, delta_t1
129
130   IF nfiles EQ 0 OR found EQ 0 THEN BEGIN & date1 = '???' & date2 = '???' & END
131
132END
Note: See TracBrowser for help on using the repository browser.