2021-04-11 08:51:32 +02:00
|
|
|
#ifdef USE_HDF5
|
|
|
|
|
|
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
|
|
#include "RiaTestDataDirectory.h"
|
|
|
|
|
#include "RifHdf5Exporter.h"
|
|
|
|
|
#include "RifHdf5SummaryReader.h"
|
|
|
|
|
#include "RifOpmHdf5Summary.h"
|
|
|
|
|
#include "RifReaderEclipseSummary.h"
|
|
|
|
|
|
2023-04-24 10:13:31 +02:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
|
#pragma warning( disable : 4251 )
|
|
|
|
|
#endif
|
2021-04-11 08:51:32 +02:00
|
|
|
#include "H5Cpp.h"
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
|
#include "RifHdf5SummaryExporter.h"
|
2022-07-07 16:42:06 +02:00
|
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
|
// Disable warning from external library to make sure treat warnings as error works
|
|
|
|
|
#pragma warning( disable : 4267 )
|
|
|
|
|
#endif
|
2021-04-11 08:51:32 +02:00
|
|
|
#include "opm/io/eclipse/ESmry.hpp"
|
|
|
|
|
#include <numeric>
|
|
|
|
|
|
2026-07-30 12:57:36 +02:00
|
|
|
#include <QByteArray>
|
|
|
|
|
#include <QFile>
|
|
|
|
|
#include <QTemporaryDir>
|
|
|
|
|
|
2021-04-11 20:53:27 +02:00
|
|
|
static const QString H5_TEST_DATA_DIRECTORY_2 = QString( "%1/h5-file/" ).arg( TEST_DATA_DIR );
|
2021-04-11 08:51:32 +02:00
|
|
|
|
2026-07-30 12:57:36 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
/// A summary file without a TIME vector must be reported as a failed export, not terminate the
|
|
|
|
|
/// application. Opm::EclIO::ESmry::dates() throws when the TIME vector is missing.
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
TEST( HDFTests, ExportSummaryFileWithoutTimeKeyword )
|
|
|
|
|
{
|
|
|
|
|
const QString sourceFolder = QString( "%1/SummaryData/Reek/" ).arg( TEST_DATA_DIR );
|
|
|
|
|
|
|
|
|
|
QTemporaryDir tempDir;
|
|
|
|
|
ASSERT_TRUE( tempDir.isValid() );
|
|
|
|
|
|
|
|
|
|
ASSERT_TRUE( QFile::copy( sourceFolder + "3_R001_REEK-1.UNSMRY", tempDir.filePath( "3_R001_REEK-1.UNSMRY" ) ) );
|
|
|
|
|
|
|
|
|
|
// Copy the SMSPEC file and rename the TIME keyword, making ESmry load without a TIME vector
|
|
|
|
|
const QString smspecFileName = tempDir.filePath( "3_R001_REEK-1.SMSPEC" );
|
|
|
|
|
{
|
|
|
|
|
QFile sourceFile( sourceFolder + "3_R001_REEK-1.SMSPEC" );
|
|
|
|
|
ASSERT_TRUE( sourceFile.open( QIODevice::ReadOnly ) );
|
|
|
|
|
|
|
|
|
|
QByteArray content = sourceFile.readAll();
|
|
|
|
|
|
|
|
|
|
const QByteArray timeKeyword( "TIME " );
|
|
|
|
|
ASSERT_EQ( 1, content.count( timeKeyword ) );
|
|
|
|
|
content.replace( timeKeyword, QByteArray( "TIMX " ) );
|
|
|
|
|
|
|
|
|
|
QFile destinationFile( smspecFileName );
|
|
|
|
|
ASSERT_TRUE( destinationFile.open( QIODevice::WriteOnly ) );
|
|
|
|
|
ASSERT_EQ( content.size(), destinationFile.write( content ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const std::string h5FileName = tempDir.filePath( "3_R001_REEK-1.h5" ).toStdString();
|
|
|
|
|
|
|
|
|
|
size_t hdfFilesCreatedCount = 0;
|
|
|
|
|
EXPECT_TRUE( RifHdf5SummaryExporter::ensureHdf5FileIsCreated( smspecFileName.toStdString(), h5FileName, true, hdfFilesCreatedCount ) );
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ( size_t( 1 ), hdfFilesCreatedCount );
|
|
|
|
|
EXPECT_TRUE( QFile::exists( QString::fromStdString( h5FileName ) ) );
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-11 08:51:32 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
TEST( DISABLED_HDFTests, WriteToHdf5SummaryExporter )
|
|
|
|
|
{
|
2021-04-11 20:53:27 +02:00
|
|
|
QString file_path = H5_TEST_DATA_DIRECTORY_2 + "NORNE_ATW2013_RFTPLT_V2.SMSPEC";
|
2021-04-11 08:51:32 +02:00
|
|
|
|
2021-04-13 19:19:55 +02:00
|
|
|
std::string exportFileName = "e:/project/scratch_export/hdf_complete.h5";
|
2021-04-11 08:51:32 +02:00
|
|
|
|
2024-04-19 15:09:15 +02:00
|
|
|
int threadCount = 1;
|
|
|
|
|
bool createEnhancedSummaryFiles = true;
|
|
|
|
|
RifHdf5SummaryExporter::ensureHdf5FileIsCreatedMultithreaded( { file_path.toStdString() },
|
|
|
|
|
{ exportFileName },
|
|
|
|
|
createEnhancedSummaryFiles,
|
|
|
|
|
threadCount );
|
2021-04-11 08:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
TEST( DISABLED_HDFTests, WriteDataToH5 )
|
|
|
|
|
{
|
2021-04-11 20:53:27 +02:00
|
|
|
QString file_path = H5_TEST_DATA_DIRECTORY_2 + "NORNE_ATW2013_RFTPLT_V2.SMPEC";
|
2021-04-11 08:51:32 +02:00
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
RifReaderEclipseSummary summaryReader;
|
2021-04-27 15:08:48 +02:00
|
|
|
summaryReader.open( file_path, nullptr );
|
2021-04-11 08:51:32 +02:00
|
|
|
|
|
|
|
|
{
|
|
|
|
|
std::string exportFileName = "e:/project/scratch_export/hdf-test.h5";
|
|
|
|
|
|
|
|
|
|
H5::H5File file( exportFileName, H5F_ACC_TRUNC ); // Overwrite existing
|
|
|
|
|
|
|
|
|
|
// General group
|
|
|
|
|
{
|
|
|
|
|
std::vector<int> values( 7 );
|
|
|
|
|
|
2021-04-11 20:53:27 +02:00
|
|
|
int day = 1;
|
|
|
|
|
int month = 2;
|
|
|
|
|
int year = 3;
|
|
|
|
|
int hour = 4;
|
|
|
|
|
int minute = 5;
|
|
|
|
|
int second = 6;
|
2021-04-11 08:51:32 +02:00
|
|
|
|
|
|
|
|
values[0] = day;
|
|
|
|
|
values[1] = month;
|
|
|
|
|
values[2] = year;
|
|
|
|
|
values[3] = hour;
|
|
|
|
|
values[4] = minute;
|
|
|
|
|
values[5] = second;
|
|
|
|
|
values[6] = 0;
|
|
|
|
|
|
|
|
|
|
auto generalGroup = file.createGroup( "/general" );
|
|
|
|
|
|
|
|
|
|
// start_date
|
|
|
|
|
{
|
|
|
|
|
hsize_t dimsf[1];
|
|
|
|
|
dimsf[0] = values.size();
|
|
|
|
|
H5::DataSpace dataspace( 1, dimsf );
|
|
|
|
|
|
|
|
|
|
H5::DataType datatype( H5::PredType::NATIVE_INT );
|
|
|
|
|
H5::DataSet dataset = generalGroup.createDataSet( "start_date", datatype, dataspace );
|
|
|
|
|
dataset.write( values.data(), H5::PredType::NATIVE_INT );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
auto summaryGroup = file.createGroup( "/summary_vectors" );
|
|
|
|
|
auto myVectorGroup = summaryGroup.createGroup( "BPR" );
|
|
|
|
|
auto dataGroup = myVectorGroup.createGroup( "66" );
|
|
|
|
|
|
|
|
|
|
std::vector<float> a( 10 );
|
|
|
|
|
std::iota( a.begin(), a.end(), 10 );
|
|
|
|
|
|
|
|
|
|
// dataset dimensions
|
|
|
|
|
hsize_t dimsf[1];
|
|
|
|
|
dimsf[0] = a.size();
|
|
|
|
|
H5::DataSpace dataspace( 1, dimsf );
|
|
|
|
|
|
|
|
|
|
H5::DataType datatype( H5::PredType::NATIVE_FLOAT );
|
|
|
|
|
H5::DataSet dataset = dataGroup.createDataSet( "values", datatype, dataspace );
|
|
|
|
|
|
|
|
|
|
dataset.write( a.data(), H5::PredType::NATIVE_FLOAT );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch ( H5::FileIException& error ) // catch failure caused by the H5File operations
|
|
|
|
|
{
|
|
|
|
|
std::cout << error.getCDetailMsg();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch ( H5::DataSetIException& error ) // catch failure caused by the DataSet operations
|
|
|
|
|
{
|
|
|
|
|
std::cout << error.getCDetailMsg();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch ( H5::DataSpaceIException& error ) // catch failure caused by the DataSpace operations
|
|
|
|
|
{
|
|
|
|
|
std::cout << error.getCDetailMsg();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch ( H5::DataTypeIException& error ) // catch failure caused by the DataSpace operations
|
|
|
|
|
{
|
|
|
|
|
std::cout << error.getCDetailMsg();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif // USE_HDF5
|