From 369ae3ce33bca8f6446cf73fa33bff7dcbcbb571 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Oberhuber?= <oberhuber.tomas@gmail.com> Date: Tue, 10 Dec 2019 22:25:29 +0100 Subject: [PATCH] Fixing MatrixReader. --- src/TNL/Matrices/MatrixReader.h | 2 +- src/TNL/Matrices/MatrixReader_impl.h | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/TNL/Matrices/MatrixReader.h b/src/TNL/Matrices/MatrixReader.h index 2c3cbb4242..ae0606678f 100644 --- a/src/TNL/Matrices/MatrixReader.h +++ b/src/TNL/Matrices/MatrixReader.h @@ -58,7 +58,7 @@ class MatrixReader IndexType& lineNumber ); protected: - static void checkMtxHeader( const String& header, + static bool checkMtxHeader( const String& header, bool& symmetric ); static void readMtxHeader( std::istream& file, diff --git a/src/TNL/Matrices/MatrixReader_impl.h b/src/TNL/Matrices/MatrixReader_impl.h index 25643d8c70..476a7327eb 100644 --- a/src/TNL/Matrices/MatrixReader_impl.h +++ b/src/TNL/Matrices/MatrixReader_impl.h @@ -156,12 +156,12 @@ bool MatrixReader< Matrix >::findLineByElement( std::istream& file, } template< typename Matrix > -void MatrixReader< Matrix >::checkMtxHeader( const String& header, +bool MatrixReader< Matrix >::checkMtxHeader( const String& header, bool& symmetric ) { std::vector< String > parsedLine = header.split( ' ', String::SplitSkip::SkipEmpty ); if( (int) parsedLine.size() < 5 || parsedLine[ 0 ] != "%%MatrixMarket" ) - throw std::runtime_error( "Wrong MTX file header. We expect line like this: %%MatrixMarket matrix coordinate real general" ); + return false; if( parsedLine[ 1 ] != "matrix" ) throw std::runtime_error( std::string( "Keyword 'matrix' is expected in the header line: " ) + header.getString() ); if( parsedLine[ 2 ] != "coordinates" && @@ -176,6 +176,7 @@ void MatrixReader< Matrix >::checkMtxHeader( const String& header, else throw std::runtime_error( std::string( "Only 'general' matrices are supported, not " ) + parsedLine[ 4 ].getString() ); } + return true; } template< typename Matrix > @@ -195,7 +196,7 @@ void MatrixReader< Matrix >::readMtxHeader( std::istream& file, std::getline( file, line ); if( ! headerParsed ) { - checkMtxHeader( line, symmetric ); + headerParsed = checkMtxHeader( line, symmetric ); if( verbose && symmetric ) std::cout << "The matrix is SYMMETRIC ... "; continue; @@ -215,6 +216,7 @@ void MatrixReader< Matrix >::readMtxHeader( std::istream& file, if( rows <= 0 || columns <= 0 ) throw std::runtime_error( "Row or column index is negative." ); + break; } } -- GitLab