如何写入特定地址GCHandle(HDF5读取)

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

我是 C# 初学者,目前使用 HDF5 库来读取我的 HDF5 文件。

我的情况是,我想使用 H5S.select_hyperslab() 读取特定行,但我不知道如何使用 GCHandle 类写入 2D 变量的特定地址。

所以我有一个浮点变量 [x,y],我想将 HDF5 文件中的行写入 [i,0]。

你知道我该怎么做吗?

我的代码涉及的部分:

        for (i = 0; i < C_NB_MAX_PARAMETERS; i++)
        {
            hnd = GCHandle.Alloc(m_correctedSignals[i,0], GCHandleType.Pinned);

            /* Get index of C_PARAMS_NAMES[i] in the file */
            datasetOffset[0] = HDF5_GET_PARAM_INDEX(pa_numbersOfParameters, pa_parametersNames, C_PARAMS_NAMES[i]);
            if (datasetOffset[0] < *pa_numbersOfParameters)
            {
                /* Parameter found */
                H5S.select_hyperslab(dataspace_id, H5S.seloper_t.SET, datasetOffset, null, datasetCount, null);

                /* Read the dataset. */
                H5D.read(dataset_id, H5T.NATIVE_FLOAT, memspace_id, dataspace_id, H5P.DEFAULT, hnd.AddrOfPinnedObject());
            }

            hnd.Free();
        }
c# pointers pinvoke hdf5
1个回答
0
投票

为了说明如何使用 HDFql 在 C# 中解决这个问题(抱歉不知道其他 API 是如何工作的),我假设您的数据集名为

dset
且类型为二维
float
(尺寸 50x100)。

// declare variable 'data' that will store values from the dataset
float []data = new float[100]; 

// read third row of dataset 'dset' using an hyperslab selection and populate variable 'data' with it
HDFql.Execute("SELECT FROM dset[2:::1] INTO MEMORY " + HDFql.VariableTransientRegister(data));

// print values stored in variable 'data'
for(int i = 0; i < 100; i++)
{
    System.Console.WriteLine(data[i]);
}
© www.soinside.com 2019 - 2024. All rights reserved.