PAR=./Par
HOME=/net/koko/homes/sep/gabriel/Research/main/Multiples/FALL2005/NEWATTENUATION
BIN=../Bin
BIN1=/net/koko/gabriel/Research/Multiples/FALL2005/NEWATTENUATION/Bin
BIN2=/net/koko/gabriel/Research/Multiples/GOM_TEST/bin
SRC1=./mysrc
SRC2=${HOME}/Src/Antoine/Lib/separ
SRC3=${HOME}/Src/Antoine/Lib/Src
BIN3=${HOME}/Src/Antoine/Lib/bin/LINUX
TT=./TT
BOBWEI=/net/koko/homes/sep/gabriel/Thesis/Fortran/Multiples/BOBWEI/wei
PK=./Picks

${BIN}/two_flat_layers.x: ${SRC1}/two_flat_layers.f90
	cd ${SRC1}; make two_flat_layers.x; cd ${HOME}
	mv ${SRC1}/two_flat_layers.x $@

${BIN}/make_vels.x: ${SRC1}/make_vels.f90
	cd ${SRC1}; make make_vels.x; cd ${HOME}
	mv ${SRC1}/make_vels.x $@

${BIN}/cmp_mute.x: ${SRC1}/cmp_mute.f90
	cd ${SRC1}; make cmp_mute.x; cd ${HOME}
	mv ${SRC1}/cmp_mute.x $@

${BIN}/Ultimatch-new.x: ${SRC3}/Ultimatch-new.f90 ${SRC2}/findmatch.f90 ${SRC2}/bigsolver.f90
	cd ${SRC2}; make all; cd ${SRC3}; make ulti
	cd ${HOME}; mv ${BIN3}/Ultimatch-new.x $@

# 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=100 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=100 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 >$@

freq_cmps_all.H: cmps_all.H
	@echo "o2=50 d2=5 label2=half-offset" >>cmps_all.H
	Pad < cmps_all.H beg2=200 > junk1.H
	Transf < junk1.H wei=y verb=y > junk2.H
	@echo "label1=hoffx label2=cmpx label3=offy label4=cmpy">>junk2.H
	Transp < junk2.H reshape=1,3,4,5 plane=12 maxsize=400 > $@
	echo "label1=cmpx label2=cmpy label3=hoffx label4=hoffy" >> $@

mig_cmps_all.H: freq_cmps_all.H cmp_vels.H
	mig_off D=freq_cmps_all.H velocity=cmp_vels.H R=$@ \
		image_real=n wei_image_real=n \
		lloyd_nref=1 wei_velocity=y adj=y \
		nz=400 dz=10 oz=0 wei_nzb=200 \
		program=${BOBWEI}/Phase.x

#nw=256 dw=0.244140625 ow=0
mig_cmps_all_inv.H: cmp_vels.H mig_cmps_all.H
	model_off R=mig_cmps_all.H velocity=cmp_vels.H \
		D=JUNK.H lloyd_nref=1 wei_velocity=y adj=n \
		nw=200 dw=0.3125 ow=0 wei_nwb=200 \
		program=${BOBWEI}/Phase.x
	Transf < JUNK.H wei=y > JUNK1.H
	Window3d < JUNK1.H min2=2000 n2=100 min4=50 n4=200 > JUNK2.H
	Transp < JUNK2.H plane=23 > JUNK3.H
	Interp < JUNK3.H n1out=400 o1out=0 d1out=0.008 > $@  
	echo "label2=half-offset" >> $@
	echo "label3=cmp" >> $@

# do adaptive subtraction of the multiples to get the primaries
#time ${BIN}/Ultimatch-new.x < junk.H 
est_cmps_all_matched.H: cmps_all.H mig_cmps_all_inv.H
	Window3d < cmps_all.H n3=2 min3=2200 > target.H
	Window3d < mig_cmps_all_inv.H n3=2 min3=2200 > junk.H
	time ${BIN2}/Ultimatch-new-weight.x < junk.H \
		target=target.H \
		mode=2 nsmode=1 wmode=1 nfilt=17,17 npatch=100,200 \
		invmode=1 niter=60 2D=1 eps=0.0 > $@

# subtract matched data from original
resid_cmps_all.H: cmps_all.H est_cmps_all_matched.H
	Window3d < cmps_all.H n3=2 min3=2200 > target.H
	Math file1=target.H \
		file2=est_cmps_all_matched.H exp="file1-file2" >$@

#----------------------------------------------------------------
# create mask of ones and zeros for vertical(v) and general(g) mute
# to zero_out the primaries
mask_prep.H: mig_cmps_all.H
	Window3d < mig_cmps_all.H > junk.H
	Transp < junk.H plane=13 > $@ maxsize=1000

mask_mul.%.H: mask_prep.H
	${BIN}/cmp_mute.x < $< picks_file=${PK}/picks_mul.$* \
		mask=y complement=n > junk2.H
	echo "esize=4" >> junk2.H
	Smooth < junk2.H tridiag=1 rect1=5 rect2=3 > junk3.H
	Transp < junk3.H plane=13 > $@ maxsize=1000

# create mask of ones and zeros for vertical(v) and general(g) mute
# to zero_out the multiples
mask_prim.%.H: mask_prep.H
	${BIN}/cmp_mute.x < $< picks_file=${PK}/picks_prim.$* \
		mask=y complement=y > junk2.H
	echo "esize=4" >> junk2.H
	Smooth < junk2.H tridiag=1 rect1=5 rect2=3 > junk3.H
	Transp < junk3.H plane=13 > $@ maxsize=1000

# create multiple model
# need to convert the mask to complex in order to use Math
# need to remap the mask to the same dimensions as the migrated data
mig_muls.%.H: mask_mul.%.H mig_cmps_all.H
	Rtoc < mask_mul.$*.H > junk.H
	echo "n2=1 o2=0 d2=1 label2=CMP_Y" >> junk.H
	echo "n3=400 o3=-950 d3=5 label3=H_X" >> junk.H
	echo "n4=1 o4=0 d4=1 label4=H_Y" >> junk.H
	echo "n5=400 o5=0 d5=10 label5=DEPTH" >> junk.H
	Math file1=mig_cmps_all.H file2=junk.H \
		exp_real='file1.re*file2.re' exp_imag='file1.re*file2.im' > $@

# create PRIMARY model
# need to convert the mask to complex in order to use Math
# need to remap the mask to the same dimensions as the migrated data
mig_prims.%.H: mask_prim.%.H mig_cmps_all.H
	Rtoc < mask_prim.$*.H > junk.H
	echo "n2=1 o2=0 d2=1 label2=CMP_Y" >> junk.H
	echo "n3=400 o3=-950 d3=5 label3=H_X" >> junk.H
	echo "n4=1 o4=0 d4=1 label4=H_Y" >> junk.H
	echo "n5=400 o5=0 d5=10 label5=DEPTH" >> junk.H
	Math file1=mig_cmps_all.H file2=junk.H \
		exp_real='file1.re*file2.re' exp_imag='file1.re*file2.im' > $@

# do inverse migration of the multiples
# need Interp to interpolate to the original sampling interval
est_muls.%.H: cmp_vels.H mig_muls.%.H
	model_off R=mig_muls.$*.H \
		velocity=cmp_vels.H \
		D=JUNK.H lloyd_nref=1 wei_velocity=y adj=n \
		nw=200 dw=0.3125 ow=0 wei_nwb=200\
		program=${BOBWEI}/Phase.x
	Transf < JUNK.H wei=y > JUNK1.H
	Window3d < JUNK1.H min2=2000 n2=100 min4=50 n4=200 > JUNK2.H
	Transp < JUNK2.H plane=23 > JUNK3.H
	Interp < JUNK3.H n1out=400 o1out=0 d1out=0.008 > $@  
	echo "label2=half-offset" >> $@
	echo "label3=cmp" >> $@

# do inverse migration of the PRIMARIES
# need Interp to interpolate to the original sampling interval
est_prims.%.H: #cmp_vels.H mig_prims.%.H
	model_off R=mig_prims.$*.H \
		velocity=cmp_vels.H \
		D=JUNK.H lloyd_nref=1 wei_velocity=y adj=n \
		nw=200 dw=0.3125 ow=0 wei_nwb=200\
		program=${BOBWEI}/Phase.x
	Transf < JUNK.H wei=y > JUNK1.H
	Window3d < JUNK1.H min2=2000 n2=100 min4=50 n4=200 > JUNK2.H
	Transp < JUNK2.H plane=23 > JUNK3.H
	Interp < JUNK3.H n1out=400 o1out=0 d1out=0.008 > $@  
	echo "label2=half-offset" >> $@
	echo "label3=cmp" >> $@

# do adaptive subtraction of the multiples to get the primaries
# DO NOT use the estimate of the primaries, just the multiples
est_muls_matched.%.H: cmps_all.H est_muls.%.H
	Window3d < cmps_all.H n3=1 min3=2200 | Scale scale_to=1.0> target.H
	Window3d < est_muls.$*.H n3=1 min3=2200 | Scale scale_to=1.0> junk.H
	time ${BIN}/Ultimatch-new-all.x < target.H \
		multiples_in=junk.H \
		mode=2 nsmode=1 wmode=1 nfilt=57,17 npatch=50,50 \
		row_op=0 niter=100 2D=1 eps=0.0 > $@

# do adaptive subtraction of the multiples to get the primaries
# using the estimate of the primaries as well as that of the multiples
est_muls_matched_row.%.H: cmps_all.H est_muls.%.H
	Window3d < cmps_all.H n3=1 min3=2200 | Scale scale_to=1.0> target.H
	Window3d < est_muls.$*.H n3=1 min3=2200 | Scale scale_to=1.0> junk1.H
	Window3d < est_prims.$*.H n3=1 min3=2200 | Scale scale_to=1.0> junk2.H
	time ${BIN}/Ultimatch-new-all.x < target.H \
		multiples_in=junk1.H primaries_in=junk2.H \
		mode=2 nsmode=1 wmode=1 nfilt=57,17 npatch=50,50 \
		row_op=1 niter=100 2D=1 eps=0.0 > $@

#mode=2 nsmode=1 wmode=1 nfilt=17,17 npatch=100,200
#mode=2 nsmode=1 wmode=1 nfilt=10,10 npatch=10,20
#invmode=1 niter=5 2D=1 eps=0.0 > junk1.H
# subtract matched multiples from original data
resid_muls.%.H: cmps_all.H est_muls_matched.%.H
	Window3d < cmps_all.H n3=2 min3=2200 | Scale scale_to=1.0 > target.H
	Scale < est_muls_matched.$*.H scale_to=1.0 > junk.H
	Math file1=target.H \
		file2=junk.H exp="file1-file2" >$@

resid_muls_row.%.H: cmps_all.H est_muls_matched_row.%.H
	Window3d < cmps_all.H n3=2 min3=2200 | Scale scale_to=1.0 > target.H
	Scale < est_muls_matched_row.$*.H scale_to=1.0 > junk.H
	Math file1=target.H \
		file2=junk.H exp="file1-file2" >$@

# compute the envelope of the estimated primaries
est_prims_env.%.H: #est_prims.%.H
	Window3d < est_prims.$*.H n3=2 min3=2200 > junk.H
	Envelope < junk.H tc1=1 tc2=1 freq=0 > $@

# compute weight to prevent the adaptive subtraction from matching
# the inexisting primaries in the multiple model
#Clip < $< chop=greater clip=0.002 to=0 > junk.H
#Clip < junk.H chop=greater clip=0.0 to=1 > junk1.H
weight.%.H: est_prims_env.%.H
	Clip < $< chop=greater clip=0.0019 to=0 > junk.H
	Clip < junk.H chop=greater clip=0.0 to=1 > junk1.H
	Smooth < junk1.H tridiag=1 rect1=1 rect2=1 > $@
	

# do adaptive subtraction of the multiples with the envelope
# of he primaries as a weight
#time ${BIN2}/Ultimatch-new.x < junk.H
est_muls_constrained_matched.%.H: #cmps_all.H est_muls.%.H weight.%.H
	Window3d < cmps_all.H n3=1 min3=2200 | Scale scale_to=1.0> target.H
	Window3d < est_muls.$*.H n3=1 min3=2200 | Scale scale_to=1.0> junk.H
		time ${BIN}/Ultimatch-new-all.x < target.H \
		multiples_in=junk.H weight=weight.$*.H \
		mode=2 nsmode=1 wmode=3 nfilt=17,17 npatch=150,200 \
		invmode=1 niter=100 2D=1 eps=0. > $@

resid_muls_constrained.%.H: cmps_all.H est_muls_constrained_matched.%.H
	Window3d < cmps_all.H n3=1 min3=2200 | Scale scale_to=1.0 > target.H
	Scale < est_muls_constrained_matched.$*.H scale_to=1.0 > junk.H
	Math file1=target.H \
		file2=junk.H exp="file1-file2" >$@

#-------------------------------------------------------------------------
#-------------------------------------------------------------------------
#-------------------------------------------------------------------------
cmp_vels_scale.%.H: cmp_vels.H
	Scale < $< dscale=$* >$@

mig_cmps_all.scale.%.H: freq_cmps_all.H cmp_vels_scale.%.H
	mig_off D=freq_cmps_all.H velocity=cmp_vels_scale.$*.H R=$@ \
		image_real=n wei_image_real=n \
		lloyd_nref=1 wei_velocity=y adj=y \
		nz=400 dz=10 oz=0 wei_nzb=400 \
		program=${BOBWEI}/Phase.x























#-------------------------------------------------------------------------
# create mask of ones and zeros for vertical(v) and general(g) mute
one_zeros_no_wbms_%.H: ${BIN}/cmp_mute.x \
		${PK}/picks_no_wbms_% mig_cmps_2fr_no_wbms.scale_%.H
	Window3d < mig_cmps_2fr_no_wbms.scale_$*.H > junk.H
	Transp < junk.H plane=13 > junk1.H maxsize=1000
	${BIN}/cmp_mute.x < junk1.H picks_file=${PK}/picks_no_wbms_$* mask=y > $@
	echo "esize=4" >> $@
mask_no_wbms_%.H: one_zeros_no_wbms_%.H
	Smooth < $< tridiag=1 rect1=5 rect2=5 > junk4.H
	Transp < junk4.H plane=13 > $@ maxsize=1000 max_size=1000
	echo "label1=CMP_X" >> $@
	echo "n2=1 o2=0 d2=1 label2=CMP_Y" >> $@
	echo "n3=380 o3=-850 d3=5 label3=H_X" >> $@
	echo "n4=1 o4=0 d4=1 label4=H_Y" >> $@
	echo "n5=400 o5=0 d5=10 label5=DEPTH" >> $@

${TT}/mask_no_wbms_%.T: mask_no_wbms_%.H
	Window3d < $< | Transp plane=13 > junk.H
	Grey < junk.H eout=1 pclip=100 > $@
	Ricksep < $@ &

# create multiple model
mig_muls_2fr_no_wbms.scale_%.H: mask_no_wbms_%.H mig_cmps_2fr_no_wbms.scale_%.H
	Rtoc < mask_no_wbms_$*.H > junk.H
	Math file1=mig_cmps_2fr_no_wbms.scale_$*.H file2=junk.H \
		exp_real='file1.re*file2.re' exp_imag='file1.re*file2.im' > $@
	echo "label1=CMP_X label2=CMP_Y label3=H_X label4=H_Y label5=DEPTH">>$@

${TT}/mig_muls_2fr_no_wbms.scale_%.T: mig_muls_2fr_no_wbms.scale_%.H
	Window3d < $< > junk.H
	Transp < junk.H plane=13 > junk1.H maxsize=1000 max_size=1000
	Real < junk1.H > junk2.H
	Grey < junk2.H eout=1 pclip=100 > $@
	Ricksep < $@ &

# do inverse migration of the multiples
# need Interp to interpolate to the original sampling interval
muls_2fr_no_wbms.scale_%.H: ${PAR}/parmig_inv.P \
		vel_3fl.scale_%.H mig_muls_2fr_no_wbms.scale_%.H
	model_off R=mig_muls_2fr_no_wbms.scale_$*.H \
		velocity=vel_3fl.scale_$*.H \
		D=JUNK.H lloyd_nref=1 wei_velocity=y adj=n \
		nw=200 dw=0.3125 ow=0 wei_nwb=200\
		program=${BOBWEI}/Phase.x
	Transf < JUNK.H wei=y > JUNK1.H
	Window3d < JUNK1.H min2=2000 n2=200 min4=50 n4=200 > JUNK2.H
	Transp < JUNK2.H plane=23 > JUNK3.H
	Interp < JUNK3.H n1out=400 o1out=0 d1out=0.008 > $@  
	echo "label2=half-offset" >> $@
	echo "label3=cmp" >> $@

# plot the inverted data
${TT}/muls_2fr_no_wbms.scale_%.T: muls_2fr_no_wbms.scale_%.H
	Grey < $< eout=1 pclip=100 gainpanel=a > $@
	Ricksep < $@ &

######################################################################
#	make test WITH FIRST ORDER water-bottom multiples 
####################################################################
mig_cmps_2fr_wbm.scale.%.H: freq_cmps_2fr_wbm.H vel_3fl.scale_%.H \
	${PAR}/parmig_fwd.P
	mig_off D=freq_cmps_2fr_wbm.H velocity=vel_3fl.scale_$*.H R=$@ \
		image_real=n wei_image_real=n \
		lloyd_nref=1 wei_velocity=y adj=y \
		nz=400 dz=10 oz=0 wei_nzb=400 \
		program=${BOBWEI}/Phase.x

mig_cmps_2fr_wbm.scale_v%.H mig_cmps_2fr_wbm.scale_g%.H: \
		mig_cmps_2fr_wbm.scale.%.H
	cp $< $@

${TT}/mig_cmps_2fr_wbm.scale.%.T: mig_cmps_2fr_wbm.scale.%.H
	Window3d < $< | Real | Transp reshape=2,3 plane=12 > junk.H
	Grey < junk.H eout=1 gainpanel=a > $@
	Ricksep < $@ &

# create mask of ones and zeros for vertical(v) and general(g) mute
prep_ones_zeros_wbm_%.H: mig_cmps_2fr_wbm.scale.%.H
	Window3d < mig_cmps_2fr_wbm.scale.$*.H > junk.H
	Transp < junk.H plane=13 > $@ maxsize=1000

ones_zeros_wbm.mul_%.H: prep_ones_zeros_wbm_%.H
	${BIN}/cmp_mute.x < $< picks_file=${PK}/picks_wbm_$* \
		mask=y complement=n > $@
	echo "esize=4" >> $@

ones_zeros_wbm.prim_%.H: prep_one_zeros_wbm_%.H
	${BIN}/cmp_mute.x < junk1.H picks_file=${PK}/picks_wbm_$* \
		mask=y complement=y > $@
	echo "esize=4" >> $@

mask_wbm_%.H: ones_zeros_wbm_%.H
	Smooth < $< tridiag=1 rect1=5 rect2=5 > junk4.H
	Transp < junk4.H plane=13 > $@ maxsize=1000 max_size=1000
	echo "label1=CMP_X" >> $@
	echo "n2=1 o2=0 d2=1 label2=CMP_Y" >> $@
	echo "n3=380 o3=-850 d3=5 label3=H_X" >> $@
	echo "n4=1 o4=0 d4=1 label4=H_Y" >> $@
	echo "n5=400 o5=0 d5=10 label5=DEPTH" >> $@

${TT}/mask_wbm_%.T: mask_wbm_%.H
	Window3d < $< | Transp plane=13 > junk.H
	Grey < junk.H eout=1 pclip=100 > $@
	Ricksep < $@ &

# create multiple model or primary model
mig_2fr_wbm.scale_%.H: mask_wbm_%.H mig_cmps_2fr_wbm.scale_%.H
	Rtoc < mask_wbm_$*.H > junk.H
	Math file1=mig_cmps_2fr_wbm.scale_$*.H file2=junk.H \
		exp_real='file1.re*file2.re' exp_imag='file1.re*file2.im' > $@
	echo "label1=CMP_X label2=CMP_Y label3=H_X label4=H_Y label5=DEPTH">>$@

# plot multiple model or primary
# plot the inverted data
${TT}/mig_muls_2fr_wbm.scale_%.T: mig_muls_2fr_wbm.scale_%.H
	Window3d < $< > junk.H
	Transp < junk.H plane=13 > junk1.H maxsize=1000 max_size=1000
	Real < junk1.H > junk2.H
	Grey < junk2.H eout=1 pclip=100 > $@
	Ricksep < $@ &

# do inverse migration of the multiples or the primaries
# need Interp to interpolate to the original sampling interval
inv_2fr_wbm.scale_%.H: ${PAR}/parmig_inv.P \
		vel_3fl.scale_%.H mig_2fr_wbm.scale_%.H
	model_off R=mig_2fr_wbm.scale_$*.H velocity=vel_3fl.scale_$*.H \
		D=JUNK.H lloyd_nref=1 wei_velocity=y adj=n \
		nw=200 dw=0.3125 ow=0 wei_nwb=200\
		program=${BOBWEI}/Phase.x
	Transf < JUNK.H wei=y > JUNK1.H
	Window3d < JUNK1.H min2=2000 n2=200 min4=50 n4=200 > JUNK2.H
	Transp < JUNK2.H plane=23 > JUNK3.H
	Interp < JUNK3.H n1out=400 o1out=0 d1out=0.008 > $@  
	echo "label2=half-offset" >> $@
	echo "label3=cmp" >> $@

# plot the inverted data
${TT}/inv_2fr_wbm.scale_%.T: inv_2fr_wbm.scale_%.H
	Grey < $< eout=1 pclip=100 gainpanel=a > $@
	Ricksep < $@ &

# match the multiples and the primaries to the original data
muls_2fr_wbm.scale_%_matched.H: cmps_2fr_wbm.H \
	muls_2fr_wbm.scale_%.H
	Window3d < cmps_2fr_wbm.H n3=2 min3=2500 > target.H
	Window3d < muls_2fr_wbm.scale_$*.H n3=2 min3=2500 > junk.H
	time ${BIN2}/Ultimatch-new.x < junk.H \
		target=target.H \
        mode=2 nsmode=1 wmode=1 nfilt=17,17 npatch=100,200 \
        invmode=1 niter=10 2D=1 eps=0.0 > $@

${TT}/muls_2fr_wbm.scale_%_matched.T: muls_2fr_wbm.scale_%_matched.H
	Grey < $< eout=1 clip=1 > $@
	Ricksep < $@ &

data-muls_2fr_wbm.scale_%.H: cmps_2fr_wbm.H \
	muls_2fr_wbm.scale_%_matched.H
	Math file1=target.H \
		file2=muls_2fr_wbm.scale_$*_matched.H exp="file1-file2" >$@

${TT}/data-muls_2fr_wbm.scale_%.T: data-muls_2fr_wbm.scale_%.H
#Grey < $< eout=1 newclip=1 bclip=-0.743469 eclip=1 >$@
	Grey < $< eout=1 clip=1 >$@
	Ricksep < $@

#------------------------------------------------------------------
# compute demigration of migration with exact velocity without
# multing the primaries
prim_muls_2fr_wbm.scale_%.H: ${PAR}/parmig_inv.P \
		vel_3fl.scale_%.H mig_cmps_2fr_wbm.scale.%.H
	model_off R=mig_cmps_2fr_wbm.scale.$*.H velocity=vel_3fl.scale_$*.H \
		D=JUNK.H lloyd_nref=1 wei_velocity=y adj=n \
		nw=200 dw=0.3125 ow=0 wei_nwb=200\
		program=${BOBWEI}/Phase.x
	Transf < JUNK.H wei=y > JUNK1.H
	Window3d < JUNK1.H min2=2000 n2=200 min4=50 n4=200 > JUNK2.H
	Transp < JUNK2.H plane=23 > JUNK3.H
	Interp < JUNK3.H n1out=400 o1out=0 d1out=0.008 > $@  
	echo "label2=half-offset" >> $@
	echo "label3=cmp" >> $@

# plot the inverted data
${TT}/prim_muls_2fr_wbm.scale_%.T: prim_muls_2fr_wbm.scale_%.H
	Grey < $< eout=1 pclip=100 gainpanel=a > $@
	Ricksep < $@ &

# do adaptive subtraction of the multiples to get the primaries
prim_muls_2fr_wbm.scale_%_matched.H: cmps_2fr_wbm.H \
	prim_muls_2fr_wbm.scale_%.H
	Window3d < cmps_2fr_wbm.H n3=2 min3=2500 > target.H
	Window3d < prim_muls_2fr_wbm.scale_$*.H n3=2 min3=2500 > junk.H
	time ${BIN2}/Ultimatch-new.x < junk.H \
		target=target.H \
        mode=2 nsmode=1 wmode=1 nfilt=17,17 npatch=100,200 \
        invmode=1 niter=70 2D=1 eps=0.0 > $@

#mode=2 nsmode=1 wmode=2 nfilt=15,17 npatch=20,50
#invmode=1 niter=200 2D=1 eps=0.0 cg=n > $@

${TT}/prim_muls_2fr_wbm.scale_%_matched.T: prim_muls_2fr_wbm.scale_%_matched.H
	Grey < $< eout=1 clip=1 > $@
	Ricksep < $@ &

resid_2fr_wbm.scale_%.H: cmps_2fr_wbm.H \
	prim_muls_2fr_wbm.scale_%_matched.H
	Math file1=target.H \
		file2=prim_muls_2fr_wbm.scale_$*_matched.H exp="file1-file2" >$@

${TT}/resid_2fr_wbm.scale_%.T: resid_2fr_wbm.scale_%.H
#Grey < $< eout=1 newclip=1 bclip=-0.743469 eclip=1 >$@
	Grey < $< eout=1 clip=1 >$@
	Ricksep < $@


#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#	TESTS with CONSTANT velocity 
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%$%$%%
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
######################################################################
#	make test without water-bottom multiples to avoid aliasing in the
#	modeling of the migrated data
####################################################################
mig_cmps_2fr_no_wbms.const.%.H: \
		vel_3fl.const.%.H ${PAR}/parmig_fwd.P freq_cmps_2fr_no_wbms.H
	mig_off D=freq_cmps_2fr_no_wbms.H velocity=vel_3fl.const.$*.H \
		R=$@ \
		image_real=n wei_image_real=n \
		lloyd_nref=1 wei_velocity=y adj=y \
		nz=400 dz=10 oz=0 wei_nzb=400 \
		program=${BOBWEI}/Phase.x

mig_cmps_2fr_no_wbms.const_v%.H mig_cmps_2fr_no_wbms.const_g%.H: \
		mig_cmps_2fr_no_wbms.const.%.H
	cp $< $@

${TT}/mig_cmps_2fr_no_wbms.const.%.T: mig_cmps_2fr_no_wbms.const.%.H
	Window3d < $< > junk.H
	Real < junk.H > junk1.H 
	Transp < junk1.H plane=13 > junk2.H maxsize=1000
	Grey < junk2.H eout=1 gainpanel=a > $@
	Ricksep < $@ &

# create mask of ones and zeros for vertical(v) and general(g) mute
one_zeros_no_wbms_const_%.H: ${BIN}/cmp_mute.x \
		${PK}/picks_no_wbms_const_% mig_cmps_2fr_no_wbms.const_%.H
	Window3d < mig_cmps_2fr_no_wbms.const_$*.H > junk.H
	Transp < junk.H plane=13 > junk1.H maxsize=1000
	${BIN}/cmp_mute.x < junk1.H picks_file=${PK}/picks_no_wbms_const_$* \
		mask=y > $@
	echo "esize=4" >> $@
mask_no_wbms_const_%.H: one_zeros_no_wbms_const_%.H
	Smooth < $< tridiag=1 rect1=5 rect2=5 > junk4.H
	Transp < junk4.H plane=13 > $@ maxsize=1000 max_size=1000
	echo "label1=CMP_X" >> $@
	echo "n2=1 o2=0 d2=1 label2=CMP_Y" >> $@
	echo "n3=380 o3=-850 d3=5 label3=H_X" >> $@
	echo "n4=1 o4=0 d4=1 label4=H_Y" >> $@
	echo "n5=400 o5=0 d5=10 label5=DEPTH" >> $@

${TT}/mask_no_wbms_const_%.T: mask_no_wbms_const_%.H
	Window3d < $< | Transp plane=13 > junk.H
	Grey < junk.H eout=1 pclip=100 > $@
	Ricksep < $@ &

# create multiple model
mig_muls_2fr_no_wbms.const_%.H: mask_no_wbms_const_%.H \
			mig_cmps_2fr_no_wbms.const_%.H
	Rtoc < mask_no_wbms_const_$*.H > junk.H
	Math file1=mig_cmps_2fr_no_wbms.const_$*.H file2=junk.H \
		exp_real='file1.re*file2.re' exp_imag='file1.re*file2.im' > $@
	echo "label1=CMP_X label2=CMP_Y label3=H_X label4=H_Y label5=DEPTH">>$@

${TT}/mig_muls_2fr_no_wbms.const_%.T: mig_muls_2fr_no_wbms.const_%.H
	Window3d < $< > junk.H
	Transp < junk.H plane=13 > junk1.H maxsize=1000 max_size=1000
	Real < junk1.H > junk2.H
	Grey < junk2.H eout=1 pclip=100 > $@
	Ricksep < $@ &

# do inverse migration of the multiples
# need Interp to interpolate to the original sampling interval
muls_2fr_no_wbms.const_%.H: ${PAR}/parmig_inv.P \
		vel_3fl.const_%.H mig_muls_2fr_no_wbms.const_%.H
	model_off R=mig_muls_2fr_no_wbms.const_$*.H \
		velocity=vel_3fl.const_$*.H \
		D=JUNK.H lloyd_nref=1 wei_velocity=y adj=n \
		nw=200 dw=0.3125 ow=0 wei_nwb=200\
		program=${BOBWEI}/Phase.x
	Transf < JUNK.H wei=y > JUNK1.H
	Window3d < JUNK1.H min2=2000 n2=200 min4=50 n4=200 > JUNK2.H
	Transp < JUNK2.H plane=23 > JUNK3.H
	Interp < JUNK3.H n1out=400 o1out=0 d1out=0.008 > $@  
	echo "label2=half-offset" >> $@
	echo "label3=cmp" >> $@

# plot the inverted data
${TT}/muls_2fr_no_wbms.const_%.T: muls_2fr_wbm.const_%.H
	Grey < $< eout=1 pclip=100 gainpanel=a > $@
	Ricksep < $@ &

############################################################################
#	make test WITH FIRST ORDER water-bottom multiple 
####################################################################
mig_cmps_2fr_wbm.const.%.H: \
		vel_3fl.const.%.H ${PAR}/parmig_fwd.P freq_cmps_2fr_wbm.H
	mig_off D=freq_cmps_2fr_wbm.H velocity=vel_3fl.const.$*.H \
		R=$@ \
		image_real=n wei_image_real=n \
		lloyd_nref=1 wei_velocity=y adj=y \
		nz=400 dz=10 oz=0 wei_nzb=400 \
		program=${BOBWEI}/Phase.x

mig_cmps_2fr_wbm.const_v%.H mig_cmps_2fr_wbm.const_g%.H: \
		mig_cmps_2fr_wbm.const.%.H
	cp $< $@

${TT}/mig_cmps_2fr_wbm.const.%.T: mig_cmps_2fr_wbm.const.%.H
	Window3d < $< > junk.H
	Real < junk.H > junk1.H 
	Transp < junk1.H plane=13 > junk2.H maxsize=1000
	Grey < junk2.H eout=1 gainpanel=a > $@
#Ricksep < $@ &

# create mask of ones and zeros for vertical(v) and general(g) mute
one_zeros_wbm_const_%.H: ${BIN}/cmp_mute.x \
		${PK}/picks_wbm_const_% mig_cmps_2fr_wbm.const_%.H
	Window3d < mig_cmps_2fr_wbm.const_$*.H > junk.H
	Transp < junk.H plane=13 > junk1.H maxsize=1000
	${BIN}/cmp_mute.x < junk1.H picks_file=${PK}/picks_wbm_const_$* mask=y > $@
	echo "esize=4" >> $@
mask_wbm_const_%.H: one_zeros_wbm_const_%.H
	Smooth < $< tridiag=1 rect1=5 rect2=5 > junk4.H
	Transp < junk4.H plane=13 > $@ maxsize=1000 max_size=1000
	echo "label1=CMP_X" >> $@
	echo "n2=1 o2=0 d2=1 label2=CMP_Y" >> $@
	echo "n3=380 o3=-850 d3=5 label3=H_X" >> $@
	echo "n4=1 o4=0 d4=1 label4=H_Y" >> $@
	echo "n5=400 o5=0 d5=10 label5=DEPTH" >> $@

${TT}/mask_wbm_const_%.T: mask_wbm_const_%.H
	Window3d < $< | Transp plane=13 > junk.H
	Grey < junk.H eout=1 pclip=100 > $@
	Ricksep < $@ &

# create multiple model
mig_muls_2fr_wbm.const_%.H: mask_wbm_const_%.H mig_cmps_2fr_wbm.const_%.H
	Rtoc < mask_wbm_const_$*.H > junk.H
	Math file1=mig_cmps_2fr_wbm.const_$*.H file2=junk.H \
		exp_real='file1.re*file2.re' exp_imag='file1.re*file2.im' > $@
	echo "label1=CMP_X label2=CMP_Y label3=H_X label4=H_Y label5=DEPTH">>$@

${TT}/mig_muls_2fr_wbm.const_%.T: mig_muls_2fr_wbm.const_%.H
	Window3d < $< > junk.H
	Transp < junk.H plane=13 > junk1.H maxsize=1000 max_size=1000
	Real < junk1.H > junk2.H
	Grey < junk2.H eout=1 pclip=100 > $@
	Ricksep < $@ &

# do inverse migration of the multiples
# need Interp to interpolate to the original sampling interval
muls_2fr_wbm.const_%.H: ${PAR}/parmig_inv.P \
		vel_3fl.const_%.H mig_muls_2fr_wbm.const_%.H
	model_off R=mig_muls_2fr_wbm.const_$*.H velocity=vel_3fl.const_$*.H \
		D=JUNK.H lloyd_nref=1 wei_velocity=y adj=n \
		nw=200 dw=0.3125 ow=0 wei_nwb=200\
		program=${BOBWEI}/Phase.x
	Transf < JUNK.H wei=y > JUNK1.H
	Window3d < JUNK1.H min2=2000 n2=200 min4=50 n4=200 > JUNK2.H
	Transp < JUNK2.H plane=23 > JUNK3.H
	Interp < JUNK3.H n1out=400 o1out=0 d1out=0.008 > $@  
	echo "label2=half-offset" >> $@
	echo "label3=cmp" >> $@

# plot the inverted data
${TT}/muls_2fr_wbm.const_%.T: muls_2fr_wbm.const_%.H
	Grey < $< eout=1 pclip=100 gainpanel=a > $@
	Ricksep < $@ &

###################################################################
# window just 2 cmps to make the matchn filter tests faster
cmps_2fr_no_wbms_win.H: cmps_2fr_no_wbms.H
	Window3d < $< n3=3 min3=3000 > $@
cmps_2fr_no_wbms_win_smooth.H: cmps_2fr_no_wbms_win.H
	Smooth < $< rect1=1 rect2=2 > $@
muls_2fr_no_wbms.scale_%_inv_win.H: muls_2fr_no_wbms.scale_%_inv.H
	Window3d < $< n3=3 min3=3000 > $@

# do adaptive subtraction of the multiples to get the primaries
muls_2fr_no_wbms.scale_%_matched.H: cmps_2fr_no_wbms_win_smooth.H \
	muls_2fr_no_wbms.scale_%_inv_win.H
	time ${BIN2}/Ultimatch-new.x < muls_2fr_no_wbms.scale_$*_inv_win.H \
		target=cmps_2fr_no_wbms_win_smooth.H \
		mode=2 nsmode=1 wmode=2 nfilt=5,7 npatch=10,5 \
		invmode=1 niter=20 2D=1 eps=0.0 cg=n > $@

${TT}/muls_2fr_no_wbms.scale_%_matched.T: muls_2fr_no_wbms.scale_%_matched.H
	Grey < $< eout=1 clip=1 > $@
	Ricksep < $@ &

prims_2fr_no_wbms.scale_%.H: cmps_2fr_no_wbms_win.H \
	muls_2fr_no_wbms.scale_%_matched.H
	Math file1=cmps_2fr_no_wbms_win.H \
		file2=muls_2fr_no_wbms.scale_$*_matched.H exp="file1-file2" >$@

${TT}/prims_2fr_no_wbms.scale_%.T: prims_2fr_no_wbms.scale_%.H
#Grey < $< eout=1 newclip=1 bclip=-0.743469 eclip=1 >$@
	Grey < $< eout=1 clip=1 >$@
	Ricksep < $@
