예제 #1
0
static void output_add_key( const ecl_sum_type * refcase , output_type * output , const char * qkey) {
  int tokens;
  double  quantile;
  char ** tmp;
  char  * sum_key;

  util_split_string( qkey , SUMMARY_JOIN , &tokens , &tmp);
  if (tokens == 1)
    util_exit("Hmmm - the key:%s is malformed - must be of the form SUMMARY_KEY:QUANTILE.\n",qkey);

  if (!util_sscanf_double( tmp[tokens - 1] , &quantile))
    util_exit("Hmmmm - failed to interpret:%s as a quantile - must be a number (0,1).\n",tmp[tokens-1]);

  if (quantile <= 0 || quantile >= 1.0)
    util_exit("Invalid quantile value:%g - must be in interval (0,1)\n", quantile);

  sum_key = util_alloc_joined_string( (const char **) tmp , tokens - 1 , SUMMARY_JOIN);
  {
    stringlist_type * matching_keys = stringlist_alloc_new();
    int i;
    ecl_sum_select_matching_general_var_list( refcase , sum_key , matching_keys );
    for (i=0; i < stringlist_get_size( matching_keys ); i++)
      vector_append_owned_ref( output->keys , quant_key_alloc( stringlist_iget( matching_keys , i ) , quantile) , quant_key_free__ );

    if (stringlist_get_size( matching_keys ) == 0)
      fprintf(stderr,"** Warning: No summary vectors matching:\'%s\' found?? \n", sum_key);
    stringlist_free( matching_keys );
  }

  util_free_stringlist( tmp, tokens );
}
예제 #2
0
static void ecl_grid_dims_read_GRID( ecl_grid_dims_type * grid_dims , fortio_type * grid_fortio , fortio_type * data_fortio ) {
  while (ecl_kw_fseek_kw( DIMENS_KW , false , false , grid_fortio)) {
    grid_dims_type * dims;
    {
      ecl_kw_type * dimens_kw = ecl_kw_fread_alloc( grid_fortio );
    
      int nx = ecl_kw_iget_int( dimens_kw , DIMENS_NX_INDEX );
      int ny = ecl_kw_iget_int( dimens_kw , DIMENS_NY_INDEX );
      int nz = ecl_kw_iget_int( dimens_kw , DIMENS_NZ_INDEX );
      
      dims = grid_dims_alloc( nx , ny , nz , 0 );
      ecl_kw_free( dimens_kw );
    }

    if (data_fortio) {
      if (ecl_kw_fseek_kw( INTEHEAD_KW , false , false , data_fortio )) {
        ecl_kw_type * intehead_kw = ecl_kw_fread_alloc( data_fortio );
        dims->nactive = ecl_kw_iget_int( intehead_kw , INTEHEAD_NACTIVE_INDEX );
        ecl_kw_free( intehead_kw );
      }
    }
    
    vector_append_owned_ref( grid_dims->dims_list , dims, grid_dims_free__ );
  } 
}
vector_type * load_expected( const ecl_grid_type * grid, const char * filename ) {
  FILE * stream = util_fopen( filename , "r");
  vector_type * expected = vector_alloc_new();

  while (true) {
    double x,y,z;
    int i,j,k,skip;

    if (fscanf( stream , "%lg %lg %lg %d %d %d %d" , &x,&y,&z,&i,&j,&k,&skip) == 7) {
      point_type * p = util_malloc( sizeof * p );
      p->x = x;
      p->y = y;
      p->z = z;

      p->i = i-1;
      p->j = j-1;
      p->k = k-1;
      p->skip = skip;
      p->g = ecl_grid_get_global_index3(grid,    p->i, p->j, p->k);
      vector_append_owned_ref( expected, p , free );
    } else
      break;
  }

  fclose( stream );
  test_assert_int_equal( 10 , vector_get_size( expected ));
  return expected;
}
예제 #4
0
config_path_elm_type * config_content_add_path_elm( config_content_type * content , const char * path ) {
  const config_path_elm_type * current_path_elm;

  if (vector_get_size( content->path_elm_stack ) == 0)
    current_path_elm = NULL;
  else
    current_path_elm = vector_get_last_const(content->path_elm_stack);

  {
    config_path_elm_type * new_path_elm;

    {
      char * rel_path = NULL;
      config_root_path_type * invoke_path = config_content_get_invoke_path( content );
      if (path != NULL) {
        if (current_path_elm == NULL)
          rel_path = util_alloc_rel_path( config_root_path_get_abs_path(invoke_path) , path);
        else
          rel_path = config_path_elm_alloc_relpath( current_path_elm , path );
      }
      new_path_elm = config_path_elm_alloc( invoke_path , rel_path );
      util_safe_free( rel_path );
    }
    vector_append_owned_ref( content->path_elm_storage , new_path_elm , config_path_elm_free__);
    vector_append_ref( content->path_elm_stack , new_path_elm );
    return new_path_elm;
  }
}
예제 #5
0
파일: plot.c 프로젝트: akva2/ResInsight
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;
    }
  }
}  
예제 #6
0
파일: group_rate.c 프로젝트: Ensembles/ert
void group_rate_add_well_rate( group_rate_type * group_rate , well_rate_type * well_rate) {
  if (well_rate_get_phase( well_rate ) == group_rate->phase) {
    char * key = util_alloc_sprintf("%s:%s" , well_rate_get_name( well_rate ) , sched_phase_type_string( group_rate->phase ));
    vector_append_owned_ref( group_rate->well_rates , well_rate , well_rate_free__ );
    free( key );
  }
}
예제 #7
0
void subst_list_insert_func(subst_list_type * subst_list , const char * func_name , const char * local_func_name) {
  
  if (subst_list->func_pool != NULL && subst_func_pool_has_func( subst_list->func_pool , func_name )) {
    subst_list_func_type * subst_func = subst_list_func_alloc( local_func_name , subst_func_pool_get_func( subst_list->func_pool , func_name ));
    vector_append_owned_ref( subst_list->func_data , subst_func , subst_list_func_free__ );
  } else
    util_abort("%s: function:%s not available \n",__func__ , func_name);
}
예제 #8
0
static subst_list_string_type * subst_list_insert_new_node(subst_list_type * subst_list , const char * key , bool append) {
  subst_list_string_type * new_node = subst_list_string_alloc(key);
  if (append)
    vector_append_owned_ref( subst_list->string_data , new_node , subst_list_string_free__ );
  else
    vector_insert_owned_ref( subst_list->string_data , 0 , new_node , subst_list_string_free__ );
  return new_node;
}
예제 #9
0
void runpath_list_add( runpath_list_type * list , int iens , int iter, const char * runpath , const char * basename) {
  runpath_node_type * node = runpath_node_alloc( iens , iter, runpath , basename );

  pthread_rwlock_wrlock( &list->lock );
  {
    vector_append_owned_ref( list->list , node , runpath_node_free__ );
  }
  pthread_rwlock_unlock( &list->lock );
}
예제 #10
0
파일: rms_tag.c 프로젝트: bramirex/ert
void rms_tag_add_tagkey(rms_tag_type *tag , const rms_tagkey_type *tagkey, int mem_mode) {
    rms_tagkey_type * tagkey_copy;

    switch (mem_mode) {
    case(COPY):
        tagkey_copy = rms_tagkey_copyc(tagkey);
        vector_append_owned_ref( tag->key_list , tagkey_copy , rms_tagkey_free_ );
        hash_insert_ref(tag->key_hash , rms_tagkey_get_name(tagkey_copy) , tagkey_copy);
        break;
    case(OWNED_REF):
        vector_append_owned_ref( tag->key_list , tagkey , rms_tagkey_free_ );
        hash_insert_ref(tag->key_hash , rms_tagkey_get_name(tagkey) , tagkey);
        break;
    case(SHARED):
        vector_append_ref( tag->key_list , tagkey );
        hash_insert_ref(tag->key_hash , rms_tagkey_get_name(tagkey) , tagkey);
        break;
    }
}
예제 #11
0
bool local_obsdata_add_node( local_obsdata_type * data , local_obsdata_node_type * node ) {
  const char * key = local_obsdata_node_get_key( node );
  if (local_obsdata_has_node(data , key))
    return false; 
  else {
    vector_append_owned_ref( data->nodes_list , node , local_obsdata_node_free__ );
    hash_insert_ref( data->nodes_map , key , node );
    return true;
  }
}
예제 #12
0
void well_segment_collection_add( well_segment_collection_type * segment_collection , well_segment_type * segment) {
  int segment_id = well_segment_get_id( segment );
  int current_index = int_vector_safe_iget( segment_collection->segment_index_map , segment_id );
  if (current_index >= 0)
    vector_iset_owned_ref( segment_collection->__segment_storage , current_index , segment , well_segment_free__);
  else {
    int new_index = vector_get_size(segment_collection->__segment_storage);
    vector_append_owned_ref( segment_collection->__segment_storage , segment , well_segment_free__);
    int_vector_iset( segment_collection->segment_index_map , segment_id , new_index);
  }
}
예제 #13
0
fault_block_type * fault_block_layer_add_block( fault_block_layer_type * layer , int block_id) {
  if (int_vector_safe_iget( layer->block_map , block_id) < 0) {
    fault_block_type * block = fault_block_alloc( layer , block_id );
    int storage_index = vector_get_size( layer->blocks );

    int_vector_iset( layer->block_map , block_id , storage_index );
    vector_append_owned_ref( layer->blocks , block , fault_block_free__ );

    return block;
  } else
    return NULL;
}
예제 #14
0
/**
   This funcion is a feeble attempt at allowing the ensemble size to
   change runtime. If the new ensemble size is larger than the current
   ensemble size ALL the currently internalized misfit information is
   dropped on the floor; if the the ensemble is shrinked only the the
   last elements of the misfit table are discarded (NOT exactly battle-tested).

*/
void misfit_ensemble_set_ens_size( misfit_ensemble_type * misfit_ensemble , int ens_size) {
  int iens;
  if (ens_size > vector_get_size( misfit_ensemble->ensemble )) {
    /* The new ensemble is larger than what we have currently internalized, 
       we drop everything and add empty misfit_member instances. */
    vector_clear( misfit_ensemble->ensemble );
    for (iens = 0; iens < ens_size; iens++)
      vector_append_owned_ref( misfit_ensemble->ensemble , misfit_member_alloc( iens ) , misfit_member_free__);
    
  } else 
    /* We shrink the vector by removing the last elements. */
    vector_shrink( misfit_ensemble->ensemble , ens_size);
}
예제 #15
0
파일: well_ts.c 프로젝트: JacobStoren/ert
void well_ts_add_well( well_ts_type * well_ts , well_state_type * well_state ) {
  well_node_type * new_node = well_node_alloc( well_state );
  vector_append_owned_ref( well_ts->ts , new_node , well_node_free__ );

  if (vector_get_size( well_ts->ts ) > 1) {
    const well_node_type * last_node = vector_get_last_const(well_ts->ts );
    if (new_node->sim_time < last_node->sim_time) 
      // The new node is chronologically before the previous node;
      // i.e. we must sort the nodes in time. This should probably happen
      // quite seldom:
      vector_sort( well_ts->ts , well_node_time_cmp );
  }
}
예제 #16
0
void ensemble_add_case( ensemble_type * ensemble , const char * data_file ) {
  sum_case_type * sum_case = sum_case_fread_alloc( data_file , ensemble->interp_time );

  pthread_rwlock_wrlock( &ensemble->rwlock );
  {
    printf("Loading case: %s \n", data_file );
    vector_append_owned_ref( ensemble->data , sum_case , sum_case_free__ );
    if (ensemble->start_time > 0)
      ensemble->start_time = util_time_t_min( ensemble->start_time , sum_case->start_time);
    else
      ensemble->start_time = ecl_sum_get_start_time( sum_case->ecl_sum );

    ensemble->end_time   = util_time_t_max( ensemble->end_time   , sum_case->end_time);
  }
  pthread_rwlock_unlock( &ensemble->rwlock );

}
예제 #17
0
파일: ert_run_context.c 프로젝트: chflo/ert
ert_run_context_type * ert_run_context_alloc_ENSEMBLE_EXPERIMENT(enkf_fs_type * fs , const bool_vector_type * iactive ,
                                                                 path_fmt_type * runpath_fmt ,
                                                                 subst_list_type * subst_list ,
                                                                 int iter) {

  ert_run_context_type * context = ert_run_context_alloc( iactive , ENSEMBLE_EXPERIMENT , fs , fs , NULL , iter);
  {
    stringlist_type * runpath_list = ert_run_context_alloc_runpath_list( iactive , runpath_fmt , subst_list , iter );
    for (int iens = 0; iens < bool_vector_size( iactive ); iens++) {
      if (bool_vector_iget( iactive , iens )) {
        run_arg_type * arg = run_arg_alloc_ENSEMBLE_EXPERIMENT( fs , iens , iter , stringlist_iget( runpath_list , iens));
        vector_append_owned_ref( context->run_args , arg , run_arg_free__);
      }
    }
    stringlist_free( runpath_list );
  }
  return context;
}
예제 #18
0
파일: nnc_info.c 프로젝트: moiw/ert
void nnc_info_add_nnc(nnc_info_type * nnc_info, int lgr_nr, int global_cell_number) {
   
  bool index_list_initialized = false; 
  
  if (int_vector_size(nnc_info->lgr_index_map) > lgr_nr) {
    int lgr_index = int_vector_iget(nnc_info->lgr_index_map, lgr_nr); 
    if (-1 != lgr_index) {
      int_vector_append(vector_iget(nnc_info->lgr_list, lgr_index), global_cell_number);
      index_list_initialized = true; 
    }
  }
  
  if (!index_list_initialized) {
    int_vector_type * nnc_for_lgr_vec = int_vector_alloc(0,0); 
    int_vector_append(nnc_for_lgr_vec, global_cell_number); 
    vector_append_owned_ref(nnc_info->lgr_list, nnc_for_lgr_vec, int_vector_free__); 
    int_vector_iset(nnc_info->lgr_index_map , lgr_nr, vector_get_size(nnc_info->lgr_list) -1 ); 
  }
 }
예제 #19
0
파일: ert_run_context.c 프로젝트: chflo/ert
ert_run_context_type * ert_run_context_alloc_SMOOTHER_RUN(enkf_fs_type * simulate_fs , enkf_fs_type * target_update_fs ,
                                                          const bool_vector_type * iactive ,
                                                          path_fmt_type * runpath_fmt ,
                                                          subst_list_type * subst_list ,
                                                          int iter) {

  ert_run_context_type * context = ert_run_context_alloc( iactive , SMOOTHER_UPDATE , simulate_fs , simulate_fs , target_update_fs , iter);
  {
    stringlist_type * runpath_list = ert_run_context_alloc_runpath_list( iactive , runpath_fmt , subst_list , iter );
    for (int iens = 0; iens < bool_vector_size( iactive ); iens++) {
      if (bool_vector_iget( iactive , iens )) {
        run_arg_type * arg = run_arg_alloc_SMOOTHER_RUN( simulate_fs , target_update_fs , iens , iter , stringlist_iget( runpath_list , iens));
        vector_append_owned_ref( context->run_args , arg , run_arg_free__);
      }
    }
    stringlist_free( runpath_list );
  }
  return context;
}
예제 #20
0
파일: run_gravity.c 프로젝트: Ensembles/ert
static void load_stations(vector_type * grav_stations , const char * filename) {
  printf("Loading from file:%s \n",filename);
  {
    int    target_width;
    FILE * stream = util_fopen(filename , "r");
    bool at_eof = false;
    /**
       When reading the first line we determine how many columns the
       file contains.
    */
    {
      char * first_line = util_fscanf_alloc_line( stream , &at_eof);
      char ** token_list;
      util_split_string( first_line , " \t" , &target_width , &token_list);
      util_free_stringlist( token_list , target_width );
      fseek( stream , 0 , SEEK_SET );
    }
    
    while(!(at_eof)) {
      double x,y,d;
      double obs_gdiff , std_gdiff;
      char station_name[32];
      int fscanf_return;
      
      if (target_width == 4)
        fscanf_return = fscanf(stream, "%s %lg %lg %lg", station_name , &x , &y , &d );
      else
        fscanf_return = fscanf(stream, "%s %lg %lg %lg %lg %lg", station_name , &x , &y , &d , &obs_gdiff , &std_gdiff);
      
      if (fscanf_return == target_width) {
        grav_station_type * g = grav_station_alloc_new(station_name , x , y , d);
        if (target_width == 6)
          grav_station_add_obs( g , obs_gdiff , std_gdiff );
        
        vector_append_owned_ref(grav_stations, g, grav_station_free__);
      } else 
        at_eof = true;
    }
    fclose(stream);
  }
}
예제 #21
0
static void ecl_sum_data_append_tstep__( ecl_sum_data_type * data , int ministep_nr , ecl_sum_tstep_type * tstep) {
  /* 
     Here the tstep is just appended naively, the vector will be
     sorted by ministep_nr before the data instance is returned.
  */

  /*
    We keep track of the earliest (in true time sence) tstep we
    have added so far; this is done somewhat manuyally because we need
    this information before the index is ready.

    The __min_time field is used to limit loading of restarted data in
    time periods where both the main case and the source case we have
    restarted from have data. This situation typically arises when we
    have restarted a simulation from a report step before the end of
    the initial simulation:

    Simulation 1:      T1-------------TR------------T2
                                      |             
    Simulation 2:                     \-----------------------T3            


    In the time interval [TR,T2] we have data from two simulations, we
    want to use only the data from simulation 2 in this period. The
    decision whether to to actually append the ministep or not must
    have been performed by the scope calling this function; when a
    ministep has arrived here it will be added.
  */
  
  if (data->__min_time == 0)
    data->__min_time = ecl_sum_tstep_get_sim_time( tstep );
  else {
    if (ecl_sum_tstep_get_sim_time( tstep ) < data->__min_time)
      data->__min_time = ecl_sum_tstep_get_sim_time( tstep );
  }
    
  vector_append_owned_ref( data->data , tstep , ecl_sum_tstep_free__);
  data->index_valid = false;
}
예제 #22
0
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;
}
예제 #23
0
ert_run_context_type * ert_run_context_alloc_ENKF_ASSIMILATION(enkf_fs_type * fs , 
                                                               const bool_vector_type * iactive , 
                                                               path_fmt_type * runpath_fmt , 
                                                               subst_list_type * subst_list ,
                                                               init_mode_type init_mode , 
                                                               state_enum init_state_parameter ,
                                                               state_enum init_state_dynamic   ,
                                                               int step1                       , 
                                                               int step2                       ,
                                                               int iter) {
  
  ert_run_context_type * context = ert_run_context_alloc( iactive , SMOOTHER_UPDATE , fs , fs , fs , init_mode , iter);
  {
    stringlist_type * runpath_list = ert_run_context_alloc_runpath_list( iactive , runpath_fmt , subst_list , iter );
    for (int iens = 0; iens < bool_vector_size( iactive ); iens++) {
      if (bool_vector_iget( iactive , iens )) {
        run_arg_type * arg = run_arg_alloc_ENKF_ASSIMILATION( fs , iens , init_state_parameter , init_state_dynamic , step1 , step2 , stringlist_iget( runpath_list , iens));
        vector_append_owned_ref( context->run_args , arg , run_arg_free__);
      }
    }
    stringlist_free( runpath_list );
  }
  return context;
}
예제 #24
0
void gen_kw_config_set_parameter_file( gen_kw_config_type * config , const char * parameter_file ) {
  config->parameter_file = util_realloc_string_copy( config->parameter_file , parameter_file );
  vector_clear( config->parameters );
  if (parameter_file != NULL) {
    FILE * stream = util_fopen(parameter_file , "r");
    
    while (true) {
      char parameter_name[256];
      int  fscanf_return;
      
      fscanf_return = fscanf(stream , "%s" , parameter_name);
      if (fscanf_return == 1) {
        gen_kw_parameter_type * parameter  = gen_kw_parameter_alloc( parameter_name , config->tag_fmt);
        trans_func_type       * trans_func = trans_func_fscanf_alloc( stream );
        gen_kw_parameter_set_trans_func( parameter , trans_func );

        vector_append_owned_ref( config->parameters , parameter , gen_kw_parameter_free__ );
      } else 
        break; /* OK - we are ate EOF. */
    } 
    
    fclose( stream );
  }
}
예제 #25
0
static void ecl_rft_file_add_node(ecl_rft_file_type * rft_vector , const ecl_rft_node_type * rft_node) {
  vector_append_owned_ref( rft_vector->data , rft_node , ecl_rft_node_free__);
}
예제 #26
0
void module_data_block_vector_add_data_block( module_data_block_vector_type * module_data_block_vector , const module_data_block_type * data_block) {
  vector_append_owned_ref(module_data_block_vector->data_block_vector, data_block , module_data_block_free__);
}
예제 #27
0
파일: workflow.c 프로젝트: YingfangZhou/ert
static void workflow_add_cmd( workflow_type * workflow , cmd_type * cmd ) {
  vector_append_owned_ref( workflow->cmd_list , cmd , cmd_free__ );
}
예제 #28
0
파일: ecl_rft_node.c 프로젝트: atgeirr/ert
void ecl_rft_node_append_cell( ecl_rft_node_type * rft_node , ecl_rft_cell_type * cell) {
  vector_append_owned_ref( rft_node->cells , cell , ecl_rft_cell_free__ );
  rft_node->sort_perm_in_sync = false;
}
예제 #29
0
config_content_node_type * config_content_item_alloc_node( const config_content_item_type * item , const config_path_elm_type * path_elm) {
  config_content_node_type * node = config_content_node_alloc( item->schema , path_elm );
  vector_append_owned_ref( item->nodes , node , config_content_node_free__);
  return node;
}
예제 #30
0
static void ecl_grav_survey_add_phase( ecl_grav_survey_type * survey, ecl_phase_enum phase , ecl_grav_phase_type * grav_phase ) {
  vector_append_owned_ref( survey->phase_list , grav_phase , ecl_grav_phase_free__ );
  hash_insert_ref( survey->phase_map , ecl_util_get_phase_name( phase ) , grav_phase );
}