2013-03-25 12:04:10 +00:00
|
|
|
/*
|
2020-01-28 14:32:34 +00:00
|
|
|
* (C) Copyright 2005- ECMWF.
|
2013-03-25 12:04:10 +00:00
|
|
|
*
|
|
|
|
* This software is licensed under the terms of the Apache Licence Version 2.0
|
|
|
|
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
|
|
|
|
*
|
|
|
|
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
|
|
|
|
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2015-12-22 17:55:45 +00:00
|
|
|
* C Implementation: grib_multi
|
2013-03-25 12:04:10 +00:00
|
|
|
*
|
2020-12-17 15:07:13 +00:00
|
|
|
* Description: How to decode GRIB2 multi-field messages.
|
|
|
|
* Try to turn the multi support on and off to
|
2013-03-25 12:04:10 +00:00
|
|
|
* see the difference. Default is OFF.
|
2022-12-21 11:23:48 +00:00
|
|
|
* For all the tools (e.g., grib_ls etc) multi support is ON.
|
2013-03-25 12:04:10 +00:00
|
|
|
*/
|
|
|
|
#include <stdio.h>
|
2020-12-17 15:07:13 +00:00
|
|
|
#include <assert.h>
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2014-12-23 10:16:21 +00:00
|
|
|
#include "eccodes.h"
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2014-06-18 16:14:01 +00:00
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
2020-01-22 14:57:43 +00:00
|
|
|
int err = 0;
|
|
|
|
long parameterCategory = 0, parameterNumber = 0, discipline = 0;
|
|
|
|
FILE* in = NULL;
|
2017-06-21 18:21:58 +00:00
|
|
|
const char* filename = "../../data/multi.grib2";
|
2020-01-22 14:57:43 +00:00
|
|
|
codes_handle* h = NULL;
|
2020-12-17 15:07:13 +00:00
|
|
|
int mcount = 0;
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2024-02-24 18:24:16 +00:00
|
|
|
/* turn off support for GRIB2 multi-field messages */
|
|
|
|
codes_grib_multi_support_off(NULL);
|
|
|
|
|
2020-12-17 15:07:13 +00:00
|
|
|
/* turn on support for GRIB2 multi-field messages */
|
|
|
|
codes_grib_multi_support_on(NULL);
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2020-01-22 14:57:43 +00:00
|
|
|
in = fopen(filename, "rb");
|
|
|
|
if (!in) {
|
2020-05-14 19:21:31 +00:00
|
|
|
fprintf(stderr, "Error: unable to open file %s\n", filename);
|
2014-06-18 16:14:01 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2024-08-19 11:15:22 +00:00
|
|
|
CODES_CHECK(codes_count_in_file(NULL, in, &mcount), 0);
|
2020-12-17 15:07:13 +00:00
|
|
|
assert(mcount == 56);
|
2024-08-19 11:15:22 +00:00
|
|
|
printf("count_in_file counted %d messages\n", mcount);
|
2020-12-17 15:07:13 +00:00
|
|
|
|
|
|
|
mcount = 0;
|
2024-08-19 11:15:22 +00:00
|
|
|
CODES_CHECK(codes_count_in_filename(NULL, filename, &mcount), 0);
|
2020-12-17 15:07:13 +00:00
|
|
|
assert(mcount == 56);
|
2024-08-19 11:15:22 +00:00
|
|
|
printf("count_in_filename counted %d messages\n", mcount);
|
2020-12-17 15:07:13 +00:00
|
|
|
|
|
|
|
mcount = 0;
|
2020-01-22 14:57:43 +00:00
|
|
|
while ((h = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err)) != NULL) {
|
|
|
|
CODES_CHECK(err, 0);
|
2020-12-17 15:07:13 +00:00
|
|
|
++mcount;
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2020-01-22 14:57:43 +00:00
|
|
|
CODES_CHECK(codes_get_long(h, "discipline", &discipline), 0);
|
|
|
|
printf("discipline=%ld\n", discipline);
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2020-01-22 14:57:43 +00:00
|
|
|
CODES_CHECK(codes_get_long(h, "parameterCategory", ¶meterCategory), 0);
|
|
|
|
printf("parameterCategory=%ld\n", parameterCategory);
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2020-01-22 14:57:43 +00:00
|
|
|
CODES_CHECK(codes_get_long(h, "parameterNumber", ¶meterNumber), 0);
|
|
|
|
printf("parameterNumber=%ld\n", parameterNumber);
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2020-01-22 14:57:43 +00:00
|
|
|
if (discipline == 0 && parameterCategory == 2) {
|
2014-06-18 16:14:01 +00:00
|
|
|
if (parameterNumber == 2) printf("-------- u -------\n");
|
|
|
|
if (parameterNumber == 3) printf("-------- v -------\n");
|
|
|
|
}
|
2014-12-23 10:16:21 +00:00
|
|
|
codes_handle_delete(h);
|
2014-06-18 16:14:01 +00:00
|
|
|
}
|
2020-12-17 15:07:13 +00:00
|
|
|
assert(mcount == 56);
|
|
|
|
printf("codes_handle_new_from_file counted %d messages\n", mcount);
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2014-06-18 16:14:01 +00:00
|
|
|
fclose(in);
|
|
|
|
return 0;
|
2013-03-25 12:04:10 +00:00
|
|
|
}
|