netcdf-c icon indicating copy to clipboard operation
netcdf-c copied to clipboard

feature request - longdouble float type

Open jswhit opened this issue 3 years ago • 1 comments
trafficstars

When dealing with times using cftime, it is often a requirement to be able to convert a time value to a date and back again with microsecond accuracy. This is not a problem when the discretization of the time variable is an integer multiple of the netcdf units, but if not then it is virtually impossible to achieve this if the times are represented as 64-bit floats. See https://github.com/Unidata/cftime/pull/284 for a discussion of this. cftime can use long doubles (numpy.float128) internally preserve round-trips, but there is no netcdf float128 data type so once the times are written to a netcdf file the required precision is lost. I see that HDF5 has a longdouble type (H5T_NATIVE_LDOUBLE) - if a netcdf longdouble data type were implemented based upon this it would really help for this use case.

jswhit avatar Jul 07 '22 02:07 jswhit

Unfortunately, reading this discussion it seems that H5T_NATIVE_LDOUBLE is a memory datatype not a file datatype, so you may not actually be able to save a long double to an HDF5 file without losing precision (unless you create a custom datatype with H5T_OPAQUE).

jswhit avatar Jul 09 '22 21:07 jswhit