我想制作一个数据类型不同的数据集,例如,一个长字符串数组。我参考了https://support.hdfgroup.org/ftp/HDF5/examples/misc-examples/sample-programs/strings.c并编写了一个简单的测试程序,但是当我打开结果文件时,它是空的。
我想知道我做错了什么。我正在使用HDF.PInvoke.1.10.5.2和C#。
using HDF.PInvoke;
using System.Globalization;
using System.IO;
using System.Runtime.InteropServices;
namespace WindowsFormsApp3
{
public unsafe struct struct_TR
{
public long[] arr_currentLong;
public string[] arr_currentString;
public struct_TR(byte size_currentTime, byte size_currentPrice)
{
arr_currentLong = new long[size_currentTime];
arr_currentString = new string[size_currentPrice];
}
}
public unsafe partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
string currentPath = Path.GetDirectoryName(Application.ExecutablePath);
Directory.SetCurrentDirectory(currentPath);
struct_TR struct01 = new struct_TR(2, 2);
struct01.arr_currentLong[0] = 10;
struct01.arr_currentLong[1] = 11;
struct01.arr_currentString[0] = "Hello";
struct01.arr_currentString[1] = "Hi";
long file_id = H5F.create(@"file.h5", H5F.ACC_TRUNC, H5P.DEFAULT, H5P.DEFAULT);
long myDataSpace = H5S.create(H5S.class_t.SCALAR);
IntPtr pnt = Marshal.AllocHGlobal(Marshal.SizeOf(struct01));
long strtype = H5T.copy(H5T.C_S1);
long myH5MessageType = H5T.create(H5T.class_t.COMPOUND, pnt);
H5T.insert(myH5MessageType, "long", pnt, H5T.NATIVE_LONG);
H5T.insert(myH5MessageType, "string", pnt, strtype);
long myDataSet = H5D.create(file_id, "/myCustomData", myH5MessageType, myDataSpace);
long write_id = H5D.write(myDataSet, myDataSpace, H5S.ALL, H5S.ALL, H5P.DEFAULT, pnt);
long status = H5D.close(myDataSet);
long status2 = H5S.close(myDataSpace);
long status3 = H5F.close(file_id);
}
}
}