Checksums a 3d array staggered at C-grid u points.
1526 type(hor_index_type),
target,
intent(in) :: hi_m
1527 real,
dimension(HI_m%isdB:,HI_m%Jsd:,:),
target,
intent(in) :: array_m
1528 character(len=*),
intent(in) :: mesg
1529 integer,
optional,
intent(in) :: haloshift
1530 logical,
optional,
intent(in) :: symmetric
1532 logical,
optional,
intent(in) :: omit_corners
1533 real,
optional,
intent(in) :: scale
1534 integer,
optional,
intent(in) :: logunit
1536 real,
pointer :: array(:,:,:)
1537 real,
allocatable,
dimension(:,:,:) :: rescaled_array
1538 type(hor_index_type),
pointer :: hi
1541 integer :: i, j, k, is
1542 real :: amean, amin, amax
1543 integer :: bc0, bcsw, bcse, bcnw, bcne, hshift
1544 integer :: bcn, bcs, bce, bcw
1545 logical :: do_corners, sym, sym_stats
1550 if (modulo(turns, 4) /= 0)
then 1552 call rotate_hor_index(hi_m, -turns, hi)
1553 if (modulo(turns, 2) /= 0)
then 1555 allocate(array(hi%isd:hi%ied, hi%JsdB:hi%JedB,
size(array_m, 3)))
1556 call rotate_array(array_m, -turns, array)
1557 call vchksum(array, mesg, hi, haloshift, symmetric, omit_corners, scale, logunit)
1560 allocate(array(hi%IsdB:hi%IedB, hi%jsd:hi%jed,
size(array_m, 3)))
1561 call rotate_array(array_m, -turns, array)
1568 if (checkfornans)
then 1569 if (is_nan(array(hi%IscB:hi%IecB,hi%jsc:hi%jec,:))) &
1570 call chksum_error(fatal,
'NaN detected: '//trim(mesg))
1575 scaling = 1.0 ;
if (
present(scale)) scaling = scale
1576 iounit = error_unit;
if(
present(logunit)) iounit = logunit
1577 sym_stats = .false. ;
if (
present(symmetric)) sym_stats = symmetric
1578 if (
present(haloshift))
then ;
if (haloshift > 0) sym_stats = .true. ;
endif 1580 if (calculatestatistics)
then 1581 if (
present(scale))
then 1582 allocate( rescaled_array(lbound(array,1):ubound(array,1), &
1583 lbound(array,2):ubound(array,2), &
1584 lbound(array,3):ubound(array,3)) )
1585 rescaled_array(:,:,:) = 0.0
1586 is = hi%isc ;
if (sym_stats) is = hi%isc-1
1587 do k=1,
size(array,3) ;
do j=hi%jsc,hi%jec ;
do i=is,hi%IecB
1588 rescaled_array(i,j,k) = scale*array(i,j,k)
1589 enddo ;
enddo ;
enddo 1590 call substats(hi, rescaled_array, sym_stats, amean, amin, amax)
1591 deallocate(rescaled_array)
1593 call substats(hi, array, sym_stats, amean, amin, amax)
1596 call chk_sum_msg(
"u-point:", amean, amin, amax, mesg, iounit)
1599 if (.not.writechksums)
return 1601 hshift = default_shift
1602 if (
present(haloshift)) hshift = haloshift
1603 if (hshift<0) hshift = hi%ied-hi%iec
1605 if ( hi%isc-hshift<hi%isd .or. hi%iec+hshift>hi%ied .or. &
1606 hi%jsc-hshift<hi%jsd .or. hi%jec+hshift>hi%jed )
then 1607 write(0,*)
'chksum_u_3d: haloshift =',hshift
1608 write(0,*)
'chksum_u_3d: isd,isc,iec,ied=',hi%isd,hi%isc,hi%iec,hi%ied
1609 write(0,*)
'chksum_u_3d: jsd,jsc,jec,jed=',hi%jsd,hi%jsc,hi%jec,hi%jed
1610 call chksum_error(fatal,
'Error in chksum_u_3d '//trim(mesg))
1613 bc0 = subchk(array, hi, 0, 0, scaling)
1615 sym = .false. ;
if (
present(symmetric)) sym = symmetric
1617 if ((hshift==0) .and. .not.sym)
then 1618 if (is_root_pe())
call chk_sum_msg(
"u-point:", bc0, mesg, iounit)
1622 do_corners = .true. ;
if (
present(omit_corners)) do_corners = .not.omit_corners
1625 bcw = subchk(array, hi, -hshift-1, 0, scaling)
1626 if (is_root_pe())
call chk_sum_msg_w(
"u-point:", bc0, bcw, mesg, iounit)
1627 elseif (do_corners)
then 1629 bcsw = subchk(array, hi, -hshift-1, -hshift, scaling)
1630 bcnw = subchk(array, hi, -hshift-1, hshift, scaling)
1632 bcsw = subchk(array, hi, -hshift, -hshift, scaling)
1633 bcnw = subchk(array, hi, -hshift, hshift, scaling)
1635 bcse = subchk(array, hi, hshift, -hshift, scaling)
1636 bcne = subchk(array, hi, hshift, hshift, scaling)
1639 call chk_sum_msg(
"u-point:", bc0, bcsw, bcse, bcnw, bcne, mesg, iounit)
1641 bcs = subchk(array, hi, 0, -hshift, scaling)
1642 bce = subchk(array, hi, hshift, 0, scaling)
1644 bcw = subchk(array, hi, -hshift-1, 0, scaling)
1646 bcw = subchk(array, hi, -hshift, 0, scaling)
1648 bcn = subchk(array, hi, 0, hshift, scaling)
1651 call chk_sum_msg_nsew(
"u-point:", bc0, bcn, bcs, bce, bcw, mesg, iounit)
1656 integer function subchk(array, HI, di, dj, scale)
1657 type(hor_index_type),
intent(in) :: hi
1658 real,
dimension(HI%IsdB:,HI%jsd:,:),
intent(in) :: array
1659 integer,
intent(in) :: di
1660 integer,
intent(in) :: dj
1661 real,
intent(in) :: scale
1662 integer :: i, j, k, bc
1665 do k=lbound(array,3),ubound(array,3) ;
do j=hi%jsc+dj,hi%jec+dj ;
do i=hi%isc+di,hi%iec+di
1666 bc = bitcount(abs(scale*array(i,j,k)))
1667 subchk = subchk + bc
1668 enddo ;
enddo ;
enddo 1669 call sum_across_pes(subchk)
1670 subchk=mod(subchk, bc_modulus)
1673 subroutine substats(HI, array, sym_stats, aMean, aMin, aMax)
1674 type(hor_index_type),
intent(in) :: hi
1675 real,
dimension(HI%IsdB:,HI%jsd:,:),
intent(in) :: array
1676 logical,
intent(in) :: sym_stats
1678 real,
intent(out) :: amean
1679 real,
intent(out) :: amin
1680 real,
intent(out) :: amax
1682 integer :: i, j, k, n, isb
1684 isb = hi%isc ;
if (sym_stats) isb = hi%isc-1
1686 amin = array(hi%isc,hi%jsc,1) ; amax = amin
1687 do k=lbound(array,3),ubound(array,3) ;
do j=hi%jsc,hi%jec ;
do i=isb,hi%IecB
1688 amin = min(amin, array(i,j,k))
1689 amax = max(amax, array(i,j,k))
1690 enddo ;
enddo ;
enddo 1692 amean = reproducing_sum(array(hi%isc:hi%iec,hi%jsc:hi%jec,:))
1693 n = (1 + hi%jec - hi%jsc) * (1 + hi%iec - hi%isc) *
size(array,3)
1694 call sum_across_pes(n)
1695 call min_across_pes(amin)
1696 call max_across_pes(amax)
1697 amean = amean /
real(n)
1698 end subroutine substats