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

Last change on this file since 114 was 114, checked in by smasson, 18 years ago

new compilation options (compile_opt idl2, strictarrsubs) in each routine

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