Chaste  Release::2017.1
ColumnDataWriter Class Reference

#include <ColumnDataWriter.hpp>

+ Inheritance diagram for ColumnDataWriter:
+ Collaboration diagram for ColumnDataWriter:

Public Member Functions

 ColumnDataWriter (const std::string &rDirectory, const std::string &rBaseName, bool cleanDirectory=true, unsigned precision=8)
 
virtual ~ColumnDataWriter ()
 
int DefineUnlimitedDimension (const std::string &rDimensionName, const std::string &rDimensionUnits)
 
int DefineFixedDimension (const std::string &rDimensionName, const std::string &rDimensionUnits, long dimensionSize)
 
int DefineVariable (const std::string &rVariableName, const std::string &rVariableUnits)
 
void SetCommentForInfoFile (std::string comment)
 
virtual void EndDefineMode ()
 
virtual void AdvanceAlongUnlimitedDimension ()
 
virtual void PutVariable (int variableID, double variableValue, long dimensionPosition=-1)
 
virtual void Close ()
 
std::string GetOutputDirectory ()
 
- Public Member Functions inherited from AbstractDataWriter
virtual ~AbstractDataWriter ()
 

Protected Member Functions

void CreateFixedDimensionFile (const std::string &rFileName)
 
void CreateInfoFile (const std::string &rFileName)
 
void CheckVariableName (const std::string &rName)
 
void CheckUnitsName (const std::string &rName)
 
void DoAdvanceAlongUnlimitedDimension ()
 

Protected Attributes

OutputFileHandler mOutputFileHandler
 
std::string mDirectory
 
std::string mBaseName
 
bool mIsInDefineMode
 
bool mIsFixedDimensionSet
 
bool mIsUnlimitedDimensionSet
 
long mUnlimitedDimensionPosition
 
long mFixedDimensionSize
 
out_stream mpCurrentOutputFile
 
out_stream mpCurrentAncillaryFile
 
DataWriterVariablempUnlimitedDimensionVariable
 
DataWriterVariablempFixedDimensionVariable
 
std::string mUnlimitedDimensionName
 
std::string mUnlimitedDimensionUnits
 
std::string mFixedDimensionName
 
std::string mFixedDimensionUnits
 
std::vector< DataWriterVariablemVariables
 
const unsigned mFieldWidth
 
const unsigned mPrecision
 
std::string mFileExtension
 
int mRowStartPosition
 
int mRowWidth
 
int mAncillaryRowStartPosition
 
int mAncillaryRowWidth
 
bool mHasPutVariable
 
bool mNeedAdvanceAlongUnlimitedDimension
 
std::string mCommentForInfoFile
 

Static Protected Attributes

static const int SPACING = 1
 
static const int FIXED_DIMENSION_VAR_ID = -1
 
static const int UNLIMITED_DIMENSION_VAR_ID = -2
 

Detailed Description

A concrete column data writer class. Writes grid-formatted data in space separated column form. Each file has a header row with names and optional units for each column.

Definition at line 51 of file ColumnDataWriter.hpp.

Constructor & Destructor Documentation

ColumnDataWriter::ColumnDataWriter ( const std::string &  rDirectory,
const std::string &  rBaseName,
bool  cleanDirectory = true,
unsigned  precision = 8 
)

Constructor.

Parameters
rDirectorythe directory in which to write the data to file
rBaseNamethe name of the file in which to write the data
cleanDirectorywhether to clean the directory (defaults to true)
precisionthe precision with which to write the data (i.e. exactly how many digits to display after the decimal point). Defaults to 8. Must be between 2 and 20 (inclusive).

Implementation file for ColumnDataWriter class.

Definition at line 52 of file ColumnDataWriter.cpp.

References EXCEPTION.

ColumnDataWriter::~ColumnDataWriter ( )
virtual

Destructor. Closes any open files.

Definition at line 80 of file ColumnDataWriter.cpp.

References Close(), mpFixedDimensionVariable, and mpUnlimitedDimensionVariable.

Member Function Documentation

void ColumnDataWriter::AdvanceAlongUnlimitedDimension ( )
virtual

Dummy function for DoAdvanceAlongUnlimitedDimension.

Implements AbstractDataWriter.

Reimplemented in ParallelColumnDataWriter.

Definition at line 400 of file ColumnDataWriter.cpp.

References mHasPutVariable, and mNeedAdvanceAlongUnlimitedDimension.

Referenced by SetCommentForInfoFile(), and OdeSolution::WriteToFile().

void ColumnDataWriter::CheckUnitsName ( const std::string &  rName)
protected

Check name of unit is allowed, i.e. contains only alphanumeric & _, and isn't blank.

Parameters
rNameunit name

Definition at line 125 of file ColumnDataWriter.cpp.

References EXCEPTION.

Referenced by CheckVariableName(), DefineFixedDimension(), DefineUnlimitedDimension(), and DefineVariable().

void ColumnDataWriter::CheckVariableName ( const std::string &  rName)
protected

Check name of variable is allowed, i.e. contains only alphanumeric & _, and isn't blank.

Parameters
rNamevariable name

Definition at line 116 of file ColumnDataWriter.cpp.

References CheckUnitsName(), and EXCEPTION.

Referenced by DefineFixedDimension(), DefineUnlimitedDimension(), and DefineVariable().

void ColumnDataWriter::Close ( )
virtual
void ColumnDataWriter::CreateFixedDimensionFile ( const std::string &  rFileName)
protected

Create the output file and write out the header for it.

Parameters
rFileNamethe name of the file to write to, relative to the output directory

Definition at line 322 of file ColumnDataWriter.cpp.

References mFixedDimensionSize, mOutputFileHandler, mpCurrentOutputFile, mpFixedDimensionVariable, mPrecision, mRowStartPosition, mRowWidth, DataWriterVariable::mVariableName, mVariables, DataWriterVariable::mVariableUnits, and OutputFileHandler::OpenOutputFile().

Referenced by DoAdvanceAlongUnlimitedDimension(), and EndDefineMode().

void ColumnDataWriter::CreateInfoFile ( const std::string &  rFileName)
protected

Create the info file.

Parameters
rFileNamethe name of the file to create, relative to the output directory

Definition at line 351 of file ColumnDataWriter.cpp.

References ChasteBuildInfo::GetProvenanceString(), mCommentForInfoFile, mFixedDimensionSize, mIsUnlimitedDimensionSet, mOutputFileHandler, mVariables, and OutputFileHandler::OpenOutputFile().

Referenced by EndDefineMode().

int ColumnDataWriter::DefineFixedDimension ( const std::string &  rDimensionName,
const std::string &  rDimensionUnits,
long  dimensionSize 
)
virtual

Define the fixed dimension.

Parameters
rDimensionNameThe name of the dimension
rDimensionUnitsThe physical units of the dimension
dimensionSizeThe size of the dimension
Returns
The identifier of the variable

Implements AbstractDataWriter.

Definition at line 165 of file ColumnDataWriter.cpp.

References CheckUnitsName(), CheckVariableName(), EXCEPTION, FIXED_DIMENSION_VAR_ID, mFixedDimensionName, mFixedDimensionSize, mFixedDimensionUnits, mIsFixedDimensionSet, mIsInDefineMode, mpFixedDimensionVariable, DataWriterVariable::mVariableName, and DataWriterVariable::mVariableUnits.

int ColumnDataWriter::DefineUnlimitedDimension ( const std::string &  rDimensionName,
const std::string &  rDimensionUnits 
)
virtual

Define the unlimited dimension, i.e. the dimension that increases as the simulation progresses.

Parameters
rDimensionNameThe name of the unlimited dimension
rDimensionUnitsThe physical units of the unlimited dimension
Returns
The identifier of the variable

Implements AbstractDataWriter.

Definition at line 137 of file ColumnDataWriter.cpp.

References CheckUnitsName(), CheckVariableName(), EXCEPTION, mIsInDefineMode, mIsUnlimitedDimensionSet, mpUnlimitedDimensionVariable, mUnlimitedDimensionName, mUnlimitedDimensionUnits, DataWriterVariable::mVariableName, DataWriterVariable::mVariableUnits, and UNLIMITED_DIMENSION_VAR_ID.

Referenced by OdeSolution::WriteToFile().

int ColumnDataWriter::DefineVariable ( const std::string &  rVariableName,
const std::string &  rVariableUnits 
)
virtual

Define a variable.

Parameters
rVariableNameThe name of the variable
rVariableUnitsThe physical units of the variable
Returns
The identifier of the variable

Implements AbstractDataWriter.

Definition at line 193 of file ColumnDataWriter.cpp.

References CheckUnitsName(), CheckVariableName(), EXCEPTION, mFixedDimensionName, mIsInDefineMode, mUnlimitedDimensionName, DataWriterVariable::mVariableName, mVariables, and DataWriterVariable::mVariableUnits.

Referenced by OdeSolution::WriteToFile().

void ColumnDataWriter::DoAdvanceAlongUnlimitedDimension ( )
protected
std::string ColumnDataWriter::GetOutputDirectory ( )
Returns
the full pathname of the directory where we're writing files.

Definition at line 96 of file ColumnDataWriter.cpp.

References OutputFileHandler::GetOutputDirectoryFullPath(), and mOutputFileHandler.

Referenced by SetCommentForInfoFile().

void ColumnDataWriter::PutVariable ( int  variableID,
double  variableValue,
long  dimensionPosition = -1 
)
virtual

Input the variable value to the output file or ancillary file.

Parameters
variableID
variableValue
dimensionPositionThe position in column (defaults to -1). This is required if there is a fixed dimension, and will be the position along that dimension

Implements AbstractDataWriter.

Reimplemented in ParallelColumnDataWriter.

Definition at line 408 of file ColumnDataWriter.cpp.

References DoAdvanceAlongUnlimitedDimension(), EXCEPTION, FIXED_DIMENSION_VAR_ID, mFieldWidth, mFixedDimensionSize, mHasPutVariable, mIsFixedDimensionSet, mIsInDefineMode, mIsUnlimitedDimensionSet, mNeedAdvanceAlongUnlimitedDimension, mpCurrentAncillaryFile, mpCurrentOutputFile, mpFixedDimensionVariable, mpUnlimitedDimensionVariable, mRowStartPosition, mRowWidth, mVariables, SPACING, and UNLIMITED_DIMENSION_VAR_ID.

Referenced by ParallelColumnDataWriter::PutVariable(), ParallelColumnDataWriter::PutVector(), SetCommentForInfoFile(), and OdeSolution::WriteToFile().

void ColumnDataWriter::SetCommentForInfoFile ( std::string  comment)
inline

Set a comment to be written in the info file (optional). This needs to be called before EndDefineMode().

Parameters
commentthe comment

Definition at line 197 of file ColumnDataWriter.hpp.

References AdvanceAlongUnlimitedDimension(), Close(), EndDefineMode(), GetOutputDirectory(), and PutVariable().

Referenced by OdeSolution::WriteToFile().

Member Data Documentation

const int ColumnDataWriter::FIXED_DIMENSION_VAR_ID = -1
staticprotected

id of fixed dimension variable

Definition at line 80 of file ColumnDataWriter.hpp.

Referenced by DefineFixedDimension(), and PutVariable().

int ColumnDataWriter::mAncillaryRowStartPosition
protected

The position of the ancillary file pointer when it's at the beginning of the current row

Definition at line 88 of file ColumnDataWriter.hpp.

Referenced by EndDefineMode().

int ColumnDataWriter::mAncillaryRowWidth
protected

The width in characters of a row in the ancillary file

Definition at line 89 of file ColumnDataWriter.hpp.

Referenced by EndDefineMode().

std::string ColumnDataWriter::mBaseName
protected

The base name for the output data files.

Definition at line 58 of file ColumnDataWriter.hpp.

Referenced by DoAdvanceAlongUnlimitedDimension(), and EndDefineMode().

std::string ColumnDataWriter::mCommentForInfoFile
protected

(Optional) comment that can be set and will be written to the info file when CreateInfoFile() is called in EndDefineMode()

Definition at line 98 of file ColumnDataWriter.hpp.

Referenced by CreateInfoFile().

std::string ColumnDataWriter::mDirectory
protected

Directory output files will be stored in.

Definition at line 57 of file ColumnDataWriter.hpp.

const unsigned ColumnDataWriter::mFieldWidth
protected

Width of each column in the text file (excludes column headers)

Definition at line 77 of file ColumnDataWriter.hpp.

Referenced by EndDefineMode(), and PutVariable().

std::string ColumnDataWriter::mFileExtension
protected

Extension of output files

Definition at line 83 of file ColumnDataWriter.hpp.

std::string ColumnDataWriter::mFixedDimensionName
protected

The name of the fixed dimension

Definition at line 72 of file ColumnDataWriter.hpp.

Referenced by DefineFixedDimension(), and DefineVariable().

long ColumnDataWriter::mFixedDimensionSize
protected

The size of the fixed dimension

Definition at line 63 of file ColumnDataWriter.hpp.

Referenced by CreateFixedDimensionFile(), CreateInfoFile(), DefineFixedDimension(), PutVariable(), and ParallelColumnDataWriter::PutVector().

std::string ColumnDataWriter::mFixedDimensionUnits
protected

The units of the fixed dimension

Definition at line 73 of file ColumnDataWriter.hpp.

Referenced by DefineFixedDimension().

bool ColumnDataWriter::mHasPutVariable
protected

Whether a variable value has been output to a file.

Definition at line 91 of file ColumnDataWriter.hpp.

Referenced by AdvanceAlongUnlimitedDimension(), DoAdvanceAlongUnlimitedDimension(), and PutVariable().

bool ColumnDataWriter::mIsFixedDimensionSet
protected

Is the fixed dimension set

Definition at line 60 of file ColumnDataWriter.hpp.

Referenced by DefineFixedDimension(), DoAdvanceAlongUnlimitedDimension(), EndDefineMode(), and PutVariable().

bool ColumnDataWriter::mIsInDefineMode
protected
bool ColumnDataWriter::mIsUnlimitedDimensionSet
protected

Is the unlimited dimension set

Definition at line 61 of file ColumnDataWriter.hpp.

Referenced by CreateInfoFile(), DefineUnlimitedDimension(), DoAdvanceAlongUnlimitedDimension(), EndDefineMode(), and PutVariable().

bool ColumnDataWriter::mNeedAdvanceAlongUnlimitedDimension
protected

Whether we need to advance along the unlimited dimension.

Definition at line 92 of file ColumnDataWriter.hpp.

Referenced by AdvanceAlongUnlimitedDimension(), DoAdvanceAlongUnlimitedDimension(), and PutVariable().

OutputFileHandler ColumnDataWriter::mOutputFileHandler
protected

For opening data files.

Definition at line 55 of file ColumnDataWriter.hpp.

Referenced by CreateFixedDimensionFile(), CreateInfoFile(), EndDefineMode(), and GetOutputDirectory().

out_stream ColumnDataWriter::mpCurrentAncillaryFile
protected

Ancillary filestream currently being addressed (required for two dimensional output) eg. time file

Definition at line 65 of file ColumnDataWriter.hpp.

Referenced by Close(), EndDefineMode(), and PutVariable().

out_stream ColumnDataWriter::mpCurrentOutputFile
protected

Filestream currently being addressed

Definition at line 64 of file ColumnDataWriter.hpp.

Referenced by Close(), CreateFixedDimensionFile(), DoAdvanceAlongUnlimitedDimension(), EndDefineMode(), and PutVariable().

DataWriterVariable* ColumnDataWriter::mpFixedDimensionVariable
protected

The variable corresponding to the fixed dimension

Definition at line 67 of file ColumnDataWriter.hpp.

Referenced by CreateFixedDimensionFile(), DefineFixedDimension(), EndDefineMode(), PutVariable(), and ~ColumnDataWriter().

const unsigned ColumnDataWriter::mPrecision
protected

Precision used in writing the data

Definition at line 78 of file ColumnDataWriter.hpp.

Referenced by CreateFixedDimensionFile(), and EndDefineMode().

DataWriterVariable* ColumnDataWriter::mpUnlimitedDimensionVariable
protected

The variable corresponding to the unlimited dimension

Definition at line 66 of file ColumnDataWriter.hpp.

Referenced by DefineUnlimitedDimension(), EndDefineMode(), PutVariable(), and ~ColumnDataWriter().

int ColumnDataWriter::mRowStartPosition
protected

The position of the file pointer when it's at the beginning of the current row

Definition at line 85 of file ColumnDataWriter.hpp.

Referenced by CreateFixedDimensionFile(), DoAdvanceAlongUnlimitedDimension(), EndDefineMode(), and PutVariable().

int ColumnDataWriter::mRowWidth
protected

The width in characters of a row in the file

Definition at line 86 of file ColumnDataWriter.hpp.

Referenced by CreateFixedDimensionFile(), DoAdvanceAlongUnlimitedDimension(), EndDefineMode(), and PutVariable().

std::string ColumnDataWriter::mUnlimitedDimensionName
protected

The name of the unlimited dimension.

Definition at line 69 of file ColumnDataWriter.hpp.

Referenced by DefineUnlimitedDimension(), and DefineVariable().

long ColumnDataWriter::mUnlimitedDimensionPosition
protected

The position along the unlimited dimension that writing of variables will take place

Definition at line 62 of file ColumnDataWriter.hpp.

Referenced by DoAdvanceAlongUnlimitedDimension(), and EndDefineMode().

std::string ColumnDataWriter::mUnlimitedDimensionUnits
protected

The physical units of the unlimited dimension.

Definition at line 70 of file ColumnDataWriter.hpp.

Referenced by DefineUnlimitedDimension().

std::vector<DataWriterVariable> ColumnDataWriter::mVariables
protected

The data variables

Definition at line 75 of file ColumnDataWriter.hpp.

Referenced by CreateFixedDimensionFile(), CreateInfoFile(), DefineVariable(), EndDefineMode(), and PutVariable().

const int ColumnDataWriter::SPACING = 1
staticprotected

Space between columns (includes minus sign)

Definition at line 79 of file ColumnDataWriter.hpp.

Referenced by EndDefineMode(), and PutVariable().

const int ColumnDataWriter::UNLIMITED_DIMENSION_VAR_ID = -2
staticprotected

id of unlimited dimension variable

Definition at line 81 of file ColumnDataWriter.hpp.

Referenced by DefineUnlimitedDimension(), and PutVariable().


The documentation for this class was generated from the following files: