BIN1=/net/koko/gabriel/Research/Multiples/FALL2005/NEWATTENUATION/Bin
BIN2=/net/koko/gabriel/Research/Multiples/GOM_TEST/bin
BIN=../Bin
#-------------------------------------------------------------------------
#-------------------------------------------------------------------------
#		ANTOINE'S DATA (THESIS CHAPTER 3)
#-------------------------------------------------------------------------
#-------------------------------------------------------------------------
signal.H: data.H noise.H
	Add scale=1,-1 data.H noise.H > $@

# mode=1 if for single filter and =2 is for non-stationary filters
# npatch and eps have no effect is mode=1

# try to match the multiples to the data without help from the primaries
# npatch is not used if mode=1
matched_muls_orig.H matched_prims_orig.H: data.H noise.H
	Scale < noise.H dscale=1 > noise_scale_1.H
	cp noise_scale_1.H junk1.H
	time ${BIN}/Ultimatch-new-all.x < data.H \
		multiples_in=junk1.H \
		nfilt=41 invmode=1 niter=10 2D=0 \
		mode=1 wmode=1 row=0 eps=0.0 mu=1. dtest=y > $@
	Add scale=1,-1 data.H matched_muls_orig.H > matched_prims_orig.H
	
# try to match the multiples to the data without help from the primaries
# using Antoine's original code
matched_muls_antoine.H matched_prims_antoine.H: data.H noise.H
	${BIN}/Ultimatch-Huber.x < noise.H target=data.H >$@ nfilt=41 \
		mode=1 gamd=8. niter=4 eps=0.

# try it with the perfect estimate of both primaries and multiples
matched_muls.H matched_prims.H res.H: data.H noise.H signal.H
	Scale < noise.H dscale=0.02 > noise_scale_0.02.H
	Scale < signal.H dscale=2000 > signal_scale_2000.H
	cp noise_scale_0.02.H junk1.H; cp signal_scale_2000.H junk2.H
	time ${BIN}/Ultimatch-new-all.x < data.H \
		multiples_in=junk1.H primaries_in=junk2.H \
		primaries_out=matched_prims.H \
		nfilt=17 invmode=1 niter=3 2D=0 \
		mode=1 row=1 eps=1.0 mu=1. > $@
	Add scale=1,1 $@ matched_prims.H > matched_data.H
	Add scale=1,-1 data.H matched_data.H > res.H

# try it with the perfect estimate of primaries and a one
# sample shift in the multiples
k1=35,50,80
k1_1=36,51,81
k1_10=45,60,90
k1_c1=30,55,75
k1_c2=15,25,90
kp1=15
kp1_1=16
kp1_10=25
kp_c1=30
kp_c2=2

noise_shft%.H:
	Spike n1=100 n2=1 k1=${k1_$*} k2=1,1,1 mag=1,1,1 nsp=3 > $@
signal_shft%.H:
	Spike n1=100 n2=1 k1=${kp1_$*} k2=1 mag=1 nsp=1 > $@

matched_shft%_muls.H: data.H signal.H noise_shft%.H
	Scale < noise_shft$*.H dscale=100. > noise_shft$*_scale.H
	Scale < signal.H dscale=0.1 > signal_scale.H
	time ${BIN}/Ultimatch-new-all.x < data.H \
		multiples_in=noise_shft$*_scale.H primaries_in=signal_scale.H \
		primaries_out=matched_shft$*_prims.H \
		nfilt=27 invmode=1 niter=5 2D=0 \
		mode=1 row=1 eps=1.0 mu=1. dtest=y > $@
	Add scale=1,1 $@ matched_shft$*_prims.H > matched_shft$*_data.H
	Add scale=1,-1 data.H matched_shft$*_data.H > res.H

# try with an estimate of the multiples where the spikes are totally
# in the wrong locations
noise_c%.H:
	Spike n1=100 n2=1 k1=${k1_c$*} k2=1,1,1 mag=1,1,1 nsp=3 > $@
signal_c%.H:
	Spike n1=100 n2=1 k1=${kp_c$*} k2=1 mag=1 nsp=1 > $@
	
matched_c%_muls.H: data.H signal_c%.H noise_c%.H
	Scale < noise_c$*.H dscale=1. > noise_c$*_scale.H
	Scale < signal.H dscale=1. > signal_scale.H
	cp noise_c$*_scale.H junk1.H
	cp signal_scale.H junk2.H
	time ${BIN}/Ultimatch-new-all.x < data.H \
		multiples_in=junk1.H primaries_in=junk2.H \
		primaries_out=matched_c$*_prims.H \
		nfilt=77,1  invmode=1 niter=20 2D=0 \
		mode=1 row=1 eps=1.0 mu=2 > $@
	Add scale=1,1 $@ matched_c$*_prims.H > matched_c$*_data.H
	Add scale=1,-1 data.H matched_c$*_data.H > res.H

#-------------------------------------------------------------------------
#-------------------------------------------------------------------------
#-------------------------------------------------------------------------
# try with the IRLS-type inversion
# create mask of 0 where the primaries are not zero and 
# one where the primaries are zero
mask.H: signal.H
	Spike n1=100 mag=2 > junk.H
	Math file1=junk.H file2=signal.H exp=file1-file2 > junk2.H
	Scale < junk2.H dscale=0.5 > $@

matched_muls_irls.H: data.H noise.H mask.H
	Scale < noise.H dscale=10. > noise_scale_10.H
	Scale < mask.H dscale=1. > mask_scale.H
	cp noise_scale_10.H junk1.H
	cp mask_scale.H junk2.H
	time ${BIN}/Ultimatch-new-all.x < data.H \
		multiples_in=junk1.H weight=junk2.H \
		nfilt=17,1 invmode=1 niter=3 2D=0 \
		mode=1 wmode=3 > $@
	Add scale=1,-1 data.H $@ > matched_prims_irls.H

# try with shifted multiples
matched_muls_shft%_irls.H: data.H noise_shft%.H mask.H
	Scale < noise_shft$*.H dscale=10. > noise_shft$*_scale_10.H
	Scale < mask.H dscale=1. > mask_scale.H
	cp noise_shft$*_scale_10.H junk1.H
	cp mask_scale.H junk2.H
	time ${BIN}/Ultimatch-new-all.x < data.H \
		multiples_in=junk1.H weight=junk2.H \
		nfilt=27,1 invmode=1 niter=10 2D=0 \
		mode=1 wmode=3 nouter=1 > $@
	Add scale=1,-1 data.H $@ > matched_prims_shft$*_irls.H

# try with arbitrary multiples
matched_muls_c%_irls.H: data.H noise_c%.H #mask%.H
	Scale < noise_c$*.H dscale=1. > noise_c$*_scale_10.H
	Scale < mask.H dscale=1. > mask$*_scale_0.1.H
	cp noise_c$*_scale_10.H junk1.H
	cp mask$*_scale_0.1.H junk2.H
	time ${BIN}/Ultimatch-new-all.x < data.H \
		multiples_in=junk1.H weight=junk2.H \
		nfilt=97,1 invmode=1 niter=20 2D=0 \
		mode=1 wmode=3 nouter=1 > $@
	Add scale=1,-1 data.H $@ > matched_prims_c$*_irls.H

#############################################################
# try with arbitrary multiples and NONstationary filter
# mode=2
matched_muls_c%_ns.H: data.H noise_c%.H
	Scale < noise_c$*.H dscale=1. > noise_c$*_scale_1.H
	cp noise_c$*_scale_1.H junk1.H
	time ${BIN}/Ultimatch-new-all.x < data.H \
		multiples_in=junk1.H \
		nfilt=17,1 invmode=1 niter=20 2D=0 \
		mode=2 wmode=1 nouter=1 dtest=y > $@
	Add scale=1,-1 data.H $@ > matched_prims_c$*_ns.H
#############################################################
# try with arbitrary multiples and NONstationary filters
# mode=2 row=1
matched_c%_ns_muls.H: data.H signal_c%.H noise_c%.H
	Scale < noise_c$*.H dscale=1. > noise_c$*_scale.H
	Scale < signal.H dscale=1. > signal_scale.H
	cp noise_c$*_scale.H junk1.H
	cp signal_scale.H junk2.H
	time ${BIN}/Ultimatch-new-all.x < data.H \
		multiples_in=junk1.H primaries_in=junk2.H \
		primaries_out=matched_c$*_ns_prims.H \
		nfilt=77,1  invmode=1 niter=20 2D=0 \
		mode=2 row=1 eps=1.0 mu=2 dtest=y > $@
	Add scale=1,1 $@ matched_c$*_ns_prims.H > matched_c$*_ns_data.H
	Add scale=1,-1 data.H matched_c$*_ns_data.H > res.H

