include ${SEPINC}/SEP.top
include ../../Src/thesis.include
include ../../Src/synth.top.inc
include ../../Src/mig.include
RESULTSER=synth-model tau-initial sigma
RESULTSER=mig0 semb-mig0 semb-mig0-ref iter1-comp iter2-comp-vel res.vel2.z res.vel2.tau res.vel0 res.vel1.z res.vel1.tau rays
RESULTSER=mig0 iter1-comp res.vel0 res.vel1.deltaz res.vel1.deltatau rays iter2-comp-vel res.vel2.deltaz res.vel2.deltatau 
UPSTEXFLAGS=invras=y
RMV=${BINDIR}/Tomo_2d.x



UF90INCLUDES=${BOBINCS} 
UF90FLAGS=-mp
UF90LIBS= ${BOBLIBS} -mp
UCLIBS=-lsuperset -lsep3d -lsep





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


#MIG=../Bin/Pre2D_salt_ssf.x

test:	${BINDIR}/Pre2D_salt_ssf.x

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


${RESDIR}/sem-final.v:	#sem_ref.vel2.deltatau.H
	Grey < sem_ref.vel2.deltatau.H wantlabel=n wanttitle=n wantaxis=n >sem.V crowd=.98 allpos=y
	Vppen < sem.V gridnum=1,6 out=$@ >sem-final.V xscale=6

${RESDIR}/iter2-comp-vel.v: #vel2.deltatau.view.H vel2.deltaz.view.H
	${DEPTH_GREY} < vel2.deltatau.view.H allpos=y bias=2. clip=2.1 >tau.V color=j
	${DEPTH_GREY} < vel2.deltaz.view.H allpos=y bias=2. clip=2.1 >depth.V color=j
	Vppen < depth.V tau.V >vel2.V out=$@ vpstyle=n gridnum=2,1 yscale=2,1

${RESDIR}/iter2-comp-vel.ps: ${RESDIR}/iter2-comp-vel.v
	${V2PS} color=y


${RESDIR}/ref-movement.v:	tau-vel_cor.H tau-vel0.H vel.vel0.view.V reflectors.vel_cor.H
	Real <  tau-vel0.H | Grey  label1="Time(s)" label2="X Position(km)" title=" "   max1=3.5 clip=2. bias=2. allpos=y ${BAR} min1=0 max1=3.5 min2=2 max2=18 > grey.V
	Graph < tau_reflectors.vel0.H  max2=3.5 wantaxis=n title=" " yreverse=y min2=0 max2=3.5 min1=2 max1=18> graph1.V  plotfat=16 plotcol=0
	Graph < tau_reflectors.vel0.H  max2=3.5 wantaxis=n title=" " yreverse=y min2=0 max2=3.5 min1=2 max1=18> graph2.V  plotfat=10 plotcol=7
	Graph < tau_reflectors.vel_cor.H  max2=3.5 wantaxis=n title=" " yreverse=y min2=0 max2=3.5 min1=2 max1=18> graph3.V  plotfat=16 plotcol=0 dash=1
	Graph < tau_reflectors.vel_cor.H  max2=3.5 wantaxis=n title=" " yreverse=y min2=0 max2=3.5 min1=2 max1=18> graph4.V  plotfat=10 plotcol=7 dash=1
	Vppen erase=o vpstyle=n < grey.V graph1.V graph2.V graph3.V graph4.V >tau.V
	Graph < reflectors.vel0.H  max2=3.5 wantaxis=n title=" " yreverse=y min2=0 max2=5 min1=2 max1=18> graph1.V  plotfat=16 plotcol=0
	Graph < reflectors.vel0.H  max2=3.5 wantaxis=n title=" " yreverse=y min2=0 max2=5 min1=2 max1=18> graph2.V  plotfat=10 plotcol=7
	Graph < reflectors.vel_cor.H  max2=3.5 wantaxis=n title=" " yreverse=y min2=0 max2=5 min1=2 max1=18> graph3.V  plotfat=16 plotcol=0 dash=1
	Graph < reflectors.vel_cor.H  max2=3.5 wantaxis=n title=" " yreverse=y min2=0 max2=5 min1=2 max1=18> graph4.V  plotfat=10 plotcol=7 dash=1
	Vppen erase=o vpstyle=n < vel.vel0.view.V graph1.V graph2.V graph3.V graph4.V >depth.V
	Vppen < depth.V tau.V >vv.V out=$@ vpstyle=n gridnum=2,1 yscale=2

${RESDIR}/mig0.v:	vel.vel0.view.V mig.vel0.overlay.V
	Vppen  <  vel.vel0.view.V mig.vel0.overlay.V > mig0.V out=$@ yscale=2 vpstyle=n gridnum=2,1



${RESDIR}/res.%.v:	gather.%.V mig.%.overlay.V
	Vppen <mig.$*.overlay.V gather.$*.V  gridnum=2,1	>a.V yscale=2 out=a.v
	vp_annotate < a.v >$@ batch=y text_file=../../Src/ss.txt
	

${RESDIR}/iter1-comp.v: #	vel1.deltaz.view.H vel1.deltatau.view.H
	Window f3=1 f1=10 n1=79  f2=10 n2=79 < delta.slow.deltaz.H |${DEPTH_GREY} >dz.V crowd=.8 o1=0 d1=.064 o2=0 d2=.256 clip=.05 color=F
	Window f3=1  f1=10 n1=79 f2=10 n2=79< delta.slow.deltatau.H| ${DEPTH_GREY}  >dt.V crowd=.8 label1="Tau(s)" o1=0 d1=.048 o2=0 d2=.256 max1=3.8 clip=.05 color=F
	${DEPTH_GREY} < vel1.deltaz.view.H  >z.V crowd=.8 allpos=y bias=2. clip=2. color=j
	${DEPTH_GREY} < vel1.deltatau.view.H  >t.V crowd=.8 allpos=y bias=2. clip=2. color=j
	Vppen gridnum=2,2 vpstyle=n  <dz.V  z.V dt.V t.V >iter1.V out=$@
	

${RESDIR}/tau-initial.v:  tau-vel_cor.V tau-vel0.V
	Vppen< tau-vel_cor.V tau-vel0.V >tau.V out=$@ gridnum=2,1 yscale=2 yscale=2

tau-%.V:  tau-%.H
	Real <  tau-$*.H | Grey  label1="Time(s)" label2="X Position(km)" title=" "   max1=3.5 clip=2. bias=2. allpos=y ${BAR} min1=0 max1=3.5 min2=2 max2=18 > grey.V
	Graph < tau_reflectors.$*.H  max2=3.5 wantaxis=n title=" " yreverse=y min2=0 max2=3.5 min1=2 max1=18> graph1.V  plotfat=16 plotcol=0
	Graph < tau_reflectors.$*.H  max2=3.5 wantaxis=n title=" " yreverse=y min2=0 max2=3.5 min1=2 max1=18> graph2.V  plotfat=10 plotcol=7
	Vppen erase=o vpstyle=n < grey.V graph1.V graph2.V >$@

tau-%.H:   ${BINDIR}/vel_convert.x  tau_convert.P %.view.H reflectors.%.H
	${BINDIR}/vel_convert.x  < $*.view.H >$@  par=tau_convert.P\
	ray_traj=reflectors.$*.H ray_traj_out=tau_reflectors.$*.H

stest.H:   ${BINDIR}/sigma_test.x  tau_convert.P vel_cor.view.H 
	Interp < vel_cor.view.H >aa.H d1out=.01
	${BINDIR}/sigma_test.x  < aa.H >ff.H  par=stest.P


#${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

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}/rays.v:	px.vel_cor.H px.vel0.H reflectors.z.vel_cor.H reflectors.vel0.H
Window3d < px.vel_cor.H f4=5 f3=8 j2=6 >a.H synch=1 n3=1 min2=6 max2=14
Window3d < px.vel0.H f4=5 f3=8 j2=6 >b.H synch=1 n3=1 j1=4 min2=6 max2=14
Graph < a.H  >cor.V yreverse=y min1=2 max1=18 min2=0 max2=5 title=" " wantaxis=n  plotcol=3 plotfat=3
Graph < b.H  >zero.V yreverse=y min1=2 max1=18 min2=0 max2=5 title=" " wantaxis=n dash=2 plotcol=1 plotfat=3 symbol="*" symbolsz=2
Graph < reflectors.vel_cor.H  >ref_cor.V yreverse=y min1=2 max1=18 min2=0 max2=5 title=" " wantaxis=n dash=0 plotcol=1 plotfat=3
Window j1=4 < reflectors.vel0.H |Graph  >ref_zero.V yreverse=y min1=2 max1=18 min2=0 max2=5 title=" " wantaxis=n dash=2 plotcol=1 plotfat=3 symbol="*" symbolsz=2
#${GREY} < vel_cor.z.HH >vel.V wantscalebar=n bias=2.
#Vppen vpstyle=n erase=o <vel.V zero.V cor.V ref_zero.V ref_cor.V >rays.V out=$@

${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}/iter3-comp-vel.v: vel3.tau.H vel3.z.H
#${GREY} < vel3.tau.H >a.V bias=2 allpos=y barlabel="Velocity(km/s)"
#${GREY} < vel3.z.H >b.V bias=2 allpos=y barlabel="Velocity(km/s)"
#Vppen gridnum=2,1 < b.V a.V >comp-vel.V out=$@ 
#
#${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 reflectors.z.vel_cor.H
#	${GREY} < vel0.H out=a.v bias=2 allpos=y >/dev/null \
#   barlabel="Velocity(km/s)"
#	Window < mig.vel0.H n2=1 |Grey out=b.v >/dev/null wantscalebar=n title=" " label1="Depth(km)" label2="X Position (km)"
#	Window j1=16 < reflectors.z.vel_cor.H|Graph out=c.v min1=2 max1=18  min2=0 max2=5 yreverse=1 >/dev/null  symbolsz=16 plotcol=0 symbol="*" wantaxis=n title=" "
#	Window j1=16 < reflectors.z.vel_cor.H |Graph out=d.v min1=2 max1=18  min2=0 max2=5 yreverse=1 >/dev/null  symbolsz=8 plotcol=7 symbol="*" wantaxis=n title=" "
#	vp_Overlay b.v c.v d.v >e.v
#	vp_SideBySideIso a.v e.v >$@
#


#${RESDIR}/res.vel3.z.v:	res.vel3.z.v
#	cp res.vel3.z.v $@

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

#${RESDIR}/res.vel0.v:	res.vel0.v
#	cp res.vel0.v $@


vel1.z.delta.V:	# vel1.z.H
	Window < delta.vel0.z.H f3=1 |\
	${GREY}   >a.V  barlabel="Slowness (s/km)"  o2=-2.56 d2=.256 o1=-.64 d1=.064\
   labelsz=16 crowd2=.7 color=F
	${GREY} < vel1.z.H barlabel="Velocity(km/s)" >b.V allpos=y bias=2 clip=2 labelsz=16 crowd2=.7 color=J
	Vppen vpstyle=n gridnum=2,1 <a.V b.V >$@ yscale=2

vel1.tau.delta.V:	vel1.tau.H
	Window < delta.vel0.tau.H  f3=1|\
	${GREY}  >a.V  barlabel="Slowness (s/km)"  o2=-2.56 d2=.256 \
		o1=-.48 d1=.048 max1=4 label1="Tau(s)" labelsz=16 crowd2=.7
	${GREY} < vel1.tau.H barlabel="Velocity(km/s)" >b.V allpos=y bias=2 clip=2 labelsz=16 crowd2=.7
	Vppen vpstyle=n gridnum=2,1 <a.V b.V >$@ yscale=2


BAR=barlabel="Velocity(km/s)"
#tau-%.v:	tau-%.H
#	Real <  tau-$*.H | ${GREY}  out=tau_$*.v max1=3.5 clip=2. bias=2. allpos=y ${BAR}
#	${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.H reflectors.z.vel_cor.H
	${GREY} < vel_cor.H  out=a.v bias=2 allpos=y barlabel="Velocity(km/s)"
	${GRAPH} < reflectors.z.vel_cor.H out=b.v symbol="*" plotcol=7
	vp_Overlay a.v b.v >$@

cor.v:
	Grey < mig.vel_cor.H  eout=1| Transp plane=23 >tt.T
	Cubeplot < tt.T frame1=85  frame2=240 out=$@  frame3=1>/dev/null point1=.7 point2=.7 pint3=.3 label1="Depth(km)" title=" " flat=y label2="X_position (km)" label3="phx (s/km)"

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 cut.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=45 label1="Depth (km)" label2="Offset angle (degrees)" title=" "
	Window <  smooth_sem.vel0.H min1=$* n1=1  >de.H
	Window <  cut.H min2=$* n2=1  >ct.H
	${BINDIR}/plot_it.x  pan=pn.H reflectors=reflectors.vel0.H < de.H >cur.H par=coher.P cut=ct.H
	< cur.H Graph out=b.v >/dev/null yreverse=y min2=0 max2=4.5 min1=0 max1=45\
   wantaxis=n  title=" " symbol="*" symbolsz=16 plotcol=0 
	< cur.H Graph out=c.v >/dev/null yreverse=y min2=0 max2=4.5 min1=0 max1=45\
   wantaxis=n symbolsz=8 plotcol=7 title=" "
	vp_Overlay a.v b.v  c.v >$@


semb-ref.vel1.z.%.V:	smooth_sem.vel1.z.H sem_ref.vel1.z.H
	Window < sem_ref.vel1.z.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.vel1.z.H f2=$* n2=1 j1=2 f1=0 |Graph symbolsz=20 min1=2 max1=18 min2=-4 max2=4  >b.V yreverse=y title=" " crowd=1. crowd=1 axis=n plotfat=13 symbol="*" plotcol=7 symbolsz=16
	Window <smooth_sem.vel1.z.H f2=$* n2=1 j1=2 f1=1 |Graph symbolsz=20 min1=2 max1=18 min2=-4 max2=4 >c.V yreverse=y title=" " crowd=1. crowd=1 axis=n plotfat=13 symbol="*" plotcol=0 symbolsz=12
	Vppen<  a.V b.V c.V  vpstyle=n erase=n >$@ 

semb-ref.vel1.tau.%.V:	smooth_sem.vel1.tau.H sem_ref.vel1.tau.H
	Window < sem_ref.vel1.tau.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.vel1.tau.H f2=$* n2=1 |Graph symbolsz=20 min1=2 max1=18 min2=-4 max2=4 out=b.v >b.V yreverse=y title=" " crowd=1. crowd=1 axis=n plotfat=13 symbol="*"
	Vppen<  a.V b.V >$@ vpstyle=n erase=n  

semb-ref.vel3.z.%.V:	smooth_sem.vel3.z.H sem_ref.vel3.z.H
	Window < sem_ref.vel3.z.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.vel3.z.H f2=$* n2=1 |Graph symbolsz=20 min1=2 max1=18 min2=-4 max2=4 out=b.v >b.V yreverse=y title=" " crowd=1. crowd=1 axis=n plotfat=13 symbol="*"
	Vppen<  a.V b.V >$@ vpstyle=n erase=n  

semb-ref.vel3.tau.%.V:	smooth_sem.vel3.tau.H sem_ref.vel3.tau.H
	Window < sem_ref.vel3.tau.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.vel3.tau.H f2=$* n2=1 |Graph symbolsz=20 min1=2 max1=18 min2=-4 max2=4 out=b.v >b.V yreverse=y title=" " crowd=1. crowd=1 axis=n plotfat=13 symbol="*"
	Vppen<  a.V b.V >$@ vpstyle=n erase=n 

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 symbolsz=16 min1=2 max1=18 min2=-4 max2=4  >b.V yreverse=y title=" " crowd=1. crowd=1 axis=n plotfat=13 symbol="*" plotcol=0
	Window <smooth_sem.vel0.H f2=$* n2=1 |Graph symbolsz=8 plotcol=0 min1=2 max1=18 min2=-4 max2=4  >c.V yreverse=y title=" " crowd=1. crowd=1 axis=n plotfat=13 symbol="*" plotcol=7
	Vppen<  a.V b.V c.V >$@ vpstyle=n erase=o 

${RESDIR}/sigma.v: tau-vel_cor.H
	Imag <  tau-vel_cor.H | ${DEPTH_GREY}  out=$@ max1=3.5  color=I barlabel="Amplitude" label1="Tau(s)"

mytest.H:  ${DATA_FREQ} vel0.mig.H #mig.P ${MIG} ${BINDIR}/ang_gather.x
	Window <  ${DATA_FREQ} >in.me.H n1=500 squeeze=n min3=0 n4=128
	${MIG} par=mig.P>log.mig2 Data=in.me.H Image=$@ Slow=vel0.mig.H

mig.vel0.H:	mytest.H ${BINDIR}/offtest.x ang.P
	${BINDIR}/offtest.x < mytest.H >gg.H par=ang.P
	Window < gg.H min2=0 >$@


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