Possible issue with IFTHEN operator
Added by Ernesto Barrera almost 13 years ago
Hi there,
While using version 1.4.6 of CDO I've found what seems to me an issue.
It is all about conditional selection operator "ifthen".
This is an example illustrating the situation (grib files are enclosed just in case you are interested in reproducing it).
Step 1: "data.grib" contains 3 fields of 2x2 elements each, the values are:
cdo outputf,"%8.4g,1" data.grib
0
0
0
0
20.86
20.33
16.88
16.53
1
1
1
1
Step 2: "mask.grib" is a mask for "data.grib" (3 fields of 2x2 elements each), the values are:
cdo outputf,"%8.4g,1" mask.grib
0
0
0
0
1
1
0
0
1
1
1
1
Step 3: Apply 'ifthen' operator to 'data.grib' using 'mask.grib':
cdo ifthen mask.grib data.grib result.grib
This operation retain original data values wherever mask elements are 1, replacing them by MISSING otherwise.
The result is:
cdo outputf,"%8.4g,1" result.grib
-9e+33 (missing)
-9e+33 (missing)
-9e+33 (missing)
-9e+33 (missing)
20.86
20.33
-9e+33 (missing)
-9e+33 (missing)
1
1
1
1
Step 4: When examining 'result.grib' with another software (ECMWF/GribAPI), the first 4 values are found to be wrongly assigned to zero.
grib_get_data -m-9E33 mask_data.grib
Latitude, Longitude, Value
27.950 -19.000 0.0000000000e+00 (?)
27.950 -18.950 0.0000000000e+00 (?)
28.000 -19.000 0.0000000000e+00 (?)
28.000 -18.950 0.0000000000e+00 (?)
Latitude, Longitude, Value
27.950 -19.000 2.0861175537e+01
27.950 -18.950 2.0329925537e+01
28.000 -19.000 -9E33 (ok)
28.000 -18.950 -9E33 (ok)
Latitude, Longitude, Value
27.950 -19.000 1.0000000000e+00
27.950 -18.950 1.0000000000e+00
28.000 -19.000 1.0000000000e+00
28.000 -18.950 1.0000000000e+00
Looking into the header (with GribAPI/grib_dump), I found that 'numberOfMissing' parameter is correctly assigned in each case (4 for the first field and 2 for the second one).
Apparently, 'missing' values are wrongly managed when 'ifthen' operator finds a fully zero field in the mask. But it works just fine when mask fields are composed by zeros and 'ones' or only 'ones'. Since the problem arises when grib files are processed with non-CDO tools I'm not totally sure it is a CDO issue.
Any hints would be appreciated.
Best regards
jbarrera
Replies (3)
Files enclosed... - Added by Ernesto Barrera almost 13 years ago
Files enclosed...
files.tar.gz (326 Bytes) files.tar.gz |
RE: Possible issue with IFTHEN operator - Added by Uwe Schulzweida over 12 years ago
Thanks for this report, I can reproduce this problem! I have checked the GRIB mask handling in CDO and it seems to be correct. wgrib can also handle this files correctly (http://www.cpc.ncep.noaa.gov/products/wesley/wgrib.html). I assume this could be a bug in the GRIB_API.
Best regards,
Uwe
RE: Possible issue with IFTHEN operator - Added by Ernesto Barrera over 12 years ago
Dear all,
Uwe was right, it was an grib_api issue and not a CDO's.
The problem has been already fixed in grib_api version 1.9.14, which will be released to the public next week.
In the mean time, remember that fields having all values missing are interpreted by grib_api as all-zero fields
Regards,
Ernesto