85
86
90#if defined ADJUST_BOUNDARY || defined ADJUST_STFLUX || \
91 defined adjust_wstress
93#endif
94#ifdef DISTRIBUTE
95
97#endif
98
99
100
101 integer, intent(in) :: ng, tile, model
102 integer, intent(in) :: LBi, UBi, LBj, UBj, LBij, UBij
103 integer, intent(in) :: NstateVars
104
105#ifdef ASSUMED_SHAPE
106# ifdef MASKING
107 real(r8), intent(in) :: rmask(LBi:,LBj:)
108 real(r8), intent(in) :: umask(LBi:,LBj:)
109 real(r8), intent(in) :: vmask(LBi:,LBj:)
110# endif
111# ifdef ADJUST_BOUNDARY
112# ifdef SOLVE3D
113 real(r8), intent(in) :: s1_t_obc(LBij:,:,:,:,:)
114 real(r8), intent(in) :: s2_t_obc(LBij:,:,:,:,:)
115 real(r8), intent(in) :: s1_u_obc(LBij:,:,:,:)
116 real(r8), intent(in) :: s2_u_obc(LBij:,:,:,:)
117 real(r8), intent(in) :: s1_v_obc(LBij:,:,:,:)
118 real(r8), intent(in) :: s2_v_obc(LBij:,:,:,:)
119# endif
120 real(r8), intent(in) :: s1_ubar_obc(LBij:,:,:)
121 real(r8), intent(in) :: s2_ubar_obc(LBij:,:,:)
122 real(r8), intent(in) :: s1_vbar_obc(LBij:,:,:)
123 real(r8), intent(in) :: s2_vbar_obc(LBij:,:,:)
124 real(r8), intent(in) :: s1_zeta_obc(LBij:,:,:)
125 real(r8), intent(in) :: s2_zeta_obc(LBij:,:,:)
126# endif
127# ifdef ADJUST_WSTRESS
128 real(r8), intent(in) :: s1_sustr(LBi:,LBj:,:)
129 real(r8), intent(in) :: s2_sustr(LBi:,LBj:,:)
130 real(r8), intent(in) :: s1_svstr(LBi:,LBj:,:)
131 real(r8), intent(in) :: s2_svstr(LBi:,LBj:,:)
132# endif
133# ifdef SOLVE3D
134# ifdef ADJUST_STFLUX
135 real(r8), intent(in) :: s1_tflux(LBi:,LBj:,:,:)
136 real(r8), intent(in) :: s2_tflux(LBi:,LBj:,:,:)
137# endif
138 real(r8), intent(in) :: s1_t(LBi:,LBj:,:,:)
139 real(r8), intent(in) :: s2_t(LBi:,LBj:,:,:)
140 real(r8), intent(in) :: s1_u(LBi:,LBj:,:)
141 real(r8), intent(in) :: s2_u(LBi:,LBj:,:)
142 real(r8), intent(in) :: s1_v(LBi:,LBj:,:)
143 real(r8), intent(in) :: s2_v(LBi:,LBj:,:)
144# else
145 real(r8), intent(in) :: s1_ubar(LBi:,LBj:)
146 real(r8), intent(in) :: s2_ubar(LBi:,LBj:)
147 real(r8), intent(in) :: s1_vbar(LBi:,LBj:)
148 real(r8), intent(in) :: s2_vbar(LBi:,LBj:)
149# endif
150 real(r8), intent(in) :: s1_zeta(LBi:,LBj:)
151 real(r8), intent(in) :: s2_zeta(LBi:,LBj:)
152
153#else
154
155# ifdef MASKING
156 real(r8), intent(in) :: rmask(LBi:UBi,LBj:UBj)
157 real(r8), intent(in) :: umask(LBi:UBi,LBj:UBj)
158 real(r8), intent(in) :: vmask(LBi:UBi,LBj:UBj)
159# endif
160
161# ifdef ADJUST_BOUNDARY
162# ifdef SOLVE3D
163 real(r8), intent(in) :: s1_t_obc(LBij:UBij,N(ng),4, &
164 & Nbrec(ng),NT(ng))
165 real(r8), intent(in) :: s2_t_obc(LBij:UBij,N(ng),4, &
166 & Nbrec(ng),NT(ng))
167 real(r8), intent(in) :: s1_u_obc(LBij:UBij,N(ng),4,Nbrec(ng))
168 real(r8), intent(in) :: s2_u_obc(LBij:UBij,N(ng),4,Nbrec(ng))
169 real(r8), intent(in) :: s1_v_obc(LBij:UBij,N(ng),4,Nbrec(ng))
170 real(r8), intent(in) :: s2_v_obc(LBij:UBij,N(ng),4,Nbrec(ng))
171# endif
172 real(r8), intent(in) :: s1_ubar_obc(LBij:UBij,4,Nbrec(ng))
173 real(r8), intent(in) :: s2_ubar_obc(LBij:UBij,4,Nbrec(ng))
174 real(r8), intent(in) :: s1_vbar_obc(LBij:UBij,4,Nbrec(ng))
175 real(r8), intent(in) :: s2_vbar_obc(LBij:UBij,4,Nbrec(ng))
176 real(r8), intent(in) :: s1_zeta_obc(LBij:UBij,4,Nbrec(ng))
177 real(r8), intent(in) :: s2_zeta_obc(LBij:UBij,4,Nbrec(ng))
178# endif
179# ifdef ADJUST_WSTRESS
180 real(r8), intent(in) :: s1_sustr(LBi:UBi,LBj:UBj,Nfrec(ng))
181 real(r8), intent(in) :: s2_sustr(LBi:UBi,LBj:UBj,Nfrec(ng))
182 real(r8), intent(in) :: s1_svstr(LBi:UBi,LBj:UBj,Nfrec(ng))
183 real(r8), intent(in) :: s2_svstr(LBi:UBi,LBj:UBj,Nfrec(ng))
184# endif
185# ifdef SOLVE3D
186# ifdef ADJUST_STFLUX
187 real(r8), intent(in) :: s1_tflux(LBi:UBi,LBj:UBj,Nfrec(ng),NT(ng))
188 real(r8), intent(in) :: s2_tflux(LBi:UBi,LBj:UBj,Nfrec(ng),NT(ng))
189# endif
190 real(r8), intent(in) :: s1_t(LBi:UBi,LBj:UBj,N(ng),NT(ng))
191 real(r8), intent(in) :: s2_t(LBi:UBi,LBj:UBj,N(ng),NT(ng))
192 real(r8), intent(in) :: s1_u(LBi:UBi,LBj:UBj,N(ng))
193 real(r8), intent(in) :: s2_u(LBi:UBi,LBj:UBj,N(ng))
194 real(r8), intent(in) :: s1_v(LBi:UBi,LBj:UBj,N(ng))
195 real(r8), intent(in) :: s2_v(LBi:UBi,LBj:UBj,N(ng))
196# else
197 real(r8), intent(in) :: s1_ubar(LBi:UBi,LBj:UBj)
198 real(r8), intent(in) :: s2_ubar(LBi:UBi,LBj:UBj)
199 real(r8), intent(in) :: s1_vbar(LBi:UBi,LBj:UBj)
200 real(r8), intent(in) :: s2_vbar(LBi:UBi,LBj:UBj)
201# endif
202 real(r8), intent(in) :: s1_zeta(LBi:UBi,LBj:UBj)
203 real(r8), intent(in) :: s2_zeta(LBi:UBi,LBj:UBj)
204#endif
205
206 real(r8), intent(out), dimension(0:NstateVars) :: DotProd
207
208
209
210 integer :: NSUB, i, j, k
211 integer :: ir, it
212
213 real(r8) :: cff
214 real(r8), dimension(0:NstateVars) :: my_DotProd
215#ifdef DISTRIBUTE
216 character (len=3), dimension(0:NstateVars) :: op_handle
217#endif
218
219#include "set_bounds.h"
220
221
222
223
224
225 DO i=0,nstatevars
226 my_dotprod(i)=0.0_r8
227 END DO
228
229
230
231 DO j=jstrt,jendt
232 DO i=istrt,iendt
233 cff=s1_zeta(i,j)*s2_zeta(i,j)
234#ifdef MASKING
235 cff=cff*rmask(i,j)
236#endif
237 my_dotprod(0)=my_dotprod(0)+cff
239 END DO
240 END DO
241
242#ifdef ADJUST_BOUNDARY
243
244
245
249 &
domain(ng)%Western_Edge(tile))
THEN
250 DO j=jstr,jend
251 cff=s1_zeta_obc(j,
iwest,ir)* &
252 & s2_zeta_obc(j,
iwest,ir)
253# ifdef MASKING
254 cff=cff*rmask(istr-1,j)
255# endif
256 my_dotprod(0)=my_dotprod(0)+cff
258 END DO
259 END IF
261 &
domain(ng)%Eastern_Edge(tile))
THEN
262 DO j=jstr,jend
263 cff=s1_zeta_obc(j,
ieast,ir)* &
264 & s2_zeta_obc(j,
ieast,ir)
265# ifdef MASKING
266 cff=cff*rmask(iend+1,j)
267# endif
268 my_dotprod(0)=my_dotprod(0)+cff
270 END DO
271 END IF
273 &
domain(ng)%Southern_Edge(tile))
THEN
274 DO i=istr,iend
275 cff=s1_zeta_obc(i,
isouth,ir)* &
276 & s2_zeta_obc(i,
isouth,ir)
277# ifdef MASKING
278 cff=cff*rmask(i,jstr-1)
279# endif
280 my_dotprod(0)=my_dotprod(0)+cff
282 END DO
283 END IF
285 &
domain(ng)%Northern_Edge(tile))
THEN
286 DO i=istr,iend
287 cff=s1_zeta_obc(i,
inorth,ir)* &
288 & s2_zeta_obc(i,
inorth,ir)
289# ifdef MASKING
290 cff=cff*rmask(i,jend+1)
291# endif
292 my_dotprod(0)=my_dotprod(0)+cff
294 END DO
295 END IF
296 END DO
297 END IF
298#endif
299
300#ifndef SOLVE3D
301
302
303
304 DO j=jstrt,jendt
305 DO i=istrp,iendt
306 cff=s1_ubar(i,j)*s2_ubar(i,j)
307# ifdef MASKING
308 cff=cff*umask(i,j)
309# endif
310 my_dotprod(0)=my_dotprod(0)+cff
312 END DO
313 END DO
314#endif
315
316#ifdef ADJUST_BOUNDARY
317
318
319
323 &
domain(ng)%Western_Edge(tile))
THEN
324 DO j=jstr,jend
325 cff=s1_ubar_obc(j,
iwest,ir)* &
326 & s2_ubar_obc(j,
iwest,ir)
327# ifdef MASKING
328 cff=cff*umask(istr,j)
329# endif
330 my_dotprod(0)=my_dotprod(0)+cff
332 END DO
333 END IF
335 &
domain(ng)%Eastern_Edge(tile))
THEN
336 DO j=jstr,jend
337 cff=s1_ubar_obc(j,
ieast,ir)* &
338 & s2_ubar_obc(j,
ieast,ir)
339# ifdef MASKING
340 cff=cff*umask(iend+1,j)
341# endif
342 my_dotprod(0)=my_dotprod(0)+cff
344 END DO
345 END IF
347 &
domain(ng)%Southern_Edge(tile))
THEN
348 DO i=istru,iend
349 cff=s1_ubar_obc(i,
isouth,ir)* &
350 & s2_ubar_obc(i,
isouth,ir)
351# ifdef MASKING
352 cff=cff*umask(i,jstr-1)
353# endif
354 my_dotprod(0)=my_dotprod(0)+cff
356 END DO
357 END IF
359 &
domain(ng)%Northern_Edge(tile))
THEN
360 DO i=istru,iend
361 cff=s1_ubar_obc(i,
inorth,ir)* &
362 & s2_ubar_obc(i,
inorth,ir)
363# ifdef MASKING
364 cff=cff*umask(i,jend+1)
365# endif
366 my_dotprod(0)=my_dotprod(0)+cff
368 END DO
369 END IF
370 END DO
371 END IF
372#endif
373
374#ifndef SOLVE3D
375
376
377
378 DO j=jstrp,jendt
379 DO i=istrt,iendt
380 cff=s1_vbar(i,j)*s2_vbar(i,j)
381# ifdef MASKING
382 cff=cff*vmask(i,j)
383# endif
384 my_dotprod(0)=my_dotprod(0)+cff
386 END DO
387 END DO
388#endif
389
390#ifdef ADJUST_BOUNDARY
391
392
393
397 &
domain(ng)%Western_Edge(tile))
THEN
398 DO j=jstrv,jend
399 cff=s1_vbar_obc(j,
iwest,ir)* &
400 & s2_vbar_obc(j,
iwest,ir)
401# ifdef MASKING
402 cff=cff*vmask(istr-1,j)
403# endif
404 my_dotprod(0)=my_dotprod(0)+cff
406 END DO
407 END IF
409 &
domain(ng)%Eastern_Edge(tile))
THEN
410 DO j=jstrv,jend
411 cff=s1_vbar_obc(j,
ieast,ir)* &
412 & s2_vbar_obc(j,
ieast,ir)
413# ifdef MASKING
414 cff=cff*vmask(iend+1,j)
415# endif
416 my_dotprod(0)=my_dotprod(0)+cff
418 END DO
419 END IF
421 &
domain(ng)%Southern_Edge(tile))
THEN
422 DO i=istr,iend
423 cff=s1_vbar_obc(i,
isouth,ir)* &
424 & s2_vbar_obc(i,
isouth,ir)
425# ifdef MASKING
426 cff=cff*vmask(i,jstr)
427# endif
428 my_dotprod(0)=my_dotprod(0)+cff
430 END DO
431 END IF
433 &
domain(ng)%Northern_Edge(tile))
THEN
434 DO i=istr,iend
435 cff=s1_vbar_obc(i,
inorth,ir)* &
436 & s2_vbar_obc(i,
inorth,ir)
437# ifdef MASKING
438 cff=cff*vmask(i,jend+1)
439# endif
440 my_dotprod(0)=my_dotprod(0)+cff
442 END DO
443 END IF
444 END DO
445 END IF
446#endif
447
448#ifdef ADJUST_WSTRESS
449
450
451
453 DO j=jstrt,jendt
454 DO i=istrp,iendt
455 cff=s1_sustr(i,j,ir)*s2_sustr(i,j,ir)
456# ifdef MASKING
457 cff=cff*umask(i,j)
458# endif
459 my_dotprod(0)=my_dotprod(0)+cff
461 END DO
462 END DO
463 DO j=jstrp,jendt
464 DO i=istrt,iendt
465 cff=s1_svstr(i,j,ir)*s2_svstr(i,j,ir)
466# ifdef MASKING
467 cff=cff*vmask(i,j)
468# endif
469 my_dotprod(0)=my_dotprod(0)+cff
471 END DO
472 END DO
473 END DO
474#endif
475
476#ifdef SOLVE3D
477
478
479
481 DO j=jstrt,jendt
482 DO i=istrp,iendt
483 cff=s1_u(i,j,k)*s2_u(i,j,k)
484# ifdef MASKING
485 cff=cff*umask(i,j)
486# endif
487 my_dotprod(0)=my_dotprod(0)+cff
489 END DO
490 END DO
491 END DO
492
493# ifdef ADJUST_BOUNDARY
494
495
496
500 &
domain(ng)%Western_Edge(tile))
THEN
502 DO j=jstr,jend
503 cff=s1_u_obc(j,k,
iwest,ir)* &
504 & s2_u_obc(j,k,
iwest,ir)
505# ifdef MASKING
506 cff=cff*umask(istr,j)
507# endif
508 my_dotprod(0)=my_dotprod(0)+cff
510 END DO
511 END DO
512 END IF
514 &
domain(ng)%Eastern_Edge(tile))
THEN
516 DO j=jstr,jend
517 cff=s1_u_obc(j,k,
ieast,ir)* &
518 & s2_u_obc(j,k,
ieast,ir)
519# ifdef MASKING
520 cff=cff*umask(iend+1,j)
521# endif
522 my_dotprod(0)=my_dotprod(0)+cff
524 END DO
525 END DO
526 END IF
528 &
domain(ng)%Southern_Edge(tile))
THEN
530 DO i=istru,iend
531 cff=s1_u_obc(i,k,
isouth,ir)* &
533# ifdef MASKING
534 cff=cff*umask(i,jstr-1)
535# endif
536 my_dotprod(0)=my_dotprod(0)+cff
538 END DO
539 END DO
540 END IF
542 &
domain(ng)%Northern_Edge(tile))
THEN
544 DO i=istru,iend
545 cff=s1_u_obc(i,k,
inorth,ir)* &
547# ifdef MASKING
548 cff=cff*umask(i,jend+1)
549# endif
550 my_dotprod(0)=my_dotprod(0)+cff
552 END DO
553 END DO
554 END IF
555 END DO
556 END IF
557# endif
558
559
560
562 DO j=jstrp,jendt
563 DO i=istrt,iendt
564 cff=s1_v(i,j,k)*s2_v(i,j,k)
565# ifdef MASKING
566 cff=cff*vmask(i,j)
567# endif
568 my_dotprod(0)=my_dotprod(0)+cff
570 END DO
571 END DO
572 END DO
573
574# ifdef ADJUST_BOUNDARY
575
576
577
581 &
domain(ng)%Western_Edge(tile))
THEN
583 DO j=jstrv,jend
584 cff=s1_v_obc(j,k,
iwest,ir)* &
585 & s2_v_obc(j,k,
iwest,ir)
586# ifdef MASKING
587 cff=cff*vmask(istr-1,j)
588# endif
589 my_dotprod(0)=my_dotprod(0)+cff
591 END DO
592 END DO
593 END IF
595 &
domain(ng)%Eastern_Edge(tile))
THEN
597 DO j=jstrv,jend
598 cff=s1_v_obc(j,k,
ieast,ir)* &
599 & s2_v_obc(j,k,
ieast,ir)
600# ifdef MASKING
601 cff=cff*vmask(iend+1,j)
602# endif
603 my_dotprod(0)=my_dotprod(0)+cff
605 END DO
606 END DO
607 END IF
609 &
domain(ng)%Southern_Edge(tile))
THEN
611 DO i=istr,iend
612 cff=s1_v_obc(i,k,
isouth,ir)* &
614# ifdef MASKING
615 cff=cff*vmask(i,jstr)
616# endif
617 my_dotprod(0)=my_dotprod(0)+cff
619 END DO
620 END DO
621 END IF
623 &
domain(ng)%Northern_Edge(tile))
THEN
625 DO i=istr,iend
626 cff=s1_v_obc(i,k,
inorth,ir)* &
628# ifdef MASKING
629 cff=cff*vmask(i,jend+1)
630# endif
631 my_dotprod(0)=my_dotprod(0)+cff
633 END DO
634 END DO
635 END IF
636 END DO
637 END IF
638# endif
639
640
641
644 DO j=jstrt,jendt
645 DO i=istrt,iendt
646 cff=s1_t(i,j,k,it)*s2_t(i,j,k,it)
647# ifdef MASKING
648 cff=cff*rmask(i,j)
649# endif
650 my_dotprod(0)=my_dotprod(0)+cff
652 END DO
653 END DO
654 END DO
655 END DO
656
657# ifdef ADJUST_BOUNDARY
658
659
660
665 &
domain(ng)%Western_Edge(tile))
THEN
667 DO j=jstr,jend
668 cff=s1_t_obc(j,k,
iwest,ir,it)* &
669 & s2_t_obc(j,k,
iwest,ir,it)
670# ifdef MASKING
671 cff=cff*rmask(istr-1,j)
672# endif
673 my_dotprod(0)=my_dotprod(0)+cff
675 END DO
676 END DO
677 END IF
679 &
domain(ng)%Eastern_Edge(tile))
THEN
681 DO j=jstr,jend
682 cff=s1_t_obc(j,k,
ieast,ir,it)* &
683 & s2_t_obc(j,k,
ieast,ir,it)
684# ifdef MASKING
685 cff=cff*rmask(iend+1,j)
686# endif
687 my_dotprod(0)=my_dotprod(0)+cff
689 END DO
690 END DO
691 END IF
693 &
domain(ng)%Southern_Edge(tile))
THEN
695 DO i=istr,iend
696 cff=s1_t_obc(i,k,
isouth,ir,it)* &
697 & s2_t_obc(i,k,
isouth,ir,it)
698# ifdef MASKING
699 cff=cff*rmask(i,jstr-1)
700# endif
701 my_dotprod(0)=my_dotprod(0)+cff
703 END DO
704 END DO
705 END IF
707 &
domain(ng)%Northern_Edge(tile))
THEN
709 DO i=istr,iend
710 cff=s1_t_obc(i,k,
inorth,ir,it)* &
711 & s2_t_obc(i,k,
inorth,ir,it)
712# ifdef MASKING
713 cff=cff*rmask(i,jend+1)
714# endif
715 my_dotprod(0)=my_dotprod(0)+cff
717 END DO
718 END DO
719 END IF
720 END DO
721 END IF
722 END DO
723# endif
724
725# ifdef ADJUST_STFLUX
726
727
728
732 DO j=jstrt,jendt
733 DO i=istrt,iendt
734 cff=s1_tflux(i,j,ir,it)*s2_tflux(i,j,ir,it)
735# ifdef MASKING
736 cff=cff*rmask(i,j)
737# endif
738 my_dotprod(0)=my_dotprod(0)+cff
740 END DO
741 END DO
742 END DO
743 END IF
744 END DO
745# endif
746
747#endif
748
749
750
751
752
753#ifdef DISTRIBUTE
754 nsub=1
755#else
756 IF (
domain(ng)%SouthWest_Corner(tile).and. &
757 &
domain(ng)%NorthEast_Corner(tile))
THEN
758 nsub=1
759 ELSE
761 END IF
762#endif
763
765 DO i=0,nstatevars
766 dotprod(i)=0.0_r8
767 END DO
768 END IF
769 DO i=0,nstatevars
770 dotprod(i)=dotprod(i)+my_dotprod(i)
771 END DO
775#ifdef DISTRIBUTE
776 DO i=0,nstatevars
777 op_handle(i)='SUM'
778 END DO
779 CALL mp_reduce (ng, model, nstatevars+1, dotprod(0:), &
780 & op_handle(0:))
781#endif
782 END IF
783
784
785 RETURN
integer, dimension(:), allocatable istvar
integer, dimension(:), allocatable istsur
integer, dimension(:), allocatable n
integer, dimension(:), allocatable ntilex
type(t_domain), dimension(:), allocatable domain
integer, dimension(:), allocatable ntilee
integer, dimension(:), allocatable nt
logical, dimension(:,:,:), allocatable lobc
logical, dimension(:,:), allocatable lstflux
integer, dimension(:), allocatable nfrec
integer, parameter isouth
integer, parameter inorth
integer, dimension(:), allocatable nbrec