mirror of https://github.com/ecmwf/eccodes.git
Geoiterator: Fix the has_next function
This commit is contained in:
parent
5ee76b97cc
commit
c51fa655df
|
@ -228,5 +228,7 @@ static long has_next(grib_iterator* iter)
|
|||
{
|
||||
if (iter->data == NULL)
|
||||
return 0;
|
||||
return iter->nv - iter->e;
|
||||
if (iter->e >= (long)(iter->nv - 1))
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* (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 <assert.h>
|
||||
|
||||
#include "grib_api.h"
|
||||
|
||||
static void usage(const char* prog)
|
||||
{
|
||||
printf("Usage: %s grib_file\n", prog);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
FILE* in = NULL;
|
||||
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);
|
||||
|
||||
iter = grib_iterator_new(h, 0, &err);
|
||||
assert(!err);
|
||||
assert(iter);
|
||||
|
||||
assert(grib_iterator_has_next(iter));
|
||||
n = 0;
|
||||
|
||||
while (grib_iterator_next(iter, &lat, &lon, &value)) {
|
||||
if (n < numberOfDataPoints - 1)
|
||||
assert(grib_iterator_has_next(iter));
|
||||
n++;
|
||||
}
|
||||
assert(n == numberOfDataPoints);
|
||||
|
||||
assert(grib_iterator_has_next(iter) == 0);
|
||||
|
||||
grib_iterator_delete(iter);
|
||||
|
||||
grib_handle_delete(h);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
#!/bin/sh
|
||||
# (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.ctest.sh
|
||||
|
||||
label="grib_geo_iter_test"
|
||||
|
||||
$EXEC ${test_dir}/grib_geo_iter
|
Loading…
Reference in New Issue