...
 
Commits (2)
......@@ -1212,12 +1212,13 @@ final class HDF5BaseWriter extends HDF5BaseReader
{
final long dataSetId;
boolean exists = h5.exists(fileId, objectPath);
if (exists && keepDataIfExists(features) == false)
final boolean isRef = h5.isReference(objectPath);
if (exists && isRef == false && keepDataIfExists(features) == false)
{
h5.deleteObject(fileId, objectPath);
exists = false;
}
if (exists)
if (exists || isRef)
{
dataSetId =
h5.openAndExtendDataSet(fileId, objectPath, fileFormat, dimensions,
......
......@@ -477,6 +477,7 @@ public class HDF5RoundtripTest
test.testObjectReferenceMDArrayAttribute();
test.testObjectReferenceMDArray();
test.testObjectReferenceMDArrayBlockWise();
test.testObjectReferenceToMDFloatArray();
test.testHDFJavaLowLevel();
test.testMDCImageGeneration();
test.testMDCImageGenerationBug();
......@@ -644,6 +645,7 @@ public class HDF5RoundtripTest
public void testUnsignedInt8ValuesArray()
{
final String byteDatasetName = "/byte";
final String uintAttrName = "uattr";
final File datasetFile = new File(workingDirectory, "unsignedInt8Values.h5");
datasetFile.delete();
assertFalse(datasetFile.exists());
......@@ -652,16 +654,23 @@ public class HDF5RoundtripTest
final byte[] valuesWritten = new byte[]
{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, (byte) 128, (byte) 255 };
writer.uint8().writeArray(byteDatasetName, valuesWritten);
writer.uint8().setAttr(byteDatasetName, "attr", (byte) 224);
writer.uint8().setAttr(byteDatasetName, uintAttrName, (byte) 224);
final byte[] valuesRead1 = writer.uint8().readArray(byteDatasetName);
assertTrue(Arrays.equals(valuesWritten, valuesRead1));
assertEquals(224, UnsignedIntUtils.toUint8(writer.uint8().getAttr(byteDatasetName, "attr")));
assertEquals(224, UnsignedIntUtils.toUint8(writer.uint8().getAttr(byteDatasetName, uintAttrName)));
writer.close();
final IHDF5Reader reader = HDF5FactoryProvider.get().openForReading(datasetFile);
assertFalse(reader.getDataSetInformation(byteDatasetName).isSigned());
final byte[] valuesRead2 = reader.uint8().readArray(byteDatasetName);
assertTrue(Arrays.equals(valuesWritten, valuesRead2));
assertEquals(224, UnsignedIntUtils.toUint8(reader.uint8().getAttr(byteDatasetName, "attr")));
assertEquals(224, UnsignedIntUtils.toUint8(reader.uint8().getAttr(byteDatasetName, uintAttrName)));
// Alternative is to use larger intege number when reading.
assertEquals(224, reader.uint16().getAttr(byteDatasetName, uintAttrName));
assertEquals(224, reader.int16().getAttr(byteDatasetName, uintAttrName));
// The regular int8() reader doesn't read this number correctly.
assertEquals(127, UnsignedIntUtils.toUint8(reader.int8().getAttr(byteDatasetName, uintAttrName)));
assertEquals(127, reader.int8().getAttr(byteDatasetName, uintAttrName));
reader.close();
}
......@@ -11747,6 +11756,41 @@ public class HDF5RoundtripTest
reader.close();
}
@Test
public void testObjectReferenceToMDFloatArray()
{
final File file = new File(workingDirectory, "testObjectReferenceToMDFloatArray.h5");
file.delete();
assertFalse(file.exists());
file.deleteOnExit();
final IHDF5Writer writer = HDF5FactoryProvider.get().open(file);
final String floatDatasetName = "/floatMatrix";
final String referenceDatasetName = "/refToFloatMatrix";
final MDFloatArray arrayWritten = new MDFloatArray(new int[]
{ 3, 2, 4 });
int count = 0;
for (int i = 0; i < arrayWritten.size(0); ++i)
{
for (int j = 0; j < arrayWritten.size(1); ++j)
{
for (int k = 0; k < arrayWritten.size(2); ++k)
{
arrayWritten.set(++count, new int[]
{ i, j, k });
}
}
}
writer.float32().createMDArray(floatDatasetName, arrayWritten.dimensions());
writer.reference().write(referenceDatasetName, floatDatasetName);
writer.float32().writeMDArray(writer.reference().read(referenceDatasetName, false), arrayWritten);
writer.close();
final IHDF5Reader reader = HDF5FactoryProvider.get().openForReading(file);
final MDFloatArray arrayRead = reader.float32().readMDArray(floatDatasetName);
assertEquals(arrayWritten, arrayRead);
reader.close();
}
@Test
public void testObjectReferenceAttribute()
{
......