# ----------------------------------------------------------------------
#  Makefile - Created by Brad Artman
#        Date:
# ----------------------------------------------------------------------
#       Usage:  
#  Parameters: 
# Description:
#             
# ----------------------------------------------------------------------
include ${SEPINC}/SEP.top

#include DEFakefile
#include FIGakefile
#include BRADTESTmakefile
#LATOPTS= class=brad # style=jfc,makeidx,amsmath'
RESDIR=./Fig
RESULTSNR=sketch syndat synoffprim synoffni sig1 mult gulfp gulf m.ni p.ni m.0n p.0n sigsub gsub

###########################GULF_WESTERN##################
WESTERN_GULF=/net/koko/gabriel/Research/Multiples/GOM_TEST
gulf.H:$(WESTERN_GULF)/shots_split.H
	cp $< $@
	echo o2=-4.876799 d2=0.026670 o3=-2.34696 d3=0.026670 >> $@
wfg.H:#	Wavelet fund=40 n1=2404 wavelet=ricker2 d1=0.004 |Add scale=-1  > t$@
	Spike n1=2404 k1=1 mag=1.| Bandpass flo=8. fhi=48. nplo=5 nphi=18 > t$@
	< t$@ Transf shotmig=y  f_min=3 f_min1=7 f_max1=55. f_max=65. >$@
	Rm t$@
f.gulf.H: gulf.H
	< $< Transf shotmig=y is2d=y f_min=3 f_min1=7 f_max1=55. f_max=65. >$@ maxsize=500 
vgulf.H:$(WESTERN_GULF)/velgom.H
	Window3d max1=6 < $< > t$@
	Pad beg2=190 end2=200 > t1$@ <  t$@ extend=1
	Transp plane=12 reshape=1,3,4 < t1$@ >$@
	Rm t$@ t1$@

mig.gulf.H: 
###########################Synthetics##################
T=700
prim.H:#$B/two_flat_layers.x
	$B/two_flat_layers.x prim2=y prim1=y wb1=n wb2=n wb3=n \
	   sm1=n im1=n plg1=n amps=n zwb=400 zref=1200 vw=1500 \
	   vr=2500 nh=400 oh=-4000 dh=20 ncmp=1 ocmp=2000 dcmp=10 \
	   nt=400 dt=0.008 fpeak=20 im1=n > $@
f.sp.pr.H:prim.H
	< $< Pad n1out=$T > t$@
	< t$@ Transf shotmig=y is2d=y wei=y > $@
	Rm t$@
one.split.H:split.H
	Window3d < $< n3=1 > t$@
	<t$@ Pad n1out=$T > $@
	Rm t$@
sp_nointra.H: #${BIN}/two_flat_layers.x
	${BIN}/two_flat_layers.x zwb=400 zref=1200 vw=1500 vr=2500 \
		nh=400 oh=-4000 dh=20 ncmp=1 ocmp=2000 dcmp=10  \
		nt=400 dt=0.008 fpeak=20 im1=n \
		wb1=y wb2=n wb3=n amps=n rhow=1. rhor=2. rhohs=2.5 > $@
f.sp.H:one.split.H
	< $< Transf shotmig=y is2d=y wei=y > $@
f.sp.ni.H:sp_nointra.H # no internal mult.
	< $< Pad n1out=$T > t$@
	< t$@ Transf shotmig=y is2d=y wei=y > $@
	Rm t$@
f.sp.0n.H:f.sp.ni.H # no near offset traces
	< $< Window3d n1=195 squeeze=n |Pad n1out=206 > a.H
	< $< Window3d f1=206 squeeze=n  > b.H
	Cat3d axis=1 space=n a.H b.H > $@
	Rm a.H b.H
wf.H: f.sp.H f.sp.ni.H
	 Wavelet fund=20 n1=$T wavelet=ricker2 d1=0.008 |Add scale=-1  > t$@
	< t$@ Transf shotmig=y >$@
	Rm t$@
vv.H: vel.H
	< $< Window3d n1=241 > t$@
	Transp reshape=1,3,4 > t1$@ < t$@
	< t1$@ Pad n3out=570 extend=1 > $@
	Rm t$@ t1$@
vw.H:vv.H
	Math file1=$< exp="file1*0.+1500" > $@
PRG=/net/koko/tang/bin/LINUX/ShotMig.x
I.%.vv.H M.%.vv.H: vv.H f.%.H wf.H
	${PRG} D=f.$*.H D_d=wf.H V=vv.H R=I.$*.vv.H M=M.$*.vv.H nhx=60 jhx=2 
I.%.vw.H M.%.vw.H: vw.H f.%.H wf.H
	${PRG} D=f.$*.H D_d=wf.H V=vw.H R=I.$*.vw.H M=M.$*.vw.H nhx=70 jhx=2 
img.%.H:%.H $B/BigImage.x
	< $< Window3d > t$@
	< t$@ Transp plane=13 > t1$@ 
	< t1$@ $B/BigImage.x ns=350  > t2$@
	< t2$@ Transp plane=23 > $@
	Rm t$@ t1$@ t2$@
img.%.T: img.%.H
	< $< Grey eout=1 gainpanel=a > $@
img.%:img.I.%.T img.M.%.T
	Rickmulti $^ 
ang.%.H:img.%.H
	< $< Window3d min2=6000 max2=6500 > t$@
	< t$@ Transp reshape=1,2,4,5 plane=23 > hmm.H
	< hmm.H OFF2ANG nzpad=650 eps=.8 > $@
	Rm hmm.H t$@
ang.%:ang.I.%.H ang.M.%.H
	Window3d < ang.I.$*.H n4=1 |Grey > /dev/null out=t.v
	Window3d < ang.M.$*.H n4=1 |Grey > /dev/null out=s.v
	tube s.v t.v
match.%.H: ang.I.sp.%.vv.H ang.M.sp.%.vv.H ## good for all data
	Window3d < ang.I.sp.$*.vv.H n4=1 |Scale scale_to=1.> tI$@
	Window3d < ang.M.sp.$*.vv.H n4=1 |Scale scale_to=1.> tM$@
	${B}/Ultimatch-new-all.x < tI$@ multiples_in=tM$@ nfilt=7,2 npatch=100,50 \
	   nouter=1 niter=200 eps=1. mu=1.0 wmode=1 mode=2 nsmode=1 op=1 2D=y dtest=n > $@
	Rm  tI$@ tM$@
#match.%.H: ang.I.sp.%.vv.H ang.M.sp.%.vv.H Makefile
#	Window3d < ang.I.sp.$*.vv.H n4=1 |Scale scale_to=1.> tI$@
#	Window3d < ang.M.sp.$*.vv.H n4=1 |Scale scale_to=1.> tM$@
#	${B}/Ultimatch-new-all.x < tI$@ multiples_in=tM$@ nfilt=7,1 npatch=100,50 \
#	   nouter=1 niter=20 eps=1. mu=1.0 wmode=1 mode=2 nsmode=1 op=1 2D=y dtest=n > $@
#	Rm  tI$@ tM$@

##  p1 is semigood only primary result
p1.%.H: ang.I.sp.%.vv.H match.%.H 
	Window3d < $< n4=1 |Scale scale_to=1.> t$@
	Add scale=-1,1 match.$*.H t$@ > $@
	Rm t$@
##  p2 is supergood only primary result
p2.%.H:ang.I.sp.%.vv.H p1.%.H
	Window3d < ang.I.sp.$*.vv.H n4=1 |Scale scale_to=1.> tI$@
	Window3d < p1.$*.H |Scale scale_to=1.> tM$@
	/net/koko/brad/bin/LINUX/Ultimatch-new-all.x < tI$@ \
	  multiples_in=tM$@ nfilt=17,17 npatch=10,1 nouter=1  dtest=n \
	  niter=40 eps=30. mu=1.0 wmode=1 mode=2 nsmode=1 op=1 2D=y> $@
	Rm  tI$@ tM$@
c= clip=.3 title=' ' label1='z(m)' label2='angle(deg)' geophysics=1 labelsz=12 labelfat=2 
$R/m.%.v:# match.%.H ang.I.sp.%.vv.H ang.M.sp.%.vv.H
	Window3d < ang.I.sp.$*.vv.H n4=1 |Scale scale_to=1.> tI
	Window3d < ang.M.sp.$*.vv.H n4=1 |Scale scale_to=1.> tM
	Grey <tI $c o1num=500. o2num=-40. > tI.V
	Grey <tM $c o1num=500. o2num=-40. > tM.V
	Grey <$<   $c o1num=500. o2num=-30. > tMm.V
	Vppen < tI.V  vpstyle=n xsize=2. ysize=4. out=tI.v > /dev/null
	Vppen < tM.V  vpstyle=n xsize=2. ysize=4. out=tM.v  xshift=1.8 > /dev/null
	Vppen < tMm.V vpstyle=n xsize=2. ysize=4. out=tMm.v xshift=3.6 > /dev/null
	vp_Overlay tMm.v tM.v tI.v > $@
	Rm tI.V tM.V tMm.V tI tM
	rm -f tI.v tM.v tMm.v
$R/p.%.v:#p1.%.H p2.%.H ang.I.sp.%.vv.H 
	Window3d < ang.I.sp.$*.vv.H n4=1 |Scale scale_to=1.> tI
	Grey <tI      $c o1num=500. o2num=-40. > tMm.V
	Grey <p1.$*.H $c o1num=500. o2num=-40. > tI.V
	Grey <p2.$*.H $c o1num=500. o2num=-40. > tM.V
	Vppen < tI.V  vpstyle=n xsize=2. ysize=4. out=tI.v > /dev/null
	Vppen < tM.V  vpstyle=n xsize=2. ysize=4. out=tM.v  xshift=1.8 > /dev/null
	Vppen < tMm.V vpstyle=n xsize=2. ysize=4. out=tMm.v xshift=3.6 > /dev/null
	vp_Overlay tMm.v tM.v tI.v > $@
	Rm tI.V tM.V tMm.V tI 
	rm -f tI.v tM.v tMm.v
#----------------------------------------------------------------
$R/syndat.v: #sp_nointra.H img.I.sp.ni.vv.H
	< sp_nointra.H Grey  label1='t(s)' label2='h(m)' geophysics=1 \
	title=' ' labelsz=18 labelfat=2 o2num=-2000. | Vppen vpstyle=n \
	xsize=2. ysize=4. out=a.v > /dev/null yshift=.15
	< img.I.sp.ni.vv.H Window3d n2=1 min2=7380 min3=-750 max3=750 |\
	 Grey  label1='z(m)' label2='h(m)' geophysics=1 pclip=99.9 \
	title=' ' labelsz=18 labelfat=2 o2num=-600. d1num=1000 | Vppen vpstyle=n \
	xsize=2. ysize=4. out=b.v > /dev/null xshift=2. yshift=.15
	vp_Overlay a.v b.v >$@
	rm -f a.v b.v
#$R/%.ps:$R/%.v
#	pstexpen $< t$@ color=n fat=1 fatmult=1.5 invras=y
#	mv t$@ $R/$@
$R/synoffprim.v: #  img.I.sp.pr.vv.H img.M.sp.pr.vv.H
	Window3d < img.I.sp.pr.vv.H min2=7380 n2=1 min3=-750 max3=750 | \
	 Grey pclip=100 grid1=1 d1num=500 > tI.V label1='z(m)' label2='h(m)' geophysics=1 \
	title=' ' labelsz=18 labelfat=2 o1num=500
	Window3d < img.M.sp.pr.vv.H min2=7380 n2=1 min3=-750 max3=750  | \
	 Grey pclip=100 grid1=1 d1num=500 > tM.V  label1='z(m)' label2='h(m)' geophysics=1 \
	 title=' ' labelsz=18 labelfat=2 o1num=500
	Vppen < tI.V vpstyle=n xsize=2. ysize=4. out=tI.v > /dev/null
	Vppen < tM.V vpstyle=n xsize=2. ysize=4. out=tM.v xshift=1.8 > /dev/null
	vp_Overlay tM.v tI.v > $@
	Rm tI.V tM.V
	rm -f tI.v tM.v
$R/synoffni.v: #  img.I.sp.ni.vv.H img.M.sp.ni.vv.H
	Window3d < img.I.sp.ni.vv.H min2=7380 n2=1 min3=-750 max3=750 | \
	 Grey pclip=100 grid1=1 d1num=500 > tI.V label1='z(m)' label2='h(m)' geophysics=1 \
	title=' ' labelsz=12 labelfat=2 o1num=500
	Window3d < img.M.sp.ni.vv.H min2=7380 n2=1 min3=-750 max3=750  | \
	 Grey pclip=100 grid1=1 d1num=500 > tM.V  label1='z(m)' label2='h(m)' geophysics=1 \
	 title=' ' labelsz=12 labelfat=2 o1num=500
	Vppen < tI.V vpstyle=n xsize=2. ysize=4. out=tI.v > /dev/null
	Vppen < tM.V vpstyle=n xsize=2. ysize=4. out=tM.v xshift=1.8 > /dev/null
	vp_Overlay tM.v tI.v > $@
	Rm tI.V tM.V
	rm -f tI.v tM.v

$R/synangni.v:   ang.I.sp.ni.vv.H ang.M.sp.ni.vv.H
	Window3d < ang.I.sp.ni.vv.H n4=1 | \
	 Grey pclip=100 grid1=1 d1num=500 > tI.V label1='z(m)' label2='angle(deg)' geophysics=1 \
	title=' ' labelsz=12 labelfat=2 o1num=500 o2num=-40 
	Window3d < ang.M.sp.ni.vv.H n4=1  | \
	 Grey pclip=100 grid1=1 d1num=500 > tM.V  label1='z(m)' label2='angle(deg)' geophysics=1 \
	 title=' ' labelsz=12 labelfat=2 o1num=500 o2num=-40 
	Vppen < tI.V vpstyle=n xsize=2. ysize=4. out=tI.v > /dev/null
	Vppen < tM.V vpstyle=n xsize=2. ysize=4. out=tM.v xshift=1.8 > /dev/null
	vp_Overlay tM.v tI.v > $@
	Rm tI.V tM.V
	rm -f tI.v tM.v
#*********************************
wlet=ricker2 max2=.4
wlet=ricker1 max2=.4
wlet=bandpass max2=.6
square.%.v:
	Wavelet wavelet=$(wlet) n1=128 tdelay=.4 phase=minimum > wtd.H fund=43.
	Wavelet wavelet=$(wlet) n1=128 > w.H fund=43.
	Cat w.H wtd.H axis=2 space=n > w2.H
	Vel n1=128 vc=2000 hgrad=1.5 n2=128 n3=1 d1=10. d2=10 d3=1 z1=0 | Window3d n2=1 >v.H
	Math file1=v.H exp="1./file1" > vv.H
	Pad n2out=2 < vv.H extend=1 > v2.H
	< w2.H Rtoc | Ft3d sign1=-1 > fw2.H
	< v2.H Rtoc | Ft3d sign1=-1 > fv2.H
	Math file1=fw2.H  exp_real="file1.re*file1.re-file1.im*file1.im" \
	  exp_imag="file1.re*file1.im+file1.re*file1.im"  > time2.H
	Cp fw2.H time1.H
	Math file1=time2.H file2=fv2.H exp_real="file1.re*file2.re-file1.im*file2.im "\
	   exp_imag="file1.re*file2.im+file2.re*file1.im" > depth2.H 
	Math file1=fw2.H file2=fv2.H exp_real="file1.re*file2.re-file1.im*file2.im "\
	   exp_imag="file1.re*file2.im+file2.re*file1.im" > depth1.H 
	Ft3d < $*2.H sign1=1 | Real > tt2.H
	Ft3d < $*1.H sign1=1 | Real > tt1.H
	Scale scale_to=1. < tt1.H > t1.H
	Scale scale_to=1. < tt2.H > t2.H
	Cat t1.H t2.H axis=2 space=n | Spectra | Graph dash=0,2,3,4 grid1=1 min1=3. $(wlet)  \
	  out=$@ title=$* >/dev/null label1=$(wlet) label2=amplitude
	Rm wtd.H w.H w2.H vv.H v.H v2.H tt2.H tt1.H time2.H time1.H t2.H t1.H fw2.H fv2.H depth2.H depth1.H

square:square.depth.v square.time.v
	vp_Movie $^ > square.$(wlet).v
	rm -f $^
#square.%.v:
#	Wavelet wavelet=$* n1=128 tdelay=.4 phase=minimum > wtd.H fund=43.
#	Wavelet wavelet=$* n1=128 > w.H fund=43.
#	Cat w.H wtd.H axis=2 space=n > w2.H
#	Vel n1=128 vc=2000 hgrad=1.5 n2=128 n3=1 d1=10. d2=10 d3=1 z1=0 | Window3d n2=1 >v.H
#	Pad n2out=2 < v.H extend=1 > v2.H
#	< w2.H Rtoc |Ft3d sign1=-1 > fw2.H
#	< v2.H Rtoc |Ft3d sign1=-1 > fv2.H
#	Math file1=fw2.H  exp_real="file1.re*file1.re-file1.im*file1.im" \
#	  exp_imag="file1.re*file1.im+file1.re*file1.im"  > sqfw2.H
#	Math file1=sqfw2.H file2=fv2.H exp_real="file1.re*file2.re-file1.im*file2.im "\
#	   exp_imag="file1.re*file2.im+file2.re*file1.im" > imfw2.H 
#	Ft3d < imfw2.H sign1=1 | Real > sqw2.H
#	Scale scale_to=1. < w2.H > tw2.H
#	Scale scale_to=1. < sqw2.H > tsqw2.H
#	Cat w2.H sqw2.H axis=2 space=n | Spectra | Graph dash=0,2,3,4 grid1=1 out=$@ title=$* >/dev/null
#	Rm tw2.H tsqw2.H fw2.H w2.H w.H wtd.H sqfw2.H v.H fv2.H v2.H
#square.v:square.spike.v square.bandpass.v square.ricker0.v square.ricker1.v square.ricker2.v
#	tube $^

#*********************************
#----------------------------------------------------------------
#migrate GOM 

$R/gulf.v:imgP.gulf.H imgM.gulf.H
	Grey < imgP.gulf.H tpow=1.5 pclip=99 label1='z(km)' label2='x(km)' geophysics=1 \
	 labelsz=4 labelfat=1 d1num=1 title=' ' crowd=.89 o2num=2. |\
	Vppen vpstyle=n > /dev/null out=a.v xsize=6. ysize=4.8 yshift=4.6 xshift=-.2
	Grey < imgM.gulf.H tpow=1.5 pclip=99 label1='z(km)' label2='x(km)' geophysics=1 \
	 labelsz=4 labelfat=1 d1num=1 title=' ' crowd=.89 o2num=2. |\
	Vppen vpstyle=n > /dev/null out=b.v xsize=6. ysize=4.8 yshift=0. xshift=-.2
	vp_Overlay a.v b.v >$@
	rm -f a.v b.v
gulf.offset.H:#$WESTERN_GULF/img.shotprofile.3refv.H
	< $WESTERN_GULF/img.shotprofile.3refv.H Window3d f2=200 n2=1 >$@
gulf.ang.H:gulf.offset.H
	Interp < gulf.offset.H d2out=.00667 | OFF2ANG nzpad=1000 > $@
$R/gulfp.v:gulf.H gulf.ang.H
	 < gulf.H Window3d n3=1 f3=200 min1=1.8 max1=7. >a.H
	Grey < a.H tpow=1.4 label1='t(s)'  label2='offset(km)'  geophysics=1 \
	 labelsz=14 labelfat=1 d1num=2 title=' ' crowd=.89  |\
	Vppen vpstyle=n > /dev/null out=a.v ysize=4  yshift=.27 xshift=.12 xsize=2.
	< gulf.ang.H Window3d f1=30 |\
	Grey tpow=1.2 label1='z(km)' label2='angle(deg)'  geophysics=1  \
	 labelsz=14 labelfat=1 d1num=1 title=' ' crowd=.89 o2num=-40. pclip=94 |\
	Vppen vpstyle=n > /dev/null out=b.v ysize=4.  yshift=.27 xshift=2.45 xsize=2.
	vp_Overlay a.v b.v > $@
	rm -f a.v b.v

$R/gulfs.v:imgP.gulf.H imgM.gulf.H
	Window3d < imgP.gulf.H max2=5.5 |Spectra mode=all | Scale scale_to=1 > b.H
	Window3d < imgM.gulf.H max2=5.5 | Spectra mode=all | Scale scale_to=1 > a.H
	< a.H Graph label1='k_z(1/km)' label2='norm.ampl.(units)' d2num=0.5 crowd1=.87 \
	   labelfat=3 labelsz=10 out=a.v plotfat=3 > /dev/null labelrot=0 title=' ' dash=2
	< b.H Graph label1='k_z(1/km)' label2='norm.ampl.(units)' d2num=0.5 crowd1=.87 \
	   labelfat=3 labelsz=10 out=b.v plotfat=3 > /dev/null labelrot=0 title=' ' dash=0
	vp_Overlay a.v b.v > $@
	rm -f a.v b.v
FWB=3.0
m.gulf.H: imgP.gulf.H imgM.gulf.H #
	 < imgP.gulf.H Scale scale_to=1. > ttI$@
	 < imgM.gulf.H Add scale=-1 | Scale scale_to=1.> ttM$@
	echo o2=-8. >>  ttI$@
	echo o2=-8. >>  ttM$@
	< ttI$@ Mute tmute=3. vmute=8.5 tramp=.2 | Window3d min1=$(FWB) > tI$@	
	< ttM$@ Mute tmute=3. vmute=8.5 tramp=.2 | Window3d min1=$(FWB) > tM$@
	Rm ttI$@ ttM$@
#	 < imgP.gulf.H Window3d min1=$(FWB) |Tpow tpow=1.5| Scale scale_to=1.5 > tI$@
#	 < imgM.gulf.H Window3d min1=$(FWB) |Add scale=-1 | Scale scale_to=1.> tM$@
	${B}/Ultimatch-new-all.x < tI$@ multiples_in=tM$@ nfilt=8,3 npatch=20,100 \
	   nouter=1 niter=100 eps=1. mu=1.0 wmode=1 mode=2 nsmode=1 op=1 2D=y dtest=n > t$@
	Pad beg1=283 < t$@ | Mute tmute=2.89 tramp=.5 vmute=0.0 > $@
	Cat axis=3 tI$@  t$@ | Grey gainpanel=e clip=.4  | Tube &
#	Rm  tI$@ tM$@ t$@

##  p1 is semigood only-primary result
pa.gulf.H: imgP.gulf.H m.gulf.H 
	< $< Scale scale_to=1.> t$@
#	< $< Tpow tpow=1.5 tmin=3.10155|Scale scale_to=1.> t$@
	Add scale=-1.,1. mode=sum m.gulf.H  t$@ > $@
	Cat tpa.gulf.H pa.gulf.H m.gulf.H | Grey tpow=1.4 | Tube &

#	Rm t$@
##  p2 is supergood only-primary result
pb.gulf.H:imgP.gulf.H pa.gulf.H
	< imgP.gulf.H Scale scale_to=1. > tI$@
	< pa.gulf.H   Scale scale_to=1.> tM$@
	/net/koko/brad/bin/LINUX/Ultimatch-new-all.x < tI$@ \
	  multiples_in=tM$@ nfilt=17,17 npatch=10,1 nouter=1  dtest=n \
	  niter=40 eps=30. mu=1.0 wmode=1 mode=2 nsmode=1 op=1 2D=y> $@
	Rm  tI$@ tM$@
$R/gsub.v: imgP.gulf.H imgM.gulf.H pb.gulf.H
	< pb.gulf.H Window3d min1=3.| Grey pclip=98 label1='z(km)' label2='x(km)' geophysics=1 \
	 labelsz=7 labelfat=1 d1num=1 title=' ' crowd=.89 o2num=2 |\
	Vppen vpstyle=n > /dev/null out=a.v xsize=6. ysize=3. yshift=0.08 xshift=-.1
	< imgM.gulf.H Window3d min1=3.| Grey pclip=98 label1='z(km)' label2='x(km)' geophysics=1 \
	 labelsz=7 labelfat=1 d1num=1 title=' ' crowd=.89 o2num=2  |\
	Vppen vpstyle=n > /dev/null out=b.v xsize=6. ysize=3. yshift=2.85 xshift=-.1
	< imgP.gulf.H Window3d min1=3.| Grey pclip=98 label1='z(km)' label2='x(km)' geophysics=1 \
	 labelsz=7 labelfat=1 d1num=1 title=' ' crowd=.89 o2num=2  |\
	Vppen vpstyle=n > /dev/null out=c.v xsize=6. ysize=3. yshift=5.61 xshift=-.1
	vp_Overlay c.v b.v a.v >$@
	rm -f a.v b.v c.v

BIN=$B
#********************SIGSBEE********************
sgsb_initial_est_muls_1.H: sgsb_est_muls.H sgsb_est_prims.H sgsb_perf_data.H
	Scale < sgsb_est_muls.H dscale=1 > junk1.H
	Scale < sgsb_perf_data.H dscale=1.0 > target.H
	time ${BIN}/Ultimatch-new-all.x < target.H \
		multiples_in=junk1.H \
		nfilt=17,2 npatch=20,20 nouter=1 niter=50 eps=5. mu=1.0 \
		wmode=1 mode=2 nsmode=1 op=1 2D=y dtest=n > $@
	Grey < sgsb_perf_data.H clip=1.0 \
		title="Initial data" \
		out=sgsb_perf_data.v >/dev/null
	Grey < $@ clip=1.0 \
		title="Initial estimate of multiples" \
		out=sgsb_initial_est_muls_1.v >/dev/null
	Add scale=1,-1 sgsb_perf_data.H $@ > sgsb_initial_est_prims_1.H
	Grey < sgsb_initial_est_prims_1.H clip=1.0 \
		title="Initial estimate of primaries" \
		out=sgsb_initial_est_muls_1.v >/dev/null
	vp_OverUnderAniso sgsb_perf_data.v sgsb_initial_est_muls_1.v \
		sgsb_initial_est_muls_1.v > sgsb_intial.v
#	tube sgsb_intial.v
##  sig1 and sig2 are in ~brad/Research/Sigsbee
$R/sig3.v:sgsb_perf_data.H sgsb_perf_prims.H sgsb_perf_muls.H
	<sgsb_perf_data.H Window3d n2=100 |Spectra mode=all |Scale scale_to=1. > a.H
	<sgsb_perf_prims.H Window3d n2=100 |Spectra mode=all |Scale scale_to=1. > b.H
	<sgsb_perf_muls.H Window3d n2=100 |Spectra mode=all |Scale scale_to=1. > c.H
	< ../Sigsbee/img.mult.mult1.split.H Window3d n2=100 j1=2 |\
	  Spectra mode=all |Scale scale_to=1. > d.H
	Cat axis=2 space=n a.H b.H d.H c.H  |\
	Graph crowd=.89 legend=1 legendloc=tr curvelabel="P+M:P:M:pred. M" \
	  dash=0,1,4,5 label2="norm.ampli.(units)" label1="k_z(1/km)" labelrot=n |\
	Vppen yshift=.5 out=$@ vpstyle=n > /dev/null
	Rm a.H b.H d.H c.H
sgsb_matchprim.H:sgsb_initial_est_prims_1.H sgsb_perf_data.H
	Scale < sgsb_perf_data.H dscale=1.0 > target.H	
	${BIN}/Ultimatch-new-all.x < target.H \
		multiples_in=$< \
		nfilt=17,2 npatch=20,20 nouter=1 niter=70 eps=10. mu=1.0 \
		wmode=1 mode=2 nsmode=1 op=1 2D=y dtest=n > $@
	Rm target.H

$R/sigsub.v:sgsb_matchprim.H sgsb_perf_data.H sgsb_perf_prims.H
	< sgsb_perf_prims.H Window3d min1=6.| Grey pclip=90 label1='z(km)' label2='x(km)' geophysics=1 \
	 labelsz=7 labelfat=1 d1num=2 title=' ' crowd=.89  |\
	Vppen vpstyle=n > /dev/null out=a.v xsize=6. ysize=3. yshift=0.08 xshift=-.1
	< sgsb_matchprim.H Window3d min1=6.| Grey pclip=90 label1='z(km)' label2='x(km)' geophysics=1 \
	 labelsz=7 labelfat=1 d1num=2 title=' ' crowd=.89  |\
	Vppen vpstyle=n > /dev/null out=b.v xsize=6. ysize=3. yshift=2.85 xshift=-.1
	< sgsb_perf_data.H Window3d min1=6.| Grey pclip=90 label1='z(km)' label2='x(km)' geophysics=1 \
	 labelsz=7 labelfat=1 d1num=2 title=' ' crowd=.89  |\
	Vppen vpstyle=n > /dev/null out=c.v xsize=6. ysize=3. yshift=5.61 xshift=-.1
	vp_Overlay c.v b.v a.v >$@
	rm -f a.v b.v c.v

include ${SEPINC}/SEP.bottom
$R/%.ps:$R/%.v
	pstexpen $< $@ color=n fat=1 fatmult=1.5 invras=y

