Checksums a 3d array staggered at C-grid v points.
1705 type(hor_index_type),
target,
intent(in) :: hi_m
1706 real,
dimension(HI_m%isd:,HI_m%JsdB:,:),
target,
intent(in) :: array_m
1707 character(len=*),
intent(in) :: mesg
1708 integer,
optional,
intent(in) :: haloshift
1709 logical,
optional,
intent(in) :: symmetric
1711 logical,
optional,
intent(in) :: omit_corners
1712 real,
optional,
intent(in) :: scale
1713 integer,
optional,
intent(in) :: logunit
1715 real,
pointer :: array(:,:,:)
1716 real,
allocatable,
dimension(:,:,:) :: rescaled_array
1717 type(hor_index_type),
pointer :: hi
1720 integer :: i, j, k, js
1721 integer :: bc0, bcsw, bcse, bcnw, bcne, hshift
1722 integer :: bcn, bcs, bce, bcw
1723 real :: amean, amin, amax
1724 logical :: do_corners, sym, sym_stats
1729 if (modulo(turns, 4) /= 0)
then 1731 call rotate_hor_index(hi_m, -turns, hi)
1732 if (modulo(turns, 2) /= 0)
then 1734 allocate(array(hi%IsdB:hi%IedB, hi%jsd:hi%jed,
size(array_m, 3)))
1735 call rotate_array(array_m, -turns, array)
1736 call uchksum(array, mesg, hi, haloshift, symmetric, omit_corners, scale, logunit)
1739 allocate(array(hi%isd:hi%ied, hi%JsdB:hi%JedB,
size(array_m, 3)))
1740 call rotate_array(array_m, -turns, array)
1747 if (checkfornans)
then 1748 if (is_nan(array(hi%isc:hi%iec,hi%JscB:hi%JecB,:))) &
1749 call chksum_error(fatal,
'NaN detected: '//trim(mesg))
1754 scaling = 1.0 ;
if (
present(scale)) scaling = scale
1755 iounit = error_unit;
if(
present(logunit)) iounit = logunit
1756 sym_stats = .false. ;
if (
present(symmetric)) sym_stats = symmetric
1757 if (
present(haloshift))
then ;
if (haloshift > 0) sym_stats = .true. ;
endif 1759 if (calculatestatistics)
then 1760 if (
present(scale))
then 1761 allocate( rescaled_array(lbound(array,1):ubound(array,1), &
1762 lbound(array,2):ubound(array,2), &
1763 lbound(array,3):ubound(array,3)) )
1764 rescaled_array(:,:,:) = 0.0
1765 js = hi%jsc ;
if (sym_stats) js = hi%jsc-1
1766 do k=1,
size(array,3) ;
do j=js,hi%JecB ;
do i=hi%isc,hi%iec
1767 rescaled_array(i,j,k) = scale*array(i,j,k)
1768 enddo ;
enddo ;
enddo 1769 call substats(hi, rescaled_array, sym_stats, amean, amin, amax)
1770 deallocate(rescaled_array)
1772 call substats(hi, array, sym_stats, amean, amin, amax)
1775 call chk_sum_msg(
"v-point:", amean, amin, amax, mesg, iounit)
1778 if (.not.writechksums)
return 1780 hshift = default_shift
1781 if (
present(haloshift)) hshift = haloshift
1782 if (hshift<0) hshift = hi%ied-hi%iec
1784 if ( hi%isc-hshift<hi%isd .or. hi%iec+hshift>hi%ied .or. &
1785 hi%jsc-hshift<hi%jsd .or. hi%jec+hshift>hi%jed )
then 1786 write(0,*)
'chksum_v_3d: haloshift =',hshift
1787 write(0,*)
'chksum_v_3d: isd,isc,iec,ied=',hi%isd,hi%isc,hi%iec,hi%ied
1788 write(0,*)
'chksum_v_3d: jsd,jsc,jec,jed=',hi%jsd,hi%jsc,hi%jec,hi%jed
1789 call chksum_error(fatal,
'Error in chksum_v_3d '//trim(mesg))
1792 bc0 = subchk(array, hi, 0, 0, scaling)
1794 sym = .false. ;
if (
present(symmetric)) sym = symmetric
1796 if ((hshift==0) .and. .not.sym)
then 1797 if (is_root_pe())
call chk_sum_msg(
"v-point:", bc0, mesg, iounit)
1801 do_corners = .true. ;
if (
present(omit_corners)) do_corners = .not.omit_corners
1804 bcs = subchk(array, hi, 0, -hshift-1, scaling)
1805 if (is_root_pe())
call chk_sum_msg_s(
"v-point:", bc0, bcs, mesg, iounit)
1806 elseif (do_corners)
then 1808 bcsw = subchk(array, hi, -hshift, -hshift-1, scaling)
1809 bcse = subchk(array, hi, hshift, -hshift-1, scaling)
1811 bcsw = subchk(array, hi, -hshift, -hshift, scaling)
1812 bcse = subchk(array, hi, hshift, -hshift, scaling)
1814 bcnw = subchk(array, hi, -hshift, hshift, scaling)
1815 bcne = subchk(array, hi, hshift, hshift, scaling)
1818 call chk_sum_msg(
"v-point:", bc0, bcsw, bcse, bcnw, bcne, mesg, iounit)
1821 bcs = subchk(array, hi, 0, -hshift-1, scaling)
1823 bcs = subchk(array, hi, 0, -hshift, scaling)
1825 bce = subchk(array, hi, hshift, 0, scaling)
1826 bcw = subchk(array, hi, -hshift, 0, scaling)
1827 bcn = subchk(array, hi, 0, hshift, scaling)
1830 call chk_sum_msg_nsew(
"v-point:", bc0, bcn, bcs, bce, bcw, mesg, iounit)
1835 integer function subchk(array, HI, di, dj, scale)
1836 type(hor_index_type),
intent(in) :: hi
1837 real,
dimension(HI%isd:,HI%JsdB:,:),
intent(in) :: array
1838 integer,
intent(in) :: di
1839 integer,
intent(in) :: dj
1840 real,
intent(in) :: scale
1841 integer :: i, j, k, bc
1844 do k=lbound(array,3),ubound(array,3) ;
do j=hi%jsc+dj,hi%jec+dj ;
do i=hi%isc+di,hi%iec+di
1845 bc = bitcount(abs(scale*array(i,j,k)))
1846 subchk = subchk + bc
1847 enddo ;
enddo ;
enddo 1848 call sum_across_pes(subchk)
1849 subchk=mod(subchk, bc_modulus)
1853 subroutine substats(HI, array, sym_stats, aMean, aMin, aMax)
1854 type(hor_index_type),
intent(in) :: hi
1855 real,
dimension(HI%isd:,HI%JsdB:,:),
intent(in) :: array
1856 logical,
intent(in) :: sym_stats
1858 real,
intent(out) :: amean
1859 real,
intent(out) :: amin
1860 real,
intent(out) :: amax
1862 integer :: i, j, k, n, jsb
1864 jsb = hi%jsc ;
if (sym_stats) jsb = hi%jsc-1
1866 amin = array(hi%isc,hi%jsc,1) ; amax = amin
1867 do k=lbound(array,3),ubound(array,3) ;
do j=jsb,hi%JecB ;
do i=hi%isc,hi%iec
1868 amin = min(amin, array(i,j,k))
1869 amax = max(amax, array(i,j,k))
1870 enddo ;
enddo ;
enddo 1872 amean = reproducing_sum(array(hi%isc:hi%iec,hi%jsc:hi%jec,:))
1873 n = (1 + hi%jec - hi%jsc) * (1 + hi%iec - hi%isc) *
size(array,3)
1874 call sum_across_pes(n)
1875 call min_across_pes(amin)
1876 call max_across_pes(amax)
1877 amean = amean /
real(n)
1878 end subroutine substats