include ${SEPINC}/SEP.top
include ../../Src/thesis.include
RESULTSER=init.overlay cor.overlay first.tomo reg.tomo
UF90INCLUDES=${BOBINCS}
UF90LIBS=${BOBLIBS}


GREY= Grey min1=0 max1=1.8 min2=0 max2=9.5 title=" "
GRAPH= Graph min2=0 max2=1.8 min1=0 max1=9.5 yreverse=y wantaxis=n title=" " wantlabel=n wantframe=n
${RESDIR}/init.overlay.v: first.error.H init.vel.H ${BINDIR}/slim_sub.x
	${GREY}  < init.vel.H allpos=y bias=1.8 clip=1.4 >vel.V
	${BINDIR}/slim_sub.x < ray_match.init.H >ff.H time=first.error.H
	<ff.H Window j2=1 | ${GRAPH}  >ray.V
	Vppen erase=o vpstyle=n < vel.V ray.V >ff.V out=$@

${RESDIR}/cor.overlay.v: first.error.H cor.vel.H ${BINDIR}/slim_sub.x
	${GREY}  < cor.vel.H allpos=y bias=1.8 clip=1.4 >vel.V
	${BINDIR}/slim_sub.x < ray_match.cor.H >ff.H time=first.error.H
	<ff.H Window j2=1 | ${GRAPH}  >ray.V
	Vppen erase=o vpstyle=n < vel.V ray.V >ff.V out=$@

${RESDIR}/second.overlay.v: first.error.H second.vel.H ${BINDIR}/slim_sub.x
	${GREY}  < second.vel.H allpos=y bias=1.8 clip=1.4 >vel.V
	${BINDIR}/slim_sub.x < ray_match.second.H >ff.H time=first.error.H
	<ff.H Window j2=1 | ${GRAPH}  >ray.V
	Vppen erase=o vpstyle=n < vel.V ray.V >ff.V out=$@

${RESDIR}/first.tomo.v: first.tomo.H
	${GREY} < first.tomo.H allpos=y bias=1.8 clip=1.4 >vel.V out=$@

${RESDIR}/reg.tomo.v: reg.tomo.H
	${GREY} < reg.tomo.H allpos=y bias=1.8 clip=1.4 >vel.V out=$@



oper.H:	${BINDIR}/oper.x oper.P
	${BINDIR}/oper.x  par=oper.P >$@

%.vel.H:	${BINDIR}/simple_model.x %.model.P
	${BINDIR}/simple_model.x par=$*.model.P |Smooth par=$*.model.P >$@


%.rec_list.H:	%.rec_list.HH
	Dd < $*.rec_list.HH >f.H esize=4
	Window < f.H n1=1 >r.H
	Window < f.H f1=1 >i.H
	Cmplx r.H  i.H >$@



#
#%.ang.H:	%.ang.HH
#	Dd < $*.ang.HH >f.H esize=4
#	Window < f.H n1=1 >r.H
#	Window < f.H f1=1 >i.H
#	Cmplx r.H  i.H >$@
#

init.source.H:	init_x.src.P ${BINDIR}/source_list.x init_z.src.P
	${BINDIR}/source_list.x par=init_x.src.P >s1.H
	${BINDIR}/source_list.x par=init_z.src.P >s2.H
	Cat s1.H s2.H >$@ axis=1

cor.source.H:	init_x.src.P ${BINDIR}/source_list.x init_z.src.P
	${BINDIR}/source_list.x par=init_x.src.P >s1.H
	${BINDIR}/source_list.x par=init_z.src.P >s2.H 
	Cat s1.H s2.H >$@ axis=1
	

second.vel.H:	first.tomo.H
	cp first.tomo.H $@

second.source.H:	init.source.H
	cp init.source.H $@

second.rec_list.H:	init.rec_list.H
	cp init.rec_list.H $@

%.rays.H:	%.source.H  ${BINDIR}/shoot.x ray.P  %.vel.H
	${BINDIR}/shoot.x par=ray.P <  $*.vel.H  sources=$*.source.H >$@
	
%.match.H:	%.rays.H %.match.P %.rec_list.H ${BINDIR}/find_true.x
	${BINDIR}/find_true.x par=$*.match.P < $*.rays.H >$@ rec=$*.rec_list.H times=$*.time.H
	
first.error.H:	cor.match.H init.match.H ${BINDIR}/time_match.x
	${BINDIR}/time_match.x < init.match.H time_in=init.time.H time_cor=cor.time.H   ray_c=cor.match.H > ray_match.init.H delta=$@ ray_c_out=ray_match.cor.H

second.error.H:	cor.match.H second.match.H ${BINDIR}/time_match.x
	${BINDIR}/time_match.x < second.match.H time_in=second.time.H time_cor=cor.time.H   ray_c=cor.match.H > ray_match.second.H delta=$@ ray_c_out=ray_match.cor.H

	

first.tomo.H:	${BINDIR}/simp_tomo.x first.error.H first.P ${BINDIR}/Extend_it.x
	Window3d < init.vel.H  j1=2 j2=2 |${BINDIR}/Extend_it.x beg2=1 beg1=1 end1=1 >gg.H
	${BINDIR}/simp_tomo.x	 par=first.P < gg.H >hh.H rays=ray_match.init.H\
    errors=first.error.H
	Window < hh.H f1=1 f2=1 n2=10 n1=10 |Interp d1out=.1 type=1|Transp|Interp  d1out=.5  type=1|Transp >$@

reg.tomo.H:	${BINDIR}/simp_tomo.x first.error.H reg.P ${BINDIR}/Extend_it.x
	Window3d < init.vel.H  j1=2 j2=2 |${BINDIR}/Extend_it.x beg2=1 beg1=1 end1=1 >gg.H
	${BINDIR}/simp_tomo.x	 par=reg.P < gg.H >hh.H rays=ray_match.init.H\
    errors=first.error.H
	Window < hh.H f1=1 f2=1 n2=10 n1=10 |Interp d1out=.1 type=1|Transp|Interp  d1out=.5  type=1|Transp >$@
	



${RESDIR}/newton.v:	oper.H
	Window < oper.H n2=1 | Graph  wantaxis=n title=" " >a.V plotfat=10 min2=-3 max2=3
	Window < oper.H f2=1 | Graph  wantaxis=n title=" " >b.V plotfat=8 dash=1 min2=-3 max2=3
	Vppen < a.V b.V vpstyle=n erase=o >newton.V out=c.v
	vp_annotate batch=y < c.v text_file=text_file >$@ 


clean: jclean
	${RM} *.v

include ${SEPINC}/SEP.bottom
