source: trunk/SRC/ReadWrite/scanctl.pro @ 177

Last change on this file since 177 was 136, checked in by pinsard, 18 years ago

some improvements and corrections in some .pro file according to
aspell and idldoc log file

  • Property svn:keywords set to Id
File size: 16.3 KB
Line 
1;+
2; @file_comments
3; GLAMBOUNDARY 2 elements vector, {lon1,lon2], the longitude
4; boundaries that should be used to visualize the data.
5;  lon2 > lon1
6;  lon2 - lon1 le 360
7; key_shift will be defined according to GLAMBOUNDARY.
8;
9; @version $Id$
10;-
11PRO scanctl, filename, filesname, jpt1file, varsname, varslev, swapbytes, bigendian, littleendian, f77sequential, fileheader, theader, xyheader, VARFMT = varfmt, _EXTRA = ex
12;
13  compile_opt idl2, strictarrsubs
14;
15@common
16
17   time1 = systime(1)           ; for key_performance
18
19;------------------------
20; DTYPE
21;------------------------
22   spawn, '\grep -i "^DTYPE" '+filename, notgood
23   if keyword_set(notgood) then begin
24      print, 'This program is not adapted to data type station or grib. Sorry...'
25      stop
26   endif
27;------------------------
28; UNDEF, define valmask
29;------------------------
30   spawn, '\grep -i "^UNDEF" '+filename, valmask
31   valmask = strtrim(valmask, 2)
32   valmask = strsplit(valmask[0],/extract)
33   valmask = float(valmask[1])
34;------------------------
35; Headers
36;------------------------
37   spawn, '\grep -i "^FILEHEADER" '+filename, fileheader
38   fileheader = strtrim(fileheader, 2)
39   if keyword_set(fileheader) then BEGIN
40      fileheader = strsplit(fileheader[0],/extract)
41      fileheader = long(fileheader[1])
42   ENDIF ELSE fileheader = 0L
43   spawn, '\grep -i "^THEADER" '+filename, theader
44   theader = strtrim(theader, 2)
45   if keyword_set(theader) then BEGIN
46      theader = strsplit(theader[0],/extract)
47      theader = long(theader[1])
48   ENDIF ELSE theader = 0L
49   spawn, '\grep -i "^XYHEADER" '+filename, xyheader
50   xyheader = strtrim(xyheader, 2)
51   if keyword_set(xyheader) then BEGIN
52      xyheader = strsplit(xyheader[0],/extract)
53      xyheader = long(xyheader[1])
54   ENDIF ELSE xyheader = 0L
55;------------------------
56;------------------------
57; find the x axis
58;------------------------
59;------------------------
60   spawn, '\sed -n -e ''/^#/d'' -e ''/^[Xx][Dd][Ee][Ff]/,/^[Yy][Dd][Ee][Ff]/p'' '+filename, xdef
61   if xdef[0] EQ '' then BEGIN
62      print, 'Bad definition of xdef or ydef'
63      stop
64   ENDIF
65   xdef = xdef[0:n_elements(xdef)-2]
66   if n_elements(xdef) NE 1 then begin
67      xdef = [byte(xdef), replicate(byte(' '),1,n_elements(xdef))]
68      xdef = xdef[where(xdef NE 0)]
69      xdef = string(xdef)
70   endif
71   xdef = strtrim(xdef[0], 2)
72   xdef = strsplit(xdef,/extract)
73   jpi = long(xdef[1])
74   case strupcase(xdef[2]) of
75      'LINEAR':xaxis = float(xdef[3])+findgen(jpi)*float(xdef[4])
76      'LEVELS':xaxis = float(xdef[3:n_elements(xdef)-1])
77   ENDCASE
78;------------------------
79;------------------------
80; find the y axis
81;------------------------
82;------------------------
83   spawn, '\sed -n -e ''/^#/d'' -e ''/^[Yy][Dd][Ee][Ff]/,/^[Zz][Dd][Ee][Ff]/p'' '+filename, ydef
84   if ydef[0] EQ '' then BEGIN
85      print, 'Bad definition of ydef or zdef'
86      stop
87   ENDIF
88   ydef = ydef[0:n_elements(ydef)-2]
89   if n_elements(ydef) NE 1 then begin
90      ydef = [byte(ydef), replicate(byte(' '),1,n_elements(ydef))]
91      ydef = ydef[where(ydef NE 0)]
92      ydef = string(ydef)
93   endif
94   ydef = strtrim(ydef[0], 2)
95   ydef = strsplit(ydef,/extract)
96   jpj = long(ydef[1])
97   case strupcase(ydef[2]) of
98      'LINEAR':yaxis = float(ydef[3])+findgen(jpj)*float(ydef[4])
99      'LEVELS':yaxis = float(ydef[3:n_elements(ydef)-1])
100   'GAUST62':BEGIN & print, 'Not yet coded...' & stop & END
101   'GAUSR15':BEGIN & print, 'Not yet coded...' & stop & END
102   'GAUSR20':BEGIN & print, 'Not yet coded...' & stop & END
103   'GAUSR30':BEGIN & print, 'Not yet coded...' & stop & END
104   'GAUSR40':BEGIN & print, 'Not yet coded...' & stop & END
105   ELSE:BEGIN & print, 'Not yet coded...' & stop & END
106   endcase
107;------------------------
108;------------------------
109; find the z axis
110;------------------------
111;------------------------
112   spawn, '\sed -n -e ''/^#/d'' -e ''/^[Zz][Dd][Ee][Ff]/,/^[Tt][Dd][Ee][Ff]/p'' '+filename, zdef
113   if zdef[0] EQ '' then BEGIN
114      print, 'Bad definition of zdef or tdef'
115      stop
116   ENDIF
117   zdef = zdef[0:n_elements(zdef)-2]
118   if n_elements(zdef) NE 1 then begin
119      zdef = [byte(zdef), replicate(byte(' '),1,n_elements(zdef))]
120      zdef = zdef[where(zdef NE 0)]
121      zdef = string(zdef)
122   endif
123   zdef = strtrim(zdef[0], 2)
124   zdef = strsplit(zdef,/extract)
125   jpk = long(zdef[1])
126   case strupcase(zdef[2]) of
127      'LINEAR':zaxis = float(zdef[3])+findgen(jpk)*float(zdef[4])
128      'LEVELS':zaxis = float(zdef[3:n_elements(zdef)-1])
129   ENDCASE
130;------------------------
131;------------------------
132; compute the grid
133;------------------------
134;------------------------
135   computegrid, xaxis = xaxis, yaxis = yaxis, zaxis = zaxis, _EXTRA = ex
136   domdef
137;------------------------
138;------------------------
139; find the time axis
140;------------------------
141;------------------------
142   spawn, '\grep -i "^TDEF" '+filename, timedef
143   timedef = strupcase(strtrim(timedef, 2))
144   timedef = strsplit(timedef[0],/extract)
145   jpt = long(timedef[1])
146;------------------------
147; initial date: y0, m0, d0, h0, mn0
148;             -> Julian day of IDL: julday(m0, d0, y0, h0, mn0, 00)
149;------------------------
150   t0 = timedef[3]
151   monthsname = string(format='(C(CMOA))',31*(indgen(12)))
152   case 1 OF
153; h[h]:mmZd[d]mmmyy[yy]
154      strpos(t0, ':') NE -1:BEGIN
155         pp = strpos(t0, ':')
156         h0 = long(strmid(t0, 0, pp))
157         mn0 = long(strmid(t0, pp+1, 2))
158         pp = strpos(t0, 'Z')
159         dd = byte(strmid(t0, pp+2, 1)) LT byte('A')
160         d0 = long(strmid(t0, pp+1, 1+dd))
161         m0 = (where(monthsname EQ strmid(t0, pp+2+dd, 3)))[0]+1
162         y0 = long(strmid(t0, pp+5+dd))
163      END
164; m[m]Zd[d]mmmyy[yy]
165      strpos(t0, 'Z') NE -1:BEGIN
166         h0 = 0+12
167         pp = strpos(t0, 'Z')
168         mn0 = long(strmid(t0, 0, pp))
169         dd = byte(strmid(t0, pp+2, 1)) LT byte('A')
170         d0 = long(strmid(t0, pp+1, 1+dd))
171         m0 = (where(monthsname EQ strmid(t0, pp+2+dd, 3)))[0]+1
172         y0 = long(strmid(t0, pp+5+dd))
173      END
174; d[d]mmmyy[yy]
175      (byte(strmid(t0, 0, 1)) LT byte('A'))[0]:BEGIN
176         h0 = 0+12
177         mn0 = 0
178         dd = byte(strmid(t0, 1, 1)) LT byte('A')
179         d0 = long(strmid(t0, 0, 1+dd))
180         m0 = (where(monthsname EQ strmid(t0, 1+dd, 3)))[0]+1
181         y0 = long(strmid(t0, 4+dd))
182      END
183; mmmyy[yy]
184      ELSE:BEGIN
185         h0 = 0+12
186         mn0 = 0
187         d0 = 1
188         m0 = (where(monthsname EQ strmid(t0, 0, 3)))[0]+1
189         y0 = long(strmid(t0, 3))
190      END
191   ENDCASE
192; if y0 is a two digit integer -> between 1950 and 2049
193   case 1 of
194      y0 LE 49:y0 = 2000+y0
195      y0 LE 99:y0 = 1900+y0
196      ELSE:
197   ENDCASE
198;------------------------
199; increment date and definition of the calendar with IDL Julian days
200;------------------------
201   tstep = timedef[4]
202   tsval = long(strmid(tstep,0, strlen(tstep)-2))
203   case strlowcase(strmid(tstep, 1, /reverse)) of
204      'mn':time = julday(m0, d0, y0, h0, mn0+lindgen(jpt)*tsval, 0)
205      'hr':time = julday(m0, d0, y0, h0+lindgen(jpt)*tsval, mn0, 0)
206      'dy':time = julday(m0, d0+lindgen(jpt)*tsval, y0, h0, mn0, 0)
207      'mo':time = julday(m0+lindgen(jpt)*tsval, d0, y0, h0, mn0, 0)
208      'yr':time = julday(m0, d0, y0+lindgen(jpt)*tsval, h0, mn0, 0)
209   ENDCASE                      ;
210; shit the calendar to correspond to the time step.
211   case strlowcase(strmid(tstep, 1, /reverse)) of
212      'dy':time = long(time)
213      'mo':time = long(time)+14L
214      'yr':time = long(time)+365L/2
215      ELSE:
216   endcase
217;------------------------
218; OPTIONS
219;------------------------
220   spawn, '\grep -i "^OPTIONS" '+filename, options
221   options = strtrim(options, 2)
222   options = strlowcase(options[0])
223   key_yreverse = strpos(options, 'yrev') NE -1
224   key_zreverse = strpos(options, 'zrev') EQ -1
225   multifiles = strpos(options, 'template') NE -1
226   f77sequential = strpos(options, 'sequential') NE -1
227   swapbytes = strpos(options, 'byteswapped') NE -1
228   bigendian = strpos(options, 'big_endian') NE -1
229   littleendian = strpos(options, 'little_endian') NE -1
230   cray = strpos(options, 'cray_32bit_ieee') NE -1
231IF cray THEN BEGIN & print, 'cray_32bit_ieee; Not yet coded...' & stop & ENDIF
232   cal365 = strpos(options, '365_day_calendar') NE -1
233IF cal365 THEN BEGIN & print, '365_day_calenda; Not yet coded...' & stop & ENDIF
234;------------------------
235;------------------------
236; building the filesname
237;------------------------
238;------------------------
239   spawn, '\grep -i "^DSET" '+filename, files
240   files = strtrim(files[0], 2)
241   files = strsplit(files,/extract)
242   if n_elements(files) NE 2 then begin
243      print, 'Bad definition of the filename. There should be 2 elements:'
244      print, 'DEST and 1 filename (that may define many files)'
245      stop
246   endif
247   files = files[1]
248;   files = strmid(files[0], strpos(files[0],' ', /reverse_search)+1)
249   filesname = files
250   if keyword_set(multifiles) then begin
251; minutes
252      if (stregex(files,'%i?n2'))[0] NE -1 then begin
253         filetsep = 'mn'
254         mnend = long(mn0+jpt-1)
255         tmp = strarr(hend-h0+1)
256         for i = 0, n_elements(tmp)-1 do tmp[i] = strjoin(strsplit(filesname,'%i?n2',/extract,/regex), string(mn0+i, format = '(i2.2)'))
257         filesname = strjoin(tmp, '!@#$')
258      endif
259; hours
260      if (stregex(files,'%i?[hf][123]'))[0] NE -1 then begin
261         filetsep = 'hr'
262         case strlowcase(strmid(tstep, 1, /reverse)) of
263            'mn':hend = long(h0+(jpt+mn0-1-1)/60.)
264            'hr':hend = long(h0+jpt-1)
265         endcase
266         tmp = strarr(hend-h0+1)
267         case 1 of
268            stregex(files,'%i?h1') NE -1:for i = 0, n_elements(tmp)-1 do tmp[i] = strjoin(strsplit(filesname,'%i?h1',/extract,/regex), strtrim(h0+i, 1))
269            stregex(files,'%i?h2') NE -1:for i = 0, n_elements(tmp)-1 do tmp[i] = strjoin(strsplit(filesname,'%i?h2',/extract,/regex), string(h0+i, format = '(i2.2)'))
270            stregex(files,'%f2') NE -1:for i = 0, n_elements(tmp)-1 do tmp[i] = strjoin(strsplit(filesname,'%f2',/extract,/regex), string(h0+i, format = '(i3.2)'))
271            stregex(files,'%i?[hf]3') NE -1:for i = 0, n_elements(tmp)-1 do tmp[i] = strjoin(strsplit(filesname,'%i?[hf]3',/extract,/regex), string(h0+i, format = '(i3.3)'))
272         endcase
273         filesname = strjoin(tmp, '!@#$')
274      endif
275; days
276      if (stregex(files,'%i?d[12]'))[0] NE -1 then begin
277         filetsep = 'dy'
278         case strlowcase(strmid(tstep, 1, /reverse)) of
279            'mn':dend = long(d0+(jpt+mn0-1-1)/1440.)
280            'hr':dend = long(d0+(jpt+h0-1-1)/24.)
281            'dy':dend = long(d0+jpt-1)
282         endcase
283         tmp = strarr(dend-d0+1)
284         case 1 of
285            stregex(files,'%i?d1') NE -1:for i = 0, n_elements(tmp)-1 do tmp[i] = strjoin(strsplit(filesname,'%i?d1',/extract,/regex), strtrim(d0+i, 1))
286            stregex(files,'%i?d2') NE -1:for i = 0, n_elements(tmp)-1 do tmp[i] = strjoin(strsplit(filesname,'%i?d2',/extract,/regex), string(d0+i, format = '(i2.2)'))
287         endcase
288         filesname = strjoin(tmp, '!@#$')
289      endif
290; months
291      if (stregex(files,'%i?m[12c]'))[0] NE -1 then begin
292         filetsep = 'mo'
293         tmp = strarr(12)
294         case 1 of
295            stregex(files,'%i?m1') NE -1:for i = 1, 12 do tmp[i-1] = strjoin(strsplit(filesname,'%i?m1',/extract,/regex), strtrim(i, 1))
296            stregex(files,'%i?m2') NE -1:for i = 1, 12 do tmp[i-1] = strjoin(strsplit(filesname,'%i?m2',/extract,/regex), string(i, format = '(i2.2)'))
297            stregex(files,'%i?mc') NE -1:for i = 1, 12 do tmp[i-1] = strjoin(strsplit(filesname,'%i?mc',/extract,/regex), monthsname[i-1])
298         endcase
299         filesname = strjoin(tmp, '!@#$')
300      endif
301; years
302      if (stregex(files,'%i?y[24]'))[0] NE -1 then begin
303         case strlowcase(strmid(tstep, 1, /reverse)) of
304            'dy':yend = long(y0+(jpt+d0-1-1)/365.)
305            'mo':yend = long(y0+(jpt+m0-1-1)/12.)
306            'yr':yend = long(y0+jpt-1)
307            ELSE:yend = y0
308         endcase
309         tmp = strarr(yend-y0+1)
310         case 1 of
311            stregex(files,'%i?y2') NE -1:for i = 0, n_elements(tmp)-1 do tmp[i] = strjoin(strsplit(filesname,'%i?y2',/extract,/regex), string((y0+i)-100*((y0+i)/100), format = '(i2.2)'))
312            stregex(files,'%i?y4') NE -1:for i = 0, n_elements(tmp)-1  do tmp[i] = strjoin(strsplit(filesname,'%i?y]4',/extract,/regex), string(y0+i, format = '(i4.4)'))
313         endcase
314         filesname = strjoin(tmp, '!@#$')
315      endif
316      filesname = strsplit(filesname, '!@#$', /extract)
317;
318; time step unit of each file:
319;
320      case 1 of
321         (stregex(files,'%i?n2'))[0] NE -1:filetsep = 'mn'
322         (stregex(files,'%i?[hf][123]'))[0] NE -1:filetsep = 'hr'
323         (stregex(files,'%i?d[12]'))[0] NE -1:filetsep = 'dy'
324         (stregex(files,'%i?m[12c]'))[0] NE -1: filetsep = 'mo'
325         (stregex(files,'%i?y[24]'))[0] NE -1:filetsep = 'yr'
326      ENDCASE
327;
328; number of time steps for each files
329;
330      case strlowcase(strmid(tstep, 1, /reverse)) of
331         'mn':BEGIN
332            case filetsep of
333               'yr':jpt1file = 60L*24L*365L
334               'mo':jpt1file = 60L*24L*30L
335               'dy':jpt1file = 60L*24L
336               'hr':jpt1file = 60L
337               'mn':jpt1file = 1L
338            endcase
339         END
340         'hr':BEGIN
341            case filetsep of
342               'yr':jpt1file = 24L*365L
343               'mo':jpt1file = 24L*30L
344               'dy':jpt1file = 24L
345               'hr':jpt1file = 1L
346            endcase
347         END
348         'dy':BEGIN
349            case filetsep of
350               'yr':jpt1file = 365L
351               'mo':jpt1file = 30L
352               'dy':jpt1file = 1L
353            endcase
354         END
355         'mo':BEGIN
356            case filetsep of
357               'yr':jpt1file = 12L
358               'mo':jpt1file = 1L
359            endcase
360         END
361         'yr':jpt1file = 1L
362      endcase
363;
364; number of files
365;
366      nof = ceil(jpt/(1.*jpt1file))
367      filesname = filesname[0:nof-1]
368   ENDIF ELSE BEGIN
369      nof = 1
370      jpt1file = jpt
371   ENDELSE
372; first character ^
373   if stregex(files,'^\^') GE 0 THEN BEGIN
374      iodir = strmid(filename,0,strpos(filename,'/',/reverse_search)+1)
375      for i = 0, nof-1 do filesname[i] = iodir+strmid(filesname[i], 1)
376   ENDIF
377;------------------------
378;------------------------
379; extracting the variables
380;------------------------
381;------------------------
382   spawn, '\grep -i "^VARS" '+filename, nvars
383   nvars = strtrim(nvars, 2)
384   nvars = strsplit(nvars[0],/extract)
385   nvars = long(nvars[1])
386   spawn, '\sed -n -e ''/^#/d'' -e ''/^[Vv][Aa][Rr][Ss]/,/^[Ee][Nn][Dd][Vv][Aa][Rr][Ss]/p'' '+filename, varlist
387   if n_elements(varlist) LE 2  then begin
388      print, 'No lines between vars and endvars???'
389      stop
390   endif
391   varlist = varlist[1:n_elements(varlist)-2]
392   if n_elements(varlist) NE nvars  then begin
393      print, 'Number of variables indicated by VARS ('+strtrim(nvars, 1)+') differs from number of lines (without ''#'' at the beginning) located between VARS and ENDVARS: '+strtrim(n_elements(varlist), 1)
394      stop
395   ENDIF
396   varsname = strarr(nvars)
397   varsdes = strarr(nvars)
398   varslev = lonarr(nvars)
399   for i = 0, nvars-1 do BEGIN
400      varlist[i] = strtrim(varlist[i], 2)
401      tmp = strsplit(varlist[i],/extract)
402      if strmid(tmp[2], 0, 2) EQ '-1' then BEGIN
403         case long(strmid(tmp[2], 3, 2)) of
404            10:BEGIN
405               print, 'Special data formats, units = -1,10... Not yet coded...'
406               stop
407            END
408            20:BEGIN
409               print, 'Special data formats, units = -1,20... Not yet coded...'
410               stop
411            END
412            30:BEGIN
413               print, 'Special data formats, units = -1,30... Not yet coded...'
414               stop
415            END
416            40:BEGIN
417               case long(strmid(tmp[2], 6)) of
418                  1:varfmt = 'byte'
419                  2:varfmt = 'uint'
420                  -2:varfmt = 'int'
421                  4:varfmt = 'long'
422                  ELSE:BEGIN
423                     print, 'Bad definition of the special data formats: '
424                     print,long(strmid(tmp[2],6))+' should be equal to 1, 2, -2 or 4'
425                     stop
426                  END
427               endcase
428            END
429            ELSE:BEGIN
430               print, 'Special data formats, units = -1, ... Not yet coded...'
431               stop
432            END
433         endcase
434      endif
435      varsname[i] = tmp[0]
436      varsdes[i] = strjoin(tmp[3:n_elements(tmp)-1], ' ')
437      varslev[i] = long(tmp[1])
438   ENDFOR
439   varslev = 1 > varslev
440
441;
442   ccmeshparameters.filename = filename
443   ccmeshparameters.filename = 'Grads'
444;
445   IF keyword_set(key_performance) EQ 1 THEN print, 'time scanctl', systime(1)-time1
446
447   return
448end
449;
450;
451
Note: See TracBrowser for help on using the repository browser.