source: trunk/LECTURE/ncdf_lec.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: 5.5 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   res = -1
45;------------------------------------------------------------
46   if NOT keyword_set(IODIR) then iodir = ''
47   if not(keyword_set(att) or keyword_set(dim) or keyword_set(var)) then BEGIN
48      att = 1
49      dim = 1
50      var = 1
51;      commande='ncdump -c '+iodir+nom
52;      spawn,commande
53;      goto,fini
54   endif
55;------------------------------------------------------------
56; ouverture du fichier nom
57;------------------------------------------------------------
58   cdfid=ncdf_open(iodir+nom)
59;------------------------------------------------------------
60; que contient le fichier??
61;------------------------------------------------------------
62   wathinside=ncdf_inquire(cdfid)
63;   print,'dans le fichier, ',iodir+nom,', il y a:'
64   if keyword_set(dim) then begin
65      print,'nombre de dimensions: ',strtrim(wathinside.ndims,1)
66      print,'numero de la dimension dont la valeur est infini: ',strtrim(wathinside.recdim,1)
67   endif
68   if keyword_set(var) then $
69    if size(var, /type) NE 7 then print,'nombre de variables  :',strtrim(wathinside.nvars,1)
70   if keyword_set(att) then begin
71      if strlowcase(att) ne 'global' then goto,nonglobal
72      print,'nombre de attributs globaux :',strtrim(wathinside.ngatts,1)
73   endif
74;------------------------------------------------------------
75; attributs globaux
76;------------------------------------------------------------
77   if keyword_set(att) then begin
78      print, '----------------------------'
79      print,'ATTRIBUTS GLOBAUX'
80      for attiq=0,wathinside.ngatts-1 do begin
81         name=ncdf_attname(cdfid,attiq,/global) ;nom de l''atribut
82         ncdf_attget,cdfid,name,value,/global ;valeur de l''atribut
83         print,name,': ',string(value)
84      endfor
85   endif
86nonglobal:
87;------------------------------------------------------------
88; affichage des differentes dimensions
89;------------------------------------------------------------
90   if keyword_set(dim) then begin
91      print, '----------------------------'
92      print,'DIMENSIONS'
93   endif
94   nomdim   =strarr(wathinside.ndims)
95   tailledim=lonarr(wathinside.ndims)
96   for dimiq=0,wathinside.ndims-1 do begin
97      ncdf_diminq,cdfid,dimiq,name,value ; nom et valeur de la dimension
98      nomdim[dimiq]=name
99      tailledim[dimiq]=value
100      if keyword_set(dim) then begin
101         print,'dimension numero ',strtrim(dimiq,1),', nom: ',nomdim[dimiq] $
102          ,', valeur: ' ,strtrim(tailledim[dimiq],1)
103      endif
104   endfor
105;------------------------------------------------------------
106; affichage des differentes variables
107;------------------------------------------------------------
108;
109   if keyword_set(att) or keyword_set(var) then begin
110; vature de var ? string ou 1
111   help, var, output = nature
112   if (strpos(nature, 'STRING'))[0] NE -1 then nature = 'string' ELSE nature = '1'
113; si on doit juste lire la variable
114   if nature EQ 'string' then begin
115      ncdf_varget, cdfid, var, res, _extra = ex
116      GOTO, sortie
117   ENDIF
118; si c''est pour avoir des renseignements
119   if not keyword_set(att) then att='rien'
120      print, '----------------------------'
121      for varid=0,wathinside.nvars-1 do begin
122         varcontent=ncdf_varinq(cdfid,varid) ; que contient la variable
123         if strlowcase(att) eq strlowcase(varcontent.name) or keyword_set(var) $
124          then begin
125            print,'variable numero: ',strtrim(varid,1),', nom:',varcontent.name $
126             ,', type:' ,varcontent.datatype,', dimensions:',nomdim(varcontent.dim)
127            if strlowcase(att) eq strlowcase(varcontent.name) then begin
128               for attiq=0,varcontent.natts-1 do begin
129                  name=ncdf_attname(cdfid,varid,attiq)
130                  ncdf_attget,cdfid,varid,name,value
131                  print,'     ',strtrim(attiq),' ',name,': ',strtrim(string(value),1)
132               endfor
133               goto, sortie
134            endif
135         endif
136      endfor
137   endif
138;------------------------------------------------------------
139sortie:
140   ncdf_close,cdfid
141;------------------------------------------------------------
142;------------------------------------------------------------
143fini:
144
145   return, res
146end
Note: See TracBrowser for help on using the repository browser.