Commit 67a09be756f65c8f46a666d40618d64cb758b31b
1 parent
42c574d9
Exists in
master
and in
99 other branches
new info for remote
Showing
1 changed file
with
77 additions
and
17 deletions
Show diff stats
php/src/ncinfo_remote.c
... | ... | @@ -6,6 +6,8 @@ |
6 | 6 | * 1 - labels |
7 | 7 | * 2 - units |
8 | 8 | * 3 - fillvalue |
9 | + * 4 - is virtual | |
10 | + * 5 - is spectra | |
9 | 11 | */ |
10 | 12 | |
11 | 13 | #include <stdio.h> |
... | ... | @@ -17,7 +19,8 @@ void check(int stat) |
17 | 19 | { |
18 | 20 | if (stat != NC_NOERR) |
19 | 21 | { |
20 | - printf("NetCDF error: %s\n", nc_strerror(stat)); | |
22 | + fprintf(stdout,"Unknown"); | |
23 | + // printf("NetCDF error: %s\n", nc_strerror(stat)); | |
21 | 24 | exit(1); |
22 | 25 | } |
23 | 26 | } |
... | ... | @@ -35,9 +38,13 @@ main(int argc, char **argv) |
35 | 38 | int infoId; |
36 | 39 | float number_attr; |
37 | 40 | |
38 | - const char *info[2]; | |
41 | + const char *info[4]; | |
39 | 42 | info[0] = "UNITS"; |
40 | 43 | info[1] = "_FillValue"; |
44 | + info[2] = "FILLVAL"; | |
45 | + info[3] = "VIRTUAL"; | |
46 | + info[4] = "DISPLAY_TYPE"; | |
47 | + info[5] = "DEPEND_1"; | |
41 | 48 | |
42 | 49 | if (argc <= 3) { |
43 | 50 | printf("Incorrect number of arguments\n"); |
... | ... | @@ -54,6 +61,7 @@ main(int argc, char **argv) |
54 | 61 | stat = nc_inq_vardimid(ncID, varID, dimids); check(stat); |
55 | 62 | |
56 | 63 | size_t len = 0; |
64 | + // size | |
57 | 65 | if (ndims > 1) |
58 | 66 | for (i = 1; i < ndims; i++) { |
59 | 67 | stat = nc_inq_dimlen(ncID, dimids[i], &len); check(stat); |
... | ... | @@ -68,19 +76,36 @@ main(int argc, char **argv) |
68 | 76 | fprintf(stdout,"%d ", len); |
69 | 77 | } |
70 | 78 | |
71 | - if (infoId == 1) | |
79 | + if (infoId == 1) // components | |
72 | 80 | { |
73 | 81 | size_t attlen = 0; |
74 | - stat = nc_inq_attlen(ncID, varID, "LABL_PTR_1", &attlen); check(stat); | |
75 | - | |
82 | + stat = nc_inq_attlen(ncID, varID, "LABL_PTR_1", &attlen); | |
83 | + | |
84 | + if (stat != NC_NOERR) { | |
85 | + fprintf(stdout, "-1"); | |
86 | + exit(0); | |
87 | + } | |
76 | 88 | unsigned char *string_attr = (unsigned char *)malloc(attlen * sizeof(char*)); |
77 | - stat = nc_get_att(ncID, varID, "LABL_PTR_1", string_attr); check(stat); | |
78 | - | |
79 | - stat = nc_inq_varid(ncID, string_attr, &labelID); check(stat); | |
80 | - stat = nc_inq_varndims(ncID, labelID, &ndims); check(stat); | |
81 | - | |
82 | - stat = nc_inq_vardimid(ncID, labelID, dimids); check(stat); | |
83 | - | |
89 | + stat = nc_get_att(ncID, varID, "LABL_PTR_1", string_attr); | |
90 | + if (stat != NC_NOERR) { | |
91 | + fprintf(stdout, "-1"); | |
92 | + exit(0); | |
93 | + } | |
94 | + stat = nc_inq_varid(ncID, string_attr, &labelID); | |
95 | + if (stat != NC_NOERR) { | |
96 | + fprintf(stdout, "-1"); | |
97 | + exit(0); | |
98 | + } | |
99 | + stat = nc_inq_varndims(ncID, labelID, &ndims); | |
100 | + if (stat != NC_NOERR) { | |
101 | + fprintf(stdout, "-1"); | |
102 | + exit(0); | |
103 | + } | |
104 | + stat = nc_inq_vardimid(ncID, labelID, dimids); | |
105 | + if (stat != NC_NOERR) { | |
106 | + fprintf(stdout, "-1"); | |
107 | + exit(0); | |
108 | + } | |
84 | 109 | for (i = 0; i < ndims; i++) { |
85 | 110 | stat = nc_inq_dimlen(ncID, dimids[i], &len); check(stat); |
86 | 111 | if (i == 0) size = len; |
... | ... | @@ -100,7 +125,7 @@ main(int argc, char **argv) |
100 | 125 | free(string_var); |
101 | 126 | } |
102 | 127 | |
103 | - if (infoId == 2) | |
128 | + if (infoId == 2) // Units | |
104 | 129 | { |
105 | 130 | size_t attlen = 0; |
106 | 131 | stat = nc_inq_attlen(ncID, varID, info[infoId-2], &attlen); check(stat); |
... | ... | @@ -111,13 +136,48 @@ main(int argc, char **argv) |
111 | 136 | free(string_attr); |
112 | 137 | } |
113 | 138 | |
114 | - if (infoId == 3) | |
139 | + if (infoId == 3) // Fill Value | |
115 | 140 | { |
116 | - stat = nc_get_att(ncID, varID, info[infoId-2], &number_attr); check(stat); | |
117 | - fprintf(stdout, "%e", number_attr); | |
118 | - | |
141 | + stat = nc_get_att(ncID, varID, info[infoId-2], &number_attr); | |
142 | + | |
143 | + if (stat != NC_NOERR) { | |
144 | + stat = nc_get_att(ncID, varID, info[infoId-1], &number_attr); | |
145 | + check(stat); | |
146 | + } | |
147 | + fprintf(stdout, "%e", number_attr); | |
119 | 148 | } |
120 | 149 | |
150 | + if (infoId == 4) // is virtual | |
151 | + { | |
152 | + size_t attlen = 0; | |
153 | + stat = nc_inq_attlen(ncID, varID, info[infoId-1], &attlen); | |
154 | + if (stat != NC_NOERR) { | |
155 | + fprintf(stdout, "1"); | |
156 | + } | |
157 | + else { | |
158 | + fprintf(stdout, "0"); | |
159 | + } | |
160 | + } | |
161 | + | |
162 | + if (infoId == 5) // is spectrogram | |
163 | + { | |
164 | + size_t attlen = 0; | |
165 | + stat = nc_inq_attlen(ncID, varID, info[infoId-1], &attlen); | |
166 | + | |
167 | + if (stat != NC_NOERR) { | |
168 | + fprintf(stdout, "0"); | |
169 | + } | |
170 | + else { | |
171 | + unsigned char *string_attr = (unsigned char *)malloc(attlen * sizeof(char*)); | |
172 | + stat = nc_get_att(ncID, varID, info[infoId-1], string_attr); | |
173 | + if (strcasecmp(string_attr,"spectrogram") != 0) | |
174 | + fprintf(stdout, "0"); | |
175 | + else | |
176 | + fprintf(stdout, "1"); | |
177 | + | |
178 | + free(string_attr); | |
179 | + } | |
180 | + } | |
121 | 181 | stat = nc_close(ncID); |
122 | 182 | exit(0); |
123 | 183 | } | ... | ... |