void test_approx_equal() {
  double_vector_type * d1 = double_vector_alloc(0,0);
  double_vector_type * d2 = double_vector_alloc(0,0);
  double_vector_type * d3 = double_vector_alloc(0,0);

  double_vector_append( d1 , 1.0 );
  double_vector_append( d1 , 2.0 );
  double_vector_append( d1 , 3.0 );


  double_vector_append( d2 , 1.0 );
  double_vector_append( d2 , 2.0 );

  test_assert_false( double_vector_approx_equal( d1 , d2 ,1e-6));

  double_vector_append( d2 , 3.0 );
  test_assert_true( double_vector_approx_equal( d1 , d2 ,1e-6));
  
  double_vector_append( d3 , 1.0 );
  double_vector_append( d3 , 2.0 );
  double_vector_append( d3 , 3.0 );

  double_vector_scale( d3 , 1 + 1e-6 );
  test_assert_true( double_vector_approx_equal( d1 , d3 ,1e-4));
  test_assert_false( double_vector_approx_equal( d1 , d3 ,1e-8));


  double_vector_free(d1);
  double_vector_free(d2);
  double_vector_free(d3);
}
示例#2
0
void ecl_sum_data_init_data_vector( const ecl_sum_data_type * data , double_vector_type * data_vector , int data_index , bool report_only) {
  double_vector_reset( data_vector );
  double_vector_append( data_vector , ecl_smspec_get_start_time( data->smspec ));
  if (report_only) {
    int report_step;
    for (report_step = data->first_report_step; report_step <= data->last_report_step; report_step++) {
      int last_index = int_vector_iget(data->report_last_index , report_step);
      const ecl_sum_tstep_type * ministep = ecl_sum_data_iget_ministep( data , last_index );
      double_vector_append( data_vector , ecl_sum_tstep_iget( ministep , data_index ));
    }
  } else {
    int i;
    for (i = 0; i < vector_get_size(data->data); i++) {
      const ecl_sum_tstep_type * ministep = ecl_sum_data_iget_ministep( data , i  );
      double_vector_append( data_vector , ecl_sum_tstep_iget( ministep , data_index ));
    }
  }
}
void test_insert_double() {
  double_vector_type * vec = double_vector_alloc(0,0);
  double_vector_append( vec , 1 );
  double_vector_insert( vec , 0 , 0 );
  
  test_assert_double_equal( 0 , double_vector_iget( vec , 0 ));
  test_assert_double_equal( 1 , double_vector_iget( vec , 1 ));
  
  double_vector_free( vec );
}
示例#4
0
void test_update_vector() {
  plot_range_type * range = plot_range_alloc();
  double_vector_type * xl = double_vector_alloc(0,0);
  double_vector_type * yl = double_vector_alloc(0,0);
  const int N = 100;
  int i;

  for (i=0; i < N; i++) {
    double x = 2*3.14159265 * i / (N - 1);
    
    double_vector_append( xl , sin(x));
    double_vector_append( yl , cos(x));
  }
  plot_range_update_vector( range , xl , yl );

  test_assert_double_equal( plot_range_get_current_xmin( range ) , -1 );
  test_assert_double_equal( plot_range_get_current_xmax( range ) ,  1 );
  test_assert_double_equal( plot_range_get_current_ymin( range ) , -1 );
  test_assert_double_equal( plot_range_get_current_ymax( range ) ,  1 );
  
  for (i=0; i < N; i++) {
    double x = 2*3.14159265 * i / (N - 1);
    
    double_vector_append( xl , 2*sin(x));
    double_vector_append( yl , 2*cos(x));
  }
  plot_range_update_vector_x( range , xl );
  plot_range_update_vector_y( range , yl );

  test_assert_double_equal( plot_range_get_current_xmin( range ) , -2 );
  test_assert_double_equal( plot_range_get_current_xmax( range ) ,  2 );
  test_assert_double_equal( plot_range_get_current_ymin( range ) , -2 );
  test_assert_double_equal( plot_range_get_current_ymax( range ) ,  2 );

  plot_range_free( range );
  double_vector_free( xl );
  double_vector_free( yl );
}
示例#5
0
文件: gen_data.c 项目: Ensembles/ert
void gen_data_copy_to_double_vector(const gen_data_type * gen_data , double_vector_type * vector){
    const ecl_data_type internal_type = gen_data_config_get_internal_data_type(gen_data->config);
    int size = gen_data_get_size( gen_data );
    if (ecl_type_is_float(internal_type)) {
      float * data       = (float *) gen_data->data;
      double_vector_reset(vector);
      for (int i = 0; i < size; i++){
        double_vector_append(vector , data[i]);
      }
    } else if (ecl_type_is_double(internal_type)) {
      double * data       = (double *) gen_data->data;
      double_vector_memcpy_from_data( vector , data , size );
    }


}
示例#6
0
void output_run_line( const output_type * output , ensemble_type * ensemble) {

  const int    data_columns = vector_get_size( output->keys );
  const int    data_rows    = time_t_vector_size( ensemble->interp_time );
  double     ** data;
  int row_nr, column_nr;

  data = util_calloc( data_rows , sizeof * data );
  /*
    time-direction, i.e. the row index is the first index and the
    column number (i.e. the different keys) is the second index.
  */
  for (row_nr=0; row_nr < data_rows; row_nr++)
    data[row_nr] = util_calloc( data_columns , sizeof * data[row_nr] );

  printf("Creating output file: %s \n",output->file );


  /*
     Go through all the cases and check that they have this key;
     exit if missing. Could also ignore the missing keys and just
     continue; and even defer the checking to the inner loop.
  */
  for (column_nr = 0; column_nr < vector_get_size( output->keys ); column_nr++) {
    const quant_key_type * qkey = vector_iget( output->keys , column_nr );
    {
      bool OK = true;

      for (int iens = 0; iens < vector_get_size( ensemble->data ); iens++) {
        const sum_case_type * sum_case = vector_iget_const( ensemble->data , iens );

        if (!ecl_sum_has_general_var(sum_case->ecl_sum , qkey->sum_key)) {
          OK = false;
          fprintf(stderr,"** Sorry: the case:%s does not have the summary key:%s \n", ecl_sum_get_case( sum_case->ecl_sum ), qkey->sum_key);
        }
      }

      if (!OK)
        util_exit("Exiting due to missing summary vector(s).\n");
    }
  }


  /* The main loop - outer loop is running over time. */
  {
    /**
       In the quite typical case that we are asking for several
       quantiles of the quantity, i.e.

       WWCT:OP_1:0.10  WWCT:OP_1:0.50  WWCT:OP_1:0.90

       the interp_data_cache construction will ensure that the
       underlying ecl_sum object is only queried once; and also the
       sorting will be performed once.
    */

    hash_type * interp_data_cache = hash_alloc();

    for (row_nr = 0; row_nr < data_rows; row_nr++) {
      time_t interp_time = time_t_vector_iget( ensemble->interp_time , row_nr);
      for (column_nr = 0; column_nr < vector_get_size( output->keys ); column_nr++) {
        const quant_key_type * qkey = vector_iget( output->keys , column_nr );
        double_vector_type * interp_data;

        /* Check if we have the vector in the cache table - if not create it. */
        if (!hash_has_key( interp_data_cache , qkey->sum_key)) {
          interp_data = double_vector_alloc(0 , 0);
          hash_insert_hash_owned_ref( interp_data_cache , qkey->sum_key , interp_data , double_vector_free__);
        }
        interp_data = hash_get( interp_data_cache , qkey->sum_key );

        /* Check if the vector has data - if not initialize it. */
        if (double_vector_size( interp_data ) == 0) {
          for (int iens = 0; iens < vector_get_size( ensemble->data ); iens++) {
            const sum_case_type * sum_case = vector_iget_const( ensemble->data , iens );

            if ((interp_time >= sum_case->start_time) && (interp_time <= sum_case->end_time))  /* We allow the different simulations to have differing length */
              double_vector_append( interp_data , ecl_sum_get_general_var_from_sim_time( sum_case->ecl_sum , interp_time , qkey->sum_key)) ;

            double_vector_sort( interp_data );
          }
        }
        data[row_nr][column_nr] = statistics_empirical_quantile__( interp_data , qkey->quantile );
      }
      hash_apply( interp_data_cache , double_vector_reset__ );
    }
    hash_free( interp_data_cache );
  }

  output_save( output , ensemble , (const double **) data);
  for (row_nr=0; row_nr < data_rows; row_nr++)
    free( data[row_nr] );
  free( data );
}
示例#7
0
void geo_polygon_add_point( geo_polygon_type * polygon , double x , double y) {
  double_vector_append( polygon->xcoord , x );
  double_vector_append( polygon->ycoord , y );
}