From 505cd91d81b8211c6c3ecdd5bb07a047e6eebf30 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Thu, 27 Jul 2017 16:57:03 +0100 Subject: [PATCH] ECC-511: grid_complex_spatial_differencing and grib_get_data --- tools/grib_get_data.c | 54 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 9 deletions(-) diff --git a/tools/grib_get_data.c b/tools/grib_get_data.c index 720af871f..c1d137fd9 100644 --- a/tools/grib_get_data.c +++ b/tools/grib_get_data.c @@ -70,10 +70,23 @@ int grib_tool_new_file_action(grib_runtime_options* options,grib_tools_file* fil return 0; } +/* Return 1 if the GRIB message has missing values encoded in data section and not in bitmap */ +/* e.g. grid_complex_spatial_differencing with missingValueManagementUsed enabled */ +static int hasMissingValuesButNoBitmap(grib_handle* h) +{ + long missingValueManagementUsed = 0; + int err = grib_get_long(h, "missingValueManagementUsed", &missingValueManagementUsed); + if (!err) { + /* Key exists */ + return (missingValueManagementUsed!=0); + } + return 0; +} int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h) { int err=0; + double missingValue = 9999; int skip_missing=1; char *missing_string=NULL; int i=0; @@ -89,6 +102,30 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h) double *data_values=0,*lats=0,*lons=0; int n = 0; size_t size=0; + /* Cater for GRIBs which have missing values but no bitmap! */ + /* e.g. grid_complex_spatial_differencing with 'missingValueManagementUsed' enabled */ + const int missingValuesButNoBitmap = hasMissingValuesButNoBitmap(h); + + if (grib_options_on("m:")) { + /* User wants to see missing values */ + char* theEnd = NULL; + double mval=0; + char* kmiss=grib_options_get_option("m:"); + char* p = kmiss; + skip_missing=0; + while (*p != ':' && *p != '\0') p++; + if (*p == ':' && *(p+1) != '\0') { + *p='\0'; + missing_string=strdup(p+1); + } else { + missing_string=strdup(kmiss); + } + mval=strtod(kmiss, &theEnd); + if (kmiss != theEnd && *theEnd == '\0') + missingValue = mval; + grib_set_double(h,"missingValue",missingValue); + /*missing_string=grib_options_get_option("m:");*/ + } if (grib_options_on("F:")) format=grib_options_get_option("F:"); @@ -142,13 +179,6 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h) GRIB_CHECK(grib_get_long_array(h,"bitmap",bitmap,&bmp_len),0); } - skip_missing=1; - if (grib_options_on("m:")) { - /* User wants to see missing values */ - skip_missing=0; - missing_string=grib_options_get_option("m:"); - } - if (iter) fprintf(dump_file,"Latitude, Longitude, "); @@ -166,7 +196,10 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h) if (skip_missing==0){ /* Show missing values in data */ for (i=0;i