Exemple #1
0
void test_fread_truncated_tail() {
  test_work_area_type * work_area = test_work_area_alloc("fortio_truncated2" );
  {
    const size_t buffer_size = 1000;
    void * buffer = util_malloc( buffer_size );
    {
      fortio_type * fortio = fortio_open_writer( "PRESSURE" , false , true );

      fortio_fwrite_record( fortio , buffer , buffer_size );
      fortio_fseek( fortio , 0 , SEEK_SET);
      util_ftruncate( fortio_get_FILE(fortio) , buffer_size + 4);
      fortio_fclose( fortio );
    }

    test_assert_long_equal( util_file_size( "PRESSURE") , buffer_size + 4);

    {
      fortio_type * fortio = fortio_open_reader( "PRESSURE" , false , true );
      test_assert_false( fortio_fread_buffer( fortio , buffer , buffer_size ));
      fortio_fclose( fortio );
    }
    free( buffer );
  }
  test_work_area_free( work_area );
}
Exemple #2
0
void test_truncated() {
  test_work_area_type * work_area = test_work_area_alloc("ecl_file_truncated" );
  {
    ecl_grid_type * grid = ecl_grid_alloc_rectangular(20,20,20,1,1,1,NULL);
    ecl_grid_fwrite_EGRID2( grid , "TEST.EGRID", ECL_METRIC_UNITS );
    ecl_grid_free( grid );
  }
  {
    ecl_file_type * ecl_file = ecl_file_open("TEST.EGRID" , 0 );
    test_assert_true( ecl_file_is_instance( ecl_file ) );
    ecl_file_close( ecl_file );
  }

  {
    offset_type file_size = util_file_size( "TEST.EGRID");
    FILE * stream = util_fopen("TEST.EGRID" , "r+");
    util_ftruncate( stream , file_size / 2 );
    fclose( stream );
  }
  {
    ecl_file_type * ecl_file = ecl_file_open("TEST.EGRID" , 0 );
    test_assert_NULL( ecl_file );
  }
  test_work_area_free( work_area );
}
Exemple #3
0
static void ecl_sum_data_fwrite_unified_step( const ecl_sum_data_type * data , const char * ecl_case , bool fmt_case , int report_step) {
  char * filename = ecl_util_alloc_filename( NULL , ecl_case , ECL_UNIFIED_SUMMARY_FILE , fmt_case , 0 );
  fortio_type * fortio = fortio_open_readwrite( filename , fmt_case , ECL_ENDIAN_FLIP );
  
  int current_step = 1;
  if (report_step > 1) {
    while (true) {
      if (ecl_kw_fseek_kw( SEQHDR_KW , false , false , fortio )) {
        if (current_step == report_step)
          break;
        current_step++;
      } else {
        current_step++;
        break;
      }
    }
  }
  
  if (current_step == report_step) { // We found the position:
    long size = fortio_ftell( fortio );
    
    util_ftruncate( fortio_get_FILE( fortio ) , size );
    ecl_sum_data_fwrite_report__( data , report_step , fortio );
  } else
    util_abort("%s: hmm could not locate the position for report step:%d in summary file:%s \n",__func__ , report_step , filename);
  
  fortio_fclose( fortio );
  free( filename );
}
Exemple #4
0
void test_truncated(const char * filename , offset_type truncate_size) {
  {
    FILE * stream = util_fopen(filename , "r+");
    util_ftruncate( stream , truncate_size);
    fclose( stream );
  }
  {
    fortio_type * fortio = fortio_open_reader( filename , false , true );
    ecl_kw_type * kw2 = ecl_kw_fread_alloc( fortio );
    test_assert_NULL( kw2 );
    fortio_fclose(fortio);
  }
}