134 & LBi, UBi, LBj, UBj, LBij, UBij, &
135 & IminS, ImaxS, JminS, JmaxS, &
138 & rmask, umask, vmask, &
140# ifdef ADJUST_BOUNDARY
142 & tl_t_obc, tl_u_obc, tl_v_obc, &
144 & tl_ubar_obc, tl_vbar_obc, &
147# ifdef ADJUST_WSTRESS
178 integer,
intent(in) :: ng, tile
179 integer,
intent(in) :: LBi, UBi, LBj, UBj, LBij, UBij
180 integer,
intent(in) :: IminS, ImaxS, JminS, JmaxS
181 integer,
intent(in) :: Lsum
185 real(r8),
intent(in) :: rmask(LBi:,LBj:)
186 real(r8),
intent(in) :: umask(LBi:,LBj:)
187 real(r8),
intent(in) :: vmask(LBi:,LBj:)
189# ifdef ADJUST_BOUNDARY
191 real(r8),
intent(in) :: tl_t_obc(LBij:,:,:,:,:,:)
192 real(r8),
intent(in) :: tl_u_obc(LBij:,:,:,:,:)
193 real(r8),
intent(in) :: tl_v_obc(LBij:,:,:,:,:)
195 real(r8),
intent(in) :: tl_ubar_obc(LBij:,:,:,:)
196 real(r8),
intent(in) :: tl_vbar_obc(LBij:,:,:,:)
197 real(r8),
intent(in) :: tl_zeta_obc(LBij:,:,:,:)
199# ifdef ADJUST_WSTRESS
200 real(r8),
intent(in) :: tl_ustr(LBi:,LBj:,:,:)
201 real(r8),
intent(in) :: tl_vstr(LBi:,LBj:,:,:)
205 real(r8),
intent(in) :: tl_tflux(LBi:,LBj:,:,:,:)
207 real(r8),
intent(in) :: tl_t(LBi:,LBj:,:,:,:)
208 real(r8),
intent(in) :: tl_u(LBi:,LBj:,:,:)
209 real(r8),
intent(in) :: tl_v(LBi:,LBj:,:,:)
211 real(r8),
intent(in) :: tl_ubar(LBi:,LBj:,:)
212 real(r8),
intent(in) :: tl_vbar(LBi:,LBj:,:)
214 real(r8),
intent(in) :: tl_zeta(LBi:,LBj:,:)
219 real(r8),
intent(in) :: rmask(LBi:UBi,LBj:UBj)
220 real(r8),
intent(in) :: umask(LBi:UBi,LBj:UBj)
221 real(r8),
intent(in) :: vmask(LBi:UBi,LBj:UBj)
223# ifdef ADJUST_BOUNDARY
225 real(r8),
intent(in) :: tl_t_obc(LBij:UBij,N(ng),4, &
226 & Nbrec(ng),2,NT(ng))
227 real(r8),
intent(in) :: tl_u_obc(LBij:UBij,N(ng),4,Nbrec(ng),2)
228 real(r8),
intent(in) :: tl_v_obc(LBij:UBij,N(ng),4,Nbrec(ng),2)
230 real(r8),
intent(in) :: tl_ubar_obc(LBij:UBij,4,Nbrec(ng),2)
231 real(r8),
intent(in) :: tl_vbar_obc(LBij:UBij,4,Nbrec(ng),2)
232 real(r8),
intent(in) :: tl_zeta_obc(LBij:UBij,4,Nbrec(ng),2)
234# ifdef ADJUST_WSTRESS
235 real(r8),
intent(in) :: tl_ustr(LBi:UBi,LBj:UBj,Nfrec(ng),2)
236 real(r8),
intent(in) :: tl_vstr(LBi:UBi,LBj:UBj,Nfrec(ng),2)
240 real(r8),
intent(in) :: tl_tflux(LBi:UBi,LBj:UBj, &
241 & Nfrec(ng),2,NT(ng))
243 real(r8),
intent(in) :: tl_t(LBi:UBi,LBj:UBj,N(ng),3,NT(ng))
244 real(r8),
intent(in) :: tl_u(LBi:UBi,LBj:UBj,N(ng),2)
245 real(r8),
intent(in) :: tl_v(LBi:UBi,LBj:UBj,N(ng),2)
247 real(r8),
intent(in) :: tl_ubar(LBi:UBi,LBj:UBj,:)
248 real(r8),
intent(in) :: tl_vbar(LBi:UBi,LBj:UBj,:)
250 real(r8),
intent(in) :: tl_zeta(LBi:UBi,LBj:UBj,:)
255 integer :: NSUB, i, ib, ir, j, k
260 real(r8),
dimension(0:NstateVar(ng)) :: my_BackCost
262 real(r8) :: cff1, cff2
265 character (len=3),
dimension(0:NstateVar(ng)) :: op_handle
268# include "set_bounds.h"
281 my_backcost(i)=0.0_r8
288 cff1=tl_zeta(i,j,lsum)
292 cff2=0.5_r8*cff1*cff1
293 my_backcost(0)=my_backcost(0)+cff2
298# ifdef ADJUST_BOUNDARY
305 &
domain(ng)%Western_Edge(tile))
THEN
308 cff1=tl_zeta_obc(j,ib,ir,lsum)
310 cff1=cff1*rmask(istr-1,j)
312 cff2=0.5_r8*cff1*cff1
313 my_backcost(0)=my_backcost(0)+cff2
318 &
domain(ng)%Eastern_Edge(tile))
THEN
321 cff1=tl_zeta_obc(j,ib,ir,lsum)
323 cff1=cff1*rmask(iend+1,j)
325 cff2=0.5_r8*cff1*cff1
326 my_backcost(0)=my_backcost(0)+cff2
331 &
domain(ng)%Southern_Edge(tile))
THEN
334 cff1=tl_zeta_obc(i,ib,ir,lsum)
336 cff1=cff1*rmask(i,jstr-1)
338 cff2=0.5_r8*cff1*cff1
339 my_backcost(0)=my_backcost(0)+cff2
344 &
domain(ng)%Northern_Edge(tile))
THEN
347 cff1=tl_zeta_obc(i,ib,ir,lsum)
349 cff1=cff1*rmask(i,jend+1)
351 cff2=0.5_r8*cff1*cff1
352 my_backcost(0)=my_backcost(0)+cff2
366 cff1=tl_ubar(i,j,lsum)
370 cff2=0.5_r8*cff1*cff1
371 my_backcost(0)=my_backcost(0)+cff2
377# ifdef ADJUST_BOUNDARY
384 &
domain(ng)%Western_Edge(tile))
THEN
387 cff1=tl_ubar_obc(j,ib,ir,lsum)
389 cff1=cff1*umask(istr,j)
391 cff2=0.5_r8*cff1*cff1
392 my_backcost(0)=my_backcost(0)+cff2
397 &
domain(ng)%Eastern_Edge(tile))
THEN
400 cff1=tl_ubar_obc(j,ib,ir,lsum)
402 cff1=cff1*umask(iend+1,j)
404 cff2=0.5_r8*cff1*cff1
405 my_backcost(0)=my_backcost(0)+cff2
410 &
domain(ng)%Southern_Edge(tile))
THEN
413 cff1=tl_ubar_obc(i,ib,ir,lsum)
415 cff1=cff1*umask(i,jstr-1)
417 cff2=0.5_r8*cff1*cff1
418 my_backcost(0)=my_backcost(0)+cff2
423 &
domain(ng)%Northern_Edge(tile))
THEN
426 cff1=tl_ubar_obc(i,ib,ir,lsum)
428 cff1=cff1*umask(i,jend+1)
430 cff2=0.5_r8*cff1*cff1
431 my_backcost(0)=my_backcost(0)+cff2
445 cff1=tl_vbar(i,j,lsum)
449 cff2=0.5_r8*cff1*cff1
450 my_backcost(0)=my_backcost(0)+cff2
456# ifdef ADJUST_BOUNDARY
463 &
domain(ng)%Western_Edge(tile))
THEN
466 cff1=tl_vbar_obc(j,ib,ir,lsum)
468 cff1=cff1*vmask(istr-1,j)
470 cff2=0.5_r8*cff1*cff1
471 my_backcost(0)=my_backcost(0)+cff2
476 &
domain(ng)%Eastern_Edge(tile))
THEN
479 cff1=tl_vbar_obc(j,ib,ir,lsum)
481 cff1=cff1*vmask(iend+1,j)
483 cff2=0.5_r8*cff1*cff1
484 my_backcost(0)=my_backcost(0)+cff2
489 &
domain(ng)%Southern_Edge(tile))
THEN
492 cff1=tl_vbar_obc(i,ib,ir,lsum)
494 cff1=cff1*vmask(i,jstr)
496 cff2=0.5_r8*cff1*cff1
497 my_backcost(0)=my_backcost(0)+cff2
502 &
domain(ng)%Northern_Edge(tile))
THEN
505 cff1=tl_vbar_obc(i,ib,ir,lsum)
507 cff1=cff1*vmask(i,jend+1)
509 cff2=0.5_r8*cff1*cff1
510 my_backcost(0)=my_backcost(0)+cff2
518# ifdef ADJUST_WSTRESS
525 cff1=tl_ustr(i,j,ir,lsum)
529 cff2=0.5_r8*cff1*cff1
530 my_backcost(0)=my_backcost(0)+cff2
536 cff1=tl_vstr(i,j,ir,lsum)
540 cff2=0.5_r8*cff1*cff1
541 my_backcost(0)=my_backcost(0)+cff2
555 cff1=tl_u(i,j,k,lsum)
559 cff2=0.5_r8*cff1*cff1
560 my_backcost(0)=my_backcost(0)+cff2
566# ifdef ADJUST_BOUNDARY
573 &
domain(ng)%Western_Edge(tile))
THEN
577 cff1=tl_u_obc(j,k,ib,ir,lsum)
579 cff1=cff1*umask(istr,j)
581 cff2=0.5_r8*cff1*cff1
582 my_backcost(0)=my_backcost(0)+cff2
588 &
domain(ng)%Eastern_Edge(tile))
THEN
592 cff1=tl_u_obc(j,k,ib,ir,lsum)
594 cff1=cff1*umask(iend+1,j)
596 cff2=0.5_r8*cff1*cff1
597 my_backcost(0)=my_backcost(0)+cff2
603 &
domain(ng)%Southern_Edge(tile))
THEN
607 cff1=tl_u_obc(i,k,ib,ir,lsum)
609 cff1=cff1*umask(i,jstr-1)
611 cff2=0.5_r8*cff1*cff1
612 my_backcost(0)=my_backcost(0)+cff2
618 &
domain(ng)%Northern_Edge(tile))
THEN
622 cff1=tl_u_obc(i,k,ib,ir,lsum)
624 cff1=cff1*umask(i,jend+1)
626 cff2=0.5_r8*cff1*cff1
627 my_backcost(0)=my_backcost(0)+cff2
641 cff1=tl_v(i,j,k,lsum)
645 cff2=0.5_r8*cff1*cff1
646 my_backcost(0)=my_backcost(0)+cff2
652# ifdef ADJUST_BOUNDARY
659 &
domain(ng)%Western_Edge(tile))
THEN
663 cff1=tl_v_obc(j,k,ib,ir,lsum)
665 cff1=cff1*vmask(istr-1,j)
667 cff2=0.5_r8*cff1*cff1
668 my_backcost(0)=my_backcost(0)+cff2
674 &
domain(ng)%Eastern_Edge(tile))
THEN
678 cff1=tl_v_obc(j,k,ib,ir,lsum)
680 cff1=cff1*vmask(iend+1,j)
682 cff2=0.5_r8*cff1*cff1
683 my_backcost(0)=my_backcost(0)+cff2
689 &
domain(ng)%Southern_Edge(tile))
THEN
693 cff1=tl_v_obc(i,k,ib,ir,lsum)
695 cff1=cff1*vmask(i,jstr)
697 cff2=0.5_r8*cff1*cff1
698 my_backcost(0)=my_backcost(0)+cff2
704 &
domain(ng)%Northern_Edge(tile))
THEN
708 cff1=tl_v_obc(i,k,ib,ir,lsum)
710 cff1=cff1*vmask(i,jend+1)
712 cff2=0.5_r8*cff1*cff1
713 my_backcost(0)=my_backcost(0)+cff2
728 cff1=tl_t(i,j,k,lsum,itrc)
732 cff2=0.5_r8*cff1*cff1
733 my_backcost(0)=my_backcost(0)+cff2
734 my_backcost(
istvar(itrc))=my_backcost(
istvar(itrc))+cff2
740# ifdef ADJUST_BOUNDARY
748 &
domain(ng)%Western_Edge(tile))
THEN
752 cff1=tl_t_obc(j,k,ib,ir,lsum,itrc)
754 cff1=cff1*rmask(istr-1,j)
756 cff2=0.5_r8*cff1*cff1
757 my_backcost(0)=my_backcost(0)+cff2
764 &
domain(ng)%Eastern_Edge(tile))
THEN
768 cff1=tl_t_obc(j,k,ib,ir,lsum,itrc)
770 cff1=cff1*rmask(iend+1,j)
772 cff2=0.5_r8*cff1*cff1
773 my_backcost(0)=my_backcost(0)+cff2
780 &
domain(ng)%Southern_Edge(tile))
THEN
784 cff1=tl_t_obc(i,k,ib,ir,lsum,itrc)
786 cff1=cff1*rmask(i,jstr-1)
788 cff2=0.5_r8*cff1*cff1
789 my_backcost(0)=my_backcost(0)+cff2
796 &
domain(ng)%Northern_Edge(tile))
THEN
800 cff1=tl_t_obc(i,k,ib,ir,lsum,itrc)
802 cff1=cff1*rmask(i,jend+1)
804 cff2=0.5_r8*cff1*cff1
805 my_backcost(0)=my_backcost(0)+cff2
825 cff1=tl_tflux(i,j,ir,lsum,itrc)
829 cff2=0.5_r8*cff1*cff1
830 my_backcost(0)=my_backcost(0)+cff2
831 my_backcost(
istsur(itrc))=my_backcost(
istsur(itrc))+cff2
847 IF (
domain(ng)%SouthWest_Corner(tile).and. &
848 &
domain(ng)%NorthEast_Corner(tile))
THEN
857 fourdvar(ng)%BackCost(i)=my_backcost(i)
873 &
fourdvar(ng)%BackCost(0:), op_handle(0:))