Skip to content

Commit

Permalink
Make sure mm_reader works on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
ddemidov committed Jul 17, 2021
1 parent eb1f473 commit 681bfc7
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions amgcl/io/mm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,10 @@ namespace io {
class mm_reader {
public:
/// Open the file by name
mm_reader(const std::string &fname) : f(fname.c_str()) {
mm_reader(const std::string &fname) : f(fname) {
precondition(f, "Failed to open file \"" + fname + "\"");

// Read banner.
std::string line;
precondition(std::getline(f, line), format_error());

std::istringstream is(line);
Expand Down Expand Up @@ -99,16 +98,11 @@ class mm_reader {
}

// Skip comments.
std::streampos pos;
do {
pos = f.tellg();
precondition(std::getline(f, line), format_error("unexpected eof"));
} while (line[0] == '%');

// Get back to the first non-comment line.
f.seekg(pos);

// Read matrix size
// The last line is comment-free and holds the matrix sizes
is.clear(); is.str(line);
precondition(is >> nrows >> ncols, format_error());
}
Expand Down Expand Up @@ -156,10 +150,9 @@ class mm_reader {
// Read sizes
ptrdiff_t n, m;
size_t nnz;
std::string line;
std::istringstream is;
{
precondition(std::getline(f, line), format_error("unexpected eof"));
// line already holds the matrix sizes
is.clear(); is.str(line);
precondition(is >> n >> m >> nnz, format_error());
}
Expand Down Expand Up @@ -265,10 +258,9 @@ class mm_reader {

// Read sizes
ptrdiff_t n, m;
std::string line;
std::istringstream is;
{
precondition(std::getline(f, line), format_error("unexpected eof"));
// line already holds the matrix sizes
is.clear(); is.str(line);
precondition(is >> n >> m, format_error());
}
Expand All @@ -295,6 +287,7 @@ class mm_reader {
}
private:
std::ifstream f;
std::string line;

bool _sparse;
bool _symmetric;
Expand Down

0 comments on commit 681bfc7

Please sign in to comment.