Skip to content
Permalink
Browse files

Update to MDAL 0.1.2

  • Loading branch information
PeterPetrik committed Dec 17, 2018
1 parent 64b81bd commit 8b542c8aa4ab8829935448104690e067cd015b5b
Showing with 2,550 additions and 244 deletions.
  1. +46 −0 external/mdal/api/mdal.h
  2. +27 −3 external/mdal/frmts/mdal_2dm.cpp
  3. +8 −3 external/mdal/frmts/mdal_2dm.hpp
  4. +20 −12 external/mdal/frmts/mdal_3di.cpp
  5. +7 −5 external/mdal/frmts/mdal_3di.hpp
  6. +37 −5 external/mdal/frmts/mdal_ascii_dat.cpp
  7. +9 −3 external/mdal/frmts/mdal_ascii_dat.hpp
  8. +30 −4 external/mdal/frmts/mdal_binary_dat.cpp
  9. +8 −3 external/mdal/frmts/mdal_binary_dat.hpp
  10. +28 −9 external/mdal/frmts/mdal_cf.cpp
  11. +10 −7 external/mdal/frmts/mdal_cf.hpp
  12. +56 −0 external/mdal/frmts/mdal_driver.cpp
  13. +53 −0 external/mdal/frmts/mdal_driver.hpp
  14. +695 −0 external/mdal/frmts/mdal_flo2d.cpp
  15. +56 −0 external/mdal/frmts/mdal_flo2d.hpp
  16. +45 −36 external/mdal/frmts/mdal_gdal.cpp
  17. +13 −7 external/mdal/frmts/mdal_gdal.hpp
  18. +14 −3 external/mdal/frmts/mdal_gdal_grib.cpp
  19. +8 −3 external/mdal/frmts/mdal_gdal_grib.hpp
  20. +14 −5 external/mdal/frmts/mdal_gdal_netcdf.cpp
  21. +8 −3 external/mdal/frmts/mdal_gdal_netcdf.hpp
  22. +528 −0 external/mdal/frmts/mdal_hec2d.cpp
  23. +67 −0 external/mdal/frmts/mdal_hec2d.hpp
  24. +2 −4 external/mdal/frmts/mdal_netcdf.hpp
  25. +373 −0 external/mdal/frmts/mdal_sww.cpp
  26. +32 −0 external/mdal/frmts/mdal_sww.hpp
  27. +34 −6 external/mdal/frmts/mdal_xmdf.cpp
  28. +8 −3 external/mdal/frmts/mdal_xmdf.hpp
  29. +76 −4 external/mdal/mdal.cpp
  30. +142 −0 external/mdal/mdal_driver_manager.cpp
  31. +46 −0 external/mdal/mdal_driver_manager.hpp
  32. +0 −88 external/mdal/mdal_loader.cpp
  33. +0 −27 external/mdal/mdal_loader.hpp
  34. +1 −1 external/mdal/mdal_memory_data_model.cpp
  35. +1 −0 external/mdal/mdal_memory_data_model.hpp
  36. +34 −0 external/mdal/mdal_utils.cpp
  37. +4 −0 external/mdal/mdal_utils.hpp
  38. +10 −0 src/providers/mdal/CMakeLists.txt
@@ -68,20 +68,66 @@ typedef void *MeshVertexIteratorH;
typedef void *MeshFaceIteratorH;
typedef void *DatasetGroupH;
typedef void *DatasetH;
typedef void *DriverH;

//! Returns MDAL version
MDAL_EXPORT const char *MDAL_Version();

//! Returns last status message
MDAL_EXPORT MDAL_Status MDAL_LastStatus();

///////////////////////////////////////////////////////////////////////////////////////
/// DRIVERS
///////////////////////////////////////////////////////////////////////////////////////

//! Returns count of registed MDAL drivers
MDAL_EXPORT int MDAL_driverCount();

/**
* Returns driver handle by index
* Do not free the returned pointer
*/
MDAL_EXPORT DriverH MDAL_driverFromIndex( int index );

/**
* Returns driver handle by name
* Do not free the returned pointer
*/
MDAL_EXPORT DriverH MDAL_driverFromName( const char *name );

/**
* Returns whether driver can be used to mesh
* if false, driver can be only used to load datasets to existing mesh
*/
MDAL_EXPORT bool MDAL_DR_meshLoadCapability( DriverH driver );

/**
* Returns name of MDAL driver
* not thread-safe and valid only till next call
*/
MDAL_EXPORT const char *MDAL_DR_name( DriverH driver );

/**
* Returns long name of MDAL driver
* not thread-safe and valid only till next call
*/
MDAL_EXPORT const char *MDAL_DR_longName( DriverH driver );

/**
* Returns file filters that MDAL driver recognizes
* Filters are separated by ;;, e.g. *.abc;;*.def
* not thread-safe and valid only till next call
*/
MDAL_EXPORT const char *MDAL_DR_filters( DriverH driver );

///////////////////////////////////////////////////////////////////////////////////////
/// MESH
///////////////////////////////////////////////////////////////////////////////////////

/**
* Loads mesh file. On error see MDAL_LastStatus for error type
* This may effectively load whole mesh in-memory for some providers
* Caller must free memory with MDAL_CloseMesh() afterwards
*/
MDAL_EXPORT MeshH MDAL_LoadMesh( const char *meshFile );
//! Closes mesh, frees the memory
@@ -57,13 +57,37 @@ size_t MDAL::Mesh2dm::vertexIndex( size_t vertexID ) const
}


MDAL::Loader2dm::Loader2dm( const std::string &meshFile ):
mMeshFile( meshFile )
MDAL::Driver2dm::Driver2dm():
Driver( "2DM",
"2DM Mesh File",
"*.2dm",
DriverType::CanReadMeshAndDatasets
)
{
}

std::unique_ptr<MDAL::Mesh> MDAL::Loader2dm::load( MDAL_Status *status )
MDAL::Driver2dm *MDAL::Driver2dm::create()
{
return new Driver2dm();
}

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

bool MDAL::Driver2dm::canRead( const std::string &uri )
{
std::ifstream in( uri, std::ifstream::in );
std::string line;
if ( !std::getline( in, line ) || !startsWith( line, "MESH2D" ) )
{
return false;
}
return true;
}

std::unique_ptr<MDAL::Mesh> MDAL::Driver2dm::load( const std::string &meshFile, MDAL_Status *status )
{
mMeshFile = meshFile;

if ( status ) *status = MDAL_Status::None;

std::ifstream in( mMeshFile, std::ifstream::in );
@@ -12,6 +12,7 @@
#include "mdal_data_model.hpp"
#include "mdal_memory_data_model.hpp"
#include "mdal.h"
#include "mdal_driver.hpp"

namespace MDAL
{
@@ -41,11 +42,15 @@ namespace MDAL
std::map<size_t, size_t> mVertexIDtoIndex;
};

class Loader2dm
class Driver2dm: public Driver
{
public:
Loader2dm( const std::string &meshFile );
std::unique_ptr< Mesh > load( MDAL_Status *status );
Driver2dm();
~Driver2dm() override;
Driver2dm *create() override;

bool canRead( const std::string &uri ) override;
std::unique_ptr< Mesh > load( const std::string &meshFile, MDAL_Status *status ) override;

private:
std::string mMeshFile;
@@ -5,35 +5,43 @@

#include "mdal_3di.hpp"

MDAL::Loader3Di::Loader3Di( const std::string &fileName )
: LoaderCF( fileName )
MDAL::Driver3Di::Driver3Di()
: DriverCF(
"3Di",
"3Di Results",
"results_3di.nc" )
{
}

MDAL::CFDimensions MDAL::Loader3Di::populateDimensions()
MDAL::Driver3Di *MDAL::Driver3Di::create()
{
return new Driver3Di();
}

MDAL::CFDimensions MDAL::Driver3Di::populateDimensions( const NetCDFFile &ncFile )
{
CFDimensions dims;
size_t count;
int ncid;

// 2D Mesh
mNcFile.getDimension( "nMesh2D_nodes", &count, &ncid );
ncFile.getDimension( "nMesh2D_nodes", &count, &ncid );
dims.setDimension( CFDimensions::Face2D, count, ncid );

mNcFile.getDimension( "nCorner_Nodes", &count, &ncid );
ncFile.getDimension( "nCorner_Nodes", &count, &ncid );
dims.setDimension( CFDimensions::MaxVerticesInFace, count, ncid );

// Vertices count is populated later in populateFacesAndVertices
// it is not known from the array dimensions

// Time
mNcFile.getDimension( "time", &count, &ncid );
ncFile.getDimension( "time", &count, &ncid );
dims.setDimension( CFDimensions::Time, count, ncid );

return dims;
}

void MDAL::Loader3Di::populateFacesAndVertices( Vertices &vertices, Faces &faces )
void MDAL::Driver3Di::populateFacesAndVertices( Vertices &vertices, Faces &faces )
{
assert( vertices.empty() );
size_t faceCount = mDimensions.size( CFDimensions::Face2D );
@@ -101,7 +109,7 @@ void MDAL::Loader3Di::populateFacesAndVertices( Vertices &vertices, Faces &faces
mDimensions.setDimension( CFDimensions::Vertex2D, vertices.size() );
}

void MDAL::Loader3Di::addBedElevation( MDAL::Mesh *mesh )
void MDAL::Driver3Di::addBedElevation( MDAL::Mesh *mesh )
{
assert( mesh );
if ( 0 == mesh->facesCount() )
@@ -139,12 +147,12 @@ void MDAL::Loader3Di::addBedElevation( MDAL::Mesh *mesh )
mesh->datasetGroups.push_back( group );
}

std::string MDAL::Loader3Di::getCoordinateSystemVariableName()
std::string MDAL::Driver3Di::getCoordinateSystemVariableName()
{
return "projected_coordinate_system";
}

std::set<std::string> MDAL::Loader3Di::ignoreNetCDFVariables()
std::set<std::string> MDAL::Driver3Di::ignoreNetCDFVariables()
{
std::set<std::string> ignore_variables;

@@ -178,13 +186,13 @@ std::set<std::string> MDAL::Loader3Di::ignoreNetCDFVariables()
return ignore_variables;
}

std::string MDAL::Loader3Di::nameSuffix( MDAL::CFDimensions::Type type )
std::string MDAL::Driver3Di::nameSuffix( MDAL::CFDimensions::Type type )
{
MDAL_UNUSED( type );
return "";
}

void MDAL::Loader3Di::parseNetCDFVariableMetadata( int varid, const std::string &variableName, std::string &name, bool *is_vector, bool *is_x )
void MDAL::Driver3Di::parseNetCDFVariableMetadata( int varid, const std::string &variableName, std::string &name, bool *is_vector, bool *is_x )
{
*is_vector = false;
*is_x = true;
@@ -11,12 +11,13 @@
#include <stddef.h>

#include "mdal_cf.hpp"
#include "mdal_driver.hpp"

namespace MDAL
{

/**
* Loader of 3Di file format.
* Driver of 3Di file format.
*
* The result 3Di NetCDF file is based on CF-conventions with some additions.
* It is unstructured grid with data stored in NetCDF/HDF5 file format.
@@ -35,14 +36,15 @@ namespace MDAL
*
* The 1D Mesh is present too, but not parsed yet.
*/
class Loader3Di: public LoaderCF
class Driver3Di: public DriverCF
{
public:
Loader3Di( const std::string &fileName );
~Loader3Di() override = default;
Driver3Di();
~Driver3Di() override = default;
Driver3Di *create() override;

private:
CFDimensions populateDimensions() override;
CFDimensions populateDimensions( const NetCDFFile &ncFile ) override;
void populateFacesAndVertices( Vertices &vertices, Faces &faces ) override;
void addBedElevation( Mesh *mesh ) override;
std::string getCoordinateSystemVariableName() override;
@@ -23,20 +23,52 @@

#define EXIT_WITH_ERROR(error) { if (status) *status = (error); return; }

MDAL::LoaderAsciiDat::LoaderAsciiDat( const std::string &datFile ):
mDatFile( datFile )
MDAL::DriverAsciiDat::DriverAsciiDat( ):
Driver( "ASCII_DAT",
"DAT",
"*.dat",
DriverType::CanReadOnlyDatasets
)
{
}

MDAL::DriverAsciiDat *MDAL::DriverAsciiDat::create()
{
return new DriverAsciiDat();
}

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

bool MDAL::DriverAsciiDat::canRead( const std::string &uri )
{
std::ifstream in( uri, std::ifstream::in );
std::string line;
if ( !std::getline( in, line ) )
{
return false;
}
line = trim( line );

if ( line != "DATASET" &&
line != "SCALAR" &&
line != "VECTOR" )
{
return false;
}
return true;
}


/**
* The DAT format contains "datasets" and each dataset has N-outputs. One output
* represents data for all vertices/faces for one timestep
*
* In MDAL we convert one output to one MDAL dataset;
*
*/
void MDAL::LoaderAsciiDat::load( MDAL::Mesh *mesh, MDAL_Status *status )
void MDAL::DriverAsciiDat::load( const std::string &datFile, MDAL::Mesh *mesh, MDAL_Status *status )
{
mDatFile = datFile;
if ( status ) *status = MDAL_Status::None;

if ( !MDAL::fileExists( mDatFile ) )
@@ -195,7 +227,7 @@ void MDAL::LoaderAsciiDat::load( MDAL::Mesh *mesh, MDAL_Status *status )
}
}

void MDAL::LoaderAsciiDat::readVertexTimestep(
void MDAL::DriverAsciiDat::readVertexTimestep(
const MDAL::Mesh *mesh,
std::shared_ptr<DatasetGroup> group,
double t,
@@ -262,7 +294,7 @@ void MDAL::LoaderAsciiDat::readVertexTimestep(
group->datasets.push_back( dataset );
}

void MDAL::LoaderAsciiDat::readFaceTimestep(
void MDAL::DriverAsciiDat::readFaceTimestep(
const MDAL::Mesh *mesh,
std::shared_ptr<DatasetGroup> group,
double t,
@@ -15,15 +15,21 @@

#include "mdal_data_model.hpp"
#include "mdal.h"
#include "mdal_driver.hpp"

namespace MDAL
{

class LoaderAsciiDat
class DriverAsciiDat: public Driver
{
public:
LoaderAsciiDat( const std::string &datFile );
void load( Mesh *mesh, MDAL_Status *status );
DriverAsciiDat();
~DriverAsciiDat( ) override;
DriverAsciiDat *create() override;

bool canRead( const std::string &uri ) override;
void load( const std::string &datFile, Mesh *mesh, MDAL_Status *status ) override;


private:
void readVertexTimestep(

0 comments on commit 8b542c8

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