Skip to content

Commit

Permalink
Merge branch 'NOAA-GFDL:main' into Data_Override_Ext_Weights
Browse files Browse the repository at this point in the history
  • Loading branch information
abrooks1085 authored May 22, 2024
2 parents 5d70e72 + c00367f commit 7718378
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 deletions.
30 changes: 19 additions & 11 deletions diag_manager/fms_diag_file_object.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1393,11 +1393,12 @@ logical function is_time_to_close_file (this, time_step)
end function

!> \brief Determine if it is time to "write" to the file
logical function is_time_to_write(this, time_step, output_buffers, do_not_write)
logical function is_time_to_write(this, time_step, output_buffers, diag_fields, do_not_write)
class(fmsDiagFileContainer_type), intent(inout), target :: this !< The file object
TYPE(time_type), intent(in) :: time_step !< Current model step time
type(fmsDiagOutputBuffer_type), intent(in) :: output_buffers(:) !< Array of output buffer.
!! This is needed for error messages!
type(fmsDiagField_type), intent(in) :: diag_fields(:) !< Array of diag_fields objects
logical, intent(out) :: do_not_write !< .True. only if this is not a new
!! time step and you are writting
!! at every time step
Expand All @@ -1411,7 +1412,7 @@ logical function is_time_to_write(this, time_step, output_buffers, do_not_write)
!! If the diag file is being written at every time step
if (time_step .ne. this%FMS_diag_file%next_output) then
!! Only write and update the next_output if it is a new time
call this%FMS_diag_file%check_buffer_times(output_buffers)
call this%FMS_diag_file%check_buffer_times(output_buffers, diag_fields)
this%FMS_diag_file%next_output = time_step
this%FMS_diag_file%next_next_output = time_step
is_time_to_write = .true.
Expand Down Expand Up @@ -1840,22 +1841,29 @@ end function get_number_of_buffers

!> Check to ensure that send_data was called at the time step for every output buffer in the file
!! This is only needed when you are output data at every time step
subroutine check_buffer_times(this, output_buffers)
subroutine check_buffer_times(this, output_buffers, diag_fields)
class(fmsDiagFile_type), intent(in) :: this !< file object
type(fmsDiagOutputBuffer_type), intent(in), target :: output_buffers(:) !< Array of output buffers
type(fmsDiagField_type), intent(in) :: diag_fields(:) !< Array of diag_fields

integer :: i
type(time_type) :: current_buffer_time
character(len=:), allocatable :: field_name
integer :: i !< For do loop
type(time_type) :: current_buffer_time !< The buffer time for the current buffer in the do loop
character(len=:), allocatable :: field_name !< The field name (for error messages)
logical :: buffer_time_set !< .True. if current_buffer_time has been set
type(fmsDiagOutputBuffer_type), pointer :: output_buffer_obj !< Pointer to the output buffer

buffer_time_set = .false.
do i = 1, this%number_of_buffers
if (i .eq. 1) then
current_buffer_time = output_buffers(this%buffer_ids(i))%get_buffer_time()
field_name = output_buffers(this%buffer_ids(i))%get_buffer_name()
output_buffer_obj => output_buffers(this%buffer_ids(i))
if (diag_fields(output_buffer_obj%get_field_id())%is_static()) cycle
if (.not. buffer_time_set) then
current_buffer_time = output_buffer_obj%get_buffer_time()
field_name = output_buffer_obj%get_buffer_name()
buffer_time_set = .true.
else
if (current_buffer_time .ne. output_buffers(this%buffer_ids(i))%get_buffer_time()) &
if (current_buffer_time .ne. output_buffer_obj%get_buffer_time()) &
call mpp_error(FATAL, "Send data has not been called at the same time steps for the fields:"//&
field_name//" and "//output_buffers(this%buffer_ids(i))%get_buffer_name()//&
field_name//" and "//output_buffer_obj%get_buffer_name()//&
" in file:"//this%get_file_fname())
endif
enddo
Expand Down
3 changes: 2 additions & 1 deletion diag_manager/fms_diag_object.F90
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,8 @@ subroutine fms_diag_do_io(this, end_time)
call diag_file%write_axis_data(this%diag_axis)
endif

finish_writing = diag_file%is_time_to_write(model_time, this%FMS_diag_output_buffers, do_not_write)
finish_writing = diag_file%is_time_to_write(model_time, this%FMS_diag_output_buffers, &
this%FMS_diag_fields, do_not_write)
unlim_dim_was_increased = .false.

! finish reduction method if its time to write
Expand Down
9 changes: 7 additions & 2 deletions test_fms/diag_manager/test_output_every_freq.F90
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ program test_output_every_freq

use fms_mod, only: fms_init, fms_end, string
use diag_manager_mod, only: diag_axis_init, send_data, diag_send_complete, diag_manager_set_time_end, &
register_diag_field, diag_manager_init, diag_manager_end
register_diag_field, diag_manager_init, diag_manager_end, register_static_field, &
diag_axis_init
use time_manager_mod, only: time_type, operator(+), JULIAN, set_time, set_calendar_type, set_date
use mpp_mod, only: FATAL, mpp_error
use fms2_io_mod, only: FmsNetcdfFile_t, open_file, close_file, read_data, get_dimension_size

implicit none

integer :: id_var0, id_var1 !< diag field ids
integer :: id_var0, id_var1, id_var2 !< diag field ids
integer :: id_axis1 !< Id for axis
logical :: used !< for send_data calls
integer :: ntimes = 48 !< Number of time steps
real :: vdata !< Buffer to store the data
Expand All @@ -45,9 +47,12 @@ program test_output_every_freq
Time_step = set_time (3600,0) !< 1 hour
call diag_manager_set_time_end(set_date(2,1,3,0,0,0))

id_axis1 = diag_axis_init('dummy_axis', (/real(1.)/), "mullions", "X")
id_var0 = register_diag_field ('ocn_mod', 'var0', Time)
id_var1 = register_diag_field ('ocn_mod', 'var1', Time)
id_var2 = register_static_field ('ocn_mod', 'var2', (/id_axis1/))

used = send_data(id_var2, real(123.456))
do i = 1, ntimes
Time = Time + Time_step
vdata = real(i)
Expand Down
8 changes: 8 additions & 0 deletions test_fms/diag_manager/test_output_every_freq.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ diag_files:
var_name: var0
reduction: none
kind: r4
- module: ocn_mod
var_name: var2
reduction: none
kind: r4
_EOF

my_test_count=1
Expand All @@ -66,6 +70,10 @@ diag_files:
var_name: var1
reduction: none
kind: r4
- module: ocn_mod
var_name: var2
reduction: none
kind: r4
_EOF

my_test_count=`expr $my_test_count + 1`
Expand Down

0 comments on commit 7718378

Please sign in to comment.