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