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