Skip to content

Commit

Permalink
Changes for release 1.0.0 (#434)
Browse files Browse the repository at this point in the history
* retrieve exact behavior of FLO2D format before #424

* fix mingw build

* fix narrowing conversion

* ver++

* typo
  • Loading branch information
vcloarec committed Oct 12, 2022
1 parent 8a57c04 commit d942911
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 23 deletions.
2 changes: 1 addition & 1 deletion mdal/frmts/mdal_flo2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1257,7 +1257,7 @@ bool MDAL::DriverFlo2D::appendGroup( HdfFile &file, MDAL::DatasetGroup *dsGroup,
{
dsGroupName = dsGroup->name() + "_" + std::to_string( i ); // make sure we have unique group name
}
HdfGroup group = file.createGroup( "/TIMDEP NETCDF OUTPUT RESULTS/" + dsGroupName );
HdfGroup group = file.createGroup( groupTNOR.id(), "/TIMDEP NETCDF OUTPUT RESULTS/" + dsGroupName );

HdfAttribute attDataType( group.id(), "Data Type", H5T_NATIVE_INT );
attDataType.write( 0 );
Expand Down
12 changes: 6 additions & 6 deletions mdal/frmts/mdal_hdf5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ void HdfAttribute::write( int value )
}

HdfDataset::HdfDataset( HdfFile::SharedHandle file, const std::string &path, HdfDataType dtype, size_t nItems )
: mType( dtype )
, mFile( file )
: mFile( file ),
mType( dtype )
{
// Crete dataspace for attribute
std::vector<hsize_t> dimsSingle = {nItems};
Expand All @@ -171,15 +171,15 @@ HdfDataset::HdfDataset( HdfFile::SharedHandle file, const std::string &path, Hdf


HdfDataset::HdfDataset( HdfFile::SharedHandle file, const std::string &path, HdfDataType dtype, HdfDataspace dataspace )
: mType( dtype )
, mFile( file )
: mFile( file ),
mType( dtype )
{
d = std::make_shared< Handle >( H5Dcreate2( file->id, path.c_str(), dtype.id(), dataspace.id(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT ) );
}

HdfDataset::HdfDataset( HdfFile::SharedHandle file, const std::string &path )
: d( std::make_shared< Handle >( H5Dopen2( file->id, path.c_str(), H5P_DEFAULT ) ) )
, mFile( file )
: mFile( file ),
d( std::make_shared< Handle >( H5Dopen2( file->id, path.c_str(), H5P_DEFAULT ) ) )
{
}

Expand Down
14 changes: 14 additions & 0 deletions mdal/frmts/mdal_hdf5.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,16 @@ class HdfFile
inline std::vector<std::string> groups() const;

inline HdfGroup group( const std::string &path ) const;

//! Creates a group with an absolute path
inline HdfGroup createGroup( const std::string &path ) const;

/**
* Creates a group with the id of location and a path that can be relative from the location
* (see https://docs.hdfgroup.org/hdf5/v1_12/group___h5_g.html#ga86d93295965f750ef25dea2505a711d9)
*/
inline HdfGroup createGroup( hid_t locationId, const std::string &path ) const;

inline HdfDataset dataset( const std::string &path ) const;
inline HdfDataset dataset( const std::string &path, HdfDataType dtype, size_t nItems = 1 ) const;
inline HdfDataset dataset( const std::string &path, HdfDataType dtype, HdfDataspace dataspace ) const;
Expand Down Expand Up @@ -319,6 +328,11 @@ inline HdfGroup HdfFile::createGroup( const std::string &path ) const
return HdfGroup( std::make_shared< HdfGroup::Handle >( H5Gcreate2( d->id, path.c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT ) ), d );
}

inline HdfGroup HdfFile::createGroup( hid_t locationId, const std::string &path ) const
{
return HdfGroup( std::make_shared< HdfGroup::Handle >( H5Gcreate2( locationId, path.c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT ) ), d );
}

inline HdfDataset HdfFile::dataset( const std::string &path ) const { return HdfDataset( d, path ); }

inline HdfDataset HdfFile::dataset( const std::string &path, HdfDataType dtype, size_t nItems ) const { return HdfDataset( d, path, dtype, nItems ); }
Expand Down
12 changes: 6 additions & 6 deletions mdal/frmts/mdal_netcdf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ std::vector<double> NetCDFFile::readDoubleArr( const std::string &name, size_t d
if ( nc_get_var_longlong( mNcid, arr_id, arr_val_int.data() ) != NC_NOERR ) throw MDAL::Error( MDAL_Status::Err_UnknownFormat, "Could not read integer array" );
for ( size_t i = 0; i < dim; ++i )
{
arr_val[i] = arr_val_int[i];
arr_val[i] = static_cast<double>( arr_val_int[i] );
}
}
else if ( typep == NC_UINT64 )
Expand All @@ -141,7 +141,7 @@ std::vector<double> NetCDFFile::readDoubleArr( const std::string &name, size_t d
if ( nc_get_var_ulonglong( mNcid, arr_id, arr_val_int.data() ) != NC_NOERR ) throw MDAL::Error( MDAL_Status::Err_UnknownFormat, "Could not read integer array" );
for ( size_t i = 0; i < dim; ++i )
{
arr_val[i] = arr_val_int[i];
arr_val[i] = static_cast<double>( arr_val_int[i] );
}
}
else
Expand Down Expand Up @@ -220,7 +220,7 @@ std::vector<double> NetCDFFile::readDoubleArr( int arr_id,
if ( nc_get_vars_longlong( mNcid, arr_id, startp.data(), countp.data(), stridep.data(), arr_val_int.data() ) != NC_NOERR ) throw MDAL::Error( MDAL_Status::Err_UnknownFormat, "Could not read double array" );
for ( size_t i = 0; i < count_dim1 * count_dim2; ++i )
{
arr_val[i] = arr_val_int[i];
arr_val[i] = static_cast<double>( arr_val_int[i] );
}
}
else if ( typep == NC_UINT64 )
Expand All @@ -229,7 +229,7 @@ std::vector<double> NetCDFFile::readDoubleArr( int arr_id,
if ( nc_get_vars_ulonglong( mNcid, arr_id, startp.data(), countp.data(), stridep.data(), arr_val_int.data() ) != NC_NOERR ) throw MDAL::Error( MDAL_Status::Err_UnknownFormat, "Could not read double array" );
for ( size_t i = 0; i < count_dim1 * count_dim2; ++i )
{
arr_val[i] = arr_val_int[i];
arr_val[i] = static_cast<double>( arr_val_int[i] );
}
}
else
Expand Down Expand Up @@ -300,7 +300,7 @@ std::vector<double> NetCDFFile::readDoubleArr( int arr_id,
if ( nc_get_vars_longlong( mNcid, arr_id, startp.data(), countp.data(), stridep.data(), arr_val_int.data() ) != NC_NOERR ) throw MDAL::Error( MDAL_Status::Err_UnknownFormat, "Could not read double array" );
for ( size_t i = 0; i < count_dim; ++i )
{
arr_val[i] = arr_val_int[i];
arr_val[i] = static_cast<double>( arr_val_int[i] );
}
}
else if ( typep == NC_UINT64 )
Expand All @@ -309,7 +309,7 @@ std::vector<double> NetCDFFile::readDoubleArr( int arr_id,
if ( nc_get_vars_ulonglong( mNcid, arr_id, startp.data(), countp.data(), stridep.data(), arr_val_int.data() ) != NC_NOERR ) throw MDAL::Error( MDAL_Status::Err_UnknownFormat, "Could not read double array" );
for ( size_t i = 0; i < count_dim; ++i )
{
arr_val[i] = arr_val_int[i];
arr_val[i] = static_cast<double>( arr_val_int[i] );
}
}
else
Expand Down
2 changes: 1 addition & 1 deletion mdal/mdal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static const char *EMPTY_STR = "";

const char *MDAL_Version()
{
return "0.9.90";
return "1.0.0";
}

MDAL_Status MDAL_LastStatus()
Expand Down
18 changes: 9 additions & 9 deletions mdal/mdal_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <ctime>
#include <stdlib.h>

#ifdef _WIN32
#ifdef _MSC_VER
#define UNICODE
#include <locale>
#include <codecvt>
Expand All @@ -38,7 +38,7 @@ std::string MDAL::getEnvVar( const std::string &varname, const std::string &defa

bool MDAL::openInputFile( std::ifstream &inputFileStream, const std::string &fileName, std::ios_base::openmode mode )
{
#ifdef _WIN32
#ifdef _MSC_VER
std::wstring_convert< std::codecvt_utf8_utf16< wchar_t > > converter;
std::wstring wStr = converter.from_bytes( fileName );
inputFileStream.open( wStr, std::ifstream::in | mode );
Expand All @@ -53,7 +53,7 @@ std::ifstream MDAL::openInputFile( const std::string &fileName, std::ios_base::o
{
std::ifstream ret;

#ifdef _WIN32
#ifdef _MSC_VER
std::wstring_convert< std::codecvt_utf8_utf16< wchar_t > > converter;
std::wstring wStr = converter.from_bytes( fileName );
ret.open( wStr, mode );
Expand All @@ -68,7 +68,7 @@ std::ofstream MDAL::openOutputFile( const std::string &fileName, std::ios_base::
{
std::ofstream ret;

#ifdef _WIN32
#ifdef _MSC_VER
std::wstring_convert< std::codecvt_utf8_utf16< wchar_t > > converter;
std::wstring wStr = converter.from_bytes( fileName );
ret.open( wStr, mode );
Expand Down Expand Up @@ -263,7 +263,7 @@ std::string MDAL::fileExtension( const std::string &path )
std::string MDAL::pathJoin( const std::string &path1, const std::string &path2 )
{
//https://stackoverflow.com/questions/6297738/how-to-build-a-full-path-string-safely-from-separate-strings#6297807
#ifdef _WIN32
#ifdef _MSC_VER
return path1 + "\\" + path2;
#else
return path1 + "/" + path2;
Expand Down Expand Up @@ -292,7 +292,7 @@ bool MDAL::contains( const std::string &str, const std::string &substr, Contains
substr.begin(), substr.end(),
[]( char ch1, char ch2 )
{
#ifdef _WIN32
#ifdef _MSC_VER
return toupper( ch1 ) == toupper( ch2 );
#else
return std::toupper( ch1 ) == std::toupper( ch2 );
Expand Down Expand Up @@ -343,7 +343,7 @@ std::string MDAL::leftJustified( const std::string &str, size_t width, char fill
std::string MDAL::toLower( const std::string &std )
{
std::string res( std );
#ifdef _WIN32
#ifdef _MSC_VER
//silence algorithm(1443): warning C4244: '=': conversion from 'int' to 'char'
std::transform( res.begin(), res.end(), res.begin(),
[]( char c ) {return static_cast<char>( ::tolower( c ) );} );
Expand Down Expand Up @@ -401,7 +401,7 @@ std::string MDAL::trim( const std::string &s, const std::string &delimiters )
return ltrim( rtrim( s, delimiters ), delimiters );
}

#ifdef _WIN32
#ifdef _MSC_VER
static std::string utf8ToWin32Recode( const std::string &utf8String )
{
//from GDAL: ./port/cpl_recode_stub.cpp, CPLWin32Recode()
Expand Down Expand Up @@ -429,7 +429,7 @@ static std::string utf8ToWin32Recode( const std::string &utf8String )
std::string MDAL::systemFileName( const std::string &utf8FileName )
{
std::string ret;
#ifdef _WIN32
#ifdef _MSC_VER
ret = utf8ToWin32Recode( utf8FileName );
#else
ret = utf8FileName;
Expand Down

0 comments on commit d942911

Please sign in to comment.