这里有一个可用的示例:
using System.Collections.Generic;
using System;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HDF5DotNet;
namespace HDF5Test
{
public class HDFTester
{
static int myFunction(H5GroupId id, string objectName, Object param)
{
Console.WriteLine("The object name is {0}", objectName);
Console.WriteLine("The object parameter is {0}", param);
return 0;
}
public static void runTest()
{
try
{
const int DATA_ARRAY_LENGTH = 12;
const int RANK = 1;
H5FileId fileId = H5F.create("myCSharp.h5",
H5F.CreateMode.ACC_TRUNC);
H5GroupId groupId = H5G.create(fileId, "/cSharpGroup");
H5GroupId subGroup = H5G.create(groupId, "mySubGroup");
ObjectInfo info = H5G.getObjectInfo(fileId, "/cSharpGroup", true);
Console.WriteLine("cSharpGroup header size is {0}", info.headerSize);
Console.WriteLine("cSharpGroup nlinks is {0}", info.nHardLinks);
Console.WriteLine("cSharpGroup fileno is {0} {1}",
info.fileNumber[0], info.fileNumber[1]);
Console.WriteLine("cSharpGroup objno is {0} {1}",
info.objectNumber[0], info.objectNumber[1]);
Console.WriteLine("cSharpGroup type is {0}", info.objectType);
H5G.close(subGroup);
long[] dims = new long[RANK];
dims[0] = DATA_ARRAY_LENGTH;
int[] dset_data = new int[DATA_ARRAY_LENGTH];
for (int i = 0; i < DATA_ARRAY_LENGTH; i++)
dset_data[i] = DATA_ARRAY_LENGTH - i;
H5DataSpaceId spaceId = H5S.create_simple(RANK, dims);
H5DataTypeId typeId = H5T.copy(H5T.H5Type.NATIVE_INT);
int typeSize = H5T.getSize(typeId);
Console.WriteLine("typeSize is {0}", typeSize);
H5T.setOrder(typeId, H5T.Order.BE);
H5T.setOrder(typeId, H5T.Order.LE);
H5DataSetId dataSetId = H5D.create(fileId, "/csharpExample",
typeId, spaceId);
H5D.write(dataSetId, new H5DataTypeId(H5T.H5Type.NATIVE_INT),
new H5Array<int>(dset_data));
int[] readDataBack = new int[DATA_ARRAY_LENGTH];
H5D.read(dataSetId, new H5DataTypeId(H5T.H5Type.NATIVE_INT),
new H5Array<int>(readDataBack));
for (int i = 0; i < DATA_ARRAY_LENGTH; i++)
{
Console.WriteLine(readDataBack[i]);
}
H5D.close(dataSetId);
dataSetId = H5D.open(fileId, "/csharpExample");
H5D.close(dataSetId);
dataSetId = H5D.open(groupId, "/csharpExample");
H5D.close(dataSetId);
H5S.close(spaceId);
H5T.close(typeId);
H5G.close(groupId);
H5GIterateCallback myDelegate;
myDelegate = myFunction;
int x = 9;
int start = 0;
int index = H5G.iterate(fileId, "/cSharpGroup",myDelegate, x, ref start);
groupId = H5G.open(fileId, "/cSharpGroup");
H5G.close(groupId);
H5F.close(fileId);
H5FileId openId = H5F.open("myCSharp.h5",
H5F.OpenMode.ACC_RDONLY);
H5F.close(openId);
}
catch (HDFException e)
{
Console.WriteLine(e.Message);
}
Console.WriteLine("Processing complete!");
Console.ReadLine();
}
}
}
H5
、h5
、H5F
、H5S
和H5D
作为变量名是不好的习惯。前两个仅大小写不同,而其他三者只有一个字母不同。 - user47589