;+ ; ; @file_comments ; ; @categories ; ; @param NAMEFILE ; ; @keyword GRID {default='T'}{type=scalar string} ; Used to specify on which grid type are located the data ; ; @keyword _EXTRA ; Used to pass keywords to isafile, ; ncdf_getaxis and ncdf_gettime ; ; @returns ; ; @uses ; ; @restrictions ; ; @examples ; ; @history ; ; @version ; $Id$ ; ; @todo ; seb : I don't know what to do with that... ; ;- FUNCTION scanfile, namefile, GRID=GRID, _EXTRA=ex ; ; liste des presupposes: ; 1) le fichier a lire est un fichier netcdf ; 2) le nom de ce fichier finit ; par U.nc, V.nc, W.nc, T.nc ou F.nc, la lettre avant le ; nc designant la grille a laquelle se rapporte la champ. ; Si tel n''est pas la cas, le fichier est attribue a la grille ; T. ; 3) ce fichier contient une dimension infinie qui doit etre ; celle qui se rapporte au temps et au mois 2 autres dimensions ; dont les noms sont 'x','lon...','xi_...' et 'y','lat...' ou ; 'eta_...' ou bien en majuscule. ; 4) il doit exister ds ce fichier une unique variable n''ayant ; qu''une dimension et etant la dimension temporelle. cette ; variable sera prise comme axe des temps. Rq: si plusieurs ; variables verifient ces criteres on considere la premiere ; variable ; 5) Cette variable axe des temps doit contenir l''attribut ; 'units' qui doit etre ecrit suivant la syntaxe: ; "seconds since 0001-01-01 00:00:00" ; "hours since 0001-01-01 00:00:00" ; "days since 1979-01-01 00:59:59" ; "months since 1979-01-01 00:59:59" ; "years since 1979-01-01 00:59:59" ; ; je crois que c''est tout! ; ; GRID='[UTVWF]' to specify the type of grid. Defaut is (1) ; based on the name of the file if the file ends by ; GRID[._][TUVFW].NC (not case sensible) or (2) T if case (1) ; is not found. ; ; compile_opt idl2, strictarrsubs ; @common ;------------------------------------------------------------ ; filename ;------------------------------------------------------------ fullname = isafile(filename = namefile, IODIRECTORY = iodir, _extra = ex) IF size(fullname, /type) NE 7 THEN return, -1 ;------------------------------------------------------------ ; open file ;------------------------------------------------------------ cdfid = ncdf_open(fullname) ;------------------------------------------------------------ ; What contains the file? ;------------------------------------------------------------ inq = ncdf_inquire(cdfid) ; ;------------------------------------------------------------ ; name of all dimensions ;------------------------------------------------------------ namedim = strarr(inq.ndims) for dimiq = 0, inq.ndims-1 do begin ncdf_diminq, cdfid, dimiq, tmpname, value namedim[dimiq] = strlowcase(tmpname) ENDFOR ;------------------------------------------------------------ ; x/y dimensions id ;------------------------------------------------------------ ncdf_getaxis, cdfid, dimidx, dimidy, _extra = ex ;------------------------------------------------------------ ; name of all variables ;------------------------------------------------------------ ; we keep only the variables containing at least x, y and time dimension (if existing...) namevar = strarr(inq.nvars) for varid = 0, inq.nvars-1 do begin varinq = ncdf_varinq(cdfid, varid) ; what contains the variable? if (inter(varinq.dim, dimidx))[0] NE -1 AND $ (inter(varinq.dim, dimidy))[0] NE -1 AND $ ((where(varinq.dim EQ inq.recdim))[0] NE -1 OR inq.recdim EQ -1) $ THEN namevar[varid] = varinq.name ENDFOR namevar = namevar[where(namevar NE '')] ;------------------------------------------------------------ ; find vargrid for each selected variable... ;------------------------------------------------------------ listgrid = strarr(n_elements(namevar)) ; default definitions IF keyword_set(grid) THEN vargrid = strupcase(grid) ELSE vargrid = 'T' ; look for values of vargrid for each variable IF finite(glamu[0]) EQ 1 AND NOT keyword_set(grid) THEN BEGIN ; for each variable, look if we in one of the case corresponding to ROMS conventions? FOR i = 0, n_elements(namevar)-1 do begin varinq = ncdf_varinq(cdfid, namevar[i]) tmpnm = namedim[varinq.dim] ; are we in one of the case corresponding to ROMS conventions? CASE 1 OF tmpnm[2 < (varinq.ndims-1)] EQ 's_w':vargrid = 'W' tmpnm[0] EQ 'xi_rho' AND tmpnm[1] EQ 'eta_rho':listgrid[i] = 'T' tmpnm[0] EQ 'xi_u' AND tmpnm[1] EQ 'eta_u' :listgrid[i] = 'U' tmpnm[0] EQ 'xi_v' AND tmpnm[1] EQ 'eta_v' :listgrid[i] = 'V' tmpnm[0] EQ 'xi_psi' AND tmpnm[1] EQ 'eta_psi':listgrid[i] = 'F' tmpnm[0] EQ 'xi_rho' AND tmpnm[1] EQ 'eta_v' :listgrid[i] = 'V' tmpnm[0] EQ 'xi_u' AND tmpnm[1] EQ 'eta_rho':listgrid[i] = 'U' tmpnm[0] EQ 'xi_u' AND tmpnm[1] EQ 'eta_v' :listgrid[i] = 'F' ELSE: ENDCASE ENDFOR empty = where(listgrid EQ '') IF empty[0] NE -1 THEN BEGIN ; could we define the grid type from the file name?? pattern = ['GRID.', 'GRID_', 'GRID', 'UPID_', '30ID_'] gdtype = ['T', 'U', 'V', 'W', 'F'] fnametest = strupcase(fullname) FOR i = 0, n_elements(pattern)-1 DO BEGIN FOR j = 0, n_elements(gdtype)-1 DO BEGIN substr = pattern[i]+gdtype[j] pos = strpos(fnametest, substr) IF pos NE -1 THEN $ vargrid = strmid(fnametest, pos+strlen(substr)-1, 1) ENDFOR ENDFOR listgrid[empty] = vargrid ENDIF ENDIF ELSE listgrid[*] = vargrid ;------------------------------------------------------------ ; time axis ;------------------------------------------------------------ time = ncdf_gettime(fullname, cdfid, caller = 'scanfile', err = err, _extra = ex) IF n_elements(err) NE 0 THEN BEGIN dummy = report(err) jpt = abs(time) fakecal = 1 ENDIF ELSE jpt = n_elements(time) ; high frequency calendar: more than one element per day IF max(histogram([long(time-time[0])])) GT 1 THEN fakecal = 1 ELSE fakecal = 0 date0fk = date2jul(19000101) IF keyword_set(fakecal) THEN time = date0fk+lindgen(1 > jpt) ;------------------------------------------------------------ ncdf_close, cdfid ;------------------------------------------------------------ return, {filename:fullname, time_counter:time, listvar:namevar $ , listgrid:strupcase(listgrid), caltype:key_caltype $ , fakecal:date0fk*fakecal} end