Navigation Menu

Skip to content

Commit

Permalink
update MDAL to 0.4.94
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterPetrik committed Jan 15, 2020
1 parent 51c2f0f commit a2a8097
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 10 deletions.
2 changes: 1 addition & 1 deletion external/mdal/frmts/mdal_2dm.cpp
Expand Up @@ -98,7 +98,7 @@ bool MDAL::Driver2dm::canReadMesh( 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
13 changes: 9 additions & 4 deletions external/mdal/frmts/mdal_ascii_dat.cpp
Expand Up @@ -44,7 +44,7 @@ bool MDAL::DriverAsciiDat::canReadDatasets( 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,7 +86,7 @@ void MDAL::DriverAsciiDat::loadOldFormat( std::ifstream &in,
);
group->setIsScalar( !isVector );
group->setDataLocation( MDAL_DataLocation::DataOnVertices2D );

MDAL::RelativeTimestamp::Unit timeUnits = MDAL::RelativeTimestamp::hours;
do
{
// Replace tabs by spaces,
Expand Down Expand Up @@ -114,10 +115,14 @@ void MDAL::DriverAsciiDat::loadOldFormat( std::ifstream &in,
{
// just ignore - we know the type from earlier...
}
else if ( cardType == "TIMEUNITS" && items.size() >= 2 )
{
timeUnits = MDAL::parseDurationTimeUnit( items[1] );
}
else if ( cardType == "TS" && items.size() >= 2 )
{
double rawTime = toDouble( items[ 1 ] );
MDAL::RelativeTimestamp t( rawTime, MDAL::RelativeTimestamp::hours );
MDAL::RelativeTimestamp t( rawTime, timeUnits );
readVertexTimestep( mesh, group, t, isVector, false, in );
}
else
Expand Down
4 changes: 4 additions & 0 deletions external/mdal/frmts/mdal_gdal.cpp
Expand Up @@ -628,6 +628,7 @@ void MDAL::DriverGdal::parseBandIsVector( std::string &band_name, bool *is_vecto
MDAL::contains( band_name, "u-component", MDAL::CaseInsensitive ) ||
MDAL::contains( band_name, "u component", MDAL::CaseInsensitive ) ||
MDAL::contains( band_name, "U wind component", MDAL::CaseInsensitive ) ||
MDAL::startsWith( band_name, "Northward", MDAL::CaseInsensitive ) ||
MDAL::contains( band_name, "x-component", MDAL::CaseInsensitive ) ||
MDAL::contains( band_name, "x component", MDAL::CaseInsensitive ) )
{
Expand All @@ -639,6 +640,7 @@ void MDAL::DriverGdal::parseBandIsVector( std::string &band_name, bool *is_vecto
MDAL::contains( band_name, "v-component", MDAL::CaseInsensitive ) ||
MDAL::contains( band_name, "v component", MDAL::CaseInsensitive ) ||
MDAL::contains( band_name, "V wind component", MDAL::CaseInsensitive ) ||
MDAL::startsWith( band_name, "Eastward", MDAL::CaseInsensitive ) ||
MDAL::contains( band_name, "y-component", MDAL::CaseInsensitive ) ||
MDAL::contains( band_name, "y component", MDAL::CaseInsensitive ) )
{
Expand All @@ -657,6 +659,8 @@ void MDAL::DriverGdal::parseBandIsVector( std::string &band_name, bool *is_vecto
band_name = MDAL::replace( band_name, "v-component of", "", MDAL::CaseInsensitive );
band_name = MDAL::replace( band_name, "U wind component", "wind", MDAL::CaseInsensitive );
band_name = MDAL::replace( band_name, "V wind component", "wind", MDAL::CaseInsensitive );
band_name = MDAL::replace( band_name, "Northward", "", MDAL::CaseInsensitive );
band_name = MDAL::replace( band_name, "Eastward", "", MDAL::CaseInsensitive );
band_name = MDAL::replace( band_name, "x-component of", "", MDAL::CaseInsensitive );
band_name = MDAL::replace( band_name, "y-component of", "", MDAL::CaseInsensitive );
band_name = MDAL::replace( band_name, "u-component", "", MDAL::CaseInsensitive );
Expand Down
2 changes: 1 addition & 1 deletion external/mdal/frmts/mdal_gdal_grib.cpp
Expand Up @@ -30,7 +30,7 @@ bool MDAL::DriverGdalGrib::parseBandInfo( const MDAL::GdalDataset *cfGDALDataset
MDAL::RelativeTimestamp *time, bool *is_vector, bool *is_x
)
{
MDAL_UNUSED( cfGDALDataset );
MDAL_UNUSED( cfGDALDataset )

metadata_hash::const_iterator iter;

Expand Down
2 changes: 1 addition & 1 deletion external/mdal/frmts/mdal_tuflowfv.cpp
Expand Up @@ -457,7 +457,7 @@ void MDAL::DriverTuflowFV::parseNetCDFVariableMetadata( int varid, const std::st
*is_x = true;

std::string long_name = mNcFile->getAttrStr( "long_name", varid );
if ( long_name.empty() )
if ( long_name.empty() || ( long_name == "??????" ) )
{
name = variableName;
}
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.93";
return "0.4.94";
}

MDAL_Status MDAL_LastStatus()
Expand Down
30 changes: 28 additions & 2 deletions external/mdal/mdal_utils.cpp
Expand Up @@ -296,7 +296,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 @@ -305,7 +314,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 Expand Up @@ -772,3 +789,12 @@ MDAL::DateTime MDAL::parseCFReferenceTime( const std::string &timeInformation, c

return MDAL::DateTime( year, month, day, hours, minutes, seconds, calendar );
}

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

#include <algorithm>

#include "mdal_data_model.hpp"
Expand Down Expand Up @@ -60,6 +61,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 a2a8097

Please sign in to comment.