void ecl_util_alloc_summary_data_files(const char * path , const char * base , bool fmt_file , stringlist_type * filelist) { char * unif_data_file = ecl_util_alloc_exfilename(path , base , ECL_UNIFIED_SUMMARY_FILE , fmt_file , -1); int files = ecl_util_select_filelist( path , base , ECL_SUMMARY_FILE , fmt_file , filelist); if ((files > 0) && (unif_data_file != NULL)) { /* We have both a unified file AND a list of files: BASE.S0000, BASE.S0001, BASE.S0002, ..., must check which is newest and load accordingly. */ bool unified_newest = true; int file_nr = 0; while (unified_newest && (file_nr < files)) { if (util_file_difftime( stringlist_iget(filelist , file_nr) , unif_data_file ) > 0) unified_newest = false; file_nr++; } if (unified_newest) { stringlist_clear( filelist ); /* Clear out all the BASE.Snnnn selections. */ stringlist_append_copy( filelist , unif_data_file ); } } else if (unif_data_file != NULL) { /* Found a unified summary file : Clear out all the BASE.Snnnn selections. */ stringlist_clear( filelist ); /* Clear out all the BASE.Snnnn selections. */ stringlist_append_copy( filelist , unif_data_file ); } util_safe_free( unif_data_file ); }
void test_load_results_job(ert_test_context_type * test_context , const char * job_name , const char * job_file) { stringlist_type * args = stringlist_alloc_new(); ert_test_context_install_workflow_job( test_context , job_name , job_file ); stringlist_append_copy( args , "0"); stringlist_append_copy( args , ","); stringlist_append_copy( args , "1"); test_assert_true( ert_test_context_run_worklow_job( test_context , job_name , args) ); stringlist_free( args ); }
void test_update_new_case_step(const char * config_file , const char * job_file) { ert_test_context_type * test_context = ert_test_context_alloc("AnalysisJob2" , config_file); stringlist_type * args = stringlist_alloc_new(); stringlist_append_copy( args , "NewCase" ); stringlist_append_copy( args , "20" ); ert_test_context_install_workflow_job( test_context , "JOB" , job_file ); test_assert_true( ert_test_context_run_worklow_job( test_context , "JOB" , args) ); stringlist_free( args ); ert_test_context_free( test_context ); }
void test_front_back() { stringlist_type * s = stringlist_alloc_new(); stringlist_append_copy(s , "First"); test_assert_string_equal("First" , stringlist_front(s)); test_assert_string_equal("First" , stringlist_back(s)); stringlist_append_copy(s , "Last"); test_assert_string_equal("First" , stringlist_front(s)); test_assert_string_equal("Last" , stringlist_back(s)); stringlist_free( s ); }
void site_config_update_pathvar( site_config_type * site_config , const char * pathvar , const char * value) { if (site_config->user_mode) { stringlist_append_copy( site_config->path_variables_user , pathvar ); stringlist_append_copy( site_config->path_values_user , value ); if (!hash_has_key( site_config->path_variables_site , pathvar )) hash_insert_ref( site_config->path_variables_site , pathvar , NULL); /* This path variable has not been touched in the site_config. We store a NULL, so can roll back (i.e. call unsetenv()). */ } util_update_path_var( pathvar , value , false ); }
void test_init_case_job(ert_test_context_type * test_context, const char * job_name , const char * job_file) { stringlist_type * args = stringlist_alloc_new(); enkf_main_type * enkf_main = ert_test_context_get_main(test_context); test_assert_true( ert_test_context_install_workflow_job( test_context , "JOB" , job_file ) ); //Test init current case from existing { enkf_fs_type * cur_fs = enkf_main_mount_alt_fs( enkf_main , "new_current_case" , true ); enkf_main_select_fs(enkf_main, "new_current_case"); test_assert_ptr_not_equal(cur_fs , enkf_main_get_fs( enkf_main )); stringlist_append_copy( args, "default"); //case to init from test_assert_true( ert_test_context_run_worklow_job( test_context , "JOB" , args) ); enkf_fs_decref(cur_fs); } { const char * current_case = enkf_main_get_current_fs( enkf_main ); test_assert_string_equal(current_case, "new_current_case"); test_assert_true(enkf_fs_has_node(enkf_main_get_fs(enkf_main), "PERMZ", PARAMETER, 0, 0, ANALYZED)); enkf_fs_type * default_fs = enkf_main_mount_alt_fs( enkf_main , "default" , true ); state_map_type * default_state_map = enkf_fs_get_state_map(default_fs); state_map_type * current_state_map = enkf_fs_get_state_map(enkf_main_get_fs(enkf_main)); test_assert_int_equal(state_map_get_size(default_state_map), state_map_get_size(current_state_map)); enkf_fs_decref(default_fs); } //Test init case from existing case: stringlist_clear(args); stringlist_append_copy(args, "default"); //case to init from stringlist_append_copy(args, "new_not_current_case"); test_assert_true( ert_test_context_run_worklow_job( test_context , "JOB" , args) ); { enkf_fs_type * fs = enkf_main_mount_alt_fs(enkf_main, "new_not_current_case", true); test_assert_not_NULL( fs ); test_assert_true( enkf_fs_has_node(fs, "PERMZ", PARAMETER, 0, 0, ANALYZED )); enkf_fs_type * default_fs = enkf_main_mount_alt_fs( enkf_main , "default" , true ); state_map_type * default_state_map = enkf_fs_get_state_map(default_fs); state_map_type * new_state_map = enkf_fs_get_state_map(fs); test_assert_int_equal(state_map_get_size(default_state_map), state_map_get_size(new_state_map)); enkf_fs_decref(fs); } stringlist_free( args ); }
void test_unique() { stringlist_type * s = stringlist_alloc_new(); test_assert_true( stringlist_unique( s )); stringlist_append_copy( s, "S1"); test_assert_true( stringlist_unique( s )); stringlist_append_copy( s, "S2"); test_assert_true( stringlist_unique( s )); stringlist_append_copy( s, "S2"); test_assert_false( stringlist_unique( s )); }
void test_join() { const char * elt0 = "AAA"; const char * elt1 = "BBB"; const char * elt2 = "CCC"; const char * elt3 = "DDD"; const char * elt4 = "EEE"; const char * elt5 = "FFF"; stringlist_type * s = stringlist_alloc_new(); { // empty join const char* empty_join = stringlist_alloc_joined_string(s, "!!!"); test_assert_not_NULL(empty_join); test_assert_string_equal("", empty_join); } stringlist_append_copy( s , elt0 ); stringlist_append_copy( s , elt1 ); stringlist_append_copy( s , elt2 ); const char * sep0 = ""; const char * sep1 = "!!!"; const char * sep2 = " abc "; const char * j0 = stringlist_alloc_joined_string( s, sep0); const char * j1 = stringlist_alloc_joined_string( s, sep1); const char * j2 = stringlist_alloc_joined_string( s, sep2); test_assert_string_equal( j0, "AAABBBCCC"); test_assert_string_equal( j1, "AAA!!!BBB!!!CCC"); test_assert_string_equal( j2, "AAA abc BBB abc CCC"); stringlist_type * s1 = stringlist_alloc_new(); stringlist_append_copy( s1 , elt0 ); test_assert_string_equal( "AAA", stringlist_alloc_joined_string( s1, sep0)); test_assert_string_equal( "AAA", stringlist_alloc_joined_string( s1, sep1)); test_assert_string_equal( "AAA", stringlist_alloc_joined_string( s1, sep2)); stringlist_type * sub = stringlist_alloc_new(); stringlist_append_copy( sub , elt0 ); stringlist_append_copy( sub , elt1 ); stringlist_append_copy( sub , elt2 ); stringlist_append_copy( sub , elt3 ); stringlist_append_copy( sub , elt4 ); stringlist_append_copy( sub , elt5 ); test_assert_string_equal( "CCC:DDD:EEE", stringlist_alloc_joined_substring( sub, 2, 5, ":")); }
stringlist_type * stringlist_alloc_deep_copy_with_limits(const stringlist_type * src, int offset , int num_strings) { stringlist_type * copy = stringlist_alloc_empty( true ); int i; for (i = 0; i < num_strings; i++) stringlist_append_copy( copy , stringlist_iget( src , i + offset)); return copy; }
void model_config_set_case_table( model_config_type * model_config , int ens_size , const char * case_table_file ) { if (model_config->case_table_file != NULL) { /* Clear the current selection */ free( model_config->case_table_file ); stringlist_free( model_config->case_names ); model_config->case_table_file = NULL; model_config->case_names = NULL; } if (case_table_file != NULL) { bool atEOF = false; char casename[128]; int case_size = 0; FILE * stream = util_fopen( case_table_file , "r"); model_config->case_names = stringlist_alloc_new(); while (!atEOF) { if (fscanf( stream , "%s" , casename) == 1) { stringlist_append_copy( model_config->case_names , casename ); case_size++; } else atEOF = true; } fclose( stream ); if (case_size < ens_size) { for (int i = case_size; i < ens_size; i++) stringlist_append_owned_ref( model_config->case_names , util_alloc_sprintf("case_%04d" , i)); fprintf(stderr, "** Warning: mismatch between NUM_REALIZATIONS:%d and size of CASE_TABLE:%d - using \'case_nnnn\' for the last cases %d.\n", ens_size , case_size , ens_size - case_size); } else if (case_size > ens_size) fprintf(stderr, "** Warning: mismatch between NUM_REALIZATIONS:%d and CASE_TABLE:%d - only the %d realizations will be used.\n", ens_size , case_size , ens_size); } }
stringlist_type * enkf_main_alloc_caselist( const enkf_main_type * enkf_main ) { stringlist_type * case_list = stringlist_alloc_new( ); { const char * ens_path = model_config_get_enspath( enkf_main->model_config ); DIR * ens_dir = opendir( ens_path ); if (ens_dir != NULL) { int ens_fd = dirfd( ens_dir ); if (ens_fd != -1) { struct dirent * dp; do { dp = readdir( ens_dir ); if (dp != NULL) { if (!(util_string_equal( dp->d_name , ".") || util_string_equal(dp->d_name , ".."))) { if (!util_string_equal( dp->d_name , CURRENT_CASE_FILE)) { char * full_path = util_alloc_filename( ens_path , dp->d_name , NULL); if (util_is_directory( full_path )) stringlist_append_copy( case_list , dp->d_name ); free( full_path); } } } } while (dp != NULL); } } closedir( ens_dir ); } return case_list; }
void test_reverse() { const char *s0 = "AAA"; const char *s1 = "BBB"; const char *s2 = "CCC"; stringlist_type * s = stringlist_alloc_new(); stringlist_append_copy( s , s0 ); stringlist_append_copy( s , s1 ); stringlist_append_copy( s , s2 ); stringlist_reverse(s); test_assert_string_equal( s2 , stringlist_iget(s , 0 )); test_assert_string_equal( s1 , stringlist_iget(s , 1 )); test_assert_string_equal( s0 , stringlist_iget(s , 2 )); }
void sched_file_parse_append(sched_file_type * sched_file , const char * filename) { bool foundEND = false; stringlist_type * token_list = sched_file_tokenize( filename ); sched_kw_type * current_kw; int token_index = 0; do { sched_util_skip_newline( token_list , &token_index ); current_kw = sched_kw_token_alloc(token_list , &token_index , sched_file->fixed_length_table, &foundEND); if (current_kw != NULL) { sched_kw_type_enum type = sched_kw_get_type(current_kw); if (type == DATES || type == TSTEP || type == TIME) { int i , num_steps; sched_kw_type ** sched_kw_dates = sched_kw_split_alloc_DATES(current_kw, &num_steps); sched_kw_free(current_kw); for(i=0; i<num_steps; i++) sched_file_add_kw( sched_file , sched_kw_dates[i]); free(sched_kw_dates); } else sched_file_add_kw( sched_file , current_kw); } } while ( current_kw != NULL ); if (foundEND) sched_file->hasEND = true; stringlist_append_copy( sched_file->files , filename ); sched_file_build_block_dates(sched_file); sched_file_update_index( sched_file ); stringlist_free( token_list ); }
stringlist_type * stringlist_alloc_argv_copy(const char ** argv , int argc) { int iarg; stringlist_type * stringlist = stringlist_alloc_empty( true); for (iarg = 0; iarg < argc; iarg++) stringlist_append_copy( stringlist , argv[iarg]); return stringlist; }
void stringlist_deep_copy( stringlist_type * target , const stringlist_type * src) { stringlist_clear( target ); { int i; for ( i=0; i < stringlist_get_size( src ); i++) stringlist_append_copy( target , stringlist_iget( src , i )); } }
void test_matching() { stringlist_type * s1 = stringlist_alloc_new(); stringlist_type * s2 = stringlist_alloc_new(); stringlist_append_copy(s1 , "AAA"); stringlist_append_copy(s1 , "ABC" ); stringlist_append_copy(s1 , "123"); stringlist_append_copy(s1 , "ABC:123"); stringlist_select_matching_elements( s2 , s1 , "*"); test_assert_int_equal( 4 , stringlist_get_size( s2 )); test_assert_string_equal( "AAA" , stringlist_iget( s2 , 0 )); test_assert_string_equal( "ABC" , stringlist_iget( s2 , 1 )); test_assert_string_equal( "123" , stringlist_iget( s2 , 2 )); test_assert_string_equal( "ABC:123" , stringlist_iget( s2 , 3 )); stringlist_select_matching_elements( s2 , s1 , "*"); test_assert_int_equal( 4 , stringlist_get_size( s2 )); test_assert_string_equal( "AAA" , stringlist_iget( s2 , 0 )); test_assert_string_equal( "ABC" , stringlist_iget( s2 , 1 )); test_assert_string_equal( "123" , stringlist_iget( s2 , 2 )); test_assert_string_equal( "ABC:123" , stringlist_iget( s2 , 3 )); stringlist_append_matching_elements( s2 , s1 , "*"); test_assert_int_equal( 8 , stringlist_get_size( s2 )); test_assert_string_equal( "AAA" , stringlist_iget( s2 , 0 )); test_assert_string_equal( "ABC" , stringlist_iget( s2 , 1 )); test_assert_string_equal( "123" , stringlist_iget( s2 , 2 )); test_assert_string_equal( "ABC:123" , stringlist_iget( s2 , 3 )); test_assert_string_equal( "AAA" , stringlist_iget( s2 , 4 )); test_assert_string_equal( "ABC" , stringlist_iget( s2 , 5 )); test_assert_string_equal( "123" , stringlist_iget( s2 , 6 )); test_assert_string_equal( "ABC:123" , stringlist_iget( s2 , 7 )); stringlist_select_matching_elements( s2 , s1 , "*B*"); test_assert_int_equal( 2 , stringlist_get_size( s2 )); test_assert_string_equal( "ABC" , stringlist_iget( s2 , 0 )); test_assert_string_equal( "ABC:123" , stringlist_iget( s2 , 1 )); stringlist_free( s2 ); stringlist_free( s1 ); }
void enkf_tui_init(enkf_main_type * enkf_main, bool all_members , bool all_parameters , bool interval ) { const int prompt_len = 35; const ensemble_config_type * ensemble_config = enkf_main_get_ensemble_config(enkf_main); int ens_size = enkf_main_get_ensemble_size( enkf_main ); int iens1, iens2; init_mode_enum init_mode = INIT_FORCE; bool iens_valid = false; /* iens2 should be interpreted as __inclusive__ */ if ( all_members ) { iens1 = 0; iens2 = ens_size - 1; iens_valid = true; } else { if( interval ) { char * iens1char = util_scanf_int_with_limits_return_char("First ensemble member in interval" , prompt_len , 0 , ens_size - 1); if (strlen(iens1char)) { util_sscanf_int(iens1char , &iens1); char * iens2char = util_scanf_int_with_limits_return_char("Second ensemble member in interval" , prompt_len , iens1 , ens_size - 1); if (strlen(iens2char)) { util_sscanf_int(iens2char , &iens2); iens_valid = true; } free(iens2char); } free(iens1char); } else { char * iens1char = util_scanf_int_with_limits_return_char("Initialize ensemble member" , prompt_len , 0 , ens_size - 1); if (strlen(iens1char)) { util_sscanf_int(iens1char , &iens1); iens2 = iens1; iens_valid = true; } free(iens1char); } } if (iens_valid) { stringlist_type * param_list = NULL; if (all_parameters) param_list = ensemble_config_alloc_keylist_from_var_type( ensemble_config , PARAMETER ); else { const enkf_config_node_type * config_node = NULL; param_list = stringlist_alloc_new(); config_node = enkf_tui_util_scanf_key(ensemble_config , prompt_len , INVALID , INVALID_VAR); if( config_node != NULL ) stringlist_append_copy( param_list , enkf_config_node_get_key(config_node)); } if (param_list != NULL) { enkf_main_initialize_from_scratch(enkf_main , param_list , iens1 , iens2 , init_mode); stringlist_free( param_list ); } } }
void test_char() { const char * S1 = "S1"; const char * S2 = "S2"; const char * S3 = "S3"; stringlist_type * s = stringlist_alloc_new(); stringlist_append_copy( s , S1 ); stringlist_append_copy( s , S2 ); stringlist_append_copy( s , S3 ); { char ** copy = stringlist_alloc_char_copy( s ); int i; for (i=0; i < stringlist_get_size( s ); i++) { if (strcmp( stringlist_iget( s , i ) , copy[i]) != 0) exit(1); } } }
void test_create_case_job(ert_test_context_type * test_context, const char * job_name , const char * job_file) { stringlist_type * args = stringlist_alloc_new(); stringlist_append_copy( args , "newly_created_case"); test_assert_true( ert_test_context_install_workflow_job( test_context , job_name , job_file )); test_assert_true( ert_test_context_run_worklow_job( test_context , job_name , args) ); char * new_case = util_alloc_filename( "storage" , "newly_created_case" , NULL); test_assert_true(util_is_directory(new_case)); free(new_case); stringlist_free( args ); }
stringlist_type * ensemble_config_alloc_keylist_from_impl_type(const ensemble_config_type * config , ert_impl_type impl_type) { stringlist_type * key_list = stringlist_alloc_new(); hash_iter_type * iter = hash_iter_alloc(config->config_nodes); while (!hash_iter_is_complete( iter )) { const char * key = hash_iter_get_next_key(iter); if (enkf_config_node_get_impl_type( hash_get(config->config_nodes , key)) == impl_type) stringlist_append_copy( key_list , key ); } hash_iter_free(iter); return key_list; }
int stringlist_append_matching_elements(stringlist_type * target , const stringlist_type * src , const char * pattern) { int ielm; int match_count = 0; for (ielm = 0; ielm < stringlist_get_size( src ); ielm++) { const char * item = stringlist_iget( src , ielm ); if (util_fnmatch( pattern , item ) == 0) { stringlist_append_copy( target , item ); match_count++; } } return match_count; }
stringlist_type * stringlist_alloc_from_split( const char * input_string , const char * sep ) { stringlist_type * slist = stringlist_alloc_new(); if (input_string != NULL) { char ** items; int num_items , i; util_split_string( input_string , sep , &num_items , &items); for ( i =0; i < num_items; i++) stringlist_append_copy( slist , items[i] ); util_free_stringlist( items , num_items ); } return slist; }
void test_iget_as_int() { stringlist_type * s = stringlist_alloc_new(); stringlist_append_copy(s , "1000" ); stringlist_append_copy(s , "1000X" ); stringlist_append_copy(s , "XXXX" ); { int value; bool valid; value = stringlist_iget_as_int( s , 0 , &valid); test_assert_int_equal( value , 1000); test_assert_true( valid ); value = stringlist_iget_as_int( s , 1 , &valid); test_assert_int_equal( value , -1); test_assert_false( valid ); value = stringlist_iget_as_int( s , 2 , NULL); test_assert_int_equal( value , -1); } }
void test_iget_as_double() { stringlist_type * s = stringlist_alloc_new(); stringlist_append_copy(s , "1000.90" ); stringlist_append_copy(s , "1000" ); stringlist_append_copy(s , "XXXX" ); { double value; bool valid; value = stringlist_iget_as_double( s , 0 , &valid); test_assert_double_equal( value , 1000.90); test_assert_true( valid ); value = stringlist_iget_as_double( s , 1 , &valid); test_assert_double_equal( value , 1000.0); test_assert_true( valid ); value = stringlist_iget_as_double( s , 2 , &valid); test_assert_double_equal( value , -1); test_assert_false( valid ); } }
stringlist_type * ensemble_config_alloc_keylist_from_var_type(const ensemble_config_type * config , int var_mask) { stringlist_type * key_list = stringlist_alloc_new(); hash_iter_type * iter = hash_iter_alloc(config->config_nodes); while (!hash_iter_is_complete( iter )) { const char * key = hash_iter_get_next_key(iter); enkf_var_type var_type = enkf_config_node_get_var_type( hash_get(config->config_nodes , key)); if (var_type & var_mask) stringlist_append_copy( key_list , key ); } hash_iter_free(iter); return key_list; }
void sched_kw_gruptree_init_child_parent_list( const sched_kw_gruptree_type * kw , stringlist_type * child , stringlist_type * parent) { stringlist_clear( child ); stringlist_clear( parent ); { hash_iter_type * iter = hash_iter_alloc( kw->gruptree_hash ); while (!hash_iter_is_complete( iter )) { const char * child_group = hash_iter_get_next_key( iter ); const char * parent_group = hash_get_string( kw->gruptree_hash , child_group ); stringlist_append_copy( child , child_group ); /* <- The iterator keys go out of scope when hash_iter_free() is called. */ stringlist_append_ref( parent , parent_group ); } hash_iter_free( iter ); } }
void parse_workflows(int argc, char ** argv, stringlist_type * workflows) { /* bool workflow_on = false; */ for (int iarg = 2; iarg < argc; iarg++) { stringlist_append_copy(workflows, argv[iarg]); /*if (strcmp(argv[iarg], WORKFLOW_OPTION) == 0) workflow_on = true; else { if (workflow_on) stringlist_append_copy(workflows, argv[iarg]); else fprintf(stderr,"**Warning - option:\'%s\' ignored\n",argv[iarg]); } */ } }
static void build_key_list( const ecl_sum_type * ecl_sum , stringlist_type * key_list , int argc , const char ** argv) { int iarg; for (iarg = 0; iarg < argc; iarg++) { /** If the string does not contain wildcards we add it unconditionally; and then subsequently let the ecl_sum_fprintf() function print a message on stderr about missing keys. */ if (util_string_has_wildcard( argv[iarg] )) ecl_sum_select_matching_general_var_list( ecl_sum , argv[iarg] , key_list); else stringlist_append_copy( key_list , argv[iarg] ); } }
int stringlist_select_matching(stringlist_type * names , const char * pattern) { int match_count = 0; stringlist_clear( names ); { int i; glob_t * pglob = util_malloc( sizeof * pglob ); int glob_flags = 0; glob( pattern , glob_flags , NULL , pglob); match_count = pglob->gl_pathc; for (i=0; i < pglob->gl_pathc; i++) stringlist_append_copy( names , pglob->gl_pathv[i] ); globfree( pglob ); /* Only frees the _internal_ data structures of the pglob object. */ free( pglob ); } return match_count; }
stringlist_type * local_ministep_alloc_data_keys( const local_ministep_type * ministep ) { stringlist_type * keys = stringlist_alloc_new(); { hash_iter_type * dataset_iter = hash_iter_alloc( ministep->datasets ); while (!hash_iter_is_complete( dataset_iter )) { const local_dataset_type * dataset = hash_iter_get_next_value( dataset_iter ); stringlist_type * node_keys = local_dataset_alloc_keys( dataset ); for (int i=0; i < stringlist_get_size( node_keys ); i++) { const char * data_key = stringlist_iget( node_keys , i ); if (!stringlist_contains(keys , data_key )) stringlist_append_copy( keys , data_key ); } stringlist_free( node_keys ); } hash_iter_free( dataset_iter ); } return keys; }