void test_reverse() { const char * val1 = "value1"; const char * val2 = "value2"; const char * val3 = "value3"; const char * val4 = "value4"; vector_type * vector1 = vector_alloc_new( ); vector_type * vector2 = vector_alloc_new( ); vector_append_ref( vector1 , val1 ); vector_append_ref( vector1 , val2 ); vector_append_ref( vector1 , val3 ); vector_append_ref( vector1 , val4 ); vector_append_ref( vector2 , val1 ); vector_append_ref( vector2 , val2 ); vector_append_ref( vector2 , val3 ); vector_append_ref( vector2 , val4 ); vector_inplace_reverse( vector1 ); { int i; int size = vector_get_size( vector1 ); for (i=0; i < vector_get_size( vector1 ); i++) test_assert_ptr_equal( vector_iget_const( vector2 , i ) , vector_iget_const( vector1 , size - 1 - i )); } vector_free( vector1 ); vector_free( vector2 ); }
static int well_ts_get_index__( const well_ts_type * well_ts , int report_step , time_t sim_time , bool use_report) { const int size = vector_get_size( well_ts->ts ); if (size == 0) return 0; else { const well_node_type * first_node = vector_iget_const( well_ts->ts , 0 ); const well_node_type * last_node = vector_get_last_const( well_ts->ts ); if (use_report) { if (report_step < first_node->report_nr) return -1; // Before the start if (report_step >= last_node->report_nr) return size - 1; // After end } else { if (sim_time < first_node->sim_time) return -1; // Before the start if (sim_time >= last_node->sim_time) return size - 1; // After end } // Binary search { int lower_index = 0; int upper_index = size - 1; while (true) { int center_index = (lower_index + upper_index) / 2; const well_node_type * center_node = vector_iget_const( well_ts->ts , center_index ); double cmp; if (use_report) cmp = center_node->report_nr - report_step; else cmp = difftime( center_node->sim_time , sim_time ); if (cmp > 0) { if ((center_index - lower_index) == 1) // We found an interval of length 1 return lower_index; else upper_index = center_index; } else { if ((upper_index - center_index) == 1) // We found an interval of length 1 return center_index; else lower_index = center_index; } } } } }
void menu_run(const menu_type * menu) { while (1) { int cmd; menu_display(menu); cmd = menu_read_cmd(menu); if (strchr(menu->quit_keys , cmd) != NULL) /* We have recieved a quit command - leave the building. */ break; /* OK - we start looking through all the available commands to see which this is. */ { int item_index = 0; while (1) { const menu_item_type * item = vector_iget_const(menu->items , item_index); if (!item->separator) { if(!item->helptext) { if (strchr(item->key_set , cmd) != NULL) { /* Calling the function ... */ menu_item_call( item ); break; } } } item_index++; } } } }
int main(int argc , char ** argv) { util_install_signals(); { ecl_grid_type * grid = ecl_grid_alloc( argv[1] ); vector_type * expected = load_expected( grid, argv[2] ); for (int c=0; c < vector_get_size( expected ); c++) { const point_type * p = vector_iget_const( expected , c ); int g = ecl_grid_get_global_index_from_xyz(grid , p->x, p->y , p->z , 0 ); if (g != ecl_grid_get_global_index3(grid, p->i,p->j, p->k)) { int i,j,k; ecl_grid_get_ijk1(grid, g, &i, &j, &k); fprintf(stderr,"point:%d (%g,%g,%g), Simulated: %d:(%d,%d,%d) Expected: %d:(%d,%d,%d) contains:%d\n", c , p->x, p->y, p->z, g, i,j,k, p->g, p->i, p->j, p->k, ecl_grid_cell_contains_xyz1( grid, p->g , p->x , p->y, p->z)); } if (!p->skip) test_assert_int_equal( g , ecl_grid_get_global_index3(grid, p->i,p->j, p->k)); else { if ( g != ecl_grid_get_global_index3(grid, p->i,p->j, p->k)) fprintf(stderr," ** Skipping failed test for point:%d \n",c); } } ecl_grid_free( grid ); vector_free( expected ); } exit(0); }
int ecl_sum_data_get_report_step_from_days(const ecl_sum_data_type * data , double sim_days) { if ((sim_days < data->days_start) || (sim_days > data->sim_length)) return -1; else { int report_step = -1; double_vector_type * days_map = double_vector_alloc( 0 , 0 ); int_vector_type * report_map = int_vector_alloc( 0 , 0 ); int i; for (i=1; i < int_vector_size( data->report_last_index ); i++) { int ministep_index = int_vector_iget( data->report_last_index , i ); const ecl_sum_tstep_type * ministep = vector_iget_const( data->data , ministep_index ); double_vector_iset( days_map , i , ecl_sum_tstep_get_sim_days( ministep )); int_vector_iset( report_map , i , ecl_sum_tstep_get_report( ministep )); } { /** Hmmmm - double == comparison ... */ int index = double_vector_index_sorted( days_map , sim_days ); if (index >= 0) report_step = int_vector_iget( report_map , index ); } int_vector_free( report_map ); double_vector_free( days_map ); return report_step; } }
double ecl_rft_node_iget_grat( const ecl_rft_node_type * rft_node , int index) { assert_type_and_index( rft_node , PLT , index ); { const ecl_rft_cell_type * cell = vector_iget_const( rft_node->cells , index); return ecl_rft_cell_get_grat( cell ); } }
void subst_list_fprintf(const subst_list_type * subst_list , FILE * stream) { int index; for (index=0; index < vector_get_size( subst_list->string_data ); index++) { const subst_list_string_type * node = vector_iget_const( subst_list->string_data , index ); fprintf(stream , "%s = %s\n" , node->key , node->value); } }
int ecl_sum_data_get_report_step_from_time(const ecl_sum_data_type * data , time_t sim_time) { if ((sim_time < data->data_start_time) || (sim_time > data->sim_end)) return -1; { int report_step = -1; time_t_vector_type * time_map = time_t_vector_alloc( 0 , 0 ); int_vector_type * report_map = int_vector_alloc( 0 , 0 ); int i; for (i=1; i < int_vector_size( data->report_last_index ); i++) { int ministep_index = int_vector_iget( data->report_last_index , i ); const ecl_sum_tstep_type * ministep = vector_iget_const( data->data , ministep_index ); time_t_vector_iset( time_map , i , ecl_sum_tstep_get_sim_time( ministep )); int_vector_iset( report_map , i , ecl_sum_tstep_get_report( ministep )); } { int index = time_t_vector_index_sorted( time_map , sim_time ); if (index >= 0) report_step = int_vector_iget( report_map , index ); } int_vector_free( report_map ); time_t_vector_free( time_map ); return report_step; } }
void ensemble_init( ensemble_type * ensemble , config_type * config) { /*1 : Loading ensembles and settings from the config instance */ /*1a: Loading the eclipse summary cases. */ { thread_pool_type * tp = thread_pool_alloc( LOAD_THREADS , true ); { int i,j; for (i=0; i < config_get_occurences( config , "CASE_LIST"); i++) { const stringlist_type * case_list = config_iget_stringlist_ref( config , "CASE_LIST" , i ); for (j=0; j < stringlist_get_size( case_list ); j++) ensemble_load_from_glob( ensemble , stringlist_iget( case_list , j ) , tp); } } thread_pool_join( tp ); thread_pool_free( tp ); } { const sum_case_type * tmp = vector_iget_const( ensemble->data , 0 ); ensemble->refcase = tmp->ecl_sum; } /*1b: Other config settings */ if (config_item_set( config , "NUM_INTERP" )) ensemble->num_interp = config_iget_as_int( config , "NUM_INTERP" , 0 , 0 ); /*2: Remaining initialization */ ensemble_init_time_interp( ensemble ); if (vector_get_size( ensemble->data ) < MIN_SIZE ) util_exit("Sorry - quantiles make no sense with with < %d realizations; should have ~> 100.\n" , MIN_SIZE); }
static void sched_block_fprintf(const sched_block_type * block, FILE * stream) { int i; for (i=0; i < vector_get_size(block->kw_list); i++) { const sched_kw_type * sched_kw = vector_iget_const( block->kw_list , i); sched_kw_fprintf(sched_kw, stream); } }
void obs_vector_install_node(obs_vector_type * obs_vector , int index , void * node) { obs_vector_assert_node_type( obs_vector , node ); { if (vector_iget_const( obs_vector->nodes , index ) == NULL) obs_vector->num_active++; vector_iset_owned_ref( obs_vector->nodes , index , node , obs_vector->freef ); } }
static bool file_map_has_kw_ptr( const file_map_type * file_map, const ecl_kw_type * ecl_kw) { int index; for (index = 0; index < vector_get_size( file_map->kw_list ); index++) { const ecl_file_kw_type * file_kw = vector_iget_const( file_map->kw_list , index ); if (ecl_file_kw_ptr_eq( file_kw , ecl_kw )) return true; } return false; }
const char * subst_list_iget_doc_string( const subst_list_type * subst_list , int index) { if (index < vector_get_size(subst_list->string_data)) { const subst_list_string_type * node = vector_iget_const( subst_list->string_data , index ); return node->doc_string; } else { util_abort("%s: index:%d to large \n",__func__ , index); return NULL; } }
bool local_updatestep_has_data_key( const local_updatestep_type * update_step , const char * key) { bool has_key = false; for (int i = 0; i < vector_get_size( update_step->ministep ); i++) { const local_ministep_type * ministep = vector_iget_const( update_step->ministep , i ); if (local_ministep_has_data_key(ministep, key)) has_key = true; } return has_key; }
const ecl_rft_cell_type * ecl_rft_node_iget_cell_sorted( ecl_rft_node_type * rft_node , int index) { if (ecl_rft_node_is_RFT( rft_node )) return ecl_rft_node_iget_cell( rft_node , index ); else { if (!rft_node->sort_perm_in_sync) ecl_rft_node_create_sort_perm( rft_node ); return vector_iget_const( rft_node->cells , int_vector_iget( rft_node->sort_perm , index )); } }
static void file_map_fprintf_kw_list(const file_map_type * file_map , FILE * stream) { int i; for (i=0; i < vector_get_size( file_map->kw_list ); i++) { const ecl_file_kw_type * file_kw = vector_iget_const( file_map->kw_list , i ); fprintf(stream , "%-8s %7d:%s\n", ecl_file_kw_get_header( file_kw ) , ecl_file_kw_get_size( file_kw ) , ecl_util_get_type_name( ecl_file_kw_get_type( file_kw ))); } }
time_t_vector_type * sched_file_alloc_time_t_vector( const sched_file_type * sched_file ) { time_t_vector_type * vector = time_t_vector_alloc(0,0); int i; time_t_vector_append( vector , sched_file->start_time ); for (i=1; i < vector_get_size( sched_file->blocks ); i++) { const sched_block_type * block = vector_iget_const( sched_file->blocks , i ); time_t_vector_append( vector , block->block_end_time ); } return vector; }
stringlist_type * gen_kw_config_alloc_name_list( const gen_kw_config_type * config ) { stringlist_type * name_list = stringlist_alloc_new(); int i; for (i=0; i < vector_get_size( config->parameters ); i++) { const gen_kw_parameter_type * parameter = vector_iget_const( config->parameters , i ); stringlist_append_ref( name_list , parameter->name ); /* If the underlying parameter goes out scope - whom bang .. */ } return name_list; }
void sched_kw_compdat_fprintf(const sched_kw_compdat_type *kw , FILE *stream) { fprintf(stream , "COMPDAT\n"); { int index; for (index = 0; index < vector_get_size( kw->completions ); index++) { const comp_type * comp = vector_iget_const( kw->completions , index ); comp_sched_fprintf(comp , stream); } } fprintf(stream , "/\n\n"); }
nnc_info_type * nnc_info_alloc_copy( const nnc_info_type * src_info ) { nnc_info_type * copy_info = nnc_info_alloc( src_info->lgr_nr ); int ivec; for (ivec = 0; ivec < vector_get_size( src_info->lgr_list ); ivec++) { nnc_vector_type * copy_vector = nnc_vector_alloc_copy( vector_iget_const( src_info->lgr_list , ivec)); nnc_info_add_vector( copy_info , copy_vector ); } return copy_info; }
bool sched_file_well_open( const sched_file_type * sched_file , int restart_nr , const char * well_name) { bool well_found = false; bool well_open = false; int block_nr = restart_nr; while (!well_found && (block_nr >= 0)) { sched_block_type * block = sched_file_iget_block( sched_file , block_nr ); if (hash_has_key( block->kw_hash , "WCONHIST")) { const vector_type * wconhist_vector = hash_get( block->kw_hash , "WCONHIST"); int i; for (i=0; i < vector_get_size( wconhist_vector ); i++) { const sched_kw_type * kw = vector_iget_const( wconhist_vector , i ); if (sched_kw_has_well( kw , well_name )) { well_found = true; well_open = sched_kw_well_open( kw , well_name ); } } } if (hash_has_key( block->kw_hash , "WCONINJE")) { const vector_type * wconinje_vector = hash_get( block->kw_hash , "WCONINJE"); int i; for (i=0; i < vector_get_size( wconinje_vector ); i++) { const sched_kw_type * kw = vector_iget_const( wconinje_vector , i ); if (sched_kw_has_well( kw , well_name )) { well_found = true; well_open = sched_kw_well_open( kw , well_name ); } } } block_nr--; } return well_open; }
void obs_vector_install_node(obs_vector_type * obs_vector , int index , void * node) { obs_vector_assert_node_type( obs_vector , node ); { if (vector_iget_const( obs_vector->nodes , index ) == NULL) { obs_vector->num_active++; int_vector_append( obs_vector->step_list , index ); int_vector_sort( obs_vector->step_list ); } vector_iset_owned_ref( obs_vector->nodes , index , node , obs_vector->freef ); } }
int obs_vector_get_last_active_step(const obs_vector_type * obs_vector) { int step = vector_get_size( obs_vector->nodes ) - 1; while (true) { const void * obs_node = vector_iget_const( obs_vector->nodes , step ); if (obs_node) break; step--; if (step < 0) break; } return step; }
void rms_tag_fprintf(const rms_tag_type * tag , FILE * stream) { fprintf(stream , " <%s>\n",tag->name); { int i; for (i=0; i < vector_get_size( tag->key_list ); i++) { const rms_tagkey_type * tagkey = vector_iget_const( tag->key_list , i ); rms_tagkey_fprintf( tagkey , stream); } } fprintf(stream , " </%s>\n",tag->name); }
/** Updates the buffer inplace with all the string substitutions in the subst_list. This is the lowest level function, which does *NOT* consider the parent pointer. */ static void subst_list_replace_strings__(const subst_list_type * subst_list , buffer_type * buffer) { int index; for (index = 0; index < vector_get_size( subst_list->string_data ); index++) { const subst_list_string_type * node = vector_iget_const( subst_list->string_data , index ); if (node->value != NULL) { bool match; buffer_rewind( buffer ); do { match = buffer_search_replace( buffer , node->key , node->value); } while (match); } } }
void rms_tag_fwrite(const rms_tag_type * tag , FILE * stream) { rms_util_fwrite_string("tag" , stream); rms_util_fwrite_string(tag->name , stream); { int i; for (i=0; i < vector_get_size( tag->key_list ); i++) { const rms_tagkey_type * tagkey = vector_iget_const( tag->key_list , i ); rms_tagkey_fwrite( tagkey , stream); } } rms_util_fwrite_string("endtag" , stream); }
subst_list_type * subst_list_alloc_deep_copy(const subst_list_type * src) { subst_list_type * copy; if (src->parent != NULL) copy = subst_list_alloc( src->parent ); else copy = subst_list_alloc( src->func_pool); { int index; for (index = 0; index < vector_get_size( src->string_data ); index++) { const subst_list_string_type * node = vector_iget_const( src->string_data , index ); subst_list_insert__( copy , node->key , node->value , node->doc_string , true , SUBST_DEEP_COPY); } for (index = 0; index < vector_get_size( src->func_data ); index++) { const subst_list_func_type * src_node = vector_iget_const( src->func_data , index ); subst_list_func_type * copy_node = subst_list_func_alloc( src_node->name , src_node->func ); vector_append_owned_ref( copy->func_data , copy_node , subst_list_func_free__ ); } } return copy; }
static void menu_display(const menu_type * menu) { int i; int length = strlen(menu->title); for (i = 0; i < vector_get_size(menu->items); i++) { const menu_item_type * item = vector_iget_const( menu->items , i); if(!item->helptext) length = util_int_max(length , item->label_length); if(item->helptext) length = util_int_max(length , 60); /* Hardcoded length for helptext*/ } printf("\n"); __print_line(length + 10 , 0); printf("| "); util_fprintf_string(menu->title , length + 6 , center_pad , stdout); printf(" |\n"); __print_line(length + 10 , 1); for (i=0; i < vector_get_size(menu->items); i++) { const menu_item_type * item = vector_iget_const( menu->items , i); if (item->separator) __print_sep(length + 6); else if (item->helptext) __print_helptext(item->label,length); else { printf("| %c: ", menu_item_get_key( item )); util_fprintf_string(item->label , length + 3 , right_pad , stdout); printf(" |\n"); } } __print_sep(length + 6); printf("| %c: ",menu->quit_keys[0]); util_fprintf_string(menu->quit_label , length + 3 , right_pad , stdout); printf(" |\n"); __print_line(length + 10 , 2); printf("\n"); }
static void subst_list_eval_funcs____(const subst_list_type * subst_list , const parser_type * parser , buffer_type * buffer) { { int index; for (index = 0; index < vector_get_size( subst_list->func_data); index++) { const subst_list_func_type * subst_func = vector_iget_const( subst_list->func_data , index ); const char * func_name = subst_func->name; bool match; buffer_rewind( buffer ); do { size_t match_pos; match = buffer_strstr( buffer , func_name ); match_pos = buffer_get_offset( buffer ); if (match) { bool update = false; char * arg_start = buffer_get_data( buffer ); arg_start += buffer_get_offset( buffer ) + strlen( func_name ); if (arg_start[0] == '(') { /* We require that an opening paren follows immediately behind the function name. */ char * arg_end = strchr( arg_start , ')'); if (arg_end != NULL) { /* OK - we found an enclosing () pair. */ char * arg_content = util_alloc_substring_copy( arg_start, 1 , arg_end - arg_start - 1); stringlist_type * arg_list = parser_tokenize_buffer( parser , arg_content , true); char * func_eval = subst_list_func_eval( subst_func , arg_list ); int old_len = strlen(func_name) + strlen( arg_content) + 2; if (func_eval != NULL) { buffer_memshift( buffer , match_pos + old_len , strlen( func_eval ) - old_len); buffer_fwrite( buffer , func_eval , strlen( func_eval ) , sizeof * func_eval ); free( func_eval ); update = true; } free( arg_content ); stringlist_free( arg_list ); } } if (!update) buffer_fseek( buffer , match_pos + strlen( func_name ) , SEEK_SET); } } while (match); } } if (subst_list->parent != NULL) subst_list_eval_funcs____( subst_list->parent , parser , buffer ); }
bool workflow_run(workflow_type * workflow, void * self , bool verbose , const subst_list_type * context) { vector_clear( workflow->stack ); workflow_try_compile( workflow , context); if (workflow->compiled) { int icmd; for (icmd = 0; icmd < vector_get_size( workflow->cmd_list ); icmd++) { const cmd_type * cmd = vector_iget_const( workflow->cmd_list , icmd ); void * return_value = workflow_job_run( cmd->workflow_job, self , verbose , cmd->arglist ); vector_push_front_ref( workflow->stack , return_value ); } return true; } else return false; }