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

bool fileExists (const std::string &filename)
 checks to see if a file/directory exists or not More...
 
FIELD3D_API 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...
 
FIELD3D_API 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

bool fileExists ( const std::string &  filename)

checks to see if a file/directory exists or not

Parameters
[in]filenamethe file/directory to check
Return values
trueif it exists
falseif it does not exist

Definition at line 1572 of file Field3DFile.cpp.

Referenced by FileSequence::FileSequence().

1573 {
1574 #ifdef WIN32
1575  struct __stat64 statbuf;
1576  return (_stat64(filename.c_str(), &statbuf) != -1);
1577 #else
1578  struct stat statbuf;
1579  return (stat(filename.c_str(), &statbuf) != -1);
1580 #endif
1581 }
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 1585 of file Field3DFile.cpp.

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

Referenced by Field3DOutputFile::writeLayer().

1586 {
1588 
1589  FieldIO::Ptr io = factory.createFieldIO(field->className());
1590  assert(io != 0);
1591  if (!io) {
1592  Msg::print(Msg::SevWarning, "Unable to find class type: " +
1593  field->className());
1594  return false;
1595  }
1596 
1597  // Add class name attribute
1598  if (!writeAttribute(layerGroup, k_classNameAttrName,
1599  field->className())) {
1600  Msg::print(Msg::SevWarning, "Error adding class name attribute.");
1601  return false;
1602  }
1603 
1604  return io->write(layerGroup, field);
1605 }
FIELD3D_API bool writeAttribute(hid_t location, const std::string &attrName, const std::string &value)
Writes a string attribute.
static ClassFactory & singleton()
}
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:66
FieldIO::Ptr createFieldIO(const std::string &className) const
Instances an IO object by name.
boost::intrusive_ptr< FieldIO > Ptr
Definition: FieldIO.h:90
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 1609 of file Field3DFile.cpp.

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

Referenced by Field3DInputFile::readPartitionAndLayerInfo().

1610 {
1612 
1613  std::string className;
1614 
1615  if (!readAttribute(mappingGroup, k_mappingTypeAttrName, className)) {
1616  Msg::print(Msg::SevWarning, "Couldn't find " + k_mappingTypeAttrName +
1617  " attribute");
1618  return FieldMapping::Ptr();
1619  }
1620 
1621  FieldMappingIO::Ptr io = factory.createFieldMappingIO(className);
1622  assert(io != 0);
1623  if (!io) {
1624  Msg::print(Msg::SevWarning, "Unable to find class type: " +
1625  className);
1626  return FieldMapping::Ptr();
1627  }
1628 
1629 
1630  FieldMapping::Ptr mapping = io->read(mappingGroup);
1631  if (!mapping) {
1632  Msg::print(Msg::SevWarning, "Couldn't read mapping");
1633  return FieldMapping::Ptr();
1634  }
1635 
1636  return mapping;
1637 }
boost::intrusive_ptr< FieldMappingIO > Ptr
FIELD3D_API bool readAttribute(hid_t location, const std::string &attrName, std::string &value)
Reads a string attribute.
static ClassFactory & singleton()
}
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:66
boost::intrusive_ptr< FieldMapping > Ptr
Definition: FieldMapping.h:92
FieldMappingIO::Ptr createFieldMappingIO(const std::string &className) const
Instances an IO object by name.
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 1641 of file Field3DFile.cpp.

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

Referenced by Field3DOutputFile::writeMapping().

1642 {
1644 
1645  std::string className = mapping->className();
1646 
1647  if (!writeAttribute(mappingGroup, k_mappingTypeAttrName, className)) {
1648  Msg::print(Msg::SevWarning, "Couldn't add " + className + " attribute");
1649  return false;
1650  }
1651 
1652  FieldMappingIO::Ptr io = factory.createFieldMappingIO(className);
1653  assert(io != 0);
1654  if (!io) {
1655  Msg::print(Msg::SevWarning, "Unable to find class type: " +
1656  className);
1657  return false;
1658  }
1659 
1660  return io->write(mappingGroup, mapping);
1661 }
boost::intrusive_ptr< FieldMappingIO > Ptr
FIELD3D_API bool writeAttribute(hid_t location, const std::string &attrName, const std::string &value)
Writes a string attribute.
static ClassFactory & singleton()
}
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:66
FieldMappingIO::Ptr createFieldMappingIO(const std::string &className) const
Instances an IO object by name.