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