source: trunk/SRC/ToBeReviewed/LECTURE/ncdf_lec.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: 5.6 KB
Line 
1;------------------------------------------------------------
2;------------------------------------------------------------
3;------------------------------------------------------------
4;+
5; NAME:ncdflec
6;
7; PURPOSE:donne des infos sur un fichier netcdf et permet de recupere
8; les variables qui y sont ecrites
9;
10; CATEGORY:lecture de fichiers netcdf
11;
12; CALLING SEQUENCE: res=ncdflec('nom_de _fichier')
13;
14; INPUTS:nom_de _fichier:nom d'un fichier net cdf situe ds e repertoire
15; stipule par iodir
16;
17; KEYWORD PARAMETERS:
18;
19;       ATT: 'global' ou au nom d'une variable. permet de voir tous les
20; attributs rattaches a une variable.
21;
22;       /DIM:donne la liste des dimensions
23;
24;       VAR:
25;       1) /var: donne la liste des variables
26;       2) var='nom de variable': ds ce cas la fonction retourne la variable
27;
28;       IODIR: string contenant le repertoire ou aller chercher le
29;       fichier a lire.
30;
31;       _EXTRA: permet de passer les mots cles definits par IDL pour
32;       les fonction NETCDF (en particulier OFFSET et COUNT ds ncdf_varget)
33;
34; OUTPUTS:-1 sauf si var='nom de variable' auquel cas la fonction retourne la variable
35;
36; REMARQUE:les noms des variables du programme sont similaires a ceux employes
37; ds le manuel IDL 'scientific data formats'
38;
39; MODIFICATION HISTORY: Sebastien Masson (smasson@lodyc.jussieu.fr)
40;                       4/1/98
41;-
42;------------------------------------------------------------
43function ncdf_lec,nom,ATT=att,DIM=dim,VAR=var, IODIR = iodir, _extra = ex
44;
45  compile_opt idl2, strictarrsubs
46;
47   res = -1
48;------------------------------------------------------------
49   if NOT keyword_set(IODIR) then iodir = ''
50   if not(keyword_set(att) or keyword_set(dim) or keyword_set(var)) then BEGIN
51      att = 1
52      dim = 1
53      var = 1
54;      commande='ncdump -c '+iodir+nom
55;      spawn,commande
56;      goto,fini
57   endif
58;------------------------------------------------------------
59; ouverture du fichier nom
60;------------------------------------------------------------
61   cdfid=ncdf_open(iodir+nom)
62;------------------------------------------------------------
63; que contient le fichier??
64;------------------------------------------------------------
65   wathinside=ncdf_inquire(cdfid)
66;   print,'dans le fichier, ',iodir+nom,', il y a:'
67   if keyword_set(dim) then begin
68      print,'nombre de dimensions: ',strtrim(wathinside.ndims,1)
69      print,'numero de la dimension dont la valeur est infini: ',strtrim(wathinside.recdim,1)
70   endif
71   if keyword_set(var) then $
72    if size(var, /type) NE 7 then print,'nombre de variables  :',strtrim(wathinside.nvars,1)
73   if keyword_set(att) then begin
74      if strlowcase(att) ne 'global' then goto,nonglobal
75      print,'nombre de attributs globaux :',strtrim(wathinside.ngatts,1)
76   endif
77;------------------------------------------------------------
78; attributs globaux
79;------------------------------------------------------------
80   if keyword_set(att) then begin
81      print, '----------------------------'
82      print,'ATTRIBUTS GLOBAUX'
83      for attiq=0,wathinside.ngatts-1 do begin
84         name=ncdf_attname(cdfid,attiq,/global) ;nom de l''atribut
85         ncdf_attget,cdfid,name,value,/global ;valeur de l''atribut
86         print,name,': ',string(value)
87      endfor
88   endif
89nonglobal:
90;------------------------------------------------------------
91; affichage des differentes dimensions
92;------------------------------------------------------------
93   if keyword_set(dim) then begin
94      print, '----------------------------'
95      print,'DIMENSIONS'
96   endif
97   nomdim   =strarr(wathinside.ndims)
98   tailledim=lonarr(wathinside.ndims)
99   for dimiq=0,wathinside.ndims-1 do begin
100      ncdf_diminq,cdfid,dimiq,name,value ; nom et valeur de la dimension
101      nomdim[dimiq]=name
102      tailledim[dimiq]=value
103      if keyword_set(dim) then begin
104         print,'dimension numero ',strtrim(dimiq,1),', nom: ',nomdim[dimiq] $
105          ,', valeur: ' ,strtrim(tailledim[dimiq],1)
106      endif
107   endfor
108;------------------------------------------------------------
109; affichage des differentes variables
110;------------------------------------------------------------
111;
112   if keyword_set(att) or keyword_set(var) then begin
113; vature de var ? string ou 1
114   help, var, output = nature
115   if (strpos(nature, 'STRING'))[0] NE -1 then nature = 'string' ELSE nature = '1'
116; si on doit juste lire la variable
117   if nature EQ 'string' then begin
118      ncdf_varget, cdfid, var, res, _extra = ex
119      GOTO, sortie
120   ENDIF
121; si c''est pour avoir des renseignements
122   if not keyword_set(att) then att='rien'
123      print, '----------------------------'
124      for varid=0,wathinside.nvars-1 do begin
125         varcontent=ncdf_varinq(cdfid,varid) ; que contient la variable
126         if strlowcase(att) eq strlowcase(varcontent.name) or keyword_set(var) $
127          then begin
128            print,'variable numero: ',strtrim(varid,1),', nom:',varcontent.name $
129             ,', type:' ,varcontent.datatype,', dimensions:',nomdim[varcontent.dim]
130            if strlowcase(att) eq strlowcase(varcontent.name) then begin
131               for attiq=0,varcontent.natts-1 do begin
132                  name=ncdf_attname(cdfid,varid,attiq)
133                  ncdf_attget,cdfid,varid,name,value
134                  print,'     ',strtrim(attiq),' ',name,': ',strtrim(string(value),1)
135               endfor
136               goto, sortie
137            endif
138         endif
139      endfor
140   endif
141;------------------------------------------------------------
142sortie:
143   ncdf_close,cdfid
144;------------------------------------------------------------
145;------------------------------------------------------------
146fini:
147
148   return, res
149end
Note: See TracBrowser for help on using the repository browser.