Skip to content
Permalink
Browse files

[mesh] [MDAL] update to 0.0.4: add support for GRIB and XMDF formats

  • Loading branch information
PeterPetrik authored and wonder-sk committed Jul 13, 2018
1 parent 7933c85 commit 14fa499ed3ce0358dd4835cd1f43b4b93df8f473
@@ -0,0 +1,12 @@
#ifndef MDAL_CONFIG_HPP
#define MDAL_CONFIG_HPP

#cmakedefine MDAL_VERSION

#cmakedefine HAVE_HDF5

#cmakedefine HAVE_GDAL

#endif // MDAL_CONFIG_HPP


@@ -26,12 +26,6 @@ std::unique_ptr<MDAL::Mesh> MDAL::Loader2dm::load( MDAL_Status *status )
{
if ( status ) *status = MDAL_Status::None;

if ( !MDAL::fileExists( mMeshFile ) )
{
if ( status ) *status = MDAL_Status::Err_FileNotFound;
return nullptr;
}

std::ifstream in( mMeshFile, std::ifstream::in );
std::string line;
if ( !std::getline( in, line ) || !startsWith( line, "MESH2D" ) )
@@ -177,7 +177,7 @@ void MDAL::LoaderAsciiDat::load( MDAL::Mesh *mesh, MDAL_Status *status )

void MDAL::LoaderAsciiDat::addDatasets( MDAL::Mesh *mesh,
const std::string &name,
const std::vector<std::shared_ptr<Dataset>> &datOutputs ) const
const Datasets &datOutputs ) const
{
for ( const std::shared_ptr<Dataset> &ds : datOutputs )
{
@@ -194,7 +194,9 @@ void MDAL::LoaderAsciiDat::addDatasets( MDAL::Mesh *mesh,
);
}

void MDAL::LoaderAsciiDat::readVertexTimestep( const MDAL::Mesh *mesh, std::vector<std::shared_ptr<MDAL::Dataset> > &datOutputs, double t, bool isVector, bool hasStatus, std::ifstream &stream )
void MDAL::LoaderAsciiDat::readVertexTimestep( const MDAL::Mesh *mesh, Datasets &datOutputs,
double t, bool isVector,
bool hasStatus, std::ifstream &stream )
{
size_t vertexCount = mesh->vertices.size();
size_t faceCount = mesh->faces.size();
@@ -259,7 +261,7 @@ void MDAL::LoaderAsciiDat::readVertexTimestep( const MDAL::Mesh *mesh, std::vect
datOutputs.push_back( std::move( dataset ) );
}

void MDAL::LoaderAsciiDat::readFaceTimestep( const MDAL::Mesh *mesh, std::vector<std::shared_ptr<MDAL::Dataset> > &datOutputs, double t, bool isVector, std::ifstream &stream )
void MDAL::LoaderAsciiDat::readFaceTimestep( const MDAL::Mesh *mesh, Datasets &datOutputs, double t, bool isVector, std::ifstream &stream )
{
size_t faceCount = mesh->faces.size();

@@ -28,22 +28,22 @@ namespace MDAL
private:
void readVertexTimestep(
const Mesh *mesh,
std::vector<std::shared_ptr<Dataset>> &datOutputs,
Datasets &datOutputs,
double t,
bool isVector,
bool hasStatus,
std::ifstream &stream );

void readFaceTimestep(
const Mesh *mesh,
std::vector<std::shared_ptr<Dataset>> &datOutputs,
Datasets &datOutputs,
double t,
bool isVector,
std::ifstream &stream );

void addDatasets( MDAL::Mesh *mesh,
const std::string &name,
const std::vector<std::shared_ptr<Dataset>> &datOutputs ) const;
const Datasets &datOutputs ) const;

std::string mDatFile;
};
@@ -33,11 +33,8 @@ static const int CT_NUMCELLS = 180;
static const int CT_NAME = 190;
static const int CT_TS = 200;
static const int CT_ENDDS = 210;
#if 0
static const int CT_RT_JULIAN = 240;
static const int CT_TIMEUNITS = 250;
#endif

//static const int CT_RT_JULIAN = 240;
//static const int CT_TIMEUNITS = 250;
static const int CT_2D_MESHES = 3;
static const int CT_FLOAT_SIZE = 4;
static const int CF_FLAG_SIZE = 1;
@@ -65,7 +62,7 @@ static bool readIStat( std::ifstream &in, int sflg, char *flag )
else
{
int istat;
in.read( ( char * )&istat, sflg );
in.read( reinterpret_cast< char * >( &istat ), sflg );
if ( !in )
return true; // error
else
@@ -122,19 +119,19 @@ void MDAL::LoaderBinaryDat::load( MDAL::Mesh *mesh, MDAL_Status *status )
char istat;
float time;

if ( read( in, ( char * )&version, 4 ) )
if ( read( in, reinterpret_cast< char * >( &version ), 4 ) )
EXIT_WITH_ERROR( MDAL_Status::Err_UnknownFormat );

if ( version != CT_VERSION ) // Version should be 3000
EXIT_WITH_ERROR( MDAL_Status::Err_UnknownFormat );

bool isVector = false;
std::string baseDatasetName;
std::vector<std::shared_ptr<Dataset>> datOutputs; // DAT outputs data
Datasets datOutputs; // DAT outputs data

while ( card != CT_ENDDS )
{
if ( read( in, ( char * )&card, 4 ) )
if ( read( in, reinterpret_cast< char * >( &card ), 4 ) )
{
// We've reached the end of the file and there was no ends card
break;
@@ -145,19 +142,19 @@ void MDAL::LoaderBinaryDat::load( MDAL::Mesh *mesh, MDAL_Status *status )

case CT_OBJTYPE:
// Object type
if ( read( in, ( char * )&objecttype, 4 ) || objecttype != CT_2D_MESHES )
if ( read( in, reinterpret_cast< char * >( &objecttype ), 4 ) || objecttype != CT_2D_MESHES )
EXIT_WITH_ERROR( MDAL_Status::Err_UnknownFormat );
break;

case CT_SFLT:
// Float size
if ( read( in, ( char * )&sflt, 4 ) || sflt != CT_FLOAT_SIZE )
if ( read( in, reinterpret_cast< char * >( &sflt ), 4 ) || sflt != CT_FLOAT_SIZE )
EXIT_WITH_ERROR( MDAL_Status::Err_UnknownFormat );
break;

case CT_SFLG:
// Flag size
if ( read( in, ( char * )&sflg, 4 ) )
if ( read( in, reinterpret_cast< char * >( &sflg ), 4 ) )
if ( sflg != CF_FLAG_SIZE && sflg != CF_FLAG_INT_SIZE )
EXIT_WITH_ERROR( MDAL_Status::Err_UnknownFormat );
break;
@@ -172,35 +169,35 @@ void MDAL::LoaderBinaryDat::load( MDAL::Mesh *mesh, MDAL_Status *status )

case CT_VECTYPE:
// Vector type
if ( read( in, ( char * )&vectype, 4 ) || vectype != 0 )
if ( read( in, reinterpret_cast< char * >( &vectype ), 4 ) || vectype != 0 )
EXIT_WITH_ERROR( MDAL_Status::Err_UnknownFormat );
break;

case CT_OBJID:
// Object id
if ( read( in, ( char * )&objid, 4 ) )
if ( read( in, reinterpret_cast< char * >( &objid ), 4 ) )
EXIT_WITH_ERROR( MDAL_Status::Err_UnknownFormat );
break;

case CT_NUMDATA:
// Num data
if ( read( in, ( char * )&numdata, 4 ) )
if ( read( in, reinterpret_cast< char * >( &numdata ), 4 ) )
EXIT_WITH_ERROR( MDAL_Status::Err_UnknownFormat );
if ( numdata != ( int ) vertexCount )
if ( numdata != static_cast< int >( vertexCount ) )
EXIT_WITH_ERROR( MDAL_Status::Err_IncompatibleMesh );
break;

case CT_NUMCELLS:
// Num data
if ( read( in, ( char * )&numcells, 4 ) )
if ( read( in, reinterpret_cast< char * >( &numcells ), 4 ) )
EXIT_WITH_ERROR( MDAL_Status::Err_UnknownFormat );
if ( numcells != ( int ) elemCount )
if ( numcells != static_cast< int >( elemCount ) )
EXIT_WITH_ERROR( MDAL_Status::Err_IncompatibleMesh );
break;

case CT_NAME:
// Name
if ( read( in, ( char * )&name, 40 ) )
if ( read( in, reinterpret_cast< char * >( &name ), 40 ) )
EXIT_WITH_ERROR( MDAL_Status::Err_UnknownFormat );
if ( name[39] != 0 )
name[39] = 0;
@@ -212,7 +209,7 @@ void MDAL::LoaderBinaryDat::load( MDAL::Mesh *mesh, MDAL_Status *status )
if ( readIStat( in, sflg, &istat ) )
EXIT_WITH_ERROR( MDAL_Status::Err_UnknownFormat );

if ( read( in, ( char * )&time, 4 ) )
if ( read( in, reinterpret_cast< char * >( &time ), 4 ) )
EXIT_WITH_ERROR( MDAL_Status::Err_UnknownFormat );

if ( readVertexTimestep( mesh, datOutputs, time, isVector, istat, sflg, in ) )
@@ -231,7 +228,7 @@ void MDAL::LoaderBinaryDat::load( MDAL::Mesh *mesh, MDAL_Status *status )

void MDAL::LoaderBinaryDat::addDatasets( MDAL::Mesh *mesh,
const std::string &name,
const std::vector<std::shared_ptr<Dataset>> &datOutputs ) const
const Datasets &datOutputs ) const
{
for ( const std::shared_ptr<Dataset> &ds : datOutputs )
{
@@ -249,7 +246,7 @@ void MDAL::LoaderBinaryDat::addDatasets( MDAL::Mesh *mesh,
);
}

bool MDAL::LoaderBinaryDat::readVertexTimestep( const MDAL::Mesh *mesh, std::vector<std::shared_ptr<MDAL::Dataset> > &datOutputs, float time,
bool MDAL::LoaderBinaryDat::readVertexTimestep( const MDAL::Mesh *mesh, MDAL::Datasets &datOutputs, float time,
bool isVector, bool hasStatus, int sflg, std::ifstream &in )
{
size_t vertexCount = mesh->vertices.size();
@@ -271,7 +268,7 @@ bool MDAL::LoaderBinaryDat::readVertexTimestep( const MDAL::Mesh *mesh, std::vec
{
if ( hasStatus )
{
if ( readIStat( in, sflg, ( char * )&active ) )
if ( readIStat( in, sflg, reinterpret_cast< char * >( &active ) ) )
return true; //error

}
@@ -284,22 +281,22 @@ bool MDAL::LoaderBinaryDat::readVertexTimestep( const MDAL::Mesh *mesh, std::vec
{
float x, y;

if ( read( in, ( char * )&x, 4 ) )
if ( read( in, reinterpret_cast< char * >( &x ), 4 ) )
return true; //error
if ( read( in, ( char * )&y, 4 ) )
if ( read( in, reinterpret_cast< char * >( &y ), 4 ) )
return true; //error

dataset->values[i].x = x;
dataset->values[i].y = y;
dataset->values[i].x = static_cast< double >( x );
dataset->values[i].y = static_cast< double >( y );
}
else
{
float scalar;

if ( read( in, ( char * )&scalar, 4 ) )
if ( read( in, reinterpret_cast< char * >( &scalar ), 4 ) )
return true; //error

dataset->values[i].x = scalar;
dataset->values[i].x = static_cast< double >( scalar );
}
}

@@ -26,18 +26,17 @@ namespace MDAL
void load( Mesh *mesh, MDAL_Status *status );

private:
bool readVertexTimestep(
const Mesh *mesh,
std::vector<std::shared_ptr<Dataset>> &datOutputs,
float time,
bool isVector,
bool hasStatus,
int sflg,
std::ifstream &in );
bool readVertexTimestep( const Mesh *mesh,
Datasets &datOutputs,
float time,
bool isVector,
bool hasStatus,
int sflg,
std::ifstream &in );

void addDatasets( MDAL::Mesh *mesh,
const std::string &name,
const std::vector<std::shared_ptr<Dataset>> &datOutputs ) const;
const Datasets &datOutputs ) const;

std::string mDatFile;
};

0 comments on commit 14fa499

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