Example #1
0
static void ecl_sum_data_build_index( ecl_sum_data_type * sum_data ) {
  /* Clear the existing index (if any): */
  ecl_sum_data_clear_index( sum_data );
  
  /*
    Sort the internal storage vector after sim_time. 
  */
  vector_sort( sum_data->data , cmp_ministep );

  
  /* Identify various global first and last values.  */
  {
    const ecl_sum_tstep_type * first_ministep = ecl_sum_data_iget_ministep( sum_data , 0 );
    sum_data->first_ministep = ecl_sum_tstep_get_ministep( first_ministep );

    /* 
       In most cases the days_start and data_start_time will agree
       with the global simulation start; however in the case where we
       have loaded a summary case from a restarted simulation where
       the case we have restarted from is not available - then there
       will be a difference.
    */
    sum_data->days_start      = ecl_sum_tstep_get_sim_days( first_ministep );
    sum_data->data_start_time = ecl_sum_tstep_get_sim_time( first_ministep );
  }
  ecl_sum_data_update_end_info( sum_data );
  
  /* Build up the report -> ministep mapping. */
  {
    int internal_index;
    for (internal_index = 0; internal_index < vector_get_size( sum_data->data ); internal_index++) {
      const ecl_sum_tstep_type * ministep = ecl_sum_data_iget_ministep( sum_data , internal_index  );
      int report_step = ecl_sum_tstep_get_report(ministep);
        
        /* Indexing internal_index - report_step */
        {
          int current_first_index = int_vector_safe_iget( sum_data->report_first_index , report_step );
          if (current_first_index < 0) /* i.e. currently not set. */
            int_vector_iset( sum_data->report_first_index , report_step , internal_index);
          else
            if (internal_index  < current_first_index)
              int_vector_iset( sum_data->report_first_index , report_step , internal_index);
        }
        
        {
          int current_last_index =  int_vector_safe_iget( sum_data->report_last_index , report_step );
          if (current_last_index < 0)
            int_vector_iset( sum_data->report_last_index , report_step ,  internal_index);
          else
            if (internal_index > current_last_index)
              int_vector_iset( sum_data->report_last_index , report_step , internal_index);
        }
        
        sum_data->first_report_step = util_int_min( sum_data->first_report_step , report_step );
        sum_data->last_report_step  = util_int_max( sum_data->last_report_step  , report_step );
    }
  }
  sum_data->index_valid = true;
}
void int_vector_insert( int_vector_type * vector , int index , int value) {
  if (index >= vector->size)
    int_vector_iset( vector , index , value );
  else {
    int_vector_memmove( vector , index , 1 );
    int_vector_iset( vector , index , value );
  }
}
Example #3
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_contains() {
  int_vector_type * int_vector = int_vector_alloc( 0 , 100);
  
  test_assert_false( int_vector_contains( int_vector , 100 ));
  int_vector_iset( int_vector , 0 , 77 );
  test_assert_false( int_vector_contains( int_vector , 100 ));
  test_assert_true( int_vector_contains( int_vector , 77 ));

  int_vector_iset( int_vector , 10 , 33 );
  test_assert_true( int_vector_contains( int_vector , 100 ));
  test_assert_true( int_vector_contains( int_vector , 77 ));
  test_assert_true( int_vector_contains( int_vector , 33 ));

  int_vector_free( int_vector );
}
Example #5
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 #6
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;
  }
}
Example #7
0
void fault_block_layer_del_block( fault_block_layer_type * layer , int block_id) {
  int storage_index = int_vector_safe_iget( layer->block_map , block_id);
  if (storage_index >= 0) {

    int_vector_iset( layer->block_map , block_id , -1 );
    vector_idel( layer->blocks , storage_index );
    {
      int index;

      for (index = 0; index < int_vector_size( layer->block_map ); index++) {
        int current_storage_index = int_vector_iget( layer->block_map , index );
        if (current_storage_index > storage_index)
          int_vector_iset( layer->block_map ,index , current_storage_index - 1);
      }
    }
  }
}
Example #8
0
static void state_map_iset__( state_map_type * map , int index , realisation_state_enum new_state) {
  realisation_state_enum current_state = int_vector_safe_iget( map->state , index );
  
  if (state_map_legal_transition( current_state , new_state ))
    int_vector_iset( map->state , index , new_state);
  else
    util_abort("%s: illegal state transition for realisation:%d %d -> %d \n" , __func__ , index , current_state , new_state );
}
int main(int argc , char ** argv) {
  
  int_vector_type * int_vector = int_vector_alloc( 0 , 99);
  
  int_vector_iset( int_vector , 2 , 0);       
  int_vector_insert( int_vector , 2 , 77 );   
  int_vector_iset( int_vector , 5 , -10);     
  
  int_vector_fprintf( int_vector , stdout , "int_vector" , "%3d");
  assert_equal( int_vector_iget(int_vector , 0 ) == 99 );
  assert_equal( int_vector_iget(int_vector , 1 ) == 99 );
  assert_equal( int_vector_iget(int_vector , 2 ) == 77 );
  assert_equal( int_vector_iget(int_vector , 3 ) == 00 );
  assert_equal( int_vector_iget(int_vector , 4 ) == 99 );
  assert_equal( int_vector_iget(int_vector , 5 ) == -10 );
  
  
  exit(0);
}
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 #11
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;
}
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);
  }
}
Example #13
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;
}
Example #14
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;
}
static int_vector_type * int_vector_alloc__(int init_size , int default_value, int * data, int alloc_size , bool data_owner ) {
  int_vector_type * vector = util_malloc( sizeof * vector );
  UTIL_TYPE_ID_INIT( vector , TYPE_VECTOR_ID);
  vector->default_value       = default_value;

  /**
     Not all combinations of (data, alloc_size, data_owner) are valid:

     1. Creating a new vector instance with fresh storage allocation
        from int_vector_alloc():

          data       == NULL
          alloc_size == 0
          data_owner == true


     2. Creating a shared wrapper from the int_vector_alloc_shared_wrapper():

          data       != NULL
          data_size   > 0
          data_owner == false


     3. Creating a private wrapper which steals the input data from
        int_vector_alloc_private_wrapper():

          data       != NULL
          data_size   > 0
          data_owner == true

  */

  if (data == NULL) {  /* Case 1: */
    vector->data              = NULL;
    vector->data_owner        = true;     /* The input values alloc_size and */
    vector->alloc_size        = 0;        /* data_owner are not even consulted. */
  } else {             /* Case 2 & 3 */
    vector->data              = data;
    vector->data_owner        = data_owner;
    vector->alloc_size        = alloc_size;
  }
  vector->size                = 0;

  int_vector_set_read_only( vector , false );
  if (init_size > 0)
    int_vector_iset( vector , init_size - 1 , default_value );  /* Filling up the init size elements with the default value */

  return vector;
}
Example #16
0
File: ecl_sum.c Project: flikka/ert
void ecl_sum_fprintf(const ecl_sum_type * ecl_sum , FILE * stream , const stringlist_type * var_list , bool report_only , const ecl_sum_fmt_type * fmt) {
  bool_vector_type  * has_var   = bool_vector_alloc( stringlist_get_size( var_list ), false );
  int_vector_type   * var_index = int_vector_alloc( stringlist_get_size( var_list ), -1 );
  char * date_string            = util_malloc( DATE_STRING_LENGTH * sizeof * date_string);

  char * current_locale = NULL;
  if (fmt->locale != NULL)
    current_locale = setlocale(LC_NUMERIC , fmt->locale);

  {
    int ivar;
    for (ivar = 0; ivar < stringlist_get_size( var_list ); ivar++) {
      if (ecl_sum_has_general_var( ecl_sum , stringlist_iget( var_list , ivar) )) {
        bool_vector_iset( has_var , ivar , true );
        int_vector_iset( var_index , ivar , ecl_sum_get_general_var_params_index( ecl_sum , stringlist_iget( var_list , ivar) ));
      } else {
        fprintf(stderr,"** Warning: could not find variable: \'%s\' in summary file \n", stringlist_iget( var_list , ivar));
        bool_vector_iset( has_var , ivar , false );
      }
    }
  }

  if (fmt->print_header)
    ecl_sum_fprintf_header( ecl_sum , var_list , has_var , stream , fmt);

  if (report_only) {
    int first_report = ecl_sum_get_first_report_step( ecl_sum );
    int last_report  = ecl_sum_get_last_report_step( ecl_sum );
    int report;

    for (report = first_report; report <= last_report; report++) {
      if (ecl_sum_data_has_report_step(ecl_sum->data , report)) {
        int time_index;
        time_index = ecl_sum_data_iget_report_end( ecl_sum->data , report );
        __ecl_sum_fprintf_line( ecl_sum , stream , time_index , has_var , var_index , date_string , fmt);
      }
    }
  } else {
    int time_index;
    for (time_index = 0; time_index < ecl_sum_get_data_length( ecl_sum ); time_index++)
      __ecl_sum_fprintf_line( ecl_sum , stream , time_index , has_var , var_index , date_string , fmt);
  }

  int_vector_free( var_index );
  bool_vector_free( has_var );
  if (current_locale != NULL)
    setlocale( LC_NUMERIC , current_locale);
  free( date_string );
}
/**
   This function will copy a block starting at index @src_offset in
   the src vector to a block starting at @target_offset in the target
   vector. The target vector will be resized and initialized with
   default values as required.

   If len goes beyond the length of the src vector the function will
   fail hard.
*/
void int_vector_memcpy_data_block( int_vector_type * target , const int_vector_type * src , int target_offset , int src_offset , int len) {
  if ((src_offset + len) > src->size)
    util_abort("%s: offset:%d  blocksize:%d  vector_size:%d - invalid \n",__func__ , src_offset , len , src->size);

  /* Force a resize + default initialisation of the target. */
  if (target->alloc_size < (target_offset + len))
    int_vector_iset( target , target_offset + len - 1 , target->default_value) ;

  /* Copy the content. */
  memcpy( &target->data[target_offset] , &src->data[src_offset] , len * sizeof * src->data );

  /* Update size of target. */
  if (target->size < (target_offset + len))
    target->size = target_offset + len;
}
Example #18
0
File: nnc_info.c Project: 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 ); 
  }
 }
Example #19
0
void gen_data_config_assert_size(gen_data_config_type * config , int data_size, int report_step) {
  pthread_mutex_lock( &config->update_lock );
  {
    int current_size = int_vector_safe_iget( config->data_size_vector , report_step );
    if (current_size < 0) {
      int_vector_iset( config->data_size_vector , report_step , data_size );
      current_size = data_size;
    }
    
    if (current_size != data_size) {
      util_abort("%s: Size mismatch when loading:%s from file - got %d elements - expected:%d [report_step:%d] \n",
                 __func__ , 
                 gen_data_config_get_key( config ),
                 data_size , 
                 current_size , 
                 report_step);
    }
  }
  pthread_mutex_unlock( &config->update_lock );
}
Example #20
0
static void state_map_iset__( state_map_type * map , int index , realisation_state_enum new_state) {
  realisation_state_enum current_state = int_vector_safe_iget( map->state , index );
  int target_mask = 0;

  if (current_state == STATE_UNDEFINED)
    target_mask = STATE_INITIALIZED | STATE_PARENT_FAILURE;
  else if (current_state == STATE_INITIALIZED)
    target_mask = STATE_LOAD_FAILURE | STATE_HAS_DATA | STATE_INITIALIZED | STATE_PARENT_FAILURE;
  else if (current_state == STATE_HAS_DATA)
    target_mask = STATE_LOAD_FAILURE | STATE_HAS_DATA | STATE_PARENT_FAILURE;
  else if (current_state == STATE_LOAD_FAILURE)
    target_mask = STATE_HAS_DATA | STATE_INITIALIZED;
  else if (current_state == STATE_PARENT_FAILURE)
    target_mask = STATE_INITIALIZED;

  if (new_state & target_mask)
    int_vector_iset( map->state , index , new_state);
  else
    util_abort("%s: illegal state transition for realisation:%d %d -> %d \n" , __func__ , index , current_state , new_state );
  
}
Example #21
0
ecl_sum_tstep_type * ecl_sum_data_add_new_tstep( ecl_sum_data_type * data , int report_step , double sim_days) {
  int ministep_nr = vector_get_size( data->data );
  ecl_sum_tstep_type * tstep = ecl_sum_tstep_alloc_new( report_step , ministep_nr , sim_days , data->smspec );
  ecl_sum_tstep_type * prev_tstep = NULL;

  if (vector_get_size( data->data ) > 0)
    prev_tstep = vector_get_last( data->data );
  
  ecl_sum_data_append_tstep__( data , ministep_nr , tstep );
  {
    bool rebuild_index = true;

    /*
      In the simple case that we just add another timestep to the
      currently active report_step, we do a limited update of the
      index, otherwise we call ecl_sum_data_build_index() to get a
      full recalculation of the index.
    */
    
    if (prev_tstep != NULL) {
      if (ecl_sum_tstep_get_report( prev_tstep ) == ecl_sum_tstep_get_report( tstep )) {        // Same report step
        if (ecl_sum_tstep_get_sim_days( prev_tstep ) < ecl_sum_tstep_get_sim_days( tstep )) {   // This tstep will become the new latest tstep
          int internal_index = vector_get_size( data->data ) - 1;
          
          ecl_sum_data_update_end_info( data );
          int_vector_iset( data->report_last_index , report_step , internal_index );
          rebuild_index = false;
        }
      }
    }
    if (rebuild_index)
      ecl_sum_data_build_index( data );
  }
  ecl_smspec_lock( data->smspec );
  
  return tstep;
}
void int_vector_resize( int_vector_type * vector , int new_size ) {
  if (new_size <= vector->size)
    vector->size = new_size;
  else
    int_vector_iset( vector , new_size - 1 , vector->default_value);
}
Example #23
0
static void validate_iset_type( validate_type * validate , int index , config_item_types type) {
  int_vector_iset( validate->type_map , index , type);
}
Example #24
0
void bootstrap_enkf_updateA(void * module_data ,
                            matrix_type * A ,
                            matrix_type * S ,
                            matrix_type * R ,
                            matrix_type * dObs ,
                            matrix_type * E ,
                            matrix_type * D ) {

    bootstrap_enkf_data_type * bootstrap_data = bootstrap_enkf_data_safe_cast( module_data );
    {
        const int num_cpu_threads = 4;
        int ens_size              = matrix_get_columns( A );
        matrix_type * X           = matrix_alloc( ens_size , ens_size );
        matrix_type * A0          = matrix_alloc_copy( A );
        matrix_type * S_resampled = matrix_alloc_copy( S );
        matrix_type * A_resampled = matrix_alloc( matrix_get_rows(A0) , matrix_get_columns( A0 ));
        int ** iens_resample      = alloc_iens_resample( bootstrap_data->rng , ens_size );
        {
            int ensemble_members_loop;
            for ( ensemble_members_loop = 0; ensemble_members_loop < ens_size; ensemble_members_loop++) {
                int unique_bootstrap_components;
                int ensemble_counter;
                /* Resample A and meas_data. Here we are careful to resample the working copy.*/
                {
                    {
                        int_vector_type * bootstrap_components = int_vector_alloc( ens_size , 0);
                        for (ensemble_counter  = 0; ensemble_counter < ens_size; ensemble_counter++) {
                            int random_column = iens_resample[ ensemble_members_loop][ensemble_counter];
                            int_vector_iset( bootstrap_components , ensemble_counter , random_column );
                            matrix_copy_column( A_resampled , A0 , ensemble_counter , random_column );
                            matrix_copy_column( S_resampled , S  , ensemble_counter , random_column );
                        }
                        int_vector_select_unique( bootstrap_components );
                        unique_bootstrap_components = int_vector_size( bootstrap_components );
                        int_vector_free( bootstrap_components );
                    }

                    if (bootstrap_data->doCV) {
                        const bool_vector_type * ens_mask = NULL;
                        cv_enkf_init_update( bootstrap_data->cv_enkf_data , ens_mask , S_resampled , R , dObs , E , D);
                        cv_enkf_initX( bootstrap_data->cv_enkf_data , X , A_resampled , S_resampled , R , dObs , E , D);
                    } else
                        std_enkf_initX(bootstrap_data->std_enkf_data , X , NULL , S_resampled,R, dObs, E,D );


                    matrix_inplace_matmul_mt1( A_resampled , X , num_cpu_threads );
                    matrix_inplace_add( A_resampled , A0 );
                    matrix_copy_column( A , A_resampled, ensemble_members_loop, ensemble_members_loop);

                }
            }
        }


        free_iens_resample( iens_resample , ens_size);
        matrix_free( X );
        matrix_free( S_resampled );
        matrix_free( A_resampled );
        matrix_free( A0 );
    }
}
void int_vector_append(int_vector_type * vector , int value) {
  int_vector_iset(vector , vector->size , value);
}
void int_vector_iset_default(int_vector_type * vector , int index , int default_value) {
  int_vector_iset( vector , index , default_value );
  int_vector_set_default( vector , default_value );
}
int int_vector_iadd( int_vector_type * vector , int index , int delta) {
  int new_value     = int_vector_safe_iget(vector , index ) + delta;
  int_vector_iset( vector , index , new_value );
  return new_value;
}
void int_vector_iset_block(int_vector_type * vector , int index , int block_size , int value) {
  int sign = (block_size > 0) ? 1 : -1 ;
  int c;
  for (c=0; c < abs(block_size); c++)
    int_vector_iset( vector , index + c * sign , value);
}
int main(int argc , char ** argv) {
  
  int_vector_type * int_vector = int_vector_alloc( 0 , 99);
  
  int_vector_iset( int_vector , 2 , 0);       
  int_vector_insert( int_vector , 2 , 77 );   
  int_vector_iset( int_vector , 5 , -10);     
  
  int_vector_fprintf( int_vector , stdout , "int_vector" , "%3d");
  assert_equal( int_vector_iget(int_vector , 0 ) == 99 );
  assert_equal( int_vector_iget(int_vector , 1 ) == 99 );
  assert_equal( int_vector_iget(int_vector , 2 ) == 77 );
  assert_equal( int_vector_iget(int_vector , 3 ) == 00 );
  assert_equal( int_vector_iget(int_vector , 4 ) == 99 );
  assert_equal( int_vector_iget(int_vector , 5 ) == -10 );
  
  {
    int N1 = 100000;
    int N2 = 10*N1;
    int_vector_type * v1 = int_vector_alloc( N1 , 0 );
    int_vector_type * v2;
    int * data1 = int_vector_get_ptr( v1 );
    int_vector_iset( v1 , N1 - 1, 99);

    int_vector_free_container( v1 );
    v2 = int_vector_alloc( N2 , 0 );
    int_vector_iset(v2 , N2 - 1, 77 );
    
    test_assert_int_equal(  data1[N1-1] , 99);
    int_vector_free( v2 );
    free( data1 );
  }                 
  
  
  test_assert_true( int_vector_init_range( int_vector , 100 , 1000 , 115 ) );
  test_assert_int_equal( int_vector_iget( int_vector , 0 ) , 100);
  test_assert_int_equal( int_vector_iget( int_vector , 1 ) , 215);
  test_assert_int_equal( int_vector_iget( int_vector , 2 ) , 330);
  test_assert_int_equal( int_vector_iget( int_vector , 3 ) , 445);
  test_assert_int_equal( int_vector_get_last( int_vector ) , 1000);
  
  test_assert_false( int_vector_init_range( int_vector , 100 , -1000 , 115 ) );
  test_assert_int_equal( int_vector_iget( int_vector , 0 ) , 100);
  test_assert_int_equal( int_vector_iget( int_vector , 1 ) , 215);
  test_assert_int_equal( int_vector_iget( int_vector , 2 ) , 330);
  test_assert_int_equal( int_vector_iget( int_vector , 3 ) , 445);
  test_assert_int_equal( int_vector_get_last( int_vector ) , 1000);

  {
    int_vector_type * v1 = int_vector_alloc(0,0);
    int_vector_type * v2 = int_vector_alloc(0,0);
    int_vector_append(v1 , 10);
    int_vector_append(v1 , 15);
    int_vector_append(v1 , 20);

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

    int_vector_append_vector( v1 , v2 );
    test_assert_int_equal( int_vector_size( v1 ) , 6 );
    test_assert_int_equal( int_vector_iget (v1 ,  0 ), 10 );
    test_assert_int_equal( int_vector_iget (v1 ,  1 ), 15 );
    test_assert_int_equal( int_vector_iget (v1 ,  2 ), 20 );
                                                               
    test_assert_int_equal( int_vector_iget (v1 ,  3 ), 1 );
    test_assert_int_equal( int_vector_iget (v1 ,  4 ), 2 );
    test_assert_int_equal( int_vector_iget (v1 ,  5 ), 3 );

    int_vector_free( v1 );
    int_vector_free( v2 );
  }
  
  exit(0);
}
void int_vector_memcpy_from_data( int_vector_type * target , const int * src , int src_size ) {
  int_vector_reset( target );
  int_vector_iset( target , src_size - 1 , 0 );
  memcpy( target->data , src , src_size * sizeof * target->data );
}