Bug when writing flags to DIMAP, NetCDF and other formats

Hello

I stumbled upon a bug in SNAP when it comes to storing FlagCodings.
More specifically when flags are defined using masks and not by a single bit (flag value)

E.g., I have three flags defined by two bits.
|| flag name || flag mask || flag value ||
| Flag 1 | 0b0110 | 0b0010 |
| Flag 2 | 0b0110 | 0b0100 |
| Flag 3 | 0b0110 | 0b0110 |
I’m using the API method: FlagCoding.addFlag(String name, int flagMask, int flagValue, String description)
When creating the product in memory and using it in SNAP Desktop everything is fine also when storing to the ZNAP format.
For BEAM-DIMAP and NetCDF4-CF it fails. Probably also other formats are affected, like GeoTiff, but I haven’t tested them.
The mask is used as value for the flags. But both need to be saved and restored.
I did all tests with 10-SNAPSHOT (from today), but the error should also occur in SNAP 9.

An example file can be downloaded from WeTransfer. It is a ZNAP file. When you convert it to other formats you will see the error.

Hey @diana_harosa, @TomBlock
I think this is quite serious and should be considered as it turns right data into wrong data.

1 Like

JIRA ticket SNAP-3641 created

1 Like