From 248ea307b3097bfea01b2e6df8a806ff4ebfd209 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Mon, 19 Aug 2013 17:12:09 +0100 Subject: [PATCH] GRIB-420: grib_to_netcdf: Should fail if several messages have the same validity time --- tools/grib_to_netcdf.c | 54 ++++++++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/tools/grib_to_netcdf.c b/tools/grib_to_netcdf.c index 417b426aa..0639614c8 100644 --- a/tools/grib_to_netcdf.c +++ b/tools/grib_to_netcdf.c @@ -1181,6 +1181,23 @@ static request* field_to_request(field* f) return f->r->r; } +static request* fieldset_to_request(fieldset *fs) +{ + int i; + request* r = empty_request("GRIB"); + + if(!fs) + return 0; + + for(i = 0; i < fs->count; i++) + { + request *s = field_to_request(fs->fields[i]); + reqmerge(r,s); + } + + return r; +} + /*===============================================================================*/ /* hypercube from mars client */ /*===============================================================================*/ @@ -1848,6 +1865,21 @@ static long fcmonth2days(long date, long months) return days; } +static long request_fields(request *r) +{ + long cnt = 1; + parameter *p = r->params; + while(p) + { + if(p->name[0] != '_') + { + cnt *= count_values(r,p->name); + } + p = p->next; + } + return cnt; +} + /* Transform MARS FCMONTHs into number of months from base date. For example, FCMONTH=1 is current month == 0 */ static void fcmonth2nbmonths(request *r) @@ -3830,25 +3862,23 @@ int grib_tool_new_filename_action(grib_runtime_options* options, const char* fil grib_file_close(file->name, &e); -#if 0 - *data_r = fieldset_to_mars_request(v); - + /* Now do some checks */ + data_r = fieldset_to_request(fs); if(setup.checkvalidtime) { - int cnt = request_fields(*data_r); - if(v->count != i || (cnt < i)) + int cnt = request_fields(data_r); + if(fs->count != i || (cnt < i)) { grib_context_log(ctx, GRIB_LOG_ERROR, "Wrong number of fields"); - grib_context_log(ctx, GRIB_LOG_ERROR, "File contains %d GRIBs, %d left in internal description, %d in request", i, v->count, cnt); - grib_context_log(ctx, GRIB_LOG_ERROR, "MARS description"); - print_all_requests(setup.mars_description); + grib_context_log(ctx, GRIB_LOG_ERROR, "File contains %d GRIBs, %d left in internal description, %d in request", i, fs->count, cnt); + /*grib_context_log(ctx, GRIB_LOG_ERROR, "MARS description");*/ + /*print_all_requests(setup.mars_description);*/ grib_context_log(ctx, GRIB_LOG_ERROR, "Internal description"); - print_all_requests(*data_r); - return -1; + print_all_requests(data_r); + exit(1); } } - *fs = v; -#endif + return e; }