diff --git a/examples/C/CMakeLists.txt b/examples/C/CMakeLists.txt index 83a97fea4..f6e40fc24 100644 --- a/examples/C/CMakeLists.txt +++ b/examples/C/CMakeLists.txt @@ -83,6 +83,7 @@ list( APPEND tests_extra grib_set_bitmap grib_list grib_get_data + grib_nearest grib_nearest_multiple set_missing bufr_attributes diff --git a/examples/C/grib_nearest.c b/examples/C/grib_nearest.c index 192203e0f..56d8f7136 100644 --- a/examples/C/grib_nearest.c +++ b/examples/C/grib_nearest.c @@ -21,7 +21,7 @@ #include "eccodes.h" static void usage(const char* prog) { - printf("Usage: %s grib_file grib_file ...\n",prog); + printf("Usage: %s [-n] grib_file grib_file ...\n",prog); exit(1); } @@ -31,6 +31,7 @@ int main(int argc, char** argv) long step=0; size_t nfiles; int i=0; + int no_values = 0; /* Default: decode the values */ codes_fieldset* set=NULL; codes_handle* h=NULL; char param[20]={0,}; @@ -41,26 +42,35 @@ int main(int argc, char** argv) double distances[4]={0,}; int indexes[4]={0,}; char* order_by="param,step"; + double* pValues = values; size_t size=4; double lat=-40,lon=15; int mode=0; int count; + int filearg_offset = 1; char** filenames; codes_nearest* nearest=NULL; if (argc < 2) usage(argv[0]); - nfiles=argc-1; + + if (strcmp(argv[1],"-n")==0) { + no_values = 1; /* No values decoding. Just indexes, distances etc */ + nfiles -= 1; + pValues = NULL; + filearg_offset++; + } + filenames=(char**)malloc(sizeof(char*)*nfiles); for (i=0;i $temp +cat > $tempRef < $temp +cat > $tempRef <= 0.5 */ + Assert(values); for (i=0;i= qdistances[ii])) { @@ -193,7 +202,9 @@ int grib_nearest_find_multiple( } *poutlats=qoutlats[idx];poutlats++; *poutlons=qoutlons[idx];poutlons++; - *pvalues=qvalues[idx];pvalues++; + if (values) { + *pvalues=qvalues[idx];pvalues++; + } *pdistances=qdistances[idx];pdistances++; *pindexes=qindexes[idx];pindexes++; } diff --git a/src/grib_nearest_class_latlon_reduced.c b/src/grib_nearest_class_latlon_reduced.c index 4e704a3a7..ab9a9d9a6 100644 --- a/src/grib_nearest_class_latlon_reduced.c +++ b/src/grib_nearest_class_latlon_reduced.c @@ -328,7 +328,9 @@ static int find(grib_nearest* nearest, grib_handle* h, distances[kk]=self->distances[kk]; outlats[kk]=self->lats[self->j[jj]]; outlons[kk]=self->lons[self->k[kk]]; - grib_get_double_element_internal(h,self->values_key,self->k[kk],&(values[kk])); + if (values) { /* ECC-499 */ + grib_get_double_element_internal(h,self->values_key,self->k[kk],&(values[kk])); + } indexes[kk]=self->k[kk]; kk++; } diff --git a/src/grib_nearest_class_reduced.c b/src/grib_nearest_class_reduced.c index ccb0884f4..c56af6799 100644 --- a/src/grib_nearest_class_reduced.c +++ b/src/grib_nearest_class_reduced.c @@ -382,7 +382,9 @@ static int find(grib_nearest* nearest, grib_handle* h, distances[kk]=self->distances[kk]; outlats[kk]=self->lats[self->j[jj]]; outlons[kk]=self->lons[self->k[kk]]; - grib_get_double_element_internal(h,self->values_key,self->k[kk],&(values[kk])); + if (values) { /* ECC-499 */ + grib_get_double_element_internal(h,self->values_key,self->k[kk],&(values[kk])); + } indexes[kk]=self->k[kk]; kk++; } diff --git a/src/grib_nearest_class_regular.c b/src/grib_nearest_class_regular.c index d138ba0db..1e6612b7d 100644 --- a/src/grib_nearest_class_regular.c +++ b/src/grib_nearest_class_regular.c @@ -420,7 +420,9 @@ static int find(grib_nearest* nearest, grib_handle* h, outlats[kk] = new_lat; outlons[kk] = new_lon; } - grib_get_double_element_internal(h,self->values_key,self->k[kk],&(values[kk])); + if (values) { /* ECC-499 */ + grib_get_double_element_internal(h,self->values_key,self->k[kk],&(values[kk])); + } /* Using the brute force approach described above */ /* Assert(self->k[kk] < nvalues); */ /* values[kk]=nearest->values[self->k[kk]]; */