Ignore:
Timestamp:
03/14/07 17:00:19 (17 years ago)
Author:
smasson
Message:

add x/ydimname and cleaning to solve ticket:61

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SRC/ToBeReviewed/WIDGET/AUTOUR_de_XXX/scanfile.pro

    r219 r221  
    99; 
    1010;  
    11 ; @keyword GRID 
    12 ; 
     11; @keyword GRID {default='T'}{type=scalar string} 
     12; Used to specify on which grid type are located the data 
    1313; 
    1414; @keyword _EXTRA 
    15 ; Used to pass your keywords 
     15; Used to pass your keywords to isafile and ncdf_getaxis 
    1616;  
    1717; @returns 
     
    7676@common 
    7777;------------------------------------------------------------ 
    78   res = -1 
    79 ;------------------------------------------------------------ 
    8078; filename 
    8179;------------------------------------------------------------ 
    8280  fullname = isafile(filename = namefile, IODIRECTORY = iodir, _extra = ex) 
     81  IF size(fullname, /type) NE 7 THEN return, -1 
    8382;------------------------------------------------------------ 
    8483; open file 
     
    8887; What contains the file? 
    8988;------------------------------------------------------------ 
    90   infile = ncdf_inquire(cdfid)  ; 
     89  inside = ncdf_inquire(cdfid)  ; 
    9190;------------------------------------------------------------ 
    9291; name of all dimensions 
    9392;------------------------------------------------------------ 
    94   namedim = strarr(infile.ndims) 
    95   for dimiq = 0, infile.ndims-1 do begin 
     93  namedim = strarr(inside.ndims) 
     94  for dimiq = 0, inside.ndims-1 do begin 
    9695    ncdf_diminq, cdfid, dimiq, tmpname, value  
    9796    namedim[dimiq] = strlowcase(tmpname) 
    9897  ENDFOR 
    99 ; roms file? 
    100   dimidx = where(namedim EQ 'xi_rho' OR namedim EQ 'xi_u' OR namedim EQ 'xi_v' OR namedim EQ 'xi_psi') 
    101   IF dimidx[0] EQ -1 THEN BEGIN 
    102 ; we are looking for a x dimension with a name matching one of the following regular expression: 
    103     testname = ['longitude', 'lon', 'x', 'longitude*', 'lon*', 'x*', '*longitude*', '*lon*', '*x*'] 
    104     cnt = -1 
    105     ii = 0 
    106     WHILE cnt NE 1 AND ii LT n_elements(testname) DO BEGIN 
    107       dimidx = where(strmatch(namedim, testname[ii]) EQ 1, cnt) 
    108       ii = ii+1 
    109     ENDWHILE 
    110     CASE cnt OF 
    111       0:begin 
    112         dummy = report(['none of the dimensions name matches one of the following regular expression:' $ 
    113                         , '''longitude'', ''lon'', ''x'', ''longitude*'', ''lon*'', ''x*'', ''*longitude*'', ''*lon*'', ''*x*''' $ 
    114                         , ' => we cannot find the x dimension']) 
    115         stop 
    116       END 
    117       1:dimidx = dimidx[0] 
    118       ELSE:begin 
    119         dummy = report(['several (and not one unique) dimensions name matches the following regular expression:' $ 
    120                         , '''longitude'', ''lon'', ''x'', ''longitude*'', ''lon*'', ''x*'', ''*longitude*'', ''*lon*'', ''*x*''' $ 
    121                         , ' => we cannot find the x dimension']) 
    122         stop 
    123       ENDELSE 
    124     ENDCASE 
    125   ENDIF 
    126 ; roms file? 
    127   dimidy = where(namedim EQ 'eta_rho' OR namedim EQ 'eta_u' OR namedim EQ 'eta_v' OR namedim EQ 'eta_psi') 
    128   IF dimidy[0] EQ -1 THEN BEGIN 
    129 ; we are looking for a y dimension with a name matching one of the following regular expression: 
    130     testname = ['latitude', 'lat', 'y', 'latitude*', 'lat*', 'y*', 'eta_*', '*latitude*', '*lat*', '*y*'] 
    131     cnt = -1 
    132     ii = 0 
    133     WHILE cnt NE 1 AND ii LT n_elements(testname) DO BEGIN 
    134       dimidy = where(strmatch(namedim, testname[ii]) EQ 1, cnt) 
    135       ii = ii+1 
    136     ENDWHILE 
    137     CASE cnt OF 
    138       0:begin 
    139         dummy = report(['none of the dimensions name matches one of the following regular expression:' $ 
    140                         , '''latitude'', ''lat'', ''y'', ''latitude*'', ''lat*'', ''y*'', ''eta_*'', ''*latitude*'', ''*lat*'', ''*y*''' $ 
    141                         , ' => we cannot find the y dimension']) 
    142         stop 
    143       END 
    144       1:dimidy = dimidy[0] 
    145       ELSE:begin 
    146         dummy = report(['several (and not one unique) dimensions name matches the following regular expression:' $ 
    147                         , '''latitude'', ''lat'', ''y'', ''latitude*'', ''lat*'', ''y*'', ''eta_*'', ''*latitude*'', ''*lat*'', ''*y*''' $ 
    148                         , ' => we cannot find the x dimension']) 
    149         stop 
    150       ENDELSE 
    151     ENDCASE 
    152   ENDIF 
     98;------------------------------------------------------------ 
     99; x/y dimensions id 
     100;------------------------------------------------------------ 
     101  ncdf_getaxis, cdfid, dimidx, dimidy, _extra = ex 
    153102;------------------------------------------------------------ 
    154103; name of all variables 
    155104;------------------------------------------------------------ 
    156105; we keep only the variables containing at least x, y and time dimension (if existing...) 
    157   namevar = strarr(infile.nvars) 
    158   for varid = 0, infile.nvars-1 do begin 
     106  namevar = strarr(inside.nvars) 
     107  for varid = 0, inside.nvars-1 do begin 
    159108    invar = ncdf_varinq(cdfid, varid) ; what contains the variable? 
    160109    if (inter(invar.dim, dimidx))[0] NE -1 AND $ 
    161110       (inter(invar.dim, dimidy))[0] NE -1 AND $ 
    162        ((where(invar.dim EQ infile.recdim))[0] NE -1 OR infile.recdim EQ -1) $ 
     111       ((where(invar.dim EQ inside.recdim))[0] NE -1 OR inside.recdim EQ -1) $ 
    163112    THEN namevar[varid] = invar.name  
    164113  ENDFOR 
     
    210159;------------------------------------------------------------ 
    211160  date0fk = date2jul(19000101) 
    212   IF infile.recdim EQ -1 THEN BEGIN  
     161  IF inside.recdim EQ -1 THEN BEGIN  
    213162    jpt = 1 
    214163    time = date0fk 
    215164    fakecal = 1 
    216165  ENDIF ELSE BEGIN 
    217     ncdf_diminq, cdfid, infile.recdim, timedimname, jpt 
     166    ncdf_diminq, cdfid, inside.recdim, timedimname, jpt 
    218167; we look for the variable containing the time axis 
    219 ; we look for the first variable having for only dimension infile.recdim 
     168; we look for the first variable having for only dimension inside.recdim 
    220169    varid = 0 
    221170    repeat BEGIN 
    222       IF varid LT infile.nvars THEN BEGIN 
     171      IF varid LT inside.nvars THEN BEGIN 
    223172        invar = ncdf_varinq(cdfid, varid)  
    224173        varid = varid+1         
    225174      ENDIF ELSE varid = 0 
    226     endrep until (n_elements(invar.dim) EQ 1 AND invar.dim[0] EQ infile.recdim) OR (varid EQ 0) 
     175    endrep until (n_elements(invar.dim) EQ 1 AND invar.dim[0] EQ inside.recdim) OR (varid EQ 0) 
    227176    varid = varid-1 
    228177; 
Note: See TracChangeset for help on using the changeset viewer.