1 | ;------------------------------------------------------------ |
---|
2 | ;------------------------------------------------------------ |
---|
3 | ;------------------------------------------------------------ |
---|
4 | ;+ |
---|
5 | ; @file_comments |
---|
6 | ; lit les fichiers Vairmer en sort: |
---|
7 | ; un tableau 2d ou 3d en fonction de nomchamp qui est le nom |
---|
8 | ; du champ a extaire (2d s'il commence par SO et 3d s'il commence par VO) |
---|
9 | ; cette fonction modifie aussi les variables globales: |
---|
10 | ; varname: trois lettres: nom de l'experience |
---|
11 | ; vargrid: nom de la grille |
---|
12 | ; vardate: date (yy)yymmdd |
---|
13 | ; varexp: nom Vairmer du champ a tarcer |
---|
14 | ; |
---|
15 | ; @obsolete |
---|
16 | ; |
---|
17 | ; @categories Graphics, lecture de fichier Vaimer |
---|
18 | ; |
---|
19 | ; @examples |
---|
20 | ; IDL> resultat=lec('nom_Vairmer'[,date[,'nom_experience']]) |
---|
21 | ; |
---|
22 | ; @param nomchamp {in}{required} 2 choix possibles: |
---|
23 | ; 1) nom de champ Vairmer (chaine de 8 caracteres en majuscule ou |
---|
24 | ; minuscule commencant par vo ou so). Dans cette methode on saute directement |
---|
25 | ; d'en-tete en en-tete jusqu'a trouver le bon fichier. |
---|
26 | ; 2) chaine de characteres commencant par vo ou so suivit du |
---|
27 | ; numero de champ a aller chercher (par ex 'vo5'). Cette methode est un peu |
---|
28 | ; plus rapide car elle va directement chercher le fichier qui nous interesse. |
---|
29 | ; |
---|
30 | ; @param date {in}{optional} nombres de 6 ou 8 chiffres (anneemoisjour, par ex:19980507) |
---|
31 | ; |
---|
32 | ; @param nomexp {in}{optional} trois lettres designant le nom de l'experience |
---|
33 | ; |
---|
34 | ; |
---|
35 | ; @keyword ANOM {in} type du fichier vairmer par rapport auquel on doit calculer |
---|
36 | ; l'anomalie ('EX','AN','SE','MO','') |
---|
37 | ; |
---|
38 | ; @keyword ECRIT {in} permet d'imprimer tous les noms vairmer que contient le fichier. |
---|
39 | ; ds ce cas en input on met seulement 'vo' ou 'so' la fonction retourne le |
---|
40 | ; nombre de fichiers lus. |
---|
41 | ; |
---|
42 | ; @keyword BOITE |
---|
43 | ; |
---|
44 | ; @keyword EXPANOM {in} si on calcule l'anom par rapport a une exper |
---|
45 | ; differente |
---|
46 | ; |
---|
47 | ; @keyword FILENAME string pour passer directement le nom du champ sans |
---|
48 | ; utiliser les inputs: nom_Vairmer',date,'nom_experience'. Rq si |
---|
49 | ; ces inputs sont qd meme donnes ils ne sont pas modifies par |
---|
50 | ; filename. |
---|
51 | ; |
---|
52 | ; @keyword GRID lorsque ce mot clef est active, lec retourne la liste |
---|
53 | ; des types de grilles (T, U...) auxquelles se rapportent les |
---|
54 | ; variables. ds ce cas en input on met seulement 'vo' ou 'so'. |
---|
55 | ; |
---|
56 | ; @keyword NAME lorsque ce mot clef est active, lec retourne la liste |
---|
57 | ; des noms des variables. ds ce cas en input on met seulement |
---|
58 | ; 'vo' ou 'so'. |
---|
59 | ; |
---|
60 | ; @keyword TOUT oblige lec a lire le champ sur tout le domaine qui a |
---|
61 | ; etait selectionne pour la cession en cours (jpi,jpj,jpk) |
---|
62 | ; |
---|
63 | ; @returns un tableau 2 ou 3d. sans le mot cle /TOUT, sa taille est |
---|
64 | ; celle du sous domaine definit par domdef (nx,ny,nz). avec /TOUT le |
---|
65 | ; champ a la taille du domaine qui a etait selectionne pour la |
---|
66 | ; cession en cours (jpi,jpj,jpk). |
---|
67 | ; pour les sous domaines cf: |
---|
68 | ; http://www.ipsl.jussieu.fr/~smlod/sousdomaine.html |
---|
69 | ; Retourne -1 en cas d'erreur. |
---|
70 | ; |
---|
71 | ; @uses common.pro isnumber.pro fivardate.pro |
---|
72 | ; |
---|
73 | ; @history Sebastien Masson (smasson\@lodyc.jussieu.fr) |
---|
74 | ; 26/5/98 |
---|
75 | ; Jerome Vialard : adaptation au format vairmer |
---|
76 | ; keyword anom et expanom |
---|
77 | ; 1/7/98 |
---|
78 | ; Sebastien Masson (masque des terres) |
---|
79 | ; 14/8/98 |
---|
80 | ; Sebastien Masson (decoupe pour les sous domaines...) |
---|
81 | ; 2/99 |
---|
82 | ; |
---|
83 | ; @version $Id$ |
---|
84 | ; |
---|
85 | ;;- |
---|
86 | ;-------------------------------------------------------------- |
---|
87 | ;-------------------------------------------------------------- |
---|
88 | ;-------------------------------------------------------------- |
---|
89 | function lec, nomchamp,date,nomexp,ECRIT=ecrit,ANOM=anom, BOITE = boite,EXPANOM=expanom, TOUT = tout, GRID = grid, NAME = name, filename = FILENAME |
---|
90 | ; |
---|
91 | compile_opt idl2, strictarrsubs, obsolete |
---|
92 | ; |
---|
93 | @common |
---|
94 | tempsun = systime(1) ; pour key_performance |
---|
95 | z = -1 |
---|
96 | ; |
---|
97 | if keyword_set(filename) then BEGIN |
---|
98 | CASE strupcase(strmid(!version.os_family, 0, 3)) of |
---|
99 | 'MAC':sep = ':' |
---|
100 | 'WIN':sep = '\' |
---|
101 | ELSE:sep = '/' |
---|
102 | ENDCASE |
---|
103 | fname = strmid(filename, rstrpos(filename, sep)+1) |
---|
104 | if n_elements(nomchamp) EQ 0 then nomchamp = strmid(fname,6, 2) |
---|
105 | if n_elements(date) EQ 0 then date = long(strmid(fname,8)) |
---|
106 | if n_elements(nomexp) EQ 0 then nomexp = strmid(fname,0, 3) |
---|
107 | endif |
---|
108 | ; |
---|
109 | nomchamp=strupcase(nomchamp) |
---|
110 | dim=string(format='(a2)',nomchamp) |
---|
111 | ;print, 'nom de l''experience: ',nomchamp |
---|
112 | ;------------------------------------------------------------ |
---|
113 | ; specification de la date et de l'experience |
---|
114 | ;------------------------------------------------------------ |
---|
115 | case n_params() OF |
---|
116 | 0:BEGIN |
---|
117 | if keyword_set(filename) then begin |
---|
118 | rien=juldate(date) |
---|
119 | prefix=nomexp |
---|
120 | ENDIF ELSE return, report('Donnez un argument en entree ou utilisez le mot clef FILENAME') |
---|
121 | END |
---|
122 | 1:date=long(day)+long(month)*100+long(year)*10000 |
---|
123 | 2:rien=juldate(date) |
---|
124 | 3:begin |
---|
125 | rien=juldate(date) |
---|
126 | prefix=nomexp |
---|
127 | end |
---|
128 | endcase |
---|
129 | ;------------------------------------------------------------ |
---|
130 | ; verification de la dim du fichier |
---|
131 | ;------------------------------------------------------------ |
---|
132 | if dim ne 'SO' and dim ne 'VO' then return, report('le nom du champ doit commencer par VO ou SO') |
---|
133 | ;------------------------------------------------------------ |
---|
134 | ; constitution de l'adresse ou aller chercher le fichier |
---|
135 | ;-------------------------------------------------------------- |
---|
136 | s_fichier=ficdate(date,dim) |
---|
137 | ;-------------------------------------------------------------------- |
---|
138 | ; ouverture du fichier a l'adresse s_fichier |
---|
139 | ;-------------------------------------------------------------------- |
---|
140 | openr, numlec, s_fichier, /get_lun,ERROR=err, /swap_if_little_endian |
---|
141 | if err ne 0 then begin |
---|
142 | ; print,!err_string |
---|
143 | return, -1 |
---|
144 | endif |
---|
145 | ;taille en octet du fichier |
---|
146 | infofichier=fstat(numlec) |
---|
147 | ;--------------------------------------------------------------------- |
---|
148 | ; definition de la taille du fichier a aller chercher: jpidta,jpjdta,jpkdta... |
---|
149 | ;--------------------------------------------------------------------- |
---|
150 | if n_elements(jpidta) EQ 0 THEN BEGIN |
---|
151 | if n_elements(ixmindta) EQ 0 OR n_elements(ixmaxdta) EQ 0 then $ |
---|
152 | jpidta = jpiglo else jpidta = ixmaxdta-ixmindta+1 |
---|
153 | endif |
---|
154 | if n_elements(jpjdta) EQ 0 THEN BEGIN |
---|
155 | if n_elements(iymindta) EQ 0 OR n_elements(iymaxdta) EQ 0 then $ |
---|
156 | jpjdta = jpjglo else jpjdta = iymaxdta-iymindta+1 |
---|
157 | endif |
---|
158 | if n_elements(jpkdta) EQ 0 THEN BEGIN |
---|
159 | if n_elements(izmindta) EQ 0 OR n_elements(izmaxdta) EQ 0 then $ |
---|
160 | jpkdta = jpkglo else jpkdta = izmaxdta-izmindta+1 |
---|
161 | endif |
---|
162 | ;--------------------------------------------------------------------- |
---|
163 | ; lecture des champs directement vers le champ ou l'en-tete que l'on recherche |
---|
164 | ; il faut savoir que: |
---|
165 | ; le fortran ajoute au debut et a la fin de chaque write 4 octets de controle |
---|
166 | ; les reels du model sont codes sur 4 octets |
---|
167 | ; un charactere fait 1 octet |
---|
168 | ;----------------------------------------------------------------------- |
---|
169 | ;4 chaines de 8 characteres+un tableau de reels+4 trucs de controle (pour les |
---|
170 | ; 2 write): |
---|
171 | if dim eq 'VO' then $ |
---|
172 | taillebloc=4*8+long(jpidta)*jpjdta*jpkdta*4+4*4 else $ |
---|
173 | taillebloc=4*8+long(jpidta)*jpjdta*4+4*4 |
---|
174 | ;--------------------------------------------------------------------- |
---|
175 | ; choix du type de lecture |
---|
176 | ;--------------------------------------------------------------------- |
---|
177 | typelec=strmid(nomchamp,2,strlen(nomchamp)) |
---|
178 | test=isnumber(typelec,numerochamp) |
---|
179 | if test eq 0 then begin |
---|
180 | ;-------------------------------------------------------------------- |
---|
181 | ; 1) LECTURE DIRECTE D'EN-TETE en EN-TETE |
---|
182 | ;-------------------------------------------------------------------- |
---|
183 | numerochamp=1 |
---|
184 | ;--------------------------------------------------------------------- |
---|
185 | ; lecture des noms de champ |
---|
186 | ;--------------------------------------------------------------------- |
---|
187 | resname = '' |
---|
188 | resgrid = '' |
---|
189 | while numerochamp*taillebloc le infofichier.size do begin |
---|
190 | offset=(numerochamp-1)*taillebloc+4 |
---|
191 | a=assoc(numlec,bytarr(8,/nozero), offset) |
---|
192 | varname=string(a[0]) |
---|
193 | if keyword_set(ecrit) OR keyword_set(name) OR keyword_set(grid) $ |
---|
194 | then begin |
---|
195 | vargrid=a[1] |
---|
196 | vargrid=string(vargrid[7]) |
---|
197 | vardate=strtrim(long(string(a[2])), 2) |
---|
198 | varexp=strtrim(a[3], 2) |
---|
199 | if keyword_set(ecrit) THEN $ |
---|
200 | print, numerochamp,' ',varname,' ',vargrid,' ',vardate,' ',varexp |
---|
201 | resname = [resname, varname] |
---|
202 | resgrid = [resgrid, vargrid] |
---|
203 | endif |
---|
204 | if nomchamp eq varname then begin |
---|
205 | vargrid=a[1] |
---|
206 | vargrid=string(vargrid[7]) |
---|
207 | vardate=strtrim(long(string(a[2])), 2) |
---|
208 | varexp=strtrim(a[3], 2) |
---|
209 | goto,sortieboucle |
---|
210 | endif |
---|
211 | numerochamp=numerochamp+1 |
---|
212 | ENDWHILE |
---|
213 | free_lun,numlec |
---|
214 | close, numlec |
---|
215 | case 1 of |
---|
216 | keyword_set(ecrit):return, numerochamp-1 |
---|
217 | keyword_set(name):return, resname[1:numerochamp-1] |
---|
218 | keyword_set(grid):$ |
---|
219 | return, strmid(resgrid[1:numerochamp-1],0 > (strlen(resgrid[0])-2)) |
---|
220 | ELSE:return, report('Ce nom Vairmer de champ n''existe pas ds le fichier: '+infofichier.name) |
---|
221 | endcase |
---|
222 | endif else begin |
---|
223 | ;---------------------------------------------------------------------- |
---|
224 | ; 2) LECTURE DIRECTEMENT DU CHAMP QUE L'ON VEUT |
---|
225 | ;--------------------------------------------------------------------- |
---|
226 | ;--------------------------------------------------------------------- |
---|
227 | ; test pour savoir si numero de champ est accessible |
---|
228 | ;--------------------------------------------------------------------- |
---|
229 | if taillebloc*numerochamp gt infofichier.size then $ |
---|
230 | return, report('Ce numero de champ n''exite pas. Le fichier '+infofichier.name+' ne contient que ',infofichier.size/taillebloc,' champs.') |
---|
231 | ;--------------------------------------------------------------------- |
---|
232 | ; lecture de l'en-tete numero numerochamp |
---|
233 | ;--------------------------------------------------------------------- |
---|
234 | offset=(numerochamp-1)*taillebloc+4 |
---|
235 | a=assoc(numlec,bytarr(8,/nozero), offset) |
---|
236 | varname=string(a[0]) |
---|
237 | vargrid=a[1] |
---|
238 | vargrid=string(vargrid[7]) |
---|
239 | vardate=string(a[2]) |
---|
240 | varexp=string(a[3]) |
---|
241 | endelse |
---|
242 | sortieboucle: |
---|
243 | ;--------------------------------------------------------------------- |
---|
244 | ; lecture du champ lui-meme |
---|
245 | ;--------------------------------------------------------------------- |
---|
246 | offset=(numerochamp-1)*taillebloc+(8+4*8)+4 |
---|
247 | if dim eq 'VO' then $ |
---|
248 | a=assoc(numlec,fltarr(jpidta,jpjdta,jpkdta,/nozero), offset) else $ |
---|
249 | a=assoc(numlec,fltarr(jpidta,jpjdta,/nozero), offset) |
---|
250 | z=a[0] |
---|
251 | ;--------------------------------------------------------------------- |
---|
252 | ; on initialise les ixmindta, iymindta au besoin |
---|
253 | ;--------------------------------------------------------------------- |
---|
254 | if n_elements(ixmindta) EQ 0 OR n_elements(ixmaxdta) EQ 0 then BEGIN |
---|
255 | ixmindta = 0 |
---|
256 | ixmaxdta = jpidta-1 |
---|
257 | endif |
---|
258 | if n_elements(iymindta) EQ 0 OR n_elements(iymaxdta) EQ 0 then BEGIN |
---|
259 | iymindta = 0 |
---|
260 | iymaxdta = jpjdta-1 |
---|
261 | endif |
---|
262 | if n_elements(izmin) EQ 0 OR n_elements(izmax) EQ 0 then BEGIN |
---|
263 | izmindta = 0 |
---|
264 | izmaxdta = jpkdta-1 |
---|
265 | endif |
---|
266 | ;--------------------------------------------------------------------- |
---|
267 | ; on reduit z selon les valeurs de ixmindta, iymindta, ... |
---|
268 | ;--------------------------------------------------------------------- |
---|
269 | if dim EQ 'SO' then z = z[ixminmesh-ixmindta:ixmaxmesh-ixmindta $ |
---|
270 | ,iyminmesh-iymindta:iymaxmesh-iymindta] $ |
---|
271 | ELSE z = z[ixminmesh-ixmindta:ixmaxmesh-ixmindta $ |
---|
272 | , iyminmesh-iymindta:iymaxmesh-iymindta, izminmesh-izmindta:izmaxmesh-izmindta] |
---|
273 | ;--------------------------------------------------------------------- |
---|
274 | ; on shift z si key_shift est defininit |
---|
275 | ;--------------------------------------------------------------------- |
---|
276 | if n_elements(key_shift) NE 0 THEN BEGIN |
---|
277 | if dim EQ 'SO' then z = shift(z,key_shift, 0) $ |
---|
278 | ELSE z = shift(z,key_shift, 0, 0) |
---|
279 | endif |
---|
280 | ;--------------------------------------------------------------------- |
---|
281 | ; si /TOUT n''est pas active, on coupe z pour q''il soit a la taille |
---|
282 | ; du zoom: nx,ny nz |
---|
283 | ;--------------------------------------------------------------------- |
---|
284 | if NOT keyword_set(tout) then BEGIN |
---|
285 | ;------------------------------------------------------------- |
---|
286 | ; changement de domaine |
---|
287 | ;------------------------------------------------------------- |
---|
288 | if keyword_set(boite) then BEGIN |
---|
289 | Case 1 Of |
---|
290 | N_Elements(Boite) Eq 1:bte=[lon1, lon2, lat1, lat2, 0.,boite[0]] |
---|
291 | N_Elements(Boite) Eq 2:bte=[lon1, lon2, lat1, lat2, boite[0],boite[1]] |
---|
292 | N_Elements(Boite) Eq 4:bte=[Boite, prof1, prof2] |
---|
293 | N_Elements(Boite) Eq 5:bte=[Boite[0:3], 0, Boite[4]] |
---|
294 | N_Elements(Boite) Eq 6:bte=Boite |
---|
295 | Else: return, report('Mauvaise Definition de Boite') |
---|
296 | endcase |
---|
297 | oldboite = [lon1, lon2, lat1, lat2, prof1, prof2] |
---|
298 | domdef, bte,GRILLE=vargrid |
---|
299 | ENDIF |
---|
300 | ;------------------------------------------------------------- |
---|
301 | grille,mask,glam,gphi,gdep,nx,ny,nz,premierx,premiery,premierz,dernierx,derniery,dernierz |
---|
302 | if nx EQ 1 OR ny EQ 1 OR nz EQ 1 then mask = reform(mask, nx, ny, nz, /over) |
---|
303 | if dim EQ 'SO' then z = z[premierx:dernierx, premiery:derniery] $ |
---|
304 | ELSE z = z[premierx:dernierx, premiery:derniery, premierz:dernierz] |
---|
305 | ENDIF ELSE BEGIN |
---|
306 | case vargrid OF ; on recupere le mask en entier ds le cas ou /TOUT |
---|
307 | 'U':mask = umask() ; n''est pas active et on le choisit en fontion |
---|
308 | 'T':mask = tmask ; de la valeur de vargrid |
---|
309 | 'W':mask = tmask |
---|
310 | 'V':mask = vmask() |
---|
311 | 'F':mask = fmask() |
---|
312 | ENDCASE |
---|
313 | ENDELSE |
---|
314 | ;--------------------------------------------------------------------- |
---|
315 | ; calcul d'une anomalie si le keyword anom est active |
---|
316 | ;--------------------------------------------------------------------- |
---|
317 | if keyword_set(anom) then begin |
---|
318 | case anom of |
---|
319 | 'EX' : adate = 0 |
---|
320 | 'AN' : adate = floor(date/10000)*10000 |
---|
321 | 'SE' : adate = floor(date - floor(date/10000)*10000)/100 * 100 |
---|
322 | 'MO' : adate = floor(date/100)*100 |
---|
323 | 'DA' : adate = date - floor(date/10000)*10000 |
---|
324 | '' : adate = date - floor(date/10000)*10000 |
---|
325 | else : return, report('Anom doit etre egal a EX,AN,SE,MO,DA ') |
---|
326 | endcase |
---|
327 | if keyword_set(expanom) then nomexpa = expanom $ |
---|
328 | else nomexpa = nomexp |
---|
329 | if keyword_set(bavard) THEN print, nomchamp,' - ',adate,' - ',nomexpa |
---|
330 | z = z - lec(nomchamp,adate,nomexpa, TOUT = tout) |
---|
331 | endif |
---|
332 | ;--------------------------------------------------------------------- |
---|
333 | ; on masque les terres par valmask |
---|
334 | ;--------------------------------------------------------------------- |
---|
335 | IF n_elements(valmask) EQ 0 THEN valmask = 1e20 |
---|
336 | if dim EQ 'SO' then BEGIN |
---|
337 | terre = where(mask[*,*,0] EQ 0) |
---|
338 | if terre[0] NE -1 then z[terre] = valmask |
---|
339 | ENDIF ELSE BEGIN |
---|
340 | terre = where(mask[*,*,0] EQ 0) |
---|
341 | if terre[0] NE -1 then z[where(mask EQ 0)] = valmask |
---|
342 | ENDELSE |
---|
343 | ;--------------------------------------------------------------------- |
---|
344 | free_lun,numlec |
---|
345 | close, numlec |
---|
346 | ;--------------------------------------------------------------------- |
---|
347 | if n_elements(oldboite) NE 0 then domdef, oldboite |
---|
348 | IF keyword_set(key_performance) EQ 1 THEN print, 'temps lec', systime(1)-tempsun |
---|
349 | ; |
---|
350 | return,reform(z) |
---|
351 | |
---|
352 | end |
---|
353 | |
---|