;+ ; ; @file_comments ; GLAMBOUNDARY 2 elements vector, [lon1,lon2], the longitude ; boundaries that should be used to visualize the data. ; lon2 > lon1 ; lon2 - lon1 le 360 ; key_shift will be defined according to GLAMBOUNDARY. ; ; @param filename ; ; @param filesname ; ; @param jpt1file ; ; @param varsname ; ; @param varslev ; ; @param swapbytes ; ; @param bigendian ; ; @param littleendian ; ; @param f77sequential ; ; @param fileheader ; ; @param theader ; ; @param xyheader ; ; @keyword VARFMT ; ; @keyword _EXTRA ; ; @version ; $Id$ ; ;- ; PRO scanctl, filename, filesname, jpt1file, varsname, varslev, swapbytes, bigendian, littleendian, f77sequential, fileheader, theader, xyheader, VARFMT = varfmt, _EXTRA = ex ; compile_opt idl2, strictarrsubs ; @common time1 = systime(1) ; for key_performance ;------------------------ ; DTYPE ;------------------------ spawn, '\grep -i "^DTYPE" '+filename, notgood if keyword_set(notgood) then begin ras = report( 'This program is not adapted to data type station or grib. Sorry...') stop endif ;------------------------ ; UNDEF, define valmask ;------------------------ spawn, '\grep -i "^UNDEF" '+filename, valmask valmask = strtrim(valmask, 2) valmask = strsplit(valmask[0],/extract) valmask = float(valmask[1]) ;------------------------ ; Headers ;------------------------ spawn, '\grep -i "^FILEHEADER" '+filename, fileheader fileheader = strtrim(fileheader, 2) if keyword_set(fileheader) then BEGIN fileheader = strsplit(fileheader[0],/extract) fileheader = long(fileheader[1]) ENDIF ELSE fileheader = 0L spawn, '\grep -i "^THEADER" '+filename, theader theader = strtrim(theader, 2) if keyword_set(theader) then BEGIN theader = strsplit(theader[0],/extract) theader = long(theader[1]) ENDIF ELSE theader = 0L spawn, '\grep -i "^XYHEADER" '+filename, xyheader xyheader = strtrim(xyheader, 2) if keyword_set(xyheader) then BEGIN xyheader = strsplit(xyheader[0],/extract) xyheader = long(xyheader[1]) ENDIF ELSE xyheader = 0L ;------------------------ ;------------------------ ; find the x axis ;------------------------ ;------------------------ spawn, '\sed -n -e ''/^#/d'' -e ''/^[Xx][Dd][Ee][Ff]/,/^[Yy][Dd][Ee][Ff]/p'' '+filename, xdef if xdef[0] EQ '' then BEGIN ras = report('Bad definition of xdef or ydef') stop ENDIF xdef = xdef[0:n_elements(xdef)-2] if n_elements(xdef) NE 1 then begin xdef = [byte(xdef), replicate(byte(' '),1,n_elements(xdef))] xdef = xdef[where(xdef NE 0)] xdef = string(xdef) endif xdef = strtrim(xdef[0], 2) xdef = strsplit(xdef,/extract) jpi = long(xdef[1]) case strupcase(xdef[2]) of 'LINEAR':xaxis = float(xdef[3])+findgen(jpi)*float(xdef[4]) 'LEVELS':xaxis = float(xdef[3:n_elements(xdef)-1]) ENDCASE ;------------------------ ;------------------------ ; find the y axis ;------------------------ ;------------------------ spawn, '\sed -n -e ''/^#/d'' -e ''/^[Yy][Dd][Ee][Ff]/,/^[Zz][Dd][Ee][Ff]/p'' '+filename, ydef if ydef[0] EQ '' then BEGIN ras = report('Bad definition of ydef or zdef') stop ENDIF ydef = ydef[0:n_elements(ydef)-2] if n_elements(ydef) NE 1 then begin ydef = [byte(ydef), replicate(byte(' '),1,n_elements(ydef))] ydef = ydef[where(ydef NE 0)] ydef = string(ydef) endif ydef = strtrim(ydef[0], 2) ydef = strsplit(ydef,/extract) jpj = long(ydef[1]) case strupcase(ydef[2]) of 'LINEAR':yaxis = float(ydef[3])+findgen(jpj)*float(ydef[4]) 'LEVELS':yaxis = float(ydef[3:n_elements(ydef)-1]) 'GAUST62':BEGIN & ras = report( 'Not yet coded...') & stop & END 'GAUSR15':BEGIN & ras = report( 'Not yet coded...') & stop & END 'GAUSR20':BEGIN & ras = report( 'Not yet coded...') & stop & END 'GAUSR30':BEGIN & ras = report( 'Not yet coded...') & stop & END 'GAUSR40':BEGIN & ras = report( 'Not yet coded...') & stop & END ELSE:BEGIN & ras = report( 'Not yet coded...') & stop & END endcase ;------------------------ ;------------------------ ; find the z axis ;------------------------ ;------------------------ spawn, '\sed -n -e ''/^#/d'' -e ''/^[Zz][Dd][Ee][Ff]/,/^[Tt][Dd][Ee][Ff]/p'' '+filename, zdef if zdef[0] EQ '' then BEGIN ras = report( 'Bad definition of zdef or tdef') stop ENDIF zdef = zdef[0:n_elements(zdef)-2] if n_elements(zdef) NE 1 then begin zdef = [byte(zdef), replicate(byte(' '),1,n_elements(zdef))] zdef = zdef[where(zdef NE 0)] zdef = string(zdef) endif zdef = strtrim(zdef[0], 2) zdef = strsplit(zdef,/extract) jpk = long(zdef[1]) case strupcase(zdef[2]) of 'LINEAR':zaxis = float(zdef[3])+findgen(jpk)*float(zdef[4]) 'LEVELS':zaxis = float(zdef[3:n_elements(zdef)-1]) ENDCASE ;------------------------ ;------------------------ ; compute the grid ;------------------------ ;------------------------ computegrid, xaxis = xaxis, yaxis = yaxis, zaxis = zaxis, _EXTRA = ex domdef ;------------------------ ;------------------------ ; find the time axis ;------------------------ ;------------------------ spawn, '\grep -i "^TDEF" '+filename, timedef timedef = strupcase(strtrim(timedef, 2)) timedef = strsplit(timedef[0],/extract) jpt = long(timedef[1]) ;------------------------ ; initial date: y0, m0, d0, h0, mn0 ; -> Julian day of IDL: julday(m0, d0, y0, h0, mn0, 00) ;------------------------ t0 = timedef[3] monthsname = string(format='(C(CMOA))',31*(indgen(12))) case 1 OF ; h[h]:mmZd[d]mmmyy[yy] strpos(t0, ':') NE -1:BEGIN pp = strpos(t0, ':') h0 = long(strmid(t0, 0, pp)) mn0 = long(strmid(t0, pp+1, 2)) pp = strpos(t0, 'Z') dd = byte(strmid(t0, pp+2, 1)) LT byte('A') d0 = long(strmid(t0, pp+1, 1+dd)) m0 = (where(monthsname EQ strmid(t0, pp+2+dd, 3)))[0]+1 y0 = long(strmid(t0, pp+5+dd)) END ; m[m]Zd[d]mmmyy[yy] strpos(t0, 'Z') NE -1:BEGIN h0 = 0+12 pp = strpos(t0, 'Z') mn0 = long(strmid(t0, 0, pp)) dd = byte(strmid(t0, pp+2, 1)) LT byte('A') d0 = long(strmid(t0, pp+1, 1+dd)) m0 = (where(monthsname EQ strmid(t0, pp+2+dd, 3)))[0]+1 y0 = long(strmid(t0, pp+5+dd)) END ; d[d]mmmyy[yy] (byte(strmid(t0, 0, 1)) LT byte('A'))[0]:BEGIN h0 = 0+12 mn0 = 0 dd = byte(strmid(t0, 1, 1)) LT byte('A') d0 = long(strmid(t0, 0, 1+dd)) m0 = (where(monthsname EQ strmid(t0, 1+dd, 3)))[0]+1 y0 = long(strmid(t0, 4+dd)) END ; mmmyy[yy] ELSE:BEGIN h0 = 0+12 mn0 = 0 d0 = 1 m0 = (where(monthsname EQ strmid(t0, 0, 3)))[0]+1 y0 = long(strmid(t0, 3)) END ENDCASE ; if y0 is a two digit integer -> between 1950 and 2049 case 1 of y0 LE 49:y0 = 2000+y0 y0 LE 99:y0 = 1900+y0 ELSE: ENDCASE ;------------------------ ; increment date and definition of the calendar with IDL Julian days ;------------------------ tstep = timedef[4] tsval = long(strmid(tstep,0, strlen(tstep)-2)) case strlowcase(strmid(tstep, 1, /reverse)) of 'mn':time = julday(m0, d0, y0, h0, mn0+lindgen(jpt)*tsval, 0) 'hr':time = julday(m0, d0, y0, h0+lindgen(jpt)*tsval, mn0, 0) 'dy':time = julday(m0, d0+lindgen(jpt)*tsval, y0, h0, mn0, 0) 'mo':time = julday(m0+lindgen(jpt)*tsval, d0, y0, h0, mn0, 0) 'yr':time = julday(m0, d0, y0+lindgen(jpt)*tsval, h0, mn0, 0) ENDCASE ; ; shit the calendar to correspond to the time step. case strlowcase(strmid(tstep, 1, /reverse)) of 'dy':time = long(time) 'mo':time = long(time)+14L 'yr':time = long(time)+365L/2 ELSE: endcase ;------------------------ ; OPTIONS ;------------------------ spawn, '\grep -i "^OPTIONS" '+filename, options options = strtrim(options, 2) options = strlowcase(options[0]) key_yreverse = strpos(options, 'yrev') NE -1 key_zreverse = strpos(options, 'zrev') EQ -1 multifiles = strpos(options, 'template') NE -1 f77sequential = strpos(options, 'sequential') NE -1 swapbytes = strpos(options, 'byteswapped') NE -1 bigendian = strpos(options, 'big_endian') NE -1 littleendian = strpos(options, 'little_endian') NE -1 cray = strpos(options, 'cray_32bit_ieee') NE -1 IF cray THEN BEGIN & ras = report( 'cray_32bit_ieee; Not yet coded...') & stop & ENDIF cal365 = strpos(options, '365_day_calendar') NE -1 IF cal365 THEN BEGIN & ras = report( '365_day_calenda; Not yet coded...') & stop & ENDIF ;------------------------ ;------------------------ ; building the filesname ;------------------------ ;------------------------ spawn, '\grep -i "^DSET" '+filename, files files = strtrim(files[0], 2) files = strsplit(files,/extract) if n_elements(files) NE 2 then begin ras = report(['Bad definition of the filename. There should be 2 elements:', $ 'DEST and 1 filename that may define many files']) stop endif files = files[1] ; files = strmid(files[0], strpos(files[0],' ', /reverse_search)+1) filesname = files if keyword_set(multifiles) then begin ; minutes if (stregex(files,'%i?n2'))[0] NE -1 then begin filetsep = 'mn' mnend = long(mn0+jpt-1) tmp = strarr(hend-h0+1) for i = 0, n_elements(tmp)-1 do tmp[i] = strjoin(strsplit(filesname,'%i?n2',/extract,/regex), string(mn0+i, format = '(i2.2)')) filesname = strjoin(tmp, '!@#$') endif ; hours if (stregex(files,'%i?[hf][123]'))[0] NE -1 then begin filetsep = 'hr' case strlowcase(strmid(tstep, 1, /reverse)) of 'mn':hend = long(h0+(jpt+mn0-1-1)/60.) 'hr':hend = long(h0+jpt-1) endcase tmp = strarr(hend-h0+1) case 1 of 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)) 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)')) 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)')) 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)')) endcase filesname = strjoin(tmp, '!@#$') endif ; days if (stregex(files,'%i?d[12]'))[0] NE -1 then begin filetsep = 'dy' case strlowcase(strmid(tstep, 1, /reverse)) of 'mn':dend = long(d0+(jpt+mn0-1-1)/1440.) 'hr':dend = long(d0+(jpt+h0-1-1)/24.) 'dy':dend = long(d0+jpt-1) endcase tmp = strarr(dend-d0+1) case 1 of 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)) 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)')) endcase filesname = strjoin(tmp, '!@#$') endif ; months if (stregex(files,'%i?m[12c]'))[0] NE -1 then begin filetsep = 'mo' tmp = strarr(12) case 1 of stregex(files,'%i?m1') NE -1:for i = 1, 12 do tmp[i-1] = strjoin(strsplit(filesname,'%i?m1',/extract,/regex), strtrim(i, 1)) 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)')) stregex(files,'%i?mc') NE -1:for i = 1, 12 do tmp[i-1] = strjoin(strsplit(filesname,'%i?mc',/extract,/regex), monthsname[i-1]) endcase filesname = strjoin(tmp, '!@#$') endif ; years if (stregex(files,'%i?y[24]'))[0] NE -1 then begin case strlowcase(strmid(tstep, 1, /reverse)) of 'dy':yend = long(y0+(jpt+d0-1-1)/365.) 'mo':yend = long(y0+(jpt+m0-1-1)/12.) 'yr':yend = long(y0+jpt-1) ELSE:yend = y0 endcase tmp = strarr(yend-y0+1) case 1 of 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)')) 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)')) endcase filesname = strjoin(tmp, '!@#$') endif filesname = strsplit(filesname, '!@#$', /extract) ; ; time step unit of each file: ; case 1 of (stregex(files,'%i?n2'))[0] NE -1:filetsep = 'mn' (stregex(files,'%i?[hf][123]'))[0] NE -1:filetsep = 'hr' (stregex(files,'%i?d[12]'))[0] NE -1:filetsep = 'dy' (stregex(files,'%i?m[12c]'))[0] NE -1: filetsep = 'mo' (stregex(files,'%i?y[24]'))[0] NE -1:filetsep = 'yr' ENDCASE ; ; number of time steps for each files ; case strlowcase(strmid(tstep, 1, /reverse)) of 'mn':BEGIN case filetsep of 'yr':jpt1file = 60L*24L*365L 'mo':jpt1file = 60L*24L*30L 'dy':jpt1file = 60L*24L 'hr':jpt1file = 60L 'mn':jpt1file = 1L endcase END 'hr':BEGIN case filetsep of 'yr':jpt1file = 24L*365L 'mo':jpt1file = 24L*30L 'dy':jpt1file = 24L 'hr':jpt1file = 1L endcase END 'dy':BEGIN case filetsep of 'yr':jpt1file = 365L 'mo':jpt1file = 30L 'dy':jpt1file = 1L endcase END 'mo':BEGIN case filetsep of 'yr':jpt1file = 12L 'mo':jpt1file = 1L endcase END 'yr':jpt1file = 1L endcase ; ; number of files ; nof = ceil(jpt/(1.*jpt1file)) filesname = filesname[0:nof-1] ENDIF ELSE BEGIN nof = 1 jpt1file = jpt ENDELSE ; first character ^ if stregex(files,'^\^') GE 0 THEN BEGIN iodir = strmid(filename,0,strpos(filename,'/',/reverse_search)+1) for i = 0, nof-1 do filesname[i] = iodir+strmid(filesname[i], 1) ENDIF ;------------------------ ;------------------------ ; extracting the variables ;------------------------ ;------------------------ spawn, '\grep -i "^VARS" '+filename, nvars nvars = strtrim(nvars, 2) nvars = strsplit(nvars[0],/extract) nvars = long(nvars[1]) spawn, '\sed -n -e ''/^#/d'' -e ''/^[Vv][Aa][Rr][Ss]/,/^[Ee][Nn][Dd][Vv][Aa][Rr][Ss]/p'' '+filename, varlist if n_elements(varlist) LE 2 then begin ras = report( 'No lines between vars and endvars???') stop endif varlist = varlist[1:n_elements(varlist)-2] if n_elements(varlist) NE nvars then begin ras = report( '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)) stop ENDIF varsname = strarr(nvars) varsdes = strarr(nvars) varslev = lonarr(nvars) for i = 0, nvars-1 do BEGIN varlist[i] = strtrim(varlist[i], 2) tmp = strsplit(varlist[i],/extract) if strmid(tmp[2], 0, 2) EQ '-1' then BEGIN case long(strmid(tmp[2], 3, 2)) of 10:BEGIN ras = report( 'Special data formats, units = -1,10... Not yet coded...') stop END 20:BEGIN ras = report( 'Special data formats, units = -1,20... Not yet coded...') stop END 30:BEGIN ras = report( 'Special data formats, units = -1,30... Not yet coded...') stop END 40:BEGIN case long(strmid(tmp[2], 6)) of 1:varfmt = 'byte' 2:varfmt = 'uint' -2:varfmt = 'int' 4:varfmt = 'long' ELSE:BEGIN ras = report( 'Bad definition of the special data formats: ') ras = report(long(strmid(tmp[2],6))+' should be equal to 1, 2, -2 or 4') stop END endcase END ELSE:BEGIN ras = report( 'Special data formats, units = -1, ... Not yet coded...') stop END endcase endif varsname[i] = tmp[0] varsdes[i] = strjoin(tmp[3:n_elements(tmp)-1], ' ') varslev[i] = long(tmp[1]) ENDFOR varslev = 1 > varslev ; ccmeshparameters.filename = filename ccmeshparameters.filename = 'Grads' ; IF keyword_set(key_performance) EQ 1 THEN print, 'time scanctl', systime(1)-time1 return end