param_info.pro
10.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
; $Id: param_info.pro,v 1.4 2009/03/30 15:45:33 budnik Exp $
;
;+
; NAME:
; PARAM_INFO
;
; PURPOSE:
; gets CDAWEB parameter Info
; to create AMDA parameter automatically
;
;
; CALLING SEQUENCE:
;
; PARAM_INFO, CDF_name, ParID
;
; INPUTS:
; CDF_name: CDF file name (master CDF or data CDF)
; ParID : variable name in CDF notation
;
; KEYWORD PARAMETERS:
;
;
; OUTPUTS:
; string "paramID%....."
;
; MODIFICATION HISTORY:
; Written by: Elena Budnik
; September, 2007
;-
pro Param_Info, CDF_name, ParID
NODATA = "%-9999"
;------------------- List of Param Attributes used for AMDA ----------------
AttributesGlobal = ["Source_name", "Descriptor", "Data_type", "Instrument_type"]
AttributesCommon = ["FIELDNAM", "DISPLAY_TYPE", "UNITS", "FILLVAL", "Frame", "VALIDMIN","VALIDMAX", "SI_conversion"]
; ALSO EXIST "DICT_KEY", "CATDESC", "AVG_TYPE"
AttributeScalar = ["LABLAXIS"]
AttributeVector = ["LABL_PTR_1"]
if (file_test(CDF_name) eq 0) then begin
print, NODATA
return
endif
Output = "paramID%" + strjoin(strsplit(ParID,"%&.><",/EXTRACT),"_");
cdfID = cdf_open(CDF_name)
;---------------- Get Global Attributes ----------------------
On_IoError, NoGlobalAttr
for i = 0, n_elements(AttributesGlobal) - 1 do begin
if (cdf_attexists(cdfid, AttributesGlobal[i])) then cdf_attget, cdfid, AttributesGlobal[i], 0, attvalue $
else cdf_attget, cdfid, strupcase(AttributesGlobal[i]), 0, attvalue
Output += "&&"+strupcase(AttributesGlobal[i])+"%" + strcompress(string(attvalue))
continue;
NoGlobalAttr: Output += "&&"+strupcase(AttributesGlobal[i]) + NODATA
endfor
On_IoError, NULL
;--------------- Get parameter Number -----------------------
par_num = cdf_varnum(cdfid, ParID, IsZVar);
;----------- Attributes & Dims for R-vars -----------------------------
if (IsZVar eq 0) then begin ; r-variable
glob = cdf_inquire(cdfid)
info = cdf_varinq(cdfid, par_num)
outDim = ""
if (glob.ndims eq 0) then dim = 1 else begin
numDim = where(info.dimvar eq 1, ndim)
if (ndim GT 0) then dim = glob.dim[numDim] else dim = 1
endelse
if (n_elements(dim) eq 1) then outDim = string(dim,format='(i3.3)') else $
for j = 0, n_elements(dim)-1 do outDim +=string(dim[j],format='(i3.3)')+","
;---------- CDF data types to DD
case info.datatype of
"CDF_CHAR": datatype = 0; DD_CHAR
"CDF_BYTE": datatype = 5;
"CDF_INT1": datatype = 5;
"CDF_INT2": datatype = 4; DD_SHORT
"CDF_UCHAR": datatype = 4;
"CDF_UINT1": datatype = 4;
"CDF_INT4": datatype = 1; DD_INT
"CDF_UINT2": datatype = 1;
"CDF_FLOAT": datatype = 2; DD_FLOAT
"CDF_REAL4": datatype = 2;
"CDF_DOUBLE": datatype = 3; DD_DOUBLE
"CDF_REAL8": datatype = 3;
"CDF_UINT4": datatype = 3;
end
Output += "&&DATATYPE%" + strcompress(string(datatype)) + "&&DIMENSION%" + outDim
On_IoError, NoAttr
for i = 0, N_elements(AttributesCommon)-1 do begin
if (cdf_attexists(cdfid, AttributesCommon[i])) then begin
cdf_attget, cdfid, AttributesCommon[i], par_num, attvalue
Output += "&&"+strupcase(AttributesCommon[i])+"%" + strcompress(string(attvalue))
endif else Output += "&&"+strupcase(AttributesCommon[i])+NODATA
continue
NoAttr : Output += "&&"+strupcase(AttributesCommon[i])+NODATA
endfor
if (n_elements(dim) eq 1 AND dim[0] eq 1) then begin
On_IoError, NoAttr1
cdf_attget, cdfid, AttributeScalar[0], par_num, attvalue
Output += "&&"+AttributeScalar[0]+"%" + strcompress(string(attvalue))
GOTO, CONT
NoAttr1: Output += "&&"+AttributeScalar[0]+NODATA
endif else begin
On_IoError, NoAttr2
cdf_attget, cdfid, "LABL_PTR_1", par_num, attvalue
var_num = cdf_varnum(cdfid, attvalue, IsZvar)
temp=strarr(dim)
if (IsZVar) then cdf_varget, cdfid, var_num, temp, /STRING, /ZVariable $
else cdf_varget, cdfid, var_num, temp, /STRING
labelOutput = ""
; Crazy stuff - don't understand how to treat
t_sort = temp(sort(reform(temp,N_elements(temp))))
t_temp = t_sort(uniq(t_sort))
for j = 0, N_elements(t_temp) - 1 do labelOutput += string(t_temp[j])+"$"
Output += "&&LABLAXIS%" + strcompress(labelOutput)
GOTO, CONT
NoAttr2: On_IoError, NoAttr3
cdf_attget, cdfid, "DEPEND_1", par_num, attvalue
var_num = cdf_varnum(cdfid, attvalue, IsZvar)
cdf_attget, cdfid, "LABL_PTR_1", var_num, attvalue
var_num = cdf_varnum(cdfid, attvalue, IsZvar)
temp=strarr(dim)
if (IsZVar) then cdf_varget,cdfid, var_num, temp, /STRING, /ZVARIABLE $
else cdf_varget,cdfid, var_num, temp, /STRING
labelOutput = ""
t_temp = temp(uniq(temp))
for j = 0, N_elements(t_temp)-1 do labelOutput += string(t_temp[j])+"$"
Output += "&&LABLAXIS%" + strcompress(labelOutput)
GOTO, CONT
NoAttr3: Output += "&&LABLAXIS"+NODATA
endelse
CONT: On_IoError, NoAttr4
if (cdf_attexists(cdfid, "VIRTUAL")) then begin
cdf_attget, cdfid, "VIRTUAL", par_num, attvalue
if (attvalue eq "TRUE") then begin
cdf_attget, cdfid, "COMPONENT_0", par_num, attvalue
Output += "&&VIRTUAL%" + attvalue
endif
endif
NoAttr4: On_IoError, NULL
endif else begin ; z-Variable
;----------- Attributes & Dims for Z-vars -----------------------------
info = cdf_varinq(cdfid, par_num, /Z)
if (n_elements(info.dimvar) GT 1) then begin
print, NODATA
return
endif
if (info.dimvar eq 0) then dim = 1 else dim = info.dim
;---------- CDF data types to DD
case info.datatype of
"CDF_CHAR": datatype = 0; DD_CHAR
"CDF_BYTE": datatype = 5;
"CDF_INT1": datatype = 5;
"CDF_INT2": datatype = 4; DD_SHORT
"CDF_UCHAR": datatype = 4;
"CDF_UINT1": datatype = 4;
"CDF_INT4": datatype = 1; DD_INT
"CDF_UINT2": datatype = 1;
"CDF_FLOAT": datatype = 2; DD_FLOAT
"CDF_REAL4": datatype = 2;
"CDF_DOUBLE": datatype = 3; DD_DOUBLE
"CDF_REAL8": datatype = 3;
"CDF_UINT4": datatype = 3;
end
Output += "&&DATATYPE%" + strcompress(string(datatype))+"&&DIMENSION%"+string(dim,format='(i3.3)')
On_IoError, NoAttrZ
for i = 0, N_elements(AttributesCommon)-1 do begin
if (cdf_attexists(cdfid, AttributesCommon[i])) then begin
cdf_attget, cdfid, AttributesCommon[i], par_num, attvalue, /ZVARIABLE
Output += "&&"+strupcase(AttributesCommon[i])+"%" + strcompress(string(attvalue))
endif else Output += "&&"+strupcase(AttributesCommon[i])+NODATA
continue
NoAttrZ: Output += "&&"+strupcase(AttributesCommon[i])+NODATA
endfor
if (dim eq 1) then begin
On_IoError, NoAttrZ1
cdf_attget, cdfid, AttributeScalar[0], par_num, attvalue, /ZVARIABLE
Output += "&&"+AttributeScalar[0]+"%" + strcompress(string(attvalue))
GOTO, CONT1
NoAttrZ1: Output += "&&"+AttributeScalar[0]+NODATA
endif else begin
On_IoError, NoAttrZ2
cdf_attget, cdfid, "LABL_PTR_1", par_num, attvalue, /ZVARIABLE
var_num = cdf_varnum(cdfid, attvalue, IsZvar)
temp=strarr(dim)
if (IsZVar) then cdf_varget,cdfid, var_num, temp, /STRING, /ZVARIABLE $
else cdf_varget,cdfid, var_num, temp, /STRING
labelOutput = ""
t_temp = temp(uniq(temp))
for j = 0, N_elements(t_temp)-1 do labelOutput += string(t_temp[j])+"$"
Output += "&&LABLAXIS%" + strcompress(labelOutput)
GOTO, CONT1
NoAttrZ2:
On_IoError, NoAttrZ3
cdf_attget, cdfid, "DEPEND_1", par_num, attvalue, /ZVARIABLE
var_num = cdf_varnum(cdfid, attvalue, IsZvar)
cdf_attget, cdfid, "LABL_PTR_1", var_num, attvalue, /ZVARIABLE
var_num = cdf_varnum(cdfid, attvalue, IsZvar)
temp=strarr(dim)
if (IsZVar) then cdf_varget,cdfid, var_num, temp, /STRING, /ZVARIABLE $
else cdf_varget,cdfid, var_num, temp, /STRING
labelOutput = ""
t_temp = temp(uniq(temp))
for j = 0, N_elements(t_temp)-1 do labelOutput += string(t_temp[j])+"$"
Output += "&&LABLAXIS%" + strcompress(labelOutput)
GOTO, CONT1
NoAttrZ3: Output += "&&LABLAXIS"+NODATA
endelse
CONT1: On_IoError, NoAttrZ4
if (cdf_attexists(cdfid, "VIRTUAL",/ZVARIABLE)) then begin
cdf_attget, cdfid, "VIRTUAL", par_num, attvalue, /ZVARIABLE
if (attvalue eq "TRUE") then begin
cdf_attget, cdfid, "COMPONENT_0", par_num, attvalue, /ZVARIABLE
Output += "&&VIRTUAL%" + attvalue
endif
endif
NoAttrZ4: On_IoError, NULL
endelse
cdf_close,cdfID
print, output
return
end