TXT Files

namespace mocca

Enable (1) or disable (0, default) the support for the Parallel HDF5 library. Requires a MPI library (e.g., OpenMPI, MPICH, etc.).

namespace io

Functions

template<typename T>
void read_mat_txt(std::string path, Matrix<T> &mat)
template<typename T>
Matrix<T> read_mat_txt(std::string path)

Reads and parses a TXT file and stores the contents in a Matrix. The TXT file must have the following format:

nrows ncols
(0, 0) (0, 1) ... (0, ncols - 1)
(1, 0) (1, 1) ... (1, ncols - 1)
...
(nrows - 1, 0) (nrows - 1, 1) ... (nrows - 1, ncols - 1)

where (i, j) is a matrix entry in the i-th row and j-th column.

Complexity: Linear with the file size.

Parameters:
  • path[in] path to the file

  • mat[out] output Matrix (optional)

Returns:

a Matrix with the contents of the file if mat is not specified. void, otherwise.

template<typename T, internal::TypeLayout L>
void read_vec_txt(std::string path, Vector<T, L> &vec)
template<typename T>
Vector<T> read_vec_txt(std::string path)

Reads and parses a TXT file and stores the contents in a Vector. The TXT file must have the following format:

size
(0)
(1)
...
(size - 1)

where (i) is a vector entry in the i-th position.

Complexity: Linear with the file size.

Parameters:
  • path[in] path of the file

  • vec[out] output Vector (optional)

Returns:

a Vector with the contents of the file if vec is not specified. void, otherwise.

template<typename T, internal::TypeLayout L>
void write_txt(const Vector<T, L> &vec, std::string path)

Writes the content of a Vector into a TXT file with the following format:

size
(0)
(1)
...
(size - 1)

where (i) is a vector entry in the i-th position.

Complexity: Linear in vec.size().

Parameters:
  • vec[in] Vector to use as data source

  • path[in] path to the file

template<typename T>
void write_txt(const Matrix<T> &mat, std::string path)

Write the content of a Matrix into a TXT file with the following format:

nrows ncols
(0, 0) (0, 1) ... (0, ncols - 1)
(1, 0) (1, 1) ... (1, ncols - 1)
...
(nrows - 1, 0) (nrows - 1, 1) ... (nrows - 1, ncols - 1)

where (i, j) is a matrix entry in the i-th row and j-th column.

Complexity: Linear in mat.size().

Parameters:
  • mat[in] Matrix to use as data source

  • path[in] path to the file