/** Will return NULL if no refcase is set. */ const char * ecl_config_get_refcase_name( const ecl_config_type * ecl_config) { const ecl_sum_type * refcase = ecl_refcase_list_get_default( ecl_config->refcase_list ); if (refcase == NULL) return NULL; else return ecl_sum_get_case( refcase ); }
const smspec_node_type * ecl_sum_get_general_var_node(const ecl_sum_type * ecl_sum , const char * lookup_kw) { const smspec_node_type * node = ecl_smspec_get_general_var_node( ecl_sum->smspec , lookup_kw ); if (node != NULL) return node; else { util_abort("%s: summary case:%s does not contain key:%s\n",__func__ , ecl_sum_get_case( ecl_sum ) , lookup_kw ); return NULL; } }
enkf_config_node_type * ensemble_config_add_summary(ensemble_config_type * ensemble_config , const char * key , load_fail_type load_fail) { enkf_config_node_type * config_node = NULL; if (hash_has_key(ensemble_config->config_nodes, key)) { config_node = hash_get(ensemble_config->config_nodes, key); if (enkf_config_node_get_impl_type( config_node ) != SUMMARY) util_abort("%s: ensemble key:%s already exists - but it is not of summary type\n",__func__ , key); { summary_config_type * summary_config = enkf_config_node_get_ref( config_node ); summary_config_update_load_fail_mode( summary_config , load_fail ); } } else { if ((ensemble_config->refcase == NULL) || (ecl_sum_has_general_var( ensemble_config->refcase , key ))) { config_node = enkf_config_node_alloc_summary( key , load_fail); ensemble_config_add_node(ensemble_config , config_node ); } else fprintf(stderr,"** warning: the refcase:%s does not contain the summary key:\"%s\" - will be ignored.\n", ecl_sum_get_case( ensemble_config->refcase ) , key); } return config_node; }
void output_run_line( const output_type * output , ensemble_type * ensemble) { const int data_columns = vector_get_size( output->keys ); const int data_rows = time_t_vector_size( ensemble->interp_time ); double ** data; int row_nr, column_nr; data = util_calloc( data_rows , sizeof * data ); /* time-direction, i.e. the row index is the first index and the column number (i.e. the different keys) is the second index. */ for (row_nr=0; row_nr < data_rows; row_nr++) data[row_nr] = util_calloc( data_columns , sizeof * data[row_nr] ); printf("Creating output file: %s \n",output->file ); /* Go through all the cases and check that they have this key; exit if missing. Could also ignore the missing keys and just continue; and even defer the checking to the inner loop. */ for (column_nr = 0; column_nr < vector_get_size( output->keys ); column_nr++) { const quant_key_type * qkey = vector_iget( output->keys , column_nr ); { bool OK = true; for (int iens = 0; iens < vector_get_size( ensemble->data ); iens++) { const sum_case_type * sum_case = vector_iget_const( ensemble->data , iens ); if (!ecl_sum_has_general_var(sum_case->ecl_sum , qkey->sum_key)) { OK = false; fprintf(stderr,"** Sorry: the case:%s does not have the summary key:%s \n", ecl_sum_get_case( sum_case->ecl_sum ), qkey->sum_key); } } if (!OK) util_exit("Exiting due to missing summary vector(s).\n"); } } /* The main loop - outer loop is running over time. */ { /** In the quite typical case that we are asking for several quantiles of the quantity, i.e. WWCT:OP_1:0.10 WWCT:OP_1:0.50 WWCT:OP_1:0.90 the interp_data_cache construction will ensure that the underlying ecl_sum object is only queried once; and also the sorting will be performed once. */ hash_type * interp_data_cache = hash_alloc(); for (row_nr = 0; row_nr < data_rows; row_nr++) { time_t interp_time = time_t_vector_iget( ensemble->interp_time , row_nr); for (column_nr = 0; column_nr < vector_get_size( output->keys ); column_nr++) { const quant_key_type * qkey = vector_iget( output->keys , column_nr ); double_vector_type * interp_data; /* Check if we have the vector in the cache table - if not create it. */ if (!hash_has_key( interp_data_cache , qkey->sum_key)) { interp_data = double_vector_alloc(0 , 0); hash_insert_hash_owned_ref( interp_data_cache , qkey->sum_key , interp_data , double_vector_free__); } interp_data = hash_get( interp_data_cache , qkey->sum_key ); /* Check if the vector has data - if not initialize it. */ if (double_vector_size( interp_data ) == 0) { for (int iens = 0; iens < vector_get_size( ensemble->data ); iens++) { const sum_case_type * sum_case = vector_iget_const( ensemble->data , iens ); if ((interp_time >= sum_case->start_time) && (interp_time <= sum_case->end_time)) /* We allow the different simulations to have differing length */ double_vector_append( interp_data , ecl_sum_get_general_var_from_sim_time( sum_case->ecl_sum , interp_time , qkey->sum_key)) ; double_vector_sort( interp_data ); } } data[row_nr][column_nr] = statistics_empirical_quantile__( interp_data , qkey->quantile ); } hash_apply( interp_data_cache , double_vector_reset__ ); } hash_free( interp_data_cache ); } output_save( output , ensemble , (const double **) data); for (row_nr=0; row_nr < data_rows; row_nr++) free( data[row_nr] ); free( data ); }
enkf_fs_type * enkf_main_mount_alt_fs(const enkf_main_type * enkf_main , const char * case_path , bool create) { if (enkf_main_case_is_current( enkf_main , case_path )) { // Fast path - we just return a reference to the currently selected case; // with increased refcount. enkf_fs_incref( enkf_main->dbase ); return enkf_main->dbase; } else { // We have asked for an alterantive fs - must mount and possibly create that first. enkf_fs_type * new_fs = NULL; if (case_path != NULL) { char * new_mount_point = enkf_main_alloc_mount_point( enkf_main , case_path ); if (!enkf_fs_exists( new_mount_point )) { if (create) enkf_main_create_fs( enkf_main , case_path ); } new_fs = enkf_fs_mount( new_mount_point ); if (new_fs) { const model_config_type * model_config = enkf_main_get_model_config( enkf_main ); const ecl_sum_type * refcase = model_config_get_refcase( model_config ); if (refcase) { time_map_type * time_map = enkf_fs_get_time_map( new_fs ); if (time_map_attach_refcase( time_map , refcase)) time_map_set_strict( time_map , false ); else ert_log_add_fmt_message(1 , stderr , "Warning mismatch between refcase:%s and existing case:%s" , ecl_sum_get_case( refcase ) , new_mount_point); } } free( new_mount_point ); } return new_fs; } }