source: trunk/SRC/Obsolete/nlec5j.pro @ 134

Last change on this file since 134 was 134, checked in by navarro, 18 years ago

change *.pro file properties (del eof-style, del executable, set keywords Id

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