void misfit_ranking_fprintf( const misfit_ranking_type * misfit_ranking , const char * filename) { FILE * stream = util_mkdir_fopen( filename , "w"); const int ens_size = misfit_ranking->ens_size; const int * permutations = misfit_ranking->sort_permutation; double summed_up = 0.0; { // All this whitespace is finely tuned and highly significant .... const char * key_fmt = " %18s "; const char * value_fmt = " %10.3f %8.3f"; const char * start_fmt = " %2d %3d %7.3f %8.3f"; hash_type * obs_hash = vector_iget( misfit_ranking->ensemble , 0); stringlist_type * obs_keys = hash_alloc_stringlist( obs_hash ); int num_obs = stringlist_get_size( obs_keys ); int iobs; int num_obs_total = num_obs * ens_size; stringlist_sort( obs_keys , enkf_util_compare_keys__ ); fprintf(stream , " Overall "); for (iobs =0; iobs < num_obs; iobs++) fprintf(stream , key_fmt , stringlist_iget( obs_keys , iobs )); fprintf(stream , "\n"); fprintf(stream , " # Realization Norm Total"); for (iobs =0; iobs < num_obs; iobs++) fprintf(stream , " Norm Total"); fprintf(stream , "\n"); for (int i = 0; i < ens_size; i++) { int iens = permutations[i]; hash_type * obs_hash = vector_iget( misfit_ranking->ensemble , iens ); double total_value = double_vector_iget( misfit_ranking->total , iens ); double normalized_misfit = sqrt(total_value / num_obs_total); summed_up = summed_up+total_value; fprintf(stream , start_fmt , i , iens , normalized_misfit , total_value); for (iobs =0; iobs < num_obs; iobs++){ double single_value = hash_get_double( obs_hash , stringlist_iget( obs_keys , iobs )); double single_value_normalized = sqrt(single_value / (num_obs_total)); fprintf(stream , value_fmt , single_value_normalized , single_value); } fprintf(stream , "\n"); } double summed_up_normalized = sqrt(summed_up / (num_obs_total * ens_size)); fprintf(stream , " All %7.3f %8.3f" , summed_up_normalized , summed_up); for (iobs = 0; iobs < num_obs; iobs++){ double single_value_summed_up = 0.0; for (int i = 0; i < ens_size; i++) { single_value_summed_up = single_value_summed_up + hash_get_double( obs_hash , stringlist_iget( obs_keys , iobs )); } double single_value_summed_up_normalized=sqrt(single_value_summed_up / (num_obs_total * ens_size)); fprintf(stream , value_fmt , single_value_summed_up_normalized , single_value_summed_up); } fprintf(stream , "\n"); } fclose( stream ); }
stringlist_type * summary_key_set_alloc_keys(summary_key_set_type * set) { stringlist_type * keys; pthread_rwlock_rdlock( &set->rw_lock ); { keys = hash_alloc_stringlist(set->key_set); } pthread_rwlock_unlock( &set->rw_lock ); return keys; }
void summary_key_set_fwrite(summary_key_set_type * set, const char * filename) { pthread_rwlock_rdlock( &set->rw_lock ); { FILE * stream = util_mkdir_fopen(filename , "w"); if (stream) { stringlist_type * keys = hash_alloc_stringlist(set->key_set); stringlist_fwrite(keys, stream); stringlist_free(keys); fclose( stream ); } else { util_abort("%s: failed to open: %s for writing \n", __func__, filename); } } pthread_rwlock_unlock( &set->rw_lock ); }
bool summary_key_matcher_match_summary_key(const summary_key_matcher_type * matcher, const char * summary_key) { stringlist_type * keys = hash_alloc_stringlist(matcher->key_set); bool has_key = false; for (int i = 0; i < stringlist_get_size(keys); i++) { const char * pattern = stringlist_iget(keys, i); if(util_fnmatch(pattern, summary_key) == 0) { has_key = true; break; } } stringlist_free(keys); return has_key; }
void misfit_ranking_display( const misfit_ranking_type * misfit_ranking , FILE * stream) { const int ens_size = double_vector_size( misfit_ranking->total ); const int * permutations = misfit_ranking->sort_permutation; hash_type * obs_hash = NULL; { // The ensemble vector can contain invalid nodes with NULL. int index = 0; while ((obs_hash == NULL) && (index < vector_get_size( misfit_ranking->ensemble))) { obs_hash = vector_iget( misfit_ranking->ensemble , index ); index++; } if (obs_hash == NULL) { fprintf(stderr,"Sorry: no valid results loaded for this misfit_ranking - returning\n"); return; } } { int i; double summed_up = 0.0; stringlist_type * obs_keys = hash_alloc_stringlist( obs_hash ); int num_obs = stringlist_get_size( obs_keys ); int num_obs_total = num_obs * ens_size; // SHould not count failed/missing members ... fprintf(stream,"\n\n"); fprintf(stream," # Realization Normalized misfit Total misfit\n"); fprintf(stream,"-------------------------------------------------------\n"); for (i = 0; i < ens_size; i++) { int iens = permutations[i]; double total_misfit = double_vector_iget( misfit_ranking->total , iens ); double normalized_misfit = sqrt(total_misfit / num_obs_total); summed_up = summed_up+total_misfit; fprintf(stream,"%3d %3d %10.3f %10.3f \n",i,iens,normalized_misfit,total_misfit); } { double normalized_summed_up = sqrt(summed_up / (num_obs_total * ens_size)); fprintf(stream," All %10.3f %10.3f \n",normalized_summed_up,summed_up); } fprintf(stream,"-------------------------------------------------------\n"); } }
custom_kw_config_type * custom_kw_config_alloc_with_definition(const char * key, const hash_type * definition) { custom_kw_config_type * custom_kw_config = custom_kw_config_alloc_empty(key, NULL, NULL); stringlist_type * keys = hash_alloc_stringlist((hash_type *) definition); for(int index = 0; index < stringlist_get_size(keys); index++) { const char * definition_key = stringlist_iget_copy(keys, index); int type_value = hash_get_int(definition, definition_key); if(type_value < 0 || type_value > 1) { fprintf(stderr ,"[%s] Warning: Value type not 0 or 1 for key: '%s', defaulting to string!\n", __func__, key); type_value = 0; } hash_insert_int(custom_kw_config->custom_keys, definition_key, index); hash_insert_int(custom_kw_config->custom_key_types, definition_key, type_value); } custom_kw_config->undefined = false; custom_kw_config->key_definition_file = util_alloc_string_copy("custom definition"); stringlist_free(keys); return custom_kw_config; }
stringlist_type * summary_key_matcher_get_keys(const summary_key_matcher_type * matcher) { return hash_alloc_stringlist(matcher->key_set); }
stringlist_type * local_dataset_alloc_keys( const local_dataset_type * dataset ) { return hash_alloc_stringlist( dataset->nodes ); }
stringlist_type * ecl_rft_file_alloc_well_list(const ecl_rft_file_type * rft_file ) { return hash_alloc_stringlist( rft_file->well_index ); }
stringlist_type * ensemble_config_alloc_keylist(const ensemble_config_type * config) { return hash_alloc_stringlist( config->config_nodes ); }
stringlist_type * ext_joblist_alloc_list( const ext_joblist_type * joblist) { return hash_alloc_stringlist( joblist->jobs ); }
stringlist_type * custom_kw_config_get_keys(const custom_kw_config_type * config) { return hash_alloc_stringlist(config->custom_keys); }
stringlist_type * ert_workflow_list_alloc_namelist( ert_workflow_list_type * workflow_list ) { return hash_alloc_stringlist( workflow_list->workflows ); }