From 4f7c44f490d6254cbba43e91c078bfb97e4a37a3 Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Fri, 17 Aug 2018 11:26:25 +0200 Subject: [PATCH] Add flag for ecl_file_open() of UNSMRY file --- applications/ecl/view_summary.c | 2 +- lib/ecl/ecl_sum.cpp | 32 ++++++++++--------- lib/ecl/ecl_sum_data.cpp | 8 ++--- lib/ecl/ecl_sum_file_data.cpp | 4 +-- lib/ecl/ecl_unsmry_loader.cpp | 5 ++- .../tests/ecl_sum_data_intermediate_test.cpp | 4 +-- lib/ecl/tests/ecl_unsmry_loader_test.cpp | 2 +- lib/include/ert/ecl/ecl_sum.hpp | 4 +-- lib/include/ert/ecl/ecl_sum_data.hpp | 2 +- .../detail/ecl/ecl_sum_file_data.hpp | 2 +- .../detail/ecl/ecl_unsmry_loader.hpp | 2 +- python/ecl/summary/ecl_sum.py | 10 +++--- 12 files changed, 40 insertions(+), 37 deletions(-) diff --git a/applications/ecl/view_summary.c b/applications/ecl/view_summary.c index ff76151363..986f390db4 100644 --- a/applications/ecl/view_summary.c +++ b/applications/ecl/view_summary.c @@ -201,7 +201,7 @@ int main(int argc , char ** argv) { const char ** arg_list = (const char **) &argv[arg_offset + 1]; - ecl_sum = ecl_sum_fread_alloc_case2__( data_file , ":" , include_restart, true); + ecl_sum = ecl_sum_fread_alloc_case2__( data_file , ":" , include_restart, true, 0); /** If no keys have been presented the function will list available keys. */ if (num_keys == 0) list_mode = true; diff --git a/lib/ecl/ecl_sum.cpp b/lib/ecl/ecl_sum.cpp index 7cb2924946..49488a6005 100644 --- a/lib/ecl/ecl_sum.cpp +++ b/lib/ecl/ecl_sum.cpp @@ -174,22 +174,22 @@ static ecl_sum_type * ecl_sum_alloc__( const char * input_arg , const char * key } -static bool ecl_sum_fread_data( ecl_sum_type * ecl_sum , const stringlist_type * data_files , bool include_restart, bool lazy_load) { +static bool ecl_sum_fread_data( ecl_sum_type * ecl_sum , const stringlist_type * data_files , bool include_restart, bool lazy_load, int file_options) { if (ecl_sum->data != NULL) ecl_sum_free_data( ecl_sum ); ecl_sum->data = ecl_sum_data_alloc( ecl_sum->smspec ); - return ecl_sum_data_fread( ecl_sum->data , data_files, lazy_load); + return ecl_sum_data_fread( ecl_sum->data , data_files, lazy_load, file_options); } -static void ecl_sum_fread_history( ecl_sum_type * ecl_sum, bool lazy_load) { +static void ecl_sum_fread_history( ecl_sum_type * ecl_sum, bool lazy_load, int file_options) { char * restart_header = ecl_util_alloc_filename(NULL, ecl_smspec_get_restart_case(ecl_sum->smspec), ECL_SUMMARY_HEADER_FILE, ecl_smspec_get_formatted(ecl_sum->smspec), -1); - ecl_sum_type * restart_case = ecl_sum_fread_alloc_case2__(restart_header, ":" , true, lazy_load); + ecl_sum_type * restart_case = ecl_sum_fread_alloc_case2__(restart_header, ":" , true, lazy_load, file_options); if (restart_case) { ecl_sum->restart_case = restart_case; ecl_sum_data_add_case(ecl_sum->data , restart_case->data ); @@ -199,7 +199,7 @@ static void ecl_sum_fread_history( ecl_sum_type * ecl_sum, bool lazy_load) { -static bool ecl_sum_fread(ecl_sum_type * ecl_sum , const char *header_file , const stringlist_type *data_files , bool include_restart, bool lazy_load) { +static bool ecl_sum_fread(ecl_sum_type * ecl_sum , const char *header_file , const stringlist_type *data_files , bool include_restart, bool lazy_load, int file_options) { ecl_sum->smspec = ecl_smspec_fread_alloc( header_file , ecl_sum->key_join_string , include_restart); if (ecl_sum->smspec) { bool fmt_file; @@ -208,7 +208,7 @@ static bool ecl_sum_fread(ecl_sum_type * ecl_sum , const char *header_file , con } else return false; - if (ecl_sum_fread_data( ecl_sum , data_files , include_restart, lazy_load )) { + if (ecl_sum_fread_data( ecl_sum , data_files , include_restart, lazy_load, file_options )) { ecl_file_enum file_type = ecl_util_get_file_type( stringlist_iget( data_files , 0 ) , NULL , NULL); if (file_type == ECL_SUMMARY_FILE) @@ -221,13 +221,13 @@ static bool ecl_sum_fread(ecl_sum_type * ecl_sum , const char *header_file , con return false; if (include_restart && ecl_smspec_get_restart_case( ecl_sum->smspec )) - ecl_sum_fread_history( ecl_sum, lazy_load); + ecl_sum_fread_history( ecl_sum, lazy_load, file_options); return true; } -static bool ecl_sum_fread_case( ecl_sum_type * ecl_sum , bool include_restart, bool lazy_load) { +static bool ecl_sum_fread_case( ecl_sum_type * ecl_sum , bool include_restart, bool lazy_load, int file_options) { char * header_file; stringlist_type * summary_file_list = stringlist_alloc_new(); @@ -235,7 +235,7 @@ static bool ecl_sum_fread_case( ecl_sum_type * ecl_sum , bool include_restart, b ecl_util_alloc_summary_files( ecl_sum->path , ecl_sum->base , ecl_sum->ext , &header_file , summary_file_list ); if ((header_file != NULL) && (stringlist_get_size( summary_file_list ) > 0)) { - caseOK = ecl_sum_fread( ecl_sum , header_file , summary_file_list , include_restart, lazy_load ); + caseOK = ecl_sum_fread( ecl_sum , header_file , summary_file_list , include_restart, lazy_load, file_options ); } free( header_file ); stringlist_free( summary_file_list ); @@ -255,10 +255,10 @@ static bool ecl_sum_fread_case( ecl_sum_type * ecl_sum , bool include_restart, b */ -ecl_sum_type * ecl_sum_fread_alloc(const char *header_file , const stringlist_type *data_files , const char * key_join_string, bool include_restart, bool lazy_load) { +ecl_sum_type * ecl_sum_fread_alloc(const char *header_file , const stringlist_type *data_files , const char * key_join_string, bool include_restart, bool lazy_load, int file_options) { ecl_sum_type * ecl_sum = ecl_sum_alloc__( header_file , key_join_string ); if (ecl_sum) { - if (!ecl_sum_fread( ecl_sum , header_file , data_files , include_restart, lazy_load)) { + if (!ecl_sum_fread( ecl_sum , header_file , data_files , include_restart, lazy_load, file_options)) { ecl_sum_free( ecl_sum ); ecl_sum = NULL; } @@ -451,12 +451,12 @@ void ecl_sum_free__(void * __ecl_sum) { */ -ecl_sum_type * ecl_sum_fread_alloc_case2__(const char * input_file , const char * key_join_string , bool include_restart, bool lazy_load){ +ecl_sum_type * ecl_sum_fread_alloc_case2__(const char * input_file , const char * key_join_string , bool include_restart, bool lazy_load, int file_options){ ecl_sum_type * ecl_sum = ecl_sum_alloc__(input_file , key_join_string); if (!ecl_sum) return NULL; - if (ecl_sum_fread_case( ecl_sum , include_restart, lazy_load)) + if (ecl_sum_fread_case( ecl_sum , include_restart, lazy_load, file_options)) return ecl_sum; else { /* @@ -470,14 +470,16 @@ ecl_sum_type * ecl_sum_fread_alloc_case2__(const char * input_file , const char ecl_sum_type * ecl_sum_fread_alloc_case__(const char * input_file , const char * key_join_string , bool include_restart) { bool lazy_load = true; - return ecl_sum_fread_alloc_case2__(input_file, key_join_string, include_restart, lazy_load); + int file_options = 0; + return ecl_sum_fread_alloc_case2__(input_file, key_join_string, include_restart, lazy_load, file_options); } ecl_sum_type * ecl_sum_fread_alloc_case(const char * input_file , const char * key_join_string){ bool include_restart = true; bool lazy_load = true; - return ecl_sum_fread_alloc_case2__( input_file , key_join_string , include_restart, lazy_load ); + int file_options = 0; + return ecl_sum_fread_alloc_case2__( input_file , key_join_string , include_restart, lazy_load, file_options ); } diff --git a/lib/ecl/ecl_sum_data.cpp b/lib/ecl/ecl_sum_data.cpp index 25596392c9..7cf72a309c 100644 --- a/lib/ecl/ecl_sum_data.cpp +++ b/lib/ecl/ecl_sum_data.cpp @@ -696,9 +696,9 @@ void ecl_sum_data_add_case(ecl_sum_data_type * self, const ecl_sum_data_type * o call to ecl_sum_data_build_index(). */ -bool ecl_sum_data_fread(ecl_sum_data_type * data , const stringlist_type * filelist, bool lazy_load) { +bool ecl_sum_data_fread(ecl_sum_data_type * data , const stringlist_type * filelist, bool lazy_load, int file_options) { ecl::ecl_sum_file_data * file_data = new ecl::ecl_sum_file_data( data->smspec ); - if (file_data->fread( filelist, lazy_load)) { + if (file_data->fread( filelist, lazy_load, file_options)) { ecl_sum_data_append_file_data( data, file_data ); ecl_sum_data_build_index(data); return true; @@ -722,9 +722,9 @@ bool ecl_sum_data_fread(ecl_sum_data_type * data , const stringlist_type * filel (manually) changed from the historical part. */ -ecl_sum_data_type * ecl_sum_data_fread_alloc( ecl_smspec_type * smspec , const stringlist_type * filelist , bool include_restart, bool lazy_load) { +ecl_sum_data_type * ecl_sum_data_fread_alloc( ecl_smspec_type * smspec , const stringlist_type * filelist , bool include_restart, bool lazy_load, int file_options) { ecl_sum_data_type * data = ecl_sum_data_alloc( smspec ); - ecl_sum_data_fread( data , filelist, lazy_load ); + ecl_sum_data_fread( data , filelist, lazy_load, file_options ); /*****************************************************************/ /* OK - now we have loaded all the data. Must sort the internal diff --git a/lib/ecl/ecl_sum_file_data.cpp b/lib/ecl/ecl_sum_file_data.cpp index d8c51ad501..9083e95ed1 100644 --- a/lib/ecl/ecl_sum_file_data.cpp +++ b/lib/ecl/ecl_sum_file_data.cpp @@ -571,7 +571,7 @@ void ecl_sum_file_data::add_ecl_file(int report_step, const ecl_file_view_type * } -bool ecl_sum_file_data::fread(const stringlist_type * filelist, bool lazy_load) { +bool ecl_sum_file_data::fread(const stringlist_type * filelist, bool lazy_load, int file_options) { if (stringlist_get_size( filelist ) == 0) return false; @@ -600,7 +600,7 @@ bool ecl_sum_file_data::fread(const stringlist_type * filelist, bool lazy_load) } else if (file_type == ECL_UNIFIED_SUMMARY_FILE) { if (lazy_load) { try { - this->loader.reset( new unsmry_loader( this->ecl_smspec, stringlist_iget(filelist, 0)) ); + this->loader.reset( new unsmry_loader( this->ecl_smspec, stringlist_iget(filelist, 0), file_options) ); } catch(const std::bad_alloc& e) { diff --git a/lib/ecl/ecl_unsmry_loader.cpp b/lib/ecl/ecl_unsmry_loader.cpp index 890bb14c7e..efbc9c9f92 100644 --- a/lib/ecl/ecl_unsmry_loader.cpp +++ b/lib/ecl/ecl_unsmry_loader.cpp @@ -11,14 +11,13 @@ namespace ecl { -unsmry_loader::unsmry_loader(const ecl_smspec_type * smspec, const std::string& filename) : +unsmry_loader::unsmry_loader(const ecl_smspec_type * smspec, const std::string& filename, int file_options) : size(ecl_smspec_get_params_size(smspec)), time_index(ecl_smspec_get_time_index(smspec)), time_seconds(ecl_smspec_get_time_seconds(smspec)), sim_start(ecl_smspec_get_start_time(smspec)) { - int options = 0; - ecl_file_type * file = ecl_file_open(filename.c_str(), options); + ecl_file_type * file = ecl_file_open(filename.c_str(), file_options); if (!file) throw std::bad_alloc(); diff --git a/lib/ecl/tests/ecl_sum_data_intermediate_test.cpp b/lib/ecl/tests/ecl_sum_data_intermediate_test.cpp index 184556c6ea..b9eda7fe52 100644 --- a/lib/ecl/tests/ecl_sum_data_intermediate_test.cpp +++ b/lib/ecl/tests/ecl_sum_data_intermediate_test.cpp @@ -96,7 +96,7 @@ void write_CASE1(bool unified) { void verify_CASE2() { - ecl_sum_type * sum = ecl_sum_fread_alloc_case2__("CASE2", ":", false, true); + ecl_sum_type * sum = ecl_sum_fread_alloc_case2__("CASE2", ":", false, true, 0); for (int i=0; i < 2; i++) { double_vector_type * d = ecl_sum_alloc_data_vector(sum, i+1, false); @@ -154,7 +154,7 @@ void write_CASE2(bool unified) { } void verify_CASE3() { - ecl_sum_type * sum = ecl_sum_fread_alloc_case2__("CASE3", ":", false, true); + ecl_sum_type * sum = ecl_sum_fread_alloc_case2__("CASE3", ":", false, true, 0); for (int i=0; i < 3; i++) { double_vector_type * d = ecl_sum_alloc_data_vector(sum, i+1, false); diff --git a/lib/ecl/tests/ecl_unsmry_loader_test.cpp b/lib/ecl/tests/ecl_unsmry_loader_test.cpp index 3cec6a06a9..8c3a7b070b 100644 --- a/lib/ecl/tests/ecl_unsmry_loader_test.cpp +++ b/lib/ecl/tests/ecl_unsmry_loader_test.cpp @@ -40,7 +40,7 @@ void test_load() { ecl_sum_type * ecl_sum = write_ecl_sum(); test_assert_true( util_file_exists("CASE.SMSPEC") ); test_assert_true( util_file_exists("CASE.UNSMRY") ); - ecl::unsmry_loader * loader = new ecl::unsmry_loader(ecl_sum_get_smspec(ecl_sum), "CASE.UNSMRY"); + ecl::unsmry_loader * loader = new ecl::unsmry_loader(ecl_sum_get_smspec(ecl_sum), "CASE.UNSMRY", 0); const std::vector& FOPT_value = loader->get_vector(1); const std::vector& BPR_value = loader->get_vector(2); diff --git a/lib/include/ert/ecl/ecl_sum.hpp b/lib/include/ert/ecl/ecl_sum.hpp index 512e86352f..a66529fb45 100644 --- a/lib/include/ert/ecl/ecl_sum.hpp +++ b/lib/include/ert/ecl/ecl_sum.hpp @@ -89,10 +89,10 @@ typedef struct ecl_sum_struct ecl_sum_type; void ecl_sum_free_data(ecl_sum_type * ); void ecl_sum_free__(void * ); void ecl_sum_free(ecl_sum_type * ); - ecl_sum_type * ecl_sum_fread_alloc(const char * , const stringlist_type * data_files, const char * key_join_string, bool include_restart, bool lazy_load); + ecl_sum_type * ecl_sum_fread_alloc(const char * , const stringlist_type * data_files, const char * key_join_string, bool include_restart, bool lazy_load, int file_options); ecl_sum_type * ecl_sum_fread_alloc_case(const char * , const char * key_join_string); ecl_sum_type * ecl_sum_fread_alloc_case__(const char * input_file , const char * key_join_string , bool include_restart); - ecl_sum_type * ecl_sum_fread_alloc_case2__(const char * , const char * key_join_string , bool include_restart, bool lazy_load); + ecl_sum_type * ecl_sum_fread_alloc_case2__(const char * , const char * key_join_string , bool include_restart, bool lazy_load, int file_options); ecl_sum_type * ecl_sum_alloc_resample(const ecl_sum_type * ecl_sum, const char * ecl_case, const time_t_vector_type * times); bool ecl_sum_case_exists( const char * input_file ); diff --git a/lib/include/ert/ecl/ecl_sum_data.hpp b/lib/include/ert/ecl/ecl_sum_data.hpp index e464e41106..0c6fdbc0b1 100644 --- a/lib/include/ert/ecl/ecl_sum_data.hpp +++ b/lib/include/ert/ecl/ecl_sum_data.hpp @@ -43,7 +43,7 @@ typedef struct ecl_sum_data_struct ecl_sum_data_type ; void ecl_sum_data_fwrite_step( const ecl_sum_data_type * data , const char * ecl_case , bool fmt_case , bool unified, int report_step); void ecl_sum_data_fwrite( const ecl_sum_data_type * data , const char * ecl_case , bool fmt_case , bool unified); bool ecl_sum_data_can_write(const ecl_sum_data_type * data); - bool ecl_sum_data_fread( ecl_sum_data_type * data , const stringlist_type * filelist, bool lazy_load); + bool ecl_sum_data_fread( ecl_sum_data_type * data , const stringlist_type * filelist, bool lazy_load, int file_options); ecl_sum_data_type * ecl_sum_data_alloc_writer( ecl_smspec_type * smspec ); ecl_sum_data_type * ecl_sum_data_alloc( ecl_smspec_type * smspec); double ecl_sum_data_time2days( const ecl_sum_data_type * data , time_t sim_time); diff --git a/lib/private-include/detail/ecl/ecl_sum_file_data.hpp b/lib/private-include/detail/ecl/ecl_sum_file_data.hpp index 1e060fa395..3435cc6017 100644 --- a/lib/private-include/detail/ecl/ecl_sum_file_data.hpp +++ b/lib/private-include/detail/ecl/ecl_sum_file_data.hpp @@ -127,7 +127,7 @@ class ecl_sum_file_data { bool can_write() const; void fwrite_unified( fortio_type * fortio ) const; void fwrite_multiple( const char * ecl_case , bool fmt_case ) const; - bool fread(const stringlist_type * filelist, bool lazy_load); + bool fread(const stringlist_type * filelist, bool lazy_load, int file_options); private: const ecl_smspec_type * ecl_smspec; diff --git a/lib/private-include/detail/ecl/ecl_unsmry_loader.hpp b/lib/private-include/detail/ecl/ecl_unsmry_loader.hpp index d755626426..c05e42b7c6 100644 --- a/lib/private-include/detail/ecl/ecl_unsmry_loader.hpp +++ b/lib/private-include/detail/ecl/ecl_unsmry_loader.hpp @@ -10,7 +10,7 @@ namespace ecl { class unsmry_loader { public: - unsmry_loader(const ecl_smspec_type * smspec, const std::string& filename); + unsmry_loader(const ecl_smspec_type * smspec, const std::string& filename, int file_options); ~unsmry_loader(); const std::vector& get_vector(int pos); diff --git a/python/ecl/summary/ecl_sum.py b/python/ecl/summary/ecl_sum.py index 6e973dc1bc..029334836a 100644 --- a/python/ecl/summary/ecl_sum.py +++ b/python/ecl/summary/ecl_sum.py @@ -86,7 +86,7 @@ def date2num(dt): class EclSum(BaseCClass): TYPE_NAME = "ecl_sum" - _fread_alloc_case2 = EclPrototype("void* ecl_sum_fread_alloc_case2__(char*, char*, bool, bool)", bind=False) + _fread_alloc_case2 = EclPrototype("void* ecl_sum_fread_alloc_case2__(char*, char*, bool, bool, int)", bind=False) _fread_alloc = EclPrototype("void* ecl_sum_fread_alloc(char*, stringlist, char*, bool)", bind=False) _create_restart_writer = EclPrototype("ecl_sum_obj ecl_sum_alloc_restart_writer2(char*, char*, int, bool, bool, char*, time_t, bool, int, int, int)", bind = False) _create_writer = EclPrototype("ecl_sum_obj ecl_sum_alloc_writer(char*, bool, bool, char*, time_t, bool, int, int, int)", bind = False) @@ -149,7 +149,7 @@ class EclSum(BaseCClass): _init_numpy_datetime64 = EclPrototype("void ecl_sum_init_datetime64_vector(ecl_sum, int64*, int)") - def __init__(self, load_case, join_string=":", include_restart=True, lazy_load=True): + def __init__(self, load_case, join_string=":", include_restart=True, lazy_load=True, file_options=0): """Loads a new EclSum instance with summary data. Loads a new summary results from the ECLIPSE case given by @@ -171,12 +171,14 @@ def __init__(self, load_case, join_string=":", include_restart=True, lazy_load=T is actually requested. This will reduce startup time and memory usage, whereas getting a vector will be slower. When the summary data is split over multiple CASE.Snnn files all the data will be loaded at - construction time, and the @lazy_load option is ignored. + construction time, and the @lazy_load option is ignored. If the + lazy_load functionality is used the file_options intege flag is passed + when opening the UNSMRY file. """ if not load_case: raise ValueError('load_case must be the basename of the simulation') - c_pointer = self._fread_alloc_case2(load_case, join_string, include_restart, lazy_load) + c_pointer = self._fread_alloc_case2(load_case, join_string, include_restart, lazy_load, file_options) if c_pointer is None: raise IOError("Failed to create summary instance from argument:%s" % load_case)