Chaste Release::3.1
|
#include <ColumnDataReader.hpp>
Public Member Functions | |
ColumnDataReader (const std::string &rDirectory, const std::string &rBaseName, bool makeAbsolute=true) | |
ColumnDataReader (const FileFinder &rDirectory, const std::string &rBaseName) | |
std::vector< double > | GetValues (const std::string &rVariableName) |
std::vector< double > | GetValues (const std::string &rVariableName, int fixedDimension) |
std::vector< double > | GetUnlimitedDimensionValues () |
bool | HasValues (const std::string &rVariableName) |
unsigned | GetFieldWidth () |
Private Member Functions | |
void | PushColumnEntryFromLine (const std::string &rLine, int col) |
void | ReadColumnFromFile (const std::string &rFilename, int col) |
void | ReadValueFromFile (const std::string &rFilename, int col, int row) |
void | CheckFiles (const std::string &rDirectory, const std::string &rBaseName) |
Private Attributes | |
std::map< std::string, int > | mVariablesToColumns |
std::map< std::string, std::string > | mVariablesToUnits |
int | mNumFixedDimensions |
bool | mHasUnlimitedDimension |
int | mNumVariables |
std::string | mInfoFilename |
std::string | mDataFilename |
std::string | mAncillaryFilename |
std::vector< double > | mValues |
unsigned | mFieldWidth |
Static Private Attributes | |
static const int | SPACING = 2 |
A concrete column data reader class.
Definition at line 50 of file ColumnDataReader.hpp.
ColumnDataReader::ColumnDataReader | ( | const std::string & | rDirectory, |
const std::string & | rBaseName, | ||
bool | makeAbsolute = true |
||
) |
Read data from the given files into memory. The files should be formatted as if written by ColumnDataWriter, with fixed width columns (except for the header line) and fields in scientific notation.
This will attempt to determine the field width from the input file. However, it needs some data to work with in order to do so. Provided at least one correctly formatted entry exists, it will be able to determine the field width, assuming that space is allowed for 3 digits in the exponent. Release 1.1 and earlier of Chaste only allowed 2 digits for the exponent; we can cope with this provided that the first data entry in the file has another entry immediately to the right of it.
rDirectory | The directory the files are stored in |
rBaseName | The base name of the files to read (i.e. without the extensions) |
makeAbsolute | Whether to convert directory to an absolute path using the OutputFileHandler (defaults to true) |
Definition at line 59 of file ColumnDataReader.cpp.
References CheckFiles(), and OutputFileHandler::GetOutputDirectoryFullPath().
ColumnDataReader::ColumnDataReader | ( | const FileFinder & | rDirectory, |
const std::string & | rBaseName | ||
) |
Alternative constructor using FileFinder to specify the directory files are stored in.
rDirectory | The directory the files are stored in |
rBaseName | The base name of the files to read (i.e. without the extensions) |
Definition at line 81 of file ColumnDataReader.cpp.
References CheckFiles(), EXCEPTION, FileFinder::Exists(), FileFinder::GetAbsolutePath(), and FileFinder::IsDir().
void ColumnDataReader::CheckFiles | ( | const std::string & | rDirectory, |
const std::string & | rBaseName | ||
) | [private] |
Set up internal data structures based on file structure, checking that they contain data in roughly the expected format.
rDirectory | Absolute path of the directory the files are stored in |
rBaseName | The base name of the files to read (i.e. without the extensions) |
Definition at line 91 of file ColumnDataReader.cpp.
References EXCEPTION, FILE_SUFFIX_WIDTH, mAncillaryFilename, mDataFilename, mFieldWidth, mHasUnlimitedDimension, mInfoFilename, mNumFixedDimensions, mNumVariables, mVariablesToColumns, mVariablesToUnits, NOT_READ, and SPACING.
Referenced by ColumnDataReader().
unsigned ColumnDataReader::GetFieldWidth | ( | ) |
Get the field width (the number of characters (excl. preceding '+' or '-') printed for each data entry in the file).
Definition at line 409 of file ColumnDataReader.cpp.
References mFieldWidth.
std::vector< double > ColumnDataReader::GetUnlimitedDimensionValues | ( | ) |
Get the entries for a given variable with unlimited dimension.
Definition at line 322 of file ColumnDataReader.cpp.
References EXCEPTION, mAncillaryFilename, mDataFilename, mHasUnlimitedDimension, mNumFixedDimensions, mValues, and ReadColumnFromFile().
std::vector< double > ColumnDataReader::GetValues | ( | const std::string & | rVariableName | ) | [virtual] |
Get the entries for a given variable.
rVariableName |
Implements AbstractDataReader.
Definition at line 244 of file ColumnDataReader.cpp.
References EXCEPTION, mDataFilename, mNumFixedDimensions, mValues, mVariablesToColumns, and ReadColumnFromFile().
std::vector< double > ColumnDataReader::GetValues | ( | const std::string & | rVariableName, |
int | fixedDimension | ||
) | [virtual] |
Get the entries for a given variable with fixed dimension.
rVariableName | |
fixedDimension |
Implements AbstractDataReader.
Definition at line 265 of file ColumnDataReader.cpp.
References EXCEPTION, FILE_SUFFIX_WIDTH, mDataFilename, mHasUnlimitedDimension, mNumFixedDimensions, mValues, mVariablesToColumns, and ReadValueFromFile().
bool ColumnDataReader::HasValues | ( | const std::string & | rVariableName | ) |
Determine whether the data file has entries for a given variable.
rVariableName |
Definition at line 403 of file ColumnDataReader.cpp.
References mVariablesToColumns.
void ColumnDataReader::PushColumnEntryFromLine | ( | const std::string & | rLine, |
int | col | ||
) | [private] |
Push back an entry from the data file into mValues.
rLine | the line of the data file |
col | the column number |
Definition at line 388 of file ColumnDataReader.cpp.
References mFieldWidth, mValues, and SPACING.
Referenced by ReadColumnFromFile(), and ReadValueFromFile().
void ColumnDataReader::ReadColumnFromFile | ( | const std::string & | rFilename, |
int | col | ||
) | [private] |
Read in a given column from a data file into mValues.
rFilename | the file name |
col | the column number |
Definition at line 362 of file ColumnDataReader.cpp.
References mValues, and PushColumnEntryFromLine().
Referenced by GetUnlimitedDimensionValues(), and GetValues().
void ColumnDataReader::ReadValueFromFile | ( | const std::string & | rFilename, |
int | col, | ||
int | row | ||
) | [private] |
Push back an entry from a file into mValues.
rFilename | the file name |
col | the column number |
row | the row number |
Definition at line 342 of file ColumnDataReader.cpp.
References EXCEPTION, and PushColumnEntryFromLine().
Referenced by GetValues().
std::string ColumnDataReader::mAncillaryFilename [private] |
The name of the ancillary file.
Definition at line 61 of file ColumnDataReader.hpp.
Referenced by CheckFiles(), and GetUnlimitedDimensionValues().
std::string ColumnDataReader::mDataFilename [private] |
The name of the data file.
Definition at line 60 of file ColumnDataReader.hpp.
Referenced by CheckFiles(), GetUnlimitedDimensionValues(), and GetValues().
unsigned ColumnDataReader::mFieldWidth [private] |
Width of each column in the text file (excludes column headers). Determined from the first data entry
Definition at line 63 of file ColumnDataReader.hpp.
Referenced by CheckFiles(), GetFieldWidth(), and PushColumnEntryFromLine().
bool ColumnDataReader::mHasUnlimitedDimension [private] |
Whether the data file has an unlimited dimension.
Definition at line 57 of file ColumnDataReader.hpp.
Referenced by CheckFiles(), GetUnlimitedDimensionValues(), and GetValues().
std::string ColumnDataReader::mInfoFilename [private] |
The name of the info file.
Definition at line 59 of file ColumnDataReader.hpp.
Referenced by CheckFiles().
int ColumnDataReader::mNumFixedDimensions [private] |
The number of fixed dimensions in data file.
Definition at line 56 of file ColumnDataReader.hpp.
Referenced by CheckFiles(), GetUnlimitedDimensionValues(), and GetValues().
int ColumnDataReader::mNumVariables [private] |
The number of variables in the data file.
Definition at line 58 of file ColumnDataReader.hpp.
Referenced by CheckFiles().
std::vector<double> ColumnDataReader::mValues [private] |
Vector to hold values for a variable.
Definition at line 62 of file ColumnDataReader.hpp.
Referenced by GetUnlimitedDimensionValues(), GetValues(), PushColumnEntryFromLine(), and ReadColumnFromFile().
std::map<std::string, int> ColumnDataReader::mVariablesToColumns [private] |
Map between variable names and data column numbers.
Definition at line 54 of file ColumnDataReader.hpp.
Referenced by CheckFiles(), GetValues(), and HasValues().
std::map<std::string, std::string> ColumnDataReader::mVariablesToUnits [private] |
Map between variable names and variable units.
Definition at line 55 of file ColumnDataReader.hpp.
Referenced by CheckFiles().
const int ColumnDataReader::SPACING = 2 [static, private] |
Space between columns (includes minus sign)
Definition at line 64 of file ColumnDataReader.hpp.
Referenced by CheckFiles(), and PushColumnEntryFromLine().