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