Exemple #1
0
void test_fread_alloc() {
  test_work_area_type * work_area = test_work_area_alloc("ecl_kw_fread" );
  {
    ecl_kw_type * kw1 = ecl_kw_alloc( "INT" , 100 , ECL_INT );
    int i;
    for (i=0; i < 100; i++)
      ecl_kw_iset_int( kw1 , i , i );
    {
      fortio_type * fortio = fortio_open_writer("INT" , false , true );
      ecl_kw_fwrite( kw1 , fortio );
      fortio_fclose( fortio );
    }
    {
      fortio_type * fortio = fortio_open_reader("INT" , false , true );
      ecl_kw_type * kw2 = ecl_kw_fread_alloc( fortio );
      test_assert_true( ecl_kw_is_instance( kw2 ));
      test_assert_true( ecl_kw_equal( kw1 , kw2 ));
      ecl_kw_free( kw2 );
      fortio_fclose( fortio );
    }

    {
      offset_type file_size = util_file_size("INT");
      test_truncated("INT" , file_size - 4 );
      test_truncated("INT" , file_size - 25 );
      test_truncated("INT" , 5 );
      test_truncated("INT" , 0 );
    }
    ecl_kw_free( kw1 );
  }
  test_work_area_free( work_area );
}
Exemple #2
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 );
}
Exemple #3
0
int main(int argc , char ** argv) {  
  int i;
  ecl_kw_type * ecl_kw = ecl_kw_alloc("HEAD" , 10  , ECL_INT_TYPE);

  for (i=0; i < 10; i++) 
    ecl_kw_iset_int(ecl_kw , i , i );

  {
    test_work_area_type * work_area = test_work_area_alloc("ecl_kw_grdecl" , true);
    FILE * stream = util_fopen( "FILE.grdecl" , "w");

    ecl_kw_fprintf_grdecl(ecl_kw , stream );
    fclose(stream);
    
    stream = util_fopen( "FILE.grdecl" , "r");
    {
      ecl_kw_type * ecl_kw2 = ecl_kw_fscanf_alloc_grdecl( stream , "HEAD" , 10 , ECL_INT_TYPE);
      
      test_assert_not_NULL( ecl_kw2 );
      test_assert_true( ecl_kw_equal( ecl_kw , ecl_kw2));
      ecl_kw_free( ecl_kw2 );
    }
    fclose( stream );

    stream = util_fopen( "FILE.grdecl" , "w");
    ecl_kw_fprintf_grdecl__(ecl_kw , "HEAD1234" , stream );
    fclose( stream );

    stream = util_fopen( "FILE.grdecl" , "r");
    {
      ecl_kw_type * ecl_kw2 = ecl_kw_fscanf_alloc_grdecl( stream , "HEAD" , 10 , ECL_INT_TYPE);
      
      test_assert_NULL( ecl_kw2 );
      ecl_kw2 = ecl_kw_fscanf_alloc_grdecl( stream , "HEAD1234" , 10 , ECL_INT_TYPE);
      test_assert_not_NULL( ecl_kw2 );
      
      test_assert_string_equal( ecl_kw_get_header( ecl_kw2 ) , "HEAD1234" );
      test_assert_true( ecl_kw_content_equal( ecl_kw , ecl_kw2 ));
      ecl_kw_free( ecl_kw2 );
    }
    fclose( stream );
    test_work_area_free( work_area );
  }
  ecl_kw_free( ecl_kw );
  
  exit(0);
}
Exemple #4
0
void test_writable(const char * src_file ) {
  test_work_area_type * work_area = test_work_area_alloc("ecl_file_writable" );
  char * fname = util_split_alloc_filename( src_file );

  test_work_area_copy_file( work_area , src_file );
  {
    ecl_file_type * ecl_file = ecl_file_open( fname , ECL_FILE_WRITABLE);
    ecl_kw_type * swat = ecl_file_iget_named_kw( ecl_file , "SWAT" , 0 );
    ecl_kw_type * swat0 = ecl_kw_alloc_copy( swat );
    test_assert_true( ecl_kw_equal( swat , swat0 ));
    ecl_kw_iset_float( swat , 0 , 1000.0 );
    ecl_file_save_kw( ecl_file , swat );
    test_assert_true( ecl_file_writable( ecl_file ));
    ecl_file_close( ecl_file );

    ecl_file = ecl_file_open( fname , 0);
    swat = ecl_file_iget_named_kw( ecl_file , "SWAT" , 0 );
    test_assert_true( util_double_approx_equal( ecl_kw_iget_float( swat , 0 ) , 1000 ));
  }
  test_work_area_free( work_area );
}
Exemple #5
0
int main( int argc , char ** argv) {
    int num_kw  = 1000;       // Total file size should roughly exceed 2GB
    int kw_size = 600000;
    ecl_kw_type * kw = ecl_kw_alloc("KW" , kw_size , ECL_INT_TYPE );
    rng_type * rng = rng_alloc( MZRAN , INIT_DEFAULT );
    int i;
    offset_type file_size;
    for (i=0; i < kw_size; i++)
        ecl_kw_iset_int( kw , i , rng_get_int( rng , 912732 ));

    {
        fortio_type * fortio = fortio_open_writer( "LARGE_FILE.UNRST" , false , ECL_ENDIAN_FLIP);
        for (i = 0; i < num_kw; i++) {
            printf("Writing keyword %d/%d to file:LARGE_FILE.UNRST \n",i+1 , num_kw );
            ecl_kw_fwrite( kw , fortio );
        }
        fortio_fclose( fortio );
    }

    /*{
      fortio_type * fortio = fortio_open_reader( "LARGE_FILE.UNRST" , false , ECL_ENDIAN_FLIP);
      for (i = 0; i < num_kw - 1; i++) {
         printf("SKipping keyword %d/%d from file:LARGE_FILE.UNRST \n",i+1 , num_kw );
         ecl_kw_fskip( fortio );
      }
      {
         ecl_kw_type * file_kw = ecl_kw_fread_alloc( fortio );
         if (ecl_kw_equal( kw , file_kw ))
            printf("Keyword read back from file correctly :-) \n");
          else
            printf("Fatal error - keyword different on return ...\n");
         ecl_kw_free( file_kw );
      }
      fortio_fclose( fortio );
    }
    */
    file_size = util_file_size( "LARGE_FILE.UNRST" );
    printf("File size: %lld \n",file_size);
    {
        fortio_type * fortio = fortio_open_reader( "LARGE_FILE.UNRST" , false , ECL_ENDIAN_FLIP);
        printf("Seeking to file end: ");
        fortio_fseek( fortio , file_size , SEEK_SET);
        fortio_fclose( fortio );
        printf("Seek OK \n");
    }


    printf("Doing ecl_file_open(..)\n");
    {
        ecl_file_type * file = ecl_file_open( "LARGE_FILE.UNRST" , 0);
        ecl_kw_type * file_kw = ecl_file_iget_named_kw( file , "KW" , num_kw - 1);
        if (ecl_kw_equal( kw , file_kw ))
            printf("Keyword read back from file correctly :-) \n");
        else
            printf("Fatal error - keyword different on return ...\n");
        ecl_file_close( file );
    }

    remove( "LARGE_FILE.UNRST" );

    exit(0);
}