Support global variables
This commit is contained in:
parent
cfe51d57ae
commit
199ab46f0c
@ -277,6 +277,17 @@ namespace MatFileHandler.Tests
|
|||||||
Assert.That(sparseArray[1, 2], Is.True);
|
Assert.That(sparseArray[1, 2], Is.True);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test reading a global variable.
|
||||||
|
/// </summary>
|
||||||
|
[Test]
|
||||||
|
public void TestGlobal()
|
||||||
|
{
|
||||||
|
var matFile = ReadHdfTestFile("global");
|
||||||
|
var variable = matFile.Variables.First();
|
||||||
|
Assert.That(variable.IsGlobal, Is.True);
|
||||||
|
}
|
||||||
|
|
||||||
private static void CheckComplexLimits<T>(IArrayOf<ComplexOf<T>> array, T[] limits)
|
private static void CheckComplexLimits<T>(IArrayOf<ComplexOf<T>> array, T[] limits)
|
||||||
where T : struct
|
where T : struct
|
||||||
{
|
{
|
||||||
|
BIN
MatFileHandler.Tests/test-data/hdf/global.mat
Normal file
BIN
MatFileHandler.Tests/test-data/hdf/global.mat
Normal file
Binary file not shown.
@ -43,6 +43,24 @@ namespace MatFileHandler
|
|||||||
return new MatFile(variables);
|
return new MatFile(variables);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool ReadGlobalFlag(long datasetId)
|
||||||
|
{
|
||||||
|
if (H5A.exists_by_name(datasetId, ".", "MATLAB_global") != 0)
|
||||||
|
{
|
||||||
|
using (var globalAttribute = new Attribute(datasetId, "MATLAB_global"))
|
||||||
|
{
|
||||||
|
using (var h = new MemoryHandle(sizeof(int)))
|
||||||
|
{
|
||||||
|
H5A.read(globalAttribute.Id, H5T.NATIVE_INT, h.Handle);
|
||||||
|
var result = Marshal.ReadInt32(h.Handle);
|
||||||
|
return result != 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private int VariableIterator(long group, IntPtr name, ref H5L.info_t info, IntPtr op_data)
|
private int VariableIterator(long group, IntPtr name, ref H5L.info_t info, IntPtr op_data)
|
||||||
{
|
{
|
||||||
var variableName = Marshal.PtrToStringAnsi(name);
|
var variableName = Marshal.PtrToStringAnsi(name);
|
||||||
@ -53,8 +71,9 @@ namespace MatFileHandler
|
|||||||
case H5O.type_t.DATASET:
|
case H5O.type_t.DATASET:
|
||||||
using (var dataset = new Dataset(group, variableName))
|
using (var dataset = new Dataset(group, variableName))
|
||||||
{
|
{
|
||||||
|
var isGlobal = ReadGlobalFlag(dataset.Id);
|
||||||
var value = ReadDataset(dataset.Id);
|
var value = ReadDataset(dataset.Id);
|
||||||
variables.Add(new MatVariable(value, variableName, false));
|
variables.Add(new MatVariable(value, variableName, isGlobal));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case H5O.type_t.GROUP:
|
case H5O.type_t.GROUP:
|
||||||
@ -64,8 +83,9 @@ namespace MatFileHandler
|
|||||||
}
|
}
|
||||||
using (var subGroup = new Group(group, variableName))
|
using (var subGroup = new Group(group, variableName))
|
||||||
{
|
{
|
||||||
|
var isGlobal = ReadGlobalFlag(subGroup.Id);
|
||||||
var groupValue = ReadGroup(subGroup.Id);
|
var groupValue = ReadGroup(subGroup.Id);
|
||||||
variables.Add(new MatVariable(groupValue, variableName, false));
|
variables.Add(new MatVariable(groupValue, variableName, isGlobal));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user