From c92e40a0ed87e846bc69abaaa9f1c36c20ed038f Mon Sep 17 00:00:00 2001 From: Ryan Mulhall <35538242+rem1776@users.noreply.github.com> Date: Tue, 14 Nov 2023 09:52:39 -0500 Subject: [PATCH] fix: merge diag_manager start time fix from 2023.02.01 into main (#1396) --- CHANGELOG.md | 6 ++++++ diag_manager/diag_manager.F90 | 14 +++++++++++--- diag_manager/diag_util.F90 | 12 +++++++++++- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 782f940443..70f365c15d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,12 @@ sequential patch number (starting from `01`). - 2023.03-alpha2 9983ce308e62e9f7215b04c227cebd30fd75e784 - 2023.03-alpha1 a46bd94fd8dd1f6f021501e29179003ff28180ec + +## [2023.02.01] - 2023-10-13 +### Fixed +- DIAG_MANAGER: Fixes issue with incorrect start_time functionality + + ## [2023.02] - 2023-07-27 ### Known Issues - GCC 11.1.0 is unsupported due to compilation issues with select type. The issue is resolved in later GCC releases. diff --git a/diag_manager/diag_manager.F90 b/diag_manager/diag_manager.F90 index 55048c04f8..9a2506f5be 100644 --- a/diag_manager/diag_manager.F90 +++ b/diag_manager/diag_manager.F90 @@ -218,7 +218,8 @@ MODULE diag_manager_mod & check_out_of_bounds, check_bounds_are_exact_dynamic, check_bounds_are_exact_static,& & diag_time_inc, find_input_field, init_input_field, init_output_field,& & diag_data_out, write_static, get_date_dif, get_subfield_vert_size, sync_file_times,& - & prepend_attribute, attribute_init, diag_util_init, field_log_separator + & prepend_attribute, attribute_init, diag_util_init, field_log_separator, & + & get_file_start_time USE diag_data_mod, ONLY: max_files, CMOR_MISSING_VALUE, DIAG_OTHER, DIAG_OCEAN, DIAG_ALL, EVERY_TIME,& & END_OF_RUN, DIAG_SECONDS, DIAG_MINUTES, DIAG_HOURS, DIAG_DAYS, DIAG_MONTHS, DIAG_YEARS, num_files,& & max_input_fields, max_output_fields, num_output_fields, EMPTY, FILL_VALUE, null_axis_id,& @@ -442,6 +443,7 @@ INTEGER FUNCTION register_diag_field_array(module_name, field_name, axes, init_t INTEGER :: stdout_unit LOGICAL :: mask_variant1, verbose1 CHARACTER(len=128) :: msg + TYPE(time_type) :: diag_file_init_time !< The intial time of the diag_file ! get stdout unit number stdout_unit = stdout() @@ -557,7 +559,6 @@ INTEGER FUNCTION register_diag_field_array(module_name, field_name, axes, init_t ind = input_fields(field)%output_fields(j) output_fields(ind)%static = .FALSE. ! Set up times in output_fields - output_fields(ind)%last_output = init_time ! Get output frequency from for the appropriate output file file_num = output_fields(ind)%output_file IF ( file_num == max_files ) CYCLE @@ -576,8 +577,10 @@ INTEGER FUNCTION register_diag_field_array(module_name, field_name, axes, init_t END IF freq = files(file_num)%output_freq + diag_file_init_time = get_file_start_time(file_num) output_units = files(file_num)%output_units - output_fields(ind)%next_output = diag_time_inc(init_time, freq, output_units, err_msg=msg) + output_fields(ind)%last_output = diag_file_init_time + output_fields(ind)%next_output = diag_time_inc(diag_file_init_time, freq, output_units, err_msg=msg) IF ( msg /= '' ) THEN IF ( fms_error_handler('diag_manager_mod::register_diag_field',& & ' file='//TRIM(files(file_num)%name)//': '//TRIM(msg),err_msg)) RETURN @@ -1909,6 +1912,11 @@ LOGICAL FUNCTION diag_send_data(diag_field_id, field, time, is_in, js_in, ks_in, ! Finished output of previously buffered data, now deal with buffering new data END IF + if (present(time)) then + !! If the last_output is greater than the time passed in, it is not time to start averaging the data + if (output_fields(out_num)%last_output > time) CYCLE + endif + IF ( .NOT.output_fields(out_num)%static .AND. .NOT.need_compute .AND. debug_diag_manager ) THEN CALL check_bounds_are_exact_dynamic(out_num, diag_field_id, Time, err_msg=err_msg_local) IF ( err_msg_local /= '' ) THEN diff --git a/diag_manager/diag_util.F90 b/diag_manager/diag_util.F90 index 23191e62e8..25ffeb9cc4 100644 --- a/diag_manager/diag_util.F90 +++ b/diag_manager/diag_util.F90 @@ -82,7 +82,7 @@ MODULE diag_util_mod & prepend_attribute, attribute_init, diag_util_init,& & update_bounds, check_out_of_bounds, check_bounds_are_exact_dynamic, check_bounds_are_exact_static,& & fms_diag_check_out_of_bounds, & - & fms_diag_check_bounds_are_exact_dynamic, fms_diag_check_bounds_are_exact_static + & fms_diag_check_bounds_are_exact_dynamic, fms_diag_check_bounds_are_exact_static, get_file_start_time !> @brief Prepend a value to a string attribute in the output field or output file. @@ -2751,6 +2751,16 @@ SUBROUTINE prepend_attribute_file(out_file, att_name, prepend_value, err_msg) END IF END SUBROUTINE prepend_attribute_file + !> @brief Get the a diag_file's start_time as it is defined in the diag_table + !! @return the start_time for the file + function get_file_start_time(file_num) & + result (start_time) + integer, intent(in) :: file_num !< File number of the file to get the start_time from + + TYPE(time_type) :: start_time !< The start_time to return + + start_time = files(file_num)%start_time + end function get_file_start_time END MODULE diag_util_mod !> @} ! close documentation grouping