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

Last change on this file since 107 was 106, checked in by pinsard, 18 years ago

start to modify headers of ReadWrite? *.pro files for better idldoc output

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