10 use mom_domains,
only : sum_across_pes, min_across_pes, max_across_pes
17 implicit none ;
private
28 #include <MOM_memory.h>
32 real :: minimum = 1.e34
33 real :: maximum = -1.e34
42 subroutine mom_state_chksum_5arg(mesg, u, v, h, uh, vh, G, GV, US, haloshift, symmetric, vel_scale)
47 real,
dimension(SZIB_(G),SZJ_(G),SZK_(G)), &
49 real,
dimension(SZI_(G),SZJB_(G),SZK_(G)), &
51 real,
dimension(SZI_(G),SZJ_(G),SZK_(G)), &
53 real,
dimension(SZIB_(G),SZJ_(G),SZK_(G)), &
56 real,
dimension(SZI_(G),SZJB_(G),SZK_(G)), &
60 integer,
optional,
intent(in) :: haloshift
61 logical,
optional,
intent(in) :: symmetric
63 real,
optional,
intent(in) :: vel_scale
67 integer :: is, ie, js, je, nz, hs
68 is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = g%ke
73 hs = 1 ;
if (
present(haloshift)) hs=haloshift
74 sym = .false. ;
if (
present(symmetric)) sym=symmetric
75 scale_vel = us%L_T_to_m_s ;
if (
present(vel_scale)) scale_vel = vel_scale
77 call uvchksum(mesg//
" [uv]", u, v, g%HI, haloshift=hs, symmetric=sym, scale=scale_vel)
78 call hchksum(h, mesg//
" h", g%HI, haloshift=hs, scale=gv%H_to_m)
79 call uvchksum(mesg//
" [uv]h", uh, vh, g%HI, haloshift=hs, &
80 symmetric=sym, scale=gv%H_to_m*us%L_to_m**2*us%s_to_T)
87 character(len=*),
intent(in) :: mesg
90 real,
dimension(SZIB_(G),SZJ_(G),SZK_(G)), &
92 real,
dimension(SZI_(G),SZJB_(G),SZK_(G)), &
94 real,
dimension(SZI_(G),SZJ_(G),SZK_(G)), &
98 integer,
optional,
intent(in) :: haloshift
99 logical,
optional,
intent(in) :: symmetric
102 integer :: is, ie, js, je, nz, hs
105 is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = g%ke
106 l_t_to_m_s = 1.0 ;
if (
present(us)) l_t_to_m_s = us%L_T_to_m_s
111 hs=1;
if (
present(haloshift)) hs=haloshift
112 sym=.false.;
if (
present(symmetric)) sym=symmetric
113 call uvchksum(mesg//
" u", u, v, g%HI, haloshift=hs, symmetric=sym, scale=l_t_to_m_s)
114 call hchksum(h, mesg//
" h",g%HI, haloshift=hs, scale=gv%H_to_m)
121 character(len=*),
intent(in) :: mesg
126 integer,
optional,
intent(in) :: haloshift
128 integer :: is, ie, js, je, nz, hs
129 is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = g%ke
130 hs=1;
if (
present(haloshift)) hs=haloshift
132 if (
associated(tv%T))
call hchksum(tv%T, mesg//
" T",g%HI,haloshift=hs)
133 if (
associated(tv%S))
call hchksum(tv%S, mesg//
" S",g%HI,haloshift=hs)
134 if (
associated(tv%frazil))
call hchksum(tv%frazil, mesg//
" frazil",g%HI,haloshift=hs)
135 if (
associated(tv%salt_deficit)) &
136 call hchksum(tv%salt_deficit, mesg//
" salt deficit",g%HI,haloshift=hs, scale=us%R_to_kg_m3*us%Z_to_m)
144 character(len=*),
intent(in) :: mesg
145 type(
surface),
intent(inout) :: sfc
149 integer,
optional,
intent(in) :: haloshift
150 logical,
optional,
intent(in) :: symmetric
156 sym = .false. ;
if (
present(symmetric)) sym = symmetric
157 hs = 1 ;
if (
present(haloshift)) hs = haloshift
159 if (
allocated(sfc%SST))
call hchksum(sfc%SST, mesg//
" SST",g%HI,haloshift=hs)
160 if (
allocated(sfc%SSS))
call hchksum(sfc%SSS, mesg//
" SSS",g%HI,haloshift=hs)
161 if (
allocated(sfc%sea_lev))
call hchksum(sfc%sea_lev, mesg//
" sea_lev",g%HI,haloshift=hs)
162 if (
allocated(sfc%Hml))
call hchksum(sfc%Hml, mesg//
" Hml",g%HI,haloshift=hs)
163 if (
allocated(sfc%u) .and.
allocated(sfc%v)) &
164 call uvchksum(mesg//
" SSU", sfc%u, sfc%v, g%HI, haloshift=hs, symmetric=sym)
166 if (
associated(sfc%frazil))
call hchksum(sfc%frazil, mesg//
" frazil",g%HI,haloshift=hs)
173 subroutine mom_accel_chksum(mesg, CAu, CAv, PFu, PFv, diffu, diffv, G, GV, US, pbce, &
174 u_accel_bt, v_accel_bt, symmetric)
175 character(len=*),
intent(in) :: mesg
178 real,
dimension(SZIB_(G),SZJ_(G),SZK_(G)), &
181 real,
dimension(SZI_(G),SZJB_(G),SZK_(G)), &
184 real,
dimension(SZIB_(G),SZJ_(G),SZK_(G)), &
187 real,
dimension(SZI_(G),SZJB_(G),SZK_(G)), &
190 real,
dimension(SZIB_(G),SZJ_(G),SZK_(G)), &
193 real,
dimension(SZI_(G),SZJB_(G),SZK_(G)), &
197 real,
dimension(SZI_(G),SZJ_(G),SZK_(G)), &
198 optional,
intent(in) :: pbce
201 real,
dimension(SZIB_(G),SZJ_(G),SZK_(G)), &
202 optional,
intent(in) :: u_accel_bt
204 real,
dimension(SZI_(G),SZJB_(G),SZK_(G)), &
205 optional,
intent(in) :: v_accel_bt
207 logical,
optional,
intent(in) :: symmetric
210 integer :: is, ie, js, je, nz
213 is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = g%ke
214 sym=.false.;
if (
present(symmetric)) sym=symmetric
219 call uvchksum(mesg//
" CA[uv]", cau, cav, g%HI, haloshift=0, symmetric=sym, scale=us%L_T2_to_m_s2)
220 call uvchksum(mesg//
" PF[uv]", pfu, pfv, g%HI, haloshift=0, symmetric=sym, scale=us%L_T2_to_m_s2)
221 call uvchksum(mesg//
" diffu", diffu, diffv, g%HI,haloshift=0, symmetric=sym, scale=us%L_T2_to_m_s2)
223 call hchksum(pbce, mesg//
" pbce",g%HI,haloshift=0, scale=gv%m_to_H*us%L_T_to_m_s**2)
224 if (
present(u_accel_bt) .and.
present(v_accel_bt)) &
225 call uvchksum(mesg//
" [uv]_accel_bt", u_accel_bt, v_accel_bt, g%HI,haloshift=0, symmetric=sym, &
226 scale=us%L_T2_to_m_s2)
232 subroutine mom_state_stats(mesg, u, v, h, Temp, Salt, G, GV, US, allowChange, permitDiminishing)
235 character(len=*),
intent(in) :: mesg
236 real,
dimension(SZIB_(G),SZJ_(G),SZK_(G)), &
238 real,
dimension(SZI_(G),SZJB_(G),SZK_(G)), &
240 real,
dimension(SZI_(G),SZJ_(G),SZK_(G)), &
242 real,
pointer,
dimension(:,:,:), &
244 real,
pointer,
dimension(:,:,:), &
247 logical,
optional,
intent(in) :: allowchange
249 logical,
optional,
intent(in) :: permitdiminishing
257 type(
stats) :: t, s, delt, dels
261 type(
stats),
save :: oldt, olds
262 logical,
save :: firstcall = .true.
265 character(len=80) :: lmsg
266 integer :: is, ie, js, je, nz, i, j, k
268 is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = g%ke
269 do_ts =
associated(temp) .and.
associated(salt)
273 do j = js, je ;
do i = is, ie
274 area = area + us%L_to_m**2*g%areaT(i,j)
276 t%minimum = 1.e34 ; t%maximum = -1.e34 ; t%average = 0.
277 s%minimum = 1.e34 ; s%maximum = -1.e34 ; s%average = 0.
278 h_minimum = 1.e34*gv%m_to_H
279 do k = 1, nz ;
do j = js, je ;
do i = is, ie
280 if (g%mask2dT(i,j)>0.)
then
281 dv = us%L_to_m**2*g%areaT(i,j)*gv%H_to_m*h(i,j,k) ; vol = vol + dv
282 if (do_ts .and. h(i,j,k)>0.)
then
283 t%minimum = min( t%minimum, temp(i,j,k) ) ; t%maximum = max( t%maximum, temp(i,j,k) )
284 t%average = t%average + dv*temp(i,j,k)
285 s%minimum = min( s%minimum, salt(i,j,k) ) ; s%maximum = max( s%maximum, salt(i,j,k) )
286 s%average = s%average + dv*salt(i,j,k)
288 if (h_minimum > h(i,j,k)) h_minimum = h(i,j,k)
290 enddo ;
enddo ;
enddo
291 call sum_across_pes( area ) ;
call sum_across_pes( vol )
293 call min_across_pes( t%minimum ) ;
call max_across_pes( t%maximum ) ;
call sum_across_pes( t%average )
294 call min_across_pes( s%minimum ) ;
call max_across_pes( s%maximum ) ;
call sum_across_pes( s%average )
295 t%average = t%average / vol ; s%average = s%average / vol
298 if (.not.firstcall)
then
300 delt%minimum = t%minimum - oldt%minimum ; delt%maximum = t%maximum - oldt%maximum
301 delt%average = t%average - oldt%average
302 dels%minimum = s%minimum - olds%minimum ; dels%maximum = s%maximum - olds%maximum
303 dels%average = s%average - olds%average
304 write(lmsg(1:80),
'(2(a,es12.4))')
'Mean thickness =', vol/area,
' frac. delta=',dv/vol
307 write(lmsg(1:80),
'(a,3es12.4)')
'Temp min/mean/max =',t%minimum,t%average,t%maximum
309 write(lmsg(1:80),
'(a,3es12.4)')
'delT min/mean/max =',delt%minimum,delt%average,delt%maximum
311 write(lmsg(1:80),
'(a,3es12.4)')
'Salt min/mean/max =',s%minimum,s%average,s%maximum
313 write(lmsg(1:80),
'(a,3es12.4)')
'delS min/mean/max =',dels%minimum,dels%average,dels%maximum
317 write(lmsg(1:80),
'(a,es12.4)')
'Mean thickness =', vol/area
320 write(lmsg(1:80),
'(a,3es12.4)')
'Temp min/mean/max =', t%minimum, t%average, t%maximum
322 write(lmsg(1:80),
'(a,3es12.4)')
'Salt min/mean/max =', s%minimum, s%average, s%maximum
327 firstcall = .false. ; oldvol = vol
328 oldt%minimum = t%minimum ; oldt%maximum = t%maximum ; oldt%average = t%average
329 olds%minimum = s%minimum ; olds%maximum = s%maximum ; olds%average = s%average
331 if (do_ts .and. t%minimum<-5.0)
then
332 do j = js, je ;
do i = is, ie
333 if (minval(temp(i,j,:)) == t%minimum)
then
334 write(0,
'(a,2f12.5)')
'x,y=', g%geoLonT(i,j), g%geoLatT(i,j)
335 write(0,
'(a3,3a12)')
'k',
'h',
'Temp',
'Salt'
337 write(0,
'(i3,3es12.4)') k, h(i,j,k), temp(i,j,k), salt(i,j,k)
339 stop
'Extremum detected'
344 if (h_minimum<0.0)
then
345 do j = js, je ;
do i = is, ie
346 if (minval(h(i,j,:)) == h_minimum)
then
347 write(0,
'(a,2f12.5)')
'x,y=',g%geoLonT(i,j),g%geoLatT(i,j)
348 write(0,
'(a3,3a12)')
'k',
'h',
'Temp',
'Salt'
350 write(0,
'(i3,3es12.4)') k, h(i,j,k), temp(i,j,k), salt(i,j,k)
352 stop
'Negative thickness detected'