Field3D
Field3DFile.cpp File Reference

Contains implementations of Field3DFile-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 "Field3DFile.h"
#include "Field.h"
#include "ClassFactory.h"

Go to the source code of this file.

Namespaces

 InputFile
 Namespace for file input specifics.
 

Functions

herr_t InputFile::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...
 
herr_t InputFile::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 Field3DFile-related member functions.

Definition in file Field3DFile.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 1558 of file Field3DFile.cpp.

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

Referenced by Field3DOutputFile::writeLayer().

1559 {
1561 
1562  FieldIO::Ptr io = factory.createFieldIO(field->className());
1563  assert(io != 0);
1564  if (!io) {
1565  Msg::print(Msg::SevWarning, "Unable to find class type: " +
1566  field->className());
1567  return false;
1568  }
1569 
1570  // Add class name attribute
1571  if (!writeAttribute(layerGroup, k_classNameAttrName,
1572  field->className())) {
1573  Msg::print(Msg::SevWarning, "Error adding class name attribute.");
1574  return false;
1575  }
1576 
1577  return io->write(layerGroup, field);
1578 }
static ClassFactory & singleton()
}
void print(Severity severity, const std::string &message)
Sends the string to the assigned output, prefixing the message with the severity. ...
Definition: Log.cpp:62
FieldIO::Ptr createFieldIO(const std::string &className) const
Instances an IO object by name.
bool writeAttribute(hid_t location, const std::string &attrName, const std::string &value)
Writes a string attribute.
boost::intrusive_ptr< FieldIO > Ptr
Definition: FieldIO.h:90

◆ 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 1582 of file Field3DFile.cpp.

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

Referenced by Field3DInputFile::readPartitionAndLayerInfo().

1583 {
1585 
1586  std::string className;
1587 
1588  if (!readAttribute(mappingGroup, k_mappingTypeAttrName, className)) {
1589  Msg::print(Msg::SevWarning, "Couldn't find " + k_mappingTypeAttrName +
1590  " attribute");
1591  return FieldMapping::Ptr();
1592  }
1593 
1594  FieldMappingIO::Ptr io = factory.createFieldMappingIO(className);
1595  assert(io != 0);
1596  if (!io) {
1597  Msg::print(Msg::SevWarning, "Unable to find class type: " +
1598  className);
1599  return FieldMapping::Ptr();
1600  }
1601 
1602 
1603  FieldMapping::Ptr mapping = io->read(mappingGroup);
1604  if (!mapping) {
1605  Msg::print(Msg::SevWarning, "Couldn't read mapping");
1606  return FieldMapping::Ptr();
1607  }
1608 
1609  return mapping;
1610 }
FieldMappingIO::Ptr createFieldMappingIO(const std::string &className) const
Instances an IO object by name.
boost::intrusive_ptr< FieldMappingIO > Ptr
static ClassFactory & singleton()
}
void print(Severity severity, const std::string &message)
Sends the string to the assigned output, prefixing the message with the severity. ...
Definition: Log.cpp:62
boost::intrusive_ptr< FieldMapping > Ptr
Definition: FieldMapping.h:92
bool readAttribute(hid_t location, const std::string &attrName, std::string &value)
Reads a string attribute.

◆ 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 1614 of file Field3DFile.cpp.

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

Referenced by Field3DOutputFile::writeMapping().

1615 {
1617 
1618  std::string className = mapping->className();
1619 
1620  if (!writeAttribute(mappingGroup, k_mappingTypeAttrName, className)) {
1621  Msg::print(Msg::SevWarning, "Couldn't add " + className + " attribute");
1622  return false;
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 false;
1631  }
1632 
1633  return io->write(mappingGroup, mapping);
1634 }
FieldMappingIO::Ptr createFieldMappingIO(const std::string &className) const
Instances an IO object by name.
boost::intrusive_ptr< FieldMappingIO > Ptr
static ClassFactory & singleton()
}
void print(Severity severity, const std::string &message)
Sends the string to the assigned output, prefixing the message with the severity. ...
Definition: Log.cpp:62
bool writeAttribute(hid_t location, const std::string &attrName, const std::string &value)
Writes a string attribute.