#include <ColumnDataWriter.hpp>
Public Member Functions | |
ColumnDataWriter (const std::string &rDirectory, const std::string &rBaseName, bool cleanDirectory=true) | |
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) |
virtual void | EndDefineMode () |
virtual void | AdvanceAlongUnlimitedDimension () |
virtual void | PutVariable (int variableID, double variableValue, long dimensionPosition=-1) |
virtual void | Close () |
std::string | GetOutputDirectory () |
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 |
DataWriterVariable * | mpUnlimitedDimensionVariable |
DataWriterVariable * | mpFixedDimensionVariable |
std::string | mUnlimitedDimensionName |
std::string | mUnlimitedDimensionUnits |
std::string | mFixedDimensionName |
std::string | mFixedDimensionUnits |
std::vector< DataWriterVariable > | mVariables |
std::string | mFileExtension |
int | mRowStartPosition |
int | mRowWidth |
int | mAncillaryRowStartPosition |
int | mAncillaryRowWidth |
bool | mHasPutVariable |
bool | mNeedAdvanceAlongUnlimitedDimension |
Static Protected Attributes | |
static const int | FIELD_WIDTH = 10 |
static const int | SPACING = 2 |
static const int | FIXED_DIMENSION_VAR_ID = -1 |
static const int | UNLIMITED_DIMENSION_VAR_ID = -2 |
Definition at line 45 of file ColumnDataWriter.hpp.
ColumnDataWriter::ColumnDataWriter | ( | const std::string & | rDirectory, | |
const std::string & | rBaseName, | |||
bool | cleanDirectory = true | |||
) |
Constructor.
rDirectory | the directory in which to write the data to file | |
rBaseName | the name of the file in which to write the data | |
cleanDirectory | whether to clean the directory (defaults to true) |
Definition at line 45 of file ColumnDataWriter.cpp.
ColumnDataWriter::~ColumnDataWriter | ( | ) | [virtual] |
Destructor. Closes any open files.
Definition at line 65 of file ColumnDataWriter.cpp.
References Close(), mpFixedDimensionVariable, and mpUnlimitedDimensionVariable.
void ColumnDataWriter::CreateFixedDimensionFile | ( | const std::string & | rFileName | ) | [protected] |
Create the output file and write out the header for it.
rFileName | the name of the file to write to, relative to the output directory |
Definition at line 305 of file ColumnDataWriter.cpp.
References FIELD_WIDTH, mFixedDimensionSize, mOutputFileHandler, mpCurrentOutputFile, mpFixedDimensionVariable, 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.
rFileName | the name of the file to create, relative to the output directory |
Definition at line 334 of file ColumnDataWriter.cpp.
References mFixedDimensionSize, mIsUnlimitedDimensionSet, mOutputFileHandler, mVariables, and OutputFileHandler::OpenOutputFile().
Referenced by EndDefineMode().
void ColumnDataWriter::CheckVariableName | ( | const std::string & | rName | ) | [protected] |
Check name of variable is allowed, i.e. contains only alphanumeric & _, and isn't blank.
rName | variable name |
Definition at line 101 of file ColumnDataWriter.cpp.
References CheckUnitsName().
Referenced by DefineFixedDimension(), DefineUnlimitedDimension(), and DefineVariable().
void ColumnDataWriter::CheckUnitsName | ( | const std::string & | rName | ) | [protected] |
Check name of unit is allowed, i.e. contains only alphanumeric & _, and isn't blank.
rName | unit name |
Definition at line 110 of file ColumnDataWriter.cpp.
Referenced by CheckVariableName(), DefineFixedDimension(), DefineUnlimitedDimension(), and DefineVariable().
void ColumnDataWriter::DoAdvanceAlongUnlimitedDimension | ( | ) | [protected] |
Advance along the unlimited dimension. Normally this will be called when all variables in a row have been input.
Definition at line 344 of file ColumnDataWriter.cpp.
References CreateFixedDimensionFile(), FILE_SUFFIX_WIDTH, mBaseName, mHasPutVariable, mIsFixedDimensionSet, mIsUnlimitedDimensionSet, mNeedAdvanceAlongUnlimitedDimension, mpCurrentOutputFile, mRowStartPosition, mRowWidth, and mUnlimitedDimensionPosition.
Referenced by ParallelColumnDataWriter::AdvanceAlongUnlimitedDimension(), and PutVariable().
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.
rDimensionName | The name of the unlimited dimension | |
rDimensionUnits | The physical units of the unlimited dimension |
Implements AbstractDataWriter.
Definition at line 122 of file ColumnDataWriter.cpp.
References CheckUnitsName(), CheckVariableName(), mIsInDefineMode, mIsUnlimitedDimensionSet, mpUnlimitedDimensionVariable, mUnlimitedDimensionName, mUnlimitedDimensionUnits, DataWriterVariable::mVariableName, DataWriterVariable::mVariableUnits, and UNLIMITED_DIMENSION_VAR_ID.
int ColumnDataWriter::DefineFixedDimension | ( | const std::string & | rDimensionName, | |
const std::string & | rDimensionUnits, | |||
long | dimensionSize | |||
) | [virtual] |
Define the fixed dimension.
rDimensionName | The name of the dimension | |
rDimensionUnits | The physical units of the dimension | |
dimensionSize | The size of the dimension |
Implements AbstractDataWriter.
Definition at line 150 of file ColumnDataWriter.cpp.
References CheckUnitsName(), CheckVariableName(), FIXED_DIMENSION_VAR_ID, mFixedDimensionName, mFixedDimensionSize, mFixedDimensionUnits, mIsFixedDimensionSet, mIsInDefineMode, mpFixedDimensionVariable, DataWriterVariable::mVariableName, and DataWriterVariable::mVariableUnits.
int ColumnDataWriter::DefineVariable | ( | const std::string & | rVariableName, | |
const std::string & | rVariableUnits | |||
) | [virtual] |
Define a variable.
rVariableName | The name of the variable | |
rVariableUnits | The physical units of the variable |
Implements AbstractDataWriter.
Definition at line 178 of file ColumnDataWriter.cpp.
References CheckUnitsName(), CheckVariableName(), mFixedDimensionName, mIsInDefineMode, mUnlimitedDimensionName, DataWriterVariable::mVariableName, mVariables, and DataWriterVariable::mVariableUnits.
void ColumnDataWriter::EndDefineMode | ( | ) | [virtual] |
End the define mode of the DataWriter.
Implements AbstractDataWriter.
Reimplemented in ParallelColumnDataWriter.
Definition at line 215 of file ColumnDataWriter.cpp.
References CreateFixedDimensionFile(), CreateInfoFile(), FIELD_WIDTH, FILE_SUFFIX_WIDTH, mAncillaryRowStartPosition, mAncillaryRowWidth, mBaseName, mIsFixedDimensionSet, mIsInDefineMode, mIsUnlimitedDimensionSet, mOutputFileHandler, mpCurrentAncillaryFile, mpCurrentOutputFile, mpFixedDimensionVariable, mpUnlimitedDimensionVariable, mRowStartPosition, mRowWidth, mUnlimitedDimensionPosition, DataWriterVariable::mVariableName, mVariables, DataWriterVariable::mVariableUnits, OutputFileHandler::OpenOutputFile(), and SPACING.
Referenced by ParallelColumnDataWriter::EndDefineMode().
void ColumnDataWriter::AdvanceAlongUnlimitedDimension | ( | ) | [virtual] |
Dummy function for DoAdvanceAlongUnlimitedDimension.
Implements AbstractDataWriter.
Reimplemented in ParallelColumnDataWriter.
Definition at line 384 of file ColumnDataWriter.cpp.
References mHasPutVariable, and mNeedAdvanceAlongUnlimitedDimension.
void ColumnDataWriter::PutVariable | ( | int | variableID, | |
double | variableValue, | |||
long | dimensionPosition = -1 | |||
) | [virtual] |
Input the variable value to the output file or ancillary file.
variableID | ||
variableValue | ||
dimensionPosition | The 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 392 of file ColumnDataWriter.cpp.
References DoAdvanceAlongUnlimitedDimension(), FIELD_WIDTH, FIXED_DIMENSION_VAR_ID, mFixedDimensionSize, mHasPutVariable, mIsFixedDimensionSet, mIsInDefineMode, mIsUnlimitedDimensionSet, mNeedAdvanceAlongUnlimitedDimension, mpCurrentAncillaryFile, mpCurrentOutputFile, mpFixedDimensionVariable, mpUnlimitedDimensionVariable, mRowStartPosition, mRowWidth, mVariables, SPACING, and UNLIMITED_DIMENSION_VAR_ID.
Referenced by ParallelColumnDataWriter::PutVariable(), and ParallelColumnDataWriter::PutVector().
void ColumnDataWriter::Close | ( | ) | [virtual] |
Close any open files.
Implements AbstractDataWriter.
Reimplemented in ParallelColumnDataWriter.
Definition at line 86 of file ColumnDataWriter.cpp.
References mpCurrentAncillaryFile, and mpCurrentOutputFile.
Referenced by ParallelColumnDataWriter::Close(), and ~ColumnDataWriter().
std::string ColumnDataWriter::GetOutputDirectory | ( | ) |
Return the full pathname of the directory where we're writing files.
Definition at line 81 of file ColumnDataWriter.cpp.
References OutputFileHandler::GetOutputDirectoryFullPath(), and mOutputFileHandler.
For opening data files.
Definition at line 49 of file ColumnDataWriter.hpp.
Referenced by CreateFixedDimensionFile(), CreateInfoFile(), EndDefineMode(), and GetOutputDirectory().
std::string ColumnDataWriter::mDirectory [protected] |
Directory output files will be stored in.
Definition at line 51 of file ColumnDataWriter.hpp.
std::string ColumnDataWriter::mBaseName [protected] |
The base name for the output data files.
Definition at line 52 of file ColumnDataWriter.hpp.
Referenced by DoAdvanceAlongUnlimitedDimension(), and EndDefineMode().
bool ColumnDataWriter::mIsInDefineMode [protected] |
Is the DataWriter in define mode or not
Definition at line 53 of file ColumnDataWriter.hpp.
Referenced by DefineFixedDimension(), DefineUnlimitedDimension(), DefineVariable(), ParallelColumnDataWriter::EndDefineMode(), EndDefineMode(), and PutVariable().
bool ColumnDataWriter::mIsFixedDimensionSet [protected] |
Is the fixed dimension set
Definition at line 54 of file ColumnDataWriter.hpp.
Referenced by DefineFixedDimension(), DoAdvanceAlongUnlimitedDimension(), EndDefineMode(), and PutVariable().
bool ColumnDataWriter::mIsUnlimitedDimensionSet [protected] |
Is the unlimited dimension set
Definition at line 55 of file ColumnDataWriter.hpp.
Referenced by CreateInfoFile(), DefineUnlimitedDimension(), DoAdvanceAlongUnlimitedDimension(), EndDefineMode(), and PutVariable().
long ColumnDataWriter::mUnlimitedDimensionPosition [protected] |
The position along the unlimited dimension that writing of variables will take place
Definition at line 56 of file ColumnDataWriter.hpp.
Referenced by DoAdvanceAlongUnlimitedDimension(), and EndDefineMode().
long ColumnDataWriter::mFixedDimensionSize [protected] |
The size of the fixed dimension
Definition at line 57 of file ColumnDataWriter.hpp.
Referenced by CreateFixedDimensionFile(), CreateInfoFile(), DefineFixedDimension(), PutVariable(), and ParallelColumnDataWriter::PutVector().
out_stream ColumnDataWriter::mpCurrentOutputFile [protected] |
Filestream currently being addressed
Definition at line 58 of file ColumnDataWriter.hpp.
Referenced by Close(), CreateFixedDimensionFile(), DoAdvanceAlongUnlimitedDimension(), EndDefineMode(), and PutVariable().
out_stream ColumnDataWriter::mpCurrentAncillaryFile [protected] |
Ancillary filestream currently being addressed (required for two dimensional output) eg. time file
Definition at line 59 of file ColumnDataWriter.hpp.
Referenced by Close(), EndDefineMode(), and PutVariable().
The variable corresponding to the unlimited dimension
Definition at line 60 of file ColumnDataWriter.hpp.
Referenced by DefineUnlimitedDimension(), EndDefineMode(), PutVariable(), and ~ColumnDataWriter().
The variable corresponding to the fixed dimension
Definition at line 61 of file ColumnDataWriter.hpp.
Referenced by CreateFixedDimensionFile(), DefineFixedDimension(), EndDefineMode(), PutVariable(), and ~ColumnDataWriter().
std::string ColumnDataWriter::mUnlimitedDimensionName [protected] |
The name of the unlimited dimension.
Definition at line 63 of file ColumnDataWriter.hpp.
Referenced by DefineUnlimitedDimension(), and DefineVariable().
std::string ColumnDataWriter::mUnlimitedDimensionUnits [protected] |
The physical units of the unlimited dimension.
Definition at line 64 of file ColumnDataWriter.hpp.
Referenced by DefineUnlimitedDimension().
std::string ColumnDataWriter::mFixedDimensionName [protected] |
The name of the fixed dimension
Definition at line 66 of file ColumnDataWriter.hpp.
Referenced by DefineFixedDimension(), and DefineVariable().
std::string ColumnDataWriter::mFixedDimensionUnits [protected] |
The units of the fixed dimension
Definition at line 67 of file ColumnDataWriter.hpp.
Referenced by DefineFixedDimension().
std::vector<DataWriterVariable> ColumnDataWriter::mVariables [protected] |
The data variables
Definition at line 69 of file ColumnDataWriter.hpp.
Referenced by CreateFixedDimensionFile(), CreateInfoFile(), DefineVariable(), EndDefineMode(), and PutVariable().
const int ColumnDataWriter::FIELD_WIDTH = 10 [static, protected] |
Width of each column in the text file (excludes column headers)
Definition at line 71 of file ColumnDataWriter.hpp.
Referenced by CreateFixedDimensionFile(), EndDefineMode(), and PutVariable().
const int ColumnDataWriter::SPACING = 2 [static, protected] |
Space between columns (includes minus sign)
Definition at line 72 of file ColumnDataWriter.hpp.
Referenced by EndDefineMode(), and PutVariable().
const int ColumnDataWriter::FIXED_DIMENSION_VAR_ID = -1 [static, protected] |
id of fixed dimension variable
Definition at line 73 of file ColumnDataWriter.hpp.
Referenced by DefineFixedDimension(), and PutVariable().
const int ColumnDataWriter::UNLIMITED_DIMENSION_VAR_ID = -2 [static, protected] |
id of unlimited dimension variable
Definition at line 74 of file ColumnDataWriter.hpp.
Referenced by DefineUnlimitedDimension(), and PutVariable().
std::string ColumnDataWriter::mFileExtension [protected] |
Extension of output files
Definition at line 76 of file ColumnDataWriter.hpp.
int ColumnDataWriter::mRowStartPosition [protected] |
The position of the file pointer when its at the beginning of the current row
Definition at line 78 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 79 of file ColumnDataWriter.hpp.
Referenced by CreateFixedDimensionFile(), DoAdvanceAlongUnlimitedDimension(), EndDefineMode(), 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 81 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 82 of file ColumnDataWriter.hpp.
Referenced by EndDefineMode().
bool ColumnDataWriter::mHasPutVariable [protected] |
Whether a variable value has been output to a file.
Definition at line 84 of file ColumnDataWriter.hpp.
Referenced by AdvanceAlongUnlimitedDimension(), DoAdvanceAlongUnlimitedDimension(), and PutVariable().
bool ColumnDataWriter::mNeedAdvanceAlongUnlimitedDimension [protected] |
Whether we need to advance along the unlimited dimension.
Definition at line 85 of file ColumnDataWriter.hpp.
Referenced by AdvanceAlongUnlimitedDimension(), DoAdvanceAlongUnlimitedDimension(), and PutVariable().