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

Last change on this file since 325 was 325, checked in by pinsard, 17 years ago

modification of some headers (+some corrections) to prepare usage of the new idldoc

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