Checksums a 3d array staggered at tracer points.
1204 type(hor_index_type),
target,
intent(in) :: HI_m
1205 real,
dimension(HI_m%isd:,HI_m%jsd:,:),
target,
intent(in) :: array_m
1206 character(len=*),
intent(in) :: mesg
1207 integer,
optional,
intent(in) :: haloshift
1208 logical,
optional,
intent(in) :: omit_corners
1209 real,
optional,
intent(in) :: scale
1210 integer,
optional,
intent(in) :: logunit
1212 real,
pointer :: array(:,:,:)
1213 real,
allocatable,
dimension(:,:,:) :: rescaled_array
1214 type(hor_index_type),
pointer :: HI
1218 real :: aMean, aMin, aMax
1219 integer :: bc0, bcSW, bcSE, bcNW, bcNE, hshift
1220 integer :: bcN, bcS, bcE, bcW
1221 logical :: do_corners
1226 if (modulo(turns, 4) /= 0)
then
1228 call rotate_hor_index(hi_m, -turns, hi)
1229 allocate(array(hi%isd:hi%ied, hi%jsd:hi%jed,
size(array_m, 3)))
1230 call rotate_array(array_m, -turns, array)
1236 if (checkfornans)
then
1237 if (is_nan(array(hi%isc:hi%iec,hi%jsc:hi%jec,:))) &
1238 call chksum_error(fatal,
'NaN detected: '//trim(mesg))
1243 scaling = 1.0 ;
if (
present(scale)) scaling = scale
1244 iounit = error_unit;
if(
present(logunit)) iounit = logunit
1246 if (calculatestatistics)
then
1247 if (
present(scale))
then
1248 allocate( rescaled_array(lbound(array,1):ubound(array,1), &
1249 lbound(array,2):ubound(array,2), &
1250 lbound(array,3):ubound(array,3)) )
1251 rescaled_array(:,:,:) = 0.0
1252 do k=1,
size(array,3) ;
do j=hi%jsc,hi%jec ;
do i=hi%isc,hi%iec
1253 rescaled_array(i,j,k) = scale*array(i,j,k)
1254 enddo ;
enddo ;
enddo
1256 call substats(hi, rescaled_array, amean, amin, amax)
1257 deallocate(rescaled_array)
1259 call substats(hi, array, amean, amin, amax)
1263 call chk_sum_msg(
"h-point:", amean, amin, amax, mesg, iounit)
1266 if (.not.writechksums)
return
1268 hshift = default_shift
1269 if (
present(haloshift)) hshift = haloshift
1270 if (hshift<0) hshift = hi%ied-hi%iec
1272 if ( hi%isc-hshift<hi%isd .or. hi%iec+hshift>hi%ied .or. &
1273 hi%jsc-hshift<hi%jsd .or. hi%jec+hshift>hi%jed )
then
1274 write(0,*)
'chksum_h_3d: haloshift =',hshift
1275 write(0,*)
'chksum_h_3d: isd,isc,iec,ied=',hi%isd,hi%isc,hi%iec,hi%ied
1276 write(0,*)
'chksum_h_3d: jsd,jsc,jec,jed=',hi%jsd,hi%jsc,hi%jec,hi%jed
1277 call chksum_error(fatal,
'Error in chksum_h_3d '//trim(mesg))
1280 bc0 = subchk(array, hi, 0, 0, scaling)
1283 if (is_root_pe())
call chk_sum_msg(
"h-point:", bc0, mesg, iounit)
1287 do_corners = .true. ;
if (
present(omit_corners)) do_corners = .not.omit_corners
1289 if (do_corners)
then
1290 bcsw = subchk(array, hi, -hshift, -hshift, scaling)
1291 bcse = subchk(array, hi, hshift, -hshift, scaling)
1292 bcnw = subchk(array, hi, -hshift, hshift, scaling)
1293 bcne = subchk(array, hi, hshift, hshift, scaling)
1296 call chk_sum_msg(
"h-point:", bc0, bcsw, bcse, bcnw, bcne, mesg, iounit)
1298 bcs = subchk(array, hi, 0, -hshift, scaling)
1299 bce = subchk(array, hi, hshift, 0, scaling)
1300 bcw = subchk(array, hi, -hshift, 0, scaling)
1301 bcn = subchk(array, hi, 0, hshift, scaling)
1304 call chk_sum_msg_nsew(
"h-point:", bc0, bcn, bcs, bce, bcw, mesg, iounit)
1309 integer function subchk(array, HI, di, dj, scale)
1310 type(hor_index_type),
intent(in) :: HI
1311 real,
dimension(HI%isd:,HI%jsd:,:),
intent(in) :: array
1312 integer,
intent(in) :: di
1313 integer,
intent(in) :: dj
1314 real,
intent(in) :: scale
1315 integer :: i, j, k, bc
1317 do k=lbound(array,3),ubound(array,3) ;
do j=hi%jsc+dj,hi%jec+dj ;
do i=hi%isc+di,hi%iec+di
1318 bc = bitcount(abs(scale*array(i,j,k)))
1319 subchk = subchk + bc
1320 enddo ;
enddo ;
enddo
1321 call sum_across_pes(subchk)
1322 subchk=mod(subchk, bc_modulus)
1325 subroutine substats(HI, array, aMean, aMin, aMax)
1326 type(hor_index_type),
intent(in) :: HI
1327 real,
dimension(HI%isd:,HI%jsd:,:),
intent(in) :: array
1328 real,
intent(out) :: aMean
1329 real,
intent(out) :: aMin
1330 real,
intent(out) :: aMax
1332 integer :: i, j, k, n
1334 amin = array(hi%isc,hi%jsc,1)
1335 amax = array(hi%isc,hi%jsc,1)
1337 do k=lbound(array,3),ubound(array,3) ;
do j=hi%jsc,hi%jec ;
do i=hi%isc,hi%iec
1338 amin = min(amin, array(i,j,k))
1339 amax = max(amax, array(i,j,k))
1341 enddo ;
enddo ;
enddo
1342 amean = reproducing_sum(array(hi%isc:hi%iec,hi%jsc:hi%jec,:))
1343 call sum_across_pes(n)
1344 call min_across_pes(amin)
1345 call max_across_pes(amax)
1346 amean = amean / real(n)
1347 end subroutine substats