Skip to content
Permalink
Browse files

update MDAL to 0.6.91 (#37937)

  • Loading branch information
PeterPetrik committed Jul 23, 2020
1 parent d35f38b commit ea74e863e38f9e99603e64d398c692d5277e0a94
Showing with 30 additions and 15 deletions.
  1. +28 −13 external/mdal/frmts/mdal_selafin.cpp
  2. +2 −2 external/mdal/frmts/mdal_selafin.hpp
@@ -49,7 +49,22 @@ void MDAL::SelafinFile::initialize()
mFileSize = mIn.tellg();
mIn.seekg( 0, mIn.beg );

mIsNativeLittleEndian = MDAL::isNativeLittleEndian();
mChangeEndianness = MDAL::isNativeLittleEndian();

//Check if need to change the endianness
// read first size_t that has to be 80
size_t firstInt = readSizeT();
mIn.seekg( 0, mIn.beg );
if ( firstInt != 80 )
{
mChangeEndianness = !mChangeEndianness;
//Retry
firstInt = readSizeT();
if ( firstInt != 80 )
throw MDAL::Error( MDAL_Status::Err_UnknownFormat, "File " + mFileName + " could not be open" );
mIn.seekg( 0, mIn.beg );
}

mParsed = false;
}

@@ -282,7 +297,7 @@ std::vector<double> MDAL::SelafinFile::datasetValues( size_t timeStepIndex, size
{
if ( !mParsed )
parseFile();
if ( variableIndex < mVariableStreamPosition.size() && timeStepIndex < mVariableStreamPosition[timeStepIndex].size() )
if ( variableIndex < mVariableStreamPosition.size() && timeStepIndex < mVariableStreamPosition[variableIndex].size() )
return readDoubleArr( mVariableStreamPosition[variableIndex][timeStepIndex], offset, count );
else
return std::vector<double>();
@@ -403,7 +418,7 @@ void MDAL::SelafinFile::populateDataset( MDAL::Mesh *mesh, std::shared_ptr<MDAL:

std::string MDAL::SelafinFile::readString( size_t len )
{
size_t length = readSizet();
size_t length = readSizeT();
if ( length != len ) throw MDAL::Error( MDAL_Status::Err_UnknownFormat, "Unable to read string" );
std::string ret = readStringWithoutLength( len );
ignoreArrayLength();
@@ -412,7 +427,7 @@ std::string MDAL::SelafinFile::readString( size_t len )

std::vector<double> MDAL::SelafinFile::readDoubleArr( size_t len )
{
size_t length = readSizet();
size_t length = readSizeT();
if ( mStreamInFloatPrecision )
{
if ( length != len * 4 )
@@ -450,7 +465,7 @@ std::vector<double> MDAL::SelafinFile::readDoubleArr( const std::streampos &posi

std::vector<int> MDAL::SelafinFile::readIntArr( size_t len )
{
size_t length = readSizet();
size_t length = readSizeT();
if ( length != len * 4 ) throw MDAL::Error( MDAL_Status::Err_UnknownFormat, "File format problem while reading int array" );
std::vector<int> ret( len );
for ( size_t i = 0; i < len; ++i )
@@ -500,13 +515,13 @@ double MDAL::SelafinFile::readDouble( )
if ( mStreamInFloatPrecision )
{
float ret_f;
if ( !readValue( ret_f, mIn, mIsNativeLittleEndian ) )
if ( !readValue( ret_f, mIn, mChangeEndianness ) )
throw MDAL::Error( MDAL_Status::Err_UnknownFormat, "Reading double failed" );
ret = static_cast<double>( ret_f );
}
else
{
if ( !readValue( ret, mIn, mIsNativeLittleEndian ) )
if ( !readValue( ret, mIn, mChangeEndianness ) )
throw MDAL::Error( MDAL_Status::Err_UnknownFormat, "Reading double failed" );
}
return ret;
@@ -520,7 +535,7 @@ int MDAL::SelafinFile::readInt( )
if ( mIn.read( reinterpret_cast< char * >( &data ), 4 ) )
if ( !mIn )
throw MDAL::Error( MDAL_Status::Err_UnknownFormat, "Unable to open stream for reading int" );
if ( mIsNativeLittleEndian )
if ( mChangeEndianness )
{
std::reverse( reinterpret_cast< char * >( &data ), reinterpret_cast< char * >( &data ) + 4 );
}
@@ -531,26 +546,26 @@ int MDAL::SelafinFile::readInt( )
return var;
}

size_t MDAL::SelafinFile::readSizet()
size_t MDAL::SelafinFile::readSizeT()
{
int var = readInt( );
return static_cast<size_t>( var );
}

bool MDAL::SelafinFile::checkIntArraySize( size_t len )
{
return ( len * 4 == readSizet() );
return ( len * 4 == readSizeT() );
}

bool MDAL::SelafinFile::checkDoubleArraySize( size_t len )
{
if ( mStreamInFloatPrecision )
{
return ( len * 4 ) == readSizet();
return ( len * 4 ) == readSizeT();
}
else
{
return ( len * 8 ) == readSizet();
return ( len * 8 ) == readSizeT();
}
}

@@ -780,7 +795,7 @@ void MDAL::MeshSelafin::calculateExtent() const
}
index += count;
}
while ( count == 0 );
while ( count != 0 );

mExtent = MDAL::computeExtent( vertices );
mIsExtentUpToDate = true;
@@ -127,7 +127,7 @@ namespace MDAL

double readDouble( );
int readInt( );
size_t readSizet( );
size_t readSizeT( );

void ignoreArrayLength( );
std::string readStringWithoutLength( size_t len );
@@ -157,7 +157,7 @@ namespace MDAL

std::string mFileName;
bool mStreamInFloatPrecision = true;
bool mIsNativeLittleEndian = true;
bool mChangeEndianness = true;
long long mFileSize = -1;

std::ifstream mIn;

0 comments on commit ea74e86

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