【问题标题】:HDF5 C Code generationHDF5 C 代码生成
【发布时间】:2012-06-26 04:40:36
【问题描述】:

我想知道是否有工具能够从 C 数据结构生成 C HDF5 读写代码。

我希望该工具能够解析 C 头文件并生成相应的 C HDF5 读/写代码。

可以区分静态分配和动态分配的情况。 第一次,我只对静态分配感兴趣。

例如,我想根据结构体 sensor_t 的定义生成以下代码,其中包含一个 int 和两个 double。显示的代码是 typedef C 结构到 C HDF5 结构的直接转换。

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);

我看了hdf网站没有成功

http://www.hdfgroup.org

我知道有些人尝试过使用 Perl 脚本的 HDF4

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

【问题讨论】:

    标签: c api code-generation hdf5


    【解决方案1】:

    有趣。在 NetCDF 土地上有 "ncgen"。 NetCDF-4 引入了复合类型的概念。 NetCDF4 也可以使用 HDF5 文件格式作为底层容器格式。

    因此,它不需要 C 头文件,但“CDL”标记非常简单:

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

    然后你可以用它来制作 netcdf C 代码:

    ncgen -c mine.cdl
    

    这不是你想要的。这根本不是你想要的,但它可能是你现在能得到的最接近的。

    【讨论】:

      猜你喜欢
      • 2013-08-01
      • 2010-10-31
      • 1970-01-01
      • 1970-01-01
      • 2011-09-17
      • 1970-01-01
      • 2012-03-04
      • 1970-01-01
      • 2015-10-25
      相关资源
      最近更新 更多