Field3D
Field3DFileHDF5.cpp File Reference

Contains implementations of Field3DFileHDF5-related member functions. More...

#include <sys/stat.h>
#include <unistd.h>
#include <hdf5.h>
#include <H5Epublic.h>
#include <boost/tokenizer.hpp>
#include <boost/utility.hpp>
#include "Field3DFileHDF5.h"
#include "Field.h"
#include "ClassFactory.h"

Go to the source code of this file.

Namespaces

 InputFileHDF5
 Namespace for file input specifics.
 

Functions

FIELD3D_API herr_t InputFileHDF5::parseLayers (hid_t loc_id, const char *partitionName, const H5L_info_t *linfo, void *opdata)
 Gets called from readPartitionAndLayerInfo to check each group found under the root of the file. It checks to see if it can find a "partition" and then passes that to writePartition. More...
 
FIELD3D_API herr_t InputFileHDF5::parsePartitions (hid_t loc_id, const char *partitionName, const H5L_info_t *linfo, void *opdata)
 Gets called from readPartitionAndLayerInfo to check each group found under the root of the file. It checks to see if it can find a "partition" and then passes that to writePartition. More...
 
FieldMapping::Ptr readFieldMapping (hid_t mappingGroup)
 This function creates a FieldMappingIO instance based on className read from mappingGroup location which then reads FieldMapping data. More...
 
bool writeField (hid_t layerGroup, FieldBase::Ptr field)
 This function creates a FieldIO instance based on field->className() which then writes the field data in layerGroup location. More...
 
bool writeFieldMapping (hid_t mappingGroup, FieldMapping::Ptr mapping)
 This function creates a FieldMappingIO instance based on mapping->className() which then writes FieldMapping data to mappingGroup location. More...
 

Detailed Description

Contains implementations of Field3DFileHDF5-related member functions.

Definition in file Field3DFileHDF5.cpp.

Function Documentation

◆ writeField()

bool writeField ( hid_t  layerGroup,
FieldBase::Ptr  field 
)

This function creates a FieldIO instance based on field->className() which then writes the field data in layerGroup location.

Definition at line 1589 of file Field3DFileHDF5.cpp.

1590 {
1592 
1593  FieldIO::Ptr io = factory.createFieldIO(field->className());
1594  assert(io != 0);
1595  if (!io) {
1596  Msg::print(Msg::SevWarning, "Unable to find class type: " +
1597  field->className());
1598  return false;
1599  }
1600 
1601  // Add class name attribute
1602  if (!writeAttribute(layerGroup, k_classNameAttrName,
1603  field->className())) {
1604  Msg::print(Msg::SevWarning, "Error adding class name attribute.");
1605  return false;
1606  }
1607 
1608  return io->write(layerGroup, field);
1609 }

References ClassFactory::createFieldIO(), Msg::print(), Msg::SevWarning, ClassFactory::singleton(), and Hdf5Util::writeAttribute().

Referenced by Field3DOutputFileHDF5::writeLayer(), and Field3DOutputFile::writeLayer().

◆ readFieldMapping()

FieldMapping::Ptr readFieldMapping ( hid_t  mappingGroup)

This function creates a FieldMappingIO instance based on className read from mappingGroup location which then reads FieldMapping data.

Definition at line 1613 of file Field3DFileHDF5.cpp.

1614 {
1616 
1617  std::string className;
1618 
1619  if (!readAttribute(mappingGroup, k_mappingTypeAttrName, className)) {
1620  Msg::print(Msg::SevWarning, "Couldn't find " + k_mappingTypeAttrName +
1621  " attribute");
1622  return FieldMapping::Ptr();
1623  }
1624 
1625  FieldMappingIO::Ptr io = factory.createFieldMappingIO(className);
1626  assert(io != 0);
1627  if (!io) {
1628  Msg::print(Msg::SevWarning, "Unable to find class type: " +
1629  className);
1630  return FieldMapping::Ptr();
1631  }
1632 
1633 
1634  FieldMapping::Ptr mapping = io->read(mappingGroup);
1635  if (!mapping) {
1636  Msg::print(Msg::SevWarning, "Couldn't read mapping");
1637  return FieldMapping::Ptr();
1638  }
1639 
1640  return mapping;
1641 }

References ClassFactory::createFieldMappingIO(), Msg::print(), Hdf5Util::readAttribute(), Msg::SevWarning, and ClassFactory::singleton().

Referenced by Field3DInputFile::readPartitionAndLayerInfo(), and Field3DInputFileHDF5::readPartitionAndLayerInfo().

◆ writeFieldMapping()

bool writeFieldMapping ( hid_t  mappingGroup,
FieldMapping::Ptr  mapping 
)

This function creates a FieldMappingIO instance based on mapping->className() which then writes FieldMapping data to mappingGroup location.

Definition at line 1645 of file Field3DFileHDF5.cpp.

1646 {
1648 
1649  std::string className = mapping->className();
1650 
1651  if (!writeAttribute(mappingGroup, k_mappingTypeAttrName, className)) {
1652  Msg::print(Msg::SevWarning, "Couldn't add " + className + " attribute");
1653  return false;
1654  }
1655 
1656  FieldMappingIO::Ptr io = factory.createFieldMappingIO(className);
1657  assert(io != 0);
1658  if (!io) {
1659  Msg::print(Msg::SevWarning, "Unable to find class type: " +
1660  className);
1661  return false;
1662  }
1663 
1664  return io->write(mappingGroup, mapping);
1665 }

References ClassFactory::createFieldMappingIO(), Msg::print(), Msg::SevWarning, ClassFactory::singleton(), and Hdf5Util::writeAttribute().

Referenced by Field3DOutputFileHDF5::writeMapping().

ClassFactory::createFieldIO
FieldIO::Ptr createFieldIO(const std::string &className) const
Instances an IO object by name.
Definition: ClassFactory.cpp:165
Hdf5Util::writeAttribute
FIELD3D_API bool writeAttribute(hid_t location, const std::string &attrName, const std::string &value)
Writes a string attribute.
Msg::SevWarning
@ SevWarning
Definition: Log.h:68
ClassFactory
Definition: ClassFactory.h:72
FieldMappingIO::Ptr
boost::intrusive_ptr< FieldMappingIO > Ptr
Definition: FieldMappingIO.h:71
FieldMapping::Ptr
boost::intrusive_ptr< FieldMapping > Ptr
Definition: FieldMapping.h:92
ClassFactory::singleton
static ClassFactory & singleton()
}
Definition: ClassFactory.cpp:278
Hdf5Util::readAttribute
FIELD3D_API bool readAttribute(hid_t location, const std::string &attrName, std::string &value)
Reads a string attribute.
FieldIO::Ptr
boost::intrusive_ptr< FieldIO > Ptr
Definition: FieldIO.h:91
Msg::print
FIELD3D_API void print(Severity severity, const std::string &message)
Sends the string to the assigned output, prefixing the message with the severity.
Definition: Log.cpp:70
ClassFactory::createFieldMappingIO
FieldMappingIO::Ptr createFieldMappingIO(const std::string &className) const
Instances an IO object by name.
Definition: ClassFactory.cpp:266