Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use six elements from summary STARTDAT keyword #642

Merged
merged 1 commit into from
Aug 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions lib/ecl/ecl_smspec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down
21 changes: 18 additions & 3 deletions lib/ecl/ecl_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -1483,24 +1483,39 @@ 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;
return ecl_util_make_date__( mday , month , year , &year_offset);
}


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 <unistd.h>
Expand Down
11 changes: 7 additions & 4 deletions lib/include/ert/ecl/ecl_kw_magic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/include/ert/ecl/ecl_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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
}
Expand Down