BIN=$B
#PAR=./Par
## the .H files not computed in this makefile are in
## /net/koko/gabriel/Research/Multiples/FALL2005/NEWATTENUATION
##-------------------------------------------------------------------------
##-------------------------------------------------------------------------
##-------------------------------------------------------------------------
##-------------------------------------------------------------------------
#
## create model data (cmps) with two flat reflectors
## contains two primaries and 4 multiples
cmps_all.H: #${BIN}/two_flat_layers.x
	${BIN}/two_flat_layers.x zwb=400 zref=1200 vw=1500 vr=2500 \
		nh=200 oh=100 dh=10 ncmp=1 ocmp=2000 dcmp=5  \
		nt=400 dt=0.008 fpeak=20 \
		wb1=y wb2=n wb3=n amps=n rhow=1. rhor=2. rhohs=2.5 > $@

shots_all.H: #${BIN}/two_flat_layers.x
	${BIN}/two_flat_layers.x zwb=400 zref=1200 vw=1500 vr=2500 \
		nh=200 oh=100 dh=10 ncmp=1 ocmp=2000 dcmp=5  \
		nt=400 dt=0.008 fpeak=20 \
		wb1=y wb2=n wb3=n amps=n rhow=1. rhor=2. rhohs=2.5 > $@

muls_only.H: #${BIN}/two_flat_layers.x
	${BIN}/two_flat_layers.x zwb=400 zref=1200 vw=1500 vr=2500 \
		nh=200 oh=100 dh=10 ncmp=1 ocmp=2000 dcmp=5  \
		nt=400 dt=0.008 fpeak=20 prim1=n prim2=n \
		wb1=y wb2=n wb3=n amps=n rhow=1. rhor=2. rhohs=2.5 > $@

prims_only.H: #${BIN}/two_flat_layers.x
	${BIN}/two_flat_layers.x zwb=400 zref=1200 vw=1500 vr=2500 \
		nh=200 oh=100 dh=10 ncmp=100 ocmp=2000 dcmp=5  \
		nt=400 dt=0.008 fpeak=20 prim1=y prim2=y \
		wb1=n wb2=n wb3=n sm1=n im1=n plg1=n amps=n rhow=1. rhor=2. rhohs=2.5 > $@

cmp_vels.H: #${BIN}/make_vels.x
	${BIN}/make_vels.x nl=3 v=1500,2500,3500 dipx=0,0 dipy=0,0 \
		zref0=400,1200 nz=1000 dz=5 oz=0 ncmpx=1000 ocmpx=0 \
		dcmpx=5 ncmpy=1 dcmpy=5 ocmpy=0 verb=1 >$@
cmp_vels_plot.H: #${BIN}/make_vels.x
	${BIN}/make_vels.x nl=3 v=1.5,2.5,3.5 dipx=0,0 dipy=0,0 \
		zref0=400,1200 nz=1000 dz=5 oz=0 ncmpx=1000 ocmpx=0 \
		dcmpx=5 ncmpy=1 dcmpy=5 ocmpy=0 verb=1 >$@

one_muls_only.H one_prims_only.H one_all.H: prims_only.H muls_only.H cmps_all.H
	Window3d < muls_only.H n3=1 > one_muls_only.H
	Window3d < prims_only.H n3=1 > one_prims_only.H
	Window3d < cmps_all.H n3=1 > one_all.H

# scale multiples and match them to the data with the standard goal
# Mf=d. The kinematics of the estmated multiples is perfect
#matched_muls.H matched_prims.H: one_muls_only.H one_all.H
#	Scale < one_muls_only.H dscale=0.1 > junk1.H
#	Scale < one_all.H dscale=1.0 > target.H
#	time ${BIN}/Ultimatch-new-all.x < target.H \
#		multiples_in=junk1.H primaries_in=junk2.H \
#		nfilt=27,1 npatch=1,1 wmode=1 mode=2 nsmode=1 \
#		op=1 mu=1.0 2D=y niter=20 eps=1. dtest=n > $@
#	Add scale=1,-1 one_all.H $@ > matched_prims.H

#nfilt=7,2 npatch=100,50 nouter=1 niter=200 eps=1. mu=1.0
match_muls.H: ang.I.sp.ni.vv.H ang.M.sp.ni.vv.H
	Window3d < ang.I.sp.ni.vv.H n4=1 |Scale scale_to=1.> tImatch.ang.H
	Window3d < ang.M.sp.ni.vv.H n4=1 |Scale scale_to=1.> tMmatch.ang.H
	/net/koko/brad/bin/LINUX/Ultimatch-new-all.x < tImatch.ang.H \
		multiples_in=tMmatch.ang.H \
		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 > $@

match_muls_resid.H: ang.I.sp.ni.vv.H match_muls.H
	Window3d < ang.I.sp.ni.vv.H n4=1 |Scale scale_to=1.> tImatch.ang.H
	Add scale=-1,1 match_muls.H tImatch.ang.H > $@

match_muls_comp.H: ang.I.sp.ni.vv.H match_muls.H ang.M.sp.ni.vv.H
	Window3d < ang.I.sp.ni.vv.H n4=1 |Scale scale_to=1.> tImatch.ang.H
	Window3d < ang.M.sp.ni.vv.H n4=1 |Scale scale_to=1.> tMmatch.ang.H
	Cat3d axis=2 space=y tMmatch.ang.H match_muls.H tImatch.ang.H match_muls_resid.H > $@

match_muls_comp.v: match_muls_comp.H
	Grey <  $< grid2=1 d2num=124.6 o2num=-60 out=$@ > /dev/null
	tube < $@
#nfilt=17,2 npatch=10,1 nouter=1 niter=40 eps=10.
est_prims.H: ang.I.sp.ni.vv.H match_muls.H
	Window3d < ang.I.sp.ni.vv.H n4=1 |Scale scale_to=1.> tImatch.ang.H
	Add scale=1,-1 tImatch.ang.H match_muls.H > $@

match_prims.H: ang.I.sp.ni.vv.H est_prims.H
	Window3d < ang.I.sp.ni.vv.H n4=1 |Scale scale_to=1.> tImatch.ang.H
	Window3d < est_prims.H |Scale scale_to=1.> tMmatch.ang.H
	/net/koko/brad/bin/LINUX/Ultimatch-new-all.x < tImatch.ang.H \
		multiples_in=tMmatch.ang.H \
		nfilt=17,17 npatch=10,1 nouter=1 niter=40 eps=30. mu=1.0 \
		wmode=1 mode=2 nsmode=1 op=1 2D=y dtest=n > $@

match_prims_comp.H: ang.I.sp.ni.vv.H est_prims.H match_prims.H
	Window3d < ang.I.sp.ni.vv.H n4=1 |Scale scale_to=1.> tImatch.ang.H
	Cat3d axis=2 space=y tImatch.ang.H est_prims.H match_prims.H > $@

match_prims_comp.v: match_prims_comp.H
	Grey <  $< grid2=1 d2num=124.6 o2num=-60 out=$@ > /dev/null
