Skip to content
Permalink
Browse files

MDAL 0.1.1, fix some minor build/memory issues

  • Loading branch information
PeterPetrik committed Dec 6, 2018
1 parent fa1ddb1 commit 7dc73790e005715a0d622c340fc01c1558b263c0
@@ -193,7 +193,7 @@ std::unique_ptr<MDAL::Mesh> MDAL::Loader2dm::load( MDAL_Status *status )
//check that we have distinct nodes
}

std::unique_ptr< MemoryMesh > mesh(
std::unique_ptr< Mesh2dm > mesh(
new Mesh2dm(
vertices.size(),
faces.size(),
@@ -205,7 +205,6 @@ std::unique_ptr<MDAL::Mesh> MDAL::Loader2dm::load( MDAL_Status *status )
);
mesh->faces = faces;
mesh->vertices = vertices;
mesh->addBedElevationDataset( vertices, faces );

return mesh;
MDAL::addBedElevationDatasetGroup( mesh.get(), vertices );
return std::unique_ptr<Mesh>( mesh.release() );
}
@@ -204,8 +204,6 @@ void MDAL::LoaderAsciiDat::readVertexTimestep(
std::ifstream &stream )
{
assert( group );

size_t vertexCount = mesh->verticesCount();
size_t faceCount = mesh->facesCount();

std::shared_ptr<MDAL::MemoryDataset> dataset = std::make_shared< MDAL::MemoryDataset >( group.get() );
@@ -110,7 +110,7 @@ void MDAL::LoaderBinaryDat::load( MDAL::Mesh *mesh, MDAL_Status *status )
int version;
int objecttype;
int sflt;
int sflg;
int sflg = 0;
int vectype;
int objid;
int numdata;
@@ -195,10 +195,11 @@ void MDAL::LoaderCF::addDatasetGroups( MDAL::Mesh *mesh, const std::vector<doubl
if ( nc_get_var_double( mNcFile.handle(), dsi.ncid_x, vals_x.data() ) ) CF_THROW_ERR;

// read Y data if vector
double fill_val_y = mNcFile.getFillValue( dsi.ncid_y );
double fill_val_y = std::numeric_limits<double>::quiet_NaN();
std::vector<double> vals_y;
if ( dsi.is_vector )
{
fill_val_y = mNcFile.getFillValue( dsi.ncid_y );
vals_y.resize( dsi.arr_size );
if ( nc_get_var_double( mNcFile.handle(), dsi.ncid_y, vals_y.data() ) ) CF_THROW_ERR;
}
@@ -212,11 +213,10 @@ void MDAL::LoaderCF::addDatasetGroups( MDAL::Mesh *mesh, const std::vector<doubl
if ( dsi.outputType == CFDimensions::Face2D )
{
dataset = createFace2DDataset( group, ts, dsi, vals_x, vals_y, fill_val_x, fill_val_y );
dataset->setTime( time );
dataset->setStatistics( MDAL::calculateStatistics( dataset ) );
group->datasets.push_back( dataset );
}

dataset->setTime( time );
dataset->setStatistics( MDAL::calculateStatistics( dataset ) );
group->datasets.push_back( dataset );
}

// Add to mesh
@@ -330,7 +330,7 @@ std::unique_ptr< MDAL::Mesh > MDAL::LoaderCF::load( MDAL_Status *status )
// Create datasets
addDatasetGroups( mesh.get(), times, dsinfo_map );

return mesh;
return std::unique_ptr<Mesh>( mesh.release() );
}
catch ( MDAL_Status error )
{
@@ -7,6 +7,7 @@
#include <assert.h>
#include <limits>
#include <gdal.h>
#include <cmath>
#include "ogr_api.h"
#include "ogr_srs_api.h"
#include "gdal_alg.h"
@@ -92,10 +92,10 @@ hid_t HdfDataset::id() const { return d->id; }
std::vector<hsize_t> HdfDataset::dims() const
{
hid_t sid = H5Dget_space( d->id );
std::vector<hsize_t> d( H5Sget_simple_extent_ndims( sid ) );
H5Sget_simple_extent_dims( sid, d.data(), NULL );
std::vector<hsize_t> ret( static_cast<size_t>( H5Sget_simple_extent_ndims( sid ) ) );
H5Sget_simple_extent_dims( sid, ret.data(), nullptr );
H5Sclose( sid );
return d;
return ret;
}

hsize_t HdfDataset::elementCount() const
@@ -192,7 +192,7 @@ std::string HdfDataset::readString() const

HdfDataspace::HdfDataspace( const std::vector<hsize_t> &dims )
: d( std::make_shared< Handle >( H5Screate_simple(
dims.size(),
static_cast<int>( dims.size() ),
dims.data(),
dims.data()
)
@@ -248,14 +248,14 @@ std::shared_ptr<MDAL::DatasetGroup> MDAL::LoaderXmdf::readXmdfGroupAsDatasetGrou
// lazy loading of min and max of the dataset group
std::vector<float> mins = dsMins.readArray();
std::vector<float> maxs = dsMaxs.readArray();
Statistics stats;
stats.minimum = static_cast<double>( *std::min_element( mins.begin(), mins.end() ) );
stats.maximum = static_cast<double>( *std::max_element( maxs.begin(), maxs.end() ) );
group->setStatistics( stats );
Statistics grpStats;
grpStats.minimum = static_cast<double>( *std::min_element( mins.begin(), mins.end() ) );
grpStats.maximum = static_cast<double>( *std::max_element( maxs.begin(), maxs.end() ) );
group->setStatistics( grpStats );

for ( hsize_t i = 0; i < nTimeSteps; ++i )
{
std::shared_ptr<XmdfDataset> dataset( new XmdfDataset( group.get(), dsValues, dsActive, i ) );
std::shared_ptr<XmdfDataset> dataset = std::make_shared< XmdfDataset >( group.get(), dsValues, dsActive, i );
dataset->setTime( double( times[i] ) );
Statistics stats;
stats.minimum = static_cast<double>( mins[i] );
@@ -20,7 +20,7 @@ static MDAL_Status sLastStatus;

const char *MDAL_Version()
{
return "0.1.0";
return "0.1.1";
}

MDAL_Status MDAL_LastStatus()
@@ -501,7 +501,7 @@ int MDAL_D_data( DatasetH dataset, int indexStart, int count, MDAL_DataType data
MDAL::Mesh *m = d->mesh();
assert( m );

size_t valuesCount;
size_t valuesCount = 0;

// Check that we are requesting correct 1D/2D for given dataset
switch ( dataType )
@@ -541,7 +541,7 @@ int MDAL_D_data( DatasetH dataset, int indexStart, int count, MDAL_DataType data
}

// Request data
size_t writtenValuesCount;
size_t writtenValuesCount = 0;
switch ( dataType )
{
case MDAL_DataType::SCALAR_DOUBLE:
@@ -79,6 +79,8 @@ MDAL::DatasetGroup::DatasetGroup( MDAL::Mesh *parent,
setName( name );
}

MDAL::DatasetGroup::~DatasetGroup() = default;

MDAL::DatasetGroup::DatasetGroup( MDAL::Mesh *parent, const std::string &uri )
: mParent( parent )
, mUri( uri )
@@ -11,6 +11,7 @@
#include <memory>
#include <map>
#include <string>
#include <limits>
#include "mdal.h"

namespace MDAL
@@ -79,6 +80,8 @@ namespace MDAL
const std::string &uri,
const std::string &name );

~DatasetGroup();

std::string getMetadata( const std::string &key );
void setMetadata( const std::string &key, const std::string &val );

@@ -34,14 +34,14 @@ std::unique_ptr<MDAL::Mesh> MDAL::Loader::load( const std::string &meshFile, MDA
return nullptr;
}

MDAL::Loader2dm loader( meshFile );
std::unique_ptr<MDAL::Mesh> mesh = loader.load( status );
MDAL::Loader2dm loader2dm( meshFile );
std::unique_ptr<MDAL::Mesh> mesh = loader2dm.load( status );

#ifdef HAVE_NETCDF
if ( !mesh && status && *status == MDAL_Status::Err_UnknownFormat )
{
MDAL::Loader3Di loader( meshFile );
mesh = loader.load( status );
MDAL::Loader3Di loader3di( meshFile );
mesh = loader3di.load( status );
}
#endif

@@ -51,14 +51,14 @@ std::unique_ptr<MDAL::Mesh> MDAL::Loader::load( const std::string &meshFile, MDA
#ifdef HAVE_NETCDF
if ( MDAL::endsWith( meshFile, ".nc" ) )
{
MDAL::LoaderGdalNetCDF loader( meshFile );
mesh = loader.load( status );
MDAL::LoaderGdalNetCDF loaderNetCDF( meshFile );
mesh = loaderNetCDF.load( status );
}
else
{
#endif // HAVE_GDAL && HAVE_NETCDF
MDAL::LoaderGdalGrib loader( meshFile );
mesh = loader.load( status );
MDAL::LoaderGdalGrib loaderGrib( meshFile );
mesh = loaderGrib.load( status );
}
#ifdef HAVE_NETCDF
}
@@ -69,20 +69,20 @@ std::unique_ptr<MDAL::Mesh> MDAL::Loader::load( const std::string &meshFile, MDA

void MDAL::Loader::loadDatasets( Mesh *mesh, const std::string &datasetFile, MDAL_Status *status )
{
MDAL::LoaderAsciiDat loader( datasetFile );
loader.load( mesh, status );
MDAL::LoaderAsciiDat loaderAsciiDat( datasetFile );
loaderAsciiDat.load( mesh, status );

if ( status && *status == MDAL_Status::Err_UnknownFormat )
{
MDAL::LoaderBinaryDat loader( datasetFile );
loader.load( mesh, status );
MDAL::LoaderBinaryDat loaderBinaryDat( datasetFile );
loaderBinaryDat.load( mesh, status );
}

#ifdef HAVE_HDF5
if ( status && *status == MDAL_Status::Err_UnknownFormat )
{
MDAL::LoaderXmdf loader( datasetFile );
loader.load( mesh, status );
MDAL::LoaderXmdf loaderXmdf( datasetFile );
loaderXmdf.load( mesh, status );
}
#endif
}
@@ -15,9 +15,9 @@ MDAL::MemoryDataset::MemoryDataset( MDAL::DatasetGroup *grp )
: Dataset( grp )
, mValues( group()->isScalar() ? valuesCount() : 2 * valuesCount(),
std::numeric_limits<double>::quiet_NaN() )
, mActive( group()->isOnVertices() ? mesh()->facesCount() : 0,
1 )
{
if ( group()->isOnVertices() )
mActive = std::vector<int>( mesh()->facesCount(), 1 );
}

MDAL::MemoryDataset::~MemoryDataset() = default;
@@ -98,21 +98,16 @@ MDAL::MemoryMesh::MemoryMesh( size_t verticesCount, size_t facesCount, size_t fa

std::unique_ptr<MDAL::MeshVertexIterator> MDAL::MemoryMesh::readVertices()
{
std::unique_ptr<MDAL::MemoryMeshVertexIterator> it( new MemoryMeshVertexIterator( this ) );
std::unique_ptr<MDAL::MeshVertexIterator> it( new MemoryMeshVertexIterator( this ) );
return it;
}

std::unique_ptr<MDAL::MeshFaceIterator> MDAL::MemoryMesh::readFaces()
{
std::unique_ptr<MDAL::MemoryMeshFaceIterator> it( new MemoryMeshFaceIterator( this ) );
std::unique_ptr<MDAL::MeshFaceIterator> it( new MemoryMeshFaceIterator( this ) );
return it;
}

void MDAL::MemoryMesh::addBedElevationDataset( const MDAL::Vertices &vertices, const MDAL::Faces &faces )
{
MDAL::addBedElevationDatasetGroup( this, vertices, faces );
}

MDAL::MemoryMesh::~MemoryMesh() = default;

MDAL::MemoryMeshVertexIterator::MemoryMeshVertexIterator( const MDAL::MemoryMesh *mesh )
@@ -87,8 +87,6 @@ namespace MDAL
std::unique_ptr<MDAL::MeshVertexIterator> readVertices() override;
std::unique_ptr<MDAL::MeshFaceIterator> readFaces() override;

void addBedElevationDataset( const Vertices &vertices, const Faces &faces );

Vertices vertices;
Faces faces;
};
@@ -11,6 +11,7 @@
#include <sstream>
#include <math.h>
#include <assert.h>
#include <cmath>

bool MDAL::fileExists( const std::string &filename )
{
@@ -150,7 +151,13 @@ std::string MDAL::join( const std::vector<std::string> parts, const std::string
std::string MDAL::toLower( const std::string &std )
{
std::string res( std );
#ifdef WIN32
//silence algorithm(1443): warning C4244: '=': conversion from 'int' to 'char'
std::transform( res.begin(), res.end(), res.begin(),
[]( char c ) {return static_cast<char>( ::tolower( c ) );} );
#else
std::transform( res.begin(), res.end(), res.begin(), ::tolower );
#endif
return res;
}

@@ -271,14 +278,14 @@ MDAL::Statistics _calculateStatistics( const std::vector<double> &values, size_t
{
double x = values[2 * i];
double y = values[2 * i + 1];
if ( isnan( x ) || isnan( y ) )
if ( std::isnan( x ) || std::isnan( y ) )
continue;
magnitude = sqrt( x * x + y * y );
}
else
{
double x = values[i];
if ( isnan( x ) )
if ( std::isnan( x ) )
continue;
magnitude = x;
}
@@ -353,20 +360,20 @@ MDAL::Statistics MDAL::calculateStatistics( std::shared_ptr<Dataset> dataset )

void MDAL::combineStatistics( MDAL::Statistics &main, const MDAL::Statistics &other )
{
if ( isnan( main.minimum ) ||
( !isnan( other.minimum ) && ( main.minimum > other.minimum ) ) )
if ( std::isnan( main.minimum ) ||
( !std::isnan( other.minimum ) && ( main.minimum > other.minimum ) ) )
{
main.minimum = other.minimum;
}

if ( isnan( main.maximum ) ||
( !isnan( other.maximum ) && ( main.maximum < other.maximum ) ) )
if ( std::isnan( main.maximum ) ||
( !std::isnan( other.maximum ) && ( main.maximum < other.maximum ) ) )
{
main.maximum = other.maximum;
}
}

void MDAL::addBedElevationDatasetGroup( MDAL::Mesh *mesh, const Vertices &vertices, const Faces &faces )
void MDAL::addBedElevationDatasetGroup( MDAL::Mesh *mesh, const Vertices &vertices )
{
if ( !mesh )
return;
@@ -104,7 +104,7 @@ namespace MDAL

// mesh & datasets
//! Add bed elevatiom dataset group to mesh
void addBedElevationDatasetGroup( MDAL::Mesh *mesh, const Vertices &vertices, const Faces &faces );
void addBedElevationDatasetGroup( MDAL::Mesh *mesh, const Vertices &vertices );

} // namespace MDAL
#endif //MDAL_UTILS_HPP

0 comments on commit 7dc7379

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