Checksums a 3d array staggered at C-grid v points.
1394 type(hor_index_type),
intent(in) :: HI
1395 real,
dimension(HI%isd:,HI%JsdB:,:),
intent(in) :: array
1396 character(len=*),
intent(in) :: mesg
1397 integer,
optional,
intent(in) :: haloshift
1398 logical,
optional,
intent(in) :: symmetric
1400 logical,
optional,
intent(in) :: omit_corners
1401 real,
optional,
intent(in) :: scale
1402 integer,
optional,
intent(in) :: logunit
1404 real,
allocatable,
dimension(:,:,:) :: rescaled_array
1407 integer :: i, j, k, Js
1408 integer :: bc0, bcSW, bcSE, bcNW, bcNE, hshift
1409 integer :: bcN, bcS, bcE, bcW
1410 real :: aMean, aMin, aMax
1411 logical :: do_corners, sym, sym_stats
1413 if (checkfornans)
then
1414 if (is_nan(array(hi%isc:hi%iec,hi%JscB:hi%JecB,:))) &
1415 call chksum_error(fatal,
'NaN detected: '//trim(mesg))
1420 scaling = 1.0 ;
if (
present(scale)) scaling = scale
1421 iounit = error_unit;
if(
present(logunit)) iounit = logunit
1422 sym_stats = .false. ;
if (
present(symmetric)) sym_stats = symmetric
1423 if (
present(haloshift))
then ;
if (haloshift > 0) sym_stats = .true. ;
endif
1425 if (calculatestatistics)
then
1426 if (
present(scale))
then
1427 allocate( rescaled_array(lbound(array,1):ubound(array,1), &
1428 lbound(array,2):ubound(array,2), &
1429 lbound(array,3):ubound(array,3)) )
1430 rescaled_array(:,:,:) = 0.0
1431 js = hi%jsc ;
if (sym_stats) js = hi%jsc-1
1432 do k=1,
size(array,3) ;
do j=js,hi%JecB ;
do i=hi%isc,hi%iec
1433 rescaled_array(i,j,k) = scale*array(i,j,k)
1434 enddo ;
enddo ;
enddo
1435 call substats(hi, rescaled_array, sym_stats, amean, amin, amax)
1436 deallocate(rescaled_array)
1438 call substats(hi, array, sym_stats, amean, amin, amax)
1441 call chk_sum_msg(
"v-point:", amean, amin, amax, mesg, iounit)
1444 if (.not.writechksums)
return
1446 hshift = default_shift
1447 if (
present(haloshift)) hshift = haloshift
1448 if (hshift<0) hshift = hi%ied-hi%iec
1450 if ( hi%isc-hshift<hi%isd .or. hi%iec+hshift>hi%ied .or. &
1451 hi%jsc-hshift<hi%jsd .or. hi%jec+hshift>hi%jed )
then
1452 write(0,*)
'chksum_v_3d: haloshift =',hshift
1453 write(0,*)
'chksum_v_3d: isd,isc,iec,ied=',hi%isd,hi%isc,hi%iec,hi%ied
1454 write(0,*)
'chksum_v_3d: jsd,jsc,jec,jed=',hi%jsd,hi%jsc,hi%jec,hi%jed
1455 call chksum_error(fatal,
'Error in chksum_v_3d '//trim(mesg))
1458 bc0 =
subchk(array, hi, 0, 0, scaling)
1460 sym = .false. ;
if (
present(symmetric)) sym = symmetric
1462 if ((hshift==0) .and. .not.sym)
then
1463 if (is_root_pe())
call chk_sum_msg(
"v-point:", bc0, mesg, iounit)
1467 do_corners = .true. ;
if (
present(omit_corners)) do_corners = .not.omit_corners
1470 bcs =
subchk(array, hi, 0, -hshift-1, scaling)
1471 if (is_root_pe())
call chk_sum_msg_s(
"v-point:", bc0, bcs, mesg, iounit)
1472 elseif (do_corners)
then
1474 bcsw =
subchk(array, hi, -hshift, -hshift-1, scaling)
1475 bcse =
subchk(array, hi, hshift, -hshift-1, scaling)
1477 bcsw =
subchk(array, hi, -hshift, -hshift, scaling)
1478 bcse =
subchk(array, hi, hshift, -hshift, scaling)
1480 bcnw =
subchk(array, hi, -hshift, hshift, scaling)
1481 bcne =
subchk(array, hi, hshift, hshift, scaling)
1484 call chk_sum_msg(
"v-point:", bc0, bcsw, bcse, bcnw, bcne, mesg, iounit)
1487 bcs =
subchk(array, hi, 0, -hshift-1, scaling)
1489 bcs =
subchk(array, hi, 0, -hshift, scaling)
1491 bce =
subchk(array, hi, hshift, 0, scaling)
1492 bcw =
subchk(array, hi, -hshift, 0, scaling)
1493 bcn =
subchk(array, hi, 0, hshift, scaling)
1496 call chk_sum_msg_nsew(
"v-point:", bc0, bcn, bcs, bce, bcw, mesg, iounit)
1501 integer function subchk(array, HI, di, dj, scale)
1502 type(hor_index_type),
intent(in) :: HI
1503 real,
dimension(HI%isd:,HI%JsdB:,:),
intent(in) :: array
1504 integer,
intent(in) :: di
1505 integer,
intent(in) :: dj
1506 real,
intent(in) :: scale
1507 integer :: i, j, k, bc
1510 do k=lbound(array,3),ubound(array,3) ;
do j=hi%jsc+dj,hi%jec+dj ;
do i=hi%isc+di,hi%iec+di
1511 bc = bitcount(abs(scale*array(i,j,k)))
1513 enddo ;
enddo ;
enddo
1514 call sum_across_pes(
subchk)
1519 subroutine substats(HI, array, sym_stats, aMean, aMin, aMax)
1520 type(hor_index_type),
intent(in) :: HI
1521 real,
dimension(HI%isd:,HI%JsdB:,:),
intent(in) :: array
1522 logical,
intent(in) :: sym_stats
1524 real,
intent(out) :: aMean, aMin, aMax
1526 integer :: i, j, k, n, JsB
1528 jsb = hi%jsc ;
if (sym_stats) jsb = hi%jsc-1
1530 amin = array(hi%isc,hi%jsc,1) ; amax = amin
1531 do k=lbound(array,3),ubound(array,3) ;
do j=jsb,hi%JecB ;
do i=hi%isc,hi%iec
1532 amin = min(amin, array(i,j,k))
1533 amax = max(amax, array(i,j,k))
1534 enddo ;
enddo ;
enddo
1536 amean = reproducing_sum(array(hi%isc:hi%iec,hi%jsc:hi%jec,:))
1537 n = (1 + hi%jec - hi%jsc) * (1 + hi%iec - hi%isc) *
size(array,3)
1538 call sum_across_pes(n)
1539 call min_across_pes(amin)
1540 call max_across_pes(amax)
1541 amean = amean / real(n)