Skip to content

Commit

Permalink
Merge pull request #450 from joakim-hove/unsmry-loader-file-flags
Browse files Browse the repository at this point in the history
Add flag for ecl_file_open() of UNSMRY file
  • Loading branch information
joakim-hove authored Aug 17, 2018
2 parents afa3a91 + 4f7c44f commit 551cfe5
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 37 deletions.
2 changes: 1 addition & 1 deletion applications/ecl/view_summary.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
32 changes: 17 additions & 15 deletions lib/ecl/ecl_sum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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;
Expand All @@ -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)
Expand All @@ -221,21 +221,21 @@ 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();

bool caseOK = false;

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 );
Expand All @@ -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;
}
Expand Down Expand Up @@ -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 {
/*
Expand All @@ -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 );
}


Expand Down
8 changes: 4 additions & 4 deletions lib/ecl/ecl_sum_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/ecl/ecl_sum_file_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,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;

Expand Down Expand Up @@ -608,7 +608,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)
{
Expand Down
5 changes: 2 additions & 3 deletions lib/ecl/ecl_unsmry_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,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();

Expand Down
4 changes: 2 additions & 2 deletions lib/ecl/tests/ecl_sum_data_intermediate_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/ecl/tests/ecl_unsmry_loader_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<double> FOPT_value = loader->get_vector(1);
const std::vector<double> BPR_value = loader->get_vector(2);
Expand Down
4 changes: 2 additions & 2 deletions lib/include/ert/ecl/ecl_sum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down
2 changes: 1 addition & 1 deletion lib/include/ert/ecl/ecl_sum_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/private-include/detail/ecl/ecl_sum_file_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/private-include/detail/ecl/ecl_unsmry_loader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

std::vector<double> get_vector(int pos) const;
Expand Down
10 changes: 6 additions & 4 deletions python/ecl/summary/ecl_sum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)

Expand Down

0 comments on commit 551cfe5

Please sign in to comment.