[2] | 1 | ;------------------------------------------------------------ |
---|
| 2 | ;------------------------------------------------------------ |
---|
| 3 | ;------------------------------------------------------------ |
---|
| 4 | ;+ |
---|
| 5 | ; NAME:NLEC5J |
---|
| 6 | ; |
---|
| 7 | ; PURPOSE:lit les fichiers Net-Cdf de l'experience TOTEM/ECMWF qui |
---|
| 8 | ; contiennent les sorties a 5j regroupees par type de grille par |
---|
| 9 | ; paquets de 6 mois. |
---|
| 10 | ; sur maia: /u/rech/eee/reee217/TOTEM/REF/OUTPUTS |
---|
| 11 | ; |
---|
| 12 | ; CATEGORY:lecture de NETCDF |
---|
| 13 | ; |
---|
| 14 | ; CALLING SEQUENCE: res=nlec5j( nom, numsortie, nbretps) |
---|
| 15 | ; |
---|
| 16 | ; INPUTS: |
---|
| 17 | ; nom:nom du tableau contenant le champ que l'on veut (le |
---|
| 18 | ; trouver avec ncdflec,fichier,/var |
---|
| 19 | ; numsortie:le numero du pas de temps que l'on veut sortir du |
---|
| 20 | ; fichier (compte a partir de 1) a partir de year |
---|
| 21 | ; nbretps:nombre de pas de temps a extraire |
---|
| 22 | ; |
---|
| 23 | ; KEYWORD PARAMETERS: |
---|
| 24 | ; |
---|
| 25 | ; BOITE: boite sur laquelle integrer (par defaut tt le domaine) |
---|
| 26 | ; |
---|
| 27 | ; GRILLE:impose la grille a laquelle est rapporte le champ. rq permet |
---|
| 28 | ; d'aller plus vite ds la lecture |
---|
| 29 | ; |
---|
| 30 | ; /TOUT:oblige a lire le tableau entier en non pas celui reduit a domdef |
---|
| 31 | ; |
---|
| 32 | ; OUTPUTS: res=tableau 2d (qd on ne demande pas de serie) ou 3d ou 4d ds le cas dune serie |
---|
| 33 | ; |
---|
| 34 | ; COMMON BLOCKS: |
---|
| 35 | ; common.pro |
---|
| 36 | ; |
---|
| 37 | ; SIDE EFFECTS: |
---|
| 38 | ; |
---|
| 39 | ; RESTRICTIONS:appele par nlec |
---|
| 40 | ; |
---|
| 41 | ; EXAMPLE: |
---|
| 42 | ; |
---|
| 43 | ; MODIFICATION HISTORY: Sebastien Masson (smasson@lodyc.jussieu.fr) |
---|
| 44 | ; |
---|
| 45 | ;- |
---|
| 46 | ;------------------------------------------------------------ |
---|
| 47 | ;------------------------------------------------------------ |
---|
| 48 | ;------------------------------------------------------------ |
---|
| 49 | function nlec5j, nom, numsortie, nbretps,BOITE = boite, GRILLE=grille,TOUT=tout, _EXTRA = ex |
---|
| 50 | @common |
---|
| 51 | ;------------------------------------------------------------ |
---|
| 52 | res=-1 |
---|
| 53 | anneedepart=1979 |
---|
| 54 | ;------------------------------------------------------------ |
---|
| 55 | ; gestion du nom du fichier |
---|
| 56 | ;------------------------------------------------------------ |
---|
| 57 | if numsortie le 36 then BEGIN |
---|
| 58 | mmdd='0101' |
---|
| 59 | numsort=numsortie |
---|
| 60 | ENDIF else BEGIN |
---|
| 61 | if leapyr(year) then mmdd='0629' else mmdd='0630' |
---|
| 62 | numsort=numsortie-36 |
---|
| 63 | endelse |
---|
| 64 | case 1 of |
---|
| 65 | year lt 10: s_year ='0'+string(format='(i1)',year) |
---|
| 66 | year lt 100 and year ge 10 :s_year = string(format='(i2)',year) |
---|
| 67 | year ge 100: s_year = string(format='(i2)',(year-1900)*(year LT 2000)) |
---|
| 68 | endcase |
---|
| 69 | numfich=(year-anneedepart)*2+7+(mmdd ne '0101') |
---|
| 70 | s_date=s_year+mmdd |
---|
| 71 | if numfich lt 10 then numfich='0'+string(format='(i1)',numfich) $ |
---|
| 72 | else numfich= string(format='(i2)',numfich) |
---|
| 73 | ;------------------------------------------------------------ |
---|
| 74 | ; gestion du nom de la grille en testant les differentes possibilites |
---|
| 75 | ; et ouverture du fichier |
---|
| 76 | ;------------------------------------------------------------ |
---|
| 77 | if keyword_set(grille) then begin |
---|
| 78 | vargrid=grille |
---|
| 79 | nomfich=prefix+'.'+numfich+'.'+s_date+'.grid.'+vargrid+'.nc' |
---|
[44] | 80 | IF !version.OS_FAMILY EQ 'unix' THEN spawn, '\file '+iodir+nomfich+' > /dev/null' |
---|
[2] | 81 | cdfid=ncdf_open(iodir+nomfich) |
---|
| 82 | varcontient=ncdf_varinq(cdfid,nom) |
---|
| 83 | endif else begin |
---|
| 84 | ; liste des fichiers pouvant convenir |
---|
| 85 | quelsfichiers = findfile(iodir+prefix+'.'+numfich+'.'+s_date+'.grid.*') |
---|
| 86 | IF quelsfichiers[0] EQ '' THEN BEGIN ; liste vide |
---|
| 87 | if keyword_set(bavard) then $ |
---|
| 88 | ras = report('LES FICHIERS: '+iodir+prefix+'.'+numfich+'.'+s_date+'.grid... n''existe pas.') |
---|
| 89 | return, -1 |
---|
| 90 | ENDIF |
---|
| 91 | for i=0,n_elements(quelsfichiers)-1 do begin |
---|
[44] | 92 | IF !version.OS_FAMILY EQ 'unix' THEN spawn, '\file '+quelsfichiers[i]+' > /dev/null' |
---|
[2] | 93 | cdfid=ncdf_open(quelsfichiers[i]) |
---|
| 94 | contient=ncdf_inquire(cdfid) |
---|
| 95 | for varid=0,contient.nvars-1 do BEGIN ; ds les fichiers existants on |
---|
| 96 | varcontient=ncdf_varinq(cdfid,varid) ; cherche le nom des variables |
---|
| 97 | if varcontient.name eq nom then BEGIN |
---|
| 98 | vargrid=strmid(quelsfichiers[i],strpos(quelsfichiers[i],'grid')+5,1) ;nom de grille |
---|
| 99 | goto, grilletrouvee |
---|
| 100 | ENDIF |
---|
| 101 | endfor |
---|
| 102 | ncdf_close,cdfid |
---|
| 103 | endfor |
---|
| 104 | if keyword_set(bavard) then $ |
---|
| 105 | ras = report('La variable '+nom+' n''existe pas ds les fichiers'+iodir+prefix+'.'+numfich+'.'+s_date+'.grid...') |
---|
| 106 | return, -1 |
---|
| 107 | endelse |
---|
| 108 | grilletrouvee: |
---|
| 109 | ;------------------------------------------------------------ |
---|
| 110 | ; lecture de certains attributs |
---|
| 111 | ;------------------------------------------------------------ |
---|
| 112 | ncdf_attget,cdfid,nom,'title',value |
---|
| 113 | varname=string(value) |
---|
| 114 | ncdf_attget,cdfid,nom,'units',value |
---|
| 115 | varunit=string(value) |
---|
| 116 | if rstrpos(varname,'(') eq -1 then varname=varname+' ('+varunit+')' |
---|
| 117 | if month lt 10 then s_month='0'+string(format='(i1)',month) $ |
---|
| 118 | else s_month= string(format='(i2)',month) |
---|
| 119 | if day lt 10 then s_day='0'+string(format='(i1)',day) $ |
---|
| 120 | else s_day= string(format='(i2)',day) |
---|
| 121 | vardate=s_year+s_month+s_day |
---|
| 122 | ncdf_attget,cdfid,'file_name',value,/global |
---|
| 123 | varexp=string(value[0:(where(value EQ (byte('.'))[0]))[0]-1]) |
---|
| 124 | ;------------------------------------------------------------ |
---|
| 125 | ;------------------------------------------------------------ |
---|
| 126 | ; extraction du tableau qui nous interesse |
---|
| 127 | ;------------------------------------------------------------ |
---|
| 128 | ;------------------------------------------------------------ |
---|
| 129 | ; determination du domaine geographique |
---|
| 130 | ;------------------------------------------------------------ |
---|
| 131 | if keyword_set(tout) then begin |
---|
| 132 | nx=jpi |
---|
| 133 | ny=jpj |
---|
| 134 | nz=jpk |
---|
| 135 | premierx = 0 |
---|
| 136 | premiery = 0 |
---|
| 137 | premierz = 0 |
---|
| 138 | endif else BEGIN |
---|
| 139 | ;------------------------------------------------------------ |
---|
| 140 | ; redefinition eventuelle du domaine ajuste a boite (a 6 elements) |
---|
| 141 | ; + on recupere la dim du no9uveau domaine |
---|
| 142 | ;------------------------------------------------------------ |
---|
| 143 | if keyword_set(boite) then BEGIN |
---|
| 144 | Case N_Elements(Boite) Of |
---|
| 145 | 1:Domdef, lon1, lon2, lat1, lat2, 0.,boite[0],GRILLE=vargrid, _EXTRA = ex |
---|
| 146 | 2:Domdef, lon1, lon2, lat1, lat2, boite[0],boite[1],GRILLE=vargrid, _EXTRA = ex |
---|
| 147 | 4:Domdef, [Boite, prof1, prof2],GRILLE=vargrid, _EXTRA = ex |
---|
| 148 | 5:Domdef, [Boite[0:3], 0, Boite[4]],GRILLE=vargrid, _EXTRA = ex |
---|
| 149 | 6:Domdef, Boite,GRILLE=vargrid, _EXTRA = ex |
---|
| 150 | Else: return, report('Mauvaise Definition de Boite') |
---|
| 151 | endcase |
---|
| 152 | ENDIF |
---|
| 153 | grille, mask, glam, gphi, gdep, nx, ny,nz,premierx,premiery, premierz, dernierx, derniery, dernierz |
---|
| 154 | ENDELSE |
---|
| 155 | ;------------------------------------------------------------ |
---|
| 156 | ; determination du nombre de pas de tps a extraire ds ce fichier |
---|
| 157 | ;------------------------------------------------------------ |
---|
| 158 | if nbretps gt 36+1*(mmdd ne '0101')-numsort+1 then nt=36+1*(mmdd ne '0101')-numsort+1 $ |
---|
| 159 | else nt=nbretps |
---|
| 160 | ;------------------------------------------------------------ |
---|
| 161 | ; |
---|
| 162 | if varcontient.ndims eq 3 then $ |
---|
| 163 | ncdf_varget,cdfid,nom,res,offset=[premierx,premiery,numsort-1],count=[nx,ny,nt] $ |
---|
| 164 | else $ |
---|
| 165 | ncdf_varget,cdfid,nom,res,offset=[premierx,premiery, premierz,numsort-1],count=[nx,ny,nz,nt] |
---|
| 166 | ;------------------------------------------------------------ |
---|
| 167 | ; rappel en boucle de nlec si il faut ouvrir de nouveaux fichiers |
---|
| 168 | ; pour constituer la serie temporelle |
---|
| 169 | ;------------------------------------------------------------ |
---|
| 170 | if nbretps gt 36+1*(mmdd ne '0101')-numsort+1 then begin |
---|
| 171 | if mmdd ne '0101' then year = year+1 |
---|
| 172 | if varcontient.ndims eq 3 then $ |
---|
| 173 | res = [[[res]] $ |
---|
| 174 | ,[[nlec5j(nom,1+36*(mmdd eq '0101'),nbretps-nt,tout=tout,GRILLE=vargrid,BOITE=boite)]]] $ |
---|
| 175 | ELSE BEGIN |
---|
| 176 | res=[res[*] $ |
---|
| 177 | ,(nlec5j(nom,1+36*(mmdd eq '0101'),nbretps-nt,tout=tout,GRILLE=vargrid, BOITE=boite))[*]] |
---|
| 178 | res=reform(res,nx,ny,nz,nbretps, /over) |
---|
| 179 | ENDELSE |
---|
| 180 | ncdf_varget,cdfid,'time_counter',temps, offset = [numsort-1],count=[nt] |
---|
| 181 | time = [long(temps)+julday(1, 5, 1979), time] |
---|
| 182 | jpt=nt+jpt |
---|
| 183 | endif else BEGIN |
---|
| 184 | ncdf_varget,cdfid,'time_counter',temps, offset = [numsort-1],count=[nt] |
---|
| 185 | time = long(temps)+julday(1, 5, 1979) |
---|
| 186 | jpt=nt |
---|
| 187 | endelse |
---|
| 188 | ;------------------------------------------------------------ |
---|
| 189 | ncdf_close,cdfid |
---|
| 190 | return,res |
---|
| 191 | ;------------------------------------------------------------ |
---|
| 192 | ;------------------------------------------------------------ |
---|
| 193 | end |
---|