-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibtau.f
2364 lines (2334 loc) · 75.1 KB
/
libtau.f
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
c subroutine asnag1(lu,mode,n,ia,ib)
c
c $$$$$ calls assign, iargc, and getarg $$$$$
c
c Asnag1 assigns logical unit lu to a direct access disk file
c with mode "mode" and record length "len". See dasign for
c details. The n th argument is used as the model name. If there
c is no n th argument and ib is non-blank, it is taken to be the
c model name. If ib is blank, the user is prompted for the
c model name using the character string in variable ia as the
c prompt. Programmed on 8 October 1980 by R. Buland.
c
c save
c logical log
c character*(*) ia,ib
c
c if(iargc(i).lt.n) go to 1
c call getarg(n,ib)
c go to 2
c
c1 if(ib.ne.' ') go to 2
c call query(ia,log)
c read(*,100)ib
c100 format(a)
c
c2 nb=index(ib,' ')-1
c if(nb.le.0) nb=len(ib)
c call assign(lu,mode,ib(1:nb)//'.hed')
c return
c end
subroutine assign(lu,mode,ia)
c
c $$$$$ calls no other routine $$$$$
c
c Subroutine assign opens (connects) logical unit lu to the disk file
c named by the character string ia with mode mode. If iabs(mode) = 1,
c then open the file for reading. If iabs(mode) = 2, then open the
c file for writing. If iabs(mode) = 3, then open a scratch file for
c writing. If mode > 0, then the file is formatted. If mode < 0,
c then the file is unformatted. All files opened by assign are
c assumed to be sequential. Programmed on 3 December 1979 by
c R. Buland.
c
save
character*(*) ia
logical exst
c
if(mode.ge.0) nf=1
if(mode.lt.0) nf=2
ns=iabs(mode)
if(ns.le.0.or.ns.gt.3) ns=3
go to (1,2),nf
1 go to (11,12,13),ns
11 open(lu,file=ia,status='old',form='formatted')
rewind lu
return
12 inquire(file=ia,exist=exst)
if(exst) go to 11
13 open(lu,file=ia,status='new',form='formatted')
return
2 go to (21,22,23),ns
21 open(lu,file=ia,status='old',form='unformatted')
rewind lu
return
22 inquire(file=ia,exist=exst)
if(exst) go to 21
23 open(lu,file=ia,status='new',form='unformatted')
return
end
subroutine bkin(lu,nrec,len,buf)
c
c $$$$$ calls no other routines $$$$$
c
c Bkin reads a block of len double precision words into array buf(len)
c from record nrec of the direct access unformatted file connected to
c logical unit lu.
c
save
double precision buf(len),tmp
c
if(nrec.le.0) go to 1
read(lu,rec=nrec)buf
tmp=buf(1)
return
c If the record doesn't exist, zero fill the buffer.
1 do 2 i=1,len
2 buf(i)=0d0
return
end
subroutine brnset(nn,pcntl,prflg)
c
c Brnset takes character array pcntl(nn) as a list of nn tokens to be
c used to select desired generic branches. Prflg(3) is the old
c prnt(2) debug print flags in the first two elements plus a new print
c flag which controls a branch selected summary from brnset. Note that
c the original two flags controlled a list of all tau interpolations
c and a branch range summary respectively. The original summary output
c still goes to logical unit 10 (ttim1.lis) while the new output goes
c to the standard output (so the caller can see what happened). Each
c token of pcntl may be either a generic branch name (e.g., P, PcP,
c PKP, etc.) or a keyword (defined in the data statement for cmdcd
c below) which translates to more than one generic branch names. Note
c that generic branch names and keywords may be mixed. The keywords
c 'all' (for all branches) and 'query' (for an interactive token input
c query mode) are also available.
c
save
parameter(ncmd=4,lcmd=16)
include 'ttlim.inc'
logical prflg(3),segmsk,prnt,fnd,all
character*(*) pcntl(nn)
character*8 phcd,segcd(jbrn),cmdcd(ncmd),cmdlst(lcmd),phtmp,
1 phlst(jseg)
double precision zs,pk,pu,pux,tauu,xu,px,xt,taut,coef,tauc,xc,
1 tcoef,tp
dimension nsgpt(jbrn),ncmpt(2,ncmd)
common/brkc/zs,pk(jseg),pu(jtsm0,2),pux(jxsm,2),tauu(jtsm,2),
1 xu(jxsm,2),px(jbrn,2),xt(jbrn,2),taut(jout),coef(5,jout),
2 tauc(jtsm),xc(jxsm),tcoef(5,jbrna,2),tp(jbrnu,2),odep,
3 fcs(jseg,3),nin,nph0,int0(2),ki,msrc(2),isrc(2),nseg,nbrn,ku(2),
4 km(2),nafl(jseg,3),indx(jseg,2),kndx(jseg,2),iidx(jseg),
5 jidx(jbrn),kk(jseg)
common/pcdc/phcd(jbrn)
c Segmsk is a logical array that actually implements the branch
c editing in depset and depcor.
common/prtflc/segmsk(jseg),prnt(2)
c
c The keywords do the following:
c P gives P-up, P, Pdiff, PKP, and PKiKP
c P+ gives P-up, P, Pdiff, PKP, PKiKP, PcP, pP, pPdiff, pPKP,
c pPKiKP, sP, sPdiff, sPKP, and sPKiKP
c S+ gives S-up, S, Sdiff, SKS, sS, sSdiff, sSKS, pS, pSdiff,
c and pSKS
c basic gives P+ and S+ as well as ScP, SKP, PKKP, SKKP, PP, and
c P'P'
c Note that generic S gives S-up, Sdiff, and SKS already and so
c doesn't require a keyword.
c
data cmdcd/'P','P+','basic','S+'/
data cmdlst/'P','PKiKP','PcP','pP','pPKiKP','sP','sPKiKP','ScP',
1 'SKP','PKKP','SKKP','PP','S','ScS','sS','pS'/
data ncmpt/1,2,1,7,1,13,13,16/
c
c Take care of the print flags.
prnt(1)=prflg(1)
prnt(2)=prflg(2)
if(prnt(1)) prnt(2)=.true.
c Copy the token list into local storage.
no=min0(nn,jseg)
do 23 i=1,no
23 phlst(i)=pcntl(i)
c See if we are in query mode.
if(no.gt.1.or.(phlst(1).ne.'query'.and.phlst(1).ne.'QUERY'))
1 go to 1
c
c In query mode, get the tokens interactively into local storage.
c
22 print *,'Enter desired branch control list at the prompts:'
no=0
21 call query(' ',fnd)
if(no.ge.jseg) go to 1
no=no+1
read(*,100,end=30) phlst(no)
100 format(a)
c Terminate the list of tokens with a blank entry.
if(phlst(no).ne.' ') go to 21
no=no-1
if(no.gt.0) go to 1
c If the first token is blank, help the user out.
print *,'You must enter some branch control information!'
print *,' possibilities are:'
print *,' all'
print 101,cmdcd
101 format(11x,a)
print *,' or any generic phase name'
go to 22
c
c An 'all' keyword is easy as this is already the default.
1 all=.false.
if(no.eq.1.and.(phlst(1).eq.'all'.or.phlst(1).eq.'ALL'))
1 all=.true.
if(all.and..not.prflg(3)) return
c
c Make one or two generic branch names for each segment. For example,
c the P segment will have the names P and PKP, the PcP segment will
c have the name PcP, etc.
c
kseg=0
j=0
c Loop over the segments.
do 2 i=1,nseg
if(.not.all) segmsk(i)=.false.
c For each segment, loop over associated branches.
9 j=j+1
phtmp=phcd(j)
c Turn the specific branch name into a generic name by stripping out
c the crustal branch and core phase branch identifiers.
do 3 l=2,8
6 if(phtmp(l:l).eq.' ') go to 4
if(phtmp(l:l).ne.'g'.and.phtmp(l:l).ne.'b'.and.phtmp(l:l).ne.'n')
1 go to 5
if(l.lt.8) phtmp(l:)=phtmp(l+1:)
if(l.ge.8) phtmp(l:)=' '
go to 6
5 if(l.ge.8) go to 3
if(phtmp(l:l+1).ne.'ab'.and.phtmp(l:l+1).ne.'ac'.and.
1 phtmp(l:l+1).ne.'df') go to 3
phtmp(l:)=' '
go to 4
3 continue
c4 print *,'j phcd phtmp =',j,' ',phcd(j),' ',phtmp
c
c Make sure generic names are unique within a segment.
4 if(kseg.lt.1) go to 7
if(phtmp.eq.segcd(kseg)) go to 8
7 kseg=kseg+1
segcd(kseg)=phtmp
nsgpt(kseg)=i
c if(prflg(3)) print *,'kseg nsgpt segcd =',kseg,nsgpt(kseg),' ',
c 1 segcd(kseg)
8 if(jidx(j).lt.indx(i,2)) go to 9
2 continue
if(all) go to 24
c
c Interpret the tokens in terms of the generic branch names.
c
do 10 i=1,no
c Try for a keyword first.
do 11 j=1,ncmd
if(phlst(i).eq.cmdcd(j)) go to 12
11 continue
c
c If the token isn't a keyword, see if it is a generic branch name.
fnd=.false.
do 14 k=1,kseg
if(phlst(i).ne.segcd(k)) go to 14
fnd=.true.
l=nsgpt(k)
segmsk(l)=.true.
c print *,'Brnset: phase found - i k l segcd =',i,k,l,' ',
c 1 segcd(k)
14 continue
c If no matching entry is found, warn the caller.
if(.not.fnd) print *,'Brnset: phase ',phlst(i),' not found.'
go to 10
c
c If the token is a keyword, find the matching generic branch names.
12 j1=ncmpt(1,j)
j2=ncmpt(2,j)
do 15 j=j1,j2
do 15 k=1,kseg
if(cmdlst(j).ne.segcd(k)) go to 15
l=nsgpt(k)
segmsk(l)=.true.
c print *,'Brnset: cmdlst found - j k l segcd =',j,k,l,' ',
c 1 segcd(k)
15 continue
10 continue
c
c Make the caller a list of the generic branch names selected.
c
24 if(.not.prflg(3)) return
fnd=.false.
c j2=0
c Loop over segments.
do 16 i=1,nseg
if(.not.segmsk(i)) go to 16
c If selected, find the associated generic branch names.
c j2=j2+1
c do 17 j1=j2,kseg
do 17 j1=1,kseg
if(nsgpt(j1).eq.i) go to 18
17 continue
print *,'Brnset: Segment pointer (',i,') missing?'
go to 16
18 do 19 j2=j1,kseg
if(nsgpt(j2).ne.i) go to 20
19 continue
j2=kseg+1
c Print the result.
20 j2=j2-1
if(.not.fnd) print *,'Brnset: the following phases have '//
1 'been selected -'
fnd=.true.
print 102,i,(segcd(j),j=j1,j2)
102 format(10x,i5,5(2x,a))
16 continue
30 continue
return
end
subroutine depcor(nph)
save
include 'ttlim.inc'
character*8 phcd
logical noend,noext,segmsk,prnt
double precision pm,zm,us,pt,tau,xlim,xbrn,dbrn,zs,pk,pu,pux,tauu,
1 xu,px,xt,taut,coef,tauc,xc,tcoef,tp,ua,taua
double precision tup(jrec),umod,zmod,tauus1(2),tauus2(2),xus1(2),
1 xus2(2),ttau,tx,sgn,umin,dtol,u0,u1,z0,z1,fac,du
common/umdc/pm(jsrc,2),zm(jsrc,2),ndex(jsrc,2),mt(2)
common/tabc/us(2),pt(jout),tau(4,jout),xlim(2,jout),xbrn(jbrn,4),
1 dbrn(jbrn,2),xn,pn,tn,dn,hn,jndx(jbrn,2),idel(jbrn,3),mbr1,mbr2
common/brkc/zs,pk(jseg),pu(jtsm0,2),pux(jxsm,2),tauu(jtsm,2),
1 xu(jxsm,2),px(jbrn,2),xt(jbrn,2),taut(jout),coef(5,jout),
2 tauc(jtsm),xc(jxsm),tcoef(5,jbrna,2),tp(jbrnu,2),odep,
3 fcs(jseg,3),nin,nph0,int0(2),ki,msrc(2),isrc(2),nseg,nbrn,ku(2),
4 km(2),nafl(jseg,3),indx(jseg,2),kndx(jseg,2),iidx(jseg),
5 jidx(jbrn),kk(jseg)
common/pcdc/phcd(jbrn)
common/pdec/ua(5,2),taua(5,2),deplim,ka
common/prtflc/segmsk(jseg),prnt(2)
equivalence (tauc,tup)
data tol,dtol,deplim,ka,lpower/.01,1d-6,1.1,4,7/
c
c write(10,*)'depcor: nph nph0',nph,nph0
if(nph.eq.nph0) go to 1
nph0=nph
us(nph)=umod(zs,isrc,nph)
c If we are in a high slowness zone, find the slowness of the lid.
umin=us(nph)
ks=isrc(nph)
c write(10,*)'ks us',ks,sngl(umin)
do 2 i=1,ks
if(pm(i,nph).gt.umin) go to 2
umin=pm(i,nph)
2 continue
c Find where the source slowness falls in the ray parameter array.
n1=ku(nph)+1
do 3 i=2,n1
if(pu(i,nph).gt.umin) go to 4
3 continue
k2=n1
if(pu(n1,nph).eq.umin) go to 50
call die('Source slowness too large.')
4 k2=i
c50 write(10,*)'k2 umin',k2,sngl(umin)
c
c Read in the appropriate depth correction values.
c
50 noext=.false.
sgn=1d0
if(msrc(nph).eq.0) msrc(nph)=1
c See if the source depth coincides with a model sample
ztol=xn*tol/(1.-xn*odep)
if(dabs(zs-zm(ks+1,nph)).gt.ztol) go to 5
ks=ks+1
go to 6
5 if(dabs(zs-zm(ks,nph)).gt.ztol) go to 7
c If so flag the fact and make sure that the right integrals are
c available.
6 noext=.true.
if(msrc(nph).eq.ks) go to 8
call bkin(nin,ndex(ks,nph),ku(nph)+km(nph),tup)
go to 11
c If it is necessary to interpolate, see if appropriate integrals
c have already been read in.
7 if(msrc(nph).ne.ks+1) go to 9
ks=ks+1
sgn=-1d0
go to 8
9 if(msrc(nph).eq.ks) go to 8
c If not, read in integrals for the model depth nearest the source
c depth.
if(dabs(zm(ks,nph)-zs).le.dabs(zm(ks+1,nph)-zs)) go to 10
ks=ks+1
sgn=-1d0
10 call bkin(nin,ndex(ks,nph),ku(nph)+km(nph),tup)
c Move the depth correction values to a less temporary area.
11 do 31 i=1,ku(nph)
31 tauu(i,nph)=tup(i)
k=ku(nph)
do 12 i=1,km(nph)
k=k+1
xc(i)=tup(k)
12 xu(i,nph)=tup(k)
c write(10,*)'bkin',ks,sngl(sgn),sngl(tauu(1,nph)),sngl(xu(1,nph))
c
c Fiddle pointers.
c
8 msrc(nph)=ks
c write(10,*)'msrc sgn',msrc(nph),sngl(sgn)
noend=.false.
if(dabs(umin-pu(k2-1,nph)).le.dtol*umin) k2=k2-1
if(dabs(umin-pu(k2,nph)).le.dtol*umin) noend=.true.
if(msrc(nph).le.1.and.noext) msrc(nph)=0
k1=k2-1
if(noend) k1=k2
c write(10,*)'noend noext k2 k1',noend,noext,k2,k1
if(noext) go to 14
c
c Correct the integrals for the depth interval [zm(msrc),zs].
c
ms=msrc(nph)
if(sgn)15,16,16
16 u0=pm(ms,nph)
z0=zm(ms,nph)
u1=us(nph)
z1=zs
go to 17
15 u0=us(nph)
z0=zs
u1=pm(ms,nph)
z1=zm(ms,nph)
17 mu=1
c write(10,*)'u0 z0',sngl(u0),sngl(z0)
c write(10,*)'u1 z1',sngl(u1),sngl(z1)
do 18 k=1,k1
call tauint(pu(k,nph),u0,u1,z0,z1,ttau,tx)
tauc(k)=tauu(k,nph)+sgn*ttau
if(dabs(pu(k,nph)-pux(mu,nph)).gt.dtol) go to 18
xc(mu)=xu(mu,nph)+sgn*tx
c write(10,*)'up x: k mu',k,mu,sngl(xu(mu,nph)),sngl(xc(mu))
mu=mu+1
18 continue
go to 39
c If there is no correction, copy the depth corrections to working
c storage.
14 mu=1
do 40 k=1,k1
tauc(k)=tauu(k,nph)
if(dabs(pu(k,nph)-pux(mu,nph)).gt.dtol) go to 40
xc(mu)=xu(mu,nph)
c write(10,*)'up x: k mu',k,mu,sngl(xu(mu,nph)),sngl(xc(mu))
mu=mu+1
40 continue
c
c Calculate integrals for the ray bottoming at the source depth.
c
39 xus1(nph)=0d0
xus2(nph)=0d0
mu=mu-1
if(dabs(umin-us(nph)).gt.dtol.and.dabs(umin-pux(mu,nph)).le.dtol)
1 mu=mu-1
c This loop may be skipped only for surface focus as range is not
c available for all ray parameters.
if(msrc(nph).le.0) go to 1
is=isrc(nph)
tauus2(nph)=0d0
if(dabs(pux(mu,nph)-umin).gt.dtol.or.dabs(us(nph)-umin).gt.dtol)
1 go to 48
c If we happen to be right at a discontinuity, range is available.
tauus1(nph)=tauc(k1)
xus1(nph)=xc(mu)
c write(10,*)'is ks tauus1 xus1',is,ks,sngl(tauus1(nph)),
c 1 sngl(xus1(nph)),' *'
go to 33
c Integrate from the surface to the source.
48 tauus1(nph)=0d0
j=1
if(is.lt.2) go to 42
do 19 i=2,is
call tauint(umin,pm(j,nph),pm(i,nph),zm(j,nph),zm(i,nph),ttau,tx)
tauus1(nph)=tauus1(nph)+ttau
xus1(nph)=xus1(nph)+tx
19 j=i
c write(10,*)'is ks tauus1 xus1',is,ks,sngl(tauus1(nph)),
c 1 sngl(xus1(nph))
42 if(dabs(zm(is,nph)-zs).le.dtol) go to 33
c Unless the source is right on a sample slowness, one more partial
c integral is needed.
call tauint(umin,pm(is,nph),us(nph),zm(is,nph),zs,ttau,tx)
tauus1(nph)=tauus1(nph)+ttau
xus1(nph)=xus1(nph)+tx
c write(10,*)'is ks tauus1 xus1',is,ks,sngl(tauus1(nph)),
c 1 sngl(xus1(nph))
33 if(pm(is+1,nph).lt.umin) go to 41
c If we are in a high slowness zone, we will also need to integrate
c down to the turning point of the shallowest down-going ray.
u1=us(nph)
z1=zs
do 35 i=is+1,mt(nph)
u0=u1
z0=z1
u1=pm(i,nph)
z1=zm(i,nph)
if(u1.lt.umin) go to 36
call tauint(umin,u0,u1,z0,z1,ttau,tx)
tauus2(nph)=tauus2(nph)+ttau
35 xus2(nph)=xus2(nph)+tx
c36 write(10,*)'is ks tauus2 xus2',is,ks,sngl(tauus2(nph)),
c 1 sngl(xus2(nph))
36 z1=zmod(umin,i-1,nph)
if(dabs(z0-z1).le.dtol) go to 41
c Unless the turning point is right on a sample slowness, one more
c partial integral is needed.
call tauint(umin,u0,umin,z0,z1,ttau,tx)
tauus2(nph)=tauus2(nph)+ttau
xus2(nph)=xus2(nph)+tx
c write(10,*)'is ks tauus2 xus2',is,ks,sngl(tauus2(nph)),
c 1 sngl(xus2(nph))
c
c Take care of converted phases.
c
41 iph=mod(nph,2)+1
xus1(iph)=0d0
xus2(iph)=0d0
tauus1(iph)=0d0
tauus2(iph)=0d0
go to (59,61),nph
61 if(umin.gt.pu(ku(1)+1,1)) go to 53
c
c If we are doing an S-wave depth correction, we may need range and
c tau for the P-wave which turns at the S-wave source slowness. This
c would bd needed for sPg and SPg when the source is in the deep mantle.
c
do 44 j=1,nbrn
if((phcd(j)(1:2).ne.'sP'.and.phcd(j)(1:2).ne.'SP').or.
1 px(j,2).le.0d0) go to 44
c write(10,*)'Depcor: j phcd px umin =',j,' ',phcd(j),px(j,1),
c 1 px(j,2),umin
if(umin.ge.px(j,1).and.umin.lt.px(j,2)) go to 45
44 continue
go to 53
c
c If we are doing an P-wave depth correction, we may need range and
c tau for the S-wave which turns at the P-wave source slowness. This
c would be needed for pS and PS.
c
59 do 60 j=1,nbrn
if((phcd(j)(1:2).ne.'pS'.and.phcd(j)(1:2).ne.'PS').or.
1 px(j,2).le.0d0) go to 60
c write(10,*)'Depcor: j phcd px umin =',j,' ',phcd(j),px(j,1),
c 1 px(j,2),umin
if(umin.ge.px(j,1).and.umin.lt.px(j,2)) go to 45
60 continue
go to 53
c
c Do the integral.
45 j=1
c write(10,*)'Depcor: do pS or sP integral - iph =',iph
do 46 i=2,mt(iph)
if(umin.ge.pm(i,iph)) go to 47
call tauint(umin,pm(j,iph),pm(i,iph),zm(j,iph),zm(i,iph),ttau,tx)
tauus1(iph)=tauus1(iph)+ttau
xus1(iph)=xus1(iph)+tx
46 j=i
47 z1=zmod(umin,j,iph)
if(dabs(zm(j,iph)-z1).le.dtol) go to 53
c Unless the turning point is right on a sample slowness, one more
c partial integral is needed.
call tauint(umin,pm(j,iph),umin,zm(j,iph),z1,ttau,tx)
tauus1(iph)=tauus1(iph)+ttau
xus1(iph)=xus1(iph)+tx
c write(10,*)'is ks tauusp xusp',j,ks,sngl(tauus1(iph)),
c 1 sngl(xus1(iph))
c
53 ua(1,nph)=-1d0
c if(odep.ge.deplim.or.odep.le..1) go to 43
if(odep.ge.deplim) go to 43
do 57 i=1,nseg
if(.not.segmsk(i)) go to 57
if(nafl(i,1).eq.nph.and.nafl(i,2).eq.0.and.iidx(i).le.0) go to 58
57 continue
go to 43
c
c If the source is very shallow, we will need to insert some extra
c ray parameter samples into the up-going branches.
c
58 du=amin1(1e-5+(odep-.4)*2e-5,1e-5)
c write(10,*)'Add: nph is ka odep du us =',nph,is,ka,odep,
c 1 sngl(du),sngl(us(nph))
lp=lpower
k=0
do 56 l=ka,1,-1
k=k+1
ua(k,nph)=us(nph)-(l**lp)*du
lp=lp-1
taua(k,nph)=0d0
j=1
if(is.lt.2) go to 54
do 55 i=2,is
call tauint(ua(k,nph),pm(j,nph),pm(i,nph),zm(j,nph),zm(i,nph),
1 ttau,tx)
taua(k,nph)=taua(k,nph)+ttau
55 j=i
c write(10,*)'l k ua taua',l,k,sngl(ua(k,nph)),sngl(taua(k,nph))
54 if(dabs(zm(is,nph)-zs).le.dtol) go to 56
c Unless the source is right on a sample slowness, one more partial
c integral is needed.
call tauint(ua(k,nph),pm(is,nph),us(nph),zm(is,nph),zs,ttau,tx)
taua(k,nph)=taua(k,nph)+ttau
c write(10,*)'l k ua taua',l,k,sngl(ua(k,nph)),sngl(taua(k,nph))
56 continue
go to 43
c
c Construct tau for all branches.
c
1 mu=mu+1
43 j=1
c write(10,*)'mu',mu
c write(10,*)'killer loop:'
do 20 i=1,nseg
if(.not.segmsk(i)) go to 20
c write(10,*)'i iidx nafl nph',i,iidx(i),nafl(i,1),nph
if(iidx(i).gt.0.or.iabs(nafl(i,1)).ne.nph.or.(msrc(nph).le.0.and.
1 nafl(i,1).gt.0)) go to 20
c
iph=nafl(i,2)
kph=nafl(i,3)
c Handle up-going P and S.
if(iph.le.0) iph=nph
if(kph.le.0) kph=nph
sgn=isign(1,nafl(i,1))
i1=indx(i,1)
i2=indx(i,2)
c write(10,*)'i1 i2 sgn iph',i1,i2,sngl(sgn),iph
m=1
do 21 k=i1,i2
if(pt(k).gt.umin) go to 22
23 if(dabs(pt(k)-pu(m,nph)).le.dtol) go to 21
m=m+1
go to 23
21 tau(1,k)=taut(k)+sgn*tauc(m)
k=i2
c write(10,*)'k m',k,m
go to 24
c22 write(10,*)'k m',k,m
22 if(dabs(pt(k-1)-umin).le.dtol) k=k-1
ki=ki+1
kk(ki)=k
pk(ki)=pt(k)
pt(k)=umin
fac=fcs(i,1)
c write(10,*)'ki fac',ki,sngl(fac)
tau(1,k)=fac*(tauus1(iph)+tauus2(iph)+tauus1(kph)+tauus2(kph))+
1 sgn*tauus1(nph)
c write(10,*)'&&&&& nph iph kph tauus1 tauus2 tau =',
c 1 nph,iph,kph,sngl(tauus1(1)),sngl(tauus1(2)),sngl(tauus2(1)),
c 2 sngl(tauus2(2)),sngl(tau(1,k))
24 m=1
26 if(jndx(j,1).ge.indx(i,1)) go to 25
j=j+1
go to 26
25 jndx(j,2)=min0(jidx(j),k)
if(jndx(j,1).lt.jndx(j,2)) go to 37
jndx(j,2)=-1
go to 20
c37 write(10,*)'j jndx jidx',j,jndx(j,1),jndx(j,2),jidx(j),' ',
c 1 phcd(j)
37 do 30 l=1,2
28 if(dabs(pux(m,nph)-px(j,l)).le.dtol) go to 27
if(m.ge.mu) go to 29
m=m+1
go to 28
27 xbrn(j,l)=xt(j,l)+sgn*xc(m)
c write(10,*)'x up: j l m ',j,l,m
go to 30
29 xbrn(j,l)=fac*(xus1(iph)+xus2(iph)+xus1(kph)+xus2(kph))+
1 sgn*xus1(nph)
c write(10,*)'x up: j l end',j,l
c write(10,*)'&&&&& nph iph kph xus1 xus2 xbrn =',
c 1 nph,iph,kph,sngl(xus1(1)),sngl(xus1(2)),sngl(xus2(1)),
c 2 sngl(xus2(2)),sngl(xbrn(j,l))
30 continue
if(j.ge.nbrn) go to 20
j=j+1
if(jndx(j,1).le.k) go to 25
20 continue
return
end
subroutine depset(dep,usrc)
save
include 'ttlim.inc'
logical dop,dos,segmsk,prnt
character*8 phcd
real usrc(2)
double precision pm,zm,us,pt,tau,xlim,xbrn,dbrn,zs,pk,pu,pux,tauu,
1 xu,px,xt,taut,coef,tauc,xc,tcoef,tp
common/umdc/pm(jsrc,2),zm(jsrc,2),ndex(jsrc,2),mt(2)
common/tabc/us(2),pt(jout),tau(4,jout),xlim(2,jout),xbrn(jbrn,4),
1 dbrn(jbrn,2),xn,pn,tn,dn,hn,jndx(jbrn,2),idel(jbrn,3),mbr1,mbr2
common/brkc/zs,pk(jseg),pu(jtsm0,2),pux(jxsm,2),tauu(jtsm,2),
1 xu(jxsm,2),px(jbrn,2),xt(jbrn,2),taut(jout),coef(5,jout),
2 tauc(jtsm),xc(jxsm),tcoef(5,jbrna,2),tp(jbrnu,2),odep,
3 fcs(jseg,3),nin,nph0,int0(2),ki,msrc(2),isrc(2),nseg,nbrn,ku(2),
4 km(2),nafl(jseg,3),indx(jseg,2),kndx(jseg,2),iidx(jseg),
5 jidx(jbrn),kk(jseg)
common/pcdc/phcd(jbrn)
common/prtflc/segmsk(jseg),prnt(2)
data segmsk,prnt/jseg*.true.,2*.false./
c
if(amax1(dep,.011).ne.odep) go to 1
dop=.false.
dos=.false.
do 2 i=1,nseg
if(.not.segmsk(i).or.iidx(i).gt.0) go to 2
if(iabs(nafl(i,1)).le.1) dop=.true.
if(iabs(nafl(i,1)).ge.2) dos=.true.
2 continue
if(dop .or. dos) go to 3
usrc(1)=us(1)/pn
usrc(2)=us(2)/pn
return
c
1 nph0=0
int0(1)=0
int0(2)=0
mbr1=nbrn+1
mbr2=0
dop=.false.
dos=.false.
do 4 i=1,nseg
if(.not.segmsk(i)) go to 4
if(iabs(nafl(i,1)).le.1) dop=.true.
if(iabs(nafl(i,1)).ge.2) dos=.true.
4 continue
do 5 i=1,nseg
if(nafl(i,2).gt.0.or.odep.lt.0.) go to 5
ind=nafl(i,1)
k=0
do 15 j=indx(i,1),indx(i,2)
k=k+1
15 pt(j)=tp(k,ind)
5 iidx(i)=-1
do 6 i=1,nbrn
6 jndx(i,2)=-1
if(ki.le.0) go to 7
do 8 i=1,ki
j=kk(i)
8 pt(j)=pk(i)
ki=0
c Sample the model at the source depth.
7 odep=amax1(dep,.011)
rdep=dep
if(rdep.lt..011) rdep=0.
zs=amin1(alog(amax1(1.-rdep*xn,1e-30)),0.)
hn=1./(pn*(1.-rdep*xn))
if(prnt(1).or.prnt(2)) write(10,100)dep
100 format(/1x,'Depth =',f7.2/)
c
3 if(nph0.gt.1) go to 12
if(dop) call depcor(1)
if(dos) call depcor(2)
go to 14
12 if(dos) call depcor(2)
if(dop) call depcor(1)
c
c Interpolate all tau branches.
c
14 j=1
do 9 i=1,nseg
if(.not.segmsk(i)) go to 9
nph=iabs(nafl(i,1))
c print *,'i iidx nph msrc nafl =',i,iidx(i),nph,msrc(nph),nafl(i,1)
if(iidx(i).gt.0.or.(msrc(nph).le.0.and.nafl(i,1).gt.0)) go to 9
iidx(i)=1
if(nafl(i,2).le.0) int=nafl(i,1)
if(nafl(i,2).gt.0.and.nafl(i,2).eq.iabs(nafl(i,1)))
1 int=nafl(i,2)+2
if(nafl(i,2).gt.0.and.nafl(i,2).ne.iabs(nafl(i,1)))
1 int=iabs(nafl(i,1))+4
if(nafl(i,2).gt.0.and.nafl(i,2).ne.nafl(i,3)) int=nafl(i,2)+6
11 if(jndx(j,1).ge.indx(i,1)) go to 10
j=j+1
go to 11
10 idel(j,3)=nafl(i,1)
c print *,'spfit: j int =',j,int
call spfit(j,int)
mbr1=min0(mbr1,j)
mbr2=max0(mbr2,j)
if(j.ge.nbrn) go to 9
j=j+1
c print *,'j jidx indx jndx =',j,jidx(j),indx(i,2),jndx(j,2)
if(jidx(j).le.indx(i,2).and.jndx(j,2).gt.0) go to 10
9 continue
c write(10,*)'mbr1 mbr2',mbr1,mbr2
c write(10,*)'msrc isrc odep zs us',msrc,isrc,odep,sngl(zs),
c 1 sngl(us(1)),sngl(us(2))
c write(10,200)ki,(i,iidx(i),kk(i),pk(i),i=1,nseg)
c200 format(/10x,i5/(1x,3i5,f12.6))
usrc(1)=us(1)/pn
usrc(2)=us(2)/pn
return
end
subroutine findtt(jb,x0,max,n,tt,dtdd,dtdh,dddp,phnm)
save
include 'ttlim.inc'
character*(*) phnm(max)
character*8 phcd
character*67 msg
dimension tt(max),dtdd(max),dtdh(max),dddp(max)
double precision us,pt,tau,xlim,xbrn,dbrn
double precision x,x0(3),p0,p1,arg,dp,dps,delp,tol,ps,deps,pend
common/tabc/us(2),pt(jout),tau(4,jout),xlim(2,jout),xbrn(jbrn,4),
1 dbrn(jbrn,2),xn,pn,tn,dn,hn,jndx(jbrn,2),idel(jbrn,3),mbr1,mbr2
common/pcdc/phcd(jbrn)
data tol/3d-6/,deps/1d-10/
c i and j are pointers into the tau spline table for a given tau branch,
c indexed by jb. For a given range x, j and i are run up so that the
c desired range is bracketed by j and i. j points to the tau spline
c segment that will be evaluated, and i is the succeeding segment (which
c is a dummy segment if at the end of the tau branch).
nph=iabs(idel(jb,3))
hsgn=isign(1,idel(jb,3))*hn
dsgn=(-1.)**idel(jb,1)*dn
dpn=-1./tn
do 10 ij=idel(jb,1),idel(jb,2)
x=x0(ij)
dsgn=-dsgn
if(x.lt.xbrn(jb,1).or.x.gt.xbrn(jb,2)) go to 12
j=jndx(jb,1)
is=j+1
ie=jndx(jb,2)
do 1 i=is,ie
if(x.le.xlim(1,j).or.x.gt.xlim(2,j)) go to 8
c Check if there is a solution in this spline interval. If so,
c find the p that corresponds to the extremum in the theta function.
le=n
p0=pt(ie)-pt(j)
p1=pt(ie)-pt(i)
delp=dmax1(tol*(pt(i)-pt(j)),1d-3)
if(dabs(tau(3,j)).le.1d-30) then
c This segment has no term in (pend - p), so we can solve for p
c using a linear equation.
dps=(x-tau(2,j))/(1.5d0*tau(4,j))
dp=dsign(dps*dps,dps)
dp0=dp
if(dp.lt.p1-delp.or.dp.gt.p0+delp) go to 9
if(n.ge.max) go to 13
n=n+1
ps=pt(ie)-dp
tt(n)=tn*(tau(1,j)+dp*(tau(2,j)+dps*tau(4,j))+ps*x)
dtdd(n)=dsgn*ps
dtdh(n)=hsgn*sqrt(abs(sngl(us(nph)*us(nph)-ps*ps)))
dddp(n)=dpn*.75d0*tau(4,j)/dmax1(dabs(dps),deps)
phnm(n)=phcd(jb)
in=index(phnm(n),'ab')
if(in.gt.0) then
if(ps.le.xbrn(jb,3)) phnm(n)(in:)='bc'
endif
else
c This segment has a term in (pend - p), so we have to solve the
c quadratic. However, try solving both with and without the
c (pend - p) term in the spline expression, and use the
c solution that falls in the range of p values expected in
c this spline interval.
do 4 jj=1,2
if (jj .eq. 1) then
arg=9d0*tau(4,j)**2+32d0*tau(3,j)*(x-tau(2,j))
if(arg.lt.0d0) then
write(msg,100)arg
100 format('Bad sqrt argument:',1pd11.2,'.')
call warn(msg(1:30))
endif
dps = -(3d0*tau(4,j) +
1 dsign(dsqrt(dabs(arg)),tau(4,j))) /
2 (8d0*tau(3,j))
dp=dsign(dps*dps,dps)
dp0=dp
else
dps=(tau(2,j)-x)/(2d0*tau(3,j)*dps)
dp=dsign(dps*dps,dps)
endif
7 if(dp.ge.p1-delp.and.dp.le.p0+delp) then
if(n.ge.max) go to 13
n=n+1
ps=pt(ie)-dp
tt(n)=tn*(
1 tau(1,j) +
2 dp*(tau(2,j) +
3 dp*tau(3,j) +
4 dps*tau(4,j)
5 ) +
6 ps*x
7 )
dtdd(n)=dsgn*ps
dtdh(n)=hsgn *
1 sqrt(abs(sngl(us(nph)*us(nph)-ps*ps)))
dddp(n)=dpn * (
1 2d0*tau(3,j) +
2 .75d0*tau(4,j)/dmax1(dabs(dps),deps)
3 )
phnm(n)=phcd(jb)
in=index(phnm(n),'ab')
if(in.gt.0) then
if(ps.le.xbrn(jb,3)) phnm(n)(in:)='bc'
endif
endif
4 continue
9 continue
if(n.le.le) then
write(msg,101)phcd(jb),x,dp0,dp,p1,p0
101 format('Failed to find phase: ',a,f8.1,4f7.4)
call warn(msg)
endif
endif
8 continue
j=i
1 continue
c
12 continue
c Check for diffracted branches
if(x.ge.dbrn(jb,1).and.x.le.dbrn(jb,2)) then
if(n.ge.max) go to 13
c Spline p is measured from endpoint of the spline branch. If
c this is a diffraction from a forward branch, the largest distance
c will be reached with the smallest p. If from a reverse branch,
c the largest distance will be reached with the largest p. Either
c way, we assume that: 1) the diffraction will be from the p
c corresponding to the largest distance travelled; and 2) that
c the p used for the spline argument will be either the absolute
c value of the p difference (largest-smallest) of the branch if the
c branch is a forward branch, or zero if the branch is a reverse
c branch. The zero arises because we are diffracting from the end
c point p of the branch, so the spline p argument is zero.
j=jndx(jb,1)
i=jndx(jb,2)
c Find p corresponding to the max distance and use this for
c extrapolation into the shadow.
c dp=pt(i)-pt(j)
c Suppress a diffracted arrival from the maximum slowness if a
c geometric arrival is already present. This inhibits an A point
c diffraction when PKPab exists.
nn = n
if (phcd(jb) .ne. 'PKPab' .or.
+ (n .gt. 0 .and.
+ phnm(max0(n,1)) .ne. 'PKPab')) then
pend=xbrn(jb,4)
if (pend .ne. pt(j)) then
j = i-1
dp = 0.D0
else
dp=dabs(xbrn(jb,3)-xbrn(jb,4))
endif
dps=dsqrt(dabs(dp))
n=n+1
tt(n)=tn*(
1 tau(1,j) +
2 dp*(tau(2,j)+dp*tau(3,j)+dps*tau(4,j)) +
3 pend*x
4 )
dtdd(n)=dsgn*sngl(pend)
dtdh(n)=hsgn*sqrt(abs(sngl(us(nph)*us(nph)-pend*pend)))
dddp(n)=dpn*(2d0*tau(3,j)+.75d0*tau(4,j)/dmax1(dps,deps))
ln=index(phcd(jb),' ')-1
if(ln.le.0) ln=len(phcd(jb))
phnm(n)=phcd(jb)(1:ln)//'diff'
endif
if (phcd(jb) .eq. 'PKPab' .and.
1 phcd(max0(1,jb-1)).eq.'PKPdf') then
c Only diffract if outer core phase and model has inner core.
if(n.ge.max) go to 13
i1=jndx(jb,1)
i2=jndx(jb,2)
p0=pt(i1)
pend=pt(i2)
dp=pend-p0
dps=dsqrt(dabs(dp))
n=n+1
tt(n)=tn*(
1 tau(1,i1) +
2 dp*(tau(2,i1)+dp*tau(3,i1)+dps*tau(4,i1)) +
3 p0*x
4 )
dtdd(n)=dsgn*sngl(p0)
dtdh(n)=hsgn*sqrt(abs(sngl(us(nph)*us(nph)-p0*p0)))
dddp(n)=dpn*(
1 2d0*tau(3,j)+.75d0*tau(4,i1)/dmax1(dps,deps)
2 )
phnm(n)=phcd(jb)
ln=index(phcd(jb),'ab')
if(ln.le.0) ln=1+len(phcd(jb))
phnm(n)(ln:)='bcdiff'
endif
endif
10 continue
return
13 write(msg,102)max
102 format('More than',i3,' arrivals found.')
call warn(msg(1:28))
return
end
subroutine fitspl(i1,i2,tau,x1,xn,coef)
c
c $$$$$ calls only library routines $$$$$
c
c Given ray parameter grid p;i (p sub i), i=1,2,...,n, corresponding
c tau;i values, and x;1 and x;n (x;i = -dtau/dp|p;i); tauspl finds
c interpolation I such that: tau(p) = a;1,i + Dp * a;2,i + Dp**2 *
c a;3,i + Dp**(3/2) * a;4,i where Dp = p;n - p and p;i <= p < p;i+1.
c Interpolation I has the following properties: 1) x;1, x;n, and
c tau;i, i=1,2,...,n are fit exactly, 2) the first and second
c derivitives with respect to p are continuous everywhere, and
c 3) because of the paramaterization d**2 tau/dp**2|p;n is infinite.
c Thus, interpolation I models the asymptotic behavior of tau(p)
c when tau(p;n) is a branch end due to a discontinuity in the
c velocity model. Note that array a must be dimensioned at least
c a(4,n) though the interpolation coefficients will be returned in
c the first n-1 columns. The remaining column is used as scratch
c space and returned as all zeros. Programmed on 16 August 1982 by
c R. Buland.
c
save
parameter (namax=70)
double precision tau(4,i2),x1,xn,coef(5,i2)
double precision a(2,namax),ap(3),b(namax),alr,g1,gn
character msg*4
c