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 | ;- |
---|
46 | ; |
---|
47 | FUNCTION ncdf_lec,nom,ATT=att,DIM=dim,VAR=var, IODIR = iodir, _EXTRA = ex |
---|
48 | ; |
---|
49 | compile_opt idl2, strictarrsubs |
---|
50 | ; |
---|
51 | res = -1 |
---|
52 | ;------------------------------------------------------------ |
---|
53 | if NOT keyword_set(IODIR) then iodir = '' |
---|
54 | if not(keyword_set(att) or keyword_set(dim) or keyword_set(var)) then BEGIN |
---|
55 | att = 1 |
---|
56 | dim = 1 |
---|
57 | var = 1 |
---|
58 | ; commande='ncdump -c '+iodir+nom |
---|
59 | ; spawn,commande |
---|
60 | ; goto,fini |
---|
61 | endif |
---|
62 | ;------------------------------------------------------------ |
---|
63 | ; opening of the file name. |
---|
64 | ;------------------------------------------------------------ |
---|
65 | cdfid=ncdf_open(iodir+nom) |
---|
66 | ;------------------------------------------------------------ |
---|
67 | ; What does the file contain?? |
---|
68 | ;------------------------------------------------------------ |
---|
69 | wathinside=ncdf_inquire(cdfid) |
---|
70 | ; print,'in the file, ',iodir+nom,', there are:' |
---|
71 | if keyword_set(dim) then begin |
---|
72 | ras = report(['number of dimensions: ' + strtrim(wathinside.ndims,1), $ |
---|
73 | 'number of the dimension which value is infinite : ',strtrim(wathinside.recdim,1)]) |
---|
74 | endif |
---|
75 | if keyword_set(var) then $ |
---|
76 | if size(var, /type) NE 7 then ras = report('number of variables :'+strtrim(wathinside.nvars,1)) |
---|
77 | if keyword_set(att) then begin |
---|
78 | if strlowcase(att) ne 'global' then goto,nonglobal |
---|
79 | ras = report('number of global attributes :' + strtrim(wathinside.ngatts,1)) |
---|
80 | endif |
---|
81 | ;------------------------------------------------------------ |
---|
82 | ; Global attributes |
---|
83 | ;------------------------------------------------------------ |
---|
84 | if keyword_set(att) then begin |
---|
85 | print, '----------------------------' |
---|
86 | print,'ATTRIBUTS GLOBAUX' |
---|
87 | for attiq=0,wathinside.ngatts-1 do begin |
---|
88 | name=ncdf_attname(cdfid,attiq,/global) ;attribute's name |
---|
89 | ncdf_attget,cdfid,name,value,/global ;attribute's value |
---|
90 | ras = report(name + ': ' + string(value)) |
---|
91 | endfor |
---|
92 | endif |
---|
93 | nonglobal: |
---|
94 | ;------------------------------------------------------------ |
---|
95 | ; Display of different dimensions. |
---|
96 | ;------------------------------------------------------------ |
---|
97 | if keyword_set(dim) then begin |
---|
98 | print, '----------------------------' |
---|
99 | print,'DIMENSIONS' |
---|
100 | endif |
---|
101 | nomdim =strarr(wathinside.ndims) |
---|
102 | tailledim=lonarr(wathinside.ndims) |
---|
103 | for dimiq=0,wathinside.ndims-1 do begin |
---|
104 | ncdf_diminq,cdfid,dimiq,name,value ; dimension's name and value |
---|
105 | nomdim[dimiq]=name |
---|
106 | tailledim[dimiq]=value |
---|
107 | if keyword_set(dim) then begin |
---|
108 | ras = report('dimension number ' + strtrim(dimiq,1) + ', name: ' + $ |
---|
109 | nomdim[dimiq] + ' value: ' + strtrim(tailledim[dimiq],1)) |
---|
110 | endif |
---|
111 | endfor |
---|
112 | ;------------------------------------------------------------ |
---|
113 | ; Display of different variables. |
---|
114 | ;------------------------------------------------------------ |
---|
115 | ; |
---|
116 | if keyword_set(att) or keyword_set(var) then begin |
---|
117 | ; var's value? string or 1 |
---|
118 | help, var, output = nature |
---|
119 | if (strpos(nature, 'STRING'))[0] NE -1 then nature = 'string' ELSE nature = '1' |
---|
120 | ; If we just have to read the variable. |
---|
121 | if nature EQ 'string' then begin |
---|
122 | ncdf_varget, cdfid, var, res, _extra = ex |
---|
123 | GOTO, sortie |
---|
124 | ENDIF |
---|
125 | ; If it is to have pieces of information. |
---|
126 | if not keyword_set(att) then att='rien' |
---|
127 | print, '----------------------------' |
---|
128 | for varid=0,wathinside.nvars-1 do begin |
---|
129 | varcontent=ncdf_varinq(cdfid,varid) ; What does variable contain?? |
---|
130 | if strlowcase(att) eq strlowcase(varcontent.name) or keyword_set(var) $ |
---|
131 | then begin |
---|
132 | ras = report('variable number: ' + strtrim(varid,1) + $ |
---|
133 | ', name:' + varcontent.name + $ |
---|
134 | ', type:' + varcontent.datatype + $ |
---|
135 | ', dimensions:' + nomdim[varcontent.dim]) |
---|
136 | if strlowcase(att) eq strlowcase(varcontent.name) then begin |
---|
137 | for attiq=0,varcontent.natts-1 do begin |
---|
138 | name=ncdf_attname(cdfid,varid,attiq) |
---|
139 | ncdf_attget,cdfid,varid,name,value |
---|
140 | ras = report(' ' + strtrim(attiq) + ' ' + $ |
---|
141 | ' name : ' + strtrim(string(value),1)) |
---|
142 | endfor |
---|
143 | goto, sortie |
---|
144 | endif |
---|
145 | endif |
---|
146 | endfor |
---|
147 | endif |
---|
148 | ;------------------------------------------------------------ |
---|
149 | sortie: |
---|
150 | ncdf_close,cdfid |
---|
151 | ;------------------------------------------------------------ |
---|
152 | ;------------------------------------------------------------ |
---|
153 | fini: |
---|
154 | |
---|
155 | return, res |
---|
156 | end |
---|