This call writes all the attributes and sets up the data space.
{
using namespace std;
using namespace Exc;
using namespace Hdf5Util;
using namespace Sparse;
Box3i ext(field->extents()), dw(field->dataWindow());
int valuesPerBlock = (1 << (field->m_blockOrder * 3)) * components;
int size[3];
size[0] = dw.max.x - dw.min.x + 1;
size[1] = dw.max.y - dw.min.y + 1;
size[2] = dw.max.z - dw.min.z + 1;
hsize_t totalSize[1];
totalSize[0] = size[0] * size[1] * size[2] * components;
int extents[6] =
{ ext.min.x, ext.min.y, ext.min.z, ext.max.x, ext.max.y, ext.max.z };
return false;
}
int dataWindow[6] =
{ dw.min.x, dw.min.y, dw.min.z, dw.max.x, dw.max.y, dw.max.z };
return false;
}
return false;
}
int blockOrder = field->m_blockOrder;
return false;
}
V3i &blockRes = field->m_blockRes;
int numBlocks = blockRes.x * blockRes.y * blockRes.z;
return false;
}
return false;
}
return false;
}
{
vector<char> isAllocated(numBlocks);
vector<char>::iterator i = isAllocated.begin();
typename vector<SparseBlock<Data_T> >::const_iterator b =
field->m_blocks.begin();
for (; i != isAllocated.end(); ++i, ++b)
*i = static_cast<char>(b->isAllocated);
writeSimpleData<char>(layerGroup, "block_is_allocated_data", isAllocated);
}
{
vector<Data_T> emptyValue(numBlocks);
typename vector<Data_T>::iterator i = emptyValue.begin();
typename vector<SparseBlock<Data_T> >::const_iterator b =
field->m_blocks.begin();
for (; i != emptyValue.end(); ++i, ++b)
*i = static_cast<Data_T>(b->emptyValue);
writeSimpleData<Data_T>(layerGroup, "block_empty_value_data", emptyValue);
}
int occupiedBlocks = 0;
typename vector<SparseBlock<Data_T> >::iterator b =
field->m_blocks.begin();
for (; b != field->m_blocks.end(); ++b) {
if (b->isAllocated)
occupiedBlocks++;
}
throw WriteAttributeException("Couldn't add attribute " +
}
if (occupiedBlocks > 0) {
hsize_t memDims[1];
memDims[0] = valuesPerBlock;
H5Sset_extent_simple(memDataSpace.id(), 1, memDims, NULL);
hsize_t fileDims[2];
fileDims[0] = occupiedBlocks;
fileDims[1] = valuesPerBlock;
H5Sset_extent_simple(fileDataSpace.id(), 2, fileDims, NULL);
hid_t dcpl = H5Pcreate(H5P_DATASET_CREATE);
hsize_t chunkSize[2];
chunkSize[0] = 1;
chunkSize[1] = valuesPerBlock;
if (gzipAvailable) {
herr_t status = H5Pset_deflate(dcpl, 9);
if (status < 0) {
return false;
}
status = H5Pset_chunk(dcpl, 2, chunkSize);
if (status < 0) {
return false;
}
}
fileDataSpace.id(),
H5P_DEFAULT, dcpl, H5P_DEFAULT);
if (dataSet.id() < 0)
throw CreateDataSetException("Couldn't create data set in "
"SparseFieldIO::writeInternal");
int nextBlockIdx = 0;
hsize_t offset[2];
hsize_t count[2];
herr_t status;
for (b = field->m_blocks.begin(); b != field->m_blocks.end(); ++b) {
if (b->isAllocated) {
offset[0] = nextBlockIdx;
offset[1] = 0;
count[0] = 1;
count[1] = valuesPerBlock;
status = H5Sselect_hyperslab(fileDataSpace.id(), H5S_SELECT_SET,
offset, NULL, count, NULL);
if (status < 0) {
throw WriteHyperSlabException(
"Couldn't select slab " +
boost::lexical_cast<std::string>(nextBlockIdx));
}
Data_T *data = &b->data[0];
memDataSpace.id(),
fileDataSpace.id(), H5P_DEFAULT, data);
if (status < 0) {
throw WriteHyperSlabException(
"Couldn't write slab " +
boost::lexical_cast<std::string>(nextBlockIdx));
}
nextBlockIdx++;
}
}
}
return true;
}