static void enkf_main_copy_ensemble( const enkf_main_type * enkf_main, enkf_fs_type * source_case_fs, int source_report_step, state_enum source_state, enkf_fs_type * target_case_fs, int target_report_step, state_enum target_state, const bool_vector_type * iens_mask, const char * ranking_key , /* It is OK to supply NULL - but if != NULL it must exist */ const stringlist_type * node_list) { const int ens_size = enkf_main_get_ensemble_size( enkf_main ); state_map_type * target_state_map = enkf_fs_get_state_map(target_case_fs); { int * ranking_permutation; int inode , src_iens; if (ranking_key != NULL) { ranking_table_type * ranking_table = enkf_main_get_ranking_table( enkf_main ); ranking_permutation = (int *) ranking_table_get_permutation( ranking_table , ranking_key ); } else { ranking_permutation = util_calloc( ens_size , sizeof * ranking_permutation ); for (src_iens = 0; src_iens < ens_size; src_iens++) ranking_permutation[src_iens] = src_iens; } for (inode =0; inode < stringlist_get_size( node_list ); inode++) { enkf_config_node_type * config_node = ensemble_config_get_node( enkf_main_get_ensemble_config(enkf_main) , stringlist_iget( node_list , inode )); for (src_iens = 0; src_iens < enkf_main_get_ensemble_size( enkf_main ); src_iens++) { if (bool_vector_safe_iget(iens_mask , src_iens)) { int target_iens = ranking_permutation[src_iens]; node_id_type src_id = {.report_step = source_report_step , .iens = src_iens , .state = source_state }; node_id_type target_id = {.report_step = target_report_step , .iens = target_iens , .state = target_state }; /* The copy is careful ... */ if (enkf_config_node_has_node( config_node , source_case_fs , src_id)) enkf_node_copy( config_node , source_case_fs , target_case_fs , src_id , target_id ); if (0 == target_report_step) state_map_iset(target_state_map, target_iens, STATE_INITIALIZED); } } } if (ranking_permutation == NULL) free( ranking_permutation ); } }
static void enkf_tui_fs_copy_ensemble__( enkf_main_type * enkf_main, const char * source_case, const char * target_case, int report_step_from, state_enum state_from, int report_step_to, state_enum state_to, bool only_parameters) { msg_type * msg = msg_alloc("Copying: " , false); ensemble_config_type * config = enkf_main_get_ensemble_config(enkf_main); int ens_size = enkf_main_get_ensemble_size(enkf_main); char * ranking_key; const int * ranking_permutation = NULL; int * identity_permutation; ranking_table_type * ranking_table = enkf_main_get_ranking_table( enkf_main ); if (ranking_table_get_size( ranking_table ) > 0) { util_printf_prompt("Name of ranking to resort by (or blank)" , 50 , '=' , "=> "); ranking_key = util_alloc_stdin_line(); if (ranking_table_has_ranking( ranking_table , ranking_key )) ranking_permutation = ranking_table_get_permutation( ranking_table , ranking_key ); else { fprintf(stderr," Sorry: ranking:%s does not exist \n", ranking_key ); return; } } identity_permutation = util_calloc( ens_size , sizeof * identity_permutation ); { int iens; for (iens =0; iens < ens_size; iens++) identity_permutation[iens] = iens; } if (ranking_permutation == NULL) ranking_permutation = identity_permutation; { /* If the current target_case does not exist it is automatically created by the select_write_dir function */ enkf_fs_type * src_fs = enkf_main_mount_alt_fs( enkf_main , source_case , false ); enkf_fs_type * target_fs = enkf_main_mount_alt_fs( enkf_main , target_case , true ); stringlist_type * nodes = ensemble_config_alloc_keylist_from_var_type(config, PARAMETER); { int num_nodes = stringlist_get_size(nodes); msg_show(msg); for(int i = 0; i < num_nodes; i++) { const char * key = stringlist_iget(nodes, i); enkf_config_node_type * config_node = ensemble_config_get_node(config , key); msg_update(msg , key); enkf_node_copy_ensemble(config_node, src_fs , target_fs , report_step_from, state_from, report_step_to , state_to , ens_size , ranking_permutation); } } enkf_fs_decref( src_fs ); enkf_fs_decref( target_fs ); msg_free(msg , true); stringlist_free(nodes); } free( identity_permutation ); }