2016-12-02 18:44:44 +00:00
|
|
|
/*
|
2020-01-28 14:32:34 +00:00
|
|
|
* (C) Copyright 2005- ECMWF.
|
2016-12-02 18:44:44 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Description: Reads a GRIB message from file, measures read time.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "grib_api_internal.h"
|
|
|
|
|
2020-01-29 12:05:02 +00:00
|
|
|
static void usage(const char* prog)
|
|
|
|
{
|
|
|
|
printf("usage: %s filename\n", prog);
|
2016-12-02 18:44:44 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef GRIB_TIMER
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
2020-01-29 12:05:02 +00:00
|
|
|
grib_timer* tes = grib_get_timer(0, "decoding", 0, 0);
|
|
|
|
FILE* in = NULL;
|
2016-12-02 18:44:44 +00:00
|
|
|
int err = 0, i = 0;
|
2020-01-29 12:05:02 +00:00
|
|
|
grib_handle* h = NULL;
|
|
|
|
size_t values_len = 0;
|
|
|
|
double* values = NULL;
|
|
|
|
double duration_actual = 0;
|
2016-12-05 14:00:08 +00:00
|
|
|
const double duration_max = 3; /* seconds */
|
2016-12-02 18:44:44 +00:00
|
|
|
const int num_repetitions = 1000;
|
|
|
|
|
2020-01-29 12:05:02 +00:00
|
|
|
if (argc < 2) usage(argv[0]);
|
2016-12-02 18:44:44 +00:00
|
|
|
|
2020-01-29 12:05:02 +00:00
|
|
|
in = fopen(argv[1], "rb");
|
|
|
|
if (!in) {
|
|
|
|
printf("ERROR: unable to open file %s\n", argv[1]);
|
2016-12-02 18:44:44 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-02-28 12:19:28 +00:00
|
|
|
/* create new handle */
|
2016-12-02 18:44:44 +00:00
|
|
|
err = 0;
|
2020-01-29 12:05:02 +00:00
|
|
|
h = grib_handle_new_from_file(0, in, &err);
|
2016-12-02 18:44:44 +00:00
|
|
|
if (h == NULL) {
|
|
|
|
printf("Error: unable to create handle from file.\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get the size of the values array*/
|
2020-01-29 12:05:02 +00:00
|
|
|
GRIB_CHECK(grib_get_size(h, "values", &values_len), 0);
|
2016-12-02 18:44:44 +00:00
|
|
|
|
2020-01-29 12:05:02 +00:00
|
|
|
values = malloc(values_len * sizeof(double));
|
2016-12-02 18:44:44 +00:00
|
|
|
|
|
|
|
/* get data values*/
|
|
|
|
grib_timer_start(tes);
|
2020-01-29 12:05:02 +00:00
|
|
|
for (i = 0; i < num_repetitions; i++) {
|
|
|
|
GRIB_CHECK(grib_get_double_array(h, "values", values, &values_len), 0);
|
2016-12-02 18:44:44 +00:00
|
|
|
}
|
2020-01-29 12:05:02 +00:00
|
|
|
grib_timer_stop(tes, 0);
|
2016-12-05 14:00:08 +00:00
|
|
|
duration_actual = grib_timer_value(tes);
|
|
|
|
if (duration_actual > duration_max) {
|
2016-12-02 18:44:44 +00:00
|
|
|
fprintf(stderr, "Decoding took longer than expected! actual time=%g, expected to take less than %g seconds",
|
2016-12-05 14:00:08 +00:00
|
|
|
duration_actual, duration_max);
|
2016-12-02 18:44:44 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2016-12-05 14:00:08 +00:00
|
|
|
printf("Test passed. Actual decode time=%g\n", duration_actual);
|
2016-12-02 18:44:44 +00:00
|
|
|
free(values);
|
|
|
|
grib_handle_delete(h);
|
|
|
|
fclose(in);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#else
|
2020-01-29 12:05:02 +00:00
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2016-12-02 18:44:44 +00:00
|
|
|
#endif
|