source: trunk/LECTURE/nlec5j.pro @ 2

Last change on this file since 2 was 2, checked in by opalod, 22 years ago

Initial revision

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