Skip to content

Commit

Permalink
+Added an optional tmp_scale arg to global_i_mean
Browse files Browse the repository at this point in the history
  Added an optional tmp_scale argument to global_i_mean and global_j_mean to
specify an internal rescaling of variables being averaged before the reproducing
sum.  All answers are bitwise identical, but there are new optional arguments
to two public interfaces.
  • Loading branch information
Hallberg-NOAA committed Dec 4, 2019
1 parent e0d7236 commit 5a8f17e
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions src/framework/MOM_spatial_means.F90
Original file line number Diff line number Diff line change
Expand Up @@ -182,17 +182,20 @@ end function global_mass_integral

!> Determine the global mean of a field along rows of constant i, returning it
!! in a 1-d array using the local indexing. This uses reproducing sums.
subroutine global_i_mean(array, i_mean, G, mask, scale)
subroutine global_i_mean(array, i_mean, G, mask, scale, tmp_scale)
type(ocean_grid_type), intent(inout) :: G !< The ocean's grid structure
real, dimension(SZI_(G),SZJ_(G)), intent(in) :: array !< The variable being averaged
real, dimension(SZJ_(G)), intent(out) :: i_mean !< Global mean of array along its i-axis
real, dimension(SZI_(G),SZJ_(G)), &
optional, intent(in) :: mask !< An array used for weighting the i-mean
real, optional, intent(in) :: scale !< A rescaling factor for the variable
optional, intent(in) :: mask !< An array used for weighting the i-mean
real, optional, intent(in) :: scale !< A rescaling factor for the output variable
real, optional, intent(in) :: tmp_scale !< A rescaling factor for the internal
!! calculations that is removed from the output

! Local variables
type(EFP_type), allocatable, dimension(:) :: asum, mask_sum
real :: scalefac ! A scaling factor for the variable.
real :: unscale ! A factor for undoing any internal rescaling before output.
real :: mask_sum_r
integer :: is, ie, js, je, idg_off, jdg_off
integer :: i, j
Expand All @@ -201,6 +204,10 @@ subroutine global_i_mean(array, i_mean, G, mask, scale)
idg_off = G%idg_offset ; jdg_off = G%jdg_offset

scalefac = 1.0 ; if (present(scale)) scalefac = scale
unscale = 1.0
if (present(tmp_scale)) then ; if (tmp_scale /= 0.0) then
scalefac = scalefac * tmp_scale ; unscale = 1.0 / tmp_scale
endif ; endif
call reset_EFP_overflow_error()

allocate(asum(G%jsg:G%jeg))
Expand Down Expand Up @@ -253,31 +260,40 @@ subroutine global_i_mean(array, i_mean, G, mask, scale)
enddo
endif

if (unscale /= 1.0) then ; do j=js,je ; i_mean(j) = unscale*i_mean(j) ; enddo ; endif

deallocate(asum)

end subroutine global_i_mean

!> Determine the global mean of a field along rows of constant j, returning it
!! in a 1-d array using the local indexing. This uses reproducing sums.
subroutine global_j_mean(array, j_mean, G, mask, scale)
subroutine global_j_mean(array, j_mean, G, mask, scale, tmp_scale)
type(ocean_grid_type), intent(inout) :: G !< The ocean's grid structure
real, dimension(SZI_(G),SZJ_(G)), intent(in) :: array !< The variable being averaged
real, dimension(SZI_(G)), intent(out) :: j_mean !< Global mean of array along its j-axis
real, dimension(SZI_(G),SZJ_(G)), &
optional, intent(in) :: mask !< An array used for weighting the j-mean
real, optional, intent(in) :: scale !< A rescaling factor for the variable
optional, intent(in) :: mask !< An array used for weighting the j-mean
real, optional, intent(in) :: scale !< A rescaling factor for the output variable
real, optional, intent(in) :: tmp_scale !< A rescaling factor for the internal
!! calculations that is removed from the output

! Local variables
type(EFP_type), allocatable, dimension(:) :: asum, mask_sum
real :: mask_sum_r
real :: scalefac ! A scaling factor for the variable.
real :: unscale ! A factor for undoing any internal rescaling before output.
integer :: is, ie, js, je, idg_off, jdg_off
integer :: i, j

is = G%isc ; ie = G%iec ; js = G%jsc ; je = G%jec
idg_off = G%idg_offset ; jdg_off = G%jdg_offset

scalefac = 1.0 ; if (present(scale)) scalefac = scale
unscale = 1.0
if (present(tmp_scale)) then ; if (tmp_scale /= 0.0) then
scalefac = scalefac * tmp_scale ; unscale = 1.0 / tmp_scale
endif ; endif
call reset_EFP_overflow_error()

allocate(asum(G%isg:G%ieg))
Expand Down Expand Up @@ -330,6 +346,8 @@ subroutine global_j_mean(array, j_mean, G, mask, scale)
enddo
endif

if (unscale /= 1.0) then ; do i=is,ie ; j_mean(i) = unscale*j_mean(i) ; enddo ; endif

deallocate(asum)

end subroutine global_j_mean
Expand Down

0 comments on commit 5a8f17e

Please sign in to comment.