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