From f33ebc810056788d59476c414ba7fb4d1c033484 Mon Sep 17 00:00:00 2001 From: Peter Petrik Date: Mon, 27 May 2019 13:15:59 +0200 Subject: [PATCH] update to MDAL 0.3.3 --- external/mdal/frmts/mdal_flo2d.cpp | 51 +++++++++++------------------- external/mdal/frmts/mdal_flo2d.hpp | 2 +- external/mdal/mdal.cpp | 2 +- external/mdal/mdal_utils.cpp | 6 ---- external/mdal/mdal_utils.hpp | 1 - 5 files changed, 21 insertions(+), 41 deletions(-) diff --git a/external/mdal/frmts/mdal_flo2d.cpp b/external/mdal/frmts/mdal_flo2d.cpp index 96c954821c4..75c55734e30 100644 --- a/external/mdal/frmts/mdal_flo2d.cpp +++ b/external/mdal/frmts/mdal_flo2d.cpp @@ -34,11 +34,6 @@ struct VertexCompare } }; -static inline bool is_nodata( double val ) -{ - return MDAL::equals( val, -9999.0, 1e-8 ); -} - static std::string fileNameFromDir( const std::string &mainFileName, const std::string &name ) { std::string dir = MDAL::dirName( mainFileName ); @@ -47,7 +42,7 @@ static std::string fileNameFromDir( const std::string &mainFileName, const std:: static double getDouble( double val ) { - if ( is_nodata( val ) ) + if ( MDAL::equals( val, 0.0, 1e-8 ) ) { return MDAL_NAN; } @@ -59,19 +54,11 @@ static double getDouble( double val ) static double getDouble( const std::string &val ) { - if ( MDAL::isNumber( val ) ) - { - double valF = MDAL::toDouble( val ); - return getDouble( valF ); - } - else - { - return MDAL_NAN; - } + double valF = MDAL::toDouble( val ); + return getDouble( valF ); } void MDAL::DriverFlo2D::addStaticDataset( - bool isOnVertices, std::vector &vals, const std::string &groupName, const std::string &datFileName ) @@ -82,7 +69,7 @@ void MDAL::DriverFlo2D::addStaticDataset( datFileName, groupName ); - group->setIsOnVertices( isOnVertices ); + group->setIsOnVertices( false ); group->setIsScalar( true ); std::shared_ptr dataset = std::make_shared< MemoryDataset >( group.get() ); @@ -257,7 +244,7 @@ void MDAL::DriverFlo2D::parseTIMDEPFile( const std::string &datFileName, const s double depth = getDouble( lineParts[1] ); depthDataset->values()[face_idx] = depth; - if ( !is_nodata( depth ) ) depth += elevations[face_idx]; + if ( !std::isnan( depth ) ) depth += elevations[face_idx]; waterLevelDataset->values()[face_idx] = depth; face_idx ++; @@ -295,9 +282,9 @@ void MDAL::DriverFlo2D::parseDEPTHFile( const std::string &datFileName, const st std::ifstream depthStream( depthFile, std::ifstream::in ); std::string line; - size_t nVertices = mMesh->verticesCount(); - std::vector maxDepth( nVertices ); - std::vector maxWaterLevel( nVertices ); + size_t nFaces = mMesh->facesCount(); + std::vector maxDepth( nFaces ); + std::vector maxWaterLevel( nFaces ); size_t vertex_idx = 0; @@ -305,7 +292,7 @@ void MDAL::DriverFlo2D::parseDEPTHFile( const std::string &datFileName, const st while ( std::getline( depthStream, line ) ) { line = MDAL::rtrim( line ); - if ( vertex_idx == nVertices ) throw MDAL_Status::Err_IncompatibleMesh; + if ( vertex_idx == nFaces ) throw MDAL_Status::Err_IncompatibleMesh; std::vector lineParts = MDAL::split( line, ' ' ); if ( lineParts.size() != 4 ) @@ -317,23 +304,23 @@ void MDAL::DriverFlo2D::parseDEPTHFile( const std::string &datFileName, const st maxDepth[vertex_idx] = val; //water level - if ( !is_nodata( val ) ) val += elevations[vertex_idx]; + if ( !std::isnan( val ) ) val += elevations[vertex_idx]; maxWaterLevel[vertex_idx] = val; vertex_idx++; } - addStaticDataset( true, maxDepth, "Depth/Maximums", datFileName ); - addStaticDataset( true, maxWaterLevel, "Water Level/Maximums", datFileName ); + addStaticDataset( maxDepth, "Depth/Maximums", datFileName ); + addStaticDataset( maxWaterLevel, "Water Level/Maximums", datFileName ); } void MDAL::DriverFlo2D::parseVELFPVELOCFile( const std::string &datFileName ) { // these files are optional, so if not present, reading is skipped - size_t nVertices = mMesh->verticesCount(); - std::vector maxVel( nVertices ); + size_t nFaces = mMesh->facesCount(); + std::vector maxVel( nFaces ); { std::string velocityFile( fileNameFromDir( datFileName, "VELFP.OUT" ) ); @@ -350,7 +337,7 @@ void MDAL::DriverFlo2D::parseVELFPVELOCFile( const std::string &datFileName ) // VELFP.OUT - COORDINATES (ELEM NUM, X, Y, MAX VEL) - Maximum floodplain flow velocity; while ( std::getline( velocityStream, line ) ) { - if ( vertex_idx == nVertices ) throw MDAL_Status::Err_IncompatibleMesh; + if ( vertex_idx == nFaces ) throw MDAL_Status::Err_IncompatibleMesh; line = MDAL::rtrim( line ); std::vector lineParts = MDAL::split( line, ' ' ); @@ -381,7 +368,7 @@ void MDAL::DriverFlo2D::parseVELFPVELOCFile( const std::string &datFileName ) // VELOC.OUT - COORDINATES (ELEM NUM, X, Y, MAX VEL) - Maximum channel flow velocity while ( std::getline( velocityStream, line ) ) { - if ( vertex_idx == nVertices ) throw MDAL_Status::Err_IncompatibleMesh; + if ( vertex_idx == nFaces ) throw MDAL_Status::Err_IncompatibleMesh; line = MDAL::rtrim( line ); std::vector lineParts = MDAL::split( line, ' ' ); @@ -391,7 +378,7 @@ void MDAL::DriverFlo2D::parseVELFPVELOCFile( const std::string &datFileName ) } double val = getDouble( lineParts[3] ); - if ( !is_nodata( val ) ) // overwrite value from VELFP if it is not 0 + if ( !std::isnan( val ) ) // overwrite value from VELFP if it is not 0 { maxVel[vertex_idx] = val; } @@ -400,7 +387,7 @@ void MDAL::DriverFlo2D::parseVELFPVELOCFile( const std::string &datFileName ) } } - addStaticDataset( true, maxVel, "Velocity/Maximums", datFileName ); + addStaticDataset( maxVel, "Velocity/Maximums", datFileName ); } double MDAL::DriverFlo2D::calcCellSize( const std::vector &cells ) @@ -671,7 +658,7 @@ std::unique_ptr< MDAL::Mesh > MDAL::DriverFlo2D::load( const std::string &result createMesh( cells, cell_size / 2.0 ); // create output for bed elevation - addStaticDataset( false, elevations, "Bed Elevation", mDatFileName ); + addStaticDataset( elevations, "Bed Elevation", mDatFileName ); if ( parseHDF5Datasets( mDatFileName ) ) { diff --git a/external/mdal/frmts/mdal_flo2d.hpp b/external/mdal/frmts/mdal_flo2d.hpp index a7b0c50b286..69a3fc85860 100644 --- a/external/mdal/frmts/mdal_flo2d.hpp +++ b/external/mdal/frmts/mdal_flo2d.hpp @@ -45,7 +45,7 @@ namespace MDAL void parseTIMDEPFile( const std::string &datFileName, const std::vector &elevations ); void parseFPLAINFile( std::vector &elevations, const std::string &datFileName, std::vector &cells ); void parseCADPTSFile( const std::string &datFileName, std::vector &cells ); - void addStaticDataset( bool isOnVertices, std::vector &vals, const std::string &groupName, const std::string &datFileName ); + void addStaticDataset( std::vector &vals, const std::string &groupName, const std::string &datFileName ); static MDAL::Vertex createVertex( size_t position, double half_cell_size, const CellCenter &cell ); static double calcCellSize( const std::vector &cells ); }; diff --git a/external/mdal/mdal.cpp b/external/mdal/mdal.cpp index 3ae05117d65..35410d1d856 100644 --- a/external/mdal/mdal.cpp +++ b/external/mdal/mdal.cpp @@ -22,7 +22,7 @@ static MDAL_Status sLastStatus; const char *MDAL_Version() { - return "0.3.2"; + return "0.3.3"; } MDAL_Status MDAL_LastStatus() diff --git a/external/mdal/mdal_utils.cpp b/external/mdal/mdal_utils.cpp index f387a66b21c..e1f0938c341 100644 --- a/external/mdal/mdal_utils.cpp +++ b/external/mdal/mdal_utils.cpp @@ -113,12 +113,6 @@ double MDAL::toDouble( const std::string &str ) return atof( str.c_str() ); } -bool MDAL::isNumber( const std::string &str ) -{ - // https://stackoverflow.com/a/16465826/2838364 - return ( strspn( str.c_str(), "-.0123456789" ) == str.size() ); -} - int MDAL::toInt( const std::string &str ) { return atoi( str.c_str() ); diff --git a/external/mdal/mdal_utils.hpp b/external/mdal/mdal_utils.hpp index 5524abcae5c..4ef88474333 100644 --- a/external/mdal/mdal_utils.hpp +++ b/external/mdal/mdal_utils.hpp @@ -65,7 +65,6 @@ namespace MDAL int toInt( const std::string &str ); double toDouble( const std::string &str ); bool toBool( const std::string &str ); - bool isNumber( const std::string &str ); /** * Splits by deliminer and skips empty parts.