Example #1
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 );
}
Example #2
0
int state_map_count_matching( state_map_type * state_map , int mask) {
   int count = 0;
   pthread_rwlock_rdlock( &state_map->rw_lock );
   {
     const int * map_ptr = int_vector_get_ptr(state_map->state);
     for (int i=0; i < int_vector_size( state_map->state ); i++) {
       int state_value = map_ptr[i];
       if (state_value & mask)
         count++;
     }
   }
   pthread_rwlock_unlock(&state_map->rw_lock);
   return count;
 }
Example #3
0
static void state_map_select_matching__( state_map_type * map , bool_vector_type * select_target , int select_mask , bool select) {
  pthread_rwlock_rdlock( &map->rw_lock );
  {
    {
      const int * map_ptr = int_vector_get_ptr( map->state );

      for (int i=0; i < int_vector_size( map->state ); i++) {
        int state_value = map_ptr[i];
        if (state_value & select_mask) 
          bool_vector_iset( select_target , i , select);
      }
    }
    pthread_rwlock_unlock( &map->rw_lock );
  }
}
Example #4
0
void ecl_sum_tstep_fwrite( const ecl_sum_tstep_type * ministep , const int_vector_type * index_map , fortio_type * fortio) {
  {
    ecl_kw_type * ministep_kw = ecl_kw_alloc( MINISTEP_KW , 1 , ECL_INT_TYPE );
    ecl_kw_iset_int( ministep_kw , 0 , ministep->ministep );
    ecl_kw_fwrite( ministep_kw , fortio );
    ecl_kw_free( ministep_kw );
  }

  {
    int compact_size = int_vector_size( index_map );
    ecl_kw_type * params_kw = ecl_kw_alloc( PARAMS_KW , compact_size , ECL_FLOAT_TYPE );

    const int * index = int_vector_get_ptr( index_map );
    float * data      = ecl_kw_get_ptr( params_kw );

    {
      int i;
      for (i=0; i < compact_size; i++)
        data[i] = ministep->data[ index[i] ];
    }
    ecl_kw_fwrite( params_kw , fortio );
    ecl_kw_free( params_kw );
  }
}
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);
}
int main(int argc , char ** argv) {
  
  int_vector_type * int_vector = int_vector_alloc( 0 , 99);
  
  test_abort();
  test_assert_int_equal( -1 , int_vector_index(int_vector , 100));
  test_assert_int_equal( -1 , int_vector_index_sorted(int_vector , 100));

  test_assert_true( int_vector_is_instance( int_vector ));
  test_assert_false( double_vector_is_instance( int_vector ));
  int_vector_iset( int_vector , 2 , 0);       
  int_vector_insert( int_vector , 2 , 77 );   
  int_vector_iset( int_vector , 5 , -10);     
  
  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 );
  }
  test_contains();
  test_contains_sorted();
  test_shift();
  test_alloc();
  test_div();
  test_memcpy_from_data();
  test_idel_insert();
  test_del();
  test_range_fill();
  test_iset_block();
  test_resize();
  test_empty();
  test_insert_double();
  exit(0);
}