From efee97ddfc7f367345c597e3ec96c911de544835 Mon Sep 17 00:00:00 2001 From: Uriel Ramirez Date: Wed, 14 Feb 2024 16:36:42 -0500 Subject: [PATCH] Fix to prevent time from being written multiple times --- diag_manager/fms_diag_file_object.F90 | 8 +++++++- diag_manager/fms_diag_object.F90 | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/diag_manager/fms_diag_file_object.F90 b/diag_manager/fms_diag_file_object.F90 index 4a42fce00..a0d77a333 100644 --- a/diag_manager/fms_diag_file_object.F90 +++ b/diag_manager/fms_diag_file_object.F90 @@ -1374,8 +1374,9 @@ logical function writing_on_this_pe(this) end function !> \brief Write out the time data to the file -subroutine write_time_data(this) +subroutine write_time_data(this, is_the_end) class(fmsDiagFileContainer_type), intent(in), target :: this !< The file object + logical, optional, intent(in) :: is_the_end !< True if it is the end of the run real :: dif !< The time as a real number class(fmsDiagFile_type), pointer :: diag_file !< Diag_file object to open @@ -1389,6 +1390,11 @@ subroutine write_time_data(this) diag_file => this%FMS_diag_file fms2io_fileobj => diag_file%fms2io_fileobj + if (present(is_the_end)) then + ! If at the end of the run, do not do anything for the static files + if (is_the_end .and. diag_file%is_static) return + endif + if (diag_file%time_ops) then middle_time = (diag_file%last_output+diag_file%next_output)/2 dif = get_date_dif(middle_time, get_base_time(), diag_file%get_file_timeunit()) diff --git a/diag_manager/fms_diag_object.F90 b/diag_manager/fms_diag_object.F90 index 74b56cff0..10b548d5d 100644 --- a/diag_manager/fms_diag_object.F90 +++ b/diag_manager/fms_diag_object.F90 @@ -824,6 +824,7 @@ subroutine fms_diag_do_io(this, end_time) call diag_file%increase_unlim_dimension_level() if (diag_file%is_time_to_close_file(model_time)) call diag_file%close_diag_file() else if (force_write) then + call diag_file%write_time_data(is_the_end = .true.) call diag_file%close_diag_file() endif enddo