From d9f2dc330b1b9a13ba299f703dbfe3b8e6bb7abc Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Thu, 1 Aug 2019 14:55:09 +0200 Subject: [PATCH] Use six elements from summary STARTDAT keyword --- lib/ecl/ecl_smspec.cpp | 25 +++++++++++++++++++------ lib/ecl/ecl_util.cpp | 21 ++++++++++++++++++--- lib/include/ert/ecl/ecl_kw_magic.hpp | 11 +++++++---- lib/include/ert/ecl/ecl_util.hpp | 2 ++ 4 files changed, 46 insertions(+), 13 deletions(-) diff --git a/lib/ecl/ecl_smspec.cpp b/lib/ecl/ecl_smspec.cpp index 7facbcf9db..920bddbfdc 100644 --- a/lib/ecl/ecl_smspec.cpp +++ b/lib/ecl/ecl_smspec.cpp @@ -425,12 +425,15 @@ static void ecl_smspec_fwrite_DIMENS(const ecl_smspec_type * smspec, fortio_type static void ecl_smspec_fwrite_STARTDAT(const ecl_smspec_type * smspec, fortio_type * fortio) { ecl_kw_type * startdat_kw = ecl_kw_alloc( STARTDAT_KW , STARTDAT_SIZE , ECL_INT ); - int day,month,year; - ecl_util_set_date_values( smspec->sim_start_time , &day, &month , &year); + int second,minute,hour,mday,month,year; + ecl_util_set_datetime_values(smspec->sim_start_time, &second, &minute, &hour, &mday,&month,&year); - ecl_kw_iset_int( startdat_kw , STARTDAT_DAY_INDEX , day ); + ecl_kw_iset_int( startdat_kw , STARTDAT_DAY_INDEX , mday ); ecl_kw_iset_int( startdat_kw , STARTDAT_MONTH_INDEX , month ); ecl_kw_iset_int( startdat_kw , STARTDAT_YEAR_INDEX , year ); + ecl_kw_iset_int( startdat_kw , STARTDAT_HOUR_INDEX , hour ); + ecl_kw_iset_int( startdat_kw , STARTDAT_MINUTE_INDEX , minute ); + ecl_kw_iset_int( startdat_kw , STARTDAT_MICRO_SECOND_INDEX , second * 1000000); ecl_kw_fwrite( startdat_kw , fortio ); ecl_kw_free( startdat_kw ); @@ -1118,9 +1121,19 @@ static bool ecl_smspec_fread_header(ecl_smspec_type * ecl_smspec, const char * h { int * date = ecl_kw_get_int_ptr(startdat); - ecl_smspec->sim_start_time = ecl_util_make_date(date[STARTDAT_DAY_INDEX] , - date[STARTDAT_MONTH_INDEX] , - date[STARTDAT_YEAR_INDEX]); + int year = date[STARTDAT_YEAR_INDEX]; + int month = date[STARTDAT_MONTH_INDEX]; + int day = date[STARTDAT_DAY_INDEX]; + int hour = 0; + int min = 0; + int sec = 0; + if (ecl_kw_get_size(startdat) == 6) { + hour = date[STARTDAT_HOUR_INDEX]; + min = date[STARTDAT_MINUTE_INDEX]; + sec = date[STARTDAT_MICRO_SECOND_INDEX] / 1000000; + } + + ecl_smspec->sim_start_time = ecl_util_make_datetime(sec, min, hour, day, month, year); } ecl_smspec->grid_dims[0] = ecl_kw_iget_int(dimens , DIMENS_SMSPEC_NX_INDEX ); diff --git a/lib/ecl/ecl_util.cpp b/lib/ecl/ecl_util.cpp index f0ddca45dd..779208420e 100644 --- a/lib/ecl/ecl_util.cpp +++ b/lib/ecl/ecl_util.cpp @@ -1465,8 +1465,8 @@ void ecl_util_init_month_range( time_t_vector_type * date_list , time_t start_da -time_t ecl_util_make_date__(int mday , int month , int year, int * __year_offset) { -time_t date; +static time_t ecl_util_make_datetime__(int sec, int min, int hour, int mday , int month , int year, int * __year_offset) { + time_t date; #ifdef ERT_TIME_T_64BIT_ACCEPT_PRE1970 *__year_offset = 0; @@ -1483,12 +1483,16 @@ time_t date; offset_initialized = true; } *__year_offset = year_offset; - date = util_make_date_utc(mday , month , year + year_offset); + date = util_make_datetime_utc(sec, min, hour, mday , month , year + year_offset); #endif return date; } +time_t ecl_util_make_date__(int mday , int month , int year, int * __year_offset) { + return ecl_util_make_datetime__(0,0,0,mday, month, year, __year_offset); +} + time_t ecl_util_make_date(int mday , int month , int year) { int year_offset; @@ -1496,11 +1500,22 @@ time_t ecl_util_make_date(int mday , int month , int year) { } +time_t ecl_util_make_datetime(int sec, int min, int hour, int mday , int month , int year) { + int year_offset; + return ecl_util_make_datetime__( sec, min, hour, mday , month , year , &year_offset); +} + void ecl_util_set_date_values(time_t t , int * mday , int * month , int * year) { return util_set_date_values_utc(t,mday,month,year); } +void ecl_util_set_datetime_values(time_t t , int * sec, int * min, int * hour, int * mday , int * month , int * year) { + return util_set_date_values_utc(t,mday,month,year); +} + + + #ifdef ERT_HAVE_UNISTD #include diff --git a/lib/include/ert/ecl/ecl_kw_magic.hpp b/lib/include/ert/ecl/ecl_kw_magic.hpp index 02dab28681..04ff5b57d6 100644 --- a/lib/include/ert/ecl/ecl_kw_magic.hpp +++ b/lib/include/ert/ecl/ecl_kw_magic.hpp @@ -443,10 +443,13 @@ values (2e20) are denoted with '*'. /* Magic indices used to locate day,month,year from the STARTDAT keyword. */ -#define STARTDAT_DAY_INDEX 0 -#define STARTDAT_MONTH_INDEX 1 -#define STARTDAT_YEAR_INDEX 2 -#define STARTDAT_SIZE 3 +#define STARTDAT_DAY_INDEX 0 +#define STARTDAT_MONTH_INDEX 1 +#define STARTDAT_YEAR_INDEX 2 +#define STARTDAT_HOUR_INDEX 3 +#define STARTDAT_MINUTE_INDEX 4 +#define STARTDAT_MICRO_SECOND_INDEX 5 +#define STARTDAT_SIZE 6 /* Magic indices uset to locate the grid dimensions from the DIMENS diff --git a/lib/include/ert/ecl/ecl_util.hpp b/lib/include/ert/ecl/ecl_util.hpp index 590068d135..bf09078cc2 100644 --- a/lib/include/ert/ecl/ecl_util.hpp +++ b/lib/include/ert/ecl/ecl_util.hpp @@ -134,6 +134,7 @@ int ecl_util_get_month_nr(const char * month_name); int ecl_util_fname_report_cmp(const void *f1, const void *f2); time_t ecl_util_make_date(int mday , int month , int year); time_t ecl_util_make_date__(int mday , int month , int year, int * year_offset); +time_t ecl_util_make_datetime(int sec, int min, int hour, int mday , int month , int year); ert_ecl_unit_enum ecl_util_get_unit_set(const char * data_file); bool ecl_util_valid_basename_fmt( const char * basename_fmt ); @@ -144,6 +145,7 @@ int ecl_util_select_filelist( const char * path , const char * base void ecl_util_append_month_range( time_t_vector_type * date_list , time_t start_date , time_t end_date , bool force_append_end); void ecl_util_init_month_range( time_t_vector_type * date_list , time_t start_date , time_t end_date); void ecl_util_set_date_values(time_t t , int * mday , int * month , int * year); +void ecl_util_set_datetime_values(time_t t , int * sec, int * min, int * hour, int * mday , int * month , int * year); bool ecl_util_path_access(const char * ecl_case); #ifdef __cplusplus }