44 #ifndef _INCLUDED_Field3D_MACFieldIO_H_
45 #define _INCLUDED_Field3D_MACFieldIO_H_
51 #include <boost/intrusive_ptr.hpp>
85 typedef boost::intrusive_ptr<MACFieldIO>
Ptr;
117 const std::string &layerPath,
126 {
return "MACField"; }
133 template <
class Data_T>
137 template <
class Data_T>
142 template <
class Data_T>
168 template <
class Data_T>
173 using namespace Hdf5Util;
178 size[0] = compSize.x;
179 size[1] = compSize.y;
180 size[2] = compSize.z;
187 { ext.min.x, ext.min.y, ext.min.z, ext.max.x, ext.max.y, ext.max.z };
190 throw WriteAttributeException(
"Couldn't write attribute " +
k_extentsStr);
195 { dw.min.x, dw.min.y, dw.min.z, dw.max.x, dw.max.y, dw.max.z };
198 throw WriteAttributeException(
"Couldn't write attribute " +
k_dataWindowStr);
203 throw WriteAttributeException(
"Couldn't write attribute " +
k_componentsStr);
214 if (!writeData<Data_T>(layerGroup, field,
MACCompU)) {
215 throw WriteMACFieldDataException(
"Error writing u_data");
218 if (!writeData<Data_T>(layerGroup, field,
MACCompV)) {
219 throw WriteMACFieldDataException(
"Error writing v_data");
222 if (!writeData<Data_T>(layerGroup, field,
MACCompW)) {
223 throw WriteMACFieldDataException(
"Error writing w_data");
232 template <
class Data_T>
238 using namespace Hdf5Util;
242 hsize_t totalSize[1];
247 totalSize[0] = compSize.x;
251 totalSize[0] = compSize.y;
255 totalSize[0] = compSize.z;
263 hsize_t preferredChunkSize = 4096 * 16;
264 const hsize_t chunkSize = std::min(preferredChunkSize, totalSize[0] / 2);
268 if (dataSpace.
id() < 0)
269 throw CreateDataSpaceException(
"Couldn't create data space in "
270 "MACFieldIO::writeData");
274 H5Sset_extent_simple(dataSpace.
id(), 1, totalSize, NULL);
278 hid_t dcpl = H5Pcreate(H5P_DATASET_CREATE);
280 herr_t status = H5Pset_deflate(dcpl, 9);
284 status = H5Pset_chunk(dcpl, 1, &chunkSize);
293 H5P_DEFAULT, dcpl, H5P_DEFAULT);
295 if (dataSet.id() < 0)
296 throw CreateDataSetException(
"Couldn't create data set in "
297 "MACFieldIO::writeData");
299 hid_t err = H5Dwrite(dataSet,
304 throw Exc::WriteLayerException(
"Error writing layer in "
305 "MACFieldIO::writeData");
313 template <
class Data_T>
319 using namespace Hdf5Util;
327 if (dataSet.
id() < 0)
328 throw OpenDataSetException(
"Couldn't open data set: " +
k_uDataStr);
332 H5Sget_simple_extent_dims(dataSpace.id(), dims, NULL);
334 if (dataSpace.id() < 0)
335 throw GetDataSpaceException(
"Couldn't get data space");
337 if (dataType.id() < 0)
338 throw GetDataTypeException(
"Couldn't get data type");
343 std::string typeName =
"MACField<" +
345 throw Exc::Hdf5DataReadException(
"Couldn't read " + typeName +
" data");
354 if (dataSet.
id() < 0)
355 throw OpenDataSetException(
"Couldn't open data set: " +
k_vDataStr);
359 H5Sget_simple_extent_dims(dataSpace.id(), dims, NULL);
361 if (dataSpace.id() < 0)
362 throw GetDataSpaceException(
"Couldn't get data space");
364 if (dataType.id() < 0)
365 throw GetDataTypeException(
"Couldn't get data type");
371 std::string typeName =
"MACField<" +
373 throw Exc::Hdf5DataReadException(
"Couldn't read " + typeName +
" data");
382 if (dataSet.
id() < 0)
383 throw OpenDataSetException(
"Couldn't open data set: " +
k_wDataStr);
387 H5Sget_simple_extent_dims(dataSpace.id(), dims, NULL);
389 if (dataSpace.id() < 0)
390 throw GetDataSpaceException(
"Couldn't get data space");
392 if (dataType.id() < 0)
393 throw GetDataTypeException(
"Couldn't get data type");
399 std::string typeName =
"MACField<" +
401 throw Exc::Hdf5DataReadException(
"Couldn't read " + typeName +
" data");
415 #endif // Include guard