static void enkf_main_gen_data_special( enkf_main_type * enkf_main , enkf_fs_type * fs ) { stringlist_type * gen_data_keys = ensemble_config_alloc_keylist_from_impl_type( enkf_main->ensemble_config , GEN_DATA); for (int i=0; i < stringlist_get_size( gen_data_keys ); i++) { enkf_config_node_type * config_node = ensemble_config_get_node( enkf_main->ensemble_config , stringlist_iget( gen_data_keys , i)); gen_data_config_type * gen_data_config = enkf_config_node_get_ref( config_node ); if (gen_data_config_is_dynamic( gen_data_config )) gen_data_config_set_ens_size( gen_data_config , enkf_main->ens_size ); } stringlist_free( gen_data_keys ); }
bool gen_data_fload_with_report_step( gen_data_type * gen_data , const char * filename , int report_step) { bool has_file = util_file_exists(filename); void * buffer = NULL; int size = 0; ecl_type_enum load_type; if ( has_file ) { ecl_type_enum internal_type = gen_data_config_get_internal_type(gen_data->config); gen_data_file_format_type input_format = gen_data_config_get_input_format( gen_data->config ); buffer = gen_common_fload_alloc( filename , input_format , internal_type , &load_type , &size); /* Look for file @filename_active - if that file is found it is interpreted as a an active|inactive mask created by the forward model. The file is assumed to be an ASCII file with integers, 0 indicates inactive elements and 1 active elements. The file should of course be as long as @filename. If the file is not found the gen_data->active_mask is set to all-true (i.e. the default true value is invoked). */ if (gen_data_config_is_dynamic( gen_data->config )) { bool_vector_reset( gen_data->active_mask ); bool_vector_iset( gen_data->active_mask , size - 1, true ); { char * active_file = util_alloc_sprintf("%s_active" , filename ); if (util_file_exists( active_file )) { FILE * stream = util_fopen( active_file , "r"); int active_int; for (int index=0; index < size; index++) { if (fscanf( stream , "%d" , &active_int) == 1) { if (active_int == 1) bool_vector_iset( gen_data->active_mask , index , true); else if (active_int == 0) bool_vector_iset( gen_data->active_mask , index , false); else util_abort("%s: error when loading active mask from:%s only 0 and 1 allowed \n",__func__ , active_file); } else util_abort("%s: error when loading active mask from:%s - file not long enough.\n",__func__ , active_file ); } fclose( stream ); } free( active_file ); } } } gen_data_set_data__(gen_data , size , report_step , load_type , buffer ); util_safe_free(buffer); return has_file; }
void gen_data_read_from_buffer(gen_data_type * gen_data , buffer_type * buffer , enkf_fs_type * fs, int report_step) { int size; enkf_util_assert_buffer_type(buffer , GEN_DATA); size = buffer_fread_int(buffer); buffer_fskip_int( buffer ); /* Skipping report_step from the buffer - was a mistake to store it - I think ... */ { size_t byte_size = size * ecl_type_get_sizeof_ctype( gen_data_config_get_internal_data_type ( gen_data->config )); size_t compressed_size = buffer_get_remaining_size( buffer ); gen_data->data = util_realloc( gen_data->data , byte_size ); buffer_fread_compressed( buffer , compressed_size , gen_data->data , byte_size ); } gen_data_assert_size( gen_data , size , report_step ); if (gen_data_config_is_dynamic(gen_data->config)) { gen_data_config_load_active( gen_data->config , fs, report_step , false ); } }
static bool gen_data_fload_active__(gen_data_type * gen_data, const char * filename, int size) { /* Look for file @filename_active - if that file is found it is interpreted as a an active|inactive mask created by the forward model. The file is assumed to be an ASCII file with integers, 0 indicates inactive elements and 1 active elements. The file should of course be as long as @filename. If the file is not found the gen_data->active_mask is set to all-true (i.e. the default true value is invoked). */ bool file_exists = false; if (gen_data_config_is_dynamic( gen_data->config )) { bool_vector_reset( gen_data->active_mask ); bool_vector_iset( gen_data->active_mask , size - 1, true ); { char * active_file = util_alloc_sprintf("%s_active" , filename ); if (util_file_exists( active_file )) { file_exists = true; FILE * stream = util_fopen( active_file , "r"); int active_int; for (int index=0; index < size; index++) { if (fscanf( stream , "%d" , &active_int) == 1) { if (active_int == 1) bool_vector_iset( gen_data->active_mask , index , true); else if (active_int == 0) bool_vector_iset( gen_data->active_mask , index , false); else util_abort("%s: error when loading active mask from:%s only 0 and 1 allowed \n",__func__ , active_file); } else util_abort("%s: error when loading active mask from:%s - file not long enough.\n",__func__ , active_file ); } fclose( stream ); } free( active_file ); } } return file_exists; }
static void gen_data_set_data__(gen_data_type * gen_data , int size, const forward_load_context_type * load_context, ecl_data_type load_data_type , const void * data) { gen_data_assert_size(gen_data , size, forward_load_context_get_load_step( load_context )); if (gen_data_config_is_dynamic( gen_data->config )) gen_data_config_update_active( gen_data->config , load_context , gen_data->active_mask); gen_data_realloc_data(gen_data); if (size > 0) { ecl_data_type internal_type = gen_data_config_get_internal_data_type( gen_data->config ); int byte_size = ecl_type_get_sizeof_ctype( internal_type ) * size ; if (ecl_type_is_equal(load_data_type, internal_type)) memcpy(gen_data->data , data , byte_size ); else { if (ecl_type_is_float(load_data_type)) util_float_to_double((double *) gen_data->data , data , size); else util_double_to_float((float *) gen_data->data , data , size); } } }
static void gen_data_set_data__(gen_data_type * gen_data , int size, int report_step , ecl_type_enum load_type , const void * data) { gen_data_assert_size(gen_data , size, report_step); if (gen_data_config_is_dynamic( gen_data->config )) gen_data_config_update_active( gen_data->config , report_step , gen_data->active_mask); gen_data_realloc_data(gen_data); if (size > 0) { ecl_type_enum internal_type = gen_data_config_get_internal_type( gen_data->config ); int byte_size = ecl_util_get_sizeof_ctype( internal_type ) * size ; if (load_type == internal_type) memcpy(gen_data->data , data , byte_size ); else { if (load_type == ECL_FLOAT_TYPE) util_float_to_double((double *) gen_data->data , data , size); else util_double_to_float((float *) gen_data->data , data , size); } } }