alex-robinson / ncio

Simple Fortran interface to NetCDF reading and writing.
23 stars 9 forks source link

Improved treatment of _FillValue and missing_value attributes in write functions #13

Closed einola closed 3 years ago

einola commented 3 years ago

There are two minor problems with the way the _FillValue and missing value attributes are currently set:

  1. The _FillValue attribute is always set to -9999d0
  2. The _FillValue and missing_value attributes are set to -9999d0, even if missing_value is not set when calling nc_write

Here I address those by

  1. Always setting v%FillValue = v%missing_value, when missing_value is present
  2. set v%missing_set and v%FillValue_set to .false. when initialising a new variable in nc_v_init.
alex-robinson commented 3 years ago

This looks like a good idea thanks.

One thing I see is that with your solution you also need to add the statements where you have defined the FillValue variable:

v%FillValue_set = .TRUE. 

If you add this update, then I can merge it in.

In general, I would note that when we originally developed ncio, missing_value was the typical attribute to set, but now CF-conventions specify that _FillValue is now the correct attribute. So this update had not been fully and cleanly implemented thereafter. I think in the future, eventually the missing_value attribute can be removed, or at least given lower priority compared to _FillValue.

einola commented 3 years ago

Yes, of course. I've pushed an update.

You're right that missing_value and _FillValue are doing the same thing, so it's annoying to have the two. But not much we can do about that it seems. I only caught this because ncview wasn't showing my mask properly :)