Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HDF5 C Code generation

I was wondering if there were a tool able to produce C HDF5 read and write code from C data structure.

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

One can distinguish the case of static allocation and dynamic allocation. In a first time, I would only be interested in static allocation.

For example, I would like to generate the following code from the definition of the structure sensor_t, that contains one int and two doubles. The code displayed is the direct conversion of a typedef C struct to a C HDF5 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 have looked on the hdf website without success

http://www.hdfgroup.org

I know some have tried for HDF4 with a Perl script

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

like image 892
Guillaume Jacquenot Avatar asked Jun 24 '12 19:06

Guillaume Jacquenot


People also ask

Is HDF5 open source?

The Hierarchical Data Format version 5 (HDF5), is an open source file format that supports large, complex, heterogeneous data. HDF5 uses a "file directory" like structure that allows you to organize data within the file in many different structured ways, as you might do with files on your computer.

How are HDF5 files structured?

HDF5 files are organized in a hierarchical structure, with two primary structures: groups and datasets. HDF5 group: a grouping structure containing instances of zero or more groups or datasets, together with supporting metadata. HDF5 dataset: a multidimensional array of data elements, together with supporting metadata.

Is HDF5 a database?

HDF5 as a zero-configuration, ad-hoc scientific database for Python.

When should I use HDF5?

It is an open-source file which comes in handy to store large amount of data. As the name suggests, it stores data in a hierarchical structure within a single file. So if we want to quickly access a particular part of the file rather than the whole file, we can easily do that using HDF5.


1 Answers

Interesting. In NetCDF land there is "ncgen". NetCDF-4 introduced the idea of compound types. NetCDF4 also can use the HDF5 file format as the underlying container format.

So, it won't take a 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 out of that:

ncgen -c mine.cdl

It's not exactly what you want. It's not really what you want at all, but it's probably the closest you can get right now.

like image 124
Rob Latham Avatar answered Oct 17 '22 22:10

Rob Latham