A high level interface class to read columns of data from an ASCII-file Supports arbitrary delimiter characters and whitespace seperated columns. Comments can begin at any point of a line. An arbitrary string can be used for the beginning of the comment.
ltl::AscFile::AscFile | ( | const string & | fname, | |
const char | delim = 0 , |
|||
const string & | comment = "#" | |||
) |
Constructs an AsciiFile object.
: in_(fname.c_str()), rows_(0), cols_(0), filename_(fname), delim_(delim), comment_(comment)
Constructs an ltl::AscFile object corresponding to the file fname.
ltl::AscFile::AscFile | ( | const string & | fname, | |
const int | b, | |||
int | e = -1 , |
|||
const char | delim = 0 , |
|||
const string & | comment = "#" | |||
) |
virtual ltl::AscFile::~AscFile | ( | ) | [virtual] |
string ltl::AscFile::readColumnFromLine__ | ( | const int | col, | |
const string & | line | |||
) | [protected] |
Internal function to extract one column from a given string.
Extracts the col'th column from the string buff, and returns it as a string.
IOException | if an EOF is encountered before the requested colum was read. | |
IOException | if the file cannot be opened. |
string ltl::AscFile::replaceColumnsInLine__ | ( | const int | col1, | |
const int | col2, | |||
string & | line, | |||
const string & | rep | |||
) | [protected] |
Internal function to replace one column in a line.
bool ltl::AscFile::readNextLine__ | ( | string & | buf | ) | [protected] |
Internal function used to read on line from the file stream.
Reads the next line from the input stream. The input stream is closed between subsequent calls, and the stream position is saved in the variable ltl::AscFile::filepos_.
char* ltl::AscFile::getNextColumn__ | ( | char *& | str | ) | [protected] |
Internal function to fast read the next column in a WS delimited file.
void ltl::AscFile::rewind__ | ( | ) | [protected] |
bool ltl::AscFile::eof__ | ( | ) | [protected] |
void ltl::AscFile::countRows__ | ( | ) | [protected] |
Internal function used to count the number of rows.
Counts the rows in the file. Might be expensive on large files, so the function is not called before the information is requested by calling ltl::AscFile::rows().
void ltl::AscFile::countCols__ | ( | ) | [protected] |
Internal function used to count the number of columns.
Counts the cols in the file. Might be expensive on large files, so the function is not called before the information is requested by calling ltl::AscFile::cols().
MArray<T,1> ltl::AscFile::readSingleCol__ | ( | const int | col, | |
const int | start = 1 , |
|||
int | nrows = -1 | |||
) | [inline, protected] |
MArray<float,1> ltl::AscFile::readSingleFloatCol__ | ( | const int | col, | |
const int | start = 1 , |
|||
int | nrows = -1 | |||
) | [protected] |
MArray<int,1> ltl::AscFile::readSingleIntCol__ | ( | const int | col, | |
const int | start = 1 , |
|||
int | nrows = -1 | |||
) | [protected] |
MArray<T,2> ltl::AscFile::readCols__ | ( | int | first = 0 , |
|
int | last = 0 , |
|||
const int | start = 1 , |
|||
int | nrows = -1 | |||
) | [inline, protected] |
MArray<float,2> ltl::AscFile::readFloatCols__ | ( | int | first = 0 , |
|
int | last = 0 , |
|||
const int | start = 1 , |
|||
int | nrows = -1 | |||
) | [protected] |
MArray<int,2> ltl::AscFile::readIntCols__ | ( | int | first = 0 , |
|
int | last = 0 , |
|||
const int | start = 1 , |
|||
int | nrows = -1 | |||
) | [protected] |
void ltl::AscFile::close | ( | ) | [inline] |
bool ltl::AscFile::readNextLine | ( | string & | buf | ) | [inline] |
void ltl::AscFile::rewind | ( | ) | [inline] |
MArray<int,1> ltl::AscFile::readIntColumn | ( | const int | col, | |
const int | start = 1 , |
|||
int | nrows = -1 | |||
) | throw (IOException) |
MArray<float,1> ltl::AscFile::readFloatColumn | ( | const int | col, | |
const int | start = 1 , |
|||
int | nrows = -1 | |||
) | throw (IOException) |
MArray<double,1> ltl::AscFile::readDoubleColumn | ( | const int | col, | |
const int | start = 1 , |
|||
int | nrows = -1 | |||
) | throw (IOException) |
MArray<int,2> ltl::AscFile::readIntColumns | ( | const int | first = 0 , |
|
const int | last = 0 , |
|||
const int | start = 1 , |
|||
int | nrows = -1 | |||
) | throw (IOException) |
MArray<float,2> ltl::AscFile::readFloatColumns | ( | const int | first = 0 , |
|
const int | last = 0 , |
|||
const int | start = 1 , |
|||
int | nrows = -1 | |||
) | throw (IOException) |
MArray<double,2> ltl::AscFile::readDoubleColumns | ( | const int | first = 0 , |
|
const int | last = 0 , |
|||
const int | start = 1 , |
|||
int | nrows = -1 | |||
) | throw (IOException) |
MArray<float,2> ltl::AscFile::readFloatColumns | ( | const int * | cols, | |
const int | ncols, | |||
const int | start = 1 , |
|||
int | nrows = -1 | |||
) |
read arbitrary list of columns
int ltl::AscFile::getHeader | ( | vector< string > & | , | |
bool | keepcs = false | |||
) |
int ltl::AscFile::rows | ( | ) | throw (IOException) |
High level interface to ltl::AscFile::rows_.
Returns the number of rows in the file.
int ltl::AscFile::cols | ( | ) | throw (IOException) |
High level interface to ltl::AscFile::cols_.
Returns the number of columns in the file
string ltl::AscFile::filename_ [protected] |
The internal storage of the represented file.
fstream ltl::AscFile::in_ [protected] |
The filestream.
streampos ltl::AscFile::begin_ [protected] |
Internal storage of the position of the filestream.
streampos ltl::AscFile::end_ [protected] |
int ltl::AscFile::rows_ [protected] |
Internal storage of the number of rows in the file.
Stores internally the the number of rows in the file. This variable is initialized with 0. The first call to ltl::AscFile::rows() updates the variable with the correct number of rows.
int ltl::AscFile::cols_ [protected] |
Internal storage of the number of columns in the file.
Stores internally the the number of columns in the file. This variable is initialized with 0. The first call to ltl::AscFile::cols() updates the variable with the correct number of columns.
char ltl::AscFile::delim_ [protected] |
Internal storage of delimiter character.
Stores internally the column delimiter. If the set to int(0) then it is assumed, that the columns are whitespace delimited, and any number of whitespace characters is treated as one delimiter.
string ltl::AscFile::comment_ [protected] |
Internal storage of the comment string.
Defaults to '#'.
int ltl::AscFile::currline_ [protected] |
Internal storage of next line to be read.