Skip to content

Commit

Permalink
Update to MDAL 0.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterPetrik committed Dec 17, 2018
1 parent 64b81bd commit 8b542c8
Show file tree
Hide file tree
Showing 38 changed files with 2,550 additions and 244 deletions.
46 changes: 46 additions & 0 deletions external/mdal/api/mdal.h
Expand Up @@ -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
Expand Down
30 changes: 27 additions & 3 deletions external/mdal/frmts/mdal_2dm.cpp
Expand Up @@ -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 );
Expand Down
11 changes: 8 additions & 3 deletions external/mdal/frmts/mdal_2dm.hpp
Expand Up @@ -12,6 +12,7 @@
#include "mdal_data_model.hpp"
#include "mdal_memory_data_model.hpp"
#include "mdal.h"
#include "mdal_driver.hpp"

namespace MDAL
{
Expand Down Expand Up @@ -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;
Expand Down
32 changes: 20 additions & 12 deletions external/mdal/frmts/mdal_3di.cpp
Expand Up @@ -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 );
Expand Down Expand Up @@ -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() )
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
12 changes: 7 additions & 5 deletions external/mdal/frmts/mdal_3di.hpp
Expand Up @@ -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.
Expand All @@ -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;
Expand Down
42 changes: 37 additions & 5 deletions external/mdal/frmts/mdal_ascii_dat.cpp
Expand Up @@ -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 ) )
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 9 additions & 3 deletions external/mdal/frmts/mdal_ascii_dat.hpp
Expand Up @@ -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(
Expand Down

0 comments on commit 8b542c8

Please sign in to comment.