1 | ; |
---|
2 | ; liste des presupposes: |
---|
3 | ; 1) le fichier a lire est un fichier netcdf |
---|
4 | ; 2) le nom de ce fichier finit |
---|
5 | ; par U.nc, V.nc, W.nc, T.nc ou F.nc, la lettre avant le |
---|
6 | ; nc designant la grille a laquelle se rapporte la champ. |
---|
7 | ; Si tel n''est pas la cas, le fichier est attribue a la grille |
---|
8 | ; T. |
---|
9 | ; 3) ce fichier contient une dimension infinie qui doit etre |
---|
10 | ; celle qui se rapporte au temps et au mois 2 autres dimensions |
---|
11 | ; dont les noms sont 'x','lon','longitude' et 'y','lat' ou |
---|
12 | ; 'latitude' ou bien en majuscule. |
---|
13 | ; 4) il doit exiter ds ce fichier une unique variable n''ayant |
---|
14 | ; qu''une dimension et etant la dimension temporelle. cette |
---|
15 | ; variable sera prise comme axe des temps. Rq: si plusieurs |
---|
16 | ; variables verifient ces criteres on considere la premiere |
---|
17 | ; variable |
---|
18 | ; 5) Cette variable axe des temps doit contenir l''attribut |
---|
19 | ; 'units'qui doit etre ecrit suivant la syntaxe: |
---|
20 | ; "seconds since 0001-01-01 00:00:00" |
---|
21 | ; "hours since 0001-01-01 00:00:00" |
---|
22 | ; "days since 1979-01-01 00:59:59" |
---|
23 | ; "months since 1979-01-01 00:59:59" |
---|
24 | ; "years since 1979-01-01 00:59:59" |
---|
25 | ; |
---|
26 | ; je crois que c''est tout! |
---|
27 | ; |
---|
28 | ; |
---|
29 | ;------------------------------------------------------------ |
---|
30 | FUNCTION scanfile, nomficher, IODIRECTORY = iodirectory |
---|
31 | @common |
---|
32 | ;------------------------------------------------------------ |
---|
33 | ; bidouille pour utiliser les mots cles (on passe par des variables |
---|
34 | ; declarees ds un common) |
---|
35 | ;------------------------------------------------------------ |
---|
36 | res = -1 |
---|
37 | ;------------------------------------------------------------ |
---|
38 | ; choix du nom du fichier |
---|
39 | ;------------------------------------------------------------ |
---|
40 | if NOT keyword_set(iodirectory) then iodirectory = iodir |
---|
41 | nom = isafile(filename = nomficher, IODIRECTORY = iodirectory) |
---|
42 | ;------------------------------------------------------------ |
---|
43 | ; ouverture du fichier nom |
---|
44 | ;------------------------------------------------------------ |
---|
45 | cdfid=ncdf_open(nom) |
---|
46 | ;------------------------------------------------------------ |
---|
47 | ; que contient le fichier?? |
---|
48 | ;------------------------------------------------------------ |
---|
49 | contient=ncdf_inquire(cdfid) |
---|
50 | vargrid = strupcase(strmid(nom, strlen(nom)-9)) |
---|
51 | if vargrid EQ 'GRID.T.NC' OR vargrid EQ 'GRID.U.NC' $ |
---|
52 | OR vargrid EQ 'GRID.V.NC' OR vargrid EQ 'GRID.F.NC' $ |
---|
53 | OR vargrid eq 'GRID.W.NC' $ |
---|
54 | OR vargrid EQ 'GRID_T.NC' OR vargrid EQ 'GRID_U.NC' $ |
---|
55 | OR vargrid EQ 'GRID_V.NC' OR vargrid EQ 'GRID_F.NC' $ |
---|
56 | OR vargrid eq 'GRID_W.NC' then $ |
---|
57 | vargrid = strupcase(strmid(nom, strlen(nom)-4, 1)) ELSE vargrid='T' |
---|
58 | ;------------------------------------------------------------ |
---|
59 | ; nom des differentes variables |
---|
60 | ;------------------------------------------------------------ |
---|
61 | ; on ne garde les noms de variable uniquement si cette variable |
---|
62 | ; contient au moins les dimensions qui doivent etre appelles x et y |
---|
63 | ; et la dimension infinie |
---|
64 | nomdim =strarr(contient.ndims) |
---|
65 | for dimiq=0,contient.ndims-1 do begin |
---|
66 | ncdf_diminq,cdfid,dimiq,name,value ; nom et valeur de la dimension |
---|
67 | nomdim[dimiq]=strlowcase(name) |
---|
68 | ENDFOR |
---|
69 | indexdimx = where(nomdim EQ 'x' OR nomdim EQ 'lon' OR nomdim EQ 'longitude') |
---|
70 | indexdimx = indexdimx[0] |
---|
71 | if indexdimx EQ -1 then begin |
---|
72 | print, 'one of the dimensions must have the name: ''x'' or ''lon'' or ''longitude''' |
---|
73 | stop |
---|
74 | endif |
---|
75 | indexdimy = where(nomdim EQ 'y' OR nomdim EQ 'lat' OR nomdim EQ 'latitude') |
---|
76 | indexdimy = indexdimy[0] |
---|
77 | if indexdimy EQ -1 then begin |
---|
78 | print, 'one of the dimensions must have the name: ''y'' or ''lat'' or ''latitude''' |
---|
79 | stop |
---|
80 | endif |
---|
81 | ; |
---|
82 | namevar = strarr(contient.nvars) |
---|
83 | for varid=0,contient.nvars-1 do begin |
---|
84 | varcontient=ncdf_varinq(cdfid,varid) ; que contient la variable |
---|
85 | if (where(varcontient.dim EQ indexdimx))[0] NE -1 AND $ |
---|
86 | (where(varcontient.dim EQ indexdimy))[0] NE -1 AND $ |
---|
87 | (where(varcontient.dim EQ contient.recdim))[0] NE -1 THEN namevar[varid]=varcontient.name |
---|
88 | ENDFOR |
---|
89 | namevar = namevar[where(namevar NE '')] |
---|
90 | listgrid = replicate(vargrid, n_elements(namevar)) |
---|
91 | ;------------------------------------------------------------ |
---|
92 | ; on recupere l''axe des temps |
---|
93 | ;------------------------------------------------------------ |
---|
94 | ; on recupere le nom de la variable contenant l''axe des temps |
---|
95 | varid = 0 |
---|
96 | repeat BEGIN ; tant que l''on a pas trouve une variable qui n''a qu'' |
---|
97 | ; une dimension: la dimension infinie |
---|
98 | varcontient=ncdf_varinq(cdfid,varid) ; que contient la variable |
---|
99 | varid = varid+1 |
---|
100 | endrep until n_elements(varcontient.dim) EQ 1 AND varcontient.dim[0] EQ contient.recdim |
---|
101 | ; on lit l''axe des temps |
---|
102 | varid = varid-1 |
---|
103 | ncdf_varget, cdfid, varid, time |
---|
104 | time = long(time) |
---|
105 | ncdf_attget,cdfid,varid,'units',value |
---|
106 | ; time_counter:units = "seconds since 0001-01-01 00:00:00" ; |
---|
107 | ; time_counter:units = "hours since 0001-01-01 00:00:00" ; |
---|
108 | ; time_counter:units = "days since 1979-01-01 00:00:00" ; |
---|
109 | ; time_counter:units = "months since 1979-01-01 00:00:00" ; |
---|
110 | ; time_counter:units = "years since 1979-01-01 00:00:00" ; |
---|
111 | value = strtrim(strcompress(string(value)), 2) |
---|
112 | mots = str_sep(value, ' ') |
---|
113 | unite = mots[0] |
---|
114 | debut = str_sep(mots[2], '-') |
---|
115 | ; |
---|
116 | ; |
---|
117 | ; ATTENTION il faut recuperer l''atribut calendar et ajuster time en |
---|
118 | ; consequense... |
---|
119 | ; |
---|
120 | ; |
---|
121 | ; on passe time en jour julien d''idl |
---|
122 | ; on suppose qu''on utilise le vrai calendrier. |
---|
123 | ; |
---|
124 | case strlowcase(unite) of |
---|
125 | 'seconds':time = julday(debut[1], debut[2], debut[0])+time/(long(24)*3600) |
---|
126 | 'hours':time = julday(debut[1], debut[2], debut[0])+time/(long(24)) |
---|
127 | 'days':time = julday(debut[1], debut[2], debut[0])+time |
---|
128 | 'months':BEGIN |
---|
129 | for t = 0, n_elements(time)-1 do begin |
---|
130 | time[t] = julday(debut[1]+time[t], debut[2], debut[0]) |
---|
131 | endfor |
---|
132 | END |
---|
133 | 'years':BEGIN |
---|
134 | for t = 0, n_elements(time)-1 do begin |
---|
135 | time[t] = julday(debut[1], debut[2], debut[0]+time[t]) |
---|
136 | endfor |
---|
137 | END |
---|
138 | ENDCASE |
---|
139 | ;------------------------------------------------------------ |
---|
140 | return, {filename:nom, time_counter:time, listvar:namevar, listgrid:strupcase(listgrid)} |
---|
141 | end |
---|