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>
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>
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>
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 #define FIELD3D_NAMESPACE_HEADER_CLOSE
Contains utility functions and classes for Hdf5 files.
const_mac_comp_iterator cbegin_comp(MACComponent comp) const
Const iterator to first element. "cbegin" matches the tr1 c++ standard.
static const std::string k_vDataStr
Scoped object - opens a dataset on creation and closes it on destruction.
Contains the Field3DFile classesOSS sanitized.
Contains the MACField class.
virtual ~MACFieldIO()
Dtor.
static int dataDims()
Dimensions of the given data type. i.e. 3 for V3f, 1 for float.
Namespace for Exception objects.
const Box3i & extents() const
Returns the extents of the data. This signifies the relevant area that the data exists over...
mac_comp_iterator begin_comp(MACComponent comp)
Iterator to first element.
Scoped object - opens a dataset on creation and closes it on destruction.
boost::intrusive_ptr< FieldBase > Ptr
boost::intrusive_ptr< MACFieldIO > Ptr
static const std::string k_componentsStr
static std::string name()
virtual std::string className() const
Returns the class name.
static const std::string k_uDataStr
Contains various utility functions for Hdf5.
static const int k_versionNumber
static FieldIO::Ptr create()
V3i getComponentSize() const
Returns the size of U,V,W components.
const Box3i & dataWindow() const
Returns the data window. Any coordinate inside this window is safe to pass to value() in the Field su...
boost::intrusive_ptr< MACField > Ptr
static const std::string k_wDataStr
bool checkHdf5Gzip()
Checks whether gzip is available in the current hdf5 library.
static const std::string k_extentsStr
bool writeInternal(hid_t layerGroup, typename MACField< Data_T >::Ptr field)
This call writes all the attributes and sets up the data space.
static const char * classType()
bool writeAttribute(hid_t location, const std::string &attrName, const std::string &value)
Writes a string attribute.
static const std::string k_versionAttrName
FieldIO base
Convenience typedef for referring to base class.
static const std::string k_dataWindowStr
static const std::string k_bitsPerComponentStr
Scoped object - creates a dataspace on creation and closes it on destruction.
virtual bool write(hid_t layerGroup, FieldBase::Ptr field)
Writes the given field to disk.
bool writeData(hid_t layerGroup, typename MACField< Data_T >::Ptr field, MACComponent comp)
This call writes out the u,v,w data.
DEFINE_FIELD_RTTI_CONCRETE_CLASS
Scoped object - creates a dataset on creation and closes it on destruction.
virtual FieldBase::Ptr read(hid_t layerGroup, const std::string &filename, const std::string &layerPath, DataTypeEnum typeEnum)
Reads the field at the given location and tries to create a MACField object from it.
boost::intrusive_ptr< FieldIO > Ptr
hid_t id() const
Query the hid_t value.
Contains Exception base class.
Scoped object - opens a dataset on creation and closes it on destruction.
bool readData(hid_t location, typename MACField< Data_T >::Ptr result)
Reads the data that is dependent on the data type on disk.