Ejemplo n.º 1
0
ecl_rft_node_type * ecl_rft_node_alloc_new(const char * well_name, const char * data_type_string, const time_t recording_date, const double days){
    ecl_rft_enum data_type = translate_from_sting_to_ecl_rft_enum(data_type_string);
    ecl_rft_node_type * rft_node = util_malloc(sizeof * rft_node );
    UTIL_TYPE_ID_INIT( rft_node , ECL_RFT_NODE_ID );
    rft_node->well_name = util_alloc_string_copy(well_name);
    rft_node->cells = vector_alloc_new();
    rft_node->recording_date = recording_date;
    rft_node->days = days;
    rft_node->data_type = data_type;
    rft_node->sort_perm = NULL;
    rft_node->sort_perm_in_sync = false;

    return rft_node;
}
Ejemplo n.º 2
0
void sched_kw_gruptree_alloc_child_parent_list(const sched_kw_gruptree_type * kw, char *** __children, char *** __parents, int * num_pairs)
{
  *num_pairs = hash_get_size(kw->gruptree_hash);
  char ** children = hash_alloc_keylist(kw->gruptree_hash);
  char ** parents  = util_malloc(*num_pairs * sizeof * parents);

  for(int child_nr = 0; child_nr < *num_pairs; child_nr++)
  {
    parents[child_nr] = util_alloc_string_copy(hash_get_string(kw->gruptree_hash, children[child_nr]));
  }

  *__children = children;
  *__parents  = parents;
}
Ejemplo n.º 3
0
obs_vector_type * obs_vector_alloc(obs_impl_type obs_type , const char * obs_key , enkf_config_node_type * config_node, int num_reports) {
  obs_vector_type * vector = util_malloc(sizeof * vector );

  UTIL_TYPE_ID_INIT( vector , OBS_VECTOR_TYPE_ID);
  vector->freef      = NULL;
  vector->measure    = NULL;
  vector->get_obs    = NULL;
  vector->user_get   = NULL;
  vector->chi2       = NULL;
  vector->update_std_scale  = NULL;
  vector->step_list  = int_vector_alloc(0,0);

  switch (obs_type) {
  case(SUMMARY_OBS):
    vector->freef      	      = summary_obs_free__;
    vector->measure    	      = summary_obs_measure__;
    vector->get_obs    	      = summary_obs_get_observations__;
    vector->user_get   	      = summary_obs_user_get__;
    vector->chi2       	      = summary_obs_chi2__;
    vector->update_std_scale  = summary_obs_update_std_scale__;
    break;
  case(BLOCK_OBS):
    vector->freef      	      = block_obs_free__;
    vector->measure    	      = block_obs_measure__;
    vector->get_obs    	      = block_obs_get_observations__;
    vector->user_get   	      = block_obs_user_get__;
    vector->chi2       	      = block_obs_chi2__;
    vector->update_std_scale  = block_obs_update_std_scale__;
    break;
  case(GEN_OBS):
    vector->freef      	      = gen_obs_free__;
    vector->measure    	      = gen_obs_measure__;
    vector->get_obs    	      = gen_obs_get_observations__;
    vector->user_get   	      = gen_obs_user_get__;
    vector->chi2       	      = gen_obs_chi2__;
    vector->update_std_scale  = gen_obs_update_std_scale__;
    break;
  default:
    util_abort("%s: internal error - obs_type:%d not recognized \n",__func__ , obs_type);
  }

  vector->obs_type           = obs_type;
  vector->config_node        = config_node;
  vector->obs_key            = util_alloc_string_copy( obs_key );
  vector->num_active         = 0;
  vector->nodes              = vector_alloc_new();
  obs_vector_resize(vector , num_reports + 1); /* +1 here ?? Ohh  - these +/- problems. */

  return vector;
}
Ejemplo n.º 4
0
char * ert_run_context_alloc_runpath( int iens , path_fmt_type * runpath_fmt , subst_list_type * subst_list , int iter) {
  char * runpath;
  {
    char * first_pass = path_fmt_alloc_path(runpath_fmt , false , iens, iter);    /* 1: Replace first %d with iens, if a second %d replace with iter */

    if (subst_list)
      runpath = subst_list_alloc_filtered_string( subst_list , first_pass );         /* 2: Filter out various magic strings like <CASE> and <CWD>. */
    else
      runpath = util_alloc_string_copy( first_pass );

    free( first_pass );
  }
  return runpath;
}
Ejemplo n.º 5
0
ensemble_config_type * ensemble_config_alloc( ) {
  ensemble_config_type * ensemble_config = util_malloc(sizeof * ensemble_config );

  UTIL_TYPE_ID_INIT( ensemble_config , ENSEMBLE_CONFIG_TYPE_ID );
  ensemble_config->config_nodes          = hash_alloc();
  ensemble_config->field_trans_table     = field_trans_table_alloc();
  ensemble_config->refcase               = NULL;
  ensemble_config->gen_kw_format_string  = util_alloc_string_copy( DEFAULT_GEN_KW_TAG_FORMAT );
  ensemble_config->have_forward_init     = false;
  ensemble_config->summary_key_matcher   = summary_key_matcher_alloc();
  pthread_mutex_init( &ensemble_config->mutex , NULL);

  return ensemble_config;
}
Ejemplo n.º 6
0
void ensemble_load_from_glob( ensemble_type * ensemble , const char * pattern , thread_pool_type * tp) {
  glob_t pglob;
  int    i;
  glob( pattern , GLOB_NOSORT , NULL , &pglob );

  for (i=0; i < pglob.gl_pathc; i++) {
    arg_pack_type * arg_pack = arg_pack_alloc( );
    arg_pack_append_ptr( arg_pack , ensemble );
    arg_pack_append_owned_ptr( arg_pack , util_alloc_string_copy( pglob.gl_pathv[i] ) , free );
    thread_pool_add_job( tp , ensemble_add_case__ , arg_pack );
  }

  globfree( &pglob );
}
Ejemplo n.º 7
0
char * util_alloc_parent_path( const char * path) {
  int     path_ncomp;
  char ** path_component_list;
  char *  parent_path = NULL;

  if (path) {
    bool is_abs = util_is_abs_path( path );
    char * work_path;
    
    if (strstr(path , "..")) {
      if (is_abs) 
        work_path = util_alloc_realpath__( path );
      else {
        char * abs_path = util_alloc_realpath__( path );
        char * cwd = util_alloc_cwd();
        work_path = util_alloc_rel_path( cwd , abs_path );
        free( abs_path );
        free( cwd );
      }
    } else
      work_path = util_alloc_string_copy( path );
    
    util_path_split( work_path , &path_ncomp , &path_component_list );
    if (path_ncomp > 0) {
      int current_length = 4;
      int ip;

      parent_path = util_realloc( parent_path , current_length * sizeof * parent_path);
      parent_path[0] = '\0';
  
      for (ip=0; ip < path_ncomp - 1; ip++) {
        const char * ipath = path_component_list[ip];
        int min_length = strlen(parent_path) + strlen(ipath) + 1;
    
        if (min_length >= current_length) {
          current_length = 2 * min_length;
          parent_path = util_realloc( parent_path , current_length * sizeof * parent_path);
        }

        if (is_abs || (ip > 0))
          strcat( parent_path , UTIL_PATH_SEP_STRING );
        strcat( parent_path , ipath );
      }
    }
    util_free_stringlist( path_component_list , path_ncomp );
    free( work_path );
  }
  return parent_path;
}
Ejemplo n.º 8
0
static point_obs_type * point_obs_alloc( block_obs_source_type   source_type , int i , int j , int k , int active_index , char * sum_key , double value , double std) {
  point_obs_type * point_obs = util_malloc( sizeof * point_obs );
  UTIL_TYPE_ID_INIT( point_obs , POINT_OBS_TYPE_ID );
  point_obs->source_type  = source_type;
  point_obs->i            = i;
  point_obs->j            = j;
  point_obs->k            = k;       
  point_obs->active_index = active_index;
  point_obs->value        = value;
  point_obs->std          = std;
  point_obs->sum_key      = util_alloc_string_copy( sum_key );
  
  
  return point_obs;
}
Ejemplo n.º 9
0
static plplot_state_type * plplot_state_alloc( const void * init_arg ) {
  plplot_state_type * state = util_malloc( sizeof * state );
  state->stream     = 0;
  {
    const arg_pack_type * arg_pack = arg_pack_safe_cast_const( init_arg );
    state->filename                = util_alloc_string_copy( arg_pack_iget_const_ptr( arg_pack , 0) );
    state->device                  = util_alloc_string_copy( arg_pack_iget_const_ptr( arg_pack , 1) );
    
    plsstrm(state->stream);
    plsdev(state->device);    /* Can this be NULL?? */
    if (strcmp(state->device , "xwin") != 0)
      plsfnam(state->filename);
  }
  state->logx       = false;
  state->logy       = false;
  state->plbox_xopt = util_alloc_string_copy( PLOT_DEFAULT_PLBOX_XOPT );
  state->plbox_yopt = util_alloc_string_copy( PLOT_DEFAULT_PLBOX_YOPT );
  /** This color initialization must be here - do not really understand what for. */
  plscol0(WHITE, 255, 255, 255);
  plscol0(BLACK, 0, 0, 0);
  plfontld(0);
  //plinit();
  return state;
}
Ejemplo n.º 10
0
config_schema_item_type * config_schema_item_alloc(const char * kw , bool required) {
  config_schema_item_type * item = util_malloc(sizeof * item );
  UTIL_TYPE_ID_INIT( item , CONFIG_SCHEMA_ITEM_ID);
  item->kw         = util_alloc_string_copy(kw);

  item->required_set            = required;
  item->deprecated             = false;
  item->deprecate_msg           = NULL;
  item->required_children       = NULL;
  item->required_children_value = NULL;
  item->expand_envvar           = true;  /* Default is to expand $VAR expressions; can be turned off with
                                            config_schema_item_set_envvar_expansion( item , false ); */
  item->validate                = validate_alloc();
  return item;
}
Ejemplo n.º 11
0
void enkf_tui_fs_copy_ensemble_of_parameters(void * arg)
{
  int prompt_len = 35;
  char * source_case;
  
  int last_report;
  int report_step_from;
  char * report_step_from_as_char;
  int report_step_to;
  state_enum state_from;
  state_enum state_to;
  
  enkf_main_type * enkf_main = enkf_main_safe_cast( arg );
  
  source_case = util_alloc_string_copy(enkf_main_get_current_fs( enkf_main ));
  last_report  = enkf_main_get_history_length( enkf_main );
  
  report_step_from_as_char = util_scanf_int_with_limits_return_char("Source report step",prompt_len , 0 , last_report);
  if(strlen(report_step_from_as_char) !=0){
    util_sscanf_int(report_step_from_as_char , &report_step_from);
    state_from = enkf_tui_util_scanf_state("Source analyzed/forecast [a|f]" , prompt_len , false);
    if(state_from != UNDEFINED){

      util_printf_prompt("Target case" , prompt_len , '=' , "=> ");
      char target_case[256];

      if ( fgets(target_case, prompt_len, stdin) ) {
        char *newline = strchr(target_case, '\n');
        if (newline)
          *newline = 0;
      }

      if (strlen(target_case)) {
        char * report_step_to_as_char = util_scanf_int_with_limits_return_char("Target report step",prompt_len , 0 , last_report);
        if(strlen(report_step_to_as_char) !=0){
          util_sscanf_int(report_step_to_as_char , &report_step_to);
          state_to       = enkf_tui_util_scanf_state("Target analyzed/forecast [a|f]" , prompt_len , false);
          if(state_to != UNDEFINED){
            enkf_tui_fs_copy_ensemble__(enkf_main, source_case, target_case, report_step_from, state_from, report_step_to, state_to, true);
          }
        }
        free(report_step_to_as_char);
      }
    }
  }
  free(source_case);
  free(report_step_from_as_char);
}
Ejemplo n.º 12
0
menu_item_type * menu_add_item(menu_type * menu , const char * label , const char * key_set , menu_func_type * func, void * arg , arg_free_ftype * free_arg) {
    if (__string_contains(menu->complete_key_set , key_set))
        util_abort("%s:fatal error when building menu - key(s) in:%s already in use \n",__func__ , key_set);
    {
        menu_item_type * item = menu_item_alloc_empty();
        item->key_set = util_alloc_string_copy(key_set);
        item->func    = func;
        item->arg     = arg;
        item->separator = false;
        item->helptext = false;
        item->free_arg  = free_arg;
        menu_append_item__(menu , item);
        menu_item_set_label(item , label);
        menu->complete_key_set = util_strcat_realloc(menu->complete_key_set , key_set);
        return item;
    }
}
Ejemplo n.º 13
0
Archivo: ecl_sum.c Proyecto: flikka/ert
static ecl_sum_type * ecl_sum_alloc__( const char * input_arg , const char * key_join_string) {
  ecl_sum_type * ecl_sum = util_malloc( sizeof * ecl_sum );
  UTIL_TYPE_ID_INIT( ecl_sum , ECL_SUM_ID );

  ecl_sum->ecl_case  = NULL;
  ecl_sum->path      = NULL;
  ecl_sum->base      = NULL;
  ecl_sum->ext       = NULL;
  ecl_sum->abs_path  = NULL;
  ecl_sum_set_case( ecl_sum , input_arg );
  ecl_sum->key_join_string = util_alloc_string_copy( key_join_string );

  ecl_sum->smspec = NULL;
  ecl_sum->data   = NULL;

  return ecl_sum;
}
Ejemplo n.º 14
0
static void enkf_tui_ranking_create_obs( void * arg ) {
  enkf_main_type    * enkf_main       = enkf_main_safe_cast( arg );  
  enkf_obs_type     * enkf_obs        = enkf_main_get_obs( enkf_main );
  enkf_fs_type      * fs              = enkf_main_get_fs( enkf_main );
  misfit_ensemble_type * misfit_ensemble    = enkf_fs_get_misfit_ensemble( fs );
  
  if (!misfit_ensemble_initialized( misfit_ensemble )) {
    fprintf(stderr,"Sorry: must initialzie the misfit table first \n");
    return;
  } else {
    ranking_table_type * ranking_table = enkf_main_get_ranking_table( enkf_main );
    const int history_length    = enkf_main_get_history_length( enkf_main );
    const int    prompt_len = 50;
    const char * prompt1      = "Observations to use for ranking";
    const char * prompt2      = "Name to store ranking under";
    const char * store_prompt = "Name of file to store ranking";
    int step1,step2;
    stringlist_type * ranking_keys;
    char * obs_keys_input;
    char * ranking_key;
    char * ranking_file;
    util_printf_prompt(prompt1 , prompt_len , '=' , "=> ");
    obs_keys_input = util_alloc_stdin_line();
    ranking_keys   = enkf_obs_alloc_matching_keylist( enkf_obs , obs_keys_input );
    enkf_tui_util_scanf_report_steps(history_length , prompt_len , &step1 , &step2);

    util_printf_prompt(prompt2 , prompt_len , '=' , "=> ");
    ranking_key = util_alloc_stdin_line();
    if (ranking_key == NULL) 
      ranking_key = util_alloc_string_copy( MISFIT_DEFAULT_RANKING_KEY );
    
    util_printf_prompt(store_prompt , prompt_len , '=' , "=> ");
    ranking_file = util_alloc_stdin_line();
        
    if (stringlist_get_size( ranking_keys ) > 0) {
      ranking_table_add_misfit_ranking( ranking_table , misfit_ensemble , ranking_keys , step1 , step2 , ranking_key );
      ranking_table_display_ranking( ranking_table , ranking_key);
    } else
      fprintf(stderr,"The input string : \"%s\" did not resolve to any valid observation keys \n", obs_keys_input);
    
    free( obs_keys_input );
    stringlist_free( ranking_keys );
    free( ranking_key );
    util_safe_free( ranking_file );
  }
}
Ejemplo n.º 15
0
void create_test_area(const char * test_name , bool store) {
  char * pre_cwd = util_alloc_cwd();
  test_work_area_type * work_area = test_work_area_alloc( test_name , store);
  char * work_path = util_alloc_string_copy( test_work_area_get_cwd( work_area ));
  
  test_assert_true( util_is_directory( work_path ));
  test_work_area_free( work_area );
  test_assert_bool_equal( store , util_entry_exists( work_path ));
  
  {
    char * post_cwd = util_alloc_cwd();
    test_assert_string_equal( pre_cwd , post_cwd );
    free( post_cwd );
  }
  free( pre_cwd );
  free( work_path );
}
Ejemplo n.º 16
0
plot_type * plot_alloc(const char * __driver_type , void * init_arg , bool logx , bool logy)
{
  plot_type * plot = util_malloc(sizeof *plot );
  {
    /*
      Loading the driver:
    */
    char * driver_type = util_alloc_string_copy( __driver_type );
    util_strupr( driver_type );

    if (util_string_equal( driver_type , "PLPLOT"))
      plot->driver  = plplot_driver_alloc(init_arg);
    else if (util_string_equal( driver_type , "TEXT"))
      plot->driver  = text_driver_alloc(init_arg);
    else
      util_abort("%s: plot driver:%s not implemented ... \n",__func__ , __driver_type);
    
    plot_driver_assert( plot->driver );

    free( driver_type );
  }

  /* Initializing plot data which is common to all drivers. */
  plot->is_histogram    = false;
  plot->dataset         = vector_alloc_new();
  plot->dataset_hash    = hash_alloc();
  plot->range           = plot_range_alloc();
  plot->timefmt         = NULL;
  plot->xlabel          = NULL;
  plot->ylabel          = NULL;
  plot->title           = NULL;
  
  /* 
     These functions only manipulate the internal plot_state
     variables, and do not call the driver functions.
  */
  plot_set_window_size(plot , PLOT_DEFAULT_WIDTH , PLOT_DEFAULT_HEIGHT);
  plot_set_box_color(plot , PLOT_DEFAULT_BOX_COLOR);
  plot_set_label_color(plot , PLOT_DEFAULT_LABEL_COLOR);
  plot_set_label_fontsize(plot , 1.0);
  plot_set_axis_fontsize(plot , 1.0);
  plot_set_labels(plot , "" , "" , ""); /* Initializeing with empty labels. */
  plot_set_log( plot , logx , logy); /* Default - no log on the axis. */
  return plot;
}
Ejemplo n.º 17
0
local_ministep_type * local_ministep_alloc(const char * name, analysis_module_type* analysis_module) {
  local_ministep_type * ministep = util_malloc( sizeof * ministep );

  ministep->name         = util_alloc_string_copy( name );

  char* obsdata_name = "OBSDATA_";
  char* result = malloc(strlen(obsdata_name)+strlen(name)+1);
  strcpy(result, obsdata_name);
  strcat(result, name);
  ministep->observations = local_obsdata_alloc(result);


  ministep->datasets     = hash_alloc();
  ministep->analysis_module = analysis_module;
  UTIL_TYPE_ID_INIT( ministep , LOCAL_MINISTEP_TYPE_ID);

  return ministep;
}
Ejemplo n.º 18
0
member_config_type * member_config_alloc(int iens , 
                                         const char                 * casename , 
                                         bool                         pre_clear_runpath , 
                                         keep_runpath_type            keep_runpath , 
                                         const ecl_config_type      * ecl_config , 
                                         const ensemble_config_type * ensemble_config,
                                         enkf_fs_type * fs) {

                                                
  member_config_type * member_config = util_malloc( sizeof * member_config );
  member_config->casename            = util_alloc_string_copy( casename );
  member_config->iens                = iens; /* Can only be changed in the allocater. */
  member_config->eclbase             = NULL;
  member_config->jobname             = NULL;
  member_config->pre_clear_runpath   = pre_clear_runpath;
  member_config_set_keep_runpath(member_config , keep_runpath);
  return member_config;
}
Ejemplo n.º 19
0
static ecl_grav_survey_type * ecl_grav_survey_alloc_empty(const ecl_grav_type * ecl_grav , 
                                                          const char * name , 
                                                          grav_calc_type calc_type) {
  ecl_grav_survey_type * survey = util_malloc( sizeof * survey );
  UTIL_TYPE_ID_INIT( survey , ECL_GRAV_SURVEY_ID );
  survey->grid_cache   = ecl_grav->grid_cache;
  survey->aquifer_cell = ecl_grav->aquifer_cell;
  survey->name         = util_alloc_string_copy( name );
  survey->phase_list   = vector_alloc_new();
  survey->phase_map    = hash_alloc();

  if (calc_type & GRAV_CALC_USE_PORV)
    survey->porv       = util_calloc( ecl_grid_cache_get_size( ecl_grav->grid_cache ) , sizeof * survey->porv );
  else
    survey->porv       = NULL;

  return survey;
}
Ejemplo n.º 20
0
data_ranking_type * data_ranking_alloc( bool sort_increasing , int ens_size , const char * user_key , const char * key_index , enkf_fs_type * fs , const enkf_config_node_type * config_node , int step , state_enum state) {
    data_ranking_type * ranking = util_malloc( sizeof * ranking );
    UTIL_TYPE_ID_INIT( ranking , DATA_RANKING_TYPE_ID );
    ranking->ens_size = ens_size;
    ranking->sort_increasing = sort_increasing;

    if (ranking->sort_increasing)
        ranking->data_ensemble = double_vector_alloc( ens_size ,  INFINITY);  // To ensure it comes last when sorting
    else
        ranking->data_ensemble = double_vector_alloc( ens_size , -INFINITY);  // To ensure it comes last when sorting

    ranking->valid = bool_vector_alloc( ens_size , false );
    ranking->sort_permutation = NULL;
    ranking->user_key = util_alloc_string_copy( user_key );

    data_ranking_init( ranking , fs , config_node , key_index , step , state );
    return ranking;
}
Ejemplo n.º 21
0
static void enkf_tui_ranking_display( void * arg ) {
  enkf_main_type    * enkf_main       = enkf_main_safe_cast( arg );  
  ranking_table_type * ranking_table  = enkf_main_get_ranking_table( enkf_main );

  const int prompt_len  = 50;
  const char * prompt1  = "Ranking to display";
  char * ranking_key;
  
  util_printf_prompt(prompt1 , prompt_len , '=' , "=> ");
  ranking_key    = util_alloc_stdin_line();
  if (ranking_key == NULL) 
    ranking_key = util_alloc_string_copy( MISFIT_DEFAULT_RANKING_KEY);
  if (ranking_table_has_ranking( ranking_table , ranking_key))
    ranking_table_display_ranking( ranking_table , ranking_key);
  else
    fprintf(stderr,"Sorry: could not find ranking key: %s \n", ranking_key );
  
  free( ranking_key );
}
Ejemplo n.º 22
0
char * util_alloc_PATH_executable(const char * executable) {
  if (util_is_abs_path(executable)) {
    if (util_is_executable(executable))
      return util_alloc_string_copy(executable);
    else
      return NULL;
  } else if (strncmp(executable , "./" , 2) == 0) {
    char * cwd = util_alloc_cwd();
    char * path = util_alloc_filename(cwd , &executable[2] , NULL);

    /* The program has been invoked as ./xxxx */
    if (!(util_is_file(path) && util_is_executable( path ))) {
      free( path );
      path = NULL;
    }
    free( cwd );

    return path;
  } else {
    char * full_path  = NULL;
    char ** path_list = util_alloc_PATH_list();
    int ipath = 0;

    while (true) {
      if (path_list[ipath] != NULL)  {
        char * current_attempt = util_alloc_filename(path_list[ipath] , executable , NULL);
      
        if ( util_is_file( current_attempt ) && util_is_executable( current_attempt )) {
          full_path = current_attempt;
          break;
        } else {
          free(current_attempt);
          ipath++;
        }
      } else
        break;
    }
    
    util_free_NULL_terminated_stringlist(path_list);
    return full_path;
  }
}
Ejemplo n.º 23
0
/**
   input_value can be NULL. 
*/
static void subst_list_string_set_value(subst_list_string_type * node, const char * input_value , const char * doc_string , subst_insert_type insert_mode) {
  subst_list_string_free_content( node );
  {
    char * value;
    if (insert_mode == SUBST_DEEP_COPY)
      value = util_alloc_string_copy(input_value);
    else
      value = (char *) input_value;
    
    if (insert_mode == SUBST_SHARED_REF)
      node->value_owner = false;
    else
      node->value_owner = true;
    
    node->value = value;
  }
  
  if (doc_string != NULL)
    node->doc_string = util_realloc_string_copy( node->doc_string , doc_string );
}
Ejemplo n.º 24
0
hash_type * hash_alloc_from_options(const stringlist_type * options) {
  int num_options = stringlist_get_size( options );
  hash_type * opt_hash = hash_alloc();
  int iopt;

  for (iopt = 0; iopt < num_options; iopt++) {
    char * option;
    char * value;

    util_binary_split_string( stringlist_iget(options , iopt) , ":" , true , &option , &value);
    if ((option != NULL) && (value != NULL))
      hash_insert_hash_owned_ref( opt_hash , option , util_alloc_string_copy(value) , free);
    // Warning: could not interpret string as KEY:VALUE - ignored


    util_safe_free(option);
    util_safe_free(value);
  }

  return opt_hash;
}
Ejemplo n.º 25
0
static int ecl_util_get_month_nr__(const char * _month_name) {
  int month_nr = -1;
  char * month_name = util_alloc_string_copy(_month_name);
  util_strupr(month_name);
  
  if (strncmp(month_name , "JAN" , 3)      == 0) 
    month_nr = 1;
  else if (strncmp(month_name , "FEB" , 3) == 0) 
    month_nr = 2;
  else if (strncmp(month_name , "MAR" , 3) == 0) 
    month_nr = 3;
  else if (strncmp(month_name , "APR" , 3) == 0) 
    month_nr = 4;
  else if (strncmp(month_name , "MAI" , 3) == 0) 
    month_nr = 5;
  else if (strncmp(month_name , "MAY" , 3) == 0) 
    month_nr = 5;
  else if (strncmp(month_name , "JUN" , 3) == 0) 
    month_nr = 6;
  else if (strncmp(month_name , "JUL" , 3) == 0) 
    month_nr = 7;
  else if (strncmp(month_name , "JLY" , 3) == 0)   /* ECLIPSE ambigus on July. */
    month_nr = 7;
  else if (strncmp(month_name , "AUG" , 3) == 0) 
    month_nr = 8;
  else if (strncmp(month_name , "SEP" , 3) == 0) 
    month_nr = 9;
  else if (strncmp(month_name , "OCT" , 3) == 0) 
    month_nr = 10;
  else if (strncmp(month_name , "OKT" , 3) == 0) 
    month_nr = 10;
  else if (strncmp(month_name , "NOV" , 3) == 0) 
    month_nr = 11;
  else if (strncmp(month_name , "DEC" , 3) == 0) 
    month_nr = 12;
  else if (strncmp(month_name , "DES" , 3) == 0) 
    month_nr = 12;
  free(month_name);
  return month_nr;
}
Ejemplo n.º 26
0
/**
   The input vectors i,j,k should contain offset zero values.
*/
block_obs_type * block_obs_alloc(const char   * obs_key,
                                 block_obs_source_type source_type , 
                                 const stringlist_type * summary_keys , 
                                 const void * data_config , 
                                 const ecl_grid_type * grid ,
                                 int            size,
                                 const int    * i,
                                 const int    * j,
                                 const int    * k,
                                 const double * obs_value,
                                 const double * obs_std)
{
  block_obs_validate_ijk( grid , size , i,j,k);
  
  {
    block_obs_type * block_obs = util_malloc(sizeof * block_obs);
    char           * sum_kw    = NULL;

    UTIL_TYPE_ID_INIT( block_obs , BLOCK_OBS_TYPE_ID );
    block_obs->obs_key         = util_alloc_string_copy(obs_key);
    block_obs->data_config     = data_config;
    block_obs->source_type     = source_type; 
    block_obs->size            = 0;
    block_obs->point_list      = NULL;
    block_obs->grid            = grid;
    block_obs_resize( block_obs , size );
    
    {
      for (int l=0; l < size; l++) {
        int active_index = ecl_grid_get_active_index3( block_obs->grid , i[l],j[l],k[l]);
        char * sum_key   = NULL;
        if (source_type == SOURCE_SUMMARY) 
          sum_key = stringlist_iget( summary_keys , l );
        
        block_obs->point_list[l] = point_obs_alloc(source_type , i[l] , j[l] , k[l] , active_index , sum_key , obs_value[l] , obs_std[l]);
      }
    }
    return block_obs;
  }
}
Ejemplo n.º 27
0
hash_type * config_content_item_alloc_hash(const config_content_item_type * item , bool copy) {
  hash_type * hash = hash_alloc();
  if (item != NULL) {
    int inode;
    for (inode = 0; inode < vector_get_size( item->nodes ); inode++) {
      const config_content_node_type * node = config_content_item_iget_node(item , inode);
      const stringlist_type * src_list = config_content_node_get_stringlist( node );
      const char * key = stringlist_iget(src_list , 0);
      const char * value = stringlist_iget(src_list , 1);
      
      if (copy) {
        hash_insert_hash_owned_ref(hash , 
                                   key ,
                                   util_alloc_string_copy(value) , 
                                   free);
      } else
        hash_insert_ref(hash , key , value );
      
    }
  }
  return hash;
}
Ejemplo n.º 28
0
static char * util_bt_alloc_current_executable(const char * bt_symbol) {
  if (__current_executable != NULL) 
    return util_alloc_string_copy(__current_executable );
  else {
    if (bt_symbol != NULL) {
      int paren_pos = 0;
      char * path;
      while (bt_symbol[paren_pos] != '(' && bt_symbol[paren_pos] != ' ')
        paren_pos++;
      
      path = util_alloc_substring_copy(bt_symbol , 0 , paren_pos);
      if (util_is_abs_path(path))
        return path;
      else {
        char * full_path = util_alloc_PATH_executable( path );
        free(path);
        return full_path;
      }
    } else 
      return NULL;
  }
}
Ejemplo n.º 29
0
well_state_type * well_state_alloc(const char * well_name , int global_well_nr , bool open, well_type_enum type , int report_nr, time_t valid_from) {
  well_state_type * well_state = util_malloc( sizeof * well_state );
  UTIL_TYPE_ID_INIT( well_state , WELL_STATE_TYPE_ID );
  well_state->index_wellhead = vector_alloc_new();
  well_state->name_wellhead  = hash_alloc();

  well_state->name = util_alloc_string_copy( well_name );
  well_state->valid_from_time = valid_from;
  well_state->valid_from_report = report_nr;
  well_state->open = open;
  well_state->type = type;
  well_state->global_well_nr = global_well_nr;
  well_state->connections = hash_alloc();
  well_state->segments = well_segment_collection_alloc();
  well_state->branches = well_branch_collection_alloc();
  well_state->is_MSW_well = false;

  /* See documentation of the 'IWEL_UNDOCUMENTED_ZERO' in well_const.h */
  if ((type == UNDOCUMENTED_ZERO) && open)
    util_abort("%s: Invalid type value for open wells.\n",__func__ );
  return well_state;
}
Ejemplo n.º 30
0
static output_type * output_alloc( const char * file , const char * format_string) {
  output_type * output = util_malloc( sizeof * output );
  output->keys = vector_alloc_new();
  output->file = util_alloc_string_copy( file );
  {
    format_type  format;

    if ( util_string_equal(format_string , S3GRAPH_STRING))
      format = S3GRAPH;
    else if ( util_string_equal( format_string , HEADER_STRING))
      format = HEADER;
    else if ( util_string_equal( format_string , PLAIN_STRING) )
      format = PLAIN;
    else {
      format = PLAIN;  /* Compiler shut up. */
      util_abort("%s: unrecognized format string:%s \n",__func__ , format_string);
    }
    output->format = format;
  }

  return output;
}