使用 HDFql 将日期时间添加到 HDF5 块

问题描述 投票:0回答:1

我有这段代码将数组块写入 HDF5,我想向每个块或另一个带有日期时间的字段添加时间戳属性

using AS.HDFql;

// declare variables
float[,,] traindata = new float[1, 100, 500];
int number;
int i;

// create an HDF5 file named 'Test.h5' and use (i.e. open) it
HDFql.Execute("create and use file Test.h5");

// create a chunked dataset named 'data' (within a group named 'grp') of data type float with three dimensions (the first dimension is extendible)
HDFql.Execute("create chunked(1, 100, 500) dataset grp/data as float(0 to unlimited, 100, 500)");

// register variable 'traindata'
number = HDFql.VariableRegister(traindata);

// loop 100000 times
for(i = 0; i < 100000; i++)
{
   // populate variable 'traindata'
   // (...)

   // insert (i.e. write) data stored in 'traindata' into the last position of 'data' (using a hyperslab selection)
   HDFql.Execute("insert into grp/data(-1:::) values from memory " + number);

   // alter (i.e. extend) first dimension of 'data' plus one unit
   HDFql.Execute("alter dimension grp/data to +1");
}
c# hdf5 hdfql
1个回答
1
投票

将时间戳与 HDF5 文件中写入的每个块相关联的一种方法是使用具有两个成员的复合数据集:第一个成员存储数据本身,而第二个成员存储时间戳(例如 UNIX 纪元时间)。更新您的代码,可能如下所示:

// use HDFql namespace
using AS.HDFql;

// declare structure
[StructLayout(LayoutKind.Sequential, Pack=1)]
public struct Data
{
    public float [,]vals;
    public int timestamp;
}

// declare variables
Data []traindata = new Data[1];
int number;
int i;

// create an HDF5 file named 'Test.h5' and use (i.e. open) it
HDFql.Execute("create and use file Test.h5");

// create a chunked dataset named 'data' (within a group named 'grp') as an extendible compound (with two members 'vals' and 'timestamp')
HDFql.Execute("create chunked(1) dataset grp/data as compound(vals as float(100, 500), timestamp as unsigned int)(0 to unlimited)");

// register variable 'traindata'
number = HDFql.VariableRegister(traindata);

// loop 100000 times
for(i = 0; i < 100000; i++)
{
    // populate variable 'traindata' (i.e. update members 'vals' and 'timestamp' with values)
    // (...)

    // alter (i.e. extend) first dimension of dataset 'data' plus one unit
    HDFql.Execute("alter dimension grp/data to +1");

    // insert (i.e. write) data stored in 'traindata' into the last position of dataset 'data' (using a hyperslab selection)
    HDFql.Execute("insert into grp/data[-1:::] values from memory " + number);
}
© www.soinside.com 2019 - 2024. All rights reserved.