From 381ea983799fedfaa9c056710ef8a58cfa79cdfb Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Thu, 12 Dec 2019 18:00:56 +0000 Subject: [PATCH] ECC-499: example --- examples/C/grib_nearest.c | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/examples/C/grib_nearest.c b/examples/C/grib_nearest.c index 56d8f7136..acb82fea1 100644 --- a/examples/C/grib_nearest.c +++ b/examples/C/grib_nearest.c @@ -11,7 +11,8 @@ /* * C Implementation: nearest * - * Description: how to get nearest point(s) + * Description: How to get nearest point(s). + * Assumes all input GRIB messages have the same grid geometry */ #include @@ -29,10 +30,10 @@ int main(int argc, char** argv) { int err = 0; long step=0; - size_t nfiles; - int i=0; - int no_values = 0; /* Default: decode the values */ + size_t nfiles=0; + size_t i=0, j=0; codes_fieldset* set=NULL; + const size_t max_numfiles = 100; codes_handle* h=NULL; char param[20]={0,}; size_t len=20; @@ -42,29 +43,29 @@ int main(int argc, char** argv) double distances[4]={0,}; int indexes[4]={0,}; char* order_by="param,step"; - double* pValues = values; + double* pValues = values; /* Default: decode the 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*)*max_numfiles); + + for(i=1; i= max_numfiles) + break; + filenames[j++]=(char*)strdup(argv[i]); + } } - - filenames=(char**)malloc(sizeof(char*)*nfiles); - for (i=0;i