GWOLLUM
4.2.0
Tools for gravitational-wave analyses
|
Parse text files with columns. More...
#include <ReadAscii.h>
Public Member Functions | |
bool | GetCol (vector< double > &col, const unsigned int co) |
Returns the content of a double column in a vector. More... | |
bool | GetCol (vector< int > &col, const unsigned int co) |
Returns the content of an integer column in a vector. More... | |
bool | GetCol (vector< string > &col, const unsigned int co) |
Returns the content of a string column in a vector. More... | |
bool | GetCol (vector< unsigned int > &col, const unsigned int co) |
Returns the content of an unsigned integer column in a vector. More... | |
bool | GetElement (double &element, const unsigned int li, const unsigned int co) |
Returns the double data value at a given line and column position. More... | |
bool | GetElement (int &element, const unsigned int li, const unsigned int co) |
Returns the integer data value at a given line and column position. More... | |
bool | GetElement (string &element, const unsigned int li, const unsigned int co) |
Returns the string data value at a given line and column position. More... | |
bool | GetElement (unsigned int &element, const unsigned int li, const unsigned int co) |
Returns the unsigned integer data value at a given line and column position. More... | |
bool | GetLine (string &line, const unsigned int li) |
Returns the content of a line as a string. More... | |
unsigned int | GetNCol (void) |
Returns the number of columns. More... | |
unsigned int | GetNLine (void) |
Returns the number of rows/lines. More... | |
unsigned int | GetNRow (void) |
Returns the number of rows/lines. More... | |
bool | SetFormat (const unsigned int co, const char aformat) |
Defines a new column format ('s', 'd', 'u' or 'i'). More... | |
Constructors and destructors | |
ReadAscii (const string afilename, const string aformat="UNKNOWN") | |
Constructor of the ReadAscii class. More... | |
virtual | ~ReadAscii (void) |
Destructor of the ReadAscii class. More... | |
Private Member Functions | |
void | ExtractCol (void) |
Extract columns. More... | |
void | ExtractFormat (void) |
Extract format vector. More... | |
void | ExtractLines (void) |
Extract lines. More... | |
void | GetMinMax (const unsigned int co) |
Extract min/max values. More... | |
Private Attributes | |
double | colmax [NCOLMAX] |
Maximum in a given column. More... | |
double | colmin [NCOLMAX] |
Minimum in a given column. More... | |
vector< double > | dcol [NCOLMAX] |
Column of double. More... | |
string | ffilename |
Input file name. More... | |
string | fformat |
Input format string. More... | |
vector< int > | icol [NCOLMAX] |
Column of int. More... | |
vector< string > | mylines |
Lines of the files. More... | |
vector< string > | scol [NCOLMAX] |
Column of string. More... | |
vector< unsigned int > | ucol [NCOLMAX] |
Column of unsigned int. More... | |
vector< string > | Vformat |
Vector of formats. More... | |
Parse text files with columns.
Many operations are then available to access and modify the data elements.
ReadAscii::ReadAscii | ( | const string | afilename, |
const string | aformat = "UNKNOWN" |
||
) |
Constructor of the ReadAscii class.
With this constructor, the text file is loaded and data are extracted.
This example means that the text file is composed of 4 columns, the 2 first ones are string fields and the 2 last ones are integer fields.
If the input format is unknown, 'aformat' should be set to "UNKNOWN" which it is by default. In that case, all columns are assumed to have a string format. This default format can be changed later on by using the SetFormat() function.
Lines with a wrong number of columns (as defined by aformat or by the first line) are skipped.
[in] | afilename | Path to the text file. |
[in] | aformat | String format to be expected in the file. |
|
virtual |
Destructor of the ReadAscii class.
|
private |
Extract columns.
|
private |
Extract format vector.
|
private |
Extract lines.
bool ReadAscii::GetCol | ( | vector< double > & | col, |
const unsigned int | co | ||
) |
Returns the content of a double column in a vector.
true is returned in case of success.
[out] | col | Returned vector of double data. |
[in] | co | Selected column number (indexing starts at 0). |
bool ReadAscii::GetCol | ( | vector< int > & | col, |
const unsigned int | co | ||
) |
Returns the content of an integer column in a vector.
true is returned in case of success.
[out] | col | Returned vector of integer data. |
[in] | co | Selected column number (indexing starts at 0). |
bool ReadAscii::GetCol | ( | vector< string > & | col, |
const unsigned int | co | ||
) |
Returns the content of a string column in a vector.
true is returned in case of success.
[out] | col | Returned vector of string data. |
[in] | co | Selected column number (indexing starts at 0). |
bool ReadAscii::GetCol | ( | vector< unsigned int > & | col, |
const unsigned int | co | ||
) |
Returns the content of an unsigned integer column in a vector.
true is returned in case of success.
[out] | col | Returned vector of integer data. |
[in] | co | Selected column number (indexing starts at 0). |
bool ReadAscii::GetElement | ( | double & | element, |
const unsigned int | li, | ||
const unsigned int | co | ||
) |
Returns the double data value at a given line and column position.
true is returned in case of success.
[out] | element | Returned data value. |
[in] | co | Selected column number (indexing starts at 0). |
[in] | li | Selected line number (indexing starts at 0). |
bool ReadAscii::GetElement | ( | int & | element, |
const unsigned int | li, | ||
const unsigned int | co | ||
) |
Returns the integer data value at a given line and column position.
true is returned in case of success.
[out] | element | Returned data value. |
[in] | co | Selected column number (indexing starts at 0). |
[in] | li | Selected line number (indexing starts at 0). |
bool ReadAscii::GetElement | ( | string & | element, |
const unsigned int | li, | ||
const unsigned int | co | ||
) |
Returns the string data value at a given line and column position.
true is returned in case of success.
[out] | element | Returned data value. |
[in] | co | Selected column number (indexing starts at 0). |
[in] | li | Selected line number (indexing starts at 0). |
bool ReadAscii::GetElement | ( | unsigned int & | element, |
const unsigned int | li, | ||
const unsigned int | co | ||
) |
Returns the unsigned integer data value at a given line and column position.
true is returned in case of success.
[out] | element | Returned data value. |
[in] | co | Selected column number (indexing starts at 0). |
[in] | li | Selected line number (indexing starts at 0). |
bool ReadAscii::GetLine | ( | string & | line, |
const unsigned int | li | ||
) |
Returns the content of a line as a string.
true is returned in case of success.
[out] | line | Returned line. |
[in] | li | Selected line number (indexing starts at 0). |
|
private |
Extract min/max values.
|
inline |
Returns the number of columns.
|
inline |
Returns the number of rows/lines.
|
inline |
Returns the number of rows/lines.
bool ReadAscii::SetFormat | ( | const unsigned int | co, |
const char | aformat | ||
) |
Defines a new column format ('s', 'd', 'u' or 'i').
The selected column is converted to a new format. Only one conversion is destructive: 'd' to 'i/u'. In that case, the doubles are recasted as integers. true is returned in case of success.
[in] | co | Selected column number (indexing starts at 0). |
[in] | aformat | char new format ('s', 'd'. 'u' or 'i'). |
|
private |
Maximum in a given column.
|
private |
Minimum in a given column.
|
private |
Column of double.
|
private |
Input file name.
|
private |
Input format string.
|
private |
Column of int.
|
private |
Lines of the files.
|
private |
Column of string.
|
private |
Column of unsigned int.
|
private |
Vector of formats.