ECC-511: grid_complex_spatial_differencing and grib_get_data

This commit is contained in:
Shahram Najm 2017-07-27 16:57:03 +01:00
parent 57de4da642
commit 505cd91d81
1 changed files with 45 additions and 9 deletions

View File

@ -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<numberOfPoints;i++) {
const int is_missing_val = (bitmapPresent && bitmap[i] == 0);
int is_missing_val = (bitmapPresent && bitmap[i] == 0);
if (!bitmapPresent && missingValuesButNoBitmap) {
is_missing_val = (data_values[i] == missingValue);
}
if (iter) fprintf(dump_file,"%9.3f%9.3f ",lats[i],lons[i]);
if (is_missing_val)
@ -183,7 +216,10 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h)
} else if ( skip_missing==1 ){
/* Skip the missing values in data */
for (i=0;i<numberOfPoints;i++) {
const int is_missing_val = (bitmapPresent && bitmap[i] == 0);
int is_missing_val = (bitmapPresent && bitmap[i] == 0);
if (!bitmapPresent && missingValuesButNoBitmap) {
is_missing_val = (data_values[i] == missingValue);
}
if (!is_missing_val){
if (iter) fprintf(dump_file,"%9.3f%9.3f ",lats[i],lons[i]);
fprintf(dump_file,format,data_values[i]);