HDF5Writer Class Reference

#include <hdf5writer.h>

Inheritance diagram for HDF5Writer:
Inheritance graph
[legend]
Collaboration diagram for HDF5Writer:
Collaboration graph
[legend]

List of all members.

Classes

struct  FieldInformation
struct  TriaInformation

Public Member Functions

 HDF5Writer ()
 ~HDF5Writer ()
hid_t getFile ()
void setVariable (std::string var, std::string value)
void setVariable (std::string var, double dValue)
void setOutputFile (string strFileName)
void close ()
bool existTriaInformation (string strName)
void setAtt (string objPath, string attName, string value)
void setAtt (string objPath, string attName, double dValue)
void writeInt (string objPath, string attName, int i)
void writeGrp (string grpName)
std::string getVariableValue (std::string var)
std::string getFileName ()

Protected Types

enum  TriaType { UNSTRUCTURED_GRID, STRUCTURED_GRID }
typedef Dictionary::const_iterator VariableIterator

Protected Member Functions

TriaInformationgetTriaInformation (string strName)
void writeInChunks (hid_t dataset, hsize_t offset[], hsize_t count[], void *buff)
FieldInformationgetFieldInfo (std::string fileName)
void writeContextVariables (std::string dataSetPath)
void validateField (string triaId, string fieldName)
std::string getNameOfLastRegisteredTriangulation ()
int getFieldCount (string fieldName)
void incFieldCount (string fieldName)
VariableIterator getVariablesIterator ()
VariableIterator getVariablesEnd ()
void appendMeshInfo (string triaId, struct TriaInformation info)
void putMeshIntoDictionary (string triaId, unsigned verts, unsigned cells)

Private Types

typedef __gnu_cxx::hash_map
< string, struct
TriaInformation, StringHashFun,
struct eqstr
TriaHeap
typedef __gnu_cxx::hash_map
< string, struct
FieldInformation,
StringHashFun, struct eqstr
FieldInfoHeap

Private Attributes

hid_t m_file
Dictionary varsHeap
TriaHeap triaHeap
FieldInfoHeap fieldInfo
string m_strFileName
string m_lastTriaName

Detailed Description

HDF5Writer

Definition at line 22 of file hdf5writer.h.


Member Typedef Documentation

typedef __gnu_cxx::hash_map<string,struct FieldInformation,StringHashFun,struct eqstr> HDF5Writer::FieldInfoHeap [private]

Definition at line 78 of file hdf5writer.h.

typedef __gnu_cxx::hash_map<string,struct TriaInformation,StringHashFun,struct eqstr> HDF5Writer::TriaHeap [private]

Definition at line 77 of file hdf5writer.h.

typedef Dictionary::const_iterator HDF5Writer::VariableIterator [protected]

Definition at line 91 of file hdf5writer.h.


Member Enumeration Documentation

enum HDF5Writer::TriaType [protected]
Enumerator:
UNSTRUCTURED_GRID 
STRUCTURED_GRID 

Definition at line 26 of file hdf5writer.h.


Constructor & Destructor Documentation

HDF5Writer::HDF5Writer (  ) 

Definition at line 7 of file hdf5writer.cpp.

00008 {
00009   m_file =-1;
00010   H5Eset_auto2(H5E_DEFAULT,(herr_t (*)(hid_t,void*))   &H5Eprint,stdout);
00011 
00012 }

HDF5Writer::~HDF5Writer (  ) 

Definition at line 30 of file hdf5writer.cpp.

00031 {
00032   close();
00033 }


Member Function Documentation

void HDF5Writer::appendMeshInfo ( string  triaId,
struct TriaInformation  info 
) [protected]

Definition at line 165 of file hdf5writer.cpp.

00166 {
00167  triaHeap[triaId]=info;
00168  m_lastTriaName = triaId; 
00169 
00170 }

void HDF5Writer::close (  ) 

Reimplemented in HDF5OrthoWriter.

Definition at line 23 of file hdf5writer.cpp.

00024 {
00025   if (m_file != -1)
00026   {
00027     H5Fclose(m_file);
00028   }
00029 }

bool HDF5Writer::existTriaInformation ( string  strName  ) 

Definition at line 102 of file hdf5writer.cpp.

00103 {
00104   if (triaHeap.find(strName) == triaHeap.end())
00105     return false;
00106   else
00107     return true;
00108 }

int HDF5Writer::getFieldCount ( string  fieldName  )  [protected]

Definition at line 110 of file hdf5writer.cpp.

00111 {
00112   if (fieldInfo.find(fieldName) == fieldInfo.end())
00113   {
00114     fieldInfo[fieldName]=FieldInformation();
00115     return 0;
00116   }
00117   else
00118   {
00119     return fieldInfo[fieldName].refCount;
00120   }
00121 }

FieldInformation& HDF5Writer::getFieldInfo ( std::string  fileName  )  [inline, protected]

Definition at line 93 of file hdf5writer.h.

00093 {return fieldInfo[fileName];}

hid_t HDF5Writer::getFile (  )  [inline]

Definition at line 106 of file hdf5writer.h.

00106 {assert(m_file != -1);return m_file;}

std::string HDF5Writer::getFileName (  )  [inline]

Definition at line 117 of file hdf5writer.h.

00117 {return m_strFileName;}

std::string HDF5Writer::getNameOfLastRegisteredTriangulation (  )  [inline, protected]

Definition at line 96 of file hdf5writer.h.

00096 {return m_lastTriaName;}

HDF5Writer::TriaInformation & HDF5Writer::getTriaInformation ( string  strName  )  [protected]

Get the triangulation information. If the triangulation is not found, an exception is raised.

Parameters:
strName The name of the triangulation
Returns:

Definition at line 96 of file hdf5writer.cpp.

00097 {
00098   if (triaHeap.find(strName) == triaHeap.end())
00099     throw new Exception("HDF5Writer: Triangulation %s does not exist",strName.c_str());
00100   return triaHeap.find(strName)->second;
00101 }

HDF5Writer::VariableIterator HDF5Writer::getVariablesEnd (  )  [protected]

Definition at line 146 of file hdf5writer.cpp.

00147 {
00148   return this->varsHeap.end();
00149 }

HDF5Writer::VariableIterator HDF5Writer::getVariablesIterator (  )  [protected]

This is the method used to get the iterator pointing to the beginning of the variables list. To get the name of the variable that the iterator it is ponting use it->first and to get its value you should use it->second. An example of its use can be seen in the method HDF5HDF5Writer::writeContextVariables .

Returns:

Definition at line 141 of file hdf5writer.cpp.

00142 {
00143   return this->varsHeap.begin();
00144 }

std::string HDF5Writer::getVariableValue ( std::string  var  ) 

Definition at line 71 of file hdf5writer.cpp.

00072 {
00073   return varsHeap[var];
00074 }

void HDF5Writer::incFieldCount ( string  fieldName  )  [protected]

Definition at line 124 of file hdf5writer.cpp.

00125 {
00126   if (fieldInfo.find(fieldName) == fieldInfo.end())
00127   {
00128     fieldInfo[fieldName]=FieldInformation();
00129   }
00130   fieldInfo[fieldName].refCount++;
00131   
00132 }

void HDF5Writer::putMeshIntoDictionary ( string  triaId,
unsigned  verts,
unsigned  cells 
) [protected]

Write mesh information.

Parameters:
triaId Name of the mesh
verts Number of vertices of the mesh
cells Number of cells
type Type of triangulation
Returns:

Definition at line 200 of file hdf5writer.cpp.

00201 {
00202   appendMeshInfo(triaId,TriaInformation(verts,cells));
00203   
00204 }

void HDF5Writer::setAtt ( string  objPath,
string  attName,
double  dValue 
)

Definition at line 218 of file hdf5writer.cpp.

00219 {
00220   char value[100];
00221   sprintf(value,"%g",dValue);
00222   herr_t error = H5LTset_attribute_string(getFile(),objPath.c_str(),attName.c_str(),value);
00223   if (error < 0)
00224   throw new Exception("HDF5OrthoWriter::setAtt error trying to set attribute \"%s/%s\"",objPath.c_str(),attName.c_str());
00225 }

void HDF5Writer::setAtt ( string  objPath,
string  attName,
string  value 
)

Definition at line 209 of file hdf5writer.cpp.

00210 {
00211   herr_t error = H5LTset_attribute_string(getFile(),objPath.c_str(),attName.c_str(),value.c_str());
00212   if (error < 0)
00213     throw new Exception("HDF5OrthoWriter::setAtt error trying to set attribute \"%s/%s\"",objPath.c_str(),attName.c_str());
00214 }

void HDF5Writer::setOutputFile ( string  strFileName  ) 

Definition at line 14 of file hdf5writer.cpp.

00015 {
00016   m_strFileName=strFileName;
00017   m_file = H5Fcreate(strFileName.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
00018   H5Gclose(H5Gcreate1(m_file,"/DataSets",0));
00019   H5Gclose(H5Gcreate1(m_file,"/Triangulations",0));
00020 }

void HDF5Writer::setVariable ( std::string  var,
double  dValue 
)

Definition at line 77 of file hdf5writer.cpp.

00078 {
00079   char str[100];
00080   sprintf(str,"%g",dValue);
00081   setVariable(var,str);
00082 }

void HDF5Writer::setVariable ( std::string  var,
std::string  value 
)

Definition at line 66 of file hdf5writer.cpp.

00067 {
00068   varsHeap[var]=value;
00069 }

void HDF5Writer::validateField ( string  triaId,
string  fieldName 
) [protected]

This method validates the name of a field associated with a given triangulation name, It checks if the triangulation referenced by the field exist, check if the fieldName is not already used to define a variable name (see HDF5Writer::setVariable) or a triangulation name

Parameters:
triaId 
fieldName 
Returns:

Definition at line 44 of file hdf5writer.cpp.

00045 {
00046   if ( varsHeap.find(fieldName) != varsHeap.end())
00047   {
00048     printf("HDF5Writer: Field name %s already defined as a variable\n",fieldName.c_str());
00049     abort();
00050   }
00051   if (triaHeap.find(fieldName) != triaHeap.end())
00052   {
00053     printf("HDF5Writer: Field name %s already defined as a triangulation\n",fieldName.c_str());
00054     abort();
00055   }
00056   if (triaHeap.find(triaId) == triaHeap.end())
00057   {    
00058     printf("HDF5Writer: Triangulation \"%s\" referenced by  field %s not defined\n",triaId.c_str(),fieldName.c_str());
00059     abort();
00060   }
00061 
00062 }

void HDF5Writer::writeContextVariables ( std::string  dataSetPath  )  [protected]

Definition at line 153 of file hdf5writer.cpp.

00154 {
00155   assert(m_file != -1);
00156   //Para todas as variaveis
00157   for (HDF5Writer::VariableIterator it = getVariablesIterator();it != getVariablesEnd();it++)
00158   {
00159     H5LTset_attribute_string(m_file,dataSetPath.c_str(),it->first.c_str(),it->second.c_str());
00160   }
00161 
00162 }

void HDF5Writer::writeGrp ( string  grpName  ) 
void HDF5Writer::writeInChunks ( hid_t  dataset,
hsize_t  offset[],
hsize_t  count[],
void *  buff 
) [protected]

Definition at line 173 of file hdf5writer.cpp.

00174 {
00175   if (!count[0])
00176     return;
00177   hid_t dataspace = H5Dget_space(dataset);
00178   H5Sselect_hyperslab(dataspace, H5S_SELECT_SET, offset, NULL,count, NULL);
00179 
00180   hid_t datatype = H5Dget_type(dataset);
00181 
00182   hsize_t dim[]={count[0],count[1]};
00183   hid_t memspace = H5Screate_simple(2,dim,NULL);
00184 
00185   int error = H5Dwrite(dataset,datatype,memspace,dataspace,H5P_DEFAULT,buff);
00186   assert(error >=0);
00187 
00188   H5Sclose(memspace);
00189   H5Sclose(dataspace);
00190   H5Tclose(datatype);
00191 }

void HDF5Writer::writeInt ( string  objPath,
string  attName,
int  i 
)

Member Data Documentation

Reference count for each field name.

Definition at line 82 of file hdf5writer.h.

hid_t HDF5Writer::m_file [private]

File to store the data

Definition at line 75 of file hdf5writer.h.

string HDF5Writer::m_lastTriaName [private]

This string contains the name of the last triangulation inserted with the method registerTriangulation()

Definition at line 85 of file hdf5writer.h.

string HDF5Writer::m_strFileName [private]

The filename of the hdf5 file

Definition at line 84 of file hdf5writer.h.

Map of all the triangulations registered

Definition at line 81 of file hdf5writer.h.

Map that contains all variable values

Definition at line 80 of file hdf5writer.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Sun Apr 8 23:13:12 2012 for CO2INJECTION by  doxygen 1.6.3