Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move weight check to output buffer, more comments + cleanup
Browse files Browse the repository at this point in the history
rem1776 authored and rem1776 committed Nov 28, 2023
1 parent 05f9144 commit 3a8a4fd
Showing 4 changed files with 15 additions and 15 deletions.
11 changes: 9 additions & 2 deletions diag_manager/fms_diag_field_object.F90
Original file line number Diff line number Diff line change
@@ -1693,18 +1693,22 @@ subroutine set_mask(this, mask_in, is, js, ks, ie, je, ke)
endif
end subroutine set_mask

!> sets halo_present to true
subroutine set_halo_present(this)
class(fmsDiagField_type), intent(inout) :: this
class(fmsDiagField_type), intent(inout) :: this !< field object to modify
this%halo_present = .true.
end subroutine set_halo_present

!> Getter for halo_present
pure function is_halo_present(this)
class(fmsDiagField_type), intent(in) :: this
class(fmsDiagField_type), intent(in) :: this !< field object to get from
logical :: is_halo_present
is_halo_present = this%halo_present
end function is_halo_present

!> Helper routine to find and set the missing value for a field
!! Always returns r8 due to reduction routine args
!! casts up to r8 from given missing val or default if needed
function find_missing_value(this, missing_val) &
result(res)
class(fmsDiagField_type), intent(in) :: this
@@ -1725,6 +1729,9 @@ function find_missing_value(this, missing_val) &
end select
end function find_missing_value

!> @returns allocation status of logical mask array
!! this just indicates whether the mask array itself has been alloc'd
!! this is different from @ref has_mask_variant, which is set earlier for whether a mask is being used at all
pure logical function has_mask_allocated(this)
class(fmsDiagField_type),intent(in) :: this
has_mask_allocated = allocated(this%mask)
4 changes: 2 additions & 2 deletions diag_manager/fms_diag_object.F90
Original file line number Diff line number Diff line change
@@ -724,7 +724,7 @@ subroutine fms_diag_do_io(this, is_end_of_run)
!! If true the metadata will need to be written
logical :: force_write, is_writing, subregional, has_halo
logical, allocatable :: mask_adj(:,:,:,:), mask_tmp(:,:,:,:) !< copy of field mask and ajusted mask
logical, parameter :: DEBUG_REDUCT = .true.
logical, parameter :: DEBUG_REDUCT = .false.
class(*), allocatable :: missing_val
real(r8_kind) :: mval
character(len=128) :: error_string
@@ -765,7 +765,7 @@ subroutine fms_diag_do_io(this, is_end_of_run)
! time_average and greater values all involve averaging so need to be "finished" before written
if( field_yaml%has_var_reduction()) then
if( field_yaml%get_var_reduction() .ge. time_average) then
call mpp_error(NOTE, "fms_diag_do_io:: finishing reduction for "//diag_field%get_longname())
if(DEBUG_REDUCT) call mpp_error(NOTE, "fms_diag_do_io:: finishing reduction for "//diag_field%get_longname())
subregional = diag_file%FMS_diag_file%has_file_sub_region()
has_halo = diag_field%is_halo_present()
! if no mask just go for it
7 changes: 3 additions & 4 deletions diag_manager/fms_diag_output_buffer.F90
Original file line number Diff line number Diff line change
@@ -603,10 +603,9 @@ function diag_reduction_done_wrapper(this, reduction_method, missing_value, is_s
logical, allocatable :: mask_tmp(:,:,:,:)
integer :: is, ie, js, je, ks, ke, zs, ze

if(.not. allocated(this%buffer)) then
call mpp_error(NOTE, "diag_reduction_done_wrapper:: called on unallocated buffer")
return
endif
if(.not. allocated(this%buffer)) return

if(this%weight_sum .eq. 0.0_r8_kind) return

! if the mask is stil bigger than the buffer, theres a halo region we can leave out
if(has_halo .and. present(mask)) then
8 changes: 1 addition & 7 deletions diag_manager/include/fms_diag_reduction_methods.inc
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@

! for any debug prints
#ifndef DEBUG_REDUCT
#define DEBUG_REDUCT .true.
#define DEBUG_REDUCT .false.
#endif

!> @brief Do the time_none reduction method (i.e copy the correct portion of the input data)
@@ -289,7 +289,6 @@ subroutine DO_TIME_SUM_UPDATE_(data_out, weight_sum, data_in, mask, is_masked, b
do k = 0, ke_out - ks_out
do j = 0, je_out - js_out
do i = 0, ie_out - is_out
if (is_in+i .gt. ubound(data_in,1)) cycle ! TODO fixes error from modern diag test (test_diag_manager2.[45-47])
data_out(is_out + i, js_out + j, ks_out + k, :, 1) = &
data_out(is_out + i, js_out + j, ks_out + k, :, 1) &
+ (data_in(is_in +i, js_in + j, ks_in + k, :) * weight_loc) ** pow_loc
@@ -310,11 +309,6 @@ subroutine SUM_UPDATE_DONE_(out_buffer_data, weight_sum, reduction_method, missi
logical :: has_mask !< whether or not mask is present
integer, parameter :: kindl = FMS_TRM_KIND_
if(weight_sum .eq. 0.0_r8_kind) then
call mpp_error(NOTE, "skipping reduction, called with zero weight")
return
endif
has_mask = present(mask)
if ( has_mask ) then

0 comments on commit 3a8a4fd

Please sign in to comment.