diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index db92d68c9..6246694c2 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -292,8 +292,6 @@ foreach( rd_filenames rd_make_date_no_shift rd_make_date_shift - rd_month_range - rd_valid_basename test_rd_nnc_data rd_nnc_pair well_conn_collection diff --git a/lib/include/resdata/rd_util.hpp b/lib/include/resdata/rd_util.hpp index 354f41ea1..6fbc6fee6 100644 --- a/lib/include/resdata/rd_util.hpp +++ b/lib/include/resdata/rd_util.hpp @@ -100,50 +100,29 @@ typedef enum { bool rd_unified_file(const char *filename); const char *rd_file_type_name(rd_file_enum file_type); -char *rd_alloc_base_guess(const char *); int rd_filename_report_nr(const char *); -rd_file_enum rd_inspect_extension(const char *ext, bool *_fmt_file, - int *_report_nr); rd_file_enum rd_get_file_type(const char *filename, bool *fmt_file, int *report_nr); char *rd_alloc_filename(const char * /* path */, const char * /* base */, rd_file_enum, bool /* fmt_file */, int /*report_nr*/); char *rd_alloc_exfilename(const char * /* path */, const char * /* base */, rd_file_enum, bool /* fmt_file */, int /*report_nr*/); -void rd_memcpy_typed_data(void *, const void *, rd_data_type, rd_data_type, - int); -void rd_escape_kw(char *kw); bool rd_alloc_summary_files(const char *, const char *, const char *, char **, stringlist_type *); -void rd_alloc_summary_data_files(const char *path, const char *base, - bool fmt_file, stringlist_type *filelist); -void rd_alloc_restart_files(const char *, const char *, char ***, int *, bool *, - bool *); time_t rd_get_start_date(const char *); int rd_get_num_cpu(const char *data_file); bool rd_fmt_file(const char *filename, bool *__fmt_file); -char *rd_alloc_exfilename_anyfmt(const char *path, const char *base, - rd_file_enum file_type, bool start_fmt, - int report_nr); -int rd_get_month_nr(const char *month_name); int rd_fname_report_cmp(const void *f1, const void *f2); time_t rd_make_date(int mday, int month, int year); time_t rd_make_date__(int mday, int month, int year, int *year_offset); time_t rd_make_datetime(int sec, int min, int hour, int mday, int month, int year); -ert_rd_unit_enum rd_get_unit_set(const char *data_file); -bool rd_valid_basename_fmt(const char *basename_fmt); -bool rd_valid_basename(const char *basename); const char *rd_get_phase_name(rd_phase_enum phase); int rd_select_filelist(const char *path, const char *base, rd_file_enum file_type, bool fmt_file, stringlist_type *filelist); -void rd_append_month_range(time_t_vector_type *date_list, time_t start_date, - time_t end_date, bool force_append_end); -void rd_init_month_range(time_t_vector_type *date_list, time_t start_date, - time_t end_date); void rd_set_date_values(time_t t, int *mday, int *month, int *year); void rd_set_datetime_values(time_t t, int *sec, int *min, int *hour, int *mday, int *month, int *year); diff --git a/lib/resdata/rd_util.cpp b/lib/resdata/rd_util.cpp index c6ddd054a..3d85114d4 100644 --- a/lib/resdata/rd_util.cpp +++ b/lib/resdata/rd_util.cpp @@ -54,7 +54,7 @@ const char *rd_get_phase_name(rd_phase_enum phase) { } } -char *rd_alloc_base_guess(const char *path) { +static char *rd_alloc_base_guess(const char *path) { char *base = NULL; stringlist_type *data_files = stringlist_alloc_new(); stringlist_type *DATA_files = stringlist_alloc_new(); @@ -88,8 +88,8 @@ int rd_filename_report_nr(const char *filename) { /* We accept mixed lowercase/uppercase Eclipse file extensions even if Eclipse itself does not accept them. */ -rd_file_enum rd_inspect_extension(const char *ext, bool *_fmt_file, - int *_report_nr) { +static rd_file_enum rd_inspect_extension(const char *ext, bool *_fmt_file, + int *_report_nr) { rd_file_enum file_type = RD_OTHER_FILE; bool fmt_file = true; int report_nr = -1; @@ -436,32 +436,6 @@ char *rd_alloc_exfilename(const char *path, const char *base, true); } -/** - This function will first try if the 'fmt_file' file exists, and - then subsequently the !fmt_file version. If neither can be found it - will return NULL. -*/ - -char *rd_alloc_exfilename_anyfmt(const char *path, const char *base, - rd_file_enum file_type, bool fmt_file_first, - int report_nr) { - - char *filename = - rd_alloc_filename(path, base, file_type, fmt_file_first, report_nr); - if (!util_file_exists(filename)) { - free(filename); - filename = rd_alloc_filename(path, base, file_type, !fmt_file_first, - report_nr); - } - - if (!util_file_exists(filename)) { - free(filename); - filename = NULL; - } - - return filename; -} - /** This function assumes that: @@ -673,73 +647,13 @@ bool rd_fmt_file(const char *filename, bool *__fmt_file) { } /** - This function copies size elements from _src_data to target_data. If - src_type == target_type the copy is a simple memcpy, otherwise the - appropriate numerical conversion is applied. -*/ - -void rd_memcpy_typed_data(void *_target_data, const void *_src_data, - rd_data_type target_type, rd_data_type src_type, - int size) { - int i; - - if (rd_type_is_equal(target_type, src_type)) - memcpy(_target_data, _src_data, - size * rd_type_get_sizeof_ctype(src_type)); - else { - switch (rd_type_get_type(target_type)) { - case (RD_DOUBLE_TYPE): { - double *target_data = (double *)_target_data; - switch (rd_type_get_type(src_type)) { - case (RD_FLOAT_TYPE): - util_float_to_double(target_data, (const float *)_src_data, - size); - break; - case (RD_INT_TYPE): - for (i = 0; i < size; i++) - target_data[i] = ((int *)_src_data)[i]; - break; - default: - util_abort("%s: double type can only load from " - "int/float/double - aborting \n", - __func__); - } - break; - } - case (RD_FLOAT_TYPE): { - float *target_data = (float *)_target_data; - switch (rd_type_get_type(src_type)) { - case (RD_FLOAT_TYPE): - util_double_to_float(target_data, (const double *)_src_data, - size); - break; - case (RD_INT_TYPE): - for (i = 0; i < size; i++) - target_data[i] = ((int *)_src_data)[i]; - break; - default: - util_abort("%s: float type can only load from int/float/double " - "- aborting \n", - __func__); - } - break; - } - default: - util_abort("%s con not convert %s -> %s \n", __func__, - rd_type_alloc_name(src_type), - rd_type_alloc_name(target_type)); - } - } -} - -/* The stringlist will be cleared before the actual matching process starts. Observe that in addition to the @path input parameter the @base input can contain an embedded path component. */ - -void rd_alloc_summary_data_files(const char *path, const char *base, - bool fmt_file, stringlist_type *filelist) { +static void rd_alloc_summary_data_files(const char *path, const char *base, + bool fmt_file, + stringlist_type *filelist) { char *unif_data_file = rd_alloc_exfilename(path, base, RD_UNIFIED_SUMMARY_FILE, fmt_file, -1); int files = @@ -937,35 +851,6 @@ bool rd_alloc_summary_files(const char *path, const char *_base, return (stringlist_get_size(filelist) > 0) ? true : false; } -void rd_alloc_restart_files(const char *path, const char *_base, - char ***_restart_files, int *num_restart_files, - bool *_fmt_file, bool *_unified) { - - util_exit("Function:%s currently not implemented - sorry \n", __func__); -} - -/** -This little function escapes eclipse keyword names so that they can be -safely used as filenames, i.e for instance the substitution: - - 1/FVFGAS -> 1-FVFGAS - -The escape process is done 'in-place' memory-wise. -*/ -void rd_escape_kw(char *kw) { - size_t index; - for (index = 0; index < strlen(kw); index++) { - switch (kw[index]) { - case ('/'): - kw[index] = '-'; - break; - case ('\\'): - kw[index] = '-'; - break; - } - } -} - /** Will return -1 for an unrecognized month name. */ @@ -1011,7 +896,7 @@ static int rd_get_month_nr__(const char *_month_name) { return month_nr; } -int rd_get_month_nr(const char *month_name) { +static int rd_get_month_nr(const char *month_name) { int month_nr = rd_get_month_nr__(month_name); if (month_nr < 0) util_abort("%s: %s not a valid month name - aborting \n", __func__, @@ -1254,111 +1139,6 @@ int rd_get_num_cpu(const char *data_file) { return num_cpu; } -ert_rd_unit_enum rd_get_unit_set(const char *data_file) { - ert_rd_unit_enum units = RD_METRIC_UNITS; - basic_parser_type *parser = - basic_parser_alloc(" \t\r\n", "\"\'", NULL, NULL, "--", "\n"); - FILE *stream = util_fopen(data_file, "r"); - - if (basic_parser_fseek_string(parser, stream, "FIELD", true, - true)) { /* Seeks case insensitive. */ - units = RD_FIELD_UNITS; - } else if (basic_parser_fseek_string(parser, stream, "LAB", true, - true)) { /* Seeks case insensitive. */ - units = RD_LAB_UNITS; - } - - basic_parser_free(parser); - fclose(stream); - return units; -} - -bool rd_valid_basename_fmt(const char *basename_fmt) { - char *eclbasename_fmt = util_split_alloc_filename(basename_fmt); - - bool valid = true; - - const char *percent_ptr = strchr(eclbasename_fmt, '%'); - if (percent_ptr) { - percent_ptr++; - while (true) { - if (*percent_ptr == 'd') { - break; - } else if (!isdigit(*percent_ptr)) { - valid = false; - break; - } else - percent_ptr++; - } - } - - free(eclbasename_fmt); - - return valid; -} - -/* - Will append time_t values corresponding to the first day in every - month in the open interval (start_date , end_date). Iff start_date - corresponds to the first date in a month the list will start with - start_date, otherwise the list will start with the first day in the - month following after start_date. - - If end_date corresponds to the first day of the month the list will - end with end_date, otherwise it will ende with the first day in the - month prior to end_date: - - (1,1,2000) , (10,3,2000) => {(1,1,2000) , (1,2,2000) , (1,3,2000) } - (10,1,2000) , (1,4,2000) => {(1,2,2000) , (1,3,2000) , (1,4,2000) } - - All time_t values added to the date list will be pure dates, - i.e. the time part will be 00:00:00; that also applies to start_date - and end_date where possible time parts will be normalized away prior - to insertion. -*/ - -void rd_append_month_range(time_t_vector_type *date_list, time_t start_date, - time_t end_date, bool force_append_end) { - start_date = util_make_pure_date_utc(start_date); - end_date = util_make_pure_date_utc(end_date); - - if (util_is_first_day_in_month_utc(start_date)) - time_t_vector_append(date_list, start_date); - - { - time_t current_date = start_date; - while (true) { - int month, year; - util_set_date_values_utc(current_date, NULL, &month, &year); - if (month == 12) { - month = 1; - year += 1; - } else - month += 1; - - current_date = rd_make_date(1, month, year); - if (current_date < end_date) - time_t_vector_append(date_list, current_date); - else { - if (current_date == end_date) - time_t_vector_append(date_list, current_date); - else if (force_append_end) - time_t_vector_append(date_list, end_date); - break; - } - } - } -} - -void rd_init_month_range(time_t_vector_type *date_list, time_t start_date, - time_t end_date) { - time_t_vector_reset(date_list); - if (!util_is_first_day_in_month_utc(start_date)) - time_t_vector_append(date_list, util_make_pure_date_utc(start_date)); - - rd_append_month_range(date_list, start_date, end_date, true); -} - static time_t rd_make_datetime__(int sec, int min, int hour, int mday, int month, int year, int *__year_offset) { time_t date; diff --git a/lib/resdata/tests/rd_month_range.cpp b/lib/resdata/tests/rd_month_range.cpp deleted file mode 100644 index 589821dd1..000000000 --- a/lib/resdata/tests/rd_month_range.cpp +++ /dev/null @@ -1,107 +0,0 @@ -#include -#include - -#include -#include -#include - -#include - -void test_body(time_t_vector_type *date_list, int offset) { - int i; - for (i = offset; i < (time_t_vector_size(date_list) - 1); i++) { - int month, year; - time_t current_date = time_t_vector_iget(date_list, i); - test_assert_true(util_is_first_day_in_month_utc(current_date)); - util_set_date_values_utc(current_date, NULL, &month, &year); - if (i > offset) { - time_t prev_date = time_t_vector_iget(date_list, i - 1); - int prev_month, prev_year; - util_set_date_values_utc(prev_date, NULL, &prev_month, &prev_year); - - if (prev_year == year) - test_assert_int_equal(month, prev_month + 1); - else { - test_assert_int_equal(month, 1); - test_assert_int_equal(prev_month, 12); - test_assert_int_equal(year - prev_year, 1); - } - } - test_assert_time_t_equal(current_date, - util_make_pure_date_utc(current_date)); - } -} - -void test_append(const char *name, time_t_vector_type *date_list, time_t date1, - time_t date2, bool force_append_end) { - int offset = time_t_vector_size(date_list); - - printf("%s ...", name); - fflush(stdout); - - rd_append_month_range(date_list, date1, date2, force_append_end); - - // The start: - test_assert_true(util_make_pure_date_utc(date1) <= - time_t_vector_iget(date_list, offset)); - - // The body: - test_body(date_list, offset); - - // The tail: - if (force_append_end) - test_assert_time_t_equal(time_t_vector_get_last(date_list), - util_make_pure_date_utc(date2)); - else - test_assert_true( - util_is_first_day_in_month_utc(time_t_vector_get_last(date_list))); - - printf(" OK \n"); -} - -void test_init(const char *name, time_t_vector_type *date_list, - time_t start_date, time_t end_date) { - printf("%s ...", name); - fflush(stdout); - { - rd_init_month_range(date_list, start_date, end_date); - test_assert_time_t_equal(time_t_vector_get_first(date_list), - util_make_pure_date_utc(start_date)); - test_body(date_list, 1); - test_assert_time_t_equal(time_t_vector_get_last(date_list), - util_make_pure_date_utc(end_date)); - } - printf(" OK \n"); -} - -int main(int argc, char **argv) { - time_t date1 = util_make_datetime_utc(0, 2, 0, 1, 1, 2000); - time_t date2 = util_make_datetime_utc(0, 3, 0, 1, 1, 2005); - time_t date3 = util_make_datetime_utc(0, 4, 0, 10, 1, 2000); - time_t date4 = util_make_datetime_utc(0, 5, 0, 10, 1, 2005); - - { - time_t_vector_type *date_list = time_t_vector_alloc(0, 0); - test_append("Append Test1", date_list, date1, date2, true); - test_append("Append Test2", date_list, date1, date2, false); - test_append("Append Test3", date_list, date1, date4, true); - test_append("Append Test4", date_list, date1, date4, false); - test_append("Append Test5", date_list, date3, date2, true); - test_append("Append Test6", date_list, date3, date2, false); - test_append("Append Test7", date_list, date3, date4, true); - test_append("Append Test8", date_list, date3, date4, false); - time_t_vector_free(date_list); - } - { - time_t_vector_type *date_list = time_t_vector_alloc(0, 0); - - test_init("Init Test1", date_list, date1, date2); - test_init("Init Test2", date_list, date1, date4); - test_init("Init Test3", date_list, date3, date2); - test_init("Init Test4", date_list, date3, date4); - - time_t_vector_free(date_list); - } - - exit(0); -} diff --git a/lib/resdata/tests/rd_valid_basename.cpp b/lib/resdata/tests/rd_valid_basename.cpp deleted file mode 100644 index b19e84e9e..000000000 --- a/lib/resdata/tests/rd_valid_basename.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include - -int main(int argc, char **argv) { - test_assert_true(rd_valid_basename_fmt("rd_%d.data")); - test_assert_true(rd_valid_basename_fmt("RD_%d.DATA")); - test_assert_true(rd_valid_basename_fmt("RD_%04d.DATA")); - test_assert_true(rd_valid_basename_fmt("mypath/RD_%04d.DATA")); - test_assert_true(rd_valid_basename_fmt("MYPATH/RD_%04d.DATA")); - test_assert_true(rd_valid_basename_fmt("MYPATH/RD_%04d.DATA")); - test_assert_true(rd_valid_basename_fmt("RD_%d.dATA")); - test_assert_false(rd_valid_basename_fmt("RD_%s.DATA")); - test_assert_false(rd_valid_basename_fmt("RD_%f.DATA")); - test_assert_true(rd_valid_basename_fmt("mypath/RD_%d.dATA")); - - exit(0); -}