Missing values: simplify logic

This commit is contained in:
Shahram Najm 2017-08-08 16:57:41 +01:00
parent 9286984f1a
commit 185edecb48
1 changed files with 12 additions and 21 deletions

View File

@ -70,18 +70,6 @@ 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;
@ -102,9 +90,7 @@ 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);
long hasMissingValues = 0;
if (grib_options_on("m:")) {
/* User wants to see missing values */
@ -171,6 +157,9 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h)
exit(err);
}
/* Cater for GRIBs which have missing values but no bitmap */
/* See ECC-511 */
GRIB_CHECK(grib_get_long(h,"missingValuesPresent",&hasMissingValues),0);
GRIB_CHECK(grib_get_long(h,"bitmapPresent",&bitmapPresent),0);
if (bitmapPresent)
{
@ -196,9 +185,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++) {
int is_missing_val = (bitmapPresent && bitmap[i] == 0);
if (!bitmapPresent && missingValuesButNoBitmap) {
is_missing_val = (data_values[i] == missingValue);
int is_missing_val = 0;
if (hasMissingValues) {
if (bitmapPresent) is_missing_val = (bitmap[i] == 0);
else is_missing_val = (data_values[i] == missingValue);
}
if (iter) fprintf(dump_file,"%9.3f%9.3f ",lats[i],lons[i]);
@ -216,9 +206,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++) {
int is_missing_val = (bitmapPresent && bitmap[i] == 0);
if (!bitmapPresent && missingValuesButNoBitmap) {
is_missing_val = (data_values[i] == missingValue);
int is_missing_val = 0;
if (hasMissingValues) {
if (bitmapPresent) is_missing_val = (bitmap[i] == 0);
else is_missing_val = (data_values[i] == missingValue);
}
if (!is_missing_val){
if (iter) fprintf(dump_file,"%9.3f%9.3f ",lats[i],lons[i]);