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

Last change on this file since 370 was 370, checked in by pinsard, 16 years ago

improvemnts of headers (typo, links)

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