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...
 

Function Documentation

◆ addCell()

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.

Parameters
[in]rowthe row of the cell.
[in]colthe column of the cell.
[in]cellthe new contents of the cell, will be wrapped.

Definition at line 107 of file textTable.hpp.

References mx::ioutils::textTable::addCell().

◆ outPut()

template<typename iosT >
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.

Template Parameters
iosTis a std::ostream-like type.
Parameters
[in]iosa 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().

◆ readColumns()

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.

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:

std::vector<int> i1;
std::vector<float> f1;
std::vector<double> d1;
readColumns("data_file.txt", i1, f1, d1);
int readColumns(const std::string &fname, arrTs &... arrays)
Read in columns from a text file.

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

readColumns<',', ';', '\r'>("data_file.csv", i1, f1, d1);

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.

Template Parameters
delimis the character separating columns, by default this is space.
commentis the character starting a comment. by default this is #
eolis the end of line character. by default this is
arrTsa variadic list of array types. this is not specified by the user.
Todo:
lineSize should be configurable
Parameters
[in]fnameis the file name to read from
[out]arraysa 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().