Skip to content

Commit

Permalink
mdal 0.8.92
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterPetrik authored and nyalldawson committed Aug 18, 2021
1 parent 7c75c4c commit 64b5ce1
Show file tree
Hide file tree
Showing 16 changed files with 588 additions and 35 deletions.
81 changes: 79 additions & 2 deletions external/mdal/api/mdal.h
Expand Up @@ -117,7 +117,7 @@ MDAL_EXPORT MDAL_Status MDAL_LastStatus();
*/
MDAL_EXPORT void MDAL_ResetStatus();

/*
/**
* Sets the last status message
* \since MDAL 0.9.0
*/
Expand Down Expand Up @@ -215,6 +215,13 @@ MDAL_EXPORT const char *MDAL_DR_longName( MDAL_DriverH driver );
*/
MDAL_EXPORT const char *MDAL_DR_filters( MDAL_DriverH driver );

/**
* Returns the maximum number of vertices per face supported by the driver
*
* \since MDAL 0.9.0
*/
MDAL_EXPORT int MDAL_DR_faceVerticesMaximumCount( MDAL_DriverH driver );

///////////////////////////////////////////////////////////////////////////////////////
/// MESH
///////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -266,6 +273,16 @@ MDAL_EXPORT MDAL_MeshH MDAL_CreateMesh( MDAL_DriverH driver );
*/
MDAL_EXPORT void MDAL_SaveMesh( MDAL_MeshH mesh, const char *meshFile, const char *driver );

/**
* Saves mesh (only mesh structure) on a file with an uri. On error see MDAL_LastStatus for error type.
*
* uri has form <DriverName>:"<MeshFilePath>"[:<SpecificMeshName>]
* examples: Ugrid:"mesh.nc":0, Ugrid:"mesh.nc":mesh2d, Ugrid:"mesh.nc"
*
* since MDAL 0.9
*/
MDAL_EXPORT void MDAL_SaveMeshWithUri( MDAL_MeshH mesh, const char *uri );

/**
* Returns mesh projection
* not thread-safe and valid only till next call
Expand Down Expand Up @@ -331,7 +348,7 @@ MDAL_EXPORT int MDAL_M_edgeCount( MDAL_MeshH mesh );
MDAL_EXPORT int MDAL_M_faceCount( MDAL_MeshH mesh );

/**
* Returns maximum number of vertices face can consist of, e.g. 4 for regular quad mesh
* Returns maximum number of vertices per face for this mesh, can consist of, e.g. 4 for regular quad mesh.
*/
MDAL_EXPORT int MDAL_M_faceVerticesMaximumCount( MDAL_MeshH mesh );

Expand All @@ -343,6 +360,36 @@ MDAL_EXPORT int MDAL_M_faceVerticesMaximumCount( MDAL_MeshH mesh );
*/
MDAL_EXPORT void MDAL_M_LoadDatasets( MDAL_MeshH mesh, const char *datasetFile );

/**
* Returns number of metadata values
*
* \since MDAL 0.9.0
*/
MDAL_EXPORT int MDAL_M_metadataCount( MDAL_MeshH mesh );

/**
* Returns dataset metadata key
* not thread-safe and valid only till next call
*
* \since MDAL 0.9.0
*/
MDAL_EXPORT const char *MDAL_M_metadataKey( MDAL_MeshH mesh, int index );

/**
* Returns dataset metadata value
* not thread-safe and valid only till next call
*
* \since MDAL 0.9.0
*/
MDAL_EXPORT const char *MDAL_M_metadataValue( MDAL_MeshH mesh, int index );

/**
* Adds new metadata to the mesh
*
* \since MDAL 0.9.0
*/
MDAL_EXPORT void MDAL_M_setMetadata( MDAL_MeshH mesh, const char *key, const char *val );

/**
* Returns dataset groups count
*/
Expand Down Expand Up @@ -580,6 +627,36 @@ MDAL_EXPORT MDAL_DatasetH MDAL_G_addDataset(
const int *active
);

/**
* Adds empty (new) 3D dataset to the group
* This increases dataset group count MDAL_G_datasetCount() by 1
*
* The dataset is opened in edit mode.
* To persist dataset, call MDAL_G_closeEditMode() on parent group
*
* Minimum and maximum dataset values are automatically calculated
*
* Only for 3D datasets
*
* \param group parent group handle
* \param time time for dataset (hours)
* \param values For scalar data, the size must be volume count
* For vector data , the size must be volume count * 2 (x1, y1, x2, y2, ..., xN, yN)
* \param verticalLevelCount Int Array holding the number of vertical levels for each face.
* Size must be the face count
* \param verticalExtrusion Double Array holding the vertical level values for the voxels
* Size must be Face count + Volume count
* \returns empty pointer if not possible to create dataset (e.g. group opened in read mode), otherwise handle to new dataset
*/

MDAL_EXPORT MDAL_DatasetH MDAL_G_addDataset3D(
MDAL_DatasetGroupH group,
double time,
const double *values,
const int *verticalLevelCount,
const double *verticalExtrusions
);

/**
* Returns whether dataset group is in edit mode
*/
Expand Down
6 changes: 3 additions & 3 deletions external/mdal/frmts/mdal_2dm.cpp
Expand Up @@ -376,15 +376,15 @@ std::unique_ptr<MDAL::Mesh> MDAL::Driver2dm::load( const std::string &meshFile,
return std::unique_ptr<Mesh>( mesh.release() );
}

void MDAL::Driver2dm::save( const std::string &uri, MDAL::Mesh *mesh )
void MDAL::Driver2dm::save( const std::string &fileName, const std::string &, MDAL::Mesh *mesh )
{
MDAL::Log::resetLastStatus();

std::ofstream file( uri, std::ofstream::out );
std::ofstream file( fileName, std::ofstream::out );

if ( !file.is_open() )
{
MDAL::Log::error( MDAL_Status::Err_FailToWriteToDisk, name(), "Could not open file " + uri );
MDAL::Log::error( MDAL_Status::Err_FailToWriteToDisk, name(), "Could not open file " + fileName );
}

std::string line = "MESH2D";
Expand Down
2 changes: 1 addition & 1 deletion external/mdal/frmts/mdal_2dm.hpp
Expand Up @@ -87,7 +87,7 @@ namespace MDAL

bool canReadMesh( const std::string &uri ) override;
std::unique_ptr< Mesh > load( const std::string &meshFile, const std::string &meshName = "" ) override;
void save( const std::string &uri, Mesh *mesh ) override;
void save( const std::string &fileName, const std::string &, Mesh *mesh ) override;

std::string saveMeshOnFileSuffix() const override;

Expand Down
26 changes: 25 additions & 1 deletion external/mdal/frmts/mdal_driver.cpp
Expand Up @@ -83,7 +83,8 @@ std::unique_ptr< MDAL::Mesh > MDAL::Driver::load( const std::string &, const std

void MDAL::Driver::load( const std::string &, Mesh * ) {}

void MDAL::Driver::save( const std::string &, MDAL::Mesh * ) {}
void MDAL::Driver::save( const std::string &, const std::string &, MDAL::Mesh * )
{}

void MDAL::Driver::createDatasetGroup( MDAL::Mesh *mesh, const std::string &groupName, MDAL_DataLocation dataLocation, bool hasScalarData, const std::string &datasetGroupFile )
{
Expand Down Expand Up @@ -116,4 +117,27 @@ void MDAL::Driver::createDataset( MDAL::DatasetGroup *group, MDAL::RelativeTimes
group->datasets.push_back( dataset );
}

void MDAL::Driver::createDataset( MDAL::DatasetGroup *group, MDAL::RelativeTimestamp time, const double *values, const int *verticalLevelCounts, const double *verticalExtrusions )
{
size_t count = 0;
size_t facesCount = group->mesh()->facesCount();
int maxVerticalLevel = 0;
for ( size_t i = 0; i < facesCount; i++ )
{
count += verticalLevelCounts[i];
if ( verticalLevelCounts[i] > maxVerticalLevel ) maxVerticalLevel = verticalLevelCounts[i];
};

std::shared_ptr<MDAL::MemoryDataset3D> dataset = std::make_shared< MemoryDataset3D >( group, count, maxVerticalLevel, verticalLevelCounts, verticalExtrusions );
dataset->setTime( time );

if ( !group->isScalar() )
count *= 2;

memcpy( dataset->values(), values, sizeof( double ) * count );

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

bool MDAL::Driver::persist( MDAL::DatasetGroup * ) { return true; } // failure
11 changes: 9 additions & 2 deletions external/mdal/frmts/mdal_driver.hpp
Expand Up @@ -58,7 +58,7 @@ namespace MDAL
// loads datasets
virtual void load( const std::string &uri, Mesh *mesh );
// save mesh
virtual void save( const std::string &uri, Mesh *mesh );
virtual void save( const std::string &fileName, const std::string &meshName, Mesh *mesh );

// create new dataset group
virtual void createDatasetGroup(
Expand All @@ -68,12 +68,19 @@ namespace MDAL
bool hasScalarData,
const std::string &datasetGroupFile );

// create new dataset from array
// create new 2D dataset from array
virtual void createDataset( DatasetGroup *group,
RelativeTimestamp time,
const double *values,
const int *active );

// create new 3D dataset from array
virtual void createDataset( DatasetGroup *group,
RelativeTimestamp time,
const double *values,
const int *verticalLevelCount,
const double *verticalExtrusion );

// persist to the file
// returns true on error, false on success
virtual bool persist( DatasetGroup *group );
Expand Down
6 changes: 3 additions & 3 deletions external/mdal/frmts/mdal_selafin.cpp
Expand Up @@ -728,7 +728,7 @@ bool MDAL::DriverSelafin::saveDatasetGroupOnFile( MDAL::DatasetGroup *datasetGro
if ( ! MDAL::fileExists( fileName ) )
{
//create a new mesh file
save( fileName, datasetGroup->mesh() );
save( fileName, "", datasetGroup->mesh() );

if ( ! MDAL::fileExists( fileName ) )
throw MDAL::Error( MDAL_Status::Err_FailToWriteToDisk, "Unable to create new file" );
Expand Down Expand Up @@ -983,9 +983,9 @@ static void writeVertices( std::ofstream &file, MDAL::Mesh *mesh )
writeValueArrayRecord( file, yValues );
}

void MDAL::DriverSelafin::save( const std::string &uri, MDAL::Mesh *mesh )
void MDAL::DriverSelafin::save( const std::string &fileName, const std::string &, MDAL::Mesh *mesh )
{
std::ofstream file( uri.c_str(), std::ofstream::binary );
std::ofstream file( fileName.c_str(), std::ofstream::binary );

std::string header( "Selafin file created by MDAL library" );
std::string remainingStr( " ", 72 - header.size() );
Expand Down
2 changes: 1 addition & 1 deletion external/mdal/frmts/mdal_selafin.hpp
Expand Up @@ -325,7 +325,7 @@ namespace MDAL
bool persist( DatasetGroup *group ) override;

int faceVerticesMaximumCount() const override {return 3;}
void save( const std::string &uri, Mesh *mesh ) override;
void save( const std::string &fileName, const std::string &meshName, Mesh *mesh ) override;

std::string writeDatasetOnFileSuffix() const override;
std::string saveMeshOnFileSuffix() const override;
Expand Down
12 changes: 5 additions & 7 deletions external/mdal/frmts/mdal_ugrid.cpp
Expand Up @@ -18,12 +18,10 @@
MDAL::DriverUgrid::DriverUgrid()
: DriverCF(
"Ugrid",
"UGRID Results",
"UGRID",
"*.nc",
Capability::ReadMesh | Capability::SaveMesh )
{

}
{}

MDAL::DriverUgrid *MDAL::DriverUgrid::create()
{
Expand Down Expand Up @@ -673,9 +671,9 @@ void MDAL::DriverUgrid::parse2VariablesFromAttribute( const std::string &name, c
}
}

void MDAL::DriverUgrid::save( const std::string &uri, MDAL::Mesh *mesh )
void MDAL::DriverUgrid::save( const std::string &fileName, const std::string &, MDAL::Mesh *mesh )
{
mFileName = uri;
mFileName = fileName;

try
{
Expand All @@ -691,7 +689,7 @@ void MDAL::DriverUgrid::save( const std::string &uri, MDAL::Mesh *mesh )
}
catch ( MDAL_Status error )
{
MDAL::Log::error( error, name(), "could not save file " + uri );
MDAL::Log::error( error, name(), "could not save file " + fileName );
}
catch ( MDAL::Error err )
{
Expand Down
3 changes: 2 additions & 1 deletion external/mdal/frmts/mdal_ugrid.hpp
Expand Up @@ -26,7 +26,8 @@ namespace MDAL
DriverUgrid();
~DriverUgrid() override = default;
DriverUgrid *create() override;
void save( const std::string &uri, Mesh *mesh ) override;
void save( const std::string &fileName, const std::string &meshName, Mesh *mesh ) override;

std::string saveMeshOnFileSuffix() const override;

private:
Expand Down

0 comments on commit 64b5ce1

Please sign in to comment.