Skip to content

Commit

Permalink
update to MDAL 0.4.2, regression fix for SWW/Telemac files
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterPetrik committed Feb 20, 2020
1 parent 9fe0ed8 commit 7ff58dd
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 8 deletions.
8 changes: 8 additions & 0 deletions external/mdal/frmts/mdal_netcdf.cpp
Expand Up @@ -144,6 +144,14 @@ double NetCDFFile::getFillValue( int varid ) const
return getAttrDouble( varid, "_FillValue" );
}

bool NetCDFFile::hasAttrDouble( int varid, const std::string &attr_name ) const
{
double res;
if ( nc_get_att_double( mNcid, varid, attr_name.c_str(), &res ) )
return false;
return true;
}

double NetCDFFile::getAttrDouble( int varid, const std::string &attr_name ) const
{
double res;
Expand Down
1 change: 1 addition & 0 deletions external/mdal/frmts/mdal_netcdf.hpp
Expand Up @@ -28,6 +28,7 @@ class NetCDFFile

bool hasAttrInt( const std::string &name, const std::string &attr_name ) const;
int getAttrInt( const std::string &name, const std::string &attr_name ) const;
bool hasAttrDouble( int varid, const std::string &attr_name ) const;
double getAttrDouble( int varid, const std::string &attr_name ) const;
/**
* Get string attribute
Expand Down
8 changes: 6 additions & 2 deletions external/mdal/frmts/mdal_sww.cpp
Expand Up @@ -122,8 +122,12 @@ MDAL::Vertices MDAL::DriverSWW::readVertices( const NetCDFFile &ncFile ) const
std::vector<double> pz = readZCoords( ncFile );

// we may need to apply a shift to the X,Y coordinates
double xLLcorner = ncFile.getAttrDouble( NC_GLOBAL, "xllcorner" );
double yLLcorner = ncFile.getAttrDouble( NC_GLOBAL, "yllcorner" );
double xLLcorner = 0.0;
if ( ncFile.hasAttrDouble( NC_GLOBAL, "xllcorner" ) )
xLLcorner = ncFile.getAttrDouble( NC_GLOBAL, "xllcorner" );
double yLLcorner = 0.0;
if ( ncFile.hasAttrDouble( NC_GLOBAL, "yllcorner" ) )
yLLcorner = ncFile.getAttrDouble( NC_GLOBAL, "yllcorner" );

MDAL::Vertices vertices( nPoints );
Vertex *vertexPtr = vertices.data();
Expand Down
2 changes: 1 addition & 1 deletion external/mdal/mdal.cpp
Expand Up @@ -22,7 +22,7 @@ static MDAL_Status sLastStatus;

const char *MDAL_Version()
{
return "0.4.1";
return "0.4.2";
}

MDAL_Status MDAL_LastStatus()
Expand Down
21 changes: 19 additions & 2 deletions external/mdal/mdal_utils.cpp
Expand Up @@ -284,7 +284,16 @@ std::string MDAL::ltrim( const std::string &s, const std::string &delimiters )
if ( s.empty() )
return s;

return s.substr( s.find_first_not_of( delimiters ) );
size_t found = s.find_first_not_of( delimiters );

if ( found == std::string::npos )
{
return "";
}
else
{
return s.substr( found );
}
}

// http://www.cplusplus.com/faq/sequences/strings/trim/
Expand All @@ -293,7 +302,15 @@ std::string MDAL::rtrim( const std::string &s, const std::string &delimiters )
if ( s.empty() )
return s;

return s.substr( 0, s.find_last_not_of( delimiters ) + 1 );
size_t found = s.find_last_not_of( delimiters );
if ( found == std::string::npos )
{
return "";
}
else
{
return s.substr( 0, found + 1 );
}
}

MDAL::BBox MDAL::computeExtent( const MDAL::Vertices &vertices )
Expand Down
6 changes: 3 additions & 3 deletions external/mdal/mdal_utils.hpp
Expand Up @@ -94,17 +94,17 @@ namespace MDAL
std::string join( const std::vector<std::string> parts, const std::string &delimiter );

//! Right trim
std::string rtrim(
MDAL_TEST_EXPORT std::string rtrim(
const std::string &s,
const std::string &delimiters = " \f\n\r\t\v" );

//! Left trim
std::string ltrim(
MDAL_TEST_EXPORT std::string ltrim(
const std::string &s,
const std::string &delimiters = " \f\n\r\t\v" );

//! Right and left trim
std::string trim(
MDAL_TEST_EXPORT std::string trim(
const std::string &s,
const std::string &delimiters = " \f\n\r\t\v" );

Expand Down

0 comments on commit 7ff58dd

Please sign in to comment.