Line data Source code
1 : module zonal_mean
2 :
3 : use shr_kind_mod, only: r8 => shr_kind_r8
4 : use dynamics_vars, only: T_FVDYCORE_GRID
5 : use pmgrid, only: plon
6 :
7 : implicit none
8 : private
9 : save
10 :
11 : public :: zonal_mean_3D
12 :
13 : real(r8), parameter :: rplon = 1._r8/plon
14 :
15 : ! External that does parallel sums reproducibly.
16 : interface
17 : subroutine par_xsum(grid, a, ltot, sum)
18 : import
19 : type (T_FVDYCORE_GRID), intent(in) :: grid
20 : integer, intent(in) :: ltot
21 : real (r8), intent(in) :: a(grid%ifirstxy:grid%ilastxy,ltot)
22 : real (r8) sum(ltot)
23 : end subroutine par_xsum
24 : end interface
25 :
26 : contains
27 :
28 0 : subroutine zonal_mean_3D(grid, nlev, fld_orig, fld_zm)
29 :
30 : ! FV dynamics grid
31 : type(T_FVDYCORE_GRID), intent(in) :: grid
32 : ! Number of vertical levels
33 : integer, intent(in) :: nlev
34 : ! Original field
35 : real(r8), intent(in) :: fld_orig(grid%ifirstxy:grid%ilastxy,nlev,grid%jfirstxy:grid%jlastxy)
36 : ! Zonal mean field
37 : real(r8), intent(out) :: fld_zm(nlev,grid%jfirstxy:grid%jlastxy)
38 :
39 : integer :: j
40 :
41 : ! Rename grid bounds for convenience.
42 : associate(beglon => grid%ifirstxy, &
43 : endlon => grid%ilastxy, &
44 : beglat => grid%jfirstxy, &
45 : endlat => grid%jlastxy)
46 :
47 0 : do j = beglat, endlat
48 0 : call par_xsum( grid, fld_orig(beglon:endlon,:,j), nlev, fld_zm(:,j) )
49 0 : fld_zm(:,j) = fld_zm(:,j) * rplon
50 : end do
51 :
52 : end associate
53 :
54 0 : end subroutine zonal_mean_3D
55 :
56 : end module zonal_mean
|