Commit 7d5742d0967ca171e216bb703a892c54e459e804
1 parent
655e355f
Exists in
master
and in
109 other branches
cdf attribute info
Showing
3 changed files
with
407 additions
and
230 deletions
Show diff stats
php/src/Makefile
@@ -5,7 +5,7 @@ CC = gcc | @@ -5,7 +5,7 @@ CC = gcc | ||
5 | 5 | ||
6 | EXE = nctimestring2double nctimeinfo getncvars ncvarinfo \ | 6 | EXE = nctimestring2double nctimeinfo getncvars ncvarinfo \ |
7 | ncinfo_remote \ | 7 | ncinfo_remote \ |
8 | - cdfinfo cdfvarinfo cdfstartstopfromdata cdfsamplingfromdata \ | 8 | + cdfinfo cdfvarinfo cdfstartstopfromdata cdfsamplingfromdata cdfvar_attr \ |
9 | AddVI | 9 | AddVI |
10 | 10 | ||
11 | lib: ${EXE} | 11 | lib: ${EXE} |
@@ -48,7 +48,10 @@ cdfinfo: cdfinfo.c | @@ -48,7 +48,10 @@ cdfinfo: cdfinfo.c | ||
48 | 48 | ||
49 | cdfvarinfo: cdfvarinfo.c | 49 | cdfvarinfo: cdfvarinfo.c |
50 | ${CC} ${CFLAGS} -o cdfvarinfo cdfvarinfo.c ${INC} ${LIB} -lcdf | 50 | ${CC} ${CFLAGS} -o cdfvarinfo cdfvarinfo.c ${INC} ${LIB} -lcdf |
51 | - | 51 | + |
52 | +cdfvar_attr: cdfvar_attr.c | ||
53 | + ${CC} ${CFLAGS} -o cdfvar_attr cdfvar_attr.c ${INC} ${LIB} -lcdf | ||
54 | + | ||
52 | cdfstartstopfromdata: cdfstartstopfromdata.c | 55 | cdfstartstopfromdata: cdfstartstopfromdata.c |
53 | ${CC} ${CFLAGS} -o cdfstartstopfromdata cdfstartstopfromdata.c ${INC} ${LIB} -lcdf | 56 | ${CC} ${CFLAGS} -o cdfstartstopfromdata cdfstartstopfromdata.c ${INC} ${LIB} -lcdf |
54 | 57 |
@@ -0,0 +1,292 @@ | @@ -0,0 +1,292 @@ | ||
1 | +/** | ||
2 | +* @file cdfvarinfo.c | ||
3 | +* @version $Id: cdfvarinfo.c,v 1.1 2010/08/31 10:32:55 budnik Exp $ | ||
4 | +* @brief | ||
5 | +*/ | ||
6 | + | ||
7 | + | ||
8 | +#include <stdio.h> | ||
9 | +#include <stdlib.h> | ||
10 | +#include <cdf.h> | ||
11 | +#include <string.h> | ||
12 | + | ||
13 | +#define MAX_FILE_NAME_LEN 120 | ||
14 | + | ||
15 | +void cdf_status_handler (CDFstatus, char *); | ||
16 | +char * cdf_str_datatype (long); | ||
17 | + | ||
18 | +typedef struct cdfvar { /* CDF variable structure */ | ||
19 | + char name[CDF_VAR_NAME_LEN+1]; | ||
20 | + long datatype; | ||
21 | + long numElements; /* string length for CDF_CHAR, 1 otherwise */ | ||
22 | + long dimensionality; /* variable dimensionality */ | ||
23 | + long dimSizes[CDF_MAX_DIMS]; /* variable dimension sizes */ | ||
24 | + long recVariance; /* record variance */ | ||
25 | + long numRecs; /* # of records this variable contains */ | ||
26 | +} CDFvar; | ||
27 | + | ||
28 | +int main(int argc, char *argv[]) | ||
29 | +{ | ||
30 | + | ||
31 | + CDFvar var; | ||
32 | + CDFid id; /* CDF file ID */ | ||
33 | + CDFstatus status; /* CDF status code */ | ||
34 | + | ||
35 | + long nZvars, nAttrs, attrId, attrScope, varId, datatype, numElements; | ||
36 | + char attrName[CDF_ATTR_NAME_LEN+1]; | ||
37 | + char fileName[MAX_FILE_NAME_LEN], varName[CDF_VAR_NAME_LEN+1], attName[CDF_ATTR_NAME_LEN+1]; | ||
38 | + char msg[100]; | ||
39 | + int dummy, i; | ||
40 | + char *cPtr; | ||
41 | + signed char *scPtr; | ||
42 | + short *sPtr; | ||
43 | + int *iPtr; | ||
44 | + float *fPtr; | ||
45 | + double *dPtr; | ||
46 | + | ||
47 | + | ||
48 | + if (argc <= 3) | ||
49 | + exit(0); /* CDF input file name not specified */ | ||
50 | + else { | ||
51 | + strcpy(fileName, argv[1]); /* Get the input file name */ | ||
52 | + strcpy(varName, argv[2]); | ||
53 | + strcpy(attName, argv[3]); | ||
54 | + } | ||
55 | + | ||
56 | + status = CDFlib (OPEN_, CDF_, fileName, &id, NULL_); | ||
57 | + | ||
58 | + if (status != CDF_OK) { | ||
59 | + strcpy(msg, "OPEN_, CDF_, "); | ||
60 | + strcat(msg, fileName); | ||
61 | + cdf_status_handler (status, msg); | ||
62 | + } | ||
63 | + | ||
64 | + /*--------------------------------------------------------------------------- | ||
65 | + * This routine retrievs the following information: | ||
66 | + * | ||
67 | + * nAttr - number of attributes (including global and variable) | ||
68 | + * nZvars - number of zVariables | ||
69 | + * | ||
70 | + * CDF file can have both rVariables (old style) and zVariables (new style) | ||
71 | + * simultaneously. zVariable is a superset of rVariable, and it is a lot | ||
72 | + * more efficient and offers all the functionality a rVariable offers and | ||
73 | + * more. Treat all CDF variables as zVariables. | ||
74 | + *--------------------------------------------------------------------------*/ | ||
75 | + | ||
76 | + status = CDFlib (SELECT_, CDF_zMODE_, zMODEon2, | ||
77 | + GET_, CDF_NUMATTRS_, &nAttrs, | ||
78 | + CDF_NUMzVARS_, &nZvars, | ||
79 | + NULL_); | ||
80 | + if (status != CDF_OK) cdf_status_handler(status, "GET_, CDF_FILEINFO_"); | ||
81 | + | ||
82 | + // printf(" nAttrs %d Zvars %d\n",nAttrs, nZvars); | ||
83 | + // printf ("Attributes:\n"); | ||
84 | + | ||
85 | + for (attrId = 0; attrId < nAttrs; attrId++) { | ||
86 | + status = CDFlib (SELECT_, ATTR_, attrId, | ||
87 | + GET_, ATTR_NAME_, attrName, ATTR_SCOPE_, &attrScope, | ||
88 | + NULL_); | ||
89 | + | ||
90 | + if (status != CDF_OK) cdf_status_handler (status, "SELECT_, ATTR_"); | ||
91 | + // printf("Attr %d %s %d\n", attrId, attrName, attrScope); | ||
92 | + } | ||
93 | + | ||
94 | + // printf ("Variables:\n"); | ||
95 | + for (varId=0; varId < nZvars; varId++) | ||
96 | + { | ||
97 | + status = CDFlib (SELECT_,zVAR_, varId, | ||
98 | + GET_, zVAR_NAME_, var.name, | ||
99 | + zVAR_DATATYPE_, &var.datatype, | ||
100 | + zVAR_NUMELEMS_, &var.numElements, | ||
101 | + zVAR_NUMDIMS_, &var.dimensionality, | ||
102 | + zVAR_DIMSIZES_, var.dimSizes, | ||
103 | + zVAR_NUMRECS_, &var.numRecs, | ||
104 | + zVAR_RECVARY_, &var.recVariance, | ||
105 | + NULL_); | ||
106 | + if (status != CDF_OK) cdf_status_handler (status, "GET_, zVARS_"); | ||
107 | + | ||
108 | + if (strcmp(var.name, varName) == 0) | ||
109 | + { | ||
110 | + for (attrId = 0; attrId < nAttrs; attrId++) { | ||
111 | + status = CDFlib (SELECT_, ATTR_, attrId, | ||
112 | + GET_, ATTR_NAME_, attrName, ATTR_SCOPE_, &attrScope, | ||
113 | + NULL_); | ||
114 | + | ||
115 | + if (status != CDF_OK) cdf_status_handler (status, "SELECT_, ATTR_"); | ||
116 | + if (attrScope == GLOBAL_SCOPE) continue; | ||
117 | + if (strcasecmp(attrName, attName) != 0) continue; | ||
118 | + | ||
119 | + // printf("%d %s ", attrId, attrName); | ||
120 | + | ||
121 | + status = CDFlib (SELECT_, zENTRY_, varId, | ||
122 | + GET_, zENTRY_DATATYPE_, &datatype, | ||
123 | + zENTRY_NUMELEMS_, &numElements, | ||
124 | + NULL_); | ||
125 | + //printf("%d %s", numElements,cdf_str_datatype(datatype)); | ||
126 | + if (status == NO_SUCH_ENTRY) continue; | ||
127 | + | ||
128 | + if (status != CDF_OK) cdf_status_handler (status,"GET_ATTR_INFO_"); | ||
129 | + | ||
130 | + switch (datatype) | ||
131 | + { | ||
132 | + case CDF_CHAR: | ||
133 | + cPtr = (char *) malloc(numElements * sizeof(char) + 1); | ||
134 | + | ||
135 | + status = CDFlib (GET_, zENTRY_DATA_, cPtr, NULL_); | ||
136 | + if (status != CDF_OK) cdf_status_handler (status, msg); | ||
137 | + strcpy(&cPtr[numElements],"\0"); | ||
138 | + printf("%s\n", cPtr); | ||
139 | + free(cPtr); | ||
140 | + break; | ||
141 | + | ||
142 | + case CDF_BYTE: | ||
143 | + case CDF_INT1: | ||
144 | + scPtr = (signed char *) malloc (sizeof(signed char) * numElements); | ||
145 | + status = CDFlib (GET_, zENTRY_DATA_, scPtr, NULL_); | ||
146 | + if (status != CDF_OK) cdf_status_handler (status, msg); | ||
147 | + free (scPtr); | ||
148 | + break; | ||
149 | + | ||
150 | + case CDF_INT2: | ||
151 | + case CDF_UCHAR: | ||
152 | + case CDF_UINT1: | ||
153 | + sPtr = (short *) malloc (sizeof(short) * numElements); | ||
154 | + status = CDFlib (GET_, zENTRY_DATA_, sPtr, NULL_); | ||
155 | + if (status != CDF_OK) cdf_status_handler (status, msg); | ||
156 | + free (sPtr); | ||
157 | + break; | ||
158 | + | ||
159 | + case CDF_INT4: | ||
160 | + case CDF_UINT2: | ||
161 | + iPtr = (int *) malloc (sizeof(int) * numElements); | ||
162 | + status = CDFlib (GET_, zENTRY_DATA_, iPtr, NULL_); | ||
163 | + if (status != CDF_OK) cdf_status_handler (status, msg); | ||
164 | + printf("%d\n", *iPtr); | ||
165 | + free (iPtr); | ||
166 | + break; | ||
167 | + | ||
168 | + case CDF_FLOAT: | ||
169 | + case CDF_REAL4: | ||
170 | + fPtr = (float *) malloc (sizeof(float) * numElements); | ||
171 | + status = CDFlib (GET_, zENTRY_DATA_, fPtr, NULL_); | ||
172 | + if (status != CDF_OK) cdf_status_handler (status, msg); | ||
173 | + printf("%8.1e\n", *fPtr); | ||
174 | + free (fPtr); | ||
175 | + break; | ||
176 | + | ||
177 | + case CDF_DOUBLE: | ||
178 | + case CDF_REAL8: | ||
179 | + case CDF_UINT4: | ||
180 | + dPtr = (double *) malloc (sizeof(double) * numElements); | ||
181 | + | ||
182 | + status = CDFlib (GET_, zENTRY_DATA_, dPtr, NULL_); | ||
183 | + if (status != CDF_OK) cdf_status_handler (status, msg); | ||
184 | + printf("%8.1e\n", *dPtr); | ||
185 | + free (dPtr); | ||
186 | + break; | ||
187 | + | ||
188 | + case CDF_EPOCH: /* 8-byte real number */ | ||
189 | + dPtr = (double *) malloc (sizeof(double) * numElements); | ||
190 | + | ||
191 | + status = CDFlib (GET_, zENTRY_DATA_, dPtr, NULL_); | ||
192 | + if (status != CDF_OK) cdf_status_handler (status, msg); | ||
193 | + | ||
194 | + free (dPtr); | ||
195 | + break; | ||
196 | + | ||
197 | + case CDF_EPOCH16: /* 16-byte real number */ | ||
198 | + dPtr = (double *) malloc (sizeof(double) * numElements * 2); | ||
199 | + status = CDFlib (GET_, zENTRY_DATA_, dPtr, NULL_); | ||
200 | + if (status != CDF_OK) cdf_status_handler (status, msg); | ||
201 | + free (dPtr); | ||
202 | + break; | ||
203 | + | ||
204 | + default: | ||
205 | + printf ("** Error in get_cdf_attribute: bad data type"); | ||
206 | + } | ||
207 | + } | ||
208 | + break; | ||
209 | + } | ||
210 | + } | ||
211 | + | ||
212 | + /* Close the CDF file */ | ||
213 | + status = CDFlib (CLOSE_, CDF_, NULL_); | ||
214 | + | ||
215 | +} | ||
216 | + | ||
217 | + | ||
218 | +void cdf_status_handler (CDFstatus status, char *source) | ||
219 | +{ | ||
220 | + char message[CDF_STATUSTEXT_LEN+1]; | ||
221 | + | ||
222 | + CDFerror (status, message); /* Get the appropriate message */ | ||
223 | + | ||
224 | + if (status < CDF_WARN) { | ||
225 | + printf ("An error has occurred, halting...\n"); | ||
226 | + printf ("%s\n", message); | ||
227 | + printf ("** Error source: %s\n", source); | ||
228 | + exit (status); | ||
229 | + } | ||
230 | + else if (status < CDF_OK) { | ||
231 | + printf ("Warning, function may not have compeleted as expected...\n"); | ||
232 | + printf ("%s\n", message); | ||
233 | + } | ||
234 | + else if (status > CDF_OK) { | ||
235 | + printf ("Function compeleted successfully, but be advised that...\n"); | ||
236 | + printf ("%s\n", message); | ||
237 | + } | ||
238 | +} | ||
239 | + | ||
240 | +/*-------------------------------------------------------------------------- | ||
241 | + * This routine returns the string representation of the given CDF | ||
242 | + * datatype. | ||
243 | + *--------------------------------------------------------------------------*/ | ||
244 | +char * cdf_str_datatype (long type) | ||
245 | +{ | ||
246 | + switch (type) { | ||
247 | + case CDF_BYTE: | ||
248 | + return "CDF_BYTE"; | ||
249 | + | ||
250 | + case CDF_INT1: | ||
251 | + return "CDF_INT1"; | ||
252 | + | ||
253 | + case CDF_CHAR: | ||
254 | + return "CDF_CHAR"; | ||
255 | + | ||
256 | + case CDF_INT2: | ||
257 | + return "CDF_INT2"; | ||
258 | + | ||
259 | + case CDF_UCHAR: | ||
260 | + return "CDF_UCHAR"; | ||
261 | + | ||
262 | + case CDF_UINT1: | ||
263 | + return "CDF_UINT1"; | ||
264 | + | ||
265 | + case CDF_INT4: | ||
266 | + return "CDF_INT4"; | ||
267 | + | ||
268 | + case CDF_UINT2: | ||
269 | + return "CDF_UINT2"; | ||
270 | + | ||
271 | + case CDF_FLOAT: | ||
272 | + return "CDF_FLOAT"; | ||
273 | + | ||
274 | + case CDF_REAL4: | ||
275 | + return "CDF_REAL4"; | ||
276 | + | ||
277 | + case CDF_DOUBLE: | ||
278 | + return "CDF_DOUBLE"; | ||
279 | + | ||
280 | + case CDF_REAL8: | ||
281 | + return "CDF_REAL8"; | ||
282 | + | ||
283 | + case CDF_UINT4: | ||
284 | + return "CDF_UINT4"; | ||
285 | + | ||
286 | + case CDF_EPOCH: | ||
287 | + return "CDF_EPOCH"; | ||
288 | + | ||
289 | + case CDF_EPOCH16: | ||
290 | + return "CDF_EPOCH16"; | ||
291 | + } | ||
292 | +} |
php/src/cdfvarinfo.c
@@ -16,49 +16,42 @@ void cdf_status_handler (CDFstatus, char *); | @@ -16,49 +16,42 @@ void cdf_status_handler (CDFstatus, char *); | ||
16 | char * cdf_str_datatype (long); | 16 | char * cdf_str_datatype (long); |
17 | 17 | ||
18 | typedef struct cdfvar { /* CDF variable structure */ | 18 | typedef struct cdfvar { /* CDF variable structure */ |
19 | - char name[CDF_VAR_NAME_LEN+1]; | ||
20 | - long datatype; | ||
21 | - long numElements; /* string length for CDF_CHAR, 1 otherwise */ | ||
22 | - long dimensionality; /* variable dimensionality */ | ||
23 | - long dimSizes[CDF_MAX_DIMS]; /* variable dimension sizes */ | ||
24 | - long recVariance; /* record variance */ | ||
25 | - long numRecs; /* # of records this variable contains */ | 19 | + char name[CDF_VAR_NAME_LEN+1]; |
20 | + long datatype; | ||
21 | + long numElements; /* string length for CDF_CHAR, 1 otherwise */ | ||
22 | + long dimensionality; /* variable dimensionality */ | ||
23 | + long dimSizes[CDF_MAX_DIMS]; /* variable dimension sizes */ | ||
24 | + long recVariance; /* record variance */ | ||
25 | + long numRecs; /* # of records this variable contains */ | ||
26 | } CDFvar; | 26 | } CDFvar; |
27 | 27 | ||
28 | int main(int argc, char *argv[]) | 28 | int main(int argc, char *argv[]) |
29 | -{ | ||
30 | - | ||
31 | - CDFvar var; | ||
32 | - CDFid id; /* CDF file ID */ | ||
33 | - CDFstatus status; /* CDF status code */ | ||
34 | - | ||
35 | - long nZvars, nAttrs, attrId, attrScope, varId, datatype, numElements; | ||
36 | - char attrName[CDF_ATTR_NAME_LEN+1]; | ||
37 | - char fileName[MAX_FILE_NAME_LEN], varName[CDF_VAR_NAME_LEN+1]; | ||
38 | - char msg[100]; | ||
39 | - int dummy, i; | ||
40 | - char *cPtr; | ||
41 | - signed char *scPtr; | ||
42 | - short *sPtr; | ||
43 | - int *iPtr; | ||
44 | - float *fPtr; | ||
45 | - double *dPtr; | 29 | +{ |
30 | + CDFvar var; | ||
31 | + CDFid id; /* CDF file ID */ | ||
32 | + CDFstatus status; /* CDF status code */ | ||
33 | + | ||
34 | + long nZvars, nAttrs, attrId, attrScope, varId, datatype, numElements; | ||
35 | + char attrName[CDF_ATTR_NAME_LEN+1]; | ||
36 | + char fileName[MAX_FILE_NAME_LEN], varName[CDF_VAR_NAME_LEN+1]; | ||
37 | + char msg[100]; | ||
38 | + int dummy, i; | ||
46 | 39 | ||
47 | 40 | ||
48 | - if (argc <= 2) | ||
49 | - exit(0); /* CDF input file name not specified */ | ||
50 | - else { | ||
51 | - strcpy(fileName, argv[1]); /* Get the input file name */ | ||
52 | - strcpy(varName, argv[2]); | ||
53 | - } | 41 | + if (argc <= 2) |
42 | + exit(0); /* CDF input file name not specified */ | ||
43 | + else { | ||
44 | + strcpy(fileName, argv[1]); /* Get the input file name */ | ||
45 | + strcpy(varName, argv[2]); | ||
46 | + } | ||
54 | 47 | ||
55 | - status = CDFlib (OPEN_, CDF_, fileName, &id, NULL_); | 48 | + status = CDFlib (OPEN_, CDF_, fileName, &id, NULL_); |
56 | 49 | ||
57 | - if (status != CDF_OK) { | ||
58 | - strcpy(msg, "OPEN_, CDF_, "); | ||
59 | - strcat(msg, fileName); | ||
60 | - cdf_status_handler (status, msg); | ||
61 | - } | 50 | + if (status != CDF_OK) { |
51 | + strcpy(msg, "OPEN_, CDF_, "); | ||
52 | + strcat(msg, fileName); | ||
53 | + cdf_status_handler (status, msg); | ||
54 | + } | ||
62 | 55 | ||
63 | /*--------------------------------------------------------------------------- | 56 | /*--------------------------------------------------------------------------- |
64 | * This routine retrievs the following information: | 57 | * This routine retrievs the following information: |
@@ -72,225 +65,114 @@ int main(int argc, char *argv[]) | @@ -72,225 +65,114 @@ int main(int argc, char *argv[]) | ||
72 | * more. Treat all CDF variables as zVariables. | 65 | * more. Treat all CDF variables as zVariables. |
73 | *--------------------------------------------------------------------------*/ | 66 | *--------------------------------------------------------------------------*/ |
74 | 67 | ||
75 | - status = CDFlib (SELECT_, CDF_zMODE_, zMODEon2, | ||
76 | - GET_, CDF_NUMATTRS_, &nAttrs, | ||
77 | - CDF_NUMzVARS_, &nZvars, | ||
78 | - NULL_); | ||
79 | - if (status != CDF_OK) cdf_status_handler(status, "GET_, CDF_FILEINFO_"); | ||
80 | - | ||
81 | - // printf(" nAttrs %d Zvars %d\n",nAttrs, nZvars); | ||
82 | - | ||
83 | -// printf ("Attributes:\n"); | ||
84 | - | ||
85 | - for (attrId = 0; attrId < nAttrs; attrId++) { | ||
86 | - status = CDFlib (SELECT_, ATTR_, attrId, | ||
87 | - GET_, ATTR_NAME_, attrName, ATTR_SCOPE_, &attrScope, | ||
88 | - NULL_); | ||
89 | - if (status != CDF_OK) cdf_status_handler (status, "SELECT_, ATTR_"); | ||
90 | - | ||
91 | - | ||
92 | - // printf("Attr %d %s %d\n", attrId, attrName, attrScope); | ||
93 | - } | ||
94 | - | ||
95 | - // printf ("Variables:\n"); | ||
96 | - for (varId=0; varId < nZvars; varId++) { | ||
97 | - | ||
98 | - status = CDFlib (SELECT_,zVAR_, varId, | ||
99 | - GET_, zVAR_NAME_, var.name, | ||
100 | - zVAR_DATATYPE_, &var.datatype, | ||
101 | - zVAR_NUMELEMS_, &var.numElements, | ||
102 | - zVAR_NUMDIMS_, &var.dimensionality, | ||
103 | - zVAR_DIMSIZES_, var.dimSizes, | ||
104 | - zVAR_NUMRECS_, &var.numRecs, | ||
105 | - zVAR_RECVARY_, &var.recVariance, | ||
106 | - NULL_); | ||
107 | - if (status != CDF_OK) cdf_status_handler (status, "GET_, zVARS_"); | 68 | + status = CDFlib (SELECT_, CDF_zMODE_, zMODEon2, |
69 | + GET_, CDF_NUMATTRS_, &nAttrs, | ||
70 | + CDF_NUMzVARS_, &nZvars, | ||
71 | + NULL_); | ||
72 | + | ||
73 | + if (status != CDF_OK) cdf_status_handler(status, "GET_, CDF_FILEINFO_"); | ||
74 | + | ||
75 | + for (varId=0; varId < nZvars; varId++) | ||
76 | + { | ||
77 | + status = CDFlib (SELECT_,zVAR_, varId, | ||
78 | + GET_, zVAR_NAME_, var.name, | ||
79 | + zVAR_DATATYPE_, &var.datatype, | ||
80 | + zVAR_NUMELEMS_, &var.numElements, | ||
81 | + zVAR_NUMDIMS_, &var.dimensionality, | ||
82 | + zVAR_DIMSIZES_, var.dimSizes, | ||
83 | + zVAR_NUMRECS_, &var.numRecs, | ||
84 | + zVAR_RECVARY_, &var.recVariance, | ||
85 | + NULL_); | ||
86 | + | ||
87 | + if (status != CDF_OK) cdf_status_handler (status, "GET_, zVARS_"); | ||
108 | 88 | ||
109 | - if (strcmp(var.name, varName) == 0) { | ||
110 | - | ||
111 | - printf("%s %d %d ", cdf_str_datatype(var.datatype), var.dimensionality, var.numRecs); | ||
112 | - for (i = 0; i < var.dimensionality; i++) printf("%d ",var.dimSizes[i]); | ||
113 | - printf("\n"); | ||
114 | - | ||
115 | - for (attrId = 0; attrId < nAttrs; attrId++) { | ||
116 | - status = CDFlib (SELECT_, ATTR_, attrId, | ||
117 | - GET_, ATTR_NAME_, attrName, | ||
118 | - ATTR_SCOPE_, &attrScope, | ||
119 | - NULL_); | ||
120 | - | ||
121 | - if (status != CDF_OK) cdf_status_handler (status, "SELECT_, ATTR_"); | ||
122 | - if (attrScope == GLOBAL_SCOPE) continue; | ||
123 | -//printf("\n%d %s ", attrId, attrName); | ||
124 | - status = CDFlib (SELECT_, zENTRY_, varId, | ||
125 | - GET_, zENTRY_DATATYPE_, &datatype, | ||
126 | - zENTRY_NUMELEMS_, &numElements, | ||
127 | - NULL_); | ||
128 | -//printf("%d %s", numElements,cdf_str_datatype(datatype)); | ||
129 | - if (status == NO_SUCH_ENTRY) continue; | ||
130 | - | ||
131 | - if (status != CDF_OK) cdf_status_handler (status,"GET_ATTR_INFO_"); | ||
132 | - | ||
133 | - switch (datatype) { | ||
134 | - case CDF_CHAR: | ||
135 | - cPtr = (char *) malloc(numElements * sizeof(char) + 1); | ||
136 | - status = CDFlib (GET_, zENTRY_DATA_, cPtr, NULL_); | ||
137 | - if (status != CDF_OK) cdf_status_handler (status, msg); | ||
138 | -// printf(" %s", cPtr); | ||
139 | - free(cPtr); | ||
140 | - break; | ||
141 | - | ||
142 | - case CDF_BYTE: | ||
143 | - case CDF_INT1: | ||
144 | - scPtr = (signed char *) malloc (sizeof(signed char) * numElements); | ||
145 | - status = CDFlib (GET_, zENTRY_DATA_, scPtr, NULL_); | ||
146 | - if (status != CDF_OK) cdf_status_handler (status, msg); | ||
147 | - free (scPtr); | ||
148 | - break; | ||
149 | - | ||
150 | - case CDF_INT2: | ||
151 | - case CDF_UCHAR: | ||
152 | - case CDF_UINT1: | ||
153 | - sPtr = (short *) malloc (sizeof(short) * numElements); | ||
154 | - status = CDFlib (GET_, zENTRY_DATA_, sPtr, NULL_); | ||
155 | - if (status != CDF_OK) cdf_status_handler (status, msg); | ||
156 | - free (sPtr); | ||
157 | - break; | ||
158 | - | ||
159 | - case CDF_INT4: | ||
160 | - case CDF_UINT2: | ||
161 | - iPtr = (int *) malloc (sizeof(int) * numElements); | ||
162 | - status = CDFlib (GET_, zENTRY_DATA_, iPtr, NULL_); | ||
163 | - if (status != CDF_OK) cdf_status_handler (status, msg); | ||
164 | - free (iPtr); | ||
165 | - break; | ||
166 | - | ||
167 | - case CDF_FLOAT: | ||
168 | - case CDF_REAL4: | ||
169 | - fPtr = (float *) malloc (sizeof(float) * numElements); | ||
170 | - status = CDFlib (GET_, zENTRY_DATA_, fPtr, NULL_); | ||
171 | - if (status != CDF_OK) cdf_status_handler (status, msg); | ||
172 | - free (fPtr); | ||
173 | - break; | ||
174 | - | ||
175 | - case CDF_DOUBLE: | ||
176 | - case CDF_REAL8: | ||
177 | - case CDF_UINT4: | ||
178 | - dPtr = (double *) malloc (sizeof(double) * numElements); | ||
179 | - | ||
180 | - status = CDFlib (GET_, zENTRY_DATA_, dPtr, NULL_); | ||
181 | - if (status != CDF_OK) cdf_status_handler (status, msg); | ||
182 | - | ||
183 | - free (dPtr); | ||
184 | - break; | ||
185 | - | ||
186 | - case CDF_EPOCH: /* 8-byte real number */ | ||
187 | - dPtr = (double *) malloc (sizeof(double) * numElements); | ||
188 | - | ||
189 | - status = CDFlib (GET_, zENTRY_DATA_, dPtr, NULL_); | ||
190 | - if (status != CDF_OK) cdf_status_handler (status, msg); | ||
191 | - | ||
192 | - free (dPtr); | ||
193 | - break; | ||
194 | - | ||
195 | - case CDF_EPOCH16: /* 16-byte real number */ | ||
196 | - dPtr = (double *) malloc (sizeof(double) * numElements * 2); | ||
197 | - status = CDFlib (GET_, zENTRY_DATA_, dPtr, NULL_); | ||
198 | - if (status != CDF_OK) cdf_status_handler (status, msg); | ||
199 | - free (dPtr); | ||
200 | - break; | ||
201 | - | ||
202 | - default: | ||
203 | - printf ("** Error in get_cdf_attribute: bad data type"); | ||
204 | - } | ||
205 | - | ||
206 | - } | ||
207 | - break; | 89 | + if (strcmp(var.name, varName) == 0) |
90 | + { | ||
91 | + printf("%s %d %d ", cdf_str_datatype(var.datatype), var.dimensionality, var.numRecs); | ||
92 | + for (i = 0; i < var.dimensionality; i++) printf("%d ",var.dimSizes[i]); | ||
93 | + | ||
94 | + printf("\n"); | ||
95 | + break; | ||
96 | + } | ||
208 | } | 97 | } |
209 | - } | ||
210 | - | ||
211 | - | ||
212 | - | ||
213 | - /* Close the CDF file */ | ||
214 | - status = CDFlib (CLOSE_, CDF_, NULL_); | ||
215 | - | 98 | + |
99 | + /* Close the CDF file */ | ||
100 | + status = CDFlib (CLOSE_, CDF_, NULL_); | ||
216 | } | 101 | } |
217 | 102 | ||
218 | 103 | ||
219 | - | ||
220 | - | ||
221 | void cdf_status_handler (CDFstatus status, char *source) | 104 | void cdf_status_handler (CDFstatus status, char *source) |
222 | { | 105 | { |
223 | - char message[CDF_STATUSTEXT_LEN+1]; | 106 | + char message[CDF_STATUSTEXT_LEN+1]; |
224 | 107 | ||
225 | - CDFerror (status, message); /* Get the appropriate message */ | 108 | + CDFerror (status, message); /* Get the appropriate message */ |
226 | 109 | ||
227 | - if (status < CDF_WARN) { | ||
228 | - printf ("An error has occurred, halting...\n"); | ||
229 | - printf ("%s\n", message); | ||
230 | - printf ("** Error source: %s\n", source); | ||
231 | - exit (status); | ||
232 | - } | ||
233 | - else if (status < CDF_OK) { | ||
234 | - printf ("Warning, function may not have compeleted as expected...\n"); | ||
235 | - printf ("%s\n", message); | ||
236 | - } | ||
237 | - else if (status > CDF_OK) { | ||
238 | - printf ("Function compeleted successfully, but be advised that...\n"); | ||
239 | - printf ("%s\n", message); | ||
240 | - } | ||
241 | - | ||
242 | - | 110 | + if (status < CDF_WARN) { |
111 | + printf ("An error has occurred, halting...\n"); | ||
112 | + printf ("%s\n", message); | ||
113 | + printf ("** Error source: %s\n", source); | ||
114 | + exit (status); | ||
115 | + } | ||
116 | + else if (status < CDF_OK) { | ||
117 | + printf ("Warning, function may not have compeleted as expected...\n"); | ||
118 | + printf ("%s\n", message); | ||
119 | + } | ||
120 | + else if (status > CDF_OK) { | ||
121 | + printf ("Function compeleted successfully, but be advised that...\n"); | ||
122 | + printf ("%s\n", message); | ||
123 | + } | ||
243 | } | 124 | } |
125 | + | ||
244 | /*-------------------------------------------------------------------------- | 126 | /*-------------------------------------------------------------------------- |
245 | * This routine returns the string representation of the given CDF | 127 | * This routine returns the string representation of the given CDF |
246 | * datatype. | 128 | * datatype. |
247 | *--------------------------------------------------------------------------*/ | 129 | *--------------------------------------------------------------------------*/ |
248 | char * cdf_str_datatype (long type) | 130 | char * cdf_str_datatype (long type) |
249 | { | 131 | { |
250 | - switch (type) { | ||
251 | - case CDF_BYTE: | ||
252 | - return "CDF_BYTE"; | 132 | + switch (type) { |
133 | + case CDF_BYTE: | ||
134 | + return "CDF_BYTE"; | ||
253 | 135 | ||
254 | - case CDF_INT1: | ||
255 | - return "CDF_INT1"; | 136 | + case CDF_INT1: |
137 | + return "CDF_INT1"; | ||
256 | 138 | ||
257 | - case CDF_CHAR: | ||
258 | - return "CDF_CHAR"; | 139 | + case CDF_CHAR: |
140 | + return "CDF_CHAR"; | ||
259 | 141 | ||
260 | - case CDF_INT2: | ||
261 | - return "CDF_INT2"; | 142 | + case CDF_INT2: |
143 | + return "CDF_INT2"; | ||
262 | 144 | ||
263 | - case CDF_UCHAR: | ||
264 | - return "CDF_UCHAR"; | 145 | + case CDF_UCHAR: |
146 | + return "CDF_UCHAR"; | ||
265 | 147 | ||
266 | - case CDF_UINT1: | ||
267 | - return "CDF_UINT1"; | 148 | + case CDF_UINT1: |
149 | + return "CDF_UINT1"; | ||
268 | 150 | ||
269 | - case CDF_INT4: | ||
270 | - return "CDF_INT4"; | 151 | + case CDF_INT4: |
152 | + return "CDF_INT4"; | ||
271 | 153 | ||
272 | - case CDF_UINT2: | ||
273 | - return "CDF_UINT2"; | 154 | + case CDF_UINT2: |
155 | + return "CDF_UINT2"; | ||
274 | 156 | ||
275 | - case CDF_FLOAT: | ||
276 | - return "CDF_FLOAT"; | 157 | + case CDF_FLOAT: |
158 | + return "CDF_FLOAT"; | ||
277 | 159 | ||
278 | - case CDF_REAL4: | ||
279 | - return "CDF_REAL4"; | 160 | + case CDF_REAL4: |
161 | + return "CDF_REAL4"; | ||
280 | 162 | ||
281 | - case CDF_DOUBLE: | ||
282 | - return "CDF_DOUBLE"; | 163 | + case CDF_DOUBLE: |
164 | + return "CDF_DOUBLE"; | ||
283 | 165 | ||
284 | - case CDF_REAL8: | ||
285 | - return "CDF_REAL8"; | 166 | + case CDF_REAL8: |
167 | + return "CDF_REAL8"; | ||
286 | 168 | ||
287 | - case CDF_UINT4: | ||
288 | - return "CDF_UINT4"; | 169 | + case CDF_UINT4: |
170 | + return "CDF_UINT4"; | ||
289 | 171 | ||
290 | - case CDF_EPOCH: | ||
291 | - return "CDF_EPOCH"; | 172 | + case CDF_EPOCH: |
173 | + return "CDF_EPOCH"; | ||
292 | 174 | ||
293 | - case CDF_EPOCH16: | ||
294 | - return "CDF_EPOCH16"; | ||
295 | - } | ||
296 | -} | 175 | + case CDF_EPOCH16: |
176 | + return "CDF_EPOCH16"; | ||
177 | + } | ||
178 | +} | ||
297 | \ No newline at end of file | 179 | \ No newline at end of file |