eccodes/tests/grib_geo_iter.cc

51 lines
1.3 KiB
C++
Raw Normal View History

2022-06-26 15:55:50 +00:00
/*
* (C) Copyright 2005- ECMWF.
*
* 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.
*/
#include <stdio.h>
#include <stdlib.h>
#include "grib_api_internal.h"
2022-06-26 15:55:50 +00:00
int main(int argc, char** argv)
{
int err = 0;
double lat, lon, value;
int n = 0;
const int numberOfDataPoints = 13280;
const char* sample_filename = "gg_sfc_grib2";
grib_handle* h = NULL;
grib_iterator* iter = NULL;
h = grib_handle_new_from_samples(0, sample_filename);
Assert(h);
2022-06-26 15:55:50 +00:00
iter = grib_iterator_new(h, 0, &err);
Assert(!err);
Assert(iter);
2022-06-26 15:55:50 +00:00
Assert(grib_iterator_has_next(iter));
2022-06-26 15:55:50 +00:00
n = 0;
while (grib_iterator_next(iter, &lat, &lon, &value)) {
if (n < numberOfDataPoints - 1)
Assert(grib_iterator_has_next(iter));
2022-06-26 15:55:50 +00:00
n++;
}
Assert(n == numberOfDataPoints);
2022-06-26 15:55:50 +00:00
Assert(grib_iterator_has_next(iter) == 0);
2022-06-26 15:55:50 +00:00
grib_iterator_delete(iter);
grib_handle_delete(h);
return 0;
}