Skip to content

Commit

Permalink
fix: start_time functionality in diag manager (#1390)
Browse files Browse the repository at this point in the history
  • Loading branch information
uramirez8707 authored Oct 13, 2023
1 parent c7a70e7 commit 7371c87
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
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 @@ -444,6 +445,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 @@ -559,7 +561,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 @@ -578,8 +579,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 @@ -1911,6 +1914,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 @@ -84,7 +84,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 @@ -2753,6 +2753,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 7371c87

Please sign in to comment.