@@ -17,19 +17,20 @@ static int get_packing_type_code(const char* packingType)
17
17
{
18
18
int result = GRIB_UTIL_PACKING_TYPE_GRID_SIMPLE;
19
19
if (packingType == NULL )
20
- return result ;
20
+ return GRIB_UTIL_PACKING_TYPE_SAME_AS_INPUT ;
21
21
22
22
if (STR_EQUAL (packingType, " grid_jpeg" ))
23
- result = GRIB_UTIL_PACKING_TYPE_JPEG;
24
- if (STR_EQUAL (packingType, " grid_ccsds" ))
25
- result = GRIB_UTIL_PACKING_TYPE_CCSDS;
23
+ return GRIB_UTIL_PACKING_TYPE_JPEG;
24
+ else if (STR_EQUAL (packingType, " grid_ccsds" ))
25
+ return GRIB_UTIL_PACKING_TYPE_CCSDS;
26
26
else if (STR_EQUAL (packingType, " grid_simple" ))
27
- result = GRIB_UTIL_PACKING_TYPE_GRID_SIMPLE;
27
+ return GRIB_UTIL_PACKING_TYPE_GRID_SIMPLE;
28
28
else if (STR_EQUAL (packingType, " grid_second_order" ))
29
- result = GRIB_UTIL_PACKING_TYPE_GRID_SECOND_ORDER;
29
+ return GRIB_UTIL_PACKING_TYPE_GRID_SECOND_ORDER;
30
30
else if (STR_EQUAL (packingType, " grid_ieee" ))
31
- result = GRIB_UTIL_PACKING_TYPE_IEEE;
31
+ return GRIB_UTIL_PACKING_TYPE_IEEE;
32
32
33
+ Assert (!" Invalid packingType" );
33
34
return result;
34
35
}
35
36
@@ -47,8 +48,8 @@ static void test_reduced_gg(int remove_local_def, int edition, const char* packi
47
48
const void * buffer = NULL ;
48
49
char gridType[128 ] = {0 ,};
49
50
50
- codes_handle * handle = 0 ;
51
- codes_handle * finalh = 0 ;
51
+ grib_handle * handle = 0 ;
52
+ grib_handle * finalh = 0 ;
52
53
grib_util_grid_spec spec = {0 ,};
53
54
grib_util_packing_spec packing_spec = {0 ,};
54
55
@@ -70,6 +71,9 @@ static void test_reduced_gg(int remove_local_def, int edition, const char* packi
70
71
CODES_CHECK (grib_get_size (handle, " values" , &inlen), 0 );
71
72
values = (double *)malloc (sizeof (double ) * inlen);
72
73
CODES_CHECK (grib_get_double_array (handle, " values" , values, &inlen), 0 );
74
+ // make sure values are not constant
75
+ values[0 ] = 4.4 ;
76
+ values[1 ] = 5.5 ;
73
77
for (i = 0 ; i < inlen; ++i) {
74
78
values[i] *= 1.10 ;
75
79
}
@@ -90,7 +94,10 @@ static void test_reduced_gg(int remove_local_def, int edition, const char* packi
90
94
packing_spec.packing_type = get_packing_type_code (packingType);
91
95
packing_spec.bitsPerValue = 24 ;
92
96
packing_spec.accuracy = GRIB_UTIL_ACCURACY_USE_PROVIDED_BITS_PER_VALUES;
93
- packing_spec.packing = GRIB_UTIL_PACKING_USE_PROVIDED;
97
+ if (packingType)
98
+ packing_spec.packing = GRIB_UTIL_PACKING_USE_PROVIDED;
99
+ else
100
+ packing_spec.packing = GRIB_UTIL_PACKING_SAME_AS_INPUT;
94
101
95
102
/* Extra settings
96
103
packing_spec.extra_settings_count++;
@@ -112,7 +119,7 @@ static void test_reduced_gg(int remove_local_def, int edition, const char* packi
112
119
113
120
/* Try some invalid inputs and check it is handled */
114
121
{
115
- codes_handle * h2 = 0 ;
122
+ grib_handle * h2 = 0 ;
116
123
packing_spec.accuracy = 999 ;
117
124
h2 = grib_util_set_spec (handle, &spec, &packing_spec, set_spec_flags, values, outlen, &err);
118
125
Assert (err == GRIB_INTERNAL_ERROR);
@@ -158,18 +165,18 @@ static void test_regular_ll(int remove_local_def, int edition, const char* packi
158
165
char gridType[128 ] = {0 ,};
159
166
long input_edition = 0 ;
160
167
161
- codes_handle * handle = 0 ;
162
- codes_handle * finalh = 0 ;
168
+ grib_handle * handle = 0 ;
169
+ grib_handle * finalh = 0 ;
163
170
grib_util_grid_spec spec = {0 ,};
164
171
grib_util_packing_spec packing_spec = {0 ,};
165
172
166
173
Assert (input_filename);
167
174
in = fopen (input_filename, " rb" );
168
175
Assert (in);
169
- handle = codes_handle_new_from_file (0 , in, PRODUCT_GRIB , &err);
176
+ handle = grib_handle_new_from_file (0 , in, &err);
170
177
Assert (handle);
171
178
172
- CODES_CHECK (codes_get_long (handle, " edition" , &input_edition), 0 );
179
+ CODES_CHECK (grib_get_long (handle, " edition" , &input_edition), 0 );
173
180
174
181
CODES_CHECK (grib_get_string (handle, " gridType" , gridType, &slen), 0 );
175
182
if (!STR_EQUAL (gridType, " regular_ll" )) {
@@ -180,9 +187,12 @@ static void test_regular_ll(int remove_local_def, int edition, const char* packi
180
187
out = fopen (output_filename, " wb" );
181
188
Assert (out);
182
189
183
- CODES_CHECK (codes_get_size (handle, " values" , &inlen), 0 );
190
+ CODES_CHECK (grib_get_size (handle, " values" , &inlen), 0 );
184
191
values = (double *)malloc (sizeof (double ) * inlen);
185
- CODES_CHECK (codes_get_double_array (handle, " values" , values, &inlen), 0 );
192
+ CODES_CHECK (grib_get_double_array (handle, " values" , values, &inlen), 0 );
193
+ // make sure values are not constant
194
+ values[0 ] = 4.4 ;
195
+ values[1 ] = 5.5 ;
186
196
187
197
spec.grid_type = GRIB_UTIL_GRID_SPEC_REGULAR_LL;
188
198
spec.Nj = 14 ;
@@ -201,7 +211,10 @@ static void test_regular_ll(int remove_local_def, int edition, const char* packi
201
211
packing_spec.packing_type = get_packing_type_code (packingType);
202
212
packing_spec.bitsPerValue = 24 ;
203
213
packing_spec.accuracy = GRIB_UTIL_ACCURACY_USE_PROVIDED_BITS_PER_VALUES;
204
- packing_spec.packing = GRIB_UTIL_PACKING_USE_PROVIDED;
214
+ if (packingType)
215
+ packing_spec.packing = GRIB_UTIL_PACKING_USE_PROVIDED;
216
+ else
217
+ packing_spec.packing = GRIB_UTIL_PACKING_SAME_AS_INPUT;
205
218
206
219
packing_spec.extra_settings_count ++;
207
220
packing_spec.extra_settings [0 ].type = GRIB_TYPE_LONG;
@@ -215,7 +228,7 @@ static void test_regular_ll(int remove_local_def, int edition, const char* packi
215
228
packing_spec.deleteLocalDefinition = 1 ;
216
229
}
217
230
218
- finalh = codes_grib_util_set_spec (
231
+ finalh = grib_util_set_spec (
219
232
handle,
220
233
&spec,
221
234
&packing_spec,
@@ -232,19 +245,19 @@ static void test_regular_ll(int remove_local_def, int edition, const char* packi
232
245
if (input_edition == 1 ) {
233
246
const double expected_lat1 = 60.001 ;
234
247
double lat1 = 0 ;
235
- CODES_CHECK (codes_get_double (finalh, " latitudeOfFirstGridPointInDegrees" , &lat1), 0 );
248
+ CODES_CHECK (grib_get_double (finalh, " latitudeOfFirstGridPointInDegrees" , &lat1), 0 );
236
249
Assert (fabs (lat1 - expected_lat1) < 1e-10 );
237
250
}
238
251
239
252
/* Write out the message to the output file */
240
- CODES_CHECK (codes_get_message (finalh, &buffer, &size), 0 );
253
+ CODES_CHECK (grib_get_message (finalh, &buffer, &size), 0 );
241
254
CODES_CHECK (codes_check_message_header (buffer, size, PRODUCT_GRIB), 0 );
242
255
CODES_CHECK (codes_check_message_footer (buffer, size, PRODUCT_GRIB), 0 );
243
256
if (fwrite (buffer, 1 , size, out) != size) {
244
257
Assert (0 );
245
258
}
246
- codes_handle_delete (handle);
247
- codes_handle_delete (finalh);
259
+ grib_handle_delete (handle);
260
+ grib_handle_delete (finalh);
248
261
free (values);
249
262
fclose (in);
250
263
fclose (out);
@@ -266,13 +279,13 @@ static void test_grid_complex_spatial_differencing(int remove_local_def, int edi
266
279
char gridType[128] = {0,};
267
280
double theMax,theMin,theAverage;
268
281
269
- codes_handle *handle = 0;
270
- codes_handle *finalh = 0;
282
+ grib_handle *handle = 0;
283
+ grib_handle *finalh = 0;
271
284
grib_util_grid_spec spec={0,};
272
285
grib_util_packing_spec packing_spec={0,};
273
286
274
287
in = fopen(input_filename,"rb"); Assert(in);
275
- handle = codes_handle_new_from_file (0, in, PRODUCT_GRIB , &err); Assert(handle);
288
+ handle = grib_handle_new_from_file (0, in, &err); Assert(handle);
276
289
277
290
CODES_CHECK(grib_get_string(handle, "packingType", gridType, &slen),0);
278
291
if (!STR_EQUAL(gridType, "grid_complex_spatial_differencing")) {
@@ -281,13 +294,13 @@ static void test_grid_complex_spatial_differencing(int remove_local_def, int edi
281
294
}
282
295
out = fopen(output_filename,"wb"); Assert(out);
283
296
284
- CODES_CHECK(codes_get_size (handle,"values",&inlen), 0);
297
+ CODES_CHECK(grib_get_size (handle,"values",&inlen), 0);
285
298
values = (double*)malloc(sizeof(double)*inlen);
286
- CODES_CHECK(codes_get_double_array (handle, "values", values,&inlen), 0);
299
+ CODES_CHECK(grib_get_double_array (handle, "values", values,&inlen), 0);
287
300
288
- CODES_CHECK(codes_get_double (handle, "max", &theMax),0);
289
- CODES_CHECK(codes_get_double (handle, "min", &theMin),0);
290
- CODES_CHECK(codes_get_double (handle, "average",&theAverage),0);
301
+ CODES_CHECK(grib_get_double (handle, "max", &theMax),0);
302
+ CODES_CHECK(grib_get_double (handle, "min", &theMin),0);
303
+ CODES_CHECK(grib_get_double (handle, "average",&theAverage),0);
291
304
printf("inlen=%lu \t max=%g \t min=%g \t avg=%g\n", inlen, theMax, theMin, theAverage);
292
305
293
306
spec.grid_type = GRIB_UTIL_GRID_SPEC_REGULAR_LL;
@@ -315,7 +328,7 @@ static void test_grid_complex_spatial_differencing(int remove_local_def, int edi
315
328
packing_spec.deleteLocalDefinition = 1;
316
329
}
317
330
318
- finalh = codes_grib_util_set_spec (
331
+ finalh = grib_util_set_spec (
319
332
handle,
320
333
&spec,
321
334
&packing_spec,
@@ -327,12 +340,12 @@ static void test_grid_complex_spatial_differencing(int remove_local_def, int edi
327
340
Assert(err == 0);
328
341
329
342
/* Write out the message to the output file */
330
- CODES_CHECK(codes_get_message (finalh, &buffer, &size),0);
343
+ CODES_CHECK(grib_get_message (finalh, &buffer, &size),0);
331
344
if(fwrite(buffer,1,size,out) != size) {
332
345
Assert(0);
333
346
}
334
- codes_handle_delete (handle);
335
- codes_handle_delete (finalh);
347
+ grib_handle_delete (handle);
348
+ grib_handle_delete (finalh);
336
349
fclose(in);
337
350
fclose(out);
338
351
}
0 commit comments