Skip to content
Permalink
Browse files

update MDAL to 0.4.1

  • Loading branch information
PeterPetrik committed Jan 9, 2020
1 parent 1b920ca commit c9bba3cecb6759973063927d4500f4622e049220
@@ -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;
}
@@ -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;
}
@@ -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
@@ -85,6 +86,7 @@ void MDAL::DriverAsciiDat::loadOldFormat( std::ifstream &in,
);
group->setIsScalar( !isVector );
group->setIsOnVertices( true );
std::string timeUnits = "hours";

do
{
@@ -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
@@ -22,7 +22,7 @@ static MDAL_Status sLastStatus;

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

MDAL_Status MDAL_LastStatus()
@@ -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 );
}

@@ -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;
}
@@ -16,6 +16,7 @@
#include <limits>
#include <sstream>
#include <fstream>

#include <algorithm>

#include "mdal_data_model.hpp"
@@ -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 );

0 comments on commit c9bba3c

Please sign in to comment.
You can’t perform that action at this time.