Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
update MDAL to 0.4.1
  • Loading branch information
PeterPetrik committed Jan 10, 2020
1 parent 1b920ca commit c9bba3c
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 5 deletions.
2 changes: 1 addition & 1 deletion external/mdal/frmts/mdal_2dm.cpp
Expand Up @@ -98,7 +98,7 @@ bool MDAL::Driver2dm::canRead( const std::string &uri )
{
std::ifstream in( uri, std::ifstream::in );
std::string line;
if ( !std::getline( in, line ) || !startsWith( line, "MESH2D" ) )
if ( !MDAL::getHeaderLine( in, line ) || !startsWith( line, "MESH2D" ) )
{
return false;
}
Expand Down
11 changes: 9 additions & 2 deletions external/mdal/frmts/mdal_ascii_dat.cpp
Expand Up @@ -44,7 +44,7 @@ bool MDAL::DriverAsciiDat::canRead( const std::string &uri )
{
std::ifstream in( uri, std::ifstream::in );
std::string line;
if ( !std::getline( in, line ) )
if ( !MDAL::getHeaderLine( in, line ) )
{
return false;
}
Expand All @@ -57,7 +57,8 @@ bool MDAL::DriverAsciiDat::canReadOldFormat( const std::string &line ) const
{
return MDAL::contains( line, "SCALAR" ) ||
MDAL::contains( line, "VECTOR" ) ||
MDAL::contains( line, "TS" );
MDAL::contains( line, "TS" ) ||
MDAL::contains( line, "TIMEUNITS" );
}

bool MDAL::DriverAsciiDat::canReadNewFormat( const std::string &line ) const
Expand Down Expand Up @@ -85,6 +86,7 @@ void MDAL::DriverAsciiDat::loadOldFormat( std::ifstream &in,
);
group->setIsScalar( !isVector );
group->setIsOnVertices( true );
std::string timeUnits = "hours";

do
{
Expand Down Expand Up @@ -112,9 +114,14 @@ void MDAL::DriverAsciiDat::loadOldFormat( std::ifstream &in,
{
// just ignore - we know the type from earlier...
}
else if ( cardType == "TIMEUNITS" && items.size() >= 2 )
{
timeUnits = items[1];
}
else if ( cardType == "TS" && items.size() >= 2 )
{
double t = toDouble( items[ 1 ] );
t = convertTimeDataToHours( t, timeUnits );
readVertexTimestep( mesh, group, t, isVector, false, in );
}
else
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.0";
return "0.4.1";
}

MDAL_Status MDAL_LastStatus()
Expand Down
18 changes: 17 additions & 1 deletion external/mdal/mdal_utils.cpp
Expand Up @@ -272,18 +272,27 @@ std::string MDAL::replace( const std::string &str, const std::string &substr, co
// http://www.cplusplus.com/faq/sequences/strings/trim/
std::string MDAL::trim( const std::string &s, const std::string &delimiters )
{
if ( s.empty() )
return s;

return ltrim( rtrim( s, delimiters ), delimiters );
}

// http://www.cplusplus.com/faq/sequences/strings/trim/
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 ) );
}

// http://www.cplusplus.com/faq/sequences/strings/trim/
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 );
}

Expand Down Expand Up @@ -625,4 +634,11 @@ std::string MDAL::doubleToString( double value, int precision )
return oss.str();
}


bool MDAL::getHeaderLine( std::ifstream &stream, std::string &line )
{
if ( !stream.is_open() ) return false;
char b[100] = "";
if ( ! stream.get( b, sizeof( b ) - 1, '\n' ) ) return false;
line = std::string( b );
return true;
}
4 changes: 4 additions & 0 deletions external/mdal/mdal_utils.hpp
Expand Up @@ -16,6 +16,7 @@
#include <limits>
#include <sstream>
#include <fstream>

#include <algorithm>

#include "mdal_data_model.hpp"
Expand Down Expand Up @@ -62,6 +63,9 @@ namespace MDAL

std::string toLower( const std::string &std );

//! Get a first line from stream clipped to first 100 characters
bool getHeaderLine( std::ifstream &stream, std::string &line );

/** Return 0 if not possible to convert */
size_t toSizeT( const std::string &str );
size_t toSizeT( const char &str );
Expand Down

0 comments on commit c9bba3c

Please sign in to comment.