Commit de7823dc authored by brinn's avatar brinn

Minor cleanup.

parent e602d877
......@@ -971,8 +971,9 @@ class HDF5
});
final long dataSpaceId = getDataSpaceForDataSet(dataSetId, registry);
final int rank = getDataSpaceRank(dataSpaceId);
final long[] dataDimensions = getDataSpaceDimensions(dataSpaceId, rank);
final long[] maxDimensions = getDataSpaceMaxDimensions(dataSpaceId, rank);
final long[][] dimsMaxDims = getDataSpaceDimensionsAndMaxDimensions(dataSpaceId, rank);
final long[] dataDimensions = dimsMaxDims[0];
final long[] maxDimensions = dimsMaxDims[1];
final HDF5StorageLayout layout = getLayout(dataSetId, registry);
extendDataSet(dataSetId, dataSpaceId, rank, layout, dataDimensions, newDimensions, maxDimensions,
overwriteMode, registry);
......@@ -1956,7 +1957,7 @@ class HDF5
public long getDataSpaceForDataSet(long dataSetId, ICleanUpRegistry registry)
{
final long dataTypeId = H5Dget_space(dataSetId);
final long dataSpaceId = H5Dget_space(dataSetId);
if (registry != null)
{
registry.registerCleanUp(new Runnable()
......@@ -1964,11 +1965,11 @@ class HDF5
@Override
public void run()
{
H5Sclose(dataTypeId);
H5Sclose(dataSpaceId);
}
});
}
return dataTypeId;
return dataSpaceId;
}
public long[] getDataDimensionsForAttribute(final long attributeId, ICleanUpRegistry registry)
......@@ -2007,35 +2008,6 @@ class HDF5
return dimensions;
}
public long[] getDataMaxDimensions(final long dataSetId)
{
ICallableWithCleanUp<long[]> dataDimensionRunnable = new ICallableWithCleanUp<long[]>()
{
@Override
public long[] call(ICleanUpRegistry registry)
{
return getDataMaxDimensions(dataSetId, registry);
}
};
return runner.call(dataDimensionRunnable);
}
long[] getDataMaxDimensions(final long dataSetId, ICleanUpRegistry registry)
{
final long dataSpaceId = H5Dget_space(dataSetId);
registry.registerCleanUp(new Runnable()
{
@Override
public void run()
{
H5Sclose(dataSpaceId);
}
});
final long[] dimensions = getDataSpaceMaxDimensions(dataSpaceId);
return dimensions;
}
public int getDataSpaceRank(long dataSpaceId)
{
return H5Sget_simple_extent_ndims(dataSpaceId);
......@@ -2073,6 +2045,13 @@ class HDF5
return maxDimensions;
}
public long[][] getDataSpaceDimensionsAndMaxDimensions(long dataSpaceId, int rank)
{
final long[][] dimsMaxDims = new long[2][rank];
H5Sget_simple_extent_dims(dataSpaceId, dimsMaxDims[0], dimsMaxDims[1]);
return dimsMaxDims;
}
/**
* @param dataSetOrAttributeId The id of either the data set or the attribute to get the rank for.
* @param isAttribute If <code>true</code>, <var>dataSetOrAttributeId</var> will be interpreted as an attribute, otherwise as a data set.
......
......@@ -26,7 +26,6 @@ import static ch.systemsx.cisd.hdf5.HDF5Utils.isNonPositive;
import static hdf.hdf5lib.H5.H5Dwrite;
import static hdf.hdf5lib.HDF5Constants.H5P_DEFAULT;
import static hdf.hdf5lib.HDF5Constants.H5S_SCALAR;
import static hdf.hdf5lib.HDF5Constants.H5S_UNLIMITED;
import static hdf.hdf5lib.HDF5Constants.H5T_NATIVE_INT16;
import static hdf.hdf5lib.HDF5Constants.H5T_NATIVE_INT32;
import static hdf.hdf5lib.HDF5Constants.H5T_NATIVE_INT8;
......@@ -1201,28 +1200,6 @@ final class HDF5BaseWriter extends HDF5BaseReader
return size;
}
/**
* Checks whether the given <var>dimensions</var> are in bounds for <var>dataSetId</var>.
*/
boolean areDimensionsInBounds(final long dataSetId, final long[] dimensions)
{
final long[] maxDimensions = h5.getDataMaxDimensions(dataSetId);
if (dimensions.length != maxDimensions.length) // Actually an error condition
{
return false;
}
for (int i = 0; i < dimensions.length; ++i)
{
if (maxDimensions[i] != H5S_UNLIMITED && dimensions[i] > maxDimensions[i])
{
return false;
}
}
return true;
}
/**
* Returns the data set id for the given <var>objectPath</var>. If the data sets exists, it
* depends on the <code>features</code> and on the status of <code>keepDataSetIfExists</code>
......
......@@ -80,19 +80,19 @@ public class HDF5DataSet implements AutoCloseable
private int fullRank;
HDF5DataSet(HDF5BaseReader baseReader, String datasetPath, long datasetId, long dataspaceId, long[] dimensions,
HDF5DataSet(HDF5BaseReader baseReader, String datasetPath, long dataSetId, long dataSpaceId, long[] dimensions,
long[] maxDimensionsOrNull, HDF5StorageLayout layout, boolean ownDataSpaceId)
{
this.baseReader = baseReader;
this.h5 = baseReader.h5;
this.dataSetPath = datasetPath;
this.dataSetId = datasetId;
this.dataSetId = dataSetId;
if (ownDataSpaceId)
{
this.dataSpaceId = dataspaceId;
this.dataSpaceId = dataSpaceId;
} else
{
this.dataSpaceId = H5Scopy(dataspaceId);
this.dataSpaceId = H5Scopy(dataSpaceId);
}
this.maxDimensions = maxDimensionsOrNull;
this.dimensions = dimensions;
......@@ -148,7 +148,7 @@ public class HDF5DataSet implements AutoCloseable
{
if (maxDimensions == null)
{
this.maxDimensions = h5.getDataSpaceMaxDimensions(dataSpaceId);
this.maxDimensions = h5.getDataSpaceMaxDimensions(dataSpaceId, dimensions.length);
}
return maxDimensions;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment