-
Notifications
You must be signed in to change notification settings - Fork 262
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add built-in support for complex numbers #2650
Comments
Support for transient data types is a worthy goal but should be done first, as a separate issue, before tackling the complex number challenge, which seems far greater. I think adding support to netcdf-c for complex data types is a great idea for the following reasons:
However, there's a lot of work here. There is more than one complex type! C90 defines three:
For Fortran we have a slightly different situation:
Unfortunately the long double type in C is not very standard: https://en.wikipedia.org/wiki/Long_double. So if we just support complex float and complex double, that will probably handle most user needs. Call them NC_COMPLEX_FLOAT and NC_COMPLEX_DOUBLE. The API would then need to add new put/get_var functions for all the different flavors of access we support, var, vara, var1, vars. (Not varm, which is deprecated.) However, all these functions call one master get/put function which does the work. Those function will need to be modified to handle two new complex types. The type conversion function in netcdf-4 must be modified to allow conversion between the two complex types. However, conversion to/from any other type would generate an error. The good news is that the dispatch table would not have to change. That make life easier and proves the value of the dispatch table. Finally once that is all done and tested, corresponding wrapper functions need to be added in netcdf-fortran. So a lot of work, but a very worthy goal which would be a great addition to netCDF. |
Yes, you're entirely right about the different sized types, I'd glossed over that 🙂 Fortran single and double precision kinds map onto Should I make a separate issue for transient types? |
I would suggest a separate issue for transient types, and that it be handled first, before complex types are introduced. |
I can see how adding built-in support for complex numbers would be helpful. In addition to the comprehensive outline provided by @edwardhartnett (thanks Ed!), there are a few higher-level logistical concerns that spring to mind:
These aren't necessarily deal breakers, although they mean we won't be adding this in the short term. They are just the sort of big picture issues we have to consider before adding the functionality. In the meantime, a possible solution may exist by adding a function in |
To extend Ward's remarks. It is easy to add a complex type to a netcdf-4 file by creating a
|
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Some HDF5 wrappers, like h5py and HDF5.jl, write complex numbers using a transient datatype stored in the variable itself. This was discussed some years ago in cf-convention/cf-conventions#267, but that seems to be more about enums specifically.
Complex numbers are used in lots of domains, and while there is a lack of true consensus on how to store them (see cf-convention/discuss#369 for example), h5py and HDF5.jl both do the same thing: an HDF5 compound type with
r
andi
members. Having complex numbers also Just Work in netCDF would be of great help to lots of scientists, and enable greater compatibility between files created by different tools.Here's a concrete example of a file created using h5py:
The example in the Python netCDF4 docs on how to create compound types uses complex numbers, and reading that file back in with h5py or h5netcdf, the conversion to
complex
is automatic.C (in C99), C++, and Fortran all natively support complex numbers (and also all use the same representation as an array of two elements), so having built-in support for them in netCDF would be very useful.
This is probably the most relevant comment for implementation from the previous discussion: #267 (comment)
So, I'm proposing two things:
NC_COMPLEX
built-in external typeThe text was updated successfully, but these errors were encountered: