Rheolef  7.2
an efficient C++ finite element environment
 
Loading...
Searching...
No Matches
mm_io.cc
Go to the documentation of this file.
1
21// matrix market io utilities
22
23# include "rheolef/mm_io.h"
24# include <sstream>
25
26using namespace std;
27namespace rheolef {
28
29struct matrix_market
31{
32 struct matrix_market mm;
34 if (!ips.do_load()) return mm; // when my_proc is not the io_proc
35 istream& is = ips.is();
36 bool already_have_a_spec_line = false;
37 std::string symmetry;
38 do {
39 char c;
40 is >> std::ws >> c;
41 if (c != '%') {
42 // no header: starts directly with sizes
43 check_macro (isdigit(c), "matrix_market read: not in matrix market format");
44 is.unget();
45 break;
46 }
47 is >> std::ws >> c;
48 bool have_a_spec_line = (c == '%');
49 std::string line;
50 getline (is, line);
51 if (have_a_spec_line && ! already_have_a_spec_line) {
52 std::stringstream spec (line);
53 std::string head, matrix, type, valued;
54 // see http://math.nist.gov/MatrixMarket/formats.html
55 // and http://math.nist.gov/MatrixMarket/reports/MMformat.ps.gz , page 7
56 spec >> head >> matrix >> type >> valued >> symmetry;
57 check_macro (head == "MatrixMarket", "matrix_market read: expect `%%MatrixMarket', get `"<<head<<"'");
58 check_macro (matrix == "matrix", "matrix_market read: unsupported `"<<matrix <<"' extension: only \"matrix\" format yet supported");
59 check_macro (type == "coordinate", "matrix_market read: unsupported `"<<type <<"': only \"coordinate\" format yet supported");
60 check_macro (valued == "real", "matrix_market read: unsupported `"<<valued <<"': only \"real\" values yet supported");
61 already_have_a_spec_line = true;
62 }
63 } while (is.good());
64 // when no header, assume the general format:
65 if (symmetry == "") symmetry = "general";
66 if (symmetry == "general") mm.format = matrix_market::general;
67 else if (symmetry == "symmetric") mm.format = matrix_market::symmetric;
68 else if (symmetry == "skew-symmetric") mm.format = matrix_market::skew_symmetric;
69 else if (symmetry == "Hermitian") mm.format = matrix_market::hermitian;
70 else error_macro ("matrix_market read: unexpected `"<<symmetry <<"' symmetry");
71 return mm;
72}
73
74} // namespace rheolef
idiststream: see the diststream page for the full documentation
Definition diststream.h:336
#define error_macro(message)
Definition dis_macros.h:49
check_macro(expr1.have_homogeneous_space(Xh1), "dual(expr1,expr2); expr1 should have homogeneous space. HINT: use dual(interpolate(Xh, expr1),expr2)")
verbose clean transpose logscale grid shrink ball stereo iso volume skipvtk deformation fastfieldload lattice reader_on_stdin color format format format format format format format format format format format format format matrix_market
This file is part of Rheolef.
struct matrix_market read_matrix_market_header(idiststream &ips)
Definition mm_io.cc:30
STL namespace.
static const format_type general
Definition mm_io.h:32
static const format_type symmetric
Definition mm_io.h:33
static const format_type skew_symmetric
Definition mm_io.h:34
static const format_type hermitian
Definition mm_io.h:35
static const format_type max_format
Definition mm_io.h:36
format_type format
Definition mm_io.h:37