void test_time_range( const ecl_sum_type * ecl_sum ) { // Hardcoded Gurbat case values time_t start = util_make_date( 1,1,2000); time_t end = util_make_date( 31,12,2004 ); test_assert_time_t_equal( ecl_sum_get_start_time( ecl_sum ) , start ); test_assert_time_t_equal( ecl_sum_get_end_time( ecl_sum ) , end ); test_assert_time_t_equal( ecl_sum_get_data_start(ecl_sum) , start); }
void test_days( const ecl_sum_type * ecl_sum ) { time_t date1 = util_make_date( 1,1,2000); time_t date2 = util_make_date( 31,12,2004 ); time_t date3 = util_make_date( 2,1,2000 ); double days1 = ecl_sum_time2days( ecl_sum , date1 ); double days2 = ecl_sum_time2days( ecl_sum , date2); double days3 = ecl_sum_time2days( ecl_sum , date3 ); test_assert_double_equal( days1 , 0 ); test_assert_double_equal( days2 , 1826 ); test_assert_double_equal( days3 , 1 ); }
void test_offset(int mday, int month , int year , int current_offset) { int year_offset; time_t t0 = ecl_util_make_date__( mday , month , year , &year_offset); time_t t1 = util_make_date( mday , month , year + current_offset); test_assert_time_t_equal(t0,t1); test_assert_int_equal( current_offset , year_offset ); }
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 ); }
time_t ecl_util_make_date__(int mday , int month , int year, int * __year_offset) { time_t date; #ifdef TIME_T_64BIT_ACCEPT_PRE1970 *__year_offset = 0; date = util_make_date(mday , month , year); #else static bool offset_initialized = false; static int year_offset = 0; if (!offset_initialized) { if (year < 1970) { year_offset = 2000 - year; fprintf(stderr,"Warning: all year values will be shifted %d years forward. \n", year_offset); } offset_initialized = true; } *__year_offset = year_offset; date = util_make_date(mday , month , year + year_offset); #endif return date; }
void test_date(int mday, int month , int year, int * year_offset) { time_t t0 = ecl_util_make_date__( mday , month , year , year_offset); time_t t1 = util_make_date( mday , month , year + *year_offset); test_assert_time_t_equal( t0 , t1 ); }