source: trunk/SRC/ToBeReviewed/LECTURE/ncdf_lec.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:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.4 KB
Line 
1;+
2;
3; @file_comments
4; Give informations on a file netcdf and allows to recuperate
5; variables which are written in it.
6;
7; @categories
8; Reading
9;
10; @param NOM {in}{required}
11; Name of a file netcdf located in the directory stipulated by iodir.
12;
13; @keyword ATT
14; 'global' or the name of a variable. Allows to see all attributes
15; associated to variable
16;
17; @keyword DIM
18; Give the list of dimensions.
19;
20; @keyword VAR
21;       1) /var: Give the list of dimensions.
22;       2) var='name_of_a_variable': in this case the function send back the variable.
23;
24; @keyword IODIR
25; String containing the directory containing the file to be read
26;
27; @keyword _EXTRA
28; Used to pass keywords defined by IDL to functions NETCDF (especially OFFSET
29; and COUNT in <proidl>NCDF_VARGET</proidl>)
30;
31; @returns
32; -1 (except if var='nom de variable', then the function send back the variable).
33;
34; @restrictions
35; Variables's names of the program are similar to these used by the IDL manual
36; 'scientific data formats'
37;
38; @history
39; Sebastien Masson (smasson\@lodyc.jussieu.fr)
40;                       4/1/98
41;
42; @version
43; $Id$
44;
45;-
46FUNCTION ncdf_lec,nom,ATT=att,DIM=dim,VAR=var, IODIR = iodir, _EXTRA = ex
47;
48  compile_opt idl2, strictarrsubs
49;
50   res = -1
51;------------------------------------------------------------
52   if NOT keyword_set(IODIR) then iodir = ''
53   if not(keyword_set(att) or keyword_set(dim) or keyword_set(var)) then BEGIN
54      att = 1
55      dim = 1
56      var = 1
57;      commande='ncdump -c '+iodir+nom
58;      spawn,commande
59;      goto,fini
60   endif
61;------------------------------------------------------------
62; opening of the file name.
63;------------------------------------------------------------
64   cdfid=ncdf_open(iodir+nom)
65;------------------------------------------------------------
66; What does the file contain??
67;------------------------------------------------------------
68   wathinside=ncdf_inquire(cdfid)
69;   print,'in the file, ',iodir+nom,', there are:'
70   if keyword_set(dim) then begin
71      ras = report(['number of dimensions: ' + strtrim(wathinside.ndims,1), $
72      'number of the dimension which value is infinite : ',strtrim(wathinside.recdim,1)])
73   endif
74   if keyword_set(var) then $
75    if size(var, /type) NE 7 then ras = report('number of variables  :'+strtrim(wathinside.nvars,1))
76   if keyword_set(att) then begin
77      if strlowcase(att) ne 'global' then goto,nonglobal
78      ras = report('number of global attributes :' + strtrim(wathinside.ngatts,1))
79   endif
80;------------------------------------------------------------
81; Global attributes
82;------------------------------------------------------------
83   if keyword_set(att) then begin
84      print, '----------------------------'
85      print,'ATTRIBUTS GLOBAUX'
86      for attiq=0,wathinside.ngatts-1 do begin
87         name=ncdf_attname(cdfid,attiq,/global) ;attribute's name
88         ncdf_attget,cdfid,name,value,/global ;attribute's value
89         ras = report(name + ': ' + string(value))
90      endfor
91   endif
92nonglobal:
93;------------------------------------------------------------
94; Display of different dimensions.
95;------------------------------------------------------------
96   if keyword_set(dim) then begin
97      print, '----------------------------'
98      print,'DIMENSIONS'
99   endif
100   nomdim   =strarr(wathinside.ndims)
101   tailledim=lonarr(wathinside.ndims)
102   for dimiq=0,wathinside.ndims-1 do begin
103      ncdf_diminq,cdfid,dimiq,name,value ; dimension's name and value
104      nomdim[dimiq]=name
105      tailledim[dimiq]=value
106      if keyword_set(dim) then begin
107         ras = report('dimension number ' + strtrim(dimiq,1) + ', name: ' + $
108               nomdim[dimiq] + ' value: ' + strtrim(tailledim[dimiq],1))
109      endif
110   endfor
111;------------------------------------------------------------
112; Display of different variables.
113;------------------------------------------------------------
114;
115   if keyword_set(att) or keyword_set(var) then begin
116; var's value? string or 1
117   help, var, output = nature
118   if (strpos(nature, 'STRING'))[0] NE -1 then nature = 'string' ELSE nature = '1'
119; If we just have to read the variable.
120   if nature EQ 'string' then begin
121      ncdf_varget, cdfid, var, res, _extra = ex
122      GOTO, sortie
123   ENDIF
124; If it is to have pieces of information.
125   if not keyword_set(att) then att='rien'
126      print, '----------------------------'
127      for varid=0,wathinside.nvars-1 do begin
128         varcontent=ncdf_varinq(cdfid,varid) ; What does variable contain??
129         if strlowcase(att) eq strlowcase(varcontent.name) or keyword_set(var) $
130          then begin
131            ras = report('variable number: ' + strtrim(varid,1) + $
132                  ', name:' + varcontent.name + $
133                  ', type:' + varcontent.datatype + $
134                  ', dimensions:' + nomdim[varcontent.dim])
135            if strlowcase(att) eq strlowcase(varcontent.name) then begin
136               for attiq=0,varcontent.natts-1 do begin
137                  name=ncdf_attname(cdfid,varid,attiq)
138                  ncdf_attget,cdfid,varid,name,value
139                  ras = report('     ' + strtrim(attiq) + ' ' + $
140                        ' name : ' + strtrim(string(value),1))
141               endfor
142               goto, sortie
143            endif
144         endif
145      endfor
146   endif
147;------------------------------------------------------------
148sortie:
149   ncdf_close,cdfid
150;------------------------------------------------------------
151;------------------------------------------------------------
152fini:
153
154   return, res
155end
Note: See TracBrowser for help on using the repository browser.