update MDAL to 0.4.94

This commit is contained in:
Peter Petrik 2020-01-15 08:00:39 +01:00
parent 51c2f0ffad
commit a2a80976c2
8 changed files with 49 additions and 10 deletions

View File

@ -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;
}

View File

@ -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;
}
@ -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,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,
@ -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

View File

@ -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 ) )
{
@ -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 ) )
{
@ -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 );

View File

@ -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;

View File

@ -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;
}

View File

@ -22,7 +22,7 @@ static MDAL_Status sLastStatus;
const char *MDAL_Version()
{
return "0.4.93";
return "0.4.94";
}
MDAL_Status MDAL_LastStatus()

View File

@ -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/
@ -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 )
@ -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;
}

View File

@ -12,6 +12,7 @@
#include <limits>
#include <sstream>
#include <fstream>
#include <algorithm>
#include "mdal_data_model.hpp"
@ -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 );