HDF5 C code generation

I was wondering if there is a tool capable of creating C HDF5 for reading and writing code from the C data structure.

I would like this tool to parse the C header file and generate the corresponding HDF5 C read / write code.

We can distinguish the case of static distribution and dynamic distribution. For the first time, I would only be interested in a static distribution.

For example, I would like to generate the following code from the definition of the sensor_t structure, which contains one int and two doubles. The displayed code is a direct conversion of the typedef C structure to the HDF5 C structure.

typedef struct { int serial_no; double temperature; double pressure; } sensor_t; #include "hdf5.h" hid_t memtype; herr_t status; memtype = H5Tcreate (H5T_COMPOUND, sizeof (sensor_t)); status = H5Tinsert (memtype, "serial_no", HOFFSET (sensor_t, serial_no), H5T_NATIVE_INT); status = H5Tinsert (memtype, "temperature", HOFFSET (sensor_t, temperature), H5T_NATIVE_DOUBLE); status = H5Tinsert (memtype, "pressure", HOFFSET (sensor_t, pressure), H5T_NATIVE_DOUBLE); sensor_t wdata[1]; status = H5Dread (dset, memtype, H5S_ALL, H5S_ALL, H5P_DEFAULT, rdata); status = H5Dwrite (dset, memtype, H5S_ALL, H5S_ALL, H5P_DEFAULT, wdata); 

I browsed the hdf website without success

http://www.hdfgroup.org

I know some tried to use HDF4 with a Perl script

http://www.srl.caltech.edu/ACE/ASC/exhdfgen/index.htm

+6
source share
1 answer

Interesting. There is "ncgen" on NetCDF land. NetCDF-4 introduced the idea of ​​complex types. NetCDF4 can also use the HDF5 file format as the main container format.

Thus, it will not accept the C header file, but the "CDL" markup is pretty simple:

 netcdf demo { types: compound mything { int id ; double d1 ; double d2 ; }; // mything dimensions: d1 = 1 ; variables: mything v1(d1) ; // global attributes: 

Then you can make netcdf C code from this:

 ncgen -c mine.cdl 

This is not exactly what you want. This is not at all what you want, but it is probably the closest thing you can get right now.

+2
source

Source: https://habr.com/ru/post/918892/


All Articles