mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
|
ASCII input/output
Classes | |
struct | mx::ioutils::skipCol |
A dummy class to allow mx::readColumns to skip a column(s) in a file without requiring memory allocation. More... | |
struct | mx::ioutils::textTable |
An ascii table formatter. More... | |
Files | |
file | readColumns.hpp |
A utility to read in columns from a text file. | |
file | textTable.hpp |
declares and defines a simple text table manager | |
file | textTable.cpp |
implementation for a simple text table manager | |
Functions | |
template<char delim = ' ', char comment = '#', char eol = '\n', typename... arrTs> | |
int | mx::ioutils::readColumns (const std::string &fname, arrTs &... arrays) |
Read in columns from a text file. More... | |
template<typename typeT > | |
void | mx::ioutils::textTable::addCell (size_t row, size_t col, const typeT &cell, int precision=0) |
Add one cell to the table, overwriting if it already exists. More... | |
template<typename iosT > | |
void | mx::ioutils::textTable::outPut (iosT &ios) |
Output the table to a stream. More... | |
void mx::ioutils::textTable::addCell | ( | size_t | row, |
size_t | col, | ||
const typeT & | cell, | ||
int | precision = 0 |
||
) |
Add one cell to the table, overwriting if it already exists.
[in] | row | the row of the cell. |
[in] | col | the column of the cell. |
[in] | cell | the new contents of the cell, will be wrapped. |
Definition at line 107 of file textTable.hpp.
References mx::ioutils::textTable::addCell().
template void mx::ioutils::textTable::outPut< std::ostream > | ( | iosT & | ios | ) |
Output the table to a stream.
Prints the table to the stream, with separators, etc.
iosT | is a std::ostream-like type. |
[in] | ios | a std::ostream-like stream. |
Definition at line 117 of file textTable.hpp.
References mx::astro::constants::k(), mx::ioutils::textTable::m_colSep, mx::ioutils::textTable::m_colWidths, mx::ioutils::textTable::m_lineEnd, mx::ioutils::textTable::m_lineStart, mx::ioutils::textTable::m_rows, and mx::ioutils::textTable::m_rowSep.
Referenced by mx::app::application::help().
int mx::ioutils::readColumns | ( | const std::string & | fname, |
arrTs &... | arrays | ||
) |
Read in columns from a text file.
This function opens a file containing data formatted in columns and reads in the data row by row. The data are stored in std::vectors, which should not be pre-allocated (though they could be reserve()-ed).
Example:
Note that the types of the vectors do not need to be specified as template arguments.
The format of the file can be specified with template arguments like
which sets the delimmiter to comma, the comment character to ;, and the end-of-line to \r.
Columns can be skipped using mx::ioutils::skipCol.
delim | is the character separating columns, by default this is space. |
comment | is the character starting a comment. by default this is # |
eol | is the end of line character. by default this is |
arrTs | a variadic list of array types. this is not specified by the user. |
[in] | fname | is the file name to read from |
[out] | arrays | a variadic list of std::vectors. Any number with mixed value_type can be specified. Neither allocated nor cleared, so repeated calls will append data. |
Definition at line 139 of file readColumns.hpp.
Referenced by mx::improc::ADIobservation< _realT, _derotFunctObj >::injectFake(), mx::improc::HCIobservation< _realT >::load_fileList(), mx::improc::HCIobservation< _realT >::load_RDIfileList(), mx::astro::maintenance::makeMSTable(), mx::improc::HCIobservation< _realT >::readPSFSub(), mx::astro::basicSpectrum< _units >::readSpectrum(), mx::astro::astroFilter< _units, _rsr >::readSpectrum(), mx::astro::calspecSpectrum< _units >::readSpectrum(), mx::astro::picklesSpectrum< _units >::readSpectrum(), mx::astro::earthAlbedo< _units >::readSpectrum(), mx::astro::venusAlbedo< _units >::readSpectrum(), mx::astro::cahoySpectrumRaw< _units >::readSpectrum(), mx::astro::phoenixSpectrum< _units >::readSpectrum(), mx::improc::HCIobservation< _realT >::readWeights(), and mx::improc::HCIobservation< _realT >::threshold().