1 | ; La lecture de ce programme se fait de bas en haut: |
---|
2 | ; 1) xncdf_lec |
---|
3 | ; -->2) xncdf_lec_event |
---|
4 | ; |--> 3) wid_var |
---|
5 | ; --> wid_var_event |
---|
6 | ; |
---|
7 | pro wid_var_event, event |
---|
8 | ; NAME:wid_var_event |
---|
9 | ; |
---|
10 | ; PURPOSE:procedure appele par xmanager qd on appuie sur un bouton du |
---|
11 | ; 2eme widget cree par wid_var |
---|
12 | ; |
---|
13 | ; INPUTS: event, une structure caracterisant le type d''evenement qui |
---|
14 | ; arrive au widget numero1 2 |
---|
15 | ; |
---|
16 | ; COMMON BLOCKS:wididbase,resultat,infovariable,indicewid,motcle |
---|
17 | ;------------------------------------------------------------ |
---|
18 | ;------------------------------------------------------------ |
---|
19 | ;------------------------------------------------------------ |
---|
20 | ; |
---|
21 | compile_opt idl2, strictarrsubs |
---|
22 | ; |
---|
23 | COMMON wididbase, base |
---|
24 | COMMON resultat, res |
---|
25 | COMMON infovariable, cdfid, listename, contient, nomdim, tailledim, varid, varcontient |
---|
26 | COMMON indicewid_var, widbase1, widbase2111, widbase212, widbase213, selectatt |
---|
27 | COMMON motcle, mcatt, mccount, mcoffset, mciodir, mcshift, mcstride, mcvar |
---|
28 | ; |
---|
29 | ; quel est le type d''evenement? |
---|
30 | widget_control, event.id, get_uvalue=uval |
---|
31 | tailledimvar = tailledim[varcontient.dim] |
---|
32 | if n_elements(uval) EQ 0 then return |
---|
33 | ; case sur le type d''evenement |
---|
34 | case uval OF |
---|
35 | 1:BEGIN ; on change des valeurs dans le tableau |
---|
36 | ; on controle que les valeurs mises dans le tableau ne sont pas |
---|
37 | ; completement fausses |
---|
38 | widget_control, widbase1, get_value = table |
---|
39 | ; agument du bon type ? |
---|
40 | ; si le type est mauvais on change automatiquement par des valeurs par |
---|
41 | ; defaut |
---|
42 | if event.x GT (size(table))[1] then return |
---|
43 | if event.y GT (size(table))[2] then return |
---|
44 | if size(table[event.x, event.y], /type) GE 6 $ |
---|
45 | OR size(table[event.x, event.y], /type) EQ 0 then BEGIN |
---|
46 | if event.x EQ 1 then $ |
---|
47 | widget_control, widbase1, use_table_select = [1, event.y,1, event.y] $ |
---|
48 | , set_value = tailledimvar[event.y] $ |
---|
49 | ELSE widget_control, widbase1 $ |
---|
50 | , use_table_select = [event.x, event.y, event.x, event.y], set_value = 0 |
---|
51 | endif |
---|
52 | ; agument avec une valeur nom debile? |
---|
53 | table = fix(table) |
---|
54 | case event.x of |
---|
55 | 0:BEGIN ; on a touche a l''offset: |
---|
56 | if table[0, event.y] LT 0 then BEGIN |
---|
57 | table[0, event.y] = 0 |
---|
58 | widget_control, widbase1, use_table_select = [0, event.y, 0, event.y] $ |
---|
59 | , set_value = 0 |
---|
60 | endif |
---|
61 | ; si il depasse la dim du tableau on le met au max et le cont a 1 |
---|
62 | if table[0, event.y] GT tailledimvar[event.y]/table[3, event.y] then begin |
---|
63 | widget_control, widbase1, use_table_select = [0, event.y,1, event.y] $ |
---|
64 | , set_value = [tailledimvar[event.y]/table[3, event.y], 1] |
---|
65 | ENDIF ELSE BEGIN |
---|
66 | ; si avec le nouvel offset le count est trop grand, on le diminue juste |
---|
67 | ; de ce qu''il faut! |
---|
68 | if table[1, event.y] GT $ |
---|
69 | (tailledimvar[event.y]/table[3, event.y])-table[0, event.y] then begin |
---|
70 | widget_control, widbase1, use_table_select = [1, event.y, 1, event.y] $ |
---|
71 | , set_value = (tailledimvar[event.y]/table[3, event.y])-table[0, event.y] |
---|
72 | endif |
---|
73 | ENDELSE |
---|
74 | END |
---|
75 | 1:BEGIN ;on a touche au count |
---|
76 | if table[1, event.y] LT 1 then BEGIN |
---|
77 | table[1, event.y] = 1 |
---|
78 | widget_control, widbase1, use_table_select = [1, event.y, 1, event.y] $ |
---|
79 | , set_value = 1 |
---|
80 | endif |
---|
81 | ; si il est trop grand, on le diminue juste de ce qu''il faut! |
---|
82 | if table[1, event.y] GT $ |
---|
83 | (tailledimvar[event.y]/table[3, event.y])-table[0, event.y] then BEGIN |
---|
84 | widget_control, widbase1, use_table_select = [1, event.y, 1, event.y] $ |
---|
85 | , set_value = (tailledimvar[event.y]/table[3, event.y])-table[0, event.y] |
---|
86 | endif |
---|
87 | END |
---|
88 | 2:BEGIN ; on a touche au shift |
---|
89 | widget_control, widbase1, use_table_select = [2, event.y, 2, event.y] $ |
---|
90 | , set_value = table[2, event.y] MOD (tailledimvar[event.y]/table[3, event.y]) |
---|
91 | END |
---|
92 | 3:BEGIN ; on touche au stride |
---|
93 | if table[3, event.y] LT 1 then BEGIN |
---|
94 | table[3, event.y] = 1 |
---|
95 | widget_control, widbase1, use_table_select = [3, event.y, 3, event.y] $ |
---|
96 | , set_value = 1 |
---|
97 | endif |
---|
98 | if table[3, event.y] EQ 0 then $ ; il ne doit pas etre nul |
---|
99 | widget_control, widbase1, use_table_select = [3, event.y, 3, event.y] $ |
---|
100 | , set_value = 1 |
---|
101 | ; il ne doit pas etre trop grand |
---|
102 | if table[3, event.y] GT tailledimvar[event.y] then $ |
---|
103 | widget_control, widbase1, use_table_select = [0, event.y,3, event.y] $ |
---|
104 | , set_value = [0, 1, 0, tailledimvar[event.y]] $ |
---|
105 | ELSE BEGIN |
---|
106 | if table[1, event.y] GT $ |
---|
107 | (tailledimvar[event.y]/table[3, event.y])-table[0, event.y] then begin |
---|
108 | widget_control, widbase1, use_table_select = [1, event.y, 1, event.y] $ |
---|
109 | , set_value = (tailledimvar[event.y]/table[3, event.y])-table[0, event.y] |
---|
110 | endif |
---|
111 | ENDELSE |
---|
112 | END |
---|
113 | ELSE: |
---|
114 | endcase |
---|
115 | END |
---|
116 | 2111:BEGIN ;on a touche aux boutons oui/non |
---|
117 | ; on actualise le vecteur selectatt a 0 ou 1 pour l''attribut concerne |
---|
118 | ; (numero event.id) |
---|
119 | selectatt[where(widbase2111 EQ event.id)] = event.select |
---|
120 | end |
---|
121 | 31:BEGIN ;on a appuye sur 'get' |
---|
122 | widget_control, widbase1, get_value = table |
---|
123 | table = fix(table) |
---|
124 | mcshift = where(table[2, *] NE 0) |
---|
125 | mcoffset = table[0, *] |
---|
126 | mccount = table[1, *] |
---|
127 | mcstride = table[3, *] |
---|
128 | if mcshift[0] NE -1 then BEGIN ; il y a des shifts |
---|
129 | ; on lit l''integralite des dimensions pour lesquelles il y a un shift |
---|
130 | mcoffset[mcshift] = 0 |
---|
131 | mccount[mcshift] = tailledimvar[mcshift] |
---|
132 | ; on active pas stride qd il n''y en a pas besoin car ca fait ecrire a |
---|
133 | ; l''ecran qqch de louche... |
---|
134 | if total(mcstride) EQ n_elements(mcstride) then $ |
---|
135 | ncdf_varget, cdfid, varid, res, OFFSET = mcoffset, COUNT = mccount $ |
---|
136 | ELSE $ |
---|
137 | ncdf_varget, cdfid, varid, res, OFFSET = mcoffset, COUNT = mccount, STRIDE = mcstride |
---|
138 | ; pour faire le shift |
---|
139 | mcshift = table[2, *] |
---|
140 | mcoffset = table[0, *] |
---|
141 | mccount = table[1, *] |
---|
142 | ; on definit commende qui permet de faire un shift |
---|
143 | commande = 'res=shift(res' |
---|
144 | for dim = 0, varcontient.ndims-1 do commande = commande+','+string(table[2,dim]) |
---|
145 | commande = commande+')' |
---|
146 | rien = execute(commande) |
---|
147 | ; on redefinit commnade qui permet de couper les dimensions qui n''ont |
---|
148 | ; pas ete encore coupees (c''est celles que l''on shift) |
---|
149 | commande = 'res=res[' ; initialisation de la commende |
---|
150 | for dim = 0, varcontient.ndims-1 do BEGIN |
---|
151 | if mcshift[dim] EQ 0 then commande = commande+'*,' $ |
---|
152 | ELSE commande=commande+string(mcoffset[dim])+':'+string(mccount[dim]+mcoffset[dim]-1)+',' |
---|
153 | ENDFOR |
---|
154 | commande = strmid(commande, 0, strlen(commande)-1)+']' |
---|
155 | rien = execute(commande) |
---|
156 | ; cas sans shift, on lit directement le bon bout de tableau |
---|
157 | ENDIF ELSE BEGIN |
---|
158 | if total(mcstride) EQ n_elements(mcstride) then $ |
---|
159 | ncdf_varget, cdfid, varid, res, OFFSET = mcoffset, COUNT = mccount $ |
---|
160 | ELSE $ |
---|
161 | ncdf_varget, cdfid, varid, res, OFFSET = mcoffset, COUNT = mccount, STRIDE = mcstride |
---|
162 | ENDELSE |
---|
163 | ; faut-il constituer une structure avec les attributs qui on ete selectionnes |
---|
164 | if total(selectatt) NE 0 then BEGIN ; il y a des attributs selectionnes |
---|
165 | res = create_struct(varcontient.name, res) ; on cree la structure |
---|
166 | selectatt = where(selectatt EQ 1) ; on trouve les attributs selectiones |
---|
167 | for attid = 0, n_elements(selectatt)-1 do BEGIN ; pour lesquels on prend |
---|
168 | widget_control, widbase212[selectatt[attid]], get_value = attname ; le nom |
---|
169 | widget_control, widbase213[selectatt[attid]], get_value = attvalue ; la valeur |
---|
170 | res = create_struct(res, attname[0], attvalue[0]) ; on concatene la structe |
---|
171 | endfor |
---|
172 | endif |
---|
173 | widget_control, event.top, /destroy ;on ferme le 2eme widget |
---|
174 | widget_control, base, /destroy ;on ferme le 1eme widget |
---|
175 | ncdf_close,cdfid |
---|
176 | END |
---|
177 | 32: ;cas de l''affichage d''un held (avec xdisplayfile) |
---|
178 | 33:widget_control, event.top, /destroy ;on ferme le 2eme widget |
---|
179 | ELSE: |
---|
180 | endcase |
---|
181 | return |
---|
182 | end |
---|
183 | ;------------------------------------------------------------ |
---|
184 | ;------------------------------------------------------------ |
---|
185 | PRO wid_var, widid_pere |
---|
186 | ;------------------------------------------------------------ |
---|
187 | ;------------------------------------------------------------ |
---|
188 | ;------------------------------------------------------------ |
---|
189 | ; NAME: wid_var |
---|
190 | ; |
---|
191 | ; PURPOSE: cette procedure gere le 2eme widget cree qd on appelle |
---|
192 | ; xncdf_lec. ce widget concerne la lecture de la variable |
---|
193 | ; |
---|
194 | ; INPUTS: widid_pere: un scalere contenant l'identite du widget pere |
---|
195 | ; qui a etait cree par xncdf_lec et qui a permis de selectionner la |
---|
196 | ; variable a lire. |
---|
197 | ; |
---|
198 | ; OUTPUTS: indirectement res (le tableau ou la structure resultat) |
---|
199 | ; |
---|
200 | ; COMMON BLOCKS:resultat,infovariable,indicewid_var,motcle |
---|
201 | ; |
---|
202 | ;------------------------------------------------------------ |
---|
203 | ;------------------------------------------------------------ |
---|
204 | ;------------------------------------------------------------ |
---|
205 | ; |
---|
206 | compile_opt idl2, strictarrsubs |
---|
207 | ; |
---|
208 | COMMON resultat, res |
---|
209 | COMMON infovariable, cdfid, listename, contient, nomdim, tailledim, varid, varcontient |
---|
210 | COMMON indicewid_var, widbase1, widbase2111, widbase212, widbase213, selectatt |
---|
211 | COMMON motcle, mcatt, mccount, mcoffset, mciodir, mcshift, mcstride, mcvar |
---|
212 | res = -1 |
---|
213 | ;------------------------------------------------------------ |
---|
214 | ; ouverture de la fenetre de base sous forme de colonnes |
---|
215 | ;------------------------------------------------------------ |
---|
216 | widbase = widget_base(/column, title='variable: '+varcontient.name, /align_center, group_leader = widid_pere) |
---|
217 | ;------------------------------------------------------------ |
---|
218 | ; ouverture de sous-fenetres de base ; |
---|
219 | ;------------------------------------------------------------ |
---|
220 | ; widbase1 tableau des offsets |
---|
221 | ;------------------------------------------------------------ |
---|
222 | rien = widget_label(widbase, value = ' ') ; on saute une ligne |
---|
223 | ; defintion des lables des lignes du tableau |
---|
224 | rowlab = string(tailledim[varcontient.dim]) |
---|
225 | for i = 0, n_elements(rowlab)-1 do rowlab[i] = strtrim(rowlab[i], 1) |
---|
226 | rowlab = nomdim[varcontient.dim]+replicate(': ', n_elements(varcontient.dim))+rowlab |
---|
227 | ; definition des valeurs initiales du tableau |
---|
228 | valinit = lonarr(4, n_elements(varcontient.dim)) |
---|
229 | ; colonne 0 : les offset |
---|
230 | if keyword_set(mcoffset) AND n_elements(mcoffset) EQ varcontient.ndims THEN $ |
---|
231 | valinit[0,*]=mcoffset ELSE valinit[0, *] = 0 |
---|
232 | ; colonne 1 : les counts |
---|
233 | if keyword_set(mccount) AND n_elements(mccount) EQ varcontient.ndims THEN $ |
---|
234 | valinit[1,*]=mccount ELSE valinit[1, *] = tailledim[varcontient.dim] |
---|
235 | ; colonne 2 : les shifts |
---|
236 | if keyword_set(mcshift) AND n_elements(mcshift) EQ varcontient.ndims THEN $ |
---|
237 | valinit[2,*]=mcshift ELSE valinit[2, *] = 0 |
---|
238 | ; colonne 3 : les strides |
---|
239 | if keyword_set(mcstride) AND n_elements(mcstride) EQ varcontient.ndims THEN $ |
---|
240 | valinit[3,*]=mcstride ELSE valinit[3, *] = 1 |
---|
241 | ; test des valeurs initiales du tableau |
---|
242 | valinit = fix(valinit) |
---|
243 | valinit[3, *] = 1 > valinit[3, *] < tailledim[varcontient.dim] ; test des strides |
---|
244 | valinit[0, *] = 0 > valinit[0, *] < tailledim[varcontient.dim] ; test des offsets |
---|
245 | ; test des counts |
---|
246 | valinit[1, *] = 1 > valinit[1, *] < ((tailledim[varcontient.dim]/valinit[3, *])-valinit[0, *]) |
---|
247 | valinit[2, *] = valinit[2, *] MOD (tailledim[varcontient.dim]/valinit[3, *]) ; test des shifts |
---|
248 | ; declaration du tableau |
---|
249 | widbase1 = widget_table(widbase, row_labels = rowlab, value = valinit, /editable $ |
---|
250 | , column_labels = ['Offset', 'Count', 'Shift', 'Stride'], uvalue = 1) |
---|
251 | ; un petit blabla |
---|
252 | rien = widget_label(widbase, value = 'ATTENTION: Faire des ''return'' pour que les valeurs', /align_center) |
---|
253 | rien = widget_label(widbase, value = 'du tableau ou des textes soient bien prises en compte', /align_center) |
---|
254 | ;------------------------------------------------------------ |
---|
255 | ; widbase2 choix des attributs |
---|
256 | ;------------------------------------------------------------ |
---|
257 | rien = widget_label(widbase, value = ' ') ; on saute une ligne |
---|
258 | widbase2 = widget_base(widbase, /column) |
---|
259 | ; pour chaque attribut, on cree un widget (widbase21) qui contient en ligne un |
---|
260 | ; bouton oui/non (widbase211), et deux wigdet text (widbase212, |
---|
261 | ; widbase213)comportant le nom et la valeur de l''attribut. |
---|
262 | widbase21 = lonarr(varcontient.natts) |
---|
263 | widbase211 = lonarr(varcontient.natts) |
---|
264 | widbase2111 = lonarr(varcontient.natts) |
---|
265 | ; vecteur qui serviera a savoir quels boutons oui/non sont |
---|
266 | ; selectiones. cf. wid_var_event |
---|
267 | selectatt = lonarr(varcontient.natts) |
---|
268 | selectatt[*] = 0 |
---|
269 | widbase212 = lonarr(varcontient.natts) |
---|
270 | widbase213 = lonarr(varcontient.natts) |
---|
271 | for attid = 0, varcontient.natts-1 do BEGIN ;boucle sur le nombre d''attributs |
---|
272 | widbase21[attid] = widget_base(widbase2, /row) |
---|
273 | name=ncdf_attname(cdfid,varid,attid) |
---|
274 | ncdf_attget,cdfid,varid,name,value |
---|
275 | widbase211[attid] = widget_base(widbase21[attid], /nonexclusive) |
---|
276 | widbase2111[attid] = widget_button(widbase211[attid], value = ' ', uvalue = 2111) |
---|
277 | widbase212[attid] = widget_text(widbase21[attid], value = name, /editable) |
---|
278 | widbase213[attid] = widget_text(widbase21[attid], value=strtrim(string(value),1), /editable) |
---|
279 | endfor |
---|
280 | ;------------------------------------------------------------ |
---|
281 | ; widbase3 boutons du bas |
---|
282 | ;------------------------------------------------------------ |
---|
283 | widbase3 = widget_base(widbase, /row,/align_center) |
---|
284 | widbase31=widget_button(widbase3,value='GET', uvalue=31) |
---|
285 | widbase32=widget_button(widbase3,value='Help', uvalue=32) |
---|
286 | widbase33=widget_button(widbase3,value='DONE', uvalue=33) |
---|
287 | ;------------------------------------------------------------ |
---|
288 | ;execution de la fentre de base et des sous-fenetres |
---|
289 | ;------------------------------------------------------------ |
---|
290 | widget_control,widbase,/realize |
---|
291 | ;------------------------------------------------------------ |
---|
292 | xmanager,'wid_var',widbase |
---|
293 | return |
---|
294 | end |
---|
295 | ;------------------------------------------------------------ |
---|
296 | |
---|
297 | PRO xncdf_lec_event, event |
---|
298 | ;------------------------------------------------------------ |
---|
299 | ;------------------------------------------------------------ |
---|
300 | ;------------------------------------------------------------ |
---|
301 | ; NAME:xncdf_lec_event |
---|
302 | ; |
---|
303 | ; PURPOSE: procedure appele par xmanager qd on appuie sur un bouton du |
---|
304 | ; 1ere widget cree par xncdf_lec |
---|
305 | ; |
---|
306 | ; INPUTS: event, une structure caracterisant le type d''evenement qui |
---|
307 | ; arrive au widget numero1 |
---|
308 | ; |
---|
309 | ; COMMON BLOCKS:resultat, infovariable, motcle |
---|
310 | ; |
---|
311 | ;------------------------------------------------------------ |
---|
312 | ;------------------------------------------------------------ |
---|
313 | ;------------------------------------------------------------ |
---|
314 | ; |
---|
315 | compile_opt idl2, strictarrsubs |
---|
316 | ; |
---|
317 | COMMON resultat, res |
---|
318 | COMMON infovariable, cdfid, listename, contient, nomdim, tailledim, varid, varcontient |
---|
319 | COMMON motcle, mcatt, mccount, mcoffset, mciodir, mcshift, mcstride, mcvar |
---|
320 | ; quel est le type d''evenement? |
---|
321 | widget_control, event.id, get_uvalue=uval |
---|
322 | ; case sur le type d''evenement |
---|
323 | case uval of |
---|
324 | 1:BEGIN ; on veut lire un autre fichier |
---|
325 | widget_control, event.id, get_value = nom ; on recupere le nom |
---|
326 | widget_control, event.top, /destroy ;on ferme le widget |
---|
327 | ncdf_close,cdfid ; on ferme le mauvais fichier qui a ete ouvert |
---|
328 | ; on reapelle xncdf_lec |
---|
329 | res = xncdf_lec(nom[0], ATT = mcatt, COUNT = mccount, OFFSET = mcoffset, IODIR = mciodir $ |
---|
330 | , SHIFT = mcshift, STRIDE = mcstride, VAR = mcvar) |
---|
331 | return |
---|
332 | END |
---|
333 | 2:BEGIN ; une variable est selectionee |
---|
334 | varid = event.index ; on recupere son numero ds le fichier Netcdf |
---|
335 | varcontient = ncdf_varinq(cdfid,varid) |
---|
336 | wid_var, event.top ; on appelle le programme qui lance le 2eme widget. cf. + haut |
---|
337 | END |
---|
338 | 3:BEGIN ; bouton done |
---|
339 | widget_control, event.top, /destroy ; on tue le widget |
---|
340 | ncdf_close,cdfid ; on ferme le fichier |
---|
341 | END |
---|
342 | ELSE: |
---|
343 | endcase |
---|
344 | return |
---|
345 | end |
---|
346 | ;------------------------------------------------------------ |
---|
347 | ;------------------------------------------------------------ |
---|
348 | ;------------------------------------------------------------ |
---|
349 | ;+ |
---|
350 | ; NAME: xncdf_lec |
---|
351 | ; |
---|
352 | ; PURPOSE: lecture d''un fichier Net Cdf avec des widgets ! |
---|
353 | ; |
---|
354 | ; CATEGORY: lecture de fichiers avec widgets |
---|
355 | ; |
---|
356 | ; CALLING SEQUENCE: res=xncdf_lec([nom_fichier]) |
---|
357 | ; |
---|
358 | ; INPUTS: |
---|
359 | ; OPTIONNEL, nom_fichier: c''est un string qui donne le nom du |
---|
360 | ; fichier a ouvrir.Si nomfichier ne contient pas le caractere |
---|
361 | ; separateur de repertoirte ('/' sous unix par ex), Le fichier |
---|
362 | ; sera cherche ds le repertoire courant |
---|
363 | ; |
---|
364 | ; KEYWORD PARAMETERS: |
---|
365 | ; |
---|
366 | ; IODIR: string contenant le repertoire ou aller chercher le |
---|
367 | ; fichier a lire. Si nomfichier ne contient pas le caractere |
---|
368 | ; separateur de repertoirte ('/' sous unix par ex), Le fichier |
---|
369 | ; cherche s''appelera iodir+nom_fichier. |
---|
370 | ; |
---|
371 | ; COUNT: An optional vector containing the counts to be used in |
---|
372 | ; reading Value. COUNT is a 1-based vector with an element for |
---|
373 | ; each dimension of the data to be written.The default matches |
---|
374 | ; the size of the variable so that all data is written out. |
---|
375 | ; |
---|
376 | ; GROUP: The widget ID of the widget that calls XNCDF_LEC. When |
---|
377 | ; this ID is specified, a death of the caller results in a death |
---|
378 | ; of XNCDF_LEC. |
---|
379 | ; |
---|
380 | ; OFFSET: An optional vector containing the starting position |
---|
381 | ; for the read. The default start position is [0, 0, ...]. |
---|
382 | ; |
---|
383 | ; SHIFT: un vecteur d''entiers, specifiant pour chaque dimension |
---|
384 | ; de combien il faut la shifter. Par defaut c''est |
---|
385 | ; [0,0,...]. cf. la fonction shift pour + |
---|
386 | ; d''explications. ATTENTION, le shift est effectue sur le |
---|
387 | ; tableau de taille maximum avant la reduction eventuelle |
---|
388 | ; determinee par OFFSET et COUNT. Par contre il est effectue |
---|
389 | ; apres l''extraction eventuelle cree par le STRIDE. |
---|
390 | ; |
---|
391 | ; STRIDE: An optional vector containing the strides, or sampling |
---|
392 | ; intervals, between accessed values of the netCDF variable. The |
---|
393 | ; default stride vector is that for a contiguous read, [1, 1, |
---|
394 | ; ...]. |
---|
395 | ; |
---|
396 | ; OUTPUTS: 2 cas possibles: |
---|
397 | ; 1) aucun attributs n''a ete selectionne. Dans ce cas res est |
---|
398 | ; le tableau que l''on voulait lire. |
---|
399 | ; 2) Des attributs ont ete selectionnes. Dans ce cas res est une |
---|
400 | ; structre dont le premier element portant le nom de la variable |
---|
401 | ; est le tableau de valeurs et les autre auguments sont les |
---|
402 | ; arguments selectiones |
---|
403 | ; |
---|
404 | ; COMMON BLOCKS: wididbase, infovariable, resultat, motcle |
---|
405 | ; |
---|
406 | ; SIDE EFFECTS: |
---|
407 | ; |
---|
408 | ; RESTRICTIONS: |
---|
409 | ; |
---|
410 | ; EXAMPLE: help, xncdf_lec() |
---|
411 | ; |
---|
412 | ; MODIFICATION HISTORY:Sebastien Masson (smasson@lodyc.jussieu.fr) |
---|
413 | ; 24/8/1999 |
---|
414 | ;- |
---|
415 | ;------------------------------------------------------------ |
---|
416 | ;------------------------------------------------------------ |
---|
417 | ;------------------------------------------------------------ |
---|
418 | FUNCTION xncdf_lec, nom, ATT = att, COUNT = count, GROUP = group, OFFSET = offset, IODIR = iodir, SHIFT = shift, STRIDE = stride, VAR = var |
---|
419 | ; |
---|
420 | compile_opt idl2, strictarrsubs |
---|
421 | ; |
---|
422 | COMMON wididbase, base |
---|
423 | COMMON infovariable, cdfid, listename, contient, nomdim, tailledim, varid, varcontient |
---|
424 | COMMON resultat, res |
---|
425 | COMMON motcle, mcatt, mccount, mcoffset, mciodir, mcshift, mcstride, mcvar |
---|
426 | ;------------------------------------------------------------ |
---|
427 | ; bidouille pour utiliser les mots cles (on passe par des variables |
---|
428 | ; declarees ds un common) |
---|
429 | ;------------------------------------------------------------ |
---|
430 | res = -1 |
---|
431 | if keyword_set(att) then mcatt = att ELSE mcatt = 0 |
---|
432 | if keyword_set(count) then mccount =count ELSE mccount = 0 |
---|
433 | if keyword_set(offset) then mcoffset = offset ELSE mcoffset = 0 |
---|
434 | if keyword_set(shift) then mcshift = shift ELSE mcshift = 0 |
---|
435 | if keyword_set(stride) then mcstride = stride ELSE mcstride = 0 |
---|
436 | if keyword_set(var) then mcvar = var ELSE mcvar = 0 |
---|
437 | ;------------------------------------------------------------ |
---|
438 | ; choix du nom du fichier |
---|
439 | ;------------------------------------------------------------ |
---|
440 | ; Quel type de machine est utiliee |
---|
441 | thisOS = strupcase(strmid(!version.os_family, 0, 3)) |
---|
442 | CASE thisOS of |
---|
443 | 'MAC':sep = ':' |
---|
444 | 'WIN':sep = '\' |
---|
445 | ELSE: sep = '/' |
---|
446 | ENDCASE |
---|
447 | ; si iodir n''est pas definit on l''initialise au repertoire courant |
---|
448 | if NOT keyword_set(iodir) then cd, current = iodir |
---|
449 | mciodir = iodir |
---|
450 | ; on complete iodir d''un caractere separateur de repertoire si besoin |
---|
451 | ; est. |
---|
452 | IF rstrpos(iodir, sep) NE strlen(iodir)-1 THEN iodir = iodir+sep |
---|
453 | if n_elements(nom) EQ 0 then BEGIN ; si nom n''est pas definit |
---|
454 | ; on en trouve un grace au programme dialog_pickfile |
---|
455 | nom = dialog_pickfile(filter = iodir+'*.nc') |
---|
456 | if nom[0] EQ '' then return, -1 ; si on a rien trouve on sort |
---|
457 | ;on complete nom par iodir si nom ne contient pas de caractere |
---|
458 | ;separateur derepertoire |
---|
459 | ENDIF ELSE if strpos(nom, sep) EQ -1 then nom = iodir+nom |
---|
460 | test = findfile(nom) ; le nom cherche correspond bien a un fichier? |
---|
461 | while test[0] EQ '' OR n_elements(test) GT 1 do BEGIN ; on en cherche un tant qu''il ne correspond a rien! |
---|
462 | test = test[0] |
---|
463 | nom = dialog_pickfile(filter = iodir+'*.nc') |
---|
464 | if nom EQ '' then return, -1 |
---|
465 | test = findfile(nom) |
---|
466 | endwhile |
---|
467 | ;------------------------------------------------------------ |
---|
468 | ; ouverture du fichier nom |
---|
469 | ;------------------------------------------------------------ |
---|
470 | cdfid=ncdf_open(nom) |
---|
471 | contient=ncdf_inquire(cdfid) |
---|
472 | ;------------------------------------------------------------ |
---|
473 | ; que contient le fichier?? |
---|
474 | ;------------------------------------------------------------ |
---|
475 | ; ouverture de la fenetre de base sous forme de colonnes |
---|
476 | if n_elements(group) EQ 0 then base = widget_base(/column, title='Fichier: '+nom, /align_left) $ |
---|
477 | ELSE base = widget_base(/column, title='Fichier: '+nom, /align_left, GROUP_LEADER = group) |
---|
478 | ; ouverture de sous-fenetres de base ; |
---|
479 | ;------------------------------------------------------------ |
---|
480 | ; base 1 titre portant le nom du fichier |
---|
481 | ;------------------------------------------------------------ |
---|
482 | base1 = widget_base(base, /column, /align_center) |
---|
483 | rien = widget_label(base1, value = 'Net Cdf filename', /align_center) ; blabla |
---|
484 | rien = widget_text(base1, value = nom, /align_center, uvalue=1, /editable) ;nom du fichier que l''on peut changer |
---|
485 | rien = widget_label(base1, value = ' ') ; on saute une ligne |
---|
486 | ;------------------------------------------------------------ |
---|
487 | ; base 2 informations generales sur le fichier |
---|
488 | ;------------------------------------------------------------ |
---|
489 | base2 = widget_base(base, /column) |
---|
490 | ;------------------------------------------------------------ |
---|
491 | ; informations sur les attributs globaux |
---|
492 | ;------------------------------------------------------------ |
---|
493 | if contient.ngatts NE -1 then begin |
---|
494 | rien = widget_label(base2, value = 'Nombre de attributs globaux: '+ strtrim(contient.ngatts,1), /align_left) |
---|
495 | for attiq=0,contient.ngatts-1 do BEGIN ; bouble sur le nombre d'attributs globaux |
---|
496 | name=ncdf_attname(cdfid,attiq,/global) ;nom de l''atribut |
---|
497 | ncdf_attget,cdfid,name,value,/global ;valeur de l''atribut |
---|
498 | rien = widget_text(base2, value = name+': '+strtrim(string(value),1), xsize = 60, /scroll, /wrap, /align_right) |
---|
499 | endfor |
---|
500 | rien = widget_label(base2, value = ' ') |
---|
501 | endif |
---|
502 | ;------------------------------------------------------------ |
---|
503 | ; informations sur les dimensions |
---|
504 | ;------------------------------------------------------------ |
---|
505 | rien = widget_label(base2, value = 'Nombre de dimensions: '+strtrim(contient.ndims,1), /align_left) |
---|
506 | if contient.recdim NE -1 then begin ; bouble sur le nombre de dimensions |
---|
507 | ncdf_diminq,cdfid,contient.recdim,name,value ; nom et valeur de la dimension |
---|
508 | rien = widget_label(base2, value = 'nom de la dimension infinie: '+name, /align_left) |
---|
509 | endif |
---|
510 | ; |
---|
511 | nomdim =strarr(contient.ndims) ; vecteur contenant le nom des dimensions |
---|
512 | tailledim=lonarr(contient.ndims) ; vecteur contenant la valeur des dimensions |
---|
513 | for dimiq=0,contient.ndims-1 do begin ; bouble sur le nombre de dimensions |
---|
514 | ncdf_diminq,cdfid,dimiq,name,value ; nom et valeur de la dimension |
---|
515 | nomdim[dimiq]=name |
---|
516 | tailledim[dimiq]=value |
---|
517 | rien = widget_label(base2, value = name+' de taille: '+strtrim(value,1), /align_right) |
---|
518 | ENDFOR |
---|
519 | rien = widget_label(base2, value = ' ') ; on saute une ligne |
---|
520 | ;------------------------------------------------------------ |
---|
521 | ; base 3 choix de la variable |
---|
522 | ;------------------------------------------------------------ |
---|
523 | base3 = widget_base(base, /column) |
---|
524 | rien = widget_label(base3, value = 'Nombre de variables: '+strtrim(contient.nvars,1), /align_left) |
---|
525 | base31 = widget_base(base3, /row, /align_center) |
---|
526 | ;creation d'un vecteur listename contenant le nom de toutes les |
---|
527 | ;variables du fichier |
---|
528 | listename = strarr(contient.nvars) |
---|
529 | for varid=0,contient.nvars-1 do begin |
---|
530 | varcontient=ncdf_varinq(cdfid,varid) ; que contient la variable |
---|
531 | listename[varid] = varcontient.name |
---|
532 | endfor |
---|
533 | rien= widget_label(base31, value = 'variable') |
---|
534 | ; creation d''un bouton a menu deroulant |
---|
535 | base311=widget_droplist(base31,value=listename, uvalue=2) |
---|
536 | rien = widget_label(base3, value = '') |
---|
537 | ;------------------------------------------------------------ |
---|
538 | ; base 4 bouton done |
---|
539 | ;------------------------------------------------------------ |
---|
540 | base4 = widget_base(base, /row) |
---|
541 | base42=widget_button(base4,value='done', uvalue=3, /align_right) |
---|
542 | ;execution de la fentre de base et des sous-fenetres |
---|
543 | widget_control,base,/realize |
---|
544 | ;------------------------------------------------------------ |
---|
545 | xmanager,'xncdf_lec',base |
---|
546 | ;------------------------------------------------------------ |
---|
547 | ;------------------------------------------------------------ |
---|
548 | ;------------------------------------------------------------ |
---|
549 | return, res |
---|
550 | end |
---|