From d942911448fbecbf56e9550fc8232fc8380a89e8 Mon Sep 17 00:00:00 2001 From: Vincent Cloarec Date: Wed, 12 Oct 2022 08:39:48 -0400 Subject: [PATCH] Changes for release 1.0.0 (#434) * retrieve exact behavior of FLO2D format before #424 * fix mingw build * fix narrowing conversion * ver++ * typo --- mdal/frmts/mdal_flo2d.cpp | 2 +- mdal/frmts/mdal_hdf5.cpp | 12 ++++++------ mdal/frmts/mdal_hdf5.hpp | 14 ++++++++++++++ mdal/frmts/mdal_netcdf.cpp | 12 ++++++------ mdal/mdal.cpp | 2 +- mdal/mdal_utils.cpp | 18 +++++++++--------- 6 files changed, 37 insertions(+), 23 deletions(-) diff --git a/mdal/frmts/mdal_flo2d.cpp b/mdal/frmts/mdal_flo2d.cpp index 150e49c8..58cc0371 100644 --- a/mdal/frmts/mdal_flo2d.cpp +++ b/mdal/frmts/mdal_flo2d.cpp @@ -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 ); diff --git a/mdal/frmts/mdal_hdf5.cpp b/mdal/frmts/mdal_hdf5.cpp index e49df88c..8e9d2f95 100644 --- a/mdal/frmts/mdal_hdf5.cpp +++ b/mdal/frmts/mdal_hdf5.cpp @@ -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 dimsSingle = {nItems}; @@ -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 ) ) ) { } diff --git a/mdal/frmts/mdal_hdf5.hpp b/mdal/frmts/mdal_hdf5.hpp index ee293acc..1f09e9d2 100644 --- a/mdal/frmts/mdal_hdf5.hpp +++ b/mdal/frmts/mdal_hdf5.hpp @@ -76,7 +76,16 @@ class HdfFile inline std::vector 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; @@ -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 ); } diff --git a/mdal/frmts/mdal_netcdf.cpp b/mdal/frmts/mdal_netcdf.cpp index 64cf9204..6be69f50 100644 --- a/mdal/frmts/mdal_netcdf.cpp +++ b/mdal/frmts/mdal_netcdf.cpp @@ -132,7 +132,7 @@ std::vector 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( arr_val_int[i] ); } } else if ( typep == NC_UINT64 ) @@ -141,7 +141,7 @@ std::vector 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( arr_val_int[i] ); } } else @@ -220,7 +220,7 @@ std::vector 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( arr_val_int[i] ); } } else if ( typep == NC_UINT64 ) @@ -229,7 +229,7 @@ std::vector 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( arr_val_int[i] ); } } else @@ -300,7 +300,7 @@ std::vector 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( arr_val_int[i] ); } } else if ( typep == NC_UINT64 ) @@ -309,7 +309,7 @@ std::vector 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( arr_val_int[i] ); } } else diff --git a/mdal/mdal.cpp b/mdal/mdal.cpp index 62e749ae..6394e751 100644 --- a/mdal/mdal.cpp +++ b/mdal/mdal.cpp @@ -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() diff --git a/mdal/mdal_utils.cpp b/mdal/mdal_utils.cpp index f3380b32..efcbc1b6 100644 --- a/mdal/mdal_utils.cpp +++ b/mdal/mdal_utils.cpp @@ -16,7 +16,7 @@ #include #include -#ifdef _WIN32 +#ifdef _MSC_VER #define UNICODE #include #include @@ -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 ); @@ -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 ); @@ -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 ); @@ -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; @@ -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 ); @@ -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( ::tolower( c ) );} ); @@ -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() @@ -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;