Commit 4eb3682d authored by brinn's avatar brinn

Add method writeMDArray() with HDF5ArrayBlockParams to primitive writers.

parent 12a29481
......@@ -26,7 +26,9 @@ public final class HDF5ArrayBlockParams
{
int[] blockDimensions;
long[] offset;
long[] blockIndex;
long[] blockOffset;
long[] boundIndexArray;
......@@ -37,17 +39,33 @@ public final class HDF5ArrayBlockParams
return blockDimensions;
}
long[] getOffset()
long[] getOffset(int[] blockDimensions)
{
if (blockDimensions == null)
if (blockOffset == null)
{
return null;
if (blockDimensions == null)
{
throw new HDF5JavaException("No block dimensions set");
}
blockOffset = new long[blockDimensions.length];
if (blockIndex != null)
{
if (blockDimensions.length != blockIndex.length)
{
throw new HDF5SpaceRankMismatch(blockDimensions.length, blockIndex.length);
}
for (int i = 0; i < blockOffset.length; ++i)
{
blockOffset[i] = blockIndex[i] * blockDimensions[i];
}
}
}
if (offset == null)
{
offset = new long[blockDimensions.length];
}
return offset;
return blockOffset;
}
long[] getOffset()
{
return getOffset(blockDimensions);
}
long[] getBoundIndexArray()
......@@ -62,7 +80,7 @@ public final class HDF5ArrayBlockParams
boolean hasBlock()
{
return blockDimensions != null;
return blockDimensions != null || blockIndex != null || blockOffset != null;
}
boolean hasSlice()
......@@ -93,19 +111,7 @@ public final class HDF5ArrayBlockParams
*/
public HDF5ArrayBlockParams index(long... blockIndex)
{
if (blockDimensions == null)
{
throw new HDF5JavaException("No block dimensions set");
}
if (blockDimensions.length != blockIndex.length)
{
throw new HDF5SpaceRankMismatch(blockDimensions.length, blockIndex.length);
}
offset = new long[blockDimensions.length];
for (int i = 0; i < offset.length; ++i)
{
offset[i] = blockIndex[i] * blockDimensions[i];
}
this.blockIndex = blockIndex;
return this;
}
......@@ -116,15 +122,7 @@ public final class HDF5ArrayBlockParams
*/
public HDF5ArrayBlockParams offset(long... offset)
{
if (blockDimensions == null)
{
throw new HDF5JavaException("No block dimensions set");
}
if (blockDimensions.length != offset.length)
{
throw new HDF5SpaceRankMismatch(blockDimensions.length, offset.length);
}
this.offset = offset;
this.blockOffset = offset;
return this;
}
......
......@@ -59,8 +59,8 @@ public class HDF5ArrayBlockParamsBuilder
}
/**
* Creates a parameter that reads an array slice. The slice is defined by "bound indices", each of
* which is fixed to a given value. The data block read or written only contains the free
* Creates a parameter that reads or writes an array slice. The slice is defined by "bound indices",
* each of which is fixed to a given value. The data block read or written only contains the free
* (i.e. non-fixed) indices.
*
* @param boundIndices The mapping of indices to index values which should be bound. For example
......@@ -73,5 +73,30 @@ public class HDF5ArrayBlockParamsBuilder
params.boundIndexMap = boundIndices;
return params;
}
/**
* Creates a parameter that writes a block with given <var>blockIndex</var>.
*
* @param blockIndex The block index in each dimension (offset: multiply with the
* <var>blockDimensions</var> in the according dimension).
*/
public static HDF5ArrayBlockParams blockIndex(long... blockIndex)
{
final HDF5ArrayBlockParams params = new HDF5ArrayBlockParams();
params.blockIndex = blockIndex;
return params;
}
/**
* Creates a parameter that writes a block with given <var>blockOffset</var>.
*
* @param blockIndex The block index in each dimension (offset: multiply with the
* <var>blockDimensions</var> in the according dimension).
*/
public static HDF5ArrayBlockParams blockOffset(long... blockOffset)
{
final HDF5ArrayBlockParams params = new HDF5ArrayBlockParams();
params.blockOffset = blockOffset;
return params;
}
}
......@@ -927,6 +927,48 @@ class HDF5ByteWriter extends HDF5ByteReader implements IHDF5ByteWriter
writeSlicedMDArrayBlockWithOffset(dataSet, data, offset, boundIndices);
}
@Override
public void writeMDArray(HDF5DataSet dataSet, MDByteArray data, HDF5ArrayBlockParams params)
{
assert dataSet != null;
assert data != null;
assert params != null;
if (params.hasBlock())
{
if (params.hasSlice())
{
if (params.getBoundIndexArray() != null)
{
writeSlicedMDArrayBlockWithOffset(dataSet, data, params.getOffset(data.dimensions()),
params.getBoundIndexArray());
} else
{
writeSlicedMDArrayBlockWithOffset(dataSet, data, params.getOffset(data.dimensions()),
params.getBoundIndexMap());
}
return;
}
writeMDArrayBlockWithOffset(dataSet, data, params.getOffset(data.dimensions()));
return;
}
if (params.hasSlice())
{
if (params.getBoundIndexArray() != null)
{
writeMDArraySlice(dataSet, data, params.getBoundIndexArray());
} else
{
writeMDArraySlice(dataSet, data, params.getBoundIndexMap());
}
return;
}
writeMDArrayBlockWithOffset(dataSet, data, new long[data.rank()]);
}
@Override
public void writeMDArrayBlockWithOffset(final String objectPath, final MDByteArray data,
final long[] offset)
......
......@@ -926,6 +926,48 @@ class HDF5DoubleWriter extends HDF5DoubleReader implements IHDF5DoubleWriter
writeSlicedMDArrayBlockWithOffset(dataSet, data, offset, boundIndices);
}
@Override
public void writeMDArray(HDF5DataSet dataSet, MDDoubleArray data, HDF5ArrayBlockParams params)
{
assert dataSet != null;
assert data != null;
assert params != null;
if (params.hasBlock())
{
if (params.hasSlice())
{
if (params.getBoundIndexArray() != null)
{
writeSlicedMDArrayBlockWithOffset(dataSet, data, params.getOffset(data.dimensions()),
params.getBoundIndexArray());
} else
{
writeSlicedMDArrayBlockWithOffset(dataSet, data, params.getOffset(data.dimensions()),
params.getBoundIndexMap());
}
return;
}
writeMDArrayBlockWithOffset(dataSet, data, params.getOffset(data.dimensions()));
return;
}
if (params.hasSlice())
{
if (params.getBoundIndexArray() != null)
{
writeMDArraySlice(dataSet, data, params.getBoundIndexArray());
} else
{
writeMDArraySlice(dataSet, data, params.getBoundIndexMap());
}
return;
}
writeMDArrayBlockWithOffset(dataSet, data, new long[data.rank()]);
}
@Override
public void writeMDArrayBlockWithOffset(final String objectPath, final MDDoubleArray data,
final long[] offset)
......
......@@ -926,6 +926,48 @@ class HDF5FloatWriter extends HDF5FloatReader implements IHDF5FloatWriter
writeSlicedMDArrayBlockWithOffset(dataSet, data, offset, boundIndices);
}
@Override
public void writeMDArray(HDF5DataSet dataSet, MDFloatArray data, HDF5ArrayBlockParams params)
{
assert dataSet != null;
assert data != null;
assert params != null;
if (params.hasBlock())
{
if (params.hasSlice())
{
if (params.getBoundIndexArray() != null)
{
writeSlicedMDArrayBlockWithOffset(dataSet, data, params.getOffset(data.dimensions()),
params.getBoundIndexArray());
} else
{
writeSlicedMDArrayBlockWithOffset(dataSet, data, params.getOffset(data.dimensions()),
params.getBoundIndexMap());
}
return;
}
writeMDArrayBlockWithOffset(dataSet, data, params.getOffset(data.dimensions()));
return;
}
if (params.hasSlice())
{
if (params.getBoundIndexArray() != null)
{
writeMDArraySlice(dataSet, data, params.getBoundIndexArray());
} else
{
writeMDArraySlice(dataSet, data, params.getBoundIndexMap());
}
return;
}
writeMDArrayBlockWithOffset(dataSet, data, new long[data.rank()]);
}
@Override
public void writeMDArrayBlockWithOffset(final String objectPath, final MDFloatArray data,
final long[] offset)
......
......@@ -927,6 +927,48 @@ class HDF5IntWriter extends HDF5IntReader implements IHDF5IntWriter
writeSlicedMDArrayBlockWithOffset(dataSet, data, offset, boundIndices);
}
@Override
public void writeMDArray(HDF5DataSet dataSet, MDIntArray data, HDF5ArrayBlockParams params)
{
assert dataSet != null;
assert data != null;
assert params != null;
if (params.hasBlock())
{
if (params.hasSlice())
{
if (params.getBoundIndexArray() != null)
{
writeSlicedMDArrayBlockWithOffset(dataSet, data, params.getOffset(data.dimensions()),
params.getBoundIndexArray());
} else
{
writeSlicedMDArrayBlockWithOffset(dataSet, data, params.getOffset(data.dimensions()),
params.getBoundIndexMap());
}
return;
}
writeMDArrayBlockWithOffset(dataSet, data, params.getOffset(data.dimensions()));
return;
}
if (params.hasSlice())
{
if (params.getBoundIndexArray() != null)
{
writeMDArraySlice(dataSet, data, params.getBoundIndexArray());
} else
{
writeMDArraySlice(dataSet, data, params.getBoundIndexMap());
}
return;
}
writeMDArrayBlockWithOffset(dataSet, data, new long[data.rank()]);
}
@Override
public void writeMDArrayBlockWithOffset(final String objectPath, final MDIntArray data,
final long[] offset)
......
......@@ -927,6 +927,48 @@ class HDF5LongWriter extends HDF5LongReader implements IHDF5LongWriter
writeSlicedMDArrayBlockWithOffset(dataSet, data, offset, boundIndices);
}
@Override
public void writeMDArray(HDF5DataSet dataSet, MDLongArray data, HDF5ArrayBlockParams params)
{
assert dataSet != null;
assert data != null;
assert params != null;
if (params.hasBlock())
{
if (params.hasSlice())
{
if (params.getBoundIndexArray() != null)
{
writeSlicedMDArrayBlockWithOffset(dataSet, data, params.getOffset(data.dimensions()),
params.getBoundIndexArray());
} else
{
writeSlicedMDArrayBlockWithOffset(dataSet, data, params.getOffset(data.dimensions()),
params.getBoundIndexMap());
}
return;
}
writeMDArrayBlockWithOffset(dataSet, data, params.getOffset(data.dimensions()));
return;
}
if (params.hasSlice())
{
if (params.getBoundIndexArray() != null)
{
writeMDArraySlice(dataSet, data, params.getBoundIndexArray());
} else
{
writeMDArraySlice(dataSet, data, params.getBoundIndexMap());
}
return;
}
writeMDArrayBlockWithOffset(dataSet, data, new long[data.rank()]);
}
@Override
public void writeMDArrayBlockWithOffset(final String objectPath, final MDLongArray data,
final long[] offset)
......
......@@ -927,6 +927,48 @@ class HDF5ShortWriter extends HDF5ShortReader implements IHDF5ShortWriter
writeSlicedMDArrayBlockWithOffset(dataSet, data, offset, boundIndices);
}
@Override
public void writeMDArray(HDF5DataSet dataSet, MDShortArray data, HDF5ArrayBlockParams params)
{
assert dataSet != null;
assert data != null;
assert params != null;
if (params.hasBlock())
{
if (params.hasSlice())
{
if (params.getBoundIndexArray() != null)
{
writeSlicedMDArrayBlockWithOffset(dataSet, data, params.getOffset(data.dimensions()),
params.getBoundIndexArray());
} else
{
writeSlicedMDArrayBlockWithOffset(dataSet, data, params.getOffset(data.dimensions()),
params.getBoundIndexMap());
}
return;
}
writeMDArrayBlockWithOffset(dataSet, data, params.getOffset(data.dimensions()));
return;
}
if (params.hasSlice())
{
if (params.getBoundIndexArray() != null)
{
writeMDArraySlice(dataSet, data, params.getBoundIndexArray());
} else
{
writeMDArraySlice(dataSet, data, params.getBoundIndexMap());
}
return;
}
writeMDArrayBlockWithOffset(dataSet, data, new long[data.rank()]);
}
@Override
public void writeMDArrayBlockWithOffset(final String objectPath, final MDShortArray data,
final long[] offset)
......
......@@ -926,6 +926,48 @@ class HDF5UnsignedByteWriter extends HDF5UnsignedByteReader implements IHDF5Byte
writeSlicedMDArrayBlockWithOffset(dataSet, data, offset, boundIndices);
}
@Override
public void writeMDArray(HDF5DataSet dataSet, MDByteArray data, HDF5ArrayBlockParams params)
{
assert dataSet != null;
assert data != null;
assert params != null;
if (params.hasBlock())
{
if (params.hasSlice())
{
if (params.getBoundIndexArray() != null)
{
writeSlicedMDArrayBlockWithOffset(dataSet, data, params.getOffset(data.dimensions()),
params.getBoundIndexArray());
} else
{
writeSlicedMDArrayBlockWithOffset(dataSet, data, params.getOffset(data.dimensions()),
params.getBoundIndexMap());
}
return;
}
writeMDArrayBlockWithOffset(dataSet, data, params.getOffset(data.dimensions()));
return;
}
if (params.hasSlice())
{
if (params.getBoundIndexArray() != null)
{
writeMDArraySlice(dataSet, data, params.getBoundIndexArray());
} else
{
writeMDArraySlice(dataSet, data, params.getBoundIndexMap());
}
return;
}
writeMDArrayBlockWithOffset(dataSet, data, new long[data.rank()]);
}
@Override
public void writeMDArrayBlockWithOffset(final String objectPath, final MDByteArray data,
final long[] offset)
......
......@@ -926,6 +926,48 @@ class HDF5UnsignedIntWriter extends HDF5UnsignedIntReader implements IHDF5IntWri
writeSlicedMDArrayBlockWithOffset(dataSet, data, offset, boundIndices);
}
@Override
public void writeMDArray(HDF5DataSet dataSet, MDIntArray data, HDF5ArrayBlockParams params)
{
assert dataSet != null;
assert data != null;
assert params != null;
if (params.hasBlock())
{
if (params.hasSlice())
{
if (params.getBoundIndexArray() != null)
{
writeSlicedMDArrayBlockWithOffset(dataSet, data, params.getOffset(data.dimensions()),
params.getBoundIndexArray());
} else
{
writeSlicedMDArrayBlockWithOffset(dataSet, data, params.getOffset(data.dimensions()),
params.getBoundIndexMap());
}
return;
}
writeMDArrayBlockWithOffset(dataSet, data, params.getOffset(data.dimensions()));
return;
}
if (params.hasSlice())
{
if (params.getBoundIndexArray() != null)
{
writeMDArraySlice(dataSet, data, params.getBoundIndexArray());
} else
{
writeMDArraySlice(dataSet, data, params.getBoundIndexMap());
}
return;
}
writeMDArrayBlockWithOffset(dataSet, data, new long[data.rank()]);
}
@Override
public void writeMDArrayBlockWithOffset(final String objectPath, final MDIntArray data,
final long[] offset)
......
......@@ -926,6 +926,48 @@ class HDF5UnsignedLongWriter extends HDF5UnsignedLongReader implements IHDF5Long
writeSlicedMDArrayBlockWithOffset(dataSet, data, offset, boundIndices);
}
@Override
public void writeMDArray(HDF5DataSet dataSet, MDLongArray data, HDF5ArrayBlockParams params)
{
assert dataSet != null;
assert data != null;
assert params != null;
if (params.hasBlock())
{
if (params.hasSlice())
{
if (params.getBoundIndexArray() != null)
{
writeSlicedMDArrayBlockWithOffset(dataSet, data, params.getOffset(data.dimensions()),
params.getBoundIndexArray());
} else
{
writeSlicedMDArrayBlockWithOffset(dataSet, data, params.getOffset(data.dimensions()),
params.getBoundIndexMap());
}
return;
}
writeMDArrayBlockWithOffset(dataSet, data, params.getOffset(data.dimensions()));
return;
}
if (params.hasSlice())
{
if (params.getBoundIndexArray() != null)
{
writeMDArraySlice(dataSet, data, params.getBoundIndexArray());
} else
{
writeMDArraySlice(dataSet, data, params.getBoundIndexMap());
}
return;
}
writeMDArrayBlockWithOffset(dataSet, data, new long[data.rank()]);
}
@Override
public void writeMDArrayBlockWithOffset(final String objectPath, final MDLongArray data,
final long[] offset)
......
......@@ -926,6 +926,48 @@ class HDF5UnsignedShortWriter extends HDF5UnsignedShortReader implements IHDF5Sh
writeSlicedMDArrayBlockWithOffset(dataSet, data, offset, boundIndices);
}
@Override
public void writeMDArray(HDF5DataSet dataSet, MDShortArray data, HDF5ArrayBlockParams params)
{
assert dataSet != null;
assert data != null;
assert params != null;
if (params.hasBlock())
{
if (params.hasSlice())
{
if (params.getBoundIndexArray() != null)
{
writeSlicedMDArrayBlockWithOffset(dataSet, data, params.getOffset(data.dimensions()),
params.getBoundIndexArray());
} else
{
writeSlicedMDArrayBlockWithOffset(dataSet, data, params.getOffset(data.dimensions()),
params.getBoundIndexMap());
}
return;
}
writeMDArrayBlockWithOffset(dataSet, data, params.getOffset(data.dimensions()));
return;
}
if (params.hasSlice())
{
if (params.getBoundIndexArray() != null)
{
writeMDArraySlice(dataSet, data, params.getBoundIndexArray());
} else
{
writeMDArraySlice(dataSet, data, params.getBoundIndexMap());
}
return;
}
writeMDArrayBlockWithOffset(dataSet, data, new long[data.rank()]);
}
@Override
public void writeMDArrayBlockWithOffset(final String objectPath, final MDShortArray data,
final long[] offset)
......
......@@ -513,6 +513,16 @@ public interface IHDF5ByteWriter extends IHDF5ByteReader
public void writeMDArray(String objectPath, MDByteArray data,
HDF5IntStorageFeatures features);
/**
* Writes out a block or a slice of a multi-dimensional <code>byte</code> array.
*
* @param dataSet The data set to write to.
* @param data The data to write. Must not be <code>null</code>.