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