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