ecl_grid_cache_type * ecl_grid_cache_alloc( const ecl_grid_type * grid ) { ecl_grid_cache_type * grid_cache = util_malloc( sizeof * grid_cache ); grid_cache->grid = grid; grid_cache->volume = NULL; grid_cache->size = ecl_grid_get_active_size( grid ); grid_cache->xpos = util_calloc( grid_cache->size , sizeof * grid_cache->xpos ); grid_cache->ypos = util_calloc( grid_cache->size , sizeof * grid_cache->ypos ); grid_cache->zpos = util_calloc( grid_cache->size , sizeof * grid_cache->zpos ); grid_cache->global_index = util_calloc( grid_cache->size , sizeof * grid_cache->global_index ); { int active_index; /* Go trough all the active cells and extract the cell center position and store it in xpos/ypos/zpos. */ for (active_index = 0; active_index < grid_cache->size; active_index++) { int global_index = ecl_grid_get_global_index1A( grid , active_index ); grid_cache->global_index[ active_index ] = global_index; ecl_grid_get_xyz1( grid , global_index , &grid_cache->xpos[ active_index ] , &grid_cache->ypos[ active_index ] , &grid_cache->zpos[ active_index ]); } } return grid_cache; }
/* This function creates a string buffer from a file. Furthermore, if the strings in pad_keys are found in the buffer, they are padded with a space before and after. I.e., if the file contains key=value and "=" is in pad_keys, then the buffer will read key = value */ static char * __conf_util_fscanf_alloc_token_buffer( const char * file, const char * comment, int num_pad_keys, const char ** pad_keys) { char * buffer_wrk = basic_parser_fread_alloc_file_content( file , NULL /* quote_set */ , NULL /* delete_set */ , "--" /* Comment start*/ , "\n" /* Comment end */); char ** padded_keys = util_calloc(num_pad_keys , sizeof * padded_keys); for(int key_nr = 0; key_nr < num_pad_keys; key_nr++) { assert(pad_keys[key_nr] != NULL); int key_len = strlen(pad_keys[key_nr]); padded_keys[key_nr] = util_calloc((key_len + 3) , sizeof * padded_keys[key_nr]); padded_keys[key_nr][0] = ' '; for(int i=0; i<key_len; i++) { padded_keys[key_nr][1+i] = pad_keys[key_nr][i]; } padded_keys[key_nr][key_len + 1] = ' '; padded_keys[key_nr][key_len + 2] = '\0'; } char * buffer = util_string_replacen_alloc(buffer_wrk, num_pad_keys, pad_keys, (const char **) padded_keys); free(buffer_wrk); util_free_stringlist(padded_keys, num_pad_keys); return buffer; }
static char * alloc_quoted_token( const char * buffer, int length, bool strip_quote_marks) { char * token; if(!strip_quote_marks) { token = util_calloc( (length + 1) , sizeof * token ); memmove(token, &buffer[0], length * sizeof * token ); token[length] = '\0'; } else { token = util_calloc( (length - 1) , sizeof * token); memmove(token, &buffer[1], (length -1) * sizeof * token); token[length-2] = '\0'; /** Removed escape char before any escaped quotation starts. */ { char expr[3]; char subs[2]; expr[0] = PARSER_ESCAPE_CHAR; expr[1] = buffer[0]; expr[2] = '\0'; subs[0] = buffer[0]; subs[1] = '\0'; util_string_replace_inplace(&token, expr, subs); } } return token; }
static ecl_subsidence_survey_type * ecl_subsidence_survey_alloc_empty(const ecl_subsidence_type * sub, const char * name) { ecl_subsidence_survey_type * survey = util_malloc( sizeof * survey ); UTIL_TYPE_ID_INIT( survey , ECL_SUBSIDENCE_SURVEY_ID ); survey->grid_cache = sub->grid_cache; survey->aquifer_cell = sub->aquifer_cell; survey->name = util_alloc_string_copy( name ); survey->porv = util_calloc( ecl_grid_cache_get_size( sub->grid_cache ) , sizeof * survey->porv ); survey->pressure = util_calloc( ecl_grid_cache_get_size( sub->grid_cache ) , sizeof * survey->pressure ); return survey; }
void plplot_plot_hist( plot_driver_type * driver, const char * label , double_vector_type * x , line_attribute_type line_attr) { int size = double_vector_size( x ); plplot_setup_linestyle( line_attr ); { int bins = (int) sqrt( size ); double xmin = double_vector_get_min( x ); double xmax = double_vector_get_max( x ); { /* Could for some fuxxxing reason not get the plhist() function to work, and had to resort to the low level plbin function. */ double * limits = util_calloc(bins + 1 , sizeof * limits ); double * x_ = util_calloc(bins , sizeof * x_ ); double * y_ = util_calloc(bins , sizeof * y_ ); int i; double delta = (xmax - xmin) / bins; for (i= 0; i <= bins; i++) limits[i] = xmin + i*delta; for (i=0; i < bins; i++) { y_[i] = 0; x_[i] = 0.50 * (limits[i] + limits[i + 1]); } for (i=0; i < size; i++) { double value = double_vector_iget(x , i); int j; for (j = 1; j <= bins; j++) if (value < limits[j]) { y_[j-1]++; break; } } /* for (i = 0; i < bins; i++) printf("x[%d] = %g y[%d] = %g\n",i,x_[i],i,y_[i]); */ plbin(bins , x_ , y_ , PL_BIN_CENTRED + PL_BIN_NOEXPAND); free(x_); free(y_); free(limits); } //plhist(size , double_vector_get_ptr(d->x) , xmin , xmax , bins , 0 /* PL_HIST_DEFAULT */); } }
static double ecl_subsidence_survey_eval_geertsma( const ecl_subsidence_survey_type * base_survey , const ecl_subsidence_survey_type * monitor_survey, ecl_region_type * region , double utm_x , double utm_y , double depth, double youngs_modulus, double poisson_ratio) { const ecl_grid_cache_type * grid_cache = base_survey->grid_cache; const double * cell_volume = ecl_grid_cache_get_volume( grid_cache ); const int size = ecl_grid_cache_get_size( grid_cache ); double scale_factor = 1e4 *(1 + poisson_ratio) * ( 1 - 2*poisson_ratio) / ( 4*M_PI*( 1 - poisson_ratio) * youngs_modulus ); double * weight = util_calloc( size , sizeof * weight ); double deltaz; for (int index = 0; index < size; index++) { if (monitor_survey) { weight[index] = - scale_factor * cell_volume[index] * (monitor_survey->pressure[index] - base_survey->pressure[index]); } else { weight[index] = - scale_factor * cell_volume[index] * (base_survey->pressure[index] ); } } deltaz = ecl_grav_common_eval_geertsma( grid_cache , region , base_survey->aquifer_cell , weight , utm_x , utm_y , depth , poisson_ratio); free( weight ); return deltaz; }
static double ecl_subsidence_survey_eval( const ecl_subsidence_survey_type * base_survey , const ecl_subsidence_survey_type * monitor_survey, ecl_region_type * region , double utm_x , double utm_y , double depth, double compressibility, double poisson_ratio) { const ecl_grid_cache_type * grid_cache = base_survey->grid_cache; const int size = ecl_grid_cache_get_size( grid_cache ); double * weight = util_calloc( size , sizeof * weight ); double deltaz; int index; if (monitor_survey != NULL) { for (index = 0; index < size; index++) weight[index] = base_survey->porv[index] * (base_survey->pressure[index] - monitor_survey->pressure[index]); } else { for (index = 0; index < size; index++) weight[index] = base_survey->porv[index] * base_survey->pressure[index]; } deltaz = compressibility * 31.83099*(1-poisson_ratio) * ecl_grav_common_eval_biot_savart( grid_cache , region , base_survey->aquifer_cell , weight , utm_x , utm_y , depth ); free( weight ); return deltaz; }
void enkf_main_initialize_from_scratch_with_bool_vector(enkf_main_type * enkf_main , const stringlist_type * param_list ,const bool_vector_type * iens_mask , init_mode_type init_mode) { int num_cpu = 4; int ens_size = enkf_main_get_ensemble_size( enkf_main ); thread_pool_type * tp = thread_pool_alloc( num_cpu , true ); arg_pack_type ** arg_list = util_calloc( ens_size , sizeof * arg_list ); int i; int iens; for (iens = 0; iens < ens_size; iens++) { arg_list[iens] = arg_pack_alloc(); if (bool_vector_safe_iget(iens_mask , iens)) { arg_pack_append_ptr( arg_list[iens] , enkf_main ); arg_pack_append_const_ptr( arg_list[iens] , param_list ); arg_pack_append_int( arg_list[iens] , iens ); arg_pack_append_int( arg_list[iens] , init_mode ); thread_pool_add_job( tp , enkf_main_initialize_from_scratch_mt , arg_list[iens]); } } thread_pool_join( tp ); for (i = 0; i < ens_size; i++) { arg_pack_free( arg_list[i] ); } free( arg_list ); thread_pool_free( tp ); }
char * util_alloc_filename(const char * path , const char * basename , const char * extension) { char * file; int length = strlen(basename) + 1; if (path != NULL) length += strlen(path) + 1; if (extension != NULL) length += strlen(extension) + 1; file = util_calloc(length , sizeof * file ); if (path == NULL) { if (extension == NULL) memcpy(file , basename , strlen(basename) + 1); else sprintf(file , "%s.%s" , basename , extension); } else { if (extension == NULL) sprintf(file , "%s%c%s" , path , UTIL_PATH_SEP_CHAR , basename); else sprintf(file , "%s%c%s.%s" , path , UTIL_PATH_SEP_CHAR , basename , extension); } return file; }
char * util_alloc_tmp_file(const char * path, const char * prefix , bool include_pid ) { // Should be reimplemented to use mkstemp() const int pid_digits = 6; const int random_digits = 6; const int random_max = 1000000; #ifdef HAVE_PID_T const int pid_max = 1000000; pid_t pid = getpid() % pid_max; #else int pid = 0; #endif char * file = util_calloc(strlen(path) + 1 + strlen(prefix) + 1 + pid_digits + 1 + random_digits + 1 , sizeof * file ); char * tmp_prefix = util_alloc_string_copy( prefix ); if (!util_is_directory(path)) util_make_path(path); util_string_tr( tmp_prefix , UTIL_PATH_SEP_CHAR , '_'); /* removing path seps. */ do { long int rand_int = rand() % random_max; if (include_pid) sprintf(file , "%s%c%s-%d-%ld" , path , UTIL_PATH_SEP_CHAR , tmp_prefix , pid , rand_int); else sprintf(file , "%s%c%s-%ld" , path , UTIL_PATH_SEP_CHAR , tmp_prefix , rand_int); } while (util_file_exists(file)); free( tmp_prefix ); return file; }
static int _themeParseTextureEntry(const char *json, jsmntok_t *tokens, const char *name, void *context) { flubGuiTheme_t *theme = (flubGuiTheme_t *)context; _jsonTextureEntry_t entry; flubGuiThemeTexture_t *texture; int red = 0; int green = 0; int blue = 0; memset(&entry, 0, sizeof(_jsonTextureEntry_t)); if(!jsonParseToStruct(json, tokens, _themeTextureParseMap, "Theme texture entry", &entry, _jsonTextureCleanup)) { return 0; } texture = util_calloc(sizeof(flubGuiThemeTexture_t), 0, NULL); texture->type = eFlubGuiThemeTexture; texture->id = entry.id; if(entry.colorkey != NULL) { parseColor(entry.colorkey, &red, &green, &blue, NULL); } if((texture->texture = texmgrLoad(entry.filename, NULL, entry.minfilter, entry.magfilter, ((entry.colorkey != NULL) ? 1 : 0), red, green, blue)) == NULL) { _jsonTextureCleanup(&entry); util_free(texture); return 0; } critbitInsert(&theme->textures, name, texture, NULL); _flubGuiThemeIndexAdd(theme, entry.id, texture); debugf(DBG_GUI, DBG_GUI_DTL_THEME, "Found texture \"%s\" as %d, file [%s], %s %s %s", name, entry.id, entry.filename, texmgrGLMinFilterStr(entry.minfilter), texmgrGLMagFilterStr(entry.magfilter), ((entry.colorkey == NULL) ? "No colorkey" : entry.colorkey)); _jsonTextureCleanup(&entry); return 1; }
static int _themeParseFontEntry(const char *json, jsmntok_t *tokens, const char *name, void *context) { flubGuiTheme_t *theme = (flubGuiTheme_t *)context; _jsonFontEntry_t entry; flubGuiThemeFont_t *font; memset(&entry, 0, sizeof(_jsonFontEntry_t)); if(!jsonParseToStruct(json, tokens, _themeFontParseMap, "Theme font entry", &entry, _jsonFontCleanup)) { return 0; } font = util_calloc(sizeof(flubGuiThemeFont_t), 0, NULL); font->type = eFlubGuiThemeFont; font->id = entry.id; if(entry.filename != NULL) { if(!flubFontLoad(entry.filename)) { _jsonFontCleanup(&entry); util_free(font); return 0; } } if((font->font = fontGet(entry.font, entry.size, 0)) == NULL) { _jsonFontCleanup(&entry); util_free(font); return 0; } critbitInsert(&theme->fonts, name, font, NULL); _flubGuiThemeIndexAdd(theme, entry.id, font); debugf(DBG_GUI, DBG_GUI_DTL_THEME, "Found font \"%s\" as %d, file [%s], %s size %d", name, entry.id, entry.filename, entry.font, entry.size); _jsonFontCleanup(&entry); return 1; }
static int _themeParseColorEntry(const char *json, jsmntok_t *tokens, const char *name, void *context) { flubGuiTheme_t *theme = (flubGuiTheme_t *)context; _jsonColorEntry_t entry; flubGuiThemeColor_t *color; int red; int green; int blue; memset(&entry, 0, sizeof(_jsonColorEntry_t)); if(!jsonParseToStruct(json, tokens,_themeColorParseMap, "Theme color entry", &entry, _jsonColorCleanup)) { return 0; } color = util_calloc(sizeof(flubGuiThemeColor_t), 0, NULL); color->type = eFlubGuiThemeColor; color->id = entry.id; parseColor(entry.color, &red, &green, &blue, NULL); color->red = COLOR_ITOF(red); color->green = COLOR_ITOF(green); color->blue = COLOR_ITOF(blue); critbitInsert(&theme->colors, name, color, NULL); _flubGuiThemeIndexAdd(theme, entry.id, color); _jsonColorCleanup(&entry); debugf(DBG_GUI, DBG_GUI_DTL_THEME, "Found color \"%s\" as %d, value #%02x%02x%02x", name, entry.id, red, green, blue); return 1; }
static int ecl_util_get_num_parallel_cpu__(parser_type* parser, FILE* stream, const char * data_file) { int num_cpu = 1; char * buffer; long int start_pos = util_ftell( stream ); int buffer_size; /* Look for terminating '/' */ if (!parser_fseek_string( parser , stream , "/" , false , true)) util_abort("%s: sorry - could not find \"/\" termination of PARALLEL keyword in data_file: \n",__func__ , data_file); buffer_size = (util_ftell(stream) - start_pos) ; buffer = util_calloc( buffer_size + 1 , sizeof * buffer ); util_fseek( stream , start_pos , SEEK_SET); util_fread( buffer , sizeof * buffer , buffer_size ,stream , __func__); buffer[buffer_size] = '\0'; { stringlist_type * tokens = parser_tokenize_buffer( parser , buffer , true ); if (stringlist_get_size( tokens ) > 0) { const char * num_cpu_string = stringlist_iget( tokens , 0 ); if (!util_sscanf_int( num_cpu_string , &num_cpu)) fprintf(stderr,"** Warning: failed to interpret:%s as integer - assuming one CPU\n",num_cpu_string); } else fprintf(stderr,"** Warning: failed to load data for PARALLEL keyword - assuming one CPU\n"); stringlist_free( tokens ); } free( buffer ); return num_cpu; }
void create_submit_script_script_according_to_input() { char ** args = util_calloc(2, sizeof * args); args[0] = "/tmp/jaja/"; args[1] = "number2arg"; char * script_filename = util_alloc_filename("/tmp/", "qsub_script", "sh"); torque_job_create_submit_script(script_filename, "job_program.py", 2, (const char **) args); printf("Create submit script OK\n"); FILE* file_stream = util_fopen(script_filename, "r"); bool at_eof = false; char * line = util_fscanf_alloc_line(file_stream, &at_eof); test_assert_string_equal("#!/bin/sh", line); free(line); line = util_fscanf_alloc_line(file_stream, &at_eof); test_assert_string_equal("job_program.py /tmp/jaja/ number2arg", line); free(line); line = util_fscanf_alloc_line(file_stream, &at_eof); free(line); test_assert_true(at_eof); fclose(file_stream); }
void matrix_dgeqrf(matrix_type * A , double * tau) { int lda = matrix_get_column_stride( A ); int m = matrix_get_rows( A ); int n = matrix_get_columns( A ); double * work = util_calloc(1 , sizeof * work ); int worksize; int info; /* Determine optimal worksize. */ worksize = -1; dgeqrf_(&m , &n , matrix_get_data( A ), &lda , tau , work , &worksize , &info); if (info != 0) util_abort("%s: dgerqf routine failed with info:%d \n",__func__ , info); worksize = ( int ) work[0]; { double * tmp = realloc(work , sizeof * work * worksize ); if (tmp == NULL) { /* OK - we could not get the optimal worksize, try again with the minimum. */ worksize = n; work = util_realloc(work , sizeof * work * worksize ); } else work = tmp; /* The request for optimal worksize succeeded */ } /* Second call - do the actual computation. */ dgeqrf_(&m , &n , matrix_get_data( A ), &lda , tau , work , &worksize , &info); if (info != 0) util_abort("%s: dgerqf routine failed with info:%d \n",__func__ , info); free( work ); }
void create_submit_script_script_according_to_input() { test_work_area_type * work_area = test_work_area_alloc("job_torque_test" , true); const char * script_filename = "qsub_script.sh"; { char ** args = util_calloc(2, sizeof * args); args[0] = "/tmp/jaja/"; args[1] = "number2arg"; torque_job_create_submit_script(script_filename, "job_program.py", 2, (const char **) args); free( args ); } { FILE* file_stream = util_fopen(script_filename, "r"); bool at_eof = false; char * line = util_fscanf_alloc_line(file_stream, &at_eof); test_assert_string_equal("#!/bin/sh", line); free(line); line = util_fscanf_alloc_line(file_stream, &at_eof); test_assert_string_equal("job_program.py /tmp/jaja/ number2arg", line); free(line); line = util_fscanf_alloc_line(file_stream, &at_eof); free(line); test_assert_true(at_eof); fclose(file_stream); } test_work_area_free( work_area ); }
widget_t *widgetCreate(int id, int type, int x, int y, int width, int height, unsigned int flags, flubGuiTheme_t *theme, widgetHandlers_t *handlers, layoutNode_t *layout, int dataSize) { widget_t *widget; widget = util_calloc(sizeof(widget_t) + dataSize, 0, NULL); widget->id = id; widget->type = type; widget->x = x; widget->y = y; widget->handlers = handlers; if((widget->handlers != NULL) && (widget->handlers->init != NULL)) { widget->handlers->init(widget); } widgetThemeApply(widget, theme); widgetAddToLayout(widget, layout); if((widget->handlers != NULL) && (widget->handlers->state != NULL)) { widget->handlers->state(widget, 1, flags); } widgetResize(widget, width, height); return widget; }
static void validate_set_argc_minmax(validate_type * validate , int argc_min , int argc_max) { if (validate->argc_min != CONFIG_DEFAULT_ARG_MIN) util_abort("%s: sorry - current implementation does not allow repeated calls to: %s \n",__func__ , __func__); if (argc_min == CONFIG_DEFAULT_ARG_MIN) argc_min = 0; validate->argc_min = argc_min; validate->argc_max = argc_max; if ((argc_max != CONFIG_DEFAULT_ARG_MAX) && (argc_max < argc_min)) util_abort("%s invalid arg min/max values. argc_min:%d argc_max:%d \n",__func__ , argc_min , argc_max); { int internal_type_size = 0; /* Should end up in the range [argc_min,argc_max] */ if (argc_max > 0) internal_type_size = argc_max; else internal_type_size = argc_min; if (internal_type_size > 0) { validate->indexed_selection_set = util_calloc( internal_type_size , sizeof * validate->indexed_selection_set ); for (int iarg=0; iarg < internal_type_size; iarg++) validate->indexed_selection_set[iarg] = NULL; } } }
@TYPE@ * @TYPE@_vector_alloc_data_copy( const @TYPE@_vector_type * vector ) { int size = vector->size * sizeof ( @TYPE@ ); @TYPE@ * copy = util_calloc(vector->size , sizeof * copy ); if (copy != NULL) memcpy( copy , vector->data , size); return copy; }
void sqrt_enkf_initX(void * module_data , matrix_type * X , matrix_type * A , matrix_type * S , matrix_type * R , matrix_type * dObs , matrix_type * E , matrix_type *D ) { sqrt_enkf_data_type * data = sqrt_enkf_data_safe_cast( module_data ); { int ncomp = std_enkf_get_subspace_dimension( data->std_data ); double truncation = std_enkf_get_truncation( data->std_data ); int nrobs = matrix_get_rows( S ); int ens_size = matrix_get_columns( S ); int nrmin = util_int_min( ens_size , nrobs); matrix_type * W = matrix_alloc(nrobs , nrmin); double * eig = util_calloc( nrmin , sizeof * eig ); matrix_subtract_row_mean( S ); /* Shift away the mean */ enkf_linalg_lowrankCinv( S , R , W , eig , truncation , ncomp); enkf_linalg_init_sqrtX( X , S , data->randrot , dObs , W , eig , false); matrix_free( W ); free( eig ); enkf_linalg_checkX( X , false ); } }
int * int_vector_alloc_data_copy( const int_vector_type * vector ) { int size = vector->size * sizeof ( int ); int * copy = util_calloc(vector->size , sizeof * copy ); if (copy != NULL) memcpy( copy , vector->data , size); return copy; }
static void smspec_node_set_lgr_ijk( smspec_node_type * index , int lgr_i , int lgr_j , int lgr_k) { if (index->lgr_ijk == NULL) index->lgr_ijk = (int*)util_calloc( 3 , sizeof * index->lgr_ijk ); index->lgr_ijk[0] = lgr_i; index->lgr_ijk[1] = lgr_j; index->lgr_ijk[2] = lgr_k; }
gen_kw_type * gen_kw_alloc(const gen_kw_config_type * config) { gen_kw_type * gen_kw = util_malloc(sizeof *gen_kw ); gen_kw->__type_id = GEN_KW; gen_kw->config = config; gen_kw->subst_list = subst_list_alloc( NULL ); gen_kw->data = util_calloc( gen_kw_config_get_data_size( config ) , sizeof * gen_kw->data ); return gen_kw; }
static void _flubGuiThemeIndexAdd(flubGuiTheme_t *theme, int id, void *ptr) { int count; count = (((id + 1) / 1024) + 1) * 1024; if(theme->idMap == NULL) { debug(DBG_GUI, DBG_GUI_DTL_THEME, "Initializing gui theme index to 1024 entries."); theme->idMap = util_calloc((sizeof(void *) * count), 0, NULL); theme->maxId = count; } else if(id >= theme->maxId) { debugf(DBG_GUI, DBG_GUI_DTL_THEME, "Resizing gui theme index to %d entries.", theme->maxId); theme->idMap = util_calloc((sizeof(void *) * count), theme->maxId, theme->idMap); theme->maxId = count; } theme->idMap[id] = ptr; }
void parser_strip_buffer(const parser_type * parser , char ** __buffer) { char * src = *__buffer; char * target = util_calloc( ( strlen( *__buffer ) + 1) , sizeof * target ); int src_position = 0; int target_position = 0; while (src_position < strlen( src )) { int comment_length; int delete_length; /** Skip comments. */ comment_length = length_of_comment( &src[src_position], parser); if(comment_length > 0) { src_position += comment_length; continue; } /** Skip characters which are just deleted. */ delete_length = length_of_delete( &src[src_position] , parser ); if (delete_length > 0) { src_position += delete_length; continue; } /* Quotations. */ if( is_in_quoters( src[src_position], parser ) ) { int length = length_of_quotation( &src[src_position] ); char * token = alloc_quoted_token( &src[src_position], length, false ); memcpy( &target[target_position] , &src[src_position] , length); free( token ); src_position += length; target_position += length; continue; } /** OK -it is a god damn normal charactar - copy it straight over: */ target[target_position] = src[src_position]; src_position += 1; target_position += 1; } target[target_position] = '\0'; target = util_realloc( target , sizeof * target * (target_position + 1) ); free( src ); *__buffer = target; }
int main(int argc , char ** argv) { test_install_SIGNALS(); double * rseg_data = util_calloc( 100 , sizeof * rseg_data ); well_segment_collection_type * sc = well_segment_collection_alloc(); test_assert_not_NULL( sc ); test_assert_int_equal( well_segment_collection_get_size( sc ) , 0 ); { int outlet_segment_id = ECLIPSE_WELL_SEGMENT_OUTLET_END_VALUE; int branch_nr = ECLIPSE_WELL_SEGMENT_BRANCH_INACTIVE_VALUE; well_segment_type * ws = well_segment_alloc(89 , outlet_segment_id , branch_nr, rseg_data); well_segment_collection_add( sc , ws ); test_assert_int_equal( well_segment_collection_get_size( sc ) , 1); test_assert_ptr_equal( well_segment_collection_iget( sc , 0 ) , ws ); test_assert_false( well_segment_collection_has_segment( sc , 451 )); test_assert_true( well_segment_collection_has_segment( sc , 89 )); test_assert_ptr_equal( well_segment_collection_get( sc , 89 ) , ws ); } { int outlet_segment_id = ECLIPSE_WELL_SEGMENT_OUTLET_END_VALUE; int branch_nr = ECLIPSE_WELL_SEGMENT_BRANCH_INACTIVE_VALUE; well_segment_type * ws = well_segment_alloc(90 , outlet_segment_id , branch_nr , rseg_data); well_segment_collection_add( sc , ws ); test_assert_int_equal( well_segment_collection_get_size( sc ) , 2); test_assert_ptr_equal( well_segment_collection_iget( sc , 1 ) , ws ); test_assert_false( well_segment_collection_has_segment( sc , 451 )); test_assert_true( well_segment_collection_has_segment( sc , 89 )); test_assert_true( well_segment_collection_has_segment( sc , 90 )); test_assert_ptr_equal( well_segment_collection_get( sc , 90 ) , ws ); test_assert_NULL( well_segment_collection_get( sc , 76 )); } { int outlet_segment_id = ECLIPSE_WELL_SEGMENT_OUTLET_END_VALUE; int branch_nr = ECLIPSE_WELL_SEGMENT_BRANCH_INACTIVE_VALUE; well_segment_type * ws = well_segment_alloc(89 , outlet_segment_id , branch_nr, rseg_data); well_segment_collection_add( sc , ws ); test_assert_int_equal( well_segment_collection_get_size( sc ) , 2); test_assert_ptr_equal( well_segment_collection_iget( sc , 0 ) , ws ); test_assert_false( well_segment_collection_has_segment( sc , 451 )); test_assert_true( well_segment_collection_has_segment( sc , 89 )); test_assert_ptr_equal( well_segment_collection_get( sc , 89 ) , ws ); } free( rseg_data ); well_segment_collection_free( sc ); exit(0); }
void vector_permute(vector_type * vector , const int_vector_type * perm_vector) { node_data_type ** new_data = (node_data_type**)util_calloc( vector->size , sizeof * new_data ); for (int index = 0; index < vector->size; index++) { int perm_index = int_vector_iget( perm_vector , index ); new_data[index] = vector->data[ perm_index ]; } free(vector->data); vector->data = new_data; }
static bool util_addr2line_lookup__(const void * bt_addr , char ** func_name , char ** file_name , int * line_nr, bool subtract_base_adress) { *func_name = NULL; // If dladdr() succeeds, but addr2line fails the func_name pointer will be set, but the function will return false anyway. *file_name = NULL; *line_nr = 0; { bool address_found = false; Dl_info dl_info; #if defined(__APPLE__) return false; #else if (dladdr(bt_addr , &dl_info)) { const char * executable = dl_info.dli_fname; *func_name = util_alloc_string_copy( dl_info.dli_sname ); if (util_file_exists( executable )) { char *stdout_file = util_alloc_tmp_file("/tmp" , "addr2line" , true); /* 1: Run addr2line application */ { char ** argv = util_calloc(3 , sizeof * argv ); argv[0] = util_alloc_string_copy("--functions"); argv[1] = util_alloc_sprintf("--exe=%s" , executable ); { char * rel_address = (char *) bt_addr; if (subtract_base_adress) rel_address -= (size_t) dl_info.dli_fbase; argv[2] = util_alloc_sprintf("%p" , (void *) rel_address); } util_spawn_blocking("addr2line", 3, (const char **) argv, stdout_file, NULL); util_free_stringlist(argv , 3); } /* 2: Parse stdout output */ { bool at_eof; FILE * stream = util_fopen(stdout_file , "r"); char * tmp_fname = util_fscanf_alloc_line(stream , &at_eof); if (strcmp(tmp_fname , UNDEFINED_FUNCTION) != 0) { char * stdout_file_name = util_fscanf_alloc_line(stream , &at_eof); char * line_string = NULL; util_binary_split_string( stdout_file_name , ":" , false , file_name , &line_string); if (line_string && util_sscanf_int( line_string , line_nr)) address_found = true; free( stdout_file_name ); util_safe_free( line_string ); } free( tmp_fname ); fclose(stream); } util_unlink_existing(stdout_file); free( stdout_file ); } } return address_found; #endif } }
static ecl_sum_tstep_type * ecl_sum_tstep_alloc( int report_step , int ministep_nr , const ecl_smspec_type * smspec) { ecl_sum_tstep_type * tstep = util_malloc( sizeof * tstep ); UTIL_TYPE_ID_INIT( tstep , ECL_SUM_TSTEP_ID); tstep->smspec = smspec; tstep->report_step = report_step; tstep->ministep = ministep_nr; tstep->data_size = ecl_smspec_get_params_size( smspec ); tstep->data = util_calloc( tstep->data_size , sizeof * tstep->data ); return tstep; }