MAKE_DEPEND=yes
include ${SEPINC}/SEP.top
BINDIR = ../Bin/
SRCDIR = ../Src
RESDIR =  ../Figs
RESULTSER=
UF90INCLUDES=-I.
UF90DEFINES=-I.
UF90LIBS=-lgeef90 -lsupersetf90 -lsuperset -lsepauxf90 -lsepaux -lsep2df90
UPSTEXFLAGS = invras=y color=y
OLEVEL=3
LAYERS=0 1 2 3 4 5 

#RESULTSNR=
#RESULTSCR= overlay-vel-cor rays-vel0 time-diff overlay-vel1 overlay-vel2 \
#overlay-vel3 overlay-vel4 panel depth-reflector-movement angles

#RESULTSER =  depth-overlay-vel0 depth-overlay-vel-cor  depth-overlay-vel1 depth-overlay-vel2 depth-overlay-vel3

RESULTSER=depth-initial tau-initial sigma





###############################################################








###############################################################


#vel1.z.H: vel0.H  tomo.1.z.P  px.vel_cor.H px.vel0.H ref.vel0.H ${BINDIR}/Tomo.x
#	Window < vel0.H >vel.a.H j1=4 j2=8
#	Extend_it.x < vel.a.H >vel.wind.H beg1=10 beg2=10 end1=10 end2=10
#	${BINDIR}/Tomo.x par=tomo.1.z.P < vel.wind.H >vel_big.H delta_t=times.vel0.H \
#   reflectors=ref.vel0.H zero_rays=zero.vel0.H px_rays=px.vel0.H\
#   delta_slow=delta.vel1.H time_errors=err.vel1.H residual_times=res.vel1.H\
#   correct_rays=px.vel_cor.H true_rays=px.vel_cor.H
#	Window < vel_big.H >$@ f1=10 f2=10 n1=79 n2=79
#

vel2.%.H:	vel1.z.H  tomo.1.%.P    px.vel_cor.H ref.vel1.%.H ${BINDIR}/Tomo.x
	<vel1.z.H Extend_it.x beg1=10 beg2=10 end1=10 end2=10 >vel.H
	${BINDIR}/Tomo.x par=tomo.1.$*.P < vel.H >vel2.$*.big.H delta_t=times.vel1.$*.H \
  reflectors=ref.vel1.$*.H zero_rays=zero.vel1.$*.H px_rays=px.vel1.$*.H \
	delta_slow=delta.vel2.$*.H time_errors=err.vel2.$*.H \
  residual_times=res.vel2.$*.H true_rays=px.vel_cor.H 
	Window < vel2.$*.big.H >$@ f1=10 f2=10 n1=79 n2=79

vel1.%.H:	vel0.z.H  tomo.1.%.P    px.vel_cor.H ref.vel0.%.H ${BINDIR}/Tomo.x
	Window<vel0.z.H j1=4 j2=8|Extend_it.x beg1=10 beg2=10 end1=10 end2=10 >vel.H
	${BINDIR}/Tomo.x par=tomo.1.$*.P < vel.H >vel1.$*.big.H delta_t=times.vel0.$*.H \
  reflectors=ref.vel0.$*.H zero_rays=zero.vel0.$*.H px_rays=px.vel0.$*.H \
	delta_slow=delta.vel1.$*.H time_errors=err.vel1.$*.H \
  residual_times=res.vel1.$*.H true_rays=px.vel_cor.H 
	Window < vel1.$*.big.H >$@ f1=10 f2=10 n1=79 n2=79



#dipsz.%.H: ref.%.H ${BINDIR}/create_dips.x dips.%.P
#	${BINDIR}/create_dips.x <ref.$*.H  par=dips.$*.P\
#	vel=$*.H |Smooth par=dips.$*.P >$@


##################################
####CREATE RAY DATABASES##########
##################################

px.%.H:  rays.P  %.H ref.%.H #${BINDIR}/Tomo.x
	${BINDIR}/Tomo.x  par=rays.P   >log.rays < $*.H\
   reflectors=ref.$*.H zero_rays=zero.$*.H px_rays=$@
	touch $@

ref.%.H:  reflectors.%.H ${BINDIR}/parse_ref.x
	${BINDIR}/parse_ref.x < reflectors.$*.H >a.H
	Real < a.H |Smooth rect1=2 >r.H
	Imag < a.H |Smooth rect1=2 >i.H
	Cmplx r.H i.H >$@

reflectors.%.z.H:	%.z.H
	cp $*.z.H $*.H
	cp $*.z.H $*.wind.H
	${MAKE} reflectors.$*.H
	mv reflectors.$*.H reflectors.$*.z.H
	${RM} reflectors.$*.H $*.H
	




#################################
######INITIAL VELOCITY###########
#################################
dome_vel.H:  ${BINDIR}/dome_model.x dome.P
	${BINDIR}/dome_model.x velocity=$@ par=dome.P >/dev/null refs=all_reflectors.H
	echo o2=0. d2=.016 >> $@

vel_cor.H:  dome_vel.H ${BINDIR}/Smooth.x
	<dome_vel.H   ${BINDIR}/Smooth.x  nwind1=19 nwind2=19 | \
	Window j1=2 j2=2 > $@


all: ${BINDIR}/Tomo.x

#################################
######DEPTH REFLECTORS###########
#################################

reflector.0.H:  dome_vel.H ${BINDIR}/make_layer.x vel_cor.H
	${BINDIR}/make_layer.x < dome_vel.H  vel=2.7 |Window f1=15 n2=1 j1=2 n1=590 >$@

reflector.1.H:  dome_vel.H ${BINDIR}/make_layer.x vel_cor.H
	${BINDIR}/make_layer.x < dome_vel.H  vel=2.592 ntime=2|Window f1=15 n2=1 j1=2 n1=590>$@

reflector.2.H:  dome_vel.H ${BINDIR}/make_layer.x vel_cor.H
	${BINDIR}/make_layer.x < dome_vel.H  vel=3.0 |Window f1=15 n2=1 j1=2  n1=590>$@

reflector.3.H:  dome_vel.H ${BINDIR}/make_layer.x vel_cor.H
	${BINDIR}/make_layer.x < dome_vel.H  vel=3.4 |Window f1=15 n2=1 j1=2  n1=590>$@

reflector.4.H:  dome_vel.H ${BINDIR}/make_layer.x vel_cor.H
	${BINDIR}/make_layer.x < dome_vel.H  vel=3.6 |Window f1=15 n2=1 j1=2  n1=590>$@

reflector.5.H:  dome_vel.H ${BINDIR}/make_layer.x vel_cor.H
	${BINDIR}/make_layer.x < dome_vel.H  vel=3.99 |Window f1=15 n2=1 j1=2  n1=590>$@
#	${BINDIR}/make_layer.x < dome_vel.H  vel=2.99 |Window f1=60 n2=1 j1=16 n1=590 >$@


reflectors.vel_cor.H:	 dome_vel.H ${BINDIR}/make_layer.x vel_cor.H
	${MAKE} $(addsuffix .H, $(addprefix reflector.,${LAYERS} )) 
	Cat axis=2 $(addsuffix .H, $(addprefix reflector.,${LAYERS}))  >$@
	${RM} $(addsuffix .H, $(addprefix reflector.,${LAYERS} ))  


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


#MAKE INITIAL PLOTS
GRAPH=Graph >/dev/null 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 >/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}/depth-initial.v:	depth-vel_cor.v depth-vel0.v
	vp_SideBySideIso depth-vel_cor.v depth-vel0.v >$@

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

depth-%.v:	reflectors.%.H %.H
	${GREY} < $*.H out=$*.v clip=2. bias=2.  allpos=y
	${GRAPH} < reflectors.$*.H out=reflectors.$*.v
	vp_Overlay $*.v reflectors.$*.v >$@

tau-%.v:	reflectors.%.H 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}/sigma.v: tau-vel_cor.H
	Imag <  tau-vel_cor.H | ${GREY}  out=$@ max1=3.5  color=I





#This creates the surface.  Basically using Vel to create a linear
#v(z) model.  Get rid of this, it is to confusing.
#Also, note: Surface needs to extend further than Refl-flat (or what
#ever the correct depth surface is) because we shoot from the correct reflector
#to the surface, and then attempt to shoot back to the reflectors time position
#if we do not cross this time position for all locations MatchRay.h will give
#an error
surface.H: surf.P 
	Vel par=surf.P >Sz.h
	Vel par=surf.P >Sx.h vr1=-2 smooth1=21.99 vr2=21.99
	Cmplx Sx.h Sz.h >$@
	${RM} Sx.h Sz.h




###################################################
####################################################
##################VELOCITY FILES####################
####################################################
####################################################


#This makes the initial velocity model. It takes the first trace
#from the correct model (something close to a v(z)) and replicates it
vel0.H  : vel_cor.H ${BINDIR}/create_vel0.x
	Window < vel_cor.H n3=1 |\
	${BINDIR}/create_vel0.x  > $@ -


vel6.H: tomo.vel5.H ${BINDIR}/expand_it.x expand.P
	Smooth rect1=2 rect2=2 < tomo.vel.vel5.H >junk1.H
	< junk1.H  ${BINDIR}/expand_it.x par=expand.P > junk2.H
	< junk2.H Smooth rect1=1 rect=1 > $@



####################################################
####################################################
#############CORRECT VELOCITY ACTIONS###############
####################################################
####################################################

rays.%.H:	 shoot.P %.H ${BINDIR}/shoot.x
	${BINDIR}/shoot.x  par=shoot.P raypar=ray_pz.$*.H\
	raymod=ray_mz.$*.H >$@ < $*.H j1=4
    

#Find the rays that cross the correct depth reflector
#Matchz contains the matching rays????
match.%.H: rays.%.H Match.P reflectors.%.H ${BINDIR}/Matchray.x
	$(BINDIR)/Matchray.x  <rays.$*.H >$@ par=Match.P \
	reflector=reflectors.$*.H raypar=ray_pz.$*.H\
	raymod=ray_mz.$*.H raypar_match=ray_par_match.$*.H \
	pos_match=pos_match.$*.H location=location.$*.H \
	raymod_match=ray_mod_match.$*.H time_match=time_match.$*.H  time_ref=time_ref.$*.H


parse_rays.%.H: ${BINDIR}/parse_rays.x parse.%.P match.%.H match.vel_cor.H
	${BINDIR}/parse_rays.x par=parse.$*.P  >$@\
	position=pos_match.$*.H  position_c=pos_match.vel_cor.H \
	location=location.$*.H   location_c=location.vel_cor.H \
	raypar=ray_par_match.$*.H raypar_c=ray_par_match.vel_cor.H \
	raymod=ray_mod_match.$*.H raymod_out=parse.ray_mod.$*.H\
	rtraj=match.$*.H rtraj_out=parse.match.$*.H\
	correct=time_match.vel_cor.H correct_out=parse.time_correct.$*.H \
	model=time_match.$*.H model_out=parse.time_model.$*.H \
	time_ref=time_ref.$*.H time_ref_out=parse.time_ref.$*.H  time_errors=err.$*.H\
	raypar_out=parse.ray_par.$*.H diff=diff.$*.H diff_out=diff_out.$*.H  \
	position_out=parse.mod_position.$*.H position_c_out=parse.cor_position.$*.H



time_up.cor.%.H :  vel_cor.H Zoff.P reflectors.vel_cor.H Tmin.%.P\
   surface.H ${BINDIR}/Raypath.x ${BINDIR}/MatchRay.x ${BINDIR}/shoot.x
	#This shoots rays from the surface in depth
	Window < reflectors.vel_cor.H f2=$* n2=1 >ref.H
	${BINDIR}/shoot.x < vel_cor.H > ray_up$*.H par=Zoff.P \
	raypar=ray_pz_up$*.H raymod=ray_mz_up$*.H sources=ref.H zero_offset=-1
#	$(BINDIR)/Raypath.x  <vel_cor.spline.H > ray_up$*.H par=Zoff.P \
#  Raypar=ray_pz_up$*.H Raymod=ray_mz_up$*.H Source=ref.H
	$(BINDIR)/MatchRay.x  <ray_up$*.H >/dev/null cross_only=1 par=Tmin.$*.P \
	Refl=surface.H Raypar=ray_pz_up$*.H Raymod=ray_mz_up$*.H  \
	Time_cross=$@ Xv_cross=xcross_up$*.H P_cross=pcross_up$*.H \
	Dip_cross=dipcross_up$*.H
#	${RM} ref.H ray_up$*.H


time_up.H:	 vel_cor.spline.H Zoff.P reflectors.vel_cor.H surface.H
	${MAKE} $(addsuffix .H, $(addprefix time_up.cor.,${LAYERS} )) 
	Cat axis=2 $(addsuffix .H, $(addprefix dipcross_up,${LAYERS} )) >a.H
	<a.H  Add scale=-1> dipcross_up.H
	Cat axis=2 $(addsuffix .H, $(addprefix ray_mz_up,${LAYERS})) > \
			ray_mz_up.H
	Cat axis=2 $(addsuffix .H, $(addprefix ray_pz_up,${LAYERS}))  >\
			ray_pz_up.H
	Cat axis=2 $(addsuffix .H, $(addprefix pcross_up,${LAYERS}))  > a.H
	Real <a.H | Smooth.x nwind1=3  >r.H #1
	Imag <a.H | Smooth.x nwind1=7 >i.H  #5
	Cmplx  r.H i.H >pcross_up.H
	Cat axis=2 $(addsuffix .H, $(addprefix xcross_up,${LAYERS}))>a.H
	Real < a.H  | Smooth.x nwind1=11 >r.H
	Imag < a.H > i.H 
	Cmplx r.H i.H >xcross_up.H
	Cat axis=2 $(addsuffix .H, $(addprefix time_up.cor.,${LAYERS}  )) | \
	Smooth.x nwind1=11 >	$@	
	${RM} r.H i.H a.H	
	${RM} $(addsuffix .H, $(addprefix dipcross_up,${LAYERS})) 
	${RM} $(addsuffix .H, $(addprefix ray_mz_up,${LAYERS})) 
	${RM} $(addsuffix .H, $(addprefix ray_pz_up,${LAYERS}))
	${RM} $(addsuffix .H, $(addprefix pcross_up,${LAYERS}))
	${RM} $(addsuffix .H, $(addprefix xcross_up,${LAYERS}))
	${RM} $(addsuffix .H, $(addprefix time_up.cor.,${LAYERS})) 






####################################################
####################################################
############ITTERATION VELOCITY ACTIONS#############
####################################################
####################################################

#CREATE SLOPES (REDO TO BE A FUNCTION OF THE MODEL)
angles.%.H: ${BINDIR}/create_mod.x ${BINDIR}/pfinder.x reflectors.%.H %.wind.H
	${BINDIR}/create_mod.x < $*.wind.H > c.H ref=reflectors.$*.H  
	Window < c.H min2=.4 max2=19 >d.H  
	Extend_it.x < d.H beg2=2 end2=4 >e.H
	${BINDIR}/pfinder.x dip=y < e.H >$@


tau_angles.%.H: reflectors.%.H tau_slope.P %.wind.H tau_convert.P
	${BINDIR}/vel_convert.x  < $*.wind.H > tau.$*.wind.H  par=tau_convert.P\
    ray_traj=reflectors.$*.H ray_traj_out=tau_reflectors.$*.H 
	${BINDIR}/find_slopes.x < tau_reflectors.$*.H par=tau_slope.P |Smooth rect1=5 rect2=3>	$@	



#This shoots rays from the surface using the current velocity model
pseudo_surf.${VELOCITY}.%.H:  ${VELOCITY}.spline.H Zoff.P  time_up.H Tmin.%.P ${BINDIR}/p_to_ang.x ${BINDIR}/shoot.x ${BINDIR}/Raypath.x
	@echo MAKE $@
	Window f2=$* n2=1 < xcross_up.H >x_up.H
	Window f2=$* n2=1 < pcross_up.H >a.H
	Add scale=-1 a.H >p_up.H
	${BINDIR}/p_to_ang.x < p_up.H >angles.H
	${BINDIR}/shoot.x < ${VELOCITY}.H >ray_path.H par=Zoff.P \
  raypar=ray_par.H raymod=ray_mod.H sources=x_up.H angles=angles.H

#	$(BINDIR)/Raypath.x  <${VELOCITY}.spline.H >ray_path.H par=Zoff.P zero_offset=-1\
#	Raypar=ray_par.H Raymod=ray_mod.H \
#	Source=x_up.H Psrc=p_up.H
	#PSEUDO_SURF
	Window <xcross_up.H    f2=$* n2=1  |Real > x.H
	Window <time_up.H      f2=$* n2=1        > t.H
	Window <dipcross_up.H  f2=$* n2=1        > dip.H
	Cmplx x.H t.H >Rt.H
	< ray_path.H  $(BINDIR)/MatchRay.x >Tz.H cross_only=1 cross_time=1  \
	par=Tmin.$*.P Refl=Rt.H Raypar=ray_par.H \
	Raymod=ray_mod.H Time_cross=time.H Xv_cross=z.H  P_cross=pcross.H \
  Dip_cross=dipcross.H
#	par=Tmin.$*.P Refl=Rt.H Dip_refl=dip.H Raypar=ray_par.H \
#	Window <z.H f1=1 | Real >zr.H
#	Window <z.H f1=1 | Imag | /biondo/bin/${MTYPE}/GSmooth nwind1=25 >zi.H
#	Cmplx zr.H zi.H > $@
	Cp z.H $@
#	${RM} zi.H zr.H x.H  Rt.H  ray_path.H ray_par.H ray_mod.H dip.H t.H 
#	${RM} z.H z.H pcross.H dipcross.H Tz.H p_up.H x_up.H time.H 


#MAKE THE pseudo surfaces
reflectors.%.H:  time_up.H Tmin.P %.H %.wind.H
	${MAKE} $(addsuffix .H, $(addprefix pseudo_surf.$*.,${LAYERS} )) VELOCITY=$*
	Cat axis=2  $(addsuffix .H, $(addprefix pseudo_surf.$*.,${LAYERS})) > $@
	${RM}   $(addsuffix .H, $(addprefix pseudo_surf.$*.,${LAYERS})) 

clean: jclean
	${RM} Pos_match




#CREATE SPLINES FOR RAYTRACING
%.spline.H: %.H ${BINDIR}/Splintab2.x
	< $*.H  ${BINDIR}/Splintab2.x >$@

ray.%.H : %.spline.H ray_z.P ${BINDIR}/Raypath.x
	$(BINDIR)/Raypath.x <$*.spline.H >$@ par=ray_z.P Raypar=ray_par.big_$*.H \
	Raymod=ray_mod.big_$*.H

#CREATE A WINDOWED VERSION OF THE MODEL
%.wind.H: %.H wind.P
	Window < $*.H > $@ par=wind.P

vel0.wind.H: vel0.H	
	Window < vel0.H >vel0.wind.H j1=4 j2=8

vel_cor.wind.H: vel_cor.H	
	Window < vel_cor.H >vel_cor.wind.H j1=4 j2=8


rays_up%.${VELOCITY}.H:	ray_up.P reflectors.${VELOCITY}.H ${VELOCITY}.H \
	${BINDIR}/shoot.x ${BINDIR}/sources_up.x
	Window < reflectors.${VELOCITY}.H f2=$* n2=1  |\
	${BINDIR}/sources_up.x > s.H par=ray_up.P
	Imag < s.H |Smooth rect1=10 >i.H; Real < s.H >r.H; Cmplx r.H i.H >sources.H
	${BINDIR}/shoot.x par=ray_up.P < ${VELOCITY}.H  sources=sources.H \
   raymod=ray_mod_up$*.${VELOCITY}.H   >$@ 

rays_up.%.H:	ray_up.P reflectors.%.H  %.H
	${MAKE} $(addsuffix .$*.H, $(addprefix rays_up, ${LAYERS})) VELOCITY=$*
	Cat axis=2  $(addsuffix .$*.H, $(addprefix rays_up, ${LAYERS})) |Transp plane=23 >$@
	Cat axis=2  $(addsuffix .$*.H, $(addprefix ray_mod_up, ${LAYERS})) |Transp plane=23 >ray_mod_up.$*.H
	echo d2=.025 o2=1 >> $@


prep.%:	%.wind.H angles.%.H rays_up.%.H parse_rays.%.H
	
tau.%:	%.wind.H tau_angles.%.H rays_up.%.H parse_rays.%.H tau_convert.P
	${BINDIR}/vel_convert.x  < $*.wind.H > tau.$*.wind.H  par=tau_convert.P\
		ray_traj=parse.match.$*.H ray_traj_out=tau.match.$*.H \
		ray_mod=parse.ray_mod.$*.H ray_mod_out=tau.ray_mod.$*.H 
	${BINDIR}/vel_convert.x  < $*.wind.H > tau.$*.wind.H  par=tau_convert.P\
		ray_traj=rays_up.$*.H ray_traj_out=tau.rays_up.$*.H \
		ray_mod=ray_mod_up.$*.H ray_mod_out=tau.ray_mod_up.$*.H 
#	${BINDIR}/vel_convert.x  < vel_cor.wind.H > tau.vel_cor.wind.H  par=tau_convert.P
	
	
#tau.
#tau.match
#tau.ray_mod
#tau.rays_up
#tau.ray_mod_up


tau_tomo.%.H  : Tau_tomo.%.P  tau_wind_it.%.P
	${BINDIR}/wind_it.x    par=tau_wind_it.$*.P time_ref=parse.time_ref.$*.H \
 time_match=parse.time_model.$*.H ray_traj=tau.match.$*.H \
  ray_mod=tau.ray_mod.$*.H  time_correct=parse.time_correct.$*.H \
	zero_off=tau.rays_up.$*.H  zero_off_mod=tau.ray_mod_up.$*.H \
  ray_par=parse.ray_par.$*.H  time_ref_out=time_ref.H  \
 time_match_out=time_model.H ray_traj_out=match.H \
  ray_mod_out=ray_mod.H  time_correct_out=time_correct.H  >aa \
	zero_off_out=zero_off.H  zero_off_mod_out=zero_off_mod.H \
  ray_par_out=ray_par.H weight=parse_rays.$*.H weight_out=weight.H
	$(BINDIR)/Tomo.x par=Tau_tomo.$*.P   >$@  Vel0=tau.$*.wind.H \
	R_traj=match.H R_rpar=ray_par.H zero_off=zero_off.H\
	R_mod=ray_mod.H  R_time_ref=time_ref.H zero_off_mod=zero_off_mod.H\
	R_time_tot=time_model.H R_time_0=time_model.H\
	R_time=time_correct.H  Vel_tomo=tau_tomo.vel.$*.H   \
	weight=weight.H slopes=tau_angles.$*.H

tau_tomo2.%.H  : Tau_tomo.%.P  tau_wind_it.%.P
	${BINDIR}/wind_it.x    par=tau_wind_it.$*.P time_ref=parse.time_ref.$*.H \
 time_match=parse.time_model.$*.H ray_traj=tau.match.$*.H \
  ray_mod=tau.ray_mod.$*.H  time_correct=parse.time_correct.$*.H \
	zero_off=tau.rays_up.$*.H  zero_off_mod=tau.ray_mod_up.$*.H \
  ray_par=parse.ray_par.$*.H  time_ref_out=time_ref.H  \
 time_match_out=time_model.H ray_traj_out=match.H \
  ray_mod_out=ray_mod.H  time_correct_out=time_correct.H  >aa \
	zero_off_out=zero_off.H  zero_off_mod_out=zero_off_mod.H \
  ray_par_out=ray_par.H weight=parse_rays.$*.H weight_out=weight.H
	$(BINDIR)/Tau_tomo.x par=Tau_tomo.$*.P   >$@  Vel0=tau.$*.wind.H \
	R_traj=match.H R_rpar=ray_par.H zero_off=zero_off.H\
	R_mod=ray_mod.H  R_time_ref=time_ref.H zero_off_mod=zero_off_mod.H\
	R_time_tot=time_model.H R_time_0=time_model.H\
	R_time=time_correct.H  Vel_tomo=tau_tomo.vel.$*.H   \
	weight=weight.H angles=tau_angles.$*.H


tomo.%.H  : Tomo.%.P  wind_it.%.P# prep.% ${BINDIR}/wind_it.x ${BINDIR}/Tomo.x
	${BINDIR}/wind_it.x    par=wind_it.$*.P time_ref=parse.time_ref.$*.H \
 time_match=parse.time_model.$*.H ray_traj=parse.match.$*.H \
  ray_mod=parse.ray_mod.$*.H  time_correct=parse.time_correct.$*.H \
	zero_off=rays_up.$*.H  zero_off_mod=ray_mod_up.$*.H \
  ray_par=parse.ray_par.$*.H  time_ref_out=time_ref.H  \
 time_match_out=time_model.H ray_traj_out=match.H \
  ray_mod_out=ray_mod.H  time_correct_out=time_correct.H  >aa \
	zero_off_out=zero_off.H  zero_off_mod_out=zero_off_mod.H \
  ray_par_out=ray_par.H weight=parse_rays.$*.H weight_out=weight.H
	Extend_it.x   < vel_cor.wind.H > cor.H beg1=10 end1=10
	Extend_it.x   < $*.wind.H > vel_0.H
	Extend_it.x   < angles.$*.H > angles.H
	$(BINDIR)/Tomo.x par=Tomo.$*.P   >$@  Vel0=vel_0.H \
	R_traj=match.H R_rpar=ray_par.H zero_off=zero_off.H\
	R_mod=ray_mod.H  R_time_ref=time_ref.H zero_off_mod=zero_off_mod.H\
	R_time_tot=time_model.H R_time_0=time_model.H\
	R_time=time_correct.H  Vel_tomo=tomo.vel.$*.H   \
	weight=weight.H slopes=angles.H




compile:	${BINDIR}/MatchRay.x ${BINDIR}/shoot.x  ${BINDIR}/Matchray.x  \
  ${BINDIR}/parse_rays.x ${BINDIR}/Splintab2.x ${BINDIR}/Raypath.x \
  ${BINDIR}/p_to_ang.x ${BINDIR}/Tomo.x ${BINDIR}/wind_it.x\
  ${BINDIR}/find_slopes.x ${BINDIR}/sources_up.x  \
	${BINDIR}/vel_convert.x ${BINDIR}/expand_it.x ${BINDIR}/slope_angle.x

${BINDIR}/Raypath.x: Raypath.o bcucof.o findvelz.o parax2dz.o rksuite.o velocitnz.o


${RESDIR}/lap2-overlay-vel-cor.v:	vel_cor.wind.H reflectors.vel_cor.H
	${GREY} < vel_cor.wind.H out=a.v
	${GRAPH} < reflectors.vel_cor.H out=b.v
	vp_Overlay a.v b.v >$@

${RESDIR}/depth2-overlay-%.v:	%.wind.H reflectors.%.H
	${GREY} < $*.wind.H out=a.v
	${GRAPH} < reflectors.$*.H out=b.v
	vp_Overlay a.v b.v >$@

${RESDIR}/vel0.v:	vel0.wind.H reflectors.vel0.H
	${GREY} < vel0.wind.H out=a.v title="Initial Velocity" 
	${GRAPH} < reflectors.vel0.H out=b.v
	vp_Overlay a.v b.v >$@

${RESDIR}/lap-vel%.v:	vel%.wind.H reflectors.vel%.H
	${GREY} < vel$*.wind.H out=a.v title="Laplacian $* Iteration(s)" 
	${GRAPH} < reflectors.vel$*.H out=b.v
	vp_Overlay a.v b.v >$@


${RESDIR}/vel-cor.v:	vel_cor.wind.H reflectors.vel_cor.H
	${GREY} < vel_cor.wind.H out=a.v title="Model" 
	${GRAPH} < reflectors.vel_cor.H out=b.v
	vp_Overlay a.v b.v >$@

${RESDIR}/depth-angles.v:	angles.vel0.H
	${GREY} <angles.vel0.H color=I bias=0. allpos=n out=$@

NONE=title=" " wantaxis=y crowd=.8 label1="Position(km)" label2="delta t" label=15
${RESDIR}/time-diff.v:	parse_rays.vel0.H
	Window < diff_out.vel0.H f3=0 n3=1 |Transp |Graph ${NONE} >a1.V
	Window < diff_out.vel0.H f3=1 n3=1 |Transp |Graph ${NONE} >a2.V
	Window < diff_out.vel0.H f3=2 n3=1 |Transp |Graph ${NONE} >a3.V
	Window < diff_out.vel0.H f3=3 n3=1 |Transp |Graph ${NONE} >a4.V
	Window < diff_out.vel0.H f3=4 n3=1 |Transp |Graph ${NONE} >a5.V
	Window < diff_out.vel0.H f3=5 n3=1 |Transp |Graph ${NONE} >a6.V
	Vppen < a1.V a2.V a3.V a4.V a5.V a6.V vpstyle=n size=r gridnum=3,2 >/dev/null\
   out=$@


$(BINDIR)/Raypath.x: Raypath.o findvelz.o parax2dz.o velocitnz.o rksuitez.o bcucofz.o


${BINDIR}/Smooth.x: Smooth.o gausw.o boxw.o zero.o compsub.o smax.o

##########################
#OTHER RULES/DEFINITIONS##
##########################

.PRECIOUS:  reflectors.%.H match.%.H time_up.%.H ref.%.H \
rays.%.H  %.wind.H %.spline.H   bad_rays.%.H parse_rays.%.H\
ray.%.H match_rays.${VELOCITY}.%.H match_big_rays.%.H helix_tomo.%.H \
rays_up.%.H






include ${SEPINC}/SEP.bottom
