forked from HYCOM/HYCOM-src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
latbdy.F90
4349 lines (4177 loc) · 148 KB
/
latbdy.F90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#if ! defined(RELO)
subroutine latbdf(n,lll)
use mod_xc ! HYCOM communication interface
use mod_cb_arrays ! HYCOM saved arrays
use mod_tides ! HYCOM tides
implicit none
!
integer n,lll
!
! --- apply lateral boundary conditions to barotropic flow field
!
! --- port flow version:
! --- NOT similar to the standard 'Browning and Kreiss' MICOM/HYCOM open
! --- boundary condition. This version uses algorithms based on a
! --- 1 invariant Flather boundary condition (setting the gradient
! --- of the incoming characteristic to zero).
!
! --- The tangential velocity is not constrained.
!
! --- see also: latbdp
!
! --- the code is as similar as possible to that for the standard case.
! --- so for example, 'speed' is in fact 1/SQRT(gH) which represents
! --- c1/g in the notation of (Bleck and Sun, Open boundary conditions
! --- for MICOM). The 1/g allows for the use of pressure fields.
!
! --- Note that East, West, North and South refers to the grid
! --- (i.e i,j points) and NOT geographic East, West, North and South
!
! --- the first call is made during initialization.
!
! --- Iris Lohmann, Carlos Lozano, NCEP, April 2006
!
logical, parameter :: ldebug_latbdf=.false.
!
integer, parameter :: mports=1 !maximum number of ports
!
integer, parameter :: nchar =120
!
logical lfatal,lfatalp
integer i,j,isec,ifrst,ilast,l
real aline(nchar), &
dline(itdm+jtdm),xline(itdm+jtdm), &
pline(itdm+jtdm),uline(itdm+jtdm)
real sum,svspin,fatal
character*3 char3
!
integer nports
integer lnport(mports),kdport(mports)
integer jfport(mports),jlport(mports), &
ifport(mports),ilport(mports)
real svpnow(mports),svport(mports)
save lnport
save svpnow,svport
save nports,kdport,ifport,ilport,jfport,jlport
!
real uportw(jtdm,mports),speedw(jtdm,mports),rspedw(jtdm,mports), &
uporte(jtdm,mports),speede(jtdm,mports),rspede(jtdm,mports), &
vportn(itdm,mports),speedn(itdm,mports),rspedn(itdm,mports), &
vports(itdm,mports),speeds(itdm,mports),rspeds(itdm,mports)
save uportw,speedw,rspedw,uporte,speede,rspede, &
vportn,speedn,rspedn,vports,speeds,rspeds
! tides stuff
integer npts_p,kdpt_p(mports), &
ifpt_p(mports),ilpt_p(mports), &
jfpt_p(mports),jlpt_p(mports),lnpt_p(mports)
integer npts_v,kdpt_v(mports), &
ifpt_v(mports),ilpt_v(mports), &
jfpt_v(mports),jlpt_v(mports),lnpt_v(mports)
integer npts_u,kdpt_u(mports), &
ifpt_u(mports),ilpt_u(mports), &
jfpt_u(mports),jlpt_u(mports),lnpt_u(mports)
! the max of itdm and jtdm is ok for any port
! number of tidal consituents (ncon) from mod_tides
real z1r_p(mports,max(jtdm,itdm),ncon)
real z1i_p(mports,max(jtdm,itdm),ncon)
real z1r_u(mports,max(jtdm,itdm),ncon)
real z1i_u(mports,max(jtdm,itdm),ncon)
real z1r_v(mports,max(jtdm,itdm),ncon)
real z1i_v(mports,max(jtdm,itdm),ncon)
real tmp1, tmp2
real tmpr(max(itdm,jtdm),ncon), tmpi(max(itdm,jtdm),ncon)
real upred(max(itdm,jtdm)),zpred(max(itdm,jtdm))
real udpred(max(itdm,jtdm))
real vpred(max(itdm,jtdm))
real ulow(max(itdm,jtdm),mports),plow(max(itdm,jtdm),mports)
real uu(max(itdm,jtdm)),vv(max(itdm,jtdm))
integer bnd_init(mports)
real*8 d_time
real*8 timermp,frmp
logical astroflag
integer jn,in,ic
save z1r_p, z1i_p
save z1r_u, z1i_u
save bnd_init
save ulow,plow
!
character*13 fmt
save fmt
data fmt / '(i4,1x,120i1)' /
!
! USER-INPUT: optimization coefficients for the 1 inv algorithm.
real w_1,w_1c
save w_1
data w_1 / 0.1 /
!
integer lcount
save lcount
data lcount / 0 /
!
! Comment out the next line to run without
! boundary tides
d_time = time_8 + lll*dlt/86400.d0
! add 15384 for obtaining mjd
lcount = lcount + 1
!
! set 1-invariant coefficient
w_1c=1.0-w_1
!
!
! --- the first call just initializes data structures.
!
if (lcount.eq.1) then
!
open(unit=uoff+99,file=trim(flnminp)//'ports.input')
!
! --- 'nports' = number of boundary port sections.
call blkini(nports,'nports')
if (mnproc.eq.1) then
write(lp,*)
endif
if (nports.eq.0) then
if (mnproc.eq.1) then
write(lp,*)
write(lp,*) 'error in latbdf - must have lbflag=0 for nports=0'
write(lp,*)
call flush(lp)
endif !1st tile
call xcstop('(latbdf)')
stop '(latbdf)'
elseif (nports.lt.0 .or. nports.gt.mports) then
if (mnproc.eq.1) then
write(lp,*)
write(lp,*) 'error in latbdf - illegal nports value'
if (nports.gt.mports) then
write(lp,*) 'increase parameter mports to',nports
endif
write(lp,*)
call flush(lp)
endif
call xcstop('(latbdf)')
stop '(latbdf)'
endif
!
! --- read in the ports one at a time
!
do l= 1,nports
!
! --- port location is w.r.t. u (EW) or v (NS) grid
! --- and identifies the sea at the port
! --- the minimum index is 0
!
! --- 'kdport' = port orientation (1=N, 2=S, 3=E, 4=W, 5=S(Fundy))
! --- 'ifport' = first i-index
! --- 'ilport' = last i-index (=ifport for N or S orientation)
! --- 'jfport' = first j-index
! --- 'jlport' = last j-index (=jfport for E or W orientation)
! --- 'svpnow' = existing port transport in Sv (+ve towards E or S)
! --- 'svport' = target port transport in Sv (+ve towards E or S)
! --- 'lnport' = port length (calculated, not input)
call blkini(kdport(l),'kdport')
call blkini(ifport(l),'ifport')
call blkini(ilport(l),'ilport')
call blkini(jfport(l),'jfport')
call blkini(jlport(l),'jlport')
call blkinr(svpnow(l),'svpnow','(a6," =",f10.4," Sv")')
call blkinr(svport(l),'svport','(a6," =",f10.4," Sv")')
if (mnproc.eq.1) then
write(lp,*)
endif
!
lnport(l) = ilport(l)-ifport(l)+jlport(l)-jfport(l)+1
!
! --- sanity check.
!
if (kdport(l).eq.3.or.kdport(l).eq.4) then
if (ifport(l).ne.ilport(l)) then
if (mnproc.eq.1) then
write(lp,*)
write(lp,*) 'error in latbdp - port direction', &
' and orientation are not consistent'
write(lp,*)
call flush(lp)
endif
call xcstop('(latbdp)')
stop '(latbdp)'
endif
else
if (jfport(l).ne.jlport(l)) then
if (mnproc.eq.1) then
write(lp,*)
write(lp,*) 'error in latbdp - port direction', &
' and orientation are not consistent'
write(lp,*)
call flush(lp)
endif
call xcstop('(latbdp)')
stop '(latbdp)'
endif
endif
if (ifport(l).gt.ilport(l) .or. &
jfport(l).gt.jlport(l) ) then
if (mnproc.eq.1) then
write(lp,*)
write(lp,*) 'error in latbdp - port', &
' location is not consistent'
write(lp,*)
call flush(lp)
endif
call xcstop('(latbdp)')
stop '(latbdp)'
endif
enddo
!
close(unit=uoff+99)
! **********************************************
!------ read low frequency input-file
! initialize the low-frequency u and eta to zero
do i = 1,max(itdm,jtdm)
do j = 1,mports
ulow(i,j) =0.0
plow(i,j) =0.0
enddo
enddo
open(unit=uoff+99,file=trim(flnminp)//'lowfreq.input')
! the file is read in order west, east, south, north
do l= 1,nports
if (kdport(l).eq.4) then
! western port
do j= jfport(l),jlport(l)
read(uoff+99,*) ulow(j,l),plow(j,l)
enddo
elseif (kdport(l).eq.3) then
! eastern port
do j= jfport(l),jlport(l)
read(uoff+99,*) ulow(j,l),plow(j,l)
enddo
elseif (kdport(l).eq.2) then
! southern port
do i= ifport(l),ilport(l)
read(uoff+99,*) ulow(i,l),plow(i,l)
enddo
elseif (kdport(l).eq.1) then
! northern port
do i= ifport(l),ilport(l)
read(uoff+99,*) ulow(i,l),plow(i,l)
enddo
endif !kdport
enddo !l=1,nports
close(uoff+99)
!************************************************
! ****** READ TIDAL CONSTITUENTS ****************
if (tidflg.ge.1) then
! initialize the tidal constituents to zero
do i = 1,mports
do j = 1,max(itdm,jtdm)
do ic = 1,ncon
z1r_p(i,j,ic) = 0.
z1i_p(i,j,ic) = 0.
z1r_u(i,j,ic) = 0.
z1i_u(i,j,ic) = 0.
z1r_v(i,j,ic) = 0.
z1i_v(i,j,ic) = 0.
enddo
enddo
enddo
do j = 1,max(itdm,jtdm)
uu(j) = 0.
vv(j) = 0.
upred(j) = 0.
vpred(j) = 0.
zpred(j) = 0.
enddo
! --------------------------------------------------------
! Now the P points
open(unit=uoff+99,file=trim(flnminp)//'tidalports_p.input')
! --- 'nports' = number of boundary port sections.
call blkini(npts_p,'npts_p')
if (mnproc.eq.1) then
write(lp,*)
endif
if (npts_p.ne.nports) then
if (mnproc.eq.1) then
write(lp,*)
write(lp,*) 'error number of ports needs to be same'
write(lp,*)
call flush(lp)
endif
call xcstop('(latbdp)')
stop '(latbdp)'
endif
do l= 1,nports
!
! --- port location is w.r.t. u (EW) or v (NS) grid
! --- and identifies the sea at the port
! --- the minimum index is 0
!
! --- 'kdport' = port orientation (1=N, 2=S, 3=E, 4=W, 5=Fundy(S))
! --- 'ifport' = first i-index
! --- 'ilport' = last i-index (=ifport for N or S orientation)
! --- 'jfport' = first j-index
! --- 'jlport' = last j-index (=jfport for E or W orientation)
! --- 'lnport' = port length (calculated, not input)
call blkini(kdpt_p(l),'kdpt_p')
if (kdpt_p(l).ne.kdport(l)) then
if (mnproc.eq.1) then
write(lp,*)
write(lp,*) 'Mismatch of the kdport'
write(lp,*)
call flush(lp)
endif
call xcstop('(latbdp)')
stop '(latbdp)'
endif
call blkini(ifpt_p(l),'ifpt_p')
if (ifpt_p(l).ne.ifport(l)) then
if (mnproc.eq.1) then
write(lp,*)
write(lp,*) 'Mismatch of the ifport'
write(lp,*)
call flush(lp)
endif
call xcstop('(latbdp)')
stop '(latbdp)'
endif
call blkini(ilpt_p(l),'ilpt_p')
if (ilpt_p(l).ne.ilport(l)) then
if (mnproc.eq.1) then
write(lp,*)
write(lp,*) 'Mismatch of the ilport'
write(lp,*)
call flush(lp)
endif
call xcstop('(latbdp)')
stop '(latbdp)'
endif
call blkini(jfpt_p(l),'jfpt_p')
if (jfpt_p(l).ne.jfport(l)) then
if (mnproc.eq.1) then
write(lp,*)
write(lp,*) 'Mismatch of the jfport'
write(lp,*)
call flush(lp)
endif
call xcstop('(latbdp)')
stop '(latbdp)'
endif
call blkini(jlpt_p(l),'jlpt_p')
if (jlpt_p(l).ne.jlport(l)) then
if (mnproc.eq.1) then
write(lp,*)
write(lp,*) 'Mismatch of the jlport'
write(lp,*)
call flush(lp)
endif
call xcstop('(latbdp)')
stop '(latbdp)'
endif
if (kdport(l).eq.4) then
!
! western port
!
do j= jfport(l),jlport(l)
do ic = 1, ncon
read(uoff+99,*) tmp1, tmp2
z1r_p(l,j,ic) = tmp1
z1i_p(l,j,ic) = tmp2
enddo
enddo
!
elseif (kdport(l).eq.3) then
!
! eastern port
do j= jfport(l),jlport(l)
do ic = 1, ncon
read(uoff+99,*) tmp1, tmp2
z1r_p(l,j,ic) = tmp1
z1i_p(l,j,ic) = tmp2
enddo
enddo
!
elseif (kdport(l).eq.1) then
!
! northern port
!
do i= ifport(l),ilport(l)
do ic = 1, ncon
read(uoff+99,*) tmp1, tmp2
z1r_p(l,i,ic) = tmp1
z1i_p(l,i,ic) = tmp2
enddo
enddo
!
elseif (kdport(l).eq.2) then
!
! southern port
!
do i= ifport(l),ilport(l)
do ic = 1, ncon
read(uoff+99,*) tmp1, tmp2
z1r_p(l,i,ic) = tmp1
z1i_p(l,i,ic) = tmp2
enddo
enddo
endif !kdport=
! Close the l = 1, nports loop
enddo !nports
close(uoff+99)
! -------------------------------------------------------------
! Now the normal-velocity points
open(unit=uoff+99,file=trim(flnminp)//'tidalports_v.input')
! --- 'nports' = number of boundary port sections.
call blkini(npts_u,'npts_u')
if (mnproc.eq.1) then
write(lp,*)
endif
if (npts_u.ne.nports) then
if (mnproc.eq.1) then
write(lp,*)
write(lp,*) 'error number of ports needs to be same'
write(lp,*)
call flush(lp)
endif
call xcstop('(latbdp)')
stop '(latbdp)'
endif
do l= 1,nports
!
! --- port location is w.r.t. u (EW) or v (NS) grid
! --- and identifies the sea at the port
! --- the minimum index is 0
!
! --- 'kdport' = port orientation (1=N, 2=S, 3=E, 4=W, 5=Fundy(S))
! --- 'ifport' = first i-index
! --- 'ilport' = last i-index (=ifport for N or S orientation)
! --- 'jfport' = first j-index
! --- 'jlport' = last j-index (=jfport for E or W orientation)
! --- 'svpnow' = existing port transport in Sv (+ve towards E or S)
! --- 'svport' = target port transport in Sv (+ve towards E or S)
! --- 'lnport' = port length (calculated, not input)
call blkini(kdpt_u(l),'kdpt_u')
if (kdpt_u(l).ne.kdport(l)) then
if (mnproc.eq.1) then
write(lp,*)
write(lp,*) 'Mismatch of the kdport'
write(lp,*)
call flush(lp)
endif
call xcstop('(latbdp)')
stop '(latbdp)'
endif
call blkini(ifpt_u(l),'ifpt_u')
if (ifpt_u(l).ne.ifport(l)) then
if (mnproc.eq.1) then
write(lp,*)
write(lp,*) 'Mismatch of the ifport'
write(lp,*)
call flush(lp)
endif
call xcstop('(latbdp)')
stop '(latbdp)'
endif
call blkini(ilpt_u(l),'ilpt_u')
if (ilpt_u(l).ne.ilport(l)) then
if (mnproc.eq.1) then
write(lp,*)
write(lp,*) 'Mismatch of the ilport'
write(lp,*)
call flush(lp)
endif
call xcstop('(latbdp)')
stop '(latbdp)'
endif
call blkini(jfpt_u(l),'jfpt_u')
if (jfpt_u(l).ne.jfport(l)) then
if (mnproc.eq.1) then
write(lp,*)
write(lp,*) 'Mismatch of the jfport'
write(lp,*)
call flush(lp)
endif
call xcstop('(latbdp)')
stop '(latbdp)'
endif
call blkini(jlpt_u(l),'jlpt_u')
if (jlpt_u(l).ne.jlport(l)) then
if (mnproc.eq.1) then
write(lp,*)
write(lp,*) 'Mismatch of the jlport'
write(lp,*)
call flush(lp)
endif
call xcstop('(latbdp)')
stop '(latbdp)'
endif
if (kdport(l).eq.4) then
!
! western port
!
do j= jfport(l),jlport(l)
do ic = 1, ncon
read(uoff+99,*) tmp1, tmp2
z1r_u(l,j,ic) = tmp1
z1i_u(l,j,ic) = tmp2
enddo
enddo
!
elseif (kdport(l).eq.3) then
!
! eastern port
do j= jfport(l),jlport(l)
do ic = 1, ncon
read(uoff+99,*) tmp1, tmp2
z1r_u(l,j,ic) = tmp1
z1i_u(l,j,ic) = tmp2
enddo
enddo
!
elseif (kdport(l).eq.1) then
!
! northern port
!
do i= ifport(l),ilport(l)
do ic = 1, ncon
read(uoff+99,*) tmp1, tmp2
z1r_u(l,i,ic) = tmp1
z1i_u(l,i,ic) = tmp2
enddo
enddo
!
elseif (kdport(l).eq.2) then
!
! southern port
!
do i= ifport(l),ilport(l)
do ic = 1, ncon
read(uoff+99,*) tmp1, tmp2
z1r_u(l,i,ic) = tmp1
z1i_u(l,i,ic) = tmp2
enddo
enddo
endif !kdport=
! Close the l = 1, nports loop
enddo !nports
close(uoff+99)
!*****************END OF READING THE TIDAL CONSTITUENTS
endif !tidflg.ge.1
!
! --- check ports against masks,
! --- mark the port locations on masks and print them out.
!
lfatal = .false.
do l= 1,nports
lfatalp = .false.
!
if (kdport(l).eq.4) then
!
! western port
!
i = ifport(l)
do j= jfport(l),jlport(l)
if (i.lt.1 .or. i.gt.itdm .or. &
j.lt.1 .or. j.gt.jtdm ) then
lfatalp = .true.
elseif (i.le.i0 .or. i.gt.i0+ii .or. &
j.le.j0 .or. j.gt.j0+jj ) then
cycle ! not on this tile.
elseif (iu(i-i0,j-j0).ne.0) then
lfatalp = .true.
iu(i-i0,j-j0) = 9 !indicate an error
else
iu(i-i0,j-j0) = -1
endif
if (iu(i-i0+1,j-j0).ne.1 .or. &
iu(i-i0+2,j-j0).ne.1 ) then
lfatalp = .true.
iu(i-i0,j-j0) = 7 !indicate an error
endif
enddo
!
elseif (kdport(l).eq.3) then
!
! eastern port
!
i = ifport(l)
do j= jfport(l),jlport(l)
if (i.lt.1 .or. i.gt.itdm .or. &
j.lt.1 .or. j.gt.jtdm ) then
lfatalp = .true.
elseif (i.le.i0 .or. i.gt.i0+ii .or. &
j.le.j0 .or. j.gt.j0+jj ) then
cycle ! not on this tile.
elseif (iu(i-i0,j-j0).ne.0) then
lfatalp = .true.
iu(i-i0,j-j0) = 9 !indicate an error
else
iu(i-i0,j-j0) = -1
endif
if (iu(i-i0-1,j-j0).ne.1 .or. &
iu(i-i0-2,j-j0).ne.1 ) then
lfatalp = .true.
iu(i-i0,j-j0) = 7 !indicate an error
endif
enddo
!
elseif (kdport(l).eq.1) then
!
! northern port
!
j = jfport(l)
do i= ifport(l),ilport(l)
if (i.lt.1 .or. i.gt.itdm .or. &
j.lt.3 .or. j.gt.jtdm ) then
lfatalp = .true.
elseif (i.le.i0 .or. i.gt.i0+ii .or. &
j.le.j0 .or. j.gt.j0+jj ) then
cycle ! not on this tile.
elseif (iv(i-i0,j-j0).ne.0) then
lfatalp = .true.
iv(i-i0,j-j0) = 9 !indicate an error
else
iv(i-i0,j-j0) = -1
endif
if (iv(i-i0,j-j0-1).ne.1 .or. &
iv(i-i0,j-j0-2).ne.1 ) then
lfatalp = .true.
iv(i-i0,j-j0) = 7 !indicate an error
endif
enddo
!
elseif (kdport(l).eq.2.or.kdport(l).eq.5) then
!
! southern port
!
j = jfport(l)
do i= ifport(l),ilport(l)
if (i.lt.1 .or. i.gt.itdm .or. &
j.lt.1 .or. j.gt.jtdm-2 ) then
lfatalp = .true.
elseif (i.le.i0 .or. i.gt.i0+ii .or. &
j.le.j0 .or. j.gt.j0+jj ) then
cycle ! not on this tile.
elseif (iv(i-i0,j-j0).ne.0) then
lfatalp = .true.
iv(i-i0,j-j0) = 9 !indicate an error
else
iv(i-i0,j-j0) = -1
endif
if (iv(i-i0,j-j0+1).ne.1 .or. &
iv(i-i0,j-j0+2).ne.1 ) then
lfatalp = .true.
iv(i-i0,j-j0) = 7 !indicate an error
endif
enddo
!
endif !kdport=
!
if (lfatalp) then
write(lp,*)
write(lp,*) 'error in latbdp - port ',l,' mislocated', &
' (mnproc = ',mnproc,')'
write(lp,*)
call flush(lp)
endif
lfatal = lfatal .or. lfatalp
enddo !nports
!
! local lfatal to global lfatal
!
if (lfatal) then
fatal = 1.0
else
fatal = 0.0
endif
call xcmaxr(fatal)
lfatal = fatal.gt.0.5
!
! --- write out -iu- and -iv- arrays, if they are not too big
! --- data are written in strips nchar points wide
if (lfatal .or. max(itdm,jtdm).le.2*nchar) then
util1(1:ii,1:jj) = iu(1:ii,1:jj) ! xclget is for real arrays
isec=(itdm-1)/nchar
do ifrst=0,nchar*isec,nchar
ilast=min(itdm,ifrst+nchar)
write (char3,'(i3)') ilast-ifrst
fmt(8:10)=char3
if (mnproc.eq.1) then
write (lp,'(a,i5,a,i5)') &
'iu array, cols',ifrst+1,' --',ilast
endif
do j= jtdm,1,-1
call xclget(aline,ilast-ifrst, util1,ifrst+1,j,1,0, 1)
if (mnproc.eq.1) then
write (lp,fmt) j,(nint(aline(i)),i=1,ilast-ifrst)
endif
enddo
enddo
if (mnproc.eq.1) then
write (lp,*)
endif
call xcsync(flush_lp)
!
util1(1:ii,1:jj) = iv(1:ii,1:jj) ! xclget is for real arrays
isec=(itdm-1)/nchar
do ifrst=0,nchar*isec,nchar
ilast=min(itdm,ifrst+nchar)
write (char3,'(i3)') ilast-ifrst
fmt(8:10)=char3
if (mnproc.eq.1) then
write (lp,'(a,i5,a,i5)') &
'iv array, cols',ifrst+1,' --',ilast
endif
do j= jtdm,1,-1
call xclget(aline,ilast-ifrst, util1,ifrst+1,j,1,0, 1)
if (mnproc.eq.1) then
write (lp,fmt) j,(nint(aline(i)),i=1,ilast-ifrst)
endif
enddo
enddo
if (mnproc.eq.1) then
write (lp,*)
endif
call xcsync(flush_lp)
endif ! small region
!
if (lfatal) then
write(lp,*)
write(lp,*) 'error in latbdp - bad port(s)'
write(lp,*)
call flush(lp)
call xchalt('(latbdp)')
stop '(latbdp)'
endif
!
! --- restore iu and iv, and zero iuopn and ivopn.
!
! $OMP PARALLEL DO PRIVATE(j,i)
! $OMP& SCHEDULE(STATIC,jblk)
do j= 1,jj
do i= 1,ii
iu(i,j) = max( iu(i,j), 0 )
iv(i,j) = max( iv(i,j), 0 )
enddo
enddo
! $OMP PARALLEL DO PRIVATE(j,i)
! $OMP& SCHEDULE(STATIC,jblk)
do j= 1-nbdy,jj+nbdy
do i= 1-nbdy,ii+nbdy
iuopn(i,j) = 0
ivopn(i,j) = 0
enddo
enddo
!
! --- initialize the ports
!
do l= 1,nports
if (kdport(l).eq.4) then
!
! western port
!
sum = 0.0
i = ifport(l)
j = jfport(l)
call xclget(dline(j),lnport(l), depths,i,j,0,1, 0)
call xclget(xline(j),lnport(l), scuy, i, j,0,1, 0)
do j= jfport(l),jlport(l)
sum = sum + dline(j)*xline(j)
enddo
sum = 1.e6/sum
do j= jfport(l),jlport(l)
uportw(j,l) = sum
speedw(j,l) = sqrt(1.0*svref/(onem*dline(j)))
rspedw(j,l) = 1.0/speedw(j,l)
if (i.ge.i0+ 1-nbdy .and. &
i.le.i0+ii+nbdy .and. &
j.ge.j0+ 1-nbdy .and. &
j.le.j0+jj+nbdy ) then
iuopn(i-i0,j-j0) = 1
endif
enddo
!
elseif (kdport(l).eq.3) then
!
! eastern port
!
sum = 0.0
i = ifport(l)-1
j = jfport(l)
call xclget(dline(j),lnport(l), depths,i, j,0,1, 0)
call xclget(xline(j),lnport(l), scuy, i+1,j,0,1, 0)
do j= jfport(l),jlport(l)
sum = sum + dline(j)*xline(j)
enddo
sum = 1.e6/sum
do j= jfport(l),jlport(l)
uporte(j,l) = sum
speede(j,l) = sqrt(1.0*svref/(onem*dline(j)))
rspede(j,l) = 1.0/speede(j,l)
if (i+1.ge.i0+ 1-nbdy .and. &
i+1.le.i0+ii+nbdy .and. &
j .ge.j0+ 1-nbdy .and. &
j .le.j0+jj+nbdy ) then
iuopn(i-i0+1,j-j0) = 1
endif
enddo
!
elseif (kdport(l).eq.1) then
!
! northern port
!
sum = 0.0
j = jfport(l)-1
i = ifport(l)
call xclget(dline(i),lnport(l), depths,i,j, 1,0, 0)
call xclget(xline(i),lnport(l), scuy, i,j+1,1,0, 0)
do i= ifport(l),ilport(l)
sum = sum + dline(i)*xline(i)
enddo
sum = 1.e6/sum
do i= ifport(l),ilport(l)
vportn(i,l) = sum
speedn(i,l) = sqrt(1.0*svref/(onem*dline(i)))
rspedn(i,l) = 1.0/speedn(i,l)
if (i .ge.i0+ 1-nbdy .and. &
i .le.i0+ii+nbdy .and. &
j+1.ge.j0+ 1-nbdy .and. &
j+1.le.j0+jj+nbdy ) then
ivopn(i-i0,j-j0+1) = 1
endif
enddo
!
elseif (kdport(l).eq.2.or.kdport(l).eq.5) then
!
! southern port
!
sum = 0.0
j = jfport(l)
i = ifport(l)
call xclget(dline(i),lnport(l), depths,i,j,1,0, 0)
call xclget(xline(i),lnport(l), scuy, i,j, 1,0, 0)
do i= ifport(l),ilport(l)
sum = sum + dline(i)*xline(i)
enddo
sum = 1.e6/sum
do i= ifport(l),ilport(l)
vports(i,l) = sum
speeds(i,l) = sqrt(1.0*svref/(onem*dline(i)))
rspeds(i,l) = 1.0/speeds(i,l)
if (i.ge.i0+ 1-nbdy .and. &
i.le.i0+ii+nbdy .and. &
j.ge.j0+ 1-nbdy .and. &
j.le.j0+jj+nbdy ) then
ivopn(i-i0,j-j0) = 1
endif
enddo
!
endif
!
enddo !nports
if (mnproc.eq.1) then
write(lp,*)
call flush(lp)
endif
!
! end of initialization
!
call xcsync(flush_lp)
return
endif !lcount=1
if ((lll.eq.0) .or. (n.eq.0)) return !called from dpthuv
!
! --- 'wellposed' treatment of pressure and normal velocity fields
! --- not in fact wellposed with this exterior data
!
! --- set ramping factor
! when ramp_time=0:no ramping of tide (=full tide)
! when ramp_time>0: ramping of tide, if...
! ...ramp_orig<=timermp<=(ramp_orig+ramp_time)
if (ramp_time.gt.0.0) then
timermp=d_time
if (timermp.ge.ramp_orig) then
timermp=(timermp-ramp_orig)/ramp_time
! frmp=(1-exp(-10*timermp))
frmp=(1-exp(-5*timermp))
else
frmp=0.0
endif
else
frmp=1.0
endif
!
do l=1,nports
if (kdport(l).eq.4) then
!
! western port
!
i = ifport(l)