Loading...
Searching...
No Matches
mm_io.cc
Go to the documentation of this file.
// matrix market io utilities
# include "rheolef/mm_io.h"
# include <sstream>
using namespace std;
namespace rheolef {
struct matrix_market
read_matrix_market_header (idiststream& ips)
{
struct matrix_market mm;
mm.format = matrix_market::max_format;
if (!ips.do_load()) return mm; // when my_proc is not the io_proc
istream& is = ips.is();
bool already_have_a_spec_line = false;
std::string symmetry;
do {
char c;
is >> std::ws >> c;
if (c != '%') {
// no header: starts directly with sizes
check_macro (isdigit(c), "matrix_market read: not in matrix market format");
is.unget();
break;
}
is >> std::ws >> c;
bool have_a_spec_line = (c == '%');
std::string line;
getline (is, line);
if (have_a_spec_line && ! already_have_a_spec_line) {
std::stringstream spec (line);
std::string head, matrix, type, valued;
// see http://math.nist.gov/MatrixMarket/formats.html
// and http://math.nist.gov/MatrixMarket/reports/MMformat.ps.gz , page 7
spec >> head >> matrix >> type >> valued >> symmetry;
check_macro (head == "MatrixMarket", "matrix_market read: expect `%%MatrixMarket', get `"<<head<<"'");
check_macro (matrix == "matrix", "matrix_market read: unsupported `"<<matrix <<"' extension: only \"matrix\" format yet supported");
check_macro (type == "coordinate", "matrix_market read: unsupported `"<<type <<"': only \"coordinate\" format yet supported");
check_macro (valued == "real", "matrix_market read: unsupported `"<<valued <<"': only \"real\" values yet supported");
already_have_a_spec_line = true;
}
} while (is.good());
// when no header, assume the general format:
if (symmetry == "") symmetry = "general";
if (symmetry == "general") mm.format = matrix_market::general;
else if (symmetry == "symmetric") mm.format = matrix_market::symmetric;
else if (symmetry == "skew-symmetric") mm.format = matrix_market::skew_symmetric;
else if (symmetry == "Hermitian") mm.format = matrix_market::hermitian;
else error_macro ("matrix_market read: unexpected `"<<symmetry <<"' symmetry");
return mm;
}
} // namespace rheolef
rheolef::idiststream
idiststream: see the diststream page for the full documentation
Definition diststream.h:336
error_macro
#define error_macro(message)
Definition dis_macros.h:49
check_macro
check_macro(expr1.have_homogeneous_space(Xh1), "dual(expr1,expr2); expr1 should have homogeneous space. HINT: use dual(interpolate(Xh, expr1),expr2)")
rheolef
This file is part of Rheolef.
Definition compiler_eigen.h:39
rheolef::read_matrix_market_header
struct matrix_market read_matrix_market_header(idiststream &ips)
Definition mm_io.cc:30
std
STL namespace.
rheolef::type
rheolef::matrix_market
Definition mm_io.h:29
rheolef::matrix_market::general
static const format_type general
Definition mm_io.h:32
rheolef::matrix_market::symmetric
static const format_type symmetric
Definition mm_io.h:33
rheolef::matrix_market::skew_symmetric
static const format_type skew_symmetric
Definition mm_io.h:34
rheolef::matrix_market::hermitian
static const format_type hermitian
Definition mm_io.h:35
rheolef::matrix_market::max_format
static const format_type max_format
Definition mm_io.h:36
rheolef::matrix_market::format
format_type format
Definition mm_io.h:37