Commit cdb91ea6b5bf0bbfcfaf5d27f063f711265e516e
1 parent
b5c2b014
Exists in
master
and in
110 other branches
redmine #5568
Showing
3 changed files
with
357 additions
and
321 deletions
Show diff stats
php/src/cdfinfo.c
... | ... | @@ -15,42 +15,42 @@ |
15 | 15 | void cdf_status_handler (CDFstatus, char *); |
16 | 16 | char * cdf_str_datatype (long); |
17 | 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 */ | |
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 | 26 | } CDFvar; |
27 | 27 | |
28 | 28 | int main(int argc, char *argv[]) |
29 | 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; | |
36 | + char attrName[CDF_ATTR_NAME_LEN+1]; | |
37 | + char fileName[MAX_FILE_NAME_LEN]; | |
38 | + char msg[100]; | |
39 | + int dummy, i; | |
30 | 40 | |
31 | - CDFvar var; | |
32 | - CDFid id; /* CDF file ID */ | |
33 | - CDFstatus status; /* CDF status code */ | |
34 | - | |
35 | - long nZvars, nAttrs, attrId, attrScope, varId; | |
36 | - char attrName[CDF_ATTR_NAME_LEN+1]; | |
37 | - char fileName[MAX_FILE_NAME_LEN]; | |
38 | - char msg[100]; | |
39 | - int dummy, i; | |
40 | - | |
41 | - if (argc <= 1) | |
42 | - exit(0); /* CDF input file name not specified */ | |
43 | - else | |
44 | - strcpy(fileName, argv[argc-1]); /* Get the input file name */ | |
41 | + if (argc <= 1) | |
42 | + exit(0); /* CDF input file name not specified */ | |
43 | + else | |
44 | + strcpy(fileName, argv[argc-1]); /* Get the input file name */ | |
45 | 45 | |
46 | 46 | |
47 | 47 | status = CDFlib (OPEN_, CDF_, fileName, &id, NULL_); |
48 | 48 | |
49 | - if (status != CDF_OK) { | |
50 | - strcpy(msg, "OPEN_, CDF_, "); | |
51 | - strcat(msg, fileName); | |
52 | - cdf_status_handler (status, msg); | |
53 | - } | |
49 | + if (status != CDF_OK) { | |
50 | + strcpy(msg, "OPEN_, CDF_, "); | |
51 | + strcat(msg, fileName); | |
52 | + cdf_status_handler (status, msg); | |
53 | + } | |
54 | 54 | |
55 | 55 | /*--------------------------------------------------------------------------- |
56 | 56 | * This routine retrievs the following information: |
... | ... | @@ -64,124 +64,119 @@ int main(int argc, char *argv[]) |
64 | 64 | * more. Treat all CDF variables as zVariables. |
65 | 65 | *--------------------------------------------------------------------------*/ |
66 | 66 | |
67 | - status = CDFlib (SELECT_, CDF_zMODE_, zMODEon2, | |
68 | - GET_, CDF_NUMATTRS_, &nAttrs, | |
69 | - CDF_NUMzVARS_, &nZvars, | |
70 | - NULL_); | |
71 | - if (status != CDF_OK) cdf_status_handler(status, "GET_, CDF_FILEINFO_"); | |
67 | + status = CDFlib (SELECT_, CDF_zMODE_, zMODEon2, | |
68 | + GET_, CDF_NUMATTRS_, &nAttrs, | |
69 | + CDF_NUMzVARS_, &nZvars, | |
70 | + NULL_); | |
71 | + if (status != CDF_OK) cdf_status_handler(status, "GET_, CDF_FILEINFO_"); | |
72 | 72 | |
73 | - // printf(" nAttrs %d Zvars %d\n",nAttrs, nZvars); | |
73 | + // printf(" nAttrs %d Zvars %d\n",nAttrs, nZvars); | |
74 | 74 | |
75 | -// printf ("Attributes:\n"); | |
75 | + // printf ("Attributes:\n"); | |
76 | 76 | |
77 | - for (attrId = 0; attrId < nAttrs; attrId++) { | |
78 | - status = CDFlib (SELECT_, ATTR_, attrId, | |
79 | - GET_, ATTR_NAME_, attrName, ATTR_SCOPE_, &attrScope, | |
80 | - NULL_); | |
81 | - if (status != CDF_OK) cdf_status_handler (status, "SELECT_, ATTR_"); | |
82 | - | |
83 | - | |
77 | + for (attrId = 0; attrId < nAttrs; attrId++) { | |
78 | + status = CDFlib (SELECT_, ATTR_, attrId, | |
79 | + GET_, ATTR_NAME_, attrName, ATTR_SCOPE_, &attrScope, | |
80 | + NULL_); | |
81 | + if (status != CDF_OK) cdf_status_handler (status, "SELECT_, ATTR_"); | |
84 | 82 | // printf("Attr %d %s %d\n", attrId, attrName, attrScope); |
85 | - } | |
83 | + } | |
86 | 84 | |
87 | - // printf ("Variables:\n"); | |
88 | - for (varId=0; varId < nZvars; varId++) { | |
89 | - status = CDFlib (SELECT_,zVAR_, varId, | |
90 | - GET_, zVAR_NAME_, var.name, | |
91 | - zVAR_DATATYPE_, &var.datatype, | |
92 | - zVAR_NUMELEMS_, &var.numElements, | |
93 | - zVAR_NUMDIMS_, &var.dimensionality, | |
94 | - zVAR_DIMSIZES_, var.dimSizes, | |
95 | - zVAR_NUMRECS_, &var.numRecs, | |
96 | - zVAR_RECVARY_, &var.recVariance, | |
97 | - NULL_); | |
98 | - if (status != CDF_OK) cdf_status_handler (status, "GET_, zVARS_"); | |
99 | - | |
100 | - // printf("Varr %d %s %s %d\n", varId, var.name, cdf_str_datatype(var.datatype), var.numRecs); | |
101 | - if (var.recVariance != 0 && var.numRecs > 1 && var.datatype != CDF_EPOCH && var.datatype != CDF_EPOCH16) printf("%s \n", var.name); | |
102 | - } | |
103 | - | |
104 | - /* Close the CDF file */ | |
105 | - status = CDFlib (CLOSE_, CDF_, NULL_); | |
85 | + // printf ("Variables:\n"); | |
86 | + for (varId=0; varId < nZvars; varId++) { | |
87 | + status = CDFlib (SELECT_,zVAR_, varId, | |
88 | + GET_, zVAR_NAME_, var.name, | |
89 | + zVAR_DATATYPE_, &var.datatype, | |
90 | + zVAR_NUMELEMS_, &var.numElements, | |
91 | + zVAR_NUMDIMS_, &var.dimensionality, | |
92 | + zVAR_DIMSIZES_, var.dimSizes, | |
93 | + zVAR_NUMRECS_, &var.numRecs, | |
94 | + zVAR_RECVARY_, &var.recVariance, | |
95 | + NULL_); | |
96 | + if (status != CDF_OK) cdf_status_handler (status, "GET_, zVARS_"); | |
97 | + // printf("Varr %d %s %s %d\n", varId, var.name, cdf_str_datatype(var.datatype), var.numRecs); | |
98 | + if (var.recVariance != 0 && var.numRecs > 1 && var.datatype != CDF_EPOCH && var.datatype != CDF_EPOCH16 && var.datatype != CDF_TIME_TT2000) printf("%s \n", var.name); | |
99 | + } | |
106 | 100 | |
101 | + /* Close the CDF file */ | |
102 | + status = CDFlib (CLOSE_, CDF_, NULL_); | |
107 | 103 | } |
108 | 104 | |
109 | - | |
110 | - | |
111 | - | |
112 | 105 | void cdf_status_handler (CDFstatus status, char *source) |
113 | 106 | { |
114 | - char message[CDF_STATUSTEXT_LEN+1]; | |
115 | - | |
116 | - CDFerror (status, message); /* Get the appropriate message */ | |
117 | - | |
118 | - if (status < CDF_WARN) { | |
119 | - printf ("An error has occurred, halting...\n"); | |
120 | - printf ("%s\n", message); | |
121 | - printf ("** Error source: %s\n", source); | |
122 | - exit (status); | |
123 | - } | |
124 | - else if (status < CDF_OK) { | |
125 | - printf ("Warning, function may not have compeleted as expected...\n"); | |
126 | - printf ("%s\n", message); | |
127 | - } | |
128 | - else if (status > CDF_OK) { | |
129 | - printf ("Function compeleted successfully, but be advised that...\n"); | |
130 | - printf ("%s\n", message); | |
131 | - } | |
132 | - | |
133 | - | |
107 | + char message[CDF_STATUSTEXT_LEN+1]; | |
108 | + | |
109 | + CDFerror (status, message); /* Get the appropriate message */ | |
110 | + | |
111 | + if (status < CDF_WARN) { | |
112 | + printf ("An error has occurred, halting...\n"); | |
113 | + printf ("%s\n", message); | |
114 | + printf ("** Error source: %s\n", source); | |
115 | + exit (status); | |
116 | + } | |
117 | + else if (status < CDF_OK) { | |
118 | + printf ("Warning, function may not have compeleted as expected...\n"); | |
119 | + printf ("%s\n", message); | |
120 | + } | |
121 | + else if (status > CDF_OK) { | |
122 | + printf ("Function compeleted successfully, but be advised that...\n"); | |
123 | + printf ("%s\n", message); | |
124 | + } | |
134 | 125 | } |
126 | + | |
135 | 127 | /*-------------------------------------------------------------------------- |
136 | 128 | * This routine returns the string representation of the given CDF |
137 | 129 | * datatype. |
138 | 130 | *--------------------------------------------------------------------------*/ |
139 | 131 | char * cdf_str_datatype (long type) |
140 | 132 | { |
141 | - switch (type) { | |
142 | - case CDF_BYTE: | |
143 | - return "CDF_BYTE"; | |
133 | + switch (type) { | |
134 | + case CDF_BYTE: | |
135 | + return "CDF_BYTE"; | |
144 | 136 | |
145 | - case CDF_INT1: | |
146 | - return "CDF_INT1"; | |
137 | + case CDF_INT1: | |
138 | + return "CDF_INT1"; | |
147 | 139 | |
148 | - case CDF_CHAR: | |
149 | - return "CDF_CHAR"; | |
140 | + case CDF_CHAR: | |
141 | + return "CDF_CHAR"; | |
150 | 142 | |
151 | - case CDF_INT2: | |
152 | - return "CDF_INT2"; | |
143 | + case CDF_INT2: | |
144 | + return "CDF_INT2"; | |
153 | 145 | |
154 | - case CDF_UCHAR: | |
155 | - return "CDF_UCHAR"; | |
146 | + case CDF_UCHAR: | |
147 | + return "CDF_UCHAR"; | |
156 | 148 | |
157 | - case CDF_UINT1: | |
158 | - return "CDF_UINT1"; | |
149 | + case CDF_UINT1: | |
150 | + return "CDF_UINT1"; | |
159 | 151 | |
160 | - case CDF_INT4: | |
161 | - return "CDF_INT4"; | |
152 | + case CDF_INT4: | |
153 | + return "CDF_INT4"; | |
162 | 154 | |
163 | - case CDF_UINT2: | |
164 | - return "CDF_UINT2"; | |
155 | + case CDF_UINT2: | |
156 | + return "CDF_UINT2"; | |
165 | 157 | |
166 | - case CDF_FLOAT: | |
167 | - return "CDF_FLOAT"; | |
158 | + case CDF_FLOAT: | |
159 | + return "CDF_FLOAT"; | |
168 | 160 | |
169 | - case CDF_REAL4: | |
170 | - return "CDF_REAL4"; | |
161 | + case CDF_REAL4: | |
162 | + return "CDF_REAL4"; | |
171 | 163 | |
172 | - case CDF_DOUBLE: | |
173 | - return "CDF_DOUBLE"; | |
164 | + case CDF_DOUBLE: | |
165 | + return "CDF_DOUBLE"; | |
174 | 166 | |
175 | - case CDF_REAL8: | |
176 | - return "CDF_REAL8"; | |
167 | + case CDF_REAL8: | |
168 | + return "CDF_REAL8"; | |
177 | 169 | |
178 | - case CDF_UINT4: | |
179 | - return "CDF_UINT4"; | |
170 | + case CDF_UINT4: | |
171 | + return "CDF_UINT4"; | |
180 | 172 | |
181 | - case CDF_EPOCH: | |
182 | - return "CDF_EPOCH"; | |
173 | + case CDF_EPOCH: | |
174 | + return "CDF_EPOCH"; | |
183 | 175 | |
184 | - case CDF_EPOCH16: | |
185 | - return "CDF_EPOCH16"; | |
186 | - } | |
176 | + case CDF_EPOCH16: | |
177 | + return "CDF_EPOCH16"; | |
178 | + | |
179 | + case CDF_TIME_TT2000: | |
180 | + return "CDF_TIME_TT2000"; | |
181 | + } | |
187 | 182 | } | ... | ... |
php/src/cdfsamplingfromdata.c
... | ... | @@ -16,153 +16,177 @@ |
16 | 16 | /************************************* |
17 | 17 | Global variables and structures |
18 | 18 | **************************************/ |
19 | -long CDFDims, // Number of dimensions in a CDF file | |
20 | - CDFVars, // Number of variables in a CDF file | |
21 | - CDFDimSizes[CDF_MAX_DIMS], // Dimension Sizes in a CDF file | |
22 | - CDFencoding, // Data encoding | |
23 | - CDFmajority, // Variable majority | |
24 | - CDFmaxRec, // max Record number | |
25 | - CDFAttrs; // number of CDF Attributes | |
26 | - // CDFdatatype; | |
19 | +long CDFDims, // Number of dimensions in a CDF file | |
20 | + CDFVars, // Number of variables in a CDF file | |
21 | + CDFDimSizes[CDF_MAX_DIMS], // Dimension Sizes in a CDF file | |
22 | + CDFencoding, // Data encoding | |
23 | + CDFmajority, // Variable majority | |
24 | + CDFmaxRec, // max Record number | |
25 | + CDFAttrs; // number of CDF Attributes | |
26 | +// CDFdatatype; | |
27 | 27 | |
28 | 28 | struct cdfvar { // CDF variable structure |
29 | - char name[CDF_VAR_NAME_LEN+1]; | |
30 | - long num; //variable number | |
31 | - long datatype; | |
32 | - long numElem; // variable dimensionality | |
33 | - long recVariance; // variable rec Variance | |
34 | - long dimVariances[CDF_MAX_DIMS]; // # of data values in dimSizes | |
29 | + char name[CDF_VAR_NAME_LEN+1]; | |
30 | + long num; //variable number | |
31 | + long datatype; | |
32 | + long numElem; // variable dimensionality | |
33 | + long recVariance; // variable rec Variance | |
34 | + long dimVariances[CDF_MAX_DIMS]; // # of data values in dimSizes | |
35 | 35 | } cdfVar; |
36 | 36 | |
37 | - | |
38 | - | |
39 | 37 | /*-------------------------------------------------------------------------- |
40 | 38 | * Handles a CDF error. |
41 | 39 | *--------------------------------------------------------------------------*/ |
42 | 40 | void cdf_handle_error(CDFstatus status) |
43 | 41 | { |
42 | + char message[CDF_STATUSTEXT_LEN+1]; | |
44 | 43 | |
45 | - char message[CDF_STATUSTEXT_LEN+1]; | |
46 | - | |
47 | - CDFerror (status, message); /* Get the appropriate message */ | |
48 | - fprintf (stderr, "%s\n", message); | |
49 | - exit(1); | |
44 | + CDFerror (status, message); /* Get the appropriate message */ | |
45 | + fprintf (stderr, "%s\n", message); | |
46 | + exit(1); | |
50 | 47 | } |
51 | 48 | |
52 | 49 | void find_min(int* delta, int nRecs, int minFalse, int* minVal) |
53 | 50 | { |
54 | - int i, n, min; | |
55 | - | |
56 | - n = 1; | |
57 | - i = 0; | |
58 | - while (abs(delta[i]) <= minFalse) i++; | |
59 | - if (i < nRecs) { | |
60 | - min = abs(delta[i]); | |
61 | - // printf(" first MIN %d \n", min); | |
62 | - for (i = 1; i < nRecs; i++) { | |
63 | -// printf(" delta %d \n", delta[i]); | |
64 | - if (delta[i] == min) n++; | |
65 | - if (delta[i] < min && delta[i] > minFalse) { | |
66 | - min = delta[i]; | |
67 | - n = 1; | |
68 | - } | |
69 | - } | |
70 | - } else { min = -10; | |
71 | - n = nRecs; | |
72 | - } | |
73 | - minVal[0] = min; | |
74 | - minVal[1] = n; | |
75 | - printf(" MIN %d %d\n", min, n); | |
51 | + int i, n, min; | |
52 | + | |
53 | + n = 1; | |
54 | + i = 0; | |
55 | + while (abs(delta[i]) <= minFalse) i++; | |
56 | + if (i < nRecs) { | |
57 | + min = abs(delta[i]); | |
58 | + // printf(" first MIN %d \n", min); | |
59 | + for (i = 1; i < nRecs; i++) { | |
60 | + // printf(" delta %d \n", delta[i]); | |
61 | + if (delta[i] == min) n++; | |
62 | + if (delta[i] < min && delta[i] > minFalse) { | |
63 | + min = delta[i]; | |
64 | + n = 1; | |
65 | + } | |
66 | + } | |
67 | + } else { | |
68 | + min = -10; | |
69 | + n = nRecs; | |
70 | + } | |
71 | + | |
72 | + minVal[0] = min; | |
73 | + minVal[1] = n; | |
74 | + printf(" MIN %d %d\n", min, n); | |
76 | 75 | } |
77 | 76 | |
78 | 77 | int main(int argc, char *argv[]) |
79 | 78 | { |
80 | - | |
81 | - long RecStart = 0, RecCount, RecInt = 1; | |
82 | - long indices[1] = {0}, intervals[1] = {1}, counts[1] = {1}; | |
83 | - long varN = -1; | |
84 | - long datatype = 0, attrN, maxEntry; | |
85 | - CDFstatus cstatus; // CDF status code | |
86 | - CDFid id; | |
87 | - double *value; | |
88 | - int *delta; | |
89 | - int i, minFalse = 0, numEnough; | |
90 | - int min[2] = {0, 0}; | |
91 | - char attrValue[300]; | |
92 | - float Sampling; | |
93 | - double epoch16[2]; | |
94 | - long year, month, day, hour, minute, sec, msec, mksec, nsec, psec; | |
79 | + long RecStart = 0, RecCount, RecInt = 1; | |
80 | + long indices[1] = {0}, intervals[1] = {1}, counts[1] = {1}; | |
81 | + long varN = -1; | |
82 | + long datatype = 0, attrN, maxEntry; | |
83 | + CDFstatus cstatus; // CDF status code | |
84 | + CDFid id; | |
85 | + double *value; | |
86 | + int *delta; | |
87 | + int i, minFalse = 0, numEnough; | |
88 | + int min[2] = {0, 0}; | |
89 | + char attrValue[300]; | |
90 | + float Sampling; | |
91 | + double epoch16[2], dbl_value, dbl_value_; | |
92 | + long year, month, day, hour, minute, sec, msec, mksec, nsec, psec; | |
93 | + long long *int_value; | |
95 | 94 | |
96 | 95 | /*********************** Open CDF file *****************************/ |
97 | - if ((cstatus = CDFopen(fileName, &id)) != CDF_OK) | |
98 | - cdf_handle_error(cstatus); | |
96 | + if ((cstatus = CDFopen(fileName, &id)) != CDF_OK) | |
97 | + cdf_handle_error(cstatus); | |
99 | 98 | |
100 | 99 | /*********** treat all vars as zVars with eliminated false dimensionality and get Nrecs **********/ |
101 | 100 | |
102 | - if ((cstatus = CDFlib(SELECT_, CDF_zMODE_, zMODEon2, NULL_)) != CDF_OK) | |
103 | - cdf_handle_error (cstatus); | |
104 | - while (datatype != CDF_EPOCH && datatype != CDF_EPOCH16){ | |
105 | - varN++; | |
106 | - if ((cstatus = CDFlib(SELECT_, zVAR_, varN, | |
107 | - GET_, zVAR_DATATYPE_, &datatype, NULL_)) != CDF_OK) | |
108 | - cdf_handle_error (cstatus); | |
109 | - | |
110 | - // if (datatype == CDF_EPOCH16) break; | |
111 | - } | |
112 | - fprintf(stdout,"DATATYPE %d %d\n", varN, datatype); | |
113 | - if ((cstatus = CDFlib(SELECT_, zVAR_, varN, | |
114 | - GET_, zVAR_MAXREC_, &CDFmaxRec, NULL_)) != CDF_OK) | |
115 | - cdf_handle_error (cstatus); | |
101 | + if ((cstatus = CDFlib(SELECT_, CDF_zMODE_, zMODEon2, NULL_)) != CDF_OK) | |
102 | + cdf_handle_error (cstatus); | |
103 | + | |
104 | + while (datatype != CDF_EPOCH && datatype != CDF_EPOCH16 && datatype != CDF_TIME_TT2000){ | |
105 | + varN++; | |
106 | + if ((cstatus = CDFlib(SELECT_, zVAR_, varN, | |
107 | + GET_, zVAR_DATATYPE_, &datatype, NULL_)) != CDF_OK) | |
108 | + cdf_handle_error (cstatus); | |
109 | + // if (datatype == CDF_EPOCH16) break; | |
110 | + } | |
111 | + fprintf(stdout,"DATATYPE %d %d\n", varN, datatype); | |
112 | + if ((cstatus = CDFlib(SELECT_, zVAR_, varN, | |
113 | + GET_, zVAR_MAXREC_, &CDFmaxRec, NULL_)) != CDF_OK) | |
114 | + cdf_handle_error (cstatus); | |
115 | + | |
116 | + fprintf(stdout,"Max Recs %d\n", CDFmaxRec+1); | |
117 | + if (CDFmaxRec < 10) { | |
118 | + fprintf(stdout," %d\n", badFile); | |
119 | + exit (0); | |
120 | + } | |
121 | + | |
122 | + if ( datatype == CDF_TIME_TT2000 ) { | |
123 | + int_value = (long long *) malloc (sizeof(long long) * (CDFmaxRec+1)); | |
124 | + /******************* Get Epoch *************************/ | |
125 | + if ((cstatus = CDFlib (SELECT_, | |
126 | + zVAR_, varN, | |
127 | + zVAR_RECNUMBER_, RecStart, | |
128 | + zVAR_RECCOUNT_, CDFmaxRec+1, | |
129 | + zVAR_RECINTERVAL_, RecInt, | |
130 | + zVAR_DIMINDICES_, indices, | |
131 | + zVAR_DIMCOUNTS_, counts, | |
132 | + zVAR_DIMINTERVALS_, intervals, | |
133 | + GET_, zVAR_HYPERDATA_, int_value, NULL_)) != CDF_OK) | |
134 | + cdf_handle_error (cstatus); | |
135 | + } | |
136 | + else { | |
137 | + value = (double *)malloc(sizeof(double)* (CDFmaxRec+1)*((datatype == CDF_EPOCH16)+1)); | |
138 | + /******************* Get Epoch *************************/ | |
139 | + if ((cstatus = CDFlib (SELECT_, | |
140 | + zVAR_, varN, | |
141 | + zVAR_RECNUMBER_, RecStart, | |
142 | + zVAR_RECCOUNT_, CDFmaxRec+1, | |
143 | + zVAR_RECINTERVAL_, RecInt, | |
144 | + zVAR_DIMINDICES_, indices, | |
145 | + zVAR_DIMCOUNTS_, counts, | |
146 | + zVAR_DIMINTERVALS_, intervals, | |
147 | + GET_, zVAR_HYPERDATA_, value, NULL_)) != CDF_OK) | |
148 | + cdf_handle_error (cstatus); | |
149 | + } | |
150 | + | |
116 | 151 | |
117 | - fprintf(stdout,"Max Recs %d\n", CDFmaxRec+1); | |
118 | - if (CDFmaxRec < 10) { | |
119 | - fprintf(stdout," %d\n", badFile); | |
120 | - exit (0); | |
121 | - } | |
122 | - value = (double *)malloc(sizeof(double)* (CDFmaxRec+1)*((datatype == CDF_EPOCH16)+1)); | |
123 | - | |
124 | -/******************* Get Epoch *************************/ | |
125 | - if ((cstatus = CDFlib (SELECT_, | |
126 | - zVAR_, varN, | |
127 | - zVAR_RECNUMBER_, RecStart, | |
128 | - zVAR_RECCOUNT_, CDFmaxRec+1, | |
129 | - zVAR_RECINTERVAL_, RecInt, | |
130 | - zVAR_DIMINDICES_, indices, | |
131 | - zVAR_DIMCOUNTS_, counts, | |
132 | - zVAR_DIMINTERVALS_, intervals, | |
133 | - GET_, zVAR_HYPERDATA_, value, NULL_)) != CDF_OK) | |
134 | - cdf_handle_error (cstatus); | |
135 | 152 | |
136 | - delta = (int *)malloc(sizeof(int)* CDFmaxRec); | |
137 | - for (i = 1; i < CDFmaxRec+1; i++) | |
138 | - { | |
139 | - if (datatype == CDF_EPOCH16) { | |
140 | - epoch16[0] = value[2*(i-1)]; | |
141 | - epoch16[1] = value[2*(i-1)+1]; | |
142 | - EPOCH16breakdown(epoch16, &year, &month, &day, &hour, &minute, &sec, &msec, &mksec, &nsec, &psec); | |
143 | - value[i-1] = computeEPOCH(year, month, day, hour, minute, sec, msec); | |
144 | - epoch16[0] = value[2*i]; | |
145 | - epoch16[1] = value[2*i+1]; | |
146 | - EPOCH16breakdown(epoch16, &year, &month, &day, &hour, &minute, &sec, &msec, &mksec, &nsec, &psec); | |
147 | - value[i] = computeEPOCH(year, month, day, hour, minute, sec, msec); | |
148 | - } | |
149 | - delta[i-1] = (int)(value[i] - value[i-1] + 50)/100; | |
150 | - } | |
151 | - // fprintf(stdout,"value %f\n", value[11]-value[10]); | |
152 | - free(value); | |
153 | - // fprintf(stdout,"delta %d\n", delta[0]); | |
154 | - numEnough = CDFmaxRec/10; | |
155 | - while (min[1] < numEnough) { | |
156 | - fprintf(stdout,"minFalse %d\n", minFalse); | |
157 | - find_min(delta, CDFmaxRec, minFalse, min); | |
158 | - minFalse = min[0]; | |
159 | - } | |
153 | + delta = (int *)malloc(sizeof(int)* CDFmaxRec); | |
154 | + for (i = 1; i < CDFmaxRec+1; i++) | |
155 | + { | |
156 | + if (datatype == CDF_TIME_TT2000) { | |
157 | + dbl_value_ = CDF_TT2000_to_UTC_EPOCH(int_value[i-1]); | |
158 | + dbl_value = CDF_TT2000_to_UTC_EPOCH(int_value[i]); | |
159 | + delta[i-1] = (int)(dbl_value - dbl_value_ + 50)/100; | |
160 | + } | |
161 | + else { | |
162 | + if (datatype == CDF_EPOCH16) { | |
163 | + epoch16[0] = value[2*(i-1)]; | |
164 | + epoch16[1] = value[2*(i-1)+1]; | |
165 | + EPOCH16breakdown(epoch16, &year, &month, &day, &hour, &minute, &sec, &msec, &mksec, &nsec, &psec); | |
166 | + value[i-1] = computeEPOCH(year, month, day, hour, minute, sec, msec); | |
167 | + epoch16[0] = value[2*i]; | |
168 | + epoch16[1] = value[2*i+1]; | |
169 | + EPOCH16breakdown(epoch16, &year, &month, &day, &hour, &minute, &sec, &msec, &mksec, &nsec, &psec); | |
170 | + value[i] = computeEPOCH(year, month, day, hour, minute, sec, msec); | |
171 | + } | |
172 | + delta[i-1] = (int)(value[i] - value[i-1] + 50)/100; | |
173 | + } | |
174 | + } | |
175 | + // fprintf(stdout,"value %f\n", value[11]-value[10]); | |
176 | + if (datatype == CDF_TIME_TT2000) free(int_value); | |
177 | + else free(value); | |
178 | + // fprintf(stdout,"delta %d\n", delta[0]); | |
179 | + numEnough = CDFmaxRec/10; | |
180 | + while (min[1] < numEnough) { | |
181 | + fprintf(stdout,"minFalse %d\n", minFalse); | |
182 | + find_min(delta, CDFmaxRec, minFalse, min); | |
183 | + minFalse = min[0]; | |
184 | + } | |
160 | 185 | |
161 | - free(delta); | |
162 | - if ((cstatus = CDFlib(CLOSE_, CDF_, NULL_)) != CDF_OK) | |
163 | - cdf_handle_error (cstatus); | |
186 | + free(delta); | |
187 | + if ((cstatus = CDFlib(CLOSE_, CDF_, NULL_)) != CDF_OK) | |
188 | + cdf_handle_error (cstatus); | |
164 | 189 | |
165 | - // fprintf(stdout,"%d %f\n",min[1], (float)min[0]/100.0); | |
166 | - fprintf(stdout,"%f\n",(float)min[0]/10.0); | |
167 | - | |
190 | + // fprintf(stdout,"%d %f\n",min[1], (float)min[0]/100.0); | |
191 | + fprintf(stdout,"%f\n",(float)min[0]/10.0); | |
168 | 192 | } | ... | ... |
php/src/cdfstartstopfromdata.c
... | ... | @@ -16,21 +16,21 @@ |
16 | 16 | Global variables and structures |
17 | 17 | **************************************/ |
18 | 18 | long CDFDims, // Number of dimensions in a CDF file |
19 | - CDFVars, // Number of variables in a CDF file | |
20 | - CDFDimSizes[CDF_MAX_DIMS], // Dimension Sizes in a CDF file | |
21 | - CDFencoding, // Data encoding | |
22 | - CDFmajority, // Variable majority | |
23 | - CDFmaxRec, // max Record number | |
24 | - CDFAttrs; // number of CDF Attributes | |
25 | - // CDFdatatype; | |
19 | + CDFVars, // Number of variables in a CDF file | |
20 | + CDFDimSizes[CDF_MAX_DIMS], // Dimension Sizes in a CDF file | |
21 | + CDFencoding, // Data encoding | |
22 | + CDFmajority, // Variable majority | |
23 | + CDFmaxRec, // max Record number | |
24 | + CDFAttrs; // number of CDF Attributes | |
25 | +// CDFdatatype; | |
26 | 26 | |
27 | 27 | struct cdfvar { // CDF variable structure |
28 | - char name[CDF_VAR_NAME_LEN+1]; | |
29 | - long num; //variable number | |
30 | - long datatype; | |
31 | - long numElem; // variable dimensionality | |
32 | - long recVariance; // variable rec Variance | |
33 | - long dimVariances[CDF_MAX_DIMS]; // # of data values in dimSizes | |
28 | + char name[CDF_VAR_NAME_LEN+1]; | |
29 | + long num; //variable number | |
30 | + long datatype; | |
31 | + long numElem; // variable dimensionality | |
32 | + long recVariance; // variable rec Variance | |
33 | + long dimVariances[CDF_MAX_DIMS]; // # of data values in dimSizes | |
34 | 34 | } cdfVar; |
35 | 35 | |
36 | 36 | |
... | ... | @@ -40,88 +40,105 @@ struct cdfvar { // CDF variable structure |
40 | 40 | *--------------------------------------------------------------------------*/ |
41 | 41 | void cdf_handle_error(CDFstatus status) |
42 | 42 | { |
43 | + char message[CDF_STATUSTEXT_LEN+1]; | |
43 | 44 | |
44 | - char message[CDF_STATUSTEXT_LEN+1]; | |
45 | - | |
46 | - CDFerror (status, message); /* Get the appropriate message */ | |
47 | - fprintf (stderr, "%s\n", message); | |
48 | - exit(1); | |
45 | + CDFerror (status, message); /* Get the appropriate message */ | |
46 | + fprintf (stderr, "%s\n", message); | |
47 | + exit(1); | |
49 | 48 | } |
50 | 49 | |
51 | - | |
52 | - | |
53 | 50 | int main(int argc, char *argv[]) |
54 | 51 | { |
55 | - char fileName[MAX_FILE_NAME_LEN]; | |
56 | - long RecStart = 0, RecCount, RecInt = 1; | |
57 | - long indices[1] = {0}, intervals[1] = {1}, counts[1] = {1}; | |
58 | - long varN = -1; | |
59 | - long datatype = 0; | |
60 | - CDFstatus cstatus; // CDF status code | |
61 | - CDFid id; | |
62 | - double *value; | |
63 | - int i; | |
64 | - double epoch16[2]; | |
65 | - long year, month, day, hour, min, sec, msec, mksec, nsec, psec; | |
66 | - | |
67 | - if (argc <= 1) | |
68 | - exit(0); /* CDF input file name not specified */ | |
69 | - else | |
70 | - strcpy(fileName, argv[argc-1]); /* Get the input file name */ | |
52 | + char fileName[MAX_FILE_NAME_LEN]; | |
53 | + long RecStart = 0, RecCount, RecInt = 1; | |
54 | + long indices[1] = {0}, intervals[1] = {1}, counts[1] = {1}; | |
55 | + long varN = -1; | |
56 | + long datatype = 0; | |
57 | + CDFstatus cstatus; // CDF status code | |
58 | + CDFid id; | |
59 | + double *value; | |
60 | + int i; | |
61 | + double epoch16[2], dbl_value, dbl_value_; | |
62 | + long year, month, day, hour, min, sec, msec, mksec, nsec, psec; | |
63 | + long long *int_value; | |
64 | + | |
65 | + if (argc <= 1) | |
66 | + exit(0); /* CDF input file name not specified */ | |
67 | + else | |
68 | + strcpy(fileName, argv[argc-1]); /* Get the input file name */ | |
71 | 69 | |
72 | 70 | /*********************** Open CDF file *****************************/ |
73 | - if ((cstatus = CDFopen(fileName, &id)) != CDF_OK) | |
74 | - cdf_handle_error(cstatus); | |
71 | + if ((cstatus = CDFopen(fileName, &id)) != CDF_OK) | |
72 | + cdf_handle_error(cstatus); | |
75 | 73 | |
76 | 74 | /*********** treat all vars as zVars with eliminated false dimensionality and get Nrecs **********/ |
77 | 75 | |
78 | - if ((cstatus = CDFlib(SELECT_, CDF_zMODE_, zMODEon2, NULL_)) != CDF_OK) | |
79 | - cdf_handle_error (cstatus); | |
80 | - while (datatype != CDF_EPOCH && datatype != CDF_EPOCH16){ | |
81 | - varN++; | |
82 | - if ((cstatus = CDFlib(SELECT_, zVAR_, varN, | |
83 | - GET_, zVAR_DATATYPE_, &datatype, NULL_)) != CDF_OK) | |
84 | - cdf_handle_error (cstatus); | |
85 | - | |
86 | - // if (datatype == CDF_EPOCH16) break; | |
87 | - } | |
76 | + if ((cstatus = CDFlib(SELECT_, CDF_zMODE_, zMODEon2, NULL_)) != CDF_OK) | |
77 | + cdf_handle_error (cstatus); | |
78 | + | |
79 | + while (datatype != CDF_EPOCH && datatype != CDF_EPOCH16 && datatype != CDF_TIME_TT2000) { | |
80 | + varN++; | |
81 | + if ((cstatus = CDFlib(SELECT_, zVAR_, varN, | |
82 | + GET_, zVAR_DATATYPE_, &datatype, NULL_)) != CDF_OK) | |
83 | + cdf_handle_error (cstatus); | |
84 | + } | |
88 | 85 | |
89 | - if ((cstatus = CDFlib(SELECT_, zVAR_, varN, | |
90 | - GET_, zVAR_MAXREC_, &CDFmaxRec, NULL_)) != CDF_OK) | |
91 | - cdf_handle_error (cstatus); | |
92 | - | |
93 | - // fprintf(stdout,"Max Recs %d\n", CDFmaxRec+1); | |
94 | - if (CDFmaxRec < 1) exit (0); | |
95 | - | |
96 | - value = (double *)malloc(sizeof(double)* (CDFmaxRec+1)*((datatype == CDF_EPOCH16)+1)); | |
86 | + if ((cstatus = CDFlib(SELECT_, zVAR_, varN, | |
87 | + GET_, zVAR_MAXREC_, &CDFmaxRec, NULL_)) != CDF_OK) | |
88 | + cdf_handle_error (cstatus); | |
97 | 89 | |
98 | -/******************* Get Epoch *************************/ | |
99 | - if ((cstatus = CDFlib (SELECT_, | |
100 | - zVAR_, varN, | |
101 | - zVAR_RECNUMBER_, RecStart, | |
102 | - zVAR_RECCOUNT_, CDFmaxRec+1, | |
103 | - zVAR_RECINTERVAL_, RecInt, | |
104 | - zVAR_DIMINDICES_, indices, | |
105 | - zVAR_DIMCOUNTS_, counts, | |
106 | - zVAR_DIMINTERVALS_, intervals, | |
107 | - GET_, zVAR_HYPERDATA_, value, NULL_)) != CDF_OK) | |
108 | - cdf_handle_error (cstatus); | |
109 | - | |
110 | - if (datatype == CDF_EPOCH16) { | |
111 | - epoch16[0] = value[0]; | |
112 | - epoch16[1] = value[1]; | |
113 | - EPOCH16breakdown(epoch16, &year, &month, &day, &hour, &min, &sec, &msec, &mksec, &nsec, &psec); | |
114 | - value[0] = computeEPOCH(year, month, day, hour, min, sec, msec); | |
115 | - epoch16[0] = value[CDFmaxRec*2]; | |
116 | - epoch16[1] = value[CDFmaxRec*2+1]; | |
117 | - EPOCH16breakdown(epoch16, &year, &month, &day, &hour, &min, &sec, &msec, &mksec, &nsec, &psec); | |
118 | - value[CDFmaxRec] = computeEPOCH(year, month, day, hour, min, sec, msec); | |
119 | - } | |
120 | - printf("%f %f\n", value[0]/1000.0-TIMESHIFT, value[CDFmaxRec]/1000.0-TIMESHIFT); | |
90 | + // fprintf(stdout,"Max Recs %d\n", CDFmaxRec+1); | |
91 | + if (CDFmaxRec < 1) exit (0); | |
92 | + | |
93 | + if ( datatype == CDF_TIME_TT2000 ) { | |
94 | + int_value = (long long *) malloc (sizeof(long long) * (CDFmaxRec+1)); | |
95 | + /******************* Get Epoch *************************/ | |
96 | + if ((cstatus = CDFlib (SELECT_, | |
97 | + zVAR_, varN, | |
98 | + zVAR_RECNUMBER_, RecStart, | |
99 | + zVAR_RECCOUNT_, CDFmaxRec+1, | |
100 | + zVAR_RECINTERVAL_, RecInt, | |
101 | + zVAR_DIMINDICES_, indices, | |
102 | + zVAR_DIMCOUNTS_, counts, | |
103 | + zVAR_DIMINTERVALS_, intervals, | |
104 | + GET_, zVAR_HYPERDATA_, int_value, NULL_)) != CDF_OK) | |
105 | + cdf_handle_error (cstatus); | |
106 | + | |
107 | + dbl_value_ = CDF_TT2000_to_UTC_EPOCH(int_value[0]); | |
108 | + dbl_value = CDF_TT2000_to_UTC_EPOCH(int_value[CDFmaxRec]); | |
109 | + printf("%f %f\n", dbl_value_/1000.0-TIMESHIFT,dbl_value/1000.0-TIMESHIFT); | |
110 | + free(int_value); | |
111 | + } | |
112 | + else { | |
113 | + value = (double *)malloc(sizeof(double)* (CDFmaxRec+1)*((datatype == CDF_EPOCH16)+1)); | |
121 | 114 | |
115 | + /******************* Get Epoch *************************/ | |
116 | + if ((cstatus = CDFlib (SELECT_, | |
117 | + zVAR_, varN, | |
118 | + zVAR_RECNUMBER_, RecStart, | |
119 | + zVAR_RECCOUNT_, CDFmaxRec+1, | |
120 | + zVAR_RECINTERVAL_, RecInt, | |
121 | + zVAR_DIMINDICES_, indices, | |
122 | + zVAR_DIMCOUNTS_, counts, | |
123 | + zVAR_DIMINTERVALS_, intervals, | |
124 | + GET_, zVAR_HYPERDATA_, value, NULL_)) != CDF_OK) | |
125 | + cdf_handle_error (cstatus); | |
126 | + | |
127 | + if (datatype == CDF_EPOCH16) { | |
128 | + epoch16[0] = value[0]; | |
129 | + epoch16[1] = value[1]; | |
130 | + EPOCH16breakdown(epoch16, &year, &month, &day, &hour, &min, &sec, &msec, &mksec, &nsec, &psec); | |
131 | + value[0] = computeEPOCH(year, month, day, hour, min, sec, msec); | |
132 | + epoch16[0] = value[CDFmaxRec*2]; | |
133 | + epoch16[1] = value[CDFmaxRec*2+1]; | |
134 | + EPOCH16breakdown(epoch16, &year, &month, &day, &hour, &min, &sec, &msec, &mksec, &nsec, &psec); | |
135 | + value[CDFmaxRec] = computeEPOCH(year, month, day, hour, min, sec, msec); | |
136 | + } | |
137 | + | |
138 | + printf("%f %f\n", value[0]/1000.0-TIMESHIFT, value[CDFmaxRec]/1000.0-TIMESHIFT); | |
139 | + free(value); | |
140 | + } | |
122 | 141 | |
123 | - if ((cstatus = CDFlib(CLOSE_, CDF_, NULL_)) != CDF_OK) | |
124 | - cdf_handle_error (cstatus); | |
125 | - | |
126 | - free(value); | |
142 | + if ((cstatus = CDFlib(CLOSE_, CDF_, NULL_)) != CDF_OK) | |
143 | + cdf_handle_error (cstatus); | |
127 | 144 | } | ... | ... |