Example #1
0
static gen_data_config_type * gen_data_config_alloc( const char * key , bool dynamic ) {
  gen_data_config_type * config = util_malloc(sizeof * config );
  UTIL_TYPE_ID_INIT( config , GEN_DATA_CONFIG_ID);

  config->key               = util_alloc_string_copy( key );

  config->template_file        = NULL;
  config->template_key         = NULL;
  config->template_buffer      = NULL;
  gen_data_config_reset_template( config );

  config->data_size          = 0;
  config->internal_type      = ECL_DOUBLE_TYPE;
  config->input_format       = GEN_DATA_UNDEFINED;
  config->output_format      = GEN_DATA_UNDEFINED;
  config->data_size_vector   = int_vector_alloc( 0 , -1 );   /* The default value: -1 - indicates "NOT SET" */
  config->active_report_steps= int_vector_alloc( 0 , 0 );
  config->active_mask        = bool_vector_alloc(0 , true ); /* Elements are explicitly set to FALSE - this MUST default to true. */ 
  config->active_report_step = -1;
  config->ens_size           = -1;
  config->read_fs            = NULL;
  config->write_fs           = NULL;
  config->dynamic            = dynamic;
  pthread_mutex_init( &config->update_lock , NULL );


  return config;
}
Example #2
0
void fault_block_layer_scan_layer( fault_block_layer_type * fault_layer , layer_type * layer) {
  int i,j;
  int_vector_type * i_list = int_vector_alloc(0,0);
  int_vector_type * j_list = int_vector_alloc(0,0);

  for (j = 0; j < layer_get_ny( layer ); j++) {
    for (i = 0; i < layer_get_nx( layer); i++) {
      int cell_value = layer_iget_cell_value( layer , i , j );
      if (cell_value != 0) {
        layer_trace_block_content( layer , true , i , j , cell_value , i_list , j_list );
        {
          int c;
          int block_id = fault_block_layer_get_next_id( fault_layer );
          fault_block_type * fault_block = fault_block_layer_add_block( fault_layer , block_id );
          for (c=0; c < int_vector_size( i_list ); c++)
            fault_block_add_cell( fault_block , int_vector_iget( i_list , c ), int_vector_iget( j_list , c ));

        }
      }
    }
  }

  int_vector_free( i_list );
  int_vector_free( j_list );
}
Example #3
0
ecl_sum_data_type * ecl_sum_data_alloc(ecl_smspec_type * smspec) {
  ecl_sum_data_type * data = util_malloc( sizeof * data );
  data->data        = vector_alloc_new();
  data->smspec      = smspec;
  data->__min_time  = 0;
  
  data->report_first_index    = int_vector_alloc( 0 , -1 );  /* This -1 value is hard-wired around in the place - not good. */
  data->report_last_index     = int_vector_alloc( 0 , -1 );
  

  ecl_sum_data_clear_index( data );
  return data;
}
Example #4
0
int ecl_sum_data_get_report_step_from_days(const ecl_sum_data_type * data , double sim_days) {
  if ((sim_days < data->days_start) || (sim_days > data->sim_length))
    return -1;
  else {
    int report_step = -1;

    double_vector_type * days_map = double_vector_alloc( 0 , 0 );
    int_vector_type    * report_map = int_vector_alloc( 0 , 0 );
    int i;

    for (i=1; i < int_vector_size( data->report_last_index ); i++) {
      int ministep_index = int_vector_iget( data->report_last_index , i );
      const ecl_sum_tstep_type * ministep = vector_iget_const( data->data , ministep_index );
      
      double_vector_iset( days_map , i , ecl_sum_tstep_get_sim_days( ministep ));
      int_vector_iset( report_map , i , ecl_sum_tstep_get_report( ministep ));
    }
    
    {
      /** Hmmmm - double == comparison ... */
      int index = double_vector_index_sorted( days_map , sim_days );
      
      if (index >= 0)
        report_step = int_vector_iget( report_map , index );
    }
    
    int_vector_free( report_map );
    double_vector_free( days_map );
    return report_step;
  }
}
void test_range_fill_int() {
  int_vector_type * int_vector = int_vector_alloc(0,0);

  int_vector_range_fill( int_vector , 10 , 10 , 40 );  /* 10,20,30,40 */
  test_assert_int_equal( int_vector_size( int_vector ), 4);
  test_assert_int_equal( int_vector_iget( int_vector , 0 ) , 10 );
  test_assert_int_equal( int_vector_iget( int_vector , 1 ) , 20 );
  test_assert_int_equal( int_vector_iget( int_vector , 2 ) , 30 );
  test_assert_int_equal( int_vector_iget( int_vector , 3 ) , 40 );
  
  int_vector_range_fill( int_vector , 10 , 10 , 44 );  /* 10,20,30,40 */
  test_assert_int_equal( int_vector_size( int_vector ), 4);
  test_assert_int_equal( int_vector_iget( int_vector , 0 ) , 10 );
  test_assert_int_equal( int_vector_iget( int_vector , 1 ) , 20 );
  test_assert_int_equal( int_vector_iget( int_vector , 2 ) , 30 );
  test_assert_int_equal( int_vector_iget( int_vector , 3 ) , 40 );

  int_vector_range_fill( int_vector , 4 , -1 , 0 );  /* 4,3,2,1,0 */
  test_assert_int_equal( int_vector_size( int_vector ), 5);
  test_assert_int_equal( int_vector_iget( int_vector , 0 ) , 4 );
  test_assert_int_equal( int_vector_iget( int_vector , 1 ) , 3 );
  test_assert_int_equal( int_vector_iget( int_vector , 2 ) , 2 );
  test_assert_int_equal( int_vector_iget( int_vector , 3 ) , 1 );
  test_assert_int_equal( int_vector_iget( int_vector , 4 ) , 0 );

  int_vector_range_fill( int_vector , 20 , -10 , -3 );  /* 20,10,0 */
  test_assert_int_equal( int_vector_size( int_vector ), 3);
  test_assert_int_equal( int_vector_iget( int_vector , 0 ) , 20 );
  test_assert_int_equal( int_vector_iget( int_vector , 1 ) , 10 );
  test_assert_int_equal( int_vector_iget( int_vector , 2 ) ,  0 );

  int_vector_free( int_vector );
}
void test_resize() {
  int i;
  int def = 77;
  int_vector_type * vec = int_vector_alloc(0,def);
  int_vector_resize( vec , 10 );
  test_assert_int_equal( int_vector_size( vec ) , 10 );
  for (i=0; i < 10; i++)
    test_assert_int_equal( int_vector_iget( vec , i ) , def );
  
  int_vector_iset_block( vec , 5 , 5 , 5 );
  for (i=5; i < 10; i++)
    test_assert_int_equal( int_vector_iget( vec , i ) , 5 );

  int_vector_resize( vec , 5 );
  test_assert_int_equal( int_vector_size( vec ) , 5 );
  for (i=0; i < 5; i++)
    test_assert_int_equal( int_vector_iget( vec , i ) , def );

  int_vector_resize( vec , 10 );
  test_assert_int_equal( int_vector_size( vec ) , 10 );
  for (i=0; i < 10; i++)
    test_assert_int_equal( int_vector_iget( vec , i ) , def );

  int_vector_free( vec );
}
void test_idel_insert() {
  int_vector_type * vec = int_vector_alloc(0,0);

  int_vector_append(vec , 1 );
  int_vector_append(vec , 2 );
  int_vector_append(vec , 2 );
  int_vector_append(vec , 3 );

  int_vector_fprintf(vec , stdout , "Vec0" , "%2d");
  int_vector_idel(vec , 1 );
  int_vector_fprintf(vec , stdout , "Vec1" , "%2d");
  int_vector_idel(vec , 1 );
  int_vector_fprintf(vec , stdout , "Vec2" , "%2d");

  test_assert_int_equal( 2 , int_vector_size( vec ));
  test_assert_int_equal( 1 , int_vector_iget( vec , 0 ));
  test_assert_int_equal( 3 , int_vector_iget( vec , 1 ));

  int_vector_insert(vec , 1 , 2 );
  int_vector_insert(vec , 1 , 2 );
  test_assert_int_equal( 4 , int_vector_size( vec ));
  test_assert_int_equal( 1 , int_vector_iget( vec , 0 ));
  test_assert_int_equal( 2 , int_vector_iget( vec , 1 ));
  test_assert_int_equal( 2 , int_vector_iget( vec , 2 ));
  test_assert_int_equal( 3 , int_vector_iget( vec , 3 ));

  int_vector_free( vec );
}
void test_shift() {
  int default_value = 88;
  int_vector_type * v = int_vector_alloc(0,default_value);

  int_vector_append(v , 1 );
  int_vector_append(v , 2 );
  int_vector_append(v , 3 );
  test_assert_int_equal( 1 , int_vector_iget( v , 0 ));
  test_assert_int_equal( 2 , int_vector_iget( v , 1 ));
  test_assert_int_equal( 3 , int_vector_iget( v , 2 ));

  int_vector_rshift(v , 3 );
  test_assert_int_equal( 6 , int_vector_size( v ));
  test_assert_int_equal( default_value , int_vector_iget( v , 0 ));
  test_assert_int_equal( default_value , int_vector_iget( v , 1 ));
  test_assert_int_equal( default_value , int_vector_iget( v , 2 ));
  test_assert_int_equal( 1 , int_vector_iget( v , 3 ));
  test_assert_int_equal( 2 , int_vector_iget( v , 4 ));
  test_assert_int_equal( 3 , int_vector_iget( v , 5 ));

  int_vector_lshift(v,4);
  test_assert_int_equal( 2 , int_vector_size( v ));
  test_assert_int_equal( 2 , int_vector_iget( v , 0 ));
  test_assert_int_equal( 3 , int_vector_iget( v , 1 ));
  
  int_vector_free( v );
}
Example #9
0
int ecl_sum_data_get_report_step_from_time(const ecl_sum_data_type * data , time_t sim_time) {
  if ((sim_time < data->data_start_time) || (sim_time > data->sim_end))
    return -1;

  {
    int report_step = -1;

    time_t_vector_type * time_map = time_t_vector_alloc( 0 , 0 );
    int_vector_type    * report_map = int_vector_alloc( 0 , 0 );
    int i;

    for (i=1; i < int_vector_size( data->report_last_index ); i++) {
      int ministep_index = int_vector_iget( data->report_last_index , i );
      const ecl_sum_tstep_type * ministep = vector_iget_const( data->data , ministep_index );
      
      time_t_vector_iset( time_map , i , ecl_sum_tstep_get_sim_time( ministep ));
      int_vector_iset( report_map , i , ecl_sum_tstep_get_report( ministep ));
      
    }
    
    {
      int index = time_t_vector_index_sorted( time_map , sim_time );
      
      if (index >= 0)
        report_step = int_vector_iget( report_map , index );
    }
    
    int_vector_free( report_map );
    time_t_vector_free( time_map );
    return report_step;
  }
}
Example #10
0
void * enkf_main_analysis_enkf_update_JOB( void * self , const stringlist_type * args) {
  enkf_main_type   * enkf_main = enkf_main_safe_cast( self );
  enkf_fs_type * target_fs = enkf_main_get_fs( enkf_main );
  int target_step;
  int_vector_type * step_list;


  // Argument 0: The number of the step to write to
  if (stringlist_get_size(args) > 1)
    util_sscanf_int(stringlist_iget( args , 1) , &target_step);
  else
    target_step = 0;

  // Argument 1 - ??: The timesteps to use in the update
  if (stringlist_get_size( args ) > 2) {
    char * step_args = stringlist_alloc_joined_substring(args , 2 , stringlist_get_size(args) , " ");
    step_list = string_util_alloc_active_list( step_args );
    free( step_args );
  } else
    step_list = int_vector_alloc(1,target_step);

  enkf_main_UPDATE( enkf_main , step_list , target_fs , target_step , SMOOTHER_UPDATE);

  int_vector_free( step_list );
  return NULL;
}
Example #11
0
File: nnc_info.c Project: moiw/ert
nnc_info_type * nnc_info_alloc() {
  nnc_info_type * nnc_info = util_malloc( sizeof * nnc_info );
  UTIL_TYPE_ID_INIT(nnc_info , NNC_INFO_TYPE_ID);
  nnc_info->lgr_list = vector_alloc_new(); 
  nnc_info->lgr_index_map = int_vector_alloc(0, -1); 
  return nnc_info; 
}
int_vector_type * int_vector_alloc_copy( const int_vector_type * src) {
  int_vector_type * copy = int_vector_alloc( src->size , src->default_value );
  int_vector_realloc_data__( copy , src->alloc_size );
  copy->size = src->size;
  memcpy(copy->data , src->data , src->alloc_size * sizeof * src->data );
  return copy;
}
Example #13
0
void * enkf_main_std_scale_correlated_obs_JOB(void * self, const stringlist_type * args)  {

  if (stringlist_get_size(args) > 0) {
    enkf_main_type * enkf_main              = enkf_main_safe_cast( self );
    int ensemble_size                       = enkf_main_get_ensemble_size(enkf_main);
    enkf_fs_type * fs                       = enkf_main_get_fs( enkf_main );
    enkf_obs_type * obs                     = enkf_main_get_obs( enkf_main );
    int_vector_type * realizations          = int_vector_alloc(1, 0);
    local_obsdata_type * obsdata = local_obsdata_alloc( "OBS-JOB" );

    int_vector_init_range(realizations, 0, ensemble_size, 1);

    for (int iarg = 0; iarg < stringlist_get_size(args); iarg++) {
      const char * arg_key = stringlist_iget( args , iarg );
      stringlist_type * key_list = enkf_obs_alloc_matching_keylist(obs, arg_key);
      for (int iobs=0; iobs < stringlist_get_size( key_list ); iobs++) {
        const char * obs_key = stringlist_iget( key_list , iobs);
        const obs_vector_type * obs_vector = enkf_obs_get_vector(obs, obs_key);
        local_obsdata_add_node( obsdata , obs_vector_alloc_local_node(obs_vector) );
      }
      stringlist_free( key_list );
    }

    if (local_obsdata_get_size(obsdata) > 0)
      enkf_obs_scale_correlated_std(obs, fs, realizations, obsdata );

    local_obsdata_free( obsdata );
  }

  return NULL;
}
Example #14
0
void test_measure( ert_test_context_type * test_context ) {
  enkf_main_type * enkf_main = ert_test_context_get_main( test_context );
  enkf_fs_type * fs = enkf_main_get_fs( enkf_main );
  enkf_obs_type * enkf_obs = enkf_main_get_obs( enkf_main );
  obs_vector_type * rft_obs = enkf_obs_get_vector( enkf_obs , "RFT_TEST");
  int_vector_type * ens_active_list = int_vector_alloc(0,0);
  active_list_type * active_list = active_list_alloc( );
  meas_data_type * meas_data_RFT;

  for (int i=0; i < enkf_main_get_ensemble_size( enkf_main ); i++)
    int_vector_append( ens_active_list , i );

  {
    bool_vector_type * ens_mask;
    ens_mask = int_vector_alloc_mask( ens_active_list );
    meas_data_RFT = meas_data_alloc( ens_mask );
    bool_vector_free( ens_mask );
  }

  obs_vector_measure( rft_obs , fs , 20 , ens_active_list , meas_data_RFT , active_list );

  int_vector_free( ens_active_list );
  active_list_free( active_list );
  meas_data_free( meas_data_RFT );
}
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;
}
well_segment_collection_type * well_segment_collection_alloc() {
  well_segment_collection_type * segment_collection = util_malloc( sizeof * segment_collection );

  segment_collection->__segment_storage = vector_alloc_new();
  segment_collection->segment_index_map = int_vector_alloc( 0 , -1 );
  return segment_collection;
}
Example #17
0
int main( int argc , char ** argv) {
  const char * egrid_file = argv[1];

  ecl_grid_type * grid = ecl_grid_alloc( egrid_file );
  ecl_file_type * gfile = ecl_file_open( egrid_file , 0 );
  const ecl_kw_type * nnc1_kw = ecl_file_iget_named_kw( gfile , "NNC1" ,0 );
  const ecl_kw_type * nnc2_kw = ecl_file_iget_named_kw( gfile , "NNC2" ,0 );
  const int_vector_type * index_list = ecl_grid_get_nnc_index_list( grid );
  
  {
    int_vector_type * nnc = int_vector_alloc(0,0);
    
    int_vector_set_many( nnc , 0 , ecl_kw_get_ptr( nnc1_kw ) , ecl_kw_get_size( nnc1_kw ));
    int_vector_append_many( nnc , ecl_kw_get_ptr( nnc2_kw ) , ecl_kw_get_size( nnc2_kw ));
    int_vector_select_unique( nnc );
    test_assert_int_equal( int_vector_size( index_list ) , int_vector_size( nnc ));
    
    {
      int i;
      for (i=0; i < int_vector_size( nnc ); i++)
        test_assert_int_equal( int_vector_iget( nnc , i ) - 1 , int_vector_iget(index_list , i ));
    }
    int_vector_free( nnc );
  }
  
  ecl_file_close( gfile );
  ecl_grid_free( grid );

  exit(0);
}
Example #18
0
void test_trace_edge( const ecl_grid_type * grid) {
  const int k = 1;
  fault_block_layer_type * layer = fault_block_layer_alloc( grid , k );
  double_vector_type * x_list = double_vector_alloc( 0,0);
  double_vector_type * y_list = double_vector_alloc( 0,0);
  fault_block_type * block = fault_block_layer_safe_get_block( layer , 99);
  int_vector_type * cell_list = int_vector_alloc(0,0);
    
  test_assert_false( fault_block_trace_edge( block , x_list , y_list , cell_list));
  fault_block_add_cell( block , 0,0);
  test_assert_true( fault_block_trace_edge( block , x_list , y_list , cell_list));
  test_assert_int_equal( 4 , double_vector_size( x_list ));
  test_assert_int_equal( 4 , double_vector_size( y_list ));
  
  test_assert_double_equal( 0 , double_vector_iget( x_list , 0 ));
  test_assert_double_equal( 1 , double_vector_iget( x_list , 1 ));
  test_assert_double_equal( 1 , double_vector_iget( x_list , 2 ));
  test_assert_double_equal( 0 , double_vector_iget( x_list , 3 ));
  
  test_assert_double_equal( 0 , double_vector_iget( y_list , 0 ));
  test_assert_double_equal( 0 , double_vector_iget( y_list , 1 ));
  test_assert_double_equal( 1 , double_vector_iget( y_list , 2 ));
  test_assert_double_equal( 1 , double_vector_iget( y_list , 3 ));

  test_assert_int_equal( 1 , int_vector_size( cell_list ));
  test_assert_int_equal( 0 , int_vector_iget( cell_list , 0));

  int_vector_free( cell_list );
  double_vector_free( x_list );
  double_vector_free( y_list );
}
Example #19
0
state_map_type * state_map_alloc( ) {
  state_map_type * map = util_malloc( sizeof * map );
  UTIL_TYPE_ID_INIT( map , STATE_MAP_TYPE_ID );
  map->state = int_vector_alloc( 0 , STATE_UNDEFINED );
  pthread_rwlock_init( &map->rw_lock , NULL);
  return map;
}
Example #20
0
ecl_sum_vector_type * ecl_sum_vector_alloc(const ecl_sum_type * ecl_sum){
    ecl_sum_vector_type * ecl_sum_vector = util_malloc( sizeof * ecl_sum_vector );
    UTIL_TYPE_ID_INIT( ecl_sum_vector , ECL_SUM_VECTOR_TYPE_ID);
    ecl_sum_vector->ecl_sum  = ecl_sum;
    ecl_sum_vector->node_index_list = int_vector_alloc(0,0);
    ecl_sum_vector->is_rate_list  = bool_vector_alloc(0,false);
    return ecl_sum_vector;
}
Example #21
0
void * enkf_main_export_runpath_file_JOB(void * self, const stringlist_type * args)  {
  enkf_main_type * enkf_main              = enkf_main_safe_cast( self );
  int ensemble_size                       = enkf_main_get_ensemble_size(enkf_main);
  analysis_config_type * analysis_config  = enkf_main_get_analysis_config(enkf_main);
  analysis_iter_config_type * iter_config = analysis_config_get_iter_config(analysis_config);
  int num_iterations                      = analysis_iter_config_get_num_iterations(iter_config);
  const model_config_type * model_config  = enkf_main_get_model_config(enkf_main);
  int_vector_type * realizations          = int_vector_alloc(1, 0);
  int_vector_init_range(realizations, 0, ensemble_size, 1);
  int_vector_type * iterations            = int_vector_alloc(1, 0);


  if (stringlist_get_size(args) > 0) {
    int offset = 0;
    while (true) {
      if (offset == stringlist_get_size( args ))
        break;
      if (0 == strcmp("|" , stringlist_iget( args, offset )))
        break;
       ++offset;
    }

    if (0 != strcmp("*", stringlist_iget(args,0))) {
      char * range_str = stringlist_alloc_joined_substring( args, 0, offset, "");
      string_util_init_value_list(range_str, realizations);
      free(range_str);
    }

    if ((offset < stringlist_get_size(args)) && model_config_runpath_requires_iter(model_config)) {
      if (0 == strcmp("*", stringlist_iget(args, (offset+1))))
        int_vector_init_range(iterations, 0, num_iterations, 1);
      else {
        char * range_str = stringlist_alloc_joined_substring( args, offset+1, stringlist_get_size(args), "");
        string_util_init_value_list(range_str, iterations);
        free(range_str);
       }
    }
  }

  enkf_main_export_runpath_file(enkf_main, realizations, iterations);

  int_vector_free(realizations);
  int_vector_free(iterations);

  return NULL;
}
void test_div() {
  int_vector_type * int_vector = int_vector_alloc( 0 , 100);
  int_vector_iset( int_vector , 10 , 100 );
  int_vector_div( int_vector , 10 );
  {
    int i;
    for (i=0; i < int_vector_size( int_vector ); i++) 
      test_assert_int_equal( 10 , int_vector_iget( int_vector , i ));
  }
}
Example #23
0
int_vector_type * bool_vector_alloc_active_list( const bool_vector_type * mask ) {
  int_vector_type * active_list = int_vector_alloc(0,0);
  int i;

  for (i =0; i < bool_vector_size( mask ); i++)
    if (bool_vector_iget( mask , i ))
      int_vector_append( active_list , i );
  
  return active_list;
}
Example #24
0
int_vector_type * vector_alloc_sort_perm(const vector_type * vector , vector_cmp_ftype * cmp) {
  vector_sort_node_type * sort_data = vector_alloc_sort_data( vector , cmp );
  int_vector_type * sort_perm = int_vector_alloc(0,0);
  int i;
  for (i = 0; i < vector->size; i++)
    int_vector_iset( sort_perm , i , sort_data[i].index);

  free( sort_data );
  return sort_perm;
}
Example #25
0
void test_write_header() {
    int nx = 10;
    int ny = 10;
    int nz = 5;

    int_vector_type * actnum = int_vector_alloc( nx*ny*nz , 1 );
    test_work_area_type * test_area = test_work_area_alloc( "ecl_init_file" );
    time_t start_time = util_make_date(15 , 12 , 2010 );
    ecl_grid_type * ecl_grid;

    int_vector_iset( actnum , 10 , 0 );
    int_vector_iset( actnum , 100 , 0 );

    ecl_grid = ecl_grid_alloc_rectangular(nx, ny, nz, 1, 1, 1, int_vector_get_ptr( actnum ));

    // Write poro with global size.
    {
        fortio_type * f = fortio_open_writer( "FOO1.INIT" , false , ECL_ENDIAN_FLIP );
        ecl_kw_type * poro = ecl_kw_alloc( "PORO" , ecl_grid_get_global_size( ecl_grid ) , ECL_FLOAT_TYPE );
        ecl_kw_scalar_set_float( poro , 0.10 );
        ecl_init_file_fwrite_header( f , ecl_grid , poro , 7 , start_time );
        ecl_kw_free( poro );
        fortio_fclose( f );
    }


    // Write poro with nactive size.
    {
        fortio_type * f = fortio_open_writer( "FOO2.INIT" , false , ECL_ENDIAN_FLIP );
        ecl_kw_type * poro = ecl_kw_alloc( "PORO" , ecl_grid_get_global_size( ecl_grid ) , ECL_FLOAT_TYPE );
        ecl_kw_scalar_set_float( poro , 0.10 );
        ecl_init_file_fwrite_header( f , ecl_grid , poro , 7 , start_time );
        ecl_kw_free( poro );
        fortio_fclose( f );
    }
    {
        ecl_file_type * file1 = ecl_file_open( "FOO1.INIT" , 0 );
        ecl_file_type * file2 = ecl_file_open( "FOO2.INIT" , 0 );

        test_assert_true( ecl_kw_equal( ecl_file_iget_named_kw( file1 , "PORV" , 0 ) ,
                                        ecl_file_iget_named_kw( file2 , "PORV" , 0)));

        ecl_file_close( file2 );
        ecl_file_close( file1 );
    }


    // Poro == NULL
    {
        fortio_type * f = fortio_open_writer( "FOO3.INIT" , false , ECL_ENDIAN_FLIP );
        ecl_init_file_fwrite_header( f , ecl_grid , NULL , 7 , start_time );
        fortio_fclose( f );
    }
    test_work_area_free( test_area );
}
void test_memcpy_from_data() {
  int_vector_type * int_vector = int_vector_alloc( 10 , 77 );
  int data[5] = {1,2,3,4,5};

  int_vector_memcpy_from_data( int_vector , data , 5 );
  test_assert_int_equal( 5 , int_vector_size( int_vector ));

  for (int i=0; i < int_vector_size( int_vector ); i++) 
    test_assert_int_equal( i + 1 , int_vector_iget( int_vector , i ));
  
  int_vector_free( int_vector );
}
Example #27
0
static validate_type * validate_alloc() {
  validate_type * validate = util_malloc(sizeof * validate );
  validate->argc_min                = CONFIG_DEFAULT_ARG_MIN;
  validate->argc_max                = CONFIG_DEFAULT_ARG_MAX;
  validate->common_selection_set    = NULL;
  validate->indexed_selection_set   = vector_alloc_new();
  validate->required_children       = NULL;
  validate->required_children_value = NULL;
  validate->type_map                = int_vector_alloc(0 , 0);
  validate_set_default_type( validate , CONFIG_STRING );
  return validate;
}
Example #28
0
int_vector_type * bool_vector_alloc_active_index_list(const bool_vector_type * mask , int default_value) {
  int_vector_type * index_list = int_vector_alloc(bool_vector_size( mask) , default_value);
  int active_index = 0;
  int i;
  for (i=0; i < bool_vector_size(mask); i++) {
    if (bool_vector_iget( mask , i)) {
      int_vector_iset(index_list , i , active_index);
      active_index++;
    }
  }
  return index_list;
}
void test_alloc() {
  const int size = 100;
  const int default_value = 77;
  int_vector_type * v = int_vector_alloc(size , default_value);

  test_assert_int_equal(size , int_vector_size(v));
  for (int i=0; i < size; i++)
    test_assert_int_equal( default_value , int_vector_iget( v , i));


  int_vector_free( v);
}
Example #30
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;
}