forked from HYCOM/HYCOM-src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod_tides.F90
1334 lines (1249 loc) · 48.8 KB
/
mod_tides.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(ROW_LAND)
#define SEA_P .true.
#define SEA_U .true.
#define SEA_V .true.
#elif defined(ROW_ALLSEA)
#define SEA_P allip(j).or.ip(i,j).ne.0
#define SEA_U alliu(j).or.iu(i,j).ne.0
#define SEA_V alliv(j).or.iv(i,j).ne.0
#else
#define SEA_P ip(i,j).ne.0
#define SEA_U iu(i,j).ne.0
#define SEA_V iv(i,j).ne.0
#endif
module mod_tides
use mod_xc ! HYCOM communication interface
!
implicit none
!
! --- HYCOM tides
!
integer, parameter, public :: ncon=8 !number of tidal consituents
!
logical, parameter, private :: debug_tides=.false. !usually .false.
!
integer, save, public :: &
tidflg, & ! 0:notide,1:bdy.;2:body;3:body&bdy.
tidcon, & ! 1 digit per constituent (Q1K2P1N2O1K1S2M2), 0=off,1=on
tidein, & ! tide input flag: 0=no; 1=yes; 2=sal
tiddrg, & ! tidal drag flag: 0:no; -1,1=scalar; 2=tensor
nhrly ! number of valid hourly samples (0 to 49)
!
logical, save, public :: &
tidgen ! generic time (don't correct tides for actual year)
!
real*8, save, public :: &
ramp_orig, & ! tide ramp origin (model day)
time_8 ! model time for tides
!
real, save, public :: &
tidsal, & ! scalar self attraction and loading factor (beta)
ramp_time ! tide ramping time (days)
!
real, allocatable, dimension(:,:), &
save, public :: &
etide, & ! body tide, in m
untide, & ! de-tided u-velocity, filtered from uhrly
vntide ! de-tided u-velocity, filtered from vhrly
!
real, allocatable, dimension(:,:,:), &
save, public :: &
uhrly, & ! hourly u-velocity samples
vhrly ! hourly v-velocity samples
!
logical, save, private :: &
tide_on(ncon)
!
real, allocatable, dimension(:,:,:), &
save, private :: &
atide, & ! real complex amplitude coefficents for body tide
btide, & ! imaginary complex amplitude coefficents for body tide
etidei ! input body tide, in m
real, save, private :: &
wt0, &
wt1
real*8, save, private :: &
amp(ncon),omega(ncon),timeref, &
pu8(ncon),pf8(ncon),arg8(ncon),time_mjd
contains
subroutine tides_set(flag)
use mod_cb_arrays ! HYCOM saved arrays
implicit none
!
integer flag !0 on initial call only
!
! --- body force tide setup
!
integer iyear,idyold,iday,ihour,inty
integer i,ihr,j,k,nleap,tidcon1
real*8 t,h0,s0,p0,db,year8
real*8 rad
real alpha2q1,alpha2o1,alpha2p1,alpha2k1
real alpha2m2,alpha2s2,alpha2n2,alpha2k2
real diur_cos,diur_sin,semi_cos,semi_sin
data rad/ 0.0174532925199432d0 /
save idyold,rad
if (tidflg.gt.0) then
if(flag.eq.0) then
tidcon1 = tidcon
do i =1,ncon
tide_on(i) = mod(tidcon1,10) .eq. 1
tidcon1 = tidcon1/10 ! shift by one decimal digit
enddo
endif
if (yrflag.eq.3) then
call forday(time_8,yrflag,iyear,iday,ihour)
if (flag.eq.0) then
idyold=iday-1 !.ne.iday
endif
! --- update once per model day
if (iday.ne.idyold) then !.or. flag.eq.0
idyold=iday
!
! time_mjd is in modified julian days, with zero on Nov 17 0:00 1858
! timeref is in HYCOM julian days, with zero on Dec 31 0:00 1900
nleap = (iyear-1901)/4
if(iyear.lt.1900)then
inty = (iyear-1857)/4
else
inty = ((iyear-1857)/4)-1 !there was no leap year in 1900
endif
timeref = 365.d0*(iyear-1901) + nleap &
+ iday
time_mjd = 365.d0*(iyear-1858) + inty &
- (31+28+31+30+31+30+31+31+30+31+17) &
+ iday
! if (mnproc.eq.1) then
! write (lp,*) 'tide_set: calling tides_nodal for a new day'
! endif !1st tile
! call xcsync(flush_lp)
call tides_nodal
! if (mnproc.eq.1) then
! year8 = iyear + (iday - 1)/365.25d0
! write(6,'(a,f11.5,8f8.4)') '#arg8 =',year8,arg8(1:8)
! write(6,'(a,f11.5,8f8.4)') '#pu8 =',year8, pu8(1:8)
! write(6,'(a,f11.5,8f8.4)') '#pf8 =',year8, pf8(1:8)
! endif !1st tile
call xcsync(flush_lp)
endif !iday.ne.idyold (.or. flag.eq.0)
endif !yrflag.eq.3
if(flag.eq.0) then
if (mnproc.eq.1) then
write (lp,*) ' now initializing tidal body forcing ...'
write (lp,'(/a,i8.8/)') ' Q1K2P1N2O1K1S2M2 = ',tidcon
endif !1st tile
call xcsync(flush_lp)
!
! --- amp is in m, and omega in 1/day.
!
amp ( 3)= 0.1424079984D+00
omega( 3)= 0.6300387913D+01 ! K1
amp ( 4)= 0.1012659967D+00
omega( 4)= 0.5840444971D+01 ! O1
amp ( 6)= 0.4712900147D-01
omega( 6)= 0.6265982327D+01 ! P1
amp ( 8)= 0.1938699931D-01
omega( 8)= 0.5612418128D+01 ! Q1
amp ( 1)= 0.2441020012D+00
omega( 1)= 0.1214083326D+02 ! M2
amp ( 2)= 0.1135720015D+00
omega( 2)= 0.1256637061D+02 ! S2
amp ( 5)= 0.4673499987D-01
omega( 5)= 0.1191280642D+02 ! N2
amp ( 7)= 0.3087499924D-01
omega( 7)= 0.1260077583D+02 ! K2
if (tidein.eq.1) then
allocate( etidei(1-nbdy:idm+nbdy,1-nbdy:jdm+nbdy,2), &
etide(1-nbdy:idm+nbdy,1-nbdy:jdm+nbdy) )
call mem_stat_add( 3*(idm+2*nbdy)*(jdm+2*nbdy) )
etidei(:,:,:) = 0.0
etide(:,:) = 0.0
wt0 = -99.0
wt1 = -99.0
call tides_forfun(time_8)
else
allocate( atide(1-nbdy:idm+nbdy,1-nbdy:jdm+nbdy,ncon), &
btide(1-nbdy:idm+nbdy,1-nbdy:jdm+nbdy,ncon), &
etide(1-nbdy:idm+nbdy,1-nbdy:jdm+nbdy) )
call mem_stat_add( 2*(idm+2*nbdy)*(jdm+2*nbdy)*ncon )
call mem_stat_add( (idm+2*nbdy)*(jdm+2*nbdy) )
if (tidein.eq.2) then
call tides_forfun_sal !input tidal SAL complex amplitudes
! --- subtract SAL forcing
atide(:,:,:) = -atide(:,:,:)
btide(:,:,:) = -btide(:,:,:)
else
atide(:,:,:) = 0.0
btide(:,:,:) = 0.0
endif
! --- alpha2=(1+k-h)g; Love numbers k,h taken from
! --- Foreman et al. JGR,98,2509-2532,1993
alpha2q1=1.0+0.298-0.603
alpha2o1=1.0+0.298-0.603
alpha2p1=1.0+0.287-0.581
alpha2k1=1.0+0.256-0.520
alpha2m2=1.0+0.302-0.609
alpha2s2=alpha2m2
alpha2n2=alpha2m2
alpha2k2=alpha2m2
!$OMP PARALLEL DO PRIVATE(j,i,semi_cos,semi_sin,diur_cos,diur_sin) &
!$OMP SCHEDULE(STATIC,jblk)
do j= 1-nbdy,jj+nbdy
do i= 1-nbdy,ii+nbdy
semi_cos=cos(rad*plat(i,j))**2*cos(rad*2*plon(i,j))
semi_sin=cos(rad*plat(i,j))**2*sin(rad*2*plon(i,j))
diur_cos=sin(2.*rad*plat(i,j))*cos(rad*plon(i,j))
diur_sin=sin(2.*rad*plat(i,j))*sin(rad*plon(i,j))
atide(i,j,3)=atide(i,j,3)+amp(3)*alpha2k1*diur_cos
btide(i,j,3)=btide(i,j,3)+amp(3)*alpha2k1*diur_sin
atide(i,j,4)=atide(i,j,4)+amp(4)*alpha2o1*diur_cos
btide(i,j,4)=btide(i,j,4)+amp(4)*alpha2o1*diur_sin
atide(i,j,6)=atide(i,j,6)+amp(6)*alpha2p1*diur_cos
btide(i,j,6)=btide(i,j,6)+amp(6)*alpha2p1*diur_sin
atide(i,j,8)=atide(i,j,8)+amp(8)*alpha2q1*diur_cos
btide(i,j,8)=btide(i,j,8)+amp(8)*alpha2q1*diur_sin
atide(i,j,1)=atide(i,j,1)+amp(1)*alpha2m2*semi_cos
btide(i,j,1)=btide(i,j,1)+amp(1)*alpha2m2*semi_sin
atide(i,j,2)=atide(i,j,2)+amp(2)*alpha2s2*semi_cos
btide(i,j,2)=btide(i,j,2)+amp(2)*alpha2s2*semi_sin
atide(i,j,5)=atide(i,j,5)+amp(5)*alpha2n2*semi_cos
btide(i,j,5)=btide(i,j,5)+amp(5)*alpha2n2*semi_sin
atide(i,j,7)=atide(i,j,7)+amp(7)*alpha2k2*semi_cos
btide(i,j,7)=btide(i,j,7)+amp(7)*alpha2k2*semi_sin
etide(i,j) = 0.0
enddo !i
enddo !j
call xctilr(atide(1-nbdy,1-nbdy,1),1,ncon, nbdy,nbdy, halo_ps)
call xctilr(btide(1-nbdy,1-nbdy,1),1,ncon, nbdy,nbdy, halo_ps)
endif !tidein.eq.1:else
if (mnproc.eq.1) then
write (lp,*) ' ...finished initializing tidal body forcing'
endif !1st tile
call xcsync(flush_lp)
endif !flag.eq.0
endif !tidflg.gt.0
if(flag.eq.0) then
if (.not.allocated(uhrly)) then
! --- restart_in did not allocate/input [uv]hrly
allocate( uhrly(1-nbdy:idm+nbdy,1-nbdy:jdm+nbdy,49), &
vhrly(1-nbdy:idm+nbdy,1-nbdy:jdm+nbdy,49), &
untide(1-nbdy:idm+nbdy,1-nbdy:jdm+nbdy), &
vntide(1-nbdy:idm+nbdy,1-nbdy:jdm+nbdy) )
call mem_stat_add( 2*(idm+2*nbdy)*(jdm+2*nbdy)*50 )
do j= 1-nbdy,jj+nbdy
do i= 1-nbdy,ii+nbdy
do ihr= 1,49
uhrly(i,j,ihr) = 0.0
vhrly(i,j,ihr) = 0.0
enddo !ihr
enddo !i
enddo !j
nhrly = 0
endif !.not.allocated
call tides_detide(1, .false.) !initialise 49-hour filter
endif !flag.eq.0
return
end subroutine tides_set
subroutine tides_detide(n, update)
use mod_cb_arrays ! HYCOM saved arrays
implicit none
!
integer n !time level index
logical update !.true. -> update hrly filter; .false. -> initialization
!
! --- form 49-hour filter
!
integer i,ihr,j,k
real pthkbl,pbop,phi,plo,ubot,vbot,fc
real*8 usum,vsum,fsum
!
real fhrly(49)
save fhrly
!
! --- a diurnal low pass filter,
! --- covering 49 hours and lagged by 24 hours.
!
! --- the filter is the convolution of a 21 hr (10 point) 2nd-order
! --- Savitzky-Golay smoothing filter and a 24.842 hr boxcar filter.
! --- it passes 0.02% of semi-diurnal and 3.2% of diurnal tides
! --- (1.2% of the total tides).
!
real f2hrly(0:24)
save f2hrly
data f2hrly / 9.297873 , &
9.297873 , 9.338932 , 9.835878 , &
10.04647 , 10.00111 , 9.730179 , &
9.264084 , 8.633219 , 7.867976 , &
6.998751 , 6.055939 , 5.069937 , &
4.071137 , 3.089936 , 2.156729 , &
1.301912 , 0.5558784,-5.0975680E-02, &
-0.4882553,-0.7255653,-0.7325106 , &
-0.4786960, 0.0 , 0.0 /
!
if (update) then
! --- calculate new hrly fields
if (thkdrg.ne.0.0) then
! --- average over thkdrg from the bottom on u and v grids
!$OMP PARALLEL DO PRIVATE(j,i,k, &
!$OMP pthkbl,pbop,phi,plo,ubot,vbot) &
!$OMP SCHEDULE(STATIC,jblk)
do j=1,jj
do i=1,ii
util5(i,j)=0.0 !probably not needed
util6(i,j)=0.0 !probably not needed
enddo !i
do i=1,ii
if (SEA_U) then
pthkbl=thkdrg*onem !thknss of bot. b.l.
pbop=depthu(i,j)-pthkbl !top of bot. b.l.
phi =max(0.5*(p(i,j,1)+p(i+1,j,1)),pbop)
ubot=0.0
do k=1,kk
plo =phi ! max(0.5*(p(i,j,k) +p(i-1,j,k)),pbop)
phi =max(min(depthu(i,j),0.5*(p(i,j,k+1)+p(i-1,j,k+1))), &
pbop)
ubot=ubot + u(i,j,k,n)*(phi-plo)
enddo !k
util5(i,j)=ubot/min(pthkbl,depthu(i,j)) + ubavg(i,j,n)
endif !ip
enddo !i
do i=1,ii
if (SEA_V) then
pthkbl=thkdrg*onem !thknss of bot. b.l.
pbop=depthv(i,j)-pthkbl !top of bot. b.l.
phi =max(0.5*(p(i,j,1)+p(i+1,j,1)),pbop)
vbot=0.0
do k=1,kk
plo =phi ! max(0.5*(p(i,j,k) +p(i-1,j,k)),pbop)
phi =max(min(depthv(i,j),0.5*(p(i,j,k+1)+p(i-1,j,k+1))), &
pbop)
vbot=vbot + v(i,j,k,n)*(phi-plo)
enddo !k
util6(i,j)=vbot/min(pthkbl,depthv(i,j)) + vbavg(i,j,n)
endif !ip
enddo !i
enddo !j
call xctilr(util5,1,1, nbdy,nbdy, halo_uv)
call xctilr(util6,1,1, nbdy,nbdy, halo_vv)
else !thkdrg.eq.0.0
! --- barotropic velocity on p-grid
!$OMP PARALLEL DO PRIVATE(j,i) &
!$OMP SCHEDULE(STATIC,jblk)
do j=1,jj
do i=1,ii
util5(i,j)=0.0 !probably not needed
util6(i,j)=0.0 !probably not needed
enddo !i
do i=1,ii
if (SEA_P) then
util5(i,j) = 0.5*( ubavg(i,j,n) + ubavg(i+1,j,n) )
util6(i,j) = 0.5*( vbavg(i,j,n) + vbavg(i,j+1,n) )
endif !ip
enddo !i
enddo !j
call xctilr(util5,1,1, nbdy,nbdy, halo_pv)
call xctilr(util6,1,1, nbdy,nbdy, halo_pv)
endif
if (nhrly.eq.49) then
! --- shift fields one hour, save new hour, form 49-hour filter
do j= 1-nbdy,jj+nbdy
do i= 1-nbdy,ii+nbdy
usum = 0.0
vsum = 0.0
do ihr= 1,48
uhrly(i,j,ihr) = uhrly(i,j,ihr+1)
vhrly(i,j,ihr) = vhrly(i,j,ihr+1)
usum = usum + fhrly(ihr)*uhrly(i,j,ihr)
vsum = vsum + fhrly(ihr)*vhrly(i,j,ihr)
enddo !ihr
uhrly(i,j,49) = util5(i,j)
vhrly(i,j,49) = util6(i,j)
usum = usum + fhrly(49)*uhrly(i,j,49)
vsum = vsum + fhrly(49)*vhrly(i,j,49)
untide(i,j) = usum
vntide(i,j) = vsum
enddo !i
enddo !j
else
! --- save one more hour
nhrly = nhrly + 1
do j= 1-nbdy,jj+nbdy
do i= 1-nbdy,ii+nbdy
uhrly(i,j,nhrly) = util5(i,j)
vhrly(i,j,nhrly) = util6(i,j)
if (nhrly.eq.49) then
! --- form 49-hour filter
usum = fhrly(1)*uhrly(i,j,1)
vsum = fhrly(1)*vhrly(i,j,1)
do ihr= 2,49
usum = usum + fhrly(ihr)*uhrly(i,j,ihr)
vsum = vsum + fhrly(ihr)*vhrly(i,j,ihr)
enddo !ihr
untide(i,j) = usum
vntide(i,j) = vsum
else
! --- not enough hours for 49-hour filter yet
untide(i,j) = 0.0
vntide(i,j) = 0.0
endif !nhrly
enddo !i
enddo !j
endif !nhrly:else
else !.not.update -> initialize
! --- normalize the filter weights
fsum = f2hrly(0)
do ihr=1,24
fsum = fsum + 2.0*f2hrly(ihr)
enddo
fc = 1.0/fsum
fhrly(25) = fc*f2hrly(0)
do ihr=1,24
fhrly(25+ihr) = fc*f2hrly(ihr)
fhrly(25-ihr) = fc*f2hrly(ihr)
enddo
!
if (nhrly.eq.49) then
! --- form 49-hour filter, from restart input
do j= 1-nbdy,jj+nbdy
do i= 1-nbdy,ii+nbdy
usum = fhrly(1)*uhrly(i,j,1)
vsum = fhrly(1)*vhrly(i,j,1)
do ihr= 2,49
usum = usum + fhrly(ihr)*uhrly(i,j,ihr)
vsum = vsum + fhrly(ihr)*vhrly(i,j,ihr)
enddo !ihr
untide(i,j) = usum
vntide(i,j) = vsum
enddo !i
enddo !j
else
! --- not enough hours for 49-hour filter from restart input
do j= 1-nbdy,jj+nbdy
do i= 1-nbdy,ii+nbdy
untide(i,j) = 0.0
vntide(i,j) = 0.0
enddo !i
enddo !j
endif !nhrly:else
endif !update:initialize
if (debug_tides) then
if (itest.gt.0 .and. jtest.gt.0) then
write (lp,'(i9,2i5,3x,a,i2.2,a,2f10.6)') &
nstep,itest+i0,jtest+j0, &
' hr',nhrly,' = ', &
uhrly(itest,jtest,nhrly), vhrly(itest,jtest,nhrly)
write (lp,'(i9,2i5,3x,a,2f10.6)') &
nstep,itest+i0,jtest+j0, &
'ntide = ', &
untide(itest,jtest), vntide(itest,jtest)
endif
call xcsync(flush_lp)
endif !debug_tides
return
end subroutine tides_detide
subroutine tides_force(ll)
use mod_xc ! HYCOM communication interface
use mod_cb_arrays ! HYCOM saved arrays
implicit none
integer ll
!
! --- calculate body tide
!
integer i,j
real*8 timef,timet,timermp
real ramp
real etide1,etide2,etide3,etide4,etide5,etide6,etide7,etide8
! ramp-up of tide signal
ramp =1.0
timermp=time_8+(ll*dlt/86400.d0)
if(ramp_time.gt.0.0 ) then
if(timermp .ge.ramp_orig)then
timermp=(timermp-ramp_orig)/ramp_time
ramp=ramp*(1.0-exp(-5.0*timermp))
else
ramp=0.0
endif
endif !ramp_time
if (.not.tidgen) then
call tides_set(1)
else
arg8(1:ncon) = 0.0 !no correction for a specific year
pu8(1:ncon) = 0.0 !no correction for a specific year
pf8(1:ncon) = 1.0 !no correction for a specific year
endif !standard:generic
!
! --- Early return?
!
if (tidflg.lt.2) then
RETURN
endif
!
if (yrflag.eq.3) then
timet=time_8+(ll*dlt/86400.d0)-timeref !time from 00Z today
else
timet=time_8+(ll*dlt/86400.d0) !time since model day zero
endif
if (tidein.eq.1) then
timef=timeref+timet
call tides_forfun(timef)
do j= 1-nbdy,jj+nbdy
do i= 1-nbdy,ii+nbdy
etide(i,j)=ramp*(wt0*etidei(i,j,1)+wt1*etidei(i,j,2))
enddo !i
enddo !j
else !generate the body tide here
etide1 = 0.0
etide2 = 0.0
etide3 = 0.0
etide4 = 0.0
etide5 = 0.0
etide6 = 0.0
etide7 = 0.0
etide8 = 0.0
!$OMP PARALLEL DO PRIVATE(j,i, &
!$OMP etide1,etide2,etide3,etide4,etide5,etide6,etide7,etide8) &
!$OMP SCHEDULE(STATIC,jblk)
do j= 1-nbdy,jj+nbdy
do i= 1-nbdy,ii+nbdy
if (tide_on(1)) then
etide1= &
atide(i,j,1)*pf8(1)*cos(omega(1)*timet+arg8(1)+pu8(1))- &
btide(i,j,1)*pf8(1)*sin(omega(1)*timet+arg8(1)+pu8(1))
endif
if (tide_on(2)) then
etide2= &
atide(i,j,2)*pf8(2)*cos(omega(2)*timet+arg8(2)+pu8(2))- &
btide(i,j,2)*pf8(2)*sin(omega(2)*timet+arg8(2)+pu8(2))
endif
if (tide_on(3)) then
etide3= &
atide(i,j,3)*pf8(3)*cos(omega(3)*timet+arg8(3)+pu8(3))- &
btide(i,j,3)*pf8(3)*sin(omega(3)*timet+arg8(3)+pu8(3))
endif
if (tide_on(4)) then
etide4= &
atide(i,j,4)*pf8(4)*cos(omega(4)*timet+arg8(4)+pu8(4))- &
btide(i,j,4)*pf8(4)*sin(omega(4)*timet+arg8(4)+pu8(4))
endif
if (tide_on(5)) then
etide5= &
atide(i,j,5)*pf8(5)*cos(omega(5)*timet+arg8(5)+pu8(5))- &
btide(i,j,5)*pf8(5)*sin(omega(5)*timet+arg8(5)+pu8(5))
endif
if (tide_on(6)) then
etide6= &
atide(i,j,6)*pf8(6)*cos(omega(6)*timet+arg8(6)+pu8(6))- &
btide(i,j,6)*pf8(6)*sin(omega(6)*timet+arg8(6)+pu8(6))
endif
if (tide_on(7)) then
etide7= &
atide(i,j,7)*pf8(7)*cos(omega(7)*timet+arg8(7)+pu8(7))- &
btide(i,j,7)*pf8(7)*sin(omega(7)*timet+arg8(7)+pu8(7))
endif
if (tide_on(8)) then
etide8= &
atide(i,j,8)*pf8(8)*cos(omega(8)*timet+arg8(8)+pu8(8))- &
btide(i,j,8)*pf8(8)*sin(omega(8)*timet+arg8(8)+pu8(8))
endif
etide(i,j)= etide1 &
+etide2 &
+etide3 &
+etide4 &
+etide5 &
+etide6 &
+etide7 &
+etide8
etide(i,j)=ramp*etide(i,j)
enddo !i
enddo !j
endif !tidein.eq.1:else
if (debug_tides) then
if (itest.gt.0 .and. jtest.gt.0) then
write (lp,'(i9,f14.6,2i5,3x,a,f10.6)') &
nstep,timeref+timet,itest+i0,jtest+j0, &
' etide = ',etide(itest,jtest)
endif
call xcsync(flush_lp)
endif !debug_tides
return
end subroutine tides_force
subroutine tides_forfun(dtime)
use mod_xc ! HYCOM communication interface
use mod_cb_arrays ! HYCOM saved arrays
use mod_za ! HYCOM I/O interface
implicit none
!
real*8 dtime
!
! --- tidal body forcing field processing.
!
! --- units of etide are m, and it is on the p grid.
!
! --- I/O and array I/O units 917 are reserved for the entire run.
!
! --- all input fields much be defined at all grid points
!
real*8 dtime0,dtime1
save dtime0,dtime1
!
character preambl(5)*79,cline*80
integer i,ios,j,lgth,nrec
!
! --- wt0 negative on first call only.
if (wt0.lt.-1.0) then
!
! --- initialize forcing fields
!
if (tidein.ne.1) then
if (mnproc.eq.1) then
write(lp,*)
write(lp,*) 'error in tides_forfun - tidein must be 1'
write(lp,*)
endif !1st tile
call xcstop('(tides_forfun)')
stop '(tides_forfun)'
endif
!
! --- open all forcing files.
if (mnproc.eq.1) then
write (lp,*) ' now initializing tidal forcing fields ...'
endif !1st tile
call xcsync(flush_lp)
!
lgth = len_trim(flnmfor)
!
call zaiopf(flnmfor(1:lgth)//'forcing.tidpot.a', 'old', 917)
if (mnproc.eq.1) then ! .b file from 1st tile only
open (unit=uoff+917,file=flnmfor(1:lgth)//'forcing.tidpot.b', &
status='old', action='read')
read (uoff+917,'(a79)') preambl
endif !1st tile
call preambl_print(preambl)
!
! --- skip ahead to the start time.
nrec = 0
dtime1 = huge(dtime1)
do ! infinate loop, with exit at end
dtime0 = dtime1
nrec = nrec + 1
call zagetc(cline,ios, uoff+917)
if (ios.ne.0) then
if (mnproc.eq.1) then
write(lp,*)
write(lp,*) 'error in tides_forfun - hit end of input'
write(lp,*) 'dtime0,dtime1 = ',dtime0,dtime1
write(lp,*) 'dtime = ',dtime
write(lp,*)
endif !1st tile
call xcstop('(tides_forfun)')
stop '(tides_forfun)'
endif !ios
i = index(cline,'=')
read (cline(i+1:),*) dtime1
if (nrec.eq.1 .and. dtime1.lt.1462.0d0) then
!
! --- must start after wind day 1462.0, 01/01/1905.
if (mnproc.eq.1) then
write(lp,'(a)') cline
write(lp,'(/ a,a / a,g15.6 /)') &
'error in tides_forfun - actual forcing', &
' must start after wind day 1462', &
'dtime1 = ',dtime1
endif !1st tile
call xcstop('(tides_forfun)')
stop '(tides_forfun)'
endif !before wind day 1462.0
if (dtime0.le.dtime .and. dtime1.gt.dtime) then
exit
endif
enddo ! infinate loop, with exit above
if (mnproc.eq.1) then ! .b file from 1st tile only
rewind(unit=uoff+917)
read (uoff+917,'(a79)') preambl
endif
call rdpall1(etidei,dtime0,917,.true.)
call rdpall1(etidei,dtime1,917,.true.)
call xctilr( etidei,1,2, nbdy,nbdy, halo_ps)
if (mnproc.eq.1) then
write (lp,*)
write (lp,*) ' dtime,dtime0,dtime1 = ',dtime,dtime0,dtime1
write (lp,*)
write (lp,*) ' ...finished initializing tidal forcing fields'
endif !1st tile
call xcsync(flush_lp)
endif ! initialization
!
if (dtime.gt.dtime1) then
!
! --- get the next set of fields.
! if (mnproc.eq.1) then
! write(lp,*) 'enter rdpall - ',dtime,dtime0,dtime1
! endif !1st tile
! call xcsync(flush_lp)
dtime0 = dtime1
call rdpall1(etidei,dtime1,917,.true.)
call xctilr( etidei(1-nbdy,1-nbdy,2),1,1, nbdy,nbdy, halo_ps)
! if (mnproc.eq.1) then
! write(lp,*) ' exit rdpall1 - ',dtime,dtime0,dtime1
! endif !1st tile
! call xcsync(flush_lp)
endif
!
! --- linear interpolation in time.
wt0 = (dtime1-dtime)/(dtime1-dtime0)
wt1 = 1.0 - wt0
! if (mnproc.eq.1) then
! write(lp,*) 'rdpall - dtime,wt0,wt1 = ',dtime,wt0,wt1
! endif !1st tile
! call xcsync(flush_lp)
return
end subroutine tides_forfun
subroutine tides_forfun_sal
use mod_xc ! HYCOM communication interface
use mod_cb_arrays ! HYCOM saved arrays
use mod_za ! HYCOM I/O interface
implicit none
!
! --- initialize real and imaginary tidal SAL complex amplitudes
!
! --- units of atide and btide are m on the p-grid.
!
! --- I/O and array I/O unit 925 used here, but not reserved.
!
! --- all input fields much be defined at all grid points
!
integer i,j,k,lgth
!
if (mnproc.eq.1) then
write (lp,*) ' now opening salReIm fields ...'
endif !1st tile
call xcsync(flush_lp)
!
lgth = len_trim(flnmfor)
!
call zaiopf(flnmfor(1:lgth)//'tidal.salReIm.a', 'old', 925)
if (mnproc.eq.1) then ! .b file from 1st tile only
open (unit=uoff+925,file=flnmfor(1:lgth)//'tidal.salReIm.b', &
status='old', action='read')
endif !1st tile
do k= 1,8
call rdmonth(atide(1-nbdy,1-nbdy,k), 925)
call rdmonth(btide(1-nbdy,1-nbdy,k), 925)
enddo !k
if (mnproc.eq.1) then ! .b file from 1st tile only
close (unit=uoff+925)
endif
call zaiocl(925)
!
call xctilr(atide,1,8, nbdy,nbdy, halo_ps)
call xctilr(btide,1,8, nbdy,nbdy, halo_ps)
!
if (mnproc.eq.1) then
write (lp,*) ' ...finished reading salReIm fields '
endif !1st tile
call xcsync(flush_lp)
!
return
end subroutine tides_forfun_sal
subroutine tides_ports(dtime,nportpts,zR,zI,zA, port_tide)
implicit none
!
real*8 dtime
integer nportpts
real zR(ncon,nportpts,3),zI(ncon,nportpts,3),zA(nportpts)
real port_tide(nportpts,3)
!
! --- generate the tidal signal (zuv) at port points
!
! --- On input:
! dtime = model time
! nportpts = number of port points
! zR = Real zuv tidal reponse for ncon constituents
! zI = Imaginary zuv tidal reponse for ncon constituents
! zA = Pang (angle of xward wrt eward) at port points, radians
!
! --- On output:
! port_tide = tidal signal (1:3 is z,u,v)
!
! --- Input u and v are eastward and northward, but
! --- Output u and v are x-ward and y-ward.
! --- On a rectilinear grid, zA is 0.0 and eastward==x-ward.
!
integer n,j,k
real ramp,pt(3)
real*8 timermp
real*8 timet,Arg_p,ct,st,Ar,Ai
timet=dtime - timeref
! ramp-up of tide signal
ramp =1.0
timermp=dtime
if(ramp_time.gt.0.0 ) then
if(timermp .ge.ramp_orig)then
timermp=(timermp-ramp_orig)/ramp_time
ramp=ramp*(1.0-exp(-5.0*timermp))
else
ramp=0.0
endif
endif !ramp_time
port_tide(:,:)=0.0 !initiialize sum over ncom tidal components
do n=1,ncon
if(tide_on(n))then
Arg_p=omega(n)*timet+pu8(n)+arg8(n)
ct=cos(Arg_p)
st=sin(Arg_p)
Ar=pf8(n)*ct
Ai=pf8(n)*st
do k=1,3
do j=1, nportpts
port_tide(j,k)=port_tide(j,k)+zR(n,j,k)*Ar-zI(n,j,k)*Ai
enddo !j
enddo !k
endif !tide_on
enddo !n
!DAN-----------------------
!DAN scale open boundary port tidal signal by ramp
!DAN
do j=1, nportpts
do k=1,3
pt(k)=ramp*port_tide(j,k)
enddo !k
port_tide(j,1)= pt(1)
port_tide(j,2)=cos(zA(j))*pt(2)+sin(zA(j))*pt(3)
port_tide(j,3)=cos(zA(j))*pt(3)-sin(zA(j))*pt(2)
enddo !j
! if (mnproc.eq.1) then
! write(lp,'(a,f8.4,2f12.5)')
! & 'tides_ports: ramp,time =',ramp,dtime,timet
! endif
return
end subroutine tides_ports
subroutine tides_driver(z1rall,z1iall,dtime, &
astroflag,zpredall,start,ijtdm,ndat) !normal
use mod_xc ! HYCOM communication interface
use mod_cb_arrays ! HYCOM saved arrays
implicit none
integer start,ijtdm,ndat
logical astroflag
real z1rall(ijtdm,ncon),z1iall(ijtdm,ncon),zpredall(ijtdm)
real*8 dtime
character*10 cdate
character*8 ctime
logical interp_micon
integer n,m,i,j,k,ic
integer ind(ncon)
real zpred(ndat),z1r(ndat,ncon),z1i(ndat,ncon)
real Ai(ncon), Ar(ncon)
! From ptide
real ww(17,ncon)
real*8 ttime
! from make_a
! If l_sal=.true. - NO solid Earth correction is applied
! USING beta_SE coefficients
logical l_sal
real beta_SE(ncon)
real ci(ncon),cr(ncon)
! the succession is: M2,S2,K1,O1,N2,P1,K2,Q1 (corresponding to
! succession in tidalports_*.input)
data beta_SE/ &
0.9540,0.9540,0.9400,0.9400, &
0.9540,0.9400,0.9540,0.9400/
save beta_SE
l_sal = .TRUE.
interp_micon =.FALSE.
do i =1,ndat
zpred(i) = zpredall(start+i-1)
do ic =1,ncon
z1r(i,ic) = z1rall(start+i-1,ic)
z1i(i,ic) = z1iall(start+i-1,ic)
enddo
enddo
do i =1,ncon
ind(i) = i
enddo
ttime=dtime-timeref !days from 00Z today
! ndat is the number of lat/lon pairs
! output is zpred which is the elevations
do k = 1, ndat
! Currently disabled
!. to include get ww from weights.h
if(interp_micon)call tides_mkw(interp_micon,ind,ncon,ww)
do j=1,ncon
i=ind(j)
if(i.ne.0)then
cr(j) = pf8(i)*cos(omega(i)*ttime+arg8(i)+pu8(i))
ci(j) = pf8(i)*sin(omega(i)*ttime+arg8(i)+pu8(i))
endif
enddo
! .true. means NO solid Earth correction will be applied in make_a
! remove solid Earth tide
if(.not.l_sal)then
do j=1,ncon
Ar(j)=0.
Ai(j)=0.
if(ind(j).ne.0) then
Ar(j)=cr(j)*beta_SE(ind(j))
Ai(j)=ci(j)*beta_SE(ind(j))
endif
enddo
else
do j=1,ncon
Ar(j)=cr(j)*1.
Ai(j)=ci(j)*1.
enddo
endif
if(ncon.eq.0)then
zpred(k)=0
else
zpred(k)=0
do i=1,ncon
zpred(k)=zpred(k)+z1r(k,i)*Ar(i) &
-z1i(k,i)*Ai(i)
enddo
endif
zpredall(start+k-1) = zpred(k)
enddo
close(1)
return
end subroutine tides_driver
subroutine tides_mkw(interp,ind,nc,wr)
real wr(17,ncon)
logical interp
integer i,j,nc,ind(nc)
real w(17,ncon)
data w(1,:)/1.0, .00, .00, .00, .00, .00, .00, .00/
data w(2,:)/0.0, 1.00, .00, .00, .00, .00, .00, .00/
data w(3,:)/0.0, .00, 1.0, .00, .00, .00, .00, .00/
data w(4,:)/0.0, .00, .00, 1.00, .00, .00, .00, .00/
data w(5,:)/0.0, .00, .00, .00, 1.00, .00, .00, .00/
data w(6,:)/0.0, .00, .00, .00, .00, 1.00, .00, .00/
data w(7,:)/0.0, .00, .00, .00, .00, .00, 1.00, .00/
data w(8,:)/0.0, .00, .00, .00, .00, .00, .00, 1.00/
data w(9,:)/-0.0379, .0,.00, .00, .30859 ,0.0, .03289,.0/
data w(10,:)/-0.03961,.0,.00, .00, .34380, 0.0, .03436,.0/
data w(11,:)/.00696, .0,.00, .00, .15719, 0.0, -.00547,.0/
data w(12,:)/.02884, .0,.00, .00, -.05036, 0.0, .07424,.0/
data w(13,:)/.00854, .0,.00, .00, -.01913, 0.0, .17685,.0/
data w(14,:)/.0, .0, -.00571, .11234, .0, .05285, .0, -.26257/
data w(15,:)/.0, .0, .00749, .07474, .0, .03904, .0, -.12959/
data w(16,:)/.0, .0, -.03748, .12419, .0, .05843, .0, -.29027/
data w(17,:)/.0, .0, .00842, .01002, .0,-.03064, .0, .15028/
save w
wr=w
if(interp)return
!
do j=1,nc