Beispiel #1
0
static errno_t
ipa_sudo_conv_store(hash_table_t *table,
                    const char *key,
                    void *value)
{
    hash_key_t hkey;
    hash_value_t hvalue;
    int hret;

    if (table == NULL || key == NULL) {
        return EINVAL;
    }

    hkey.type = HASH_KEY_STRING;
    hkey.str = discard_const(key);

    /* If value is NULL we don't want to override existing entry. */
    if (value == NULL && hash_has_key(table, &hkey)) {
        return EEXIST;
    }

    hvalue.type = HASH_VALUE_PTR;
    hvalue.ptr = value;

    hret = hash_enter(table, &hkey, &hvalue);
    if (hret != HASH_SUCCESS) {
        return EIO;
    }

    if (value != NULL) {
        talloc_steal(table, value);
    }

    return EOK;
}
ecl_rft_file_type * ecl_rft_file_alloc(const char * filename) {
  ecl_rft_file_type * rft_vector = ecl_rft_file_alloc_empty( filename );
  ecl_file_type * ecl_file       = ecl_file_open( filename , 0);
  int global_index = 0;
  int block_nr = 0;

  while (true) {
    if (ecl_file_select_block( ecl_file , TIME_KW , block_nr)) {
      ecl_rft_node_type * rft_node = ecl_rft_node_alloc( ecl_file );
      if (rft_node != NULL) {
        const char * well_name = ecl_rft_node_get_well_name( rft_node );
        ecl_rft_file_add_node(rft_vector , rft_node);
        if (!hash_has_key( rft_vector->well_index , well_name))
          hash_insert_hash_owned_ref( rft_vector->well_index , well_name , int_vector_alloc( 0 , 0 ) , int_vector_free__);
        {
          int_vector_type * index_list = hash_get( rft_vector->well_index , well_name );
          int_vector_append(index_list , global_index);
        }
        global_index++;
      }
    } else
      break;
    block_nr++;
  }
  ecl_file_close( ecl_file );
  return rft_vector;
}
Beispiel #3
0
void set_remove_key(set_type * set, const char * key) {
  if (!hash_has_key(set->key_hash , key)) {
    fprintf(stderr, "%s: set does not have key: %s - aborting \n",__func__ , key);
    abort();
  }
  hash_del(set->key_hash  , key);
}
Beispiel #4
0
static int file_map_get_num_named_kw(const file_map_type * file_map , const char * kw) {
  if (hash_has_key(file_map->kw_index , kw)) {
    const int_vector_type * index_vector = hash_get(file_map->kw_index , kw);
    return int_vector_size( index_vector );
  } else
    return 0;
}
Beispiel #5
0
plot_dataset_type * plot_alloc_new_dataset(plot_type * plot , const char * __label , plot_data_type data_type) {
  if (data_type == PLOT_HIST) {
    if (vector_get_size( plot->dataset) > 0)
      util_abort("%s: sorry - when using histograms you can *only* have one dataset\n",__func__);
    plot->is_histogram = true;
  } else if (plot->is_histogram)
    util_abort("%s: sorry - when using histograms you can *only* have one dataset\n",__func__);
  
  {
    char * label;
    if (__label == NULL)
      label = util_alloc_sprintf("data_%d" , vector_get_size( plot->dataset ));
    else
      label = (char *) __label;
    
    if (hash_has_key( plot->dataset_hash , label))
      util_abort("%s: sorry - the label %s is already in use - must be unique \n",__func__ , label);
    {
      plot_dataset_type * dataset = plot_dataset_alloc(data_type, label , plot->logx , plot->logy);
      vector_append_owned_ref(plot->dataset , dataset , plot_dataset_free__);
      hash_insert_ref( plot->dataset_hash , label , dataset);
      if (__label == NULL)
        free(label);
      return dataset;
    }
  }
}  
Beispiel #6
0
enkf_config_node_type * ensemble_config_get_or_create_summary_node(ensemble_config_type * ensemble_config, const char * key) {
    if (!hash_has_key(ensemble_config->config_nodes , key)) {
        ensemble_config_add_summary(ensemble_config, key, LOAD_FAIL_SILENT);
    }

    return ensemble_config_get_node(ensemble_config, key);
}
Beispiel #7
0
double sched_file_well_wconinje_rate( const sched_file_type * sched_file , 
                                      int restart_nr , 
                                      const char * well_name) {
  double rate = -1;
  bool well_found = 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 , "WCONINJE")) {
      const vector_type * wconhist_vector = hash_get( block->kw_hash , "WCONINJE");
      int i;
      for (i=0; i < vector_get_size( wconhist_vector ); i++) {
        sched_kw_type * kw = vector_iget( wconhist_vector , i );
        if (sched_kw_has_well( kw , well_name )) {
          well_found = true;
          rate = sched_kw_wconinje_get_surface_flow( sched_kw_get_data( kw ) , well_name );
        }
      }
    }
    
    block_nr--;
  } 
  return rate;
}
Beispiel #8
0
bool set_add_key(set_type * set, const char * key) {
  if (hash_has_key(set->key_hash , key))
    return false;
  else {
    hash_insert_int(set->key_hash , key , 1);
    return true;
  }
}
Beispiel #9
0
workflow_type *  ert_workflow_list_get_workflow(ert_workflow_list_type * workflow_list , const char * workflow_name ) {
  const char * lookup_name = workflow_name;

  if (hash_has_key( workflow_list->alias_map , workflow_name))
    lookup_name = hash_get( workflow_list->alias_map , workflow_name );

  return hash_get( workflow_list->workflows , lookup_name );
}
Beispiel #10
0
ext_job_type * ext_joblist_get_job_copy(const ext_joblist_type * joblist , const char * job_name) {
  if (hash_has_key(joblist->jobs , job_name))
    return ext_job_alloc_copy(hash_get(joblist->jobs , job_name));
  else {
    util_abort("%s: asked for job:%s which does not exist\n",__func__ , job_name);
    return NULL;
  }
}
Beispiel #11
0
bool summary_key_matcher_summary_key_is_required(const summary_key_matcher_type * matcher, const char * summary_key) {
    bool is_required = false;

    if(!util_string_has_wildcard(summary_key) && hash_has_key(matcher->key_set, summary_key)) {
        is_required = (bool) hash_get_int(matcher->key_set, summary_key);
    }

    return is_required;
}
Beispiel #12
0
int hash_inc_counter(hash_type * hash , const char * counter_key) {
  if (hash_has_key( hash , counter_key)) {
    node_data_type * node_data = hash_get_node_data(hash , counter_key);
    return node_data_fetch_and_inc_int( node_data );
  } else {
    hash_insert_int(hash , counter_key , 0);
    return 0;
  }
}
Beispiel #13
0
enkf_config_node_type * ensemble_config_get_node(const ensemble_config_type * ensemble_config, const char * key) {
  if (hash_has_key(ensemble_config->config_nodes , key)) {
    enkf_config_node_type * node = hash_get(ensemble_config->config_nodes , key);
    return node;
  } else {
    util_abort("%s: ens node:\"%s\" does not exist \n",__func__ , key);
    return NULL; /* compiler shut up */
  }
}
Beispiel #14
0
static void sched_history_add_groups_gruptree( sched_history_type * sched_history , const sched_kw_gruptree_type * gruptree , int report_step , const stringlist_type * child_groups , const stringlist_type * parent_groups) {
  for (int i = 0; i < stringlist_get_size( child_groups ); i++) {
    const char * parent_group_name  = stringlist_iget( parent_groups , i );
    const char * child_group_name   = stringlist_iget( child_groups , i );
    group_history_type * parent_group;
    group_history_type * child_group;


    if (!hash_has_key( sched_history->group_history , parent_group_name )) 
      sched_history_add_group( sched_history , group_history_alloc( parent_group_name , sched_history->time , report_step) , NULL , report_step );
    parent_group = sched_history_get_group( sched_history , parent_group_name );

    if (!hash_has_key( sched_history->group_history , child_group_name )) 
      sched_history_add_group( sched_history , group_history_alloc( child_group_name , sched_history->time , report_step ) , parent_group , report_step );
    child_group = sched_history_get_group( sched_history , child_group_name );

    group_history_add_child( parent_group , child_group , child_group_name , report_step);
  }
}
Beispiel #15
0
bool summary_key_set_has_summary_key(summary_key_set_type * set, const char * summary_key) {
    bool has_key = false;

    pthread_rwlock_rdlock( &set->rw_lock );
    {
        has_key = hash_has_key(set->key_set, summary_key);
    }
    pthread_rwlock_unlock( &set->rw_lock );

    return has_key;
}
Beispiel #16
0
static void sched_block_add_kw(sched_block_type * block, const sched_kw_type * kw)
{
  vector_append_ref(block->kw_list , kw );
  if (!hash_has_key( block->kw_hash , sched_kw_get_name( kw ))) 
    hash_insert_hash_owned_ref( block->kw_hash , sched_kw_get_name( kw ) , vector_alloc_new() , vector_free__);
  
  {
    vector_type * kw_vector = hash_get( block->kw_hash , sched_kw_get_name( kw ));
    vector_append_ref( kw_vector , kw );
  }
}
Beispiel #17
0
enkf_var_type ensemble_config_var_type(const ensemble_config_type *ensemble_config, const char * ecl_kw_name) {
  enkf_var_type var_type = INVALID_VAR;

  if (hash_has_key(ensemble_config->config_nodes , ecl_kw_name)) {
    enkf_config_node_type * node = hash_get(ensemble_config->config_nodes , ecl_kw_name);
    var_type = enkf_config_node_get_var_type(node);
  } else
    util_abort("%s: internal error: asked for implementation type of unknown node:%s \n",__func__ , ecl_kw_name);

  return var_type;
}
Beispiel #18
0
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;
}
Beispiel #19
0
void site_config_setenv( site_config_type * site_config , const char * variable, const char * __value) {
  const char * value = util_interp_setenv( variable , __value );

  if (site_config->user_mode) {
    /* In the table meant for user-export we store the literal $var strings. */
    hash_insert_hash_owned_ref( site_config->env_variables_user , variable , util_alloc_string_copy( __value ) , free);
    
    if (!hash_has_key( site_config->env_variables_site , variable))
      hash_insert_ref( site_config->env_variables_site , variable , NULL);   /* We insert a NULL so we can recover a unsetenv() in _clear_env(). */
  } else
    hash_insert_hash_owned_ref( site_config->env_variables_site , variable , util_alloc_string_copy( value ) , free);
}
Beispiel #20
0
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 );
}
Beispiel #21
0
static void sched_history_add_groups_welspecs( sched_history_type * sched_history , const sched_kw_welspecs_type * welspecs , int report_step , const stringlist_type * wells, const stringlist_type * groups) {
  for (int i = 0; i < stringlist_get_size( groups ); i++) {
    const char * group_name  = stringlist_iget( groups , i );
    const char * well_name   = stringlist_iget( wells , i );
    well_history_type * well = sched_history_get_well( sched_history , well_name );
    group_history_type * group;
    if (!hash_has_key( sched_history->group_history , group_name )) 
      sched_history_add_group( sched_history , group_history_alloc( group_name , sched_history->time , report_step ) , NULL , report_step );
    
    group = sched_history_get_group( sched_history , group_name );
    group_history_add_child( group , well , well_name , report_step);
  }
}
Beispiel #22
0
bool rms_tag_name_eq(const rms_tag_type *tag , const char * tagname , const char *tagkey_name , const char *keyvalue) {
    bool eq = false;
    if (strcmp(tag->name , tagname) == 0) {
        if (tagkey_name != NULL && keyvalue != NULL) {
            if (hash_has_key(tag->key_hash , tagkey_name)) {
                const rms_tagkey_type *tagkey = hash_get(tag->key_hash , tagkey_name);
                eq = rms_tagkey_char_eq(tagkey , keyvalue);
            }
        } else
            eq = true;
    }
    return eq;
}
Beispiel #23
0
static void sched_history_add_wells( sched_history_type * sched_history , const sched_kw_welspecs_type * welspecs , const stringlist_type * wells) {
  for (int iw = 0; iw < stringlist_get_size( wells ); iw++) {
    const char * well = stringlist_iget( wells , iw );
    if (!hash_has_key( sched_history->well_history , well)) 
      hash_insert_hash_owned_ref( sched_history->well_history , well , well_history_alloc( well , sched_history->time ), well_history_free__ );
    
    /* Could possibly extract more information from the welspecs
       keyword and update well_history object here, but it does not
       seem to contain any more interesting info???
    */
    
  }
}
Beispiel #24
0
bool model_config_select_runpath( model_config_type * model_config , const char * path_key) {
  if (hash_has_key( model_config->runpath_map , path_key )) {
    model_config->current_runpath = hash_get( model_config->runpath_map , path_key );
    model_config->current_path_key = util_realloc_string_copy( model_config->current_path_key , path_key);
    return true;
  } else {
    if (model_config->current_runpath != NULL)  // OK - we already have a valid selection - stick to that and return False.
      return false;
    else {
      util_abort("%s: path_key:%s does not exist - and currently no valid runpath selected \n",__func__ , path_key);
      return false;
    }
  }
}
Beispiel #25
0
/**
  Get the next key.

  Returns NULL if the iteration has ended.
*/
const char * hash_iter_get_next_key(hash_iter_type * iter) {
  const char * key;

  if(iter->current_key_num == iter->num_keys)
    return NULL;

  key = iter->keylist[iter->current_key_num];
  iter->current_key_num++;

  if(!hash_has_key(iter->hash, key))
    util_abort("%s: Programming error. Using hash_iter with multi-threading??\n", __func__);

  return key;
}
Beispiel #26
0
bool ranking_table_display_ranking( const ranking_table_type * ranking_table , const char * ranking_key ) {
  if (hash_has_key( ranking_table->ranking_table , ranking_key)) {
    void * ranking = hash_get( ranking_table->ranking_table , ranking_key );
    
    if (data_ranking_is_instance( ranking )) {
      data_ranking_type * data_ranking = data_ranking_safe_cast( ranking );
      data_ranking_display( data_ranking , stdout );
    } else if (misfit_ranking_is_instance( ranking )) {
      misfit_ranking_type * misfit_ranking = misfit_ranking_safe_cast( ranking );
      misfit_ranking_display( misfit_ranking , stdout );
    } else
      util_abort("%s: internal error \n",__func__);
    

    return true;
  } else
    return false;
}
Beispiel #27
0
const perm_vector_type * ranking_table_get_permutation( const ranking_table_type * ranking_table , const char * ranking_key) {
  if (hash_has_key( ranking_table->ranking_table , ranking_key)) {
    void * ranking = hash_get( ranking_table->ranking_table , ranking_key );
    
    if (data_ranking_is_instance( ranking )) {
      data_ranking_type * data_ranking = data_ranking_safe_cast( ranking );
      return data_ranking_get_permutation( data_ranking );
    } else if (misfit_ranking_is_instance( ranking )) {
      misfit_ranking_type * misfit_ranking = misfit_ranking_safe_cast( ranking );
      return misfit_ranking_get_permutation( misfit_ranking );
    } else {
      util_abort("%s: internal error \n");
      return NULL;
    }

  } else
    return NULL;
}
Beispiel #28
0
bool sched_history_open( const sched_history_type * sched_history , const char * key , int report_step) {
    if(hash_has_key(sched_history->index, key)) {
      const void * index = hash_get(sched_history->index , key );
      if (well_index_is_instance( index )) {
        const well_index_type * well_index = well_index_safe_cast_const( index );
        const char * well_name = well_index_get_name( well_index );
        return sched_history_well_open( sched_history , well_name , report_step);
      } else if (group_index_is_instance( index )) {
        const group_index_type * group_index = group_index_safe_cast_const( index );
        const char * group_name = group_index_get_name( group_index );
        return sched_history_group_exists( sched_history , group_name , report_step);
      } else {
        util_abort("%s: - hmm internal fuckup \n",__func__);
        return false;
      }
    }
   return false;
}
static ecl_grav_survey_type * ecl_grav_get_survey( const ecl_grav_type * grav , const char * name) {
  if (name == NULL)
    return NULL;  // Calling scope must determine if this is OK?
  else {
    if (hash_has_key( grav->surveys , name))
      return hash_get( grav->surveys , name );
    else {
      hash_iter_type * survey_iter = hash_iter_alloc( grav->surveys );
      fprintf(stderr,"Survey name:%s not registered. Available surveys are: \n\n     " , name);
      while (!hash_iter_is_complete( survey_iter )) {
        const char * survey = hash_iter_get_next_key( survey_iter );
        fprintf(stderr,"%s ",survey);
      }
      fprintf(stderr,"\n\n");
      hash_iter_free( survey_iter );
      exit(1);
    }
  }
}
Beispiel #30
0
static bool custom_kw_config_read_data__(const custom_kw_config_type * config, const char * result_file, stringlist_type * result) {
    FILE * stream = util_fopen__(result_file, "r");
    if (stream != NULL) {
        bool read_ok = true;

        stringlist_clear(result);
        stringlist_iset_ref(result, hash_get_size(config->custom_keys) - 1, NULL);
        hash_type * read_keys = hash_alloc();

        char key[128];
        char value[128];
        int read_count;
        while ((read_count = fscanf(stream, "%s %s", key, value)) != EOF) {
            if (read_count == 1) {
                fprintf(stderr ,"[%s] Warning: Key: '%s:%s' missing value in file: %s!\n", __func__, config->name, key, result_file);
                read_ok = false;
                break;
            }

            if (custom_kw_config_has_key(config, key)) {
                if (hash_has_key(read_keys, key)) {
                    fprintf(stderr ,"[%s] Warning:  Key: '%s:%s' has appeared multiple times. Only the last occurrence will be used!\n", __func__, config->name, key);
                }

                hash_insert_int(read_keys, key, 1);
                int index = custom_kw_config_index_of_key(config, key);
                stringlist_iset_copy(result, index, value);

            } else {
                fprintf(stderr ,"[%s] Warning: Key: '%s:%s' not in the available set. Ignored!\n", __func__, config->name, key);
            }
        }

        fclose(stream);

        if (read_ok) {
            read_ok = hash_key_list_compare(read_keys, config->custom_keys);
        }

        return read_ok;
    }
    return false;
}