Skip to content

Commit

Permalink
fix #211 reading of sww files without xllcorner and yllcorner attribu…
Browse files Browse the repository at this point in the history
…tes (#214)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
mdal-bot and github-actions[bot] committed Feb 20, 2020
1 parent 3ffbf15 commit 356de8e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
8 changes: 8 additions & 0 deletions mdal/frmts/mdal_netcdf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ double NetCDFFile::getFillValue( int varid ) const
return getAttrDouble( varid, "_FillValue" );
}

bool NetCDFFile::hasAttrDouble( int varid, const std::string &attr_name ) const
{
double res;
if ( nc_get_att_double( mNcid, varid, attr_name.c_str(), &res ) )
return false;
return true;
}

double NetCDFFile::getAttrDouble( int varid, const std::string &attr_name ) const
{
double res;
Expand Down
1 change: 1 addition & 0 deletions mdal/frmts/mdal_netcdf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class NetCDFFile

bool hasAttrInt( const std::string &name, const std::string &attr_name ) const;
int getAttrInt( const std::string &name, const std::string &attr_name ) const;
bool hasAttrDouble( int varid, const std::string &attr_name ) const;
double getAttrDouble( int varid, const std::string &attr_name ) const;
/**
* Get string attribute
Expand Down
8 changes: 6 additions & 2 deletions mdal/frmts/mdal_sww.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,12 @@ MDAL::Vertices MDAL::DriverSWW::readVertices( const NetCDFFile &ncFile ) const
std::vector<double> pz = readZCoords( ncFile );

// we may need to apply a shift to the X,Y coordinates
double xLLcorner = ncFile.getAttrDouble( NC_GLOBAL, "xllcorner" );
double yLLcorner = ncFile.getAttrDouble( NC_GLOBAL, "yllcorner" );
double xLLcorner = 0.0;
if ( ncFile.hasAttrDouble( NC_GLOBAL, "xllcorner" ) )
xLLcorner = ncFile.getAttrDouble( NC_GLOBAL, "xllcorner" );
double yLLcorner = 0.0;
if ( ncFile.hasAttrDouble( NC_GLOBAL, "yllcorner" ) )
yLLcorner = ncFile.getAttrDouble( NC_GLOBAL, "yllcorner" );

MDAL::Vertices vertices( nPoints );
Vertex *vertexPtr = vertices.data();
Expand Down
18 changes: 6 additions & 12 deletions tests/test_sww.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,15 @@ TEST( MeshSWWTest, Cairns )

std::vector<double> expectedCoords =
{
0.0, 0.0, 0.0,
12, 0, 0.0,
12, 12, 0.0,
0, 12, 0.0,
12, 24, 0.0,
0, 24, 0.0,
24, 0, 0.0,
24, 12, 0.0,
24, 24, 0.0
368725.71875, 8129547, 3.109999895095825,
368745.71875, 8129547, 3.010999917984009,
368765.71875, 8129547, 2.920000076293945
};
EXPECT_EQ( expectedCoords.size(), 9 * 3 );
EXPECT_EQ( expectedCoords.size(), 3 * 3 );

std::vector<double> coordinates = getCoordinates( m, 9 );
std::vector<double> coordinates = getCoordinates( m, 3 );

compareVectors( expectedCoords, coordinates );
EXPECT_TRUE( compareVectors( expectedCoords, coordinates ) );

// ///////////
// Faces
Expand Down

0 comments on commit 356de8e

Please sign in to comment.