source: trunk/SRC/ToBeReviewed/WIDGET/AUTOUR_de_XXX/scanfile.pro @ 367

Last change on this file since 367 was 327, checked in by pinsard, 16 years ago

modification of headers : mainly blanks around = sign for keywords in declaration of function and pro

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 6.5 KB
Line 
1;+
2;
3; @file_comments
4;
5; @categories
6;
7; @param NAMEFILE
8;
9; @keyword GRID {default='T'}{type=scalar string}
10; Used to specify on which grid type are located the data
11;
12; @keyword _EXTRA
13; Used to pass keywords to <pro>isafile</pro>,
14; <pro>ncdf_getaxis</pro> and <pro>ncdf_gettime</pro>
15;
16; @returns
17;
18; @uses
19;
20; @restrictions
21;
22; @examples
23;
24; @history
25;
26; @version
27; $Id$
28;
29; @todo
30; seb : I don't know what to do with that...
31;
32;-
33FUNCTION scanfile, namefile, GRID=GRID, _EXTRA=ex
34;
35;  liste des presupposes:
36;       1) le fichier a lire est un fichier netcdf
37;       2) le nom de ce fichier finit
38;       par U.nc, V.nc, W.nc, T.nc ou F.nc, la lettre avant le
39;       nc designant la grille a laquelle se rapporte la champ.
40;       Si tel n''est pas la cas, le fichier est attribue a la grille
41;       T.
42;       3) ce fichier contient une dimension infinie qui doit etre
43;       celle qui se rapporte au temps et au mois 2 autres dimensions
44;       dont les noms sont 'x','lon...','xi_...' et 'y','lat...' ou
45;       'eta_...' ou bien en majuscule.
46;       4) il doit exister ds ce fichier une unique variable n''ayant
47;       qu''une dimension et etant la dimension temporelle. cette
48;       variable sera prise comme axe des temps. Rq: si plusieurs
49;       variables verifient ces criteres on considere la premiere
50;       variable
51;       5) Cette variable axe des temps doit contenir l''attribut
52;       'units' qui doit etre ecrit suivant la syntaxe:
53;               "seconds since 0001-01-01 00:00:00"
54;               "hours since 0001-01-01 00:00:00"
55;               "days since 1979-01-01 00:59:59"
56;               "months since 1979-01-01 00:59:59"
57;               "years since 1979-01-01 00:59:59"
58;
59; je crois que c''est tout!
60;
61;        GRID='[UTVWF]' to specify the type of grid. Defaut is (1)
62;        based on the name of the file if the file ends by
63;        GRID[._][TUVFW].NC (not case sensible) or (2) T if case (1)
64;        is not found.
65;
66;
67  compile_opt idl2, strictarrsubs
68;
69@common
70;------------------------------------------------------------
71; filename
72;------------------------------------------------------------
73  fullname = isafile(filename = namefile, IODIRECTORY = iodir, _extra = ex)
74  IF size(fullname, /type) NE 7 THEN return, -1
75;------------------------------------------------------------
76; open file
77;------------------------------------------------------------
78  cdfid = ncdf_open(fullname)
79;------------------------------------------------------------
80; What contains the file?
81;------------------------------------------------------------
82  inq = ncdf_inquire(cdfid)  ;
83;------------------------------------------------------------
84; name of all dimensions
85;------------------------------------------------------------
86  namedim = strarr(inq.ndims)
87  for dimiq = 0, inq.ndims-1 do begin
88    ncdf_diminq, cdfid, dimiq, tmpname, value
89    namedim[dimiq] = strlowcase(tmpname)
90  ENDFOR
91;------------------------------------------------------------
92; x/y dimensions id
93;------------------------------------------------------------
94  ncdf_getaxis, cdfid, dimidx, dimidy, _extra = ex
95;------------------------------------------------------------
96; name of all variables
97;------------------------------------------------------------
98; we keep only the variables containing at least x, y and time dimension (if existing...)
99  namevar = strarr(inq.nvars)
100  for varid = 0, inq.nvars-1 do begin
101    varinq = ncdf_varinq(cdfid, varid) ; what contains the variable?
102    if (inter(varinq.dim, dimidx))[0] NE -1 AND $
103       (inter(varinq.dim, dimidy))[0] NE -1 AND $
104       ((where(varinq.dim EQ inq.recdim))[0] NE -1 OR inq.recdim EQ -1) $
105    THEN namevar[varid] = varinq.name
106  ENDFOR
107  namevar = namevar[where(namevar NE '')]
108;------------------------------------------------------------
109; find vargrid for each selected variable...
110;------------------------------------------------------------
111  listgrid = strarr(n_elements(namevar))
112; default definitions
113  IF keyword_set(grid) THEN vargrid = strupcase(grid) ELSE vargrid = 'T'
114; look for values of vargrid for each variable
115  IF finite(glamu[0]) EQ 1 AND NOT keyword_set(grid) THEN BEGIN
116; for each variable, look if we in one of the case corresponding to ROMS conventions?
117    FOR i = 0, n_elements(namevar)-1 do begin
118      varinq = ncdf_varinq(cdfid, namevar[i])
119      tmpnm = namedim[varinq.dim]
120; are we in one of the case corresponding to ROMS conventions?
121      CASE 1 OF
122        tmpnm[2 < (varinq.ndims-1)] EQ 's_w':vargrid = 'W'
123        tmpnm[0] EQ 'xi_rho' AND tmpnm[1] EQ 'eta_rho':listgrid[i] = 'T'
124        tmpnm[0] EQ 'xi_u'   AND tmpnm[1] EQ 'eta_u'  :listgrid[i] = 'U'
125        tmpnm[0] EQ 'xi_v'   AND tmpnm[1] EQ 'eta_v'  :listgrid[i] = 'V'
126        tmpnm[0] EQ 'xi_psi' AND tmpnm[1] EQ 'eta_psi':listgrid[i] = 'F'
127        tmpnm[0] EQ 'xi_rho' AND tmpnm[1] EQ 'eta_v'  :listgrid[i] = 'V'
128        tmpnm[0] EQ 'xi_u'   AND tmpnm[1] EQ 'eta_rho':listgrid[i] = 'U'
129        tmpnm[0] EQ 'xi_u'   AND tmpnm[1] EQ 'eta_v'  :listgrid[i] = 'F'
130        ELSE:
131      ENDCASE
132    ENDFOR
133    empty = where(listgrid EQ '')
134    IF empty[0] NE -1 THEN BEGIN
135; could we define the grid type from the file name??
136      pattern = ['GRID.', 'GRID_', 'GRID', 'UPID_', '30ID_']
137      gdtype = ['T', 'U', 'V', 'W', 'F']
138      fnametest = strupcase(fullname)
139      FOR i = 0, n_elements(pattern)-1 DO BEGIN
140        FOR j = 0, n_elements(gdtype)-1 DO BEGIN
141          substr = pattern[i]+gdtype[j]
142          pos = strpos(fnametest, substr)
143          IF pos NE -1 THEN $
144             vargrid = strmid(fnametest, pos+strlen(substr)-1, 1)
145        ENDFOR
146      ENDFOR
147      listgrid[empty] = vargrid
148    ENDIF
149  ENDIF ELSE listgrid[*] = vargrid
150;------------------------------------------------------------
151; time axis
152;------------------------------------------------------------
153  time = ncdf_gettime(fullname, cdfid, caller = 'scanfile', err = err, _extra = ex)
154  IF n_elements(err) NE 0 THEN BEGIN
155    dummy = report(err)
156    jpt = abs(time)
157    fakecal = 1
158  ENDIF ELSE jpt = n_elements(time)
159; high frequency calendar: more than one element per day
160  IF max(histogram([long(time-time[0])])) GT 1 THEN fakecal = 1 ELSE fakecal = 0
161  date0fk = date2jul(19000101)
162  IF keyword_set(fakecal) THEN time = date0fk+lindgen(1 > jpt)
163;------------------------------------------------------------
164  ncdf_close, cdfid
165;------------------------------------------------------------
166  return, {filename:fullname, time_counter:time, listvar:namevar $
167           , listgrid:strupcase(listgrid), caltype:key_caltype $
168           , fakecal:date0fk*fakecal}
169end
Note: See TracBrowser for help on using the repository browser.