Skip to content

Commit

Permalink
fix: merge diag_manager start time fix from 2023.02.01 into main (#1396)
Browse files Browse the repository at this point in the history
  • Loading branch information
rem1776 authored Nov 14, 2023
1 parent 0ede185 commit c92e40a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 11 additions & 3 deletions diag_manager/diag_manager.F90
Original file line number Diff line number Diff line change
Expand Up @@ -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,&
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion diag_manager/diag_util.F90
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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

0 comments on commit c92e40a

Please sign in to comment.