include ${SEPINC}/SEP.top
include ../../Src/thesis.include
include ../../Src/synth.top.inc
include ../../Src/mig.include

ifeq (${ARCH},LINUX)
FFT=/net/kana/biondo/FFTW/lib/libsfftw.a /net/kana/biondo/FFTW/lib/libsrfftw.a
endif
BBLIB=-L/net/kana/biondo/lib/gendown3d_v9/${MTYPE} -L/net/kana/biondo/lib/timers_v1/${MTYPE}   -lgendown3d  -lSEPtimers 
UF90LIBDIRS=/usr/local/SEP5.1/lib
BBINC=-I/net/kana/biondo/include/gendown3d_v9/${MTYPE} -I/net/kana/biondo/include/timers_v1/${MTYPE} -I//net/kana/biondo/include/gendown3d_v9/${MTYPE}
UF90LIBS=-lsepauxf90 -lsepaux -lsupersetf90 -lsuperset  -lgeef90 -lsep2df90 ${BBLIB} ${FFT} -lsepauxf90 -lsepaux
SRCDIR=../../tau/Src
BINDIR=../Bin
RESDIR=../Figs
UF90INCLUDES= -I. ${BBINC}
#F90OLEVEL=2
#UF90FLAGS=-Mbounds
RESULTSER=synth-model tau-initial sigma dips-correct dips-z-vel0 tau-dips
RESULTSCR=mig0 semb-mig0 semb-mig0-ref iter1-comp
RESULTSCR=res.vel1 res.velb
RESULTSCR=res.vel1.steerz res.vel1.lapz all.res.vel1.tau res.vel1.steer \
          res.vel3.steer all.res.vel3.tau res.vel2.lapz res.vel3.steerz \
          vel1 velb
RESULTSER=bad



ifeq (${SEP_ARCH}, LINUX)
	UF90LIBS:=${UF90LIBS} -mp
	UF90FLAGS:=${UF90FLAGS} -mp 
endif

DATA=/net/kana/bob/data/synth.HH
TRANSF=/net/kana/bob/Transf

GREY_VEL=Grey >/dev/null min1=0 max1=5 min2=2 max2=18  title=" " \
 wantscalebar=y color=v label1="Depth(km)" label2="X Position(km)"  color=j

${RESDIR}/res.vel1.v: res.vel1.steerz.v res.vel1.tau.v res.vel1.steer.v
	vp_OverUnderAniso res.vel1.steerz.v res.vel1.tau.v res.vel1.steer.v >$@

${RESDIR}/vel1.v: vel1.steerz.plot.V vel1.tau.plot.V vel1.steer.plot.V vel1.lapz.plot.V
	Vppen < vel1.lapz.plot.V vel1.steerz.plot.V  vel1.tau.plot.V vel1.steer.plot.V gridnum=2,2 >vel1.V out=$@ 

${RESDIR}/velb.v: vel3.steerz.plot.V vel3.tau.plot.V vel3.steer.plot.V vel2.lapz.plot.V
	Vppen < vel3.lapz.plot.V vel3.steerz.plot.V  vel3.tau.plot.V vel3.steer.plot.V gridnum=2,2 >velb.V out=$@ 


${RESDIR}/res.velb.v: res.vel1.steerz.v res.vel3.tau.v res.vel3.steer.v
	vp_OverUnderAniso res.vel1.steerz.v res.vel3.tau.v res.vel3.steer.v >$@



MIG2=/net/kana/biondo/bin/${MTYPE}/Pre2D_salt_ssf.x
MIG=../Bin/Pre2D_salt_ssf.x

#MIG=${BINDIR}/Pre2D_salt_ssf.x

test:	${BINDIR}/Pre2D_salt_ssf.x

#################################
#####  PLOTTING         #########
#################################

PANELS=2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
PANELS=7 7.25 7.5 7.75 8 8.25 8.50 8.75 9 9.25 9.5 9.75 10 10.25 10.5 10.75 11 11.25 

${RESDIR}/all.res.vel1.tau.v:  ${RESDIR}/res.vel1.tau.v
	cp ${RESDIR}/res.vel1.tau.v $@

${RESDIR}/all.res.vel2.tau.v:  ${RESDIR}/res.vel2.tau.v
	cp ${RESDIR}/res.vel2.tau.v $@

${RESDIR}/all.res.vel3.tau.v:  ${RESDIR}/res.vel3.tau.v
	cp ${RESDIR}/res.vel3.tau.v $@

${RESDIR}/res.%.v:  FORCE
	Window < mig.$*.H n2=1 |Grey title=" " label1="Depth(km)" label2="X_position(km)" min2=4 max2=16 >a1.V  
	Window j1=16 < reflectors.z.vel_cor.H  |Graph plotcol=7 title=" " wantaxis=n min1=4 max1=16 min2=0 max2=4.960 yreverse=y symbolsz=16 plotcol=7 symbol="*" >a2.V 
	Window j1=16 < reflectors.z.vel_cor.H  |Graph plotcol=7 title=" " wantaxis=n min1=4 max1=16 min2=0 max2=4.960 yreverse=y symbolsz=28 plotcol=0 symbol="*" >a3.V 
	Vppen erase=once < a1.V a3.V a2.V vpstyle=n erase=once >a.V
	Window < mig.$*.H min3=5.5 j3=70 |Window n3=1 |Grey >b.V  title=" " label1="Depth(km)" \
	  label2="p\\s60 \\_hx\\^\\s100 " labelsz=16 labelfat=20  title="5.5" titlesz=36 titlefat=20 wantaxis=n  crowd1=1.  
	Window < mig.$*.H min3=5.5 j3=70  |Window n3=1 f3=1|Grey >c.V  title=" " label1="Depth(km)"crowd1=1. \
  label2="p\\s60 \\_hx\\^\\s100 " labelsz=16 labelfat=20  title="7.75" titlesz=36 titlefat=20 wantaxis=n crowd1=1.  
	Window < mig.$*.H min3=5.5 j3=70  |Window n3=1 f3=2|Grey >d.V  title=" " label1="Depth(km)"  \
   label2="p\\s60 \\_hx\\^\\s100 " labelsz=16 labelfat=20 title="10" titlesz=36 titlefat=20 wantaxis=n crowd1=1.  
	Vppen < b.V c.V d.V gridnum=3,1  vpstyle=n >e.V yscale=3  
	Vppen < a.V e.V >res.$*.V out=g.v vpstle=n yscale=2 gridnum=2,1
	vp_annotate < g.v >$@ batch=y text_file=ss.txt
	

${RESDIR}/dips-z-vel0.v: dips.steerz.H reflectors.vel0.H
	Graph < reflectors.vel0.H min1=2 max1=18 min2=0 max2=5 label1="Depth(km)"\
  label2="X Position(km)" title=" " >refs.V yreverse=y plotfat=10 clip=.5
	Grey < dips.steerz.H >dips.V min1=0 max1=5 min2=0 max2=18 label1="Depth(km)" \
   label2="X Position(km)" title=" " wantscalebar=y barlabel="Slope" clip=.5
	Vppen <refs.V dips.V gridnum=2,1 >d.V out=$@ yscale=2
	
${RESDIR}/dips-correct.v: dips.steerz.H dips.cor.z.H
	Grey < dips.cor.z.H >dips.V min1=0 max1=4.2 min2=0 max2=18 label1="Depth(km)" \
   label2="X Position(km)" title=" " wantscalebar=y barlabel="Slope" clip=.5
	Add scale=1,-1 dips.cor.z.H dips.steerz.H >err.z.H
	Grey < err.z.H >err.V min1=0 max1=4.2 min2=0 max2=18 label1="Depth(km)" \
   label2="X Position(km)" title=" " wantscalebar=y barlabel="Slope" clip=.2
	Vppen <dips.V err.V gridnum=2,1 >d.V out=$@ yscale=2
	

${RESDIR}/tau-dips.v:	dips.vel0.H dips.vel_cor.H
	Grey < dips.vel0.H >dip1.V min1=0 max1=4.2 min2=0 max2=18 label1="Depth(km)" \
   label2="X Position(km)" title=" " wantscalebar=y barlabel="Slope" clip=.5
	Grey < dips.vel_cor.H >dip2.V min1=0 max1=4.2 min2=0 max2=18 label1="Depth(km)" \
   label2="X Position(km)" title=" " wantscalebar=y barlabel="Slope" clip=.5
	Add scale=1,-1 dips.vel_cor.H dips.vel0.H >err.z.H
	Grey < err.z.H >err.V min1=0 max1=4.2 min2=0 max2=18 label1="Depth(km)" \
   label2="X Position(km)" title=" " wantscalebar=y barlabel="Slope" clip=.2
	Vppen <dip1.V dip2.V  err.V gridnum=3,1 >d.V out=$@ yscale=3



GRAPH=Graph min1=2 max1=18 min2=0 max2=5 yreverse=y wantaxis=n title=" "  wantframe=n plotcol=7 plotfat=12 yll=1.25 xur=11.2 yur=8.98 xll=2.1

GREY=Grey  min1=0 max1=5 min2=2 max2=18  title=" " \
 wantscalebar=y  label1="Depth(km)" label2="X Position(km)"  


${RESDIR}/synth-model.v: zero-synth.v vel_cor.v
	vp_SideBySideIso vel_cor.v zero-synth.v  >$@

${RESDIR}/semb-mig0.v:	overlay.vel0.8.v
	cp  overlay.vel0.8.v $@

${RESDIR}/iter1-comp.v:	 vel1.z.delta.V vel1.tau.delta.V
	Vppen gridnum=1,2 vpstyle=n <vel1.z.delta.V vel1.tau.delta.V >iter1-comp.V out=$@ xscale=2

${RESDIR}/mig0.v:	mig.vel0.H vel0.H
	${GREY} < vel0.H out=a.v bias=2 allpos=y
	Window < mig.vel0.H n2=1 | ${GREY} out=b.v 
	vp_SideBySideIso a.v b.v >$@


${RESDIR}/tau-initial.v:  tau-vel_cor.v tau-vel0.v
	vp_SideBySideIso tau-vel_cor.v tau-vel0.v >$@



%.plot.V:	%.H
	${GREY} <$*.H  >$@  bias=2 allpos=y clip=2 wantscalebar=n crowd=.95 wantaxis=n

${RESDIR}/bad.v: vel1.bad.H
	${GREY} <vel1.bad.H  >bad.V out=$@  bias=2 allpos=y clip=2 barlabel="Velocity(km/s)"

vel1.%.delta.V:	vel1.%.H
	Add scale=1,-1 vel1.$*.H vel0.wind.H >diff.H
	${GREY} <diff.H  >a.V   
	${GREY} <vel1.$*.H  >b.V  bias=2 allpos=y 
	Vppen < a.V b.V gridnum=2,1 vpstlye=n >$@ yscale=2
vel1.%.delta.V:	vel1.%.H
	Add scale=1,-1 vel1.$*.H vel0.wind.H >diff.H
	${GREY} <diff.H  >a.V   
	${GREY} <vel1.$*.H  >b.V  bias=2 allpos=y 
	Vppen < a.V b.V gridnum=2,1 vpstlye=n >$@ yscale=2


tau-%.v:	tau-%.H
	Real <  tau-$*.H | ${GREY}  out=tau_$*.v max1=3.5 clip=2. bias=2. allpos=y
	${GRAPH} < tau_reflectors.$*.H out=tau_reflectors.$*.v max2=3.5
	vp_Overlay tau_$*.v tau_reflectors.$*.v >$@

${RESDIR}/semb-mig0-ref.v:	${addprefix semb-ref.vel0.,${addsuffix .V,0 1 2 3 4 5}}
	Vppen <${addprefix semb-ref.vel0.,${addsuffix .V,0 1 2 3 4 5}} out=$@ vpstyle=n gridnum=1,6 >/dev/null xscale=6
	


vel_cor.v:#	vel_cor.z.H reflectors.z.vel_cor.H
	${GREY} < vel_cor.z.H  out=a.v bias=2 allpos=y
	${GRAPH} < reflectors.z.vel_cor.H out=b.v symbol="*"
	vp_Overlay a.v b.v >$@

zero-synth.v: ${DATA}
	Grey < ${DATA} eout=1 >tt.T
	Cubeplot < tt.T frame1=200  frame2=100 out=$@ >/dev/null point1=.7 point2=.7 pint3=.3 label1="Time(s)" title=" " flat=n

ov.movie.v:	${addprefix overlay.,${addsuffix .v,${PANELS}}}
	vp_Movie ${addprefix overlay.,${addsuffix .v,${PANELS}}} >$@


overlay.vel0.%.v:	${BINDIR}/plot_it.x smooth_sem.vel0.H mig.vel0.H reflectors.vel0.H
	Window < mig.vel0.H min3=$* n3=1  >pn.H
	<pn.H Grey out=a.v >/dev/null min1=0 max1=4.5 min2=0 max2=.62 title="$*"
	Window <  smooth_sem.vel0.H min1=$* n1=1  >de.H
	${BINDIR}/plot_it.x  pan=pn.H reflectors=reflectors.vel0.H < de.H >cur.H par=coher.P
	< cur.H Graph out=b.v >/dev/null yreverse=y min2=0 max2=4.5 min1=0 max1=.62\
   wantaxis=n plotfat=12 title=" "
	vp_Overlay a.v b.v >$@


semb-ref.vel0.%.V:	smooth_sem.vel0.H sem_ref.vel0.H
	Window < sem_ref.vel0.H f3=$* n3=1 |Grey out=a.v  min1=-4 max1=4 min2=2 max2=18 allpos=y >a.V title=" " crowd=1 axis=n
	Window <smooth_sem.vel0.H f2=$* n2=1 |Graph min1=2 max1=18 min2=-4 max2=4 out=b.v >b.V yreverse=y title=" " crowd=1. crowd=1 axis=n
	Vppen<  a.V b.V >$@ vpstyle=n erase=n >$@ 

${RESDIR}/sigma.v: tau-vel_cor.H
	Imag <  tau-vel_cor.H | ${GREY}  out=$@ max1=3.5  color=I

dips.%.H: reflectors.%.H ${BINDIR}/create_dips.x dips.P  ${BINDIR}/Extend_it.x
	${BINDIR}/create_dips.x <reflectors.$*.H  par=dips.P  ref_out=ref_out.$*.H \
 vel=$*.H |${BINDIR}/Extend_it.x beg1=10 beg2=10 end1=10 end2=10 |\
  Smooth par=dips.P >$@

#
vel2.%.H:  ${BINDIR}/Tomo_2d.x vel0.H  tomo.2.%.P smooth_sem.vel1.%.H dips.vel1.%.H
	<vel1.$*.H Window j1=2 j2=8  |Extend_it.x  beg2=10 end1=10 end2=10 |Reverse which=1 >end.H
	Spike n1=10 mag=2. n2=99 >beg.H
	Cat end.H beg.H axis=1 |Reverse which=1 >vel.H
	${BINDIR}/Tomo_2d.x par=tomo.2.$*.P < vel.H >v.$*.H delta_t=times.vel1.$*.H\
  reflectors=reflectors.vel1.$*.H zero_rays=zero.vel1.$*.H  px_rays=px.vel1.$*.H \
 delta_slow=delta.vel1.$*.H time_errors=err.vel1.$*.H pfile=dips.vel1.$*.H \
  residual_times=res.vel1.$*.H semblance=smooth_sem.vel1.$*.H
#



.PRECIOUS:  reflectors.%.H  ${BINDIR}/%.x mig.%.H  vel1.%.H sem_ref.%.H coher.%.H vel2.%.H vel3.%.H vel4.%.H

include ../../Src/synth.bot.inc
include ${SEPINC}/SEP.bottom
