Skip to content
Permalink
Browse files
mdal 0.8.92
  • Loading branch information
PeterPetrik authored and nyalldawson committed Aug 18, 2021
1 parent 7c75c4c commit 64b5ce1648514ccb0b42e681c3cf2974816998f3
@@ -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
*/
@@ -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
///////////////////////////////////////////////////////////////////////////////////////
@@ -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
@@ -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 );

@@ -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
*/
@@ -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
*/
@@ -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";
@@ -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;

@@ -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 )
{
@@ -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
@@ -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(
@@ -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 );
@@ -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" );
@@ -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() );
@@ -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;
@@ -18,12 +18,10 @@
MDAL::DriverUgrid::DriverUgrid()
: DriverCF(
"Ugrid",
"UGRID Results",
"UGRID",
"*.nc",
Capability::ReadMesh | Capability::SaveMesh )
{

}
{}

MDAL::DriverUgrid *MDAL::DriverUgrid::create()
{
@@ -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
{
@@ -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 )
{
@@ -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:

0 comments on commit 64b5ce1

Please sign in to comment.