Checksums a 3d array staggered at C-grid u points.
1240 type(hor_index_type),
intent(in) :: HI
1241 real,
dimension(HI%isdB:,HI%Jsd:,:),
intent(in) :: array
1242 character(len=*),
intent(in) :: mesg
1243 integer,
optional,
intent(in) :: haloshift
1244 logical,
optional,
intent(in) :: symmetric
1246 logical,
optional,
intent(in) :: omit_corners
1247 real,
optional,
intent(in) :: scale
1248 integer,
optional,
intent(in) :: logunit
1250 real,
allocatable,
dimension(:,:,:) :: rescaled_array
1253 integer :: i, j, k, Is
1254 real :: aMean, aMin, aMax
1255 integer :: bc0, bcSW, bcSE, bcNW, bcNE, hshift
1256 integer :: bcN, bcS, bcE, bcW
1257 logical :: do_corners, sym, sym_stats
1259 if (checkfornans)
then
1260 if (is_nan(array(hi%IscB:hi%IecB,hi%jsc:hi%jec,:))) &
1261 call chksum_error(fatal,
'NaN detected: '//trim(mesg))
1266 scaling = 1.0 ;
if (
present(scale)) scaling = scale
1267 iounit = error_unit;
if(
present(logunit)) iounit = logunit
1268 sym_stats = .false. ;
if (
present(symmetric)) sym_stats = symmetric
1269 if (
present(haloshift))
then ;
if (haloshift > 0) sym_stats = .true. ;
endif
1271 if (calculatestatistics)
then
1272 if (
present(scale))
then
1273 allocate( rescaled_array(lbound(array,1):ubound(array,1), &
1274 lbound(array,2):ubound(array,2), &
1275 lbound(array,3):ubound(array,3)) )
1276 rescaled_array(:,:,:) = 0.0
1277 is = hi%isc ;
if (sym_stats) is = hi%isc-1
1278 do k=1,
size(array,3) ;
do j=hi%jsc,hi%jec ;
do i=is,hi%IecB
1279 rescaled_array(i,j,k) = scale*array(i,j,k)
1280 enddo ;
enddo ;
enddo
1281 call substats(hi, rescaled_array, sym_stats, amean, amin, amax)
1282 deallocate(rescaled_array)
1284 call substats(hi, array, sym_stats, amean, amin, amax)
1287 call chk_sum_msg(
"u-point:", amean, amin, amax, mesg, iounit)
1290 if (.not.writechksums)
return
1292 hshift = default_shift
1293 if (
present(haloshift)) hshift = haloshift
1294 if (hshift<0) hshift = hi%ied-hi%iec
1296 if ( hi%isc-hshift<hi%isd .or. hi%iec+hshift>hi%ied .or. &
1297 hi%jsc-hshift<hi%jsd .or. hi%jec+hshift>hi%jed )
then
1298 write(0,*)
'chksum_u_3d: haloshift =',hshift
1299 write(0,*)
'chksum_u_3d: isd,isc,iec,ied=',hi%isd,hi%isc,hi%iec,hi%ied
1300 write(0,*)
'chksum_u_3d: jsd,jsc,jec,jed=',hi%jsd,hi%jsc,hi%jec,hi%jed
1301 call chksum_error(fatal,
'Error in chksum_u_3d '//trim(mesg))
1304 bc0 =
subchk(array, hi, 0, 0, scaling)
1306 sym = .false. ;
if (
present(symmetric)) sym = symmetric
1308 if ((hshift==0) .and. .not.sym)
then
1309 if (is_root_pe())
call chk_sum_msg(
"u-point:", bc0, mesg, iounit)
1313 do_corners = .true. ;
if (
present(omit_corners)) do_corners = .not.omit_corners
1316 bcw =
subchk(array, hi, -hshift-1, 0, scaling)
1317 if (is_root_pe())
call chk_sum_msg_w(
"u-point:", bc0, bcw, mesg, iounit)
1318 elseif (do_corners)
then
1320 bcsw =
subchk(array, hi, -hshift-1, -hshift, scaling)
1321 bcnw =
subchk(array, hi, -hshift-1, hshift, scaling)
1323 bcsw =
subchk(array, hi, -hshift, -hshift, scaling)
1324 bcnw =
subchk(array, hi, -hshift, hshift, scaling)
1326 bcse =
subchk(array, hi, hshift, -hshift, scaling)
1327 bcne =
subchk(array, hi, hshift, hshift, scaling)
1330 call chk_sum_msg(
"u-point:", bc0, bcsw, bcse, bcnw, bcne, mesg, iounit)
1332 bcs =
subchk(array, hi, 0, -hshift, scaling)
1333 bce =
subchk(array, hi, hshift, 0, scaling)
1335 bcw =
subchk(array, hi, -hshift-1, 0, scaling)
1337 bcw =
subchk(array, hi, -hshift, 0, scaling)
1339 bcn =
subchk(array, hi, 0, hshift, scaling)
1342 call chk_sum_msg_nsew(
"u-point:", bc0, bcn, bcs, bce, bcw, mesg, iounit)
1347 integer function subchk(array, HI, di, dj, scale)
1348 type(hor_index_type),
intent(in) :: HI
1349 real,
dimension(HI%IsdB:,HI%jsd:,:),
intent(in) :: array
1350 integer,
intent(in) :: di
1351 integer,
intent(in) :: dj
1352 real,
intent(in) :: scale
1353 integer :: i, j, k, bc
1356 do k=lbound(array,3),ubound(array,3) ;
do j=hi%jsc+dj,hi%jec+dj ;
do i=hi%isc+di,hi%iec+di
1357 bc = bitcount(abs(scale*array(i,j,k)))
1359 enddo ;
enddo ;
enddo
1360 call sum_across_pes(
subchk)
1364 subroutine substats(HI, array, sym_stats, aMean, aMin, aMax)
1365 type(hor_index_type),
intent(in) :: HI
1366 real,
dimension(HI%IsdB:,HI%jsd:,:),
intent(in) :: array
1367 logical,
intent(in) :: sym_stats
1369 real,
intent(out) :: aMean, aMin, aMax
1371 integer :: i, j, k, n, IsB
1373 isb = hi%isc ;
if (sym_stats) isb = hi%isc-1
1375 amin = array(hi%isc,hi%jsc,1) ; amax = amin
1376 do k=lbound(array,3),ubound(array,3) ;
do j=hi%jsc,hi%jec ;
do i=isb,hi%IecB
1377 amin = min(amin, array(i,j,k))
1378 amax = max(amax, array(i,j,k))
1379 enddo ;
enddo ;
enddo
1381 amean = reproducing_sum(array(hi%isc:hi%iec,hi%jsc:hi%jec,:))
1382 n = (1 + hi%jec - hi%jsc) * (1 + hi%iec - hi%isc) *
size(array,3)
1383 call sum_across_pes(n)
1384 call min_across_pes(amin)
1385 call max_across_pes(amax)
1386 amean = amean / real(n)