Skip to content

Commit

Permalink
MDAL v1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
vcloarec authored and nyalldawson committed Mar 1, 2023
1 parent 0ebc409 commit de81494
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 55 deletions.
72 changes: 46 additions & 26 deletions external/mdal/frmts/mdal_gdal.cpp
Expand Up @@ -111,7 +111,7 @@ bool MDAL::DriverGdal::initVertices( Vertices &vertices )
return is_longitude_shifted;
}

void MDAL::DriverGdal::initFaces( Vertices &Vertexs, Faces &Faces, bool is_longitude_shifted )
void MDAL::DriverGdal::initFaces( const Vertices &Vertexs, Faces &Faces, bool is_longitude_shifted )
{
int reconnected = 0;
unsigned int mXSize = meshGDALDataset()->mXSize;
Expand Down Expand Up @@ -587,7 +587,7 @@ std::unique_ptr<MDAL::Mesh> MDAL::DriverGdal::load( const std::string &fileName,
}
}

for ( std::shared_ptr<MDAL::GdalDataset> ds : datasets )
for ( std::shared_ptr<MDAL::GdalDataset> &ds : datasets )
if ( gdal_datasets.empty() || meshes_equals( meshGDALDataset(), ds.get() ) )
gdal_datasets.push_back( ds );

Expand Down Expand Up @@ -645,26 +645,28 @@ void MDAL::DriverGdal::parseBandIsVector( std::string &band_name, bool *is_vecto
{
band_name = MDAL::trim( band_name );

if ( MDAL::startsWith( band_name, "u-", MDAL::CaseInsensitive ) ||
MDAL::startsWith( band_name, "x-", MDAL::CaseInsensitive ) ||
if ( MDAL::contains( band_name, "U wind component", MDAL::CaseInsensitive ) ||
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::startsWith( band_name, "u-", MDAL::CaseInsensitive ) ||
MDAL::contains( band_name, "x-component", MDAL::CaseInsensitive ) ||
MDAL::contains( band_name, "x component", MDAL::CaseInsensitive ) )
MDAL::contains( band_name, "x component", MDAL::CaseInsensitive ) ||
MDAL::startsWith( band_name, "x-", MDAL::CaseInsensitive ) ||
MDAL::contains( band_name, "eastward", MDAL::CaseInsensitive ) ||
MDAL::contains( band_name, "zonal", MDAL::CaseInsensitive ) )
{
*is_vector = true; // vector
*is_x = true; //X-Axis
}
else if ( MDAL::startsWith( band_name, "v-", MDAL::CaseInsensitive ) ||
MDAL::startsWith( band_name, "y-", MDAL::CaseInsensitive ) ||
else if ( MDAL::contains( band_name, "V wind component", MDAL::CaseInsensitive ) ||
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::startsWith( band_name, "v-", MDAL::CaseInsensitive ) ||
MDAL::contains( band_name, "y-component", MDAL::CaseInsensitive ) ||
MDAL::contains( band_name, "y component", MDAL::CaseInsensitive ) )
MDAL::contains( band_name, "y component", MDAL::CaseInsensitive ) ||
MDAL::startsWith( band_name, "y-", MDAL::CaseInsensitive ) ||
MDAL::contains( band_name, "northward", MDAL::CaseInsensitive ) ||
MDAL::contains( band_name, "meridional", MDAL::CaseInsensitive ) )
{
*is_vector = true; // vector
*is_x = false; //Y-Axis
Expand All @@ -677,30 +679,48 @@ void MDAL::DriverGdal::parseBandIsVector( std::string &band_name, bool *is_vecto

if ( *is_vector )
{
band_name = MDAL::replace( band_name, "u-component of", "", MDAL::CaseInsensitive );
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 of", "", MDAL::CaseInsensitive );
band_name = MDAL::replace( band_name, "v-component of", "", MDAL::CaseInsensitive );
band_name = MDAL::replace( band_name, "u-component", "", MDAL::CaseInsensitive );
band_name = MDAL::replace( band_name, "v-component", "", MDAL::CaseInsensitive );
band_name = MDAL::replace( band_name, "x-component", "", MDAL::CaseInsensitive );
band_name = MDAL::replace( band_name, "y-component", "", MDAL::CaseInsensitive );
band_name = MDAL::replace( band_name, "u-", "", MDAL::CaseInsensitive );
band_name = MDAL::replace( band_name, "v-", "", MDAL::CaseInsensitive );

band_name = MDAL::replace( band_name, "u component of", "", MDAL::CaseInsensitive );
band_name = MDAL::replace( band_name, "v component of", "", 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 );
band_name = MDAL::replace( band_name, "v component", "", MDAL::CaseInsensitive );
band_name = MDAL::replace( band_name, "x component", "", MDAL::CaseInsensitive );
band_name = MDAL::replace( band_name, "y component", "", MDAL::CaseInsensitive );
band_name = MDAL::replace( band_name, "u-", "", MDAL::CaseInsensitive );
band_name = MDAL::replace( band_name, "v-", "", 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, "x-component", "", MDAL::CaseInsensitive );
band_name = MDAL::replace( band_name, "y-component", "", MDAL::CaseInsensitive );
band_name = MDAL::replace( band_name, "x-", "", MDAL::CaseInsensitive );
band_name = MDAL::replace( band_name, "y-", "", 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, "x component", "", MDAL::CaseInsensitive );
band_name = MDAL::replace( band_name, "y component", "", MDAL::CaseInsensitive );

band_name = MDAL::replace( band_name, "eastward component of", "", MDAL::CaseInsensitive );
band_name = MDAL::replace( band_name, "northward component of", "", MDAL::CaseInsensitive );
band_name = MDAL::replace( band_name, "eastward component", "", MDAL::CaseInsensitive );
band_name = MDAL::replace( band_name, "northward component", "", MDAL::CaseInsensitive );
band_name = MDAL::replace( band_name, "eastward", "", MDAL::CaseInsensitive );
band_name = MDAL::replace( band_name, "northward", "", MDAL::CaseInsensitive );

band_name = MDAL::replace( band_name, "zonal component of", "", MDAL::CaseInsensitive );
band_name = MDAL::replace( band_name, "meridional component of", "", MDAL::CaseInsensitive );
band_name = MDAL::replace( band_name, "zonal component", "", MDAL::CaseInsensitive );
band_name = MDAL::replace( band_name, "meridional component", "", MDAL::CaseInsensitive );
band_name = MDAL::replace( band_name, "zonal", "", MDAL::CaseInsensitive );
band_name = MDAL::replace( band_name, "meridional", "", MDAL::CaseInsensitive );

band_name = MDAL::trim( band_name );
}
}
2 changes: 1 addition & 1 deletion external/mdal/frmts/mdal_gdal.hpp
Expand Up @@ -79,7 +79,7 @@ namespace MDAL

void registerDriver();

void initFaces( Vertices &nodes, Faces &Faces, bool is_longitude_shifted );
void initFaces( const Vertices &nodes, Faces &Faces, bool is_longitude_shifted );
bool initVertices( Vertices &vertices ); //returns is_longitude_shifted

const GdalDataset *meshGDALDataset();
Expand Down
34 changes: 18 additions & 16 deletions external/mdal/frmts/mdal_hec2d.cpp
Expand Up @@ -738,7 +738,7 @@ bool MDAL::DriverHec2D::canReadMesh( const std::string &uri )
{
HdfFile hdfFile = openHdfFile( uri );
std::string fileType = openHdfAttribute( hdfFile, "File Type" );
return canReadFormat( fileType ) || canReadFormat505( fileType );
return canReadFormat( fileType );
}
catch ( MDAL_Status )
{
Expand All @@ -752,17 +752,12 @@ bool MDAL::DriverHec2D::canReadMesh( const std::string &uri )

bool MDAL::DriverHec2D::canReadFormat( const std::string &fileType ) const
{
return fileType == "HEC-RAS Results";
return fileType == "HEC-RAS Results" || fileType == "HEC-RAS Geometry";
}

bool MDAL::DriverHec2D::canReadFormat505( const std::string &fileType ) const
std::unique_ptr<MDAL::Mesh> MDAL::DriverHec2D::load( const std::string &fileName, const std::string & )
{
return fileType == "HEC-RAS Geometry";
}

std::unique_ptr<MDAL::Mesh> MDAL::DriverHec2D::load( const std::string &resultsFile, const std::string & )
{
mFileName = resultsFile;
mFileName = fileName;
MDAL::Log::resetLastStatus();
mMesh.reset();

Expand All @@ -787,22 +782,29 @@ std::unique_ptr<MDAL::Mesh> MDAL::DriverHec2D::load( const std::string &resultsF
parseMesh( gGeom2DFlowAreas, areaElemStartIndex, flowAreaNames );
setProjection( hdfFile );

mTimes = readTimes( hdfFile );
mReferenceTime = readReferenceDateTime( hdfFile );
bool hasResults = hdfFile.pathExists( "Results" );
if ( hasResults )
{
mTimes = readTimes( hdfFile );
mReferenceTime = readReferenceDateTime( hdfFile );
}

//Elevation
std::shared_ptr<MDAL::MemoryDataset2D> bed_elevation = readBedElevation( gGeom2DFlowAreas, areaElemStartIndex, flowAreaNames );

// Element centered Values
readElemResults( hdfFile, bed_elevation, areaElemStartIndex, flowAreaNames );
if ( hasResults )
{
// Element centered Values
readElemResults( hdfFile, bed_elevation, areaElemStartIndex, flowAreaNames );

// Face centered Values
readFaceResults( hdfFile, areaElemStartIndex, flowAreaNames );
// Face centered Values
readFaceResults( hdfFile, areaElemStartIndex, flowAreaNames );
}

}
catch ( MDAL_Status error )
{
MDAL::Log::error( error, name(), "Error occurred while loading file " + resultsFile );
MDAL::Log::error( error, name(), "Error occurred while loading file " + fileName );
mMesh.reset();
}
catch ( MDAL::Error err )
Expand Down
6 changes: 1 addition & 5 deletions external/mdal/frmts/mdal_hec2d.hpp
Expand Up @@ -43,7 +43,7 @@ namespace MDAL
DriverHec2D *create() override;

bool canReadMesh( const std::string &uri ) override;
std::unique_ptr< Mesh > load( const std::string &resultsFile, const std::string &meshName = "" ) override;
std::unique_ptr< Mesh > load( const std::string &fileName, const std::string &meshName = "" ) override;

private:
std::unique_ptr< MDAL::MemoryMesh > mMesh;
Expand All @@ -52,12 +52,8 @@ namespace MDAL
std::vector<MDAL::RelativeTimestamp> mTimes ;
DateTime mReferenceTime;

// Regular format
bool canReadFormat( const std::string &fileType ) const;

// 5.0.5 format
bool canReadFormat505( const std::string &fileType ) const;

std::vector<std::string> read2DFlowAreasNamesFromNameDataset( HdfGroup gGeom2DFlowAreas ) const;
std::vector<std::string> read2DFlowAreasNamesFromAttributesDataset( HdfGroup gGeom2DFlowAreas ) const;

Expand Down
64 changes: 58 additions & 6 deletions external/mdal/frmts/mdal_ugrid.cpp
Expand Up @@ -531,16 +531,22 @@ void MDAL::DriverUgrid::parseNetCDFVariableMetadata( int varid,
else
{
variableName = standardName;
if ( MDAL::contains( standardName, "_x_" ) )
if ( MDAL::contains( standardName, "_x_" ) ||
MDAL::contains( standardName, "eastward_" ) )
{
*isVector = true;
name = MDAL::replace( standardName, "_x_", "" );
name = MDAL::replace( name, "_eastward_", "" );
name = MDAL::replace( name, "eastward_", "" );
}
else if ( MDAL::contains( standardName, "_y_" ) )
else if ( MDAL::contains( standardName, "_y_" ) ||
MDAL::contains( standardName, "northward_" ) )
{
*isVector = true;
*isX = false;
name = MDAL::replace( standardName, "_y_", "" );
name = MDAL::replace( name, "_northward_", "" );
name = MDAL::replace( name, "northward_", "" );
}
else if ( MDAL::contains( standardName, "_from_direction" ) )
{
Expand Down Expand Up @@ -568,18 +574,64 @@ void MDAL::DriverUgrid::parseNetCDFVariableMetadata( int varid,
else
{
variableName = longName;
if ( MDAL::contains( longName, ", x-component" ) || MDAL::contains( longName, "u component of " ) )
if ( MDAL::contains( longName, "x-component" ) ||
MDAL::contains( longName, "x component" ) ||
MDAL::contains( longName, "u-component" ) ||
MDAL::contains( longName, "u component" ) ||
MDAL::contains( longName, "eastward" ) ||
MDAL::contains( longName, "zonal" ) )
{
*isVector = true;
name = MDAL::replace( longName, ", x-component", "" );
name = MDAL::replace( name, "u component of ", "" );
name = MDAL::replace( name, "x-component of", "" );
name = MDAL::replace( name, "x-component", "" );
name = MDAL::replace( name, "x component of", "" );
name = MDAL::replace( name, "x component", "" );

name = MDAL::replace( name, "u-component of", "" );
name = MDAL::replace( name, "u-component", "" );
name = MDAL::replace( name, "u component of", "" );
name = MDAL::replace( name, "u component", "" );

name = MDAL::replace( name, "eastward component of", "" );
name = MDAL::replace( name, "eastward component", "" );
name = MDAL::replace( name, "eastward", "" );

name = MDAL::replace( name, "zonal component of", "" );
name = MDAL::replace( name, "zonal component", "" );
name = MDAL::replace( name, "zonal", "" );

name = MDAL::trim( name );
}
else if ( MDAL::contains( longName, ", y-component" ) || MDAL::contains( longName, "v component of " ) )
else if ( MDAL::contains( longName, "y-component" ) ||
MDAL::contains( longName, "y component" ) ||
MDAL::contains( longName, "v-component" ) ||
MDAL::contains( longName, "v component" ) ||
MDAL::contains( longName, "northward" ) ||
MDAL::contains( longName, "meridional" ) )
{
*isVector = true;
*isX = false;
name = MDAL::replace( longName, ", y-component", "" );
name = MDAL::replace( name, "v component of ", "" );
name = MDAL::replace( name, "y-component of", "" );
name = MDAL::replace( name, "y-component", "" );
name = MDAL::replace( name, "y component of", "" );
name = MDAL::replace( name, "y component", "" );

name = MDAL::replace( name, "v-component of", "" );
name = MDAL::replace( name, "v-component", "" );
name = MDAL::replace( name, "v component of", "" );
name = MDAL::replace( name, "v component", "" );

name = MDAL::replace( name, "northward component of", "" );
name = MDAL::replace( name, "northward component", "" );
name = MDAL::replace( name, "northward", "" );

name = MDAL::replace( name, "meridional component of", "" );
name = MDAL::replace( name, "meridional component", "" );
name = MDAL::replace( name, "meridional", "" );

name = MDAL::trim( name );
}
else if ( MDAL::contains( longName, " magnitude" ) )
{
Expand Down
2 changes: 1 addition & 1 deletion external/mdal/mdal.cpp
Expand Up @@ -21,7 +21,7 @@ static const char *EMPTY_STR = "";

const char *MDAL_Version()
{
return "1.0.0";
return "1.0.2";
}

MDAL_Status MDAL_LastStatus()
Expand Down

0 comments on commit de81494

Please sign in to comment.