      MAKE_DEPEND=yes
include ${SEPINC}/SEP.top
RESDIR=.
FFTWLIBS=-L/usr/local/FFTW/FFTW3/lib -lfftw3f
FFTWLIBS=-L/opt/FFTW/lib -lfftw3f

ACMLIB=#-L/opt/acml3.1.0/gnu64/lib -lacml -lacml_mv  /usr/lib64/libg2c.so.0.0.0
UF90LIBS=-lsep2df90 -lsepparf90 -lseppar -lsupersetf90 -lsuperset ${FFTWLIBS} ${ACMLIB} -lsepgeef90
UF90FLAGS=-O3  - # 	-CB


UF90DEFINES=-DFFTW=1 -DSEP_OMP -DOMP# -DDEBUG# -DAMD -DDEBUG

OBJS= wei_cam.o   wei_file.o              wei_step.o       wei_wem.o \
wei_damp.o  wei_fk_fx_wavefield.o  wei_kmap.o   wei_table.o      wei_wem_ssf.o \
wei_dsr.o   wei_fk_type.o          wei_ssf.o    wei_wavespace.o \
wei_fft.o  wei_fft_fftw.o  wei_fft_mkl.o  wei_sg_basic_image.o

all: ${OBJS}

compile: S_G_wem.x S_G_cam.x

marm.freq.H: marmcmp.H
	Transf < marmcmp.H >a.H f_min=3 f_max=19 is_2d=y
	Reverse < a.H which=1 |Pad beg1=4 |Transp |Transp plane=23 >$@
	echo d3=25 >>$@

sref.H: marmvel.H
	Window3d < marmvel.H j1=3 |Transp plane=12 |Transp plane=23 >vel.H
	Lloyd_vel < vel.H  >$@ nref=2

gmage.%.H:  fmage.%.H
	Transp < fmage.$*.H  reshape=2,4,5 plane=13 >m.H
	<m.H Reverse which=2 >x.H core=1
	< x.H OFF2ANG >$@
nmage.%.H:  mmage.%.H
	Transp < mmage.$*.H  reshape=2,4,5 plane=13 >m.H
	<m.H Reverse which=2 >x.H core=1
	< x.H OFF2ANG >$@
gtot.H:  image_tot.H
	Transp < image_tot.H  reshape=2,4,5 plane=13 >m.H
	<m.H Reverse which=2 >x.H core=1
	< x.H OFF2ANG >$@


LAB3=label1="Depth(m)" label2="X Position(m)" label3="Angle(degrees)" title=" "
angle.v3 angle.v: gmage.8.H gtot.H gmage.32.H gmage.127.H
	Window3d < gmage.8.H |Transp plane=23 |Grey eout=1 gainpanel=a |Cubeplot center=1 frame3=2  >a1.V ${LAB3}
	Window3d < gmage.8.H |Transp plane=23|Scale >a1.H
	Window3d < gtot.H |Transp plane=23|Scale >a2.H
	Add scale=1,-1 a1.H a2.H >b1.H
	< b1.H Grey eout=1 gainpanel=a clip=.42 |Cubeplot center=1 frame3=2  >a2.V  ${LAB3}
	< b1.H Grey eout=1 gainpanel=a clip=.042 |Cubeplot center=1 frame3=2  >a3.V ${LAB3}
	Window3d < gmage.32.H |Transp plane=23 |Grey eout=1 gainpanel=a |Cubeplot center=1 frame3=2  >b1.V ${LAB3}
	Window3d < gmage.32.H |Transp plane=23|Scale >a1.H
	Window3d < gtot.H |Transp plane=23|Scale >a2.H
	Add scale=1,-1 a1.H a2.H >b1.H
	< b1.H Grey eout=1 gainpanel=a clip=.42 |Cubeplot center=1 frame3=2  >b2.V  ${LAB3}
	< b1.H Grey eout=1 gainpanel=a clip=.042 |Cubeplot center=1 frame3=2  >b3.V ${LAB3}
	Window3d < gmage.128.H |Transp plane=23 |Grey eout=1 gainpanel=a |Cubeplot center=1 frame3=2  >c1.V ${LAB3}
	Window3d < gmage.128.H |Transp plane=23|Scale >a1.H
	Window3d < gtot.H |Transp plane=23|Scale >a2.H
	Add scale=1,-1 a1.H a2.H >b1.H
	< b1.H Grey eout=1 gainpanel=a clip=.42 |Cubeplot center=1 frame3=2  >c2.V  ${LAB3}
	< b1.H Grey eout=1 gainpanel=a clip=.042 |Cubeplot center=1 frame3=2  >c3.V ${LAB3}
	Vppen gridnum a1.V a2.V a3.V b1.V b2.V b3.V c1.V c2.V c3.V out=angle.v3  >c.V vpstyle=n
	Vppen gridnum a1.V a2.V a3.V b1.V b2.V b3.V c1.V c2.V c3.V out=angle.v gridnum=3,3  >c.V vpstyle=n 

ang.v3 ang.v: nmage.256.H gtot.H nmage.1024.H nmage.2048.H
	Window3d < nmage.256.H |Transp plane=23 |Grey eout=1 gainpanel=a |Cubeplot center=1 frame3=2  >a1.V ${LAB3}
	Window3d < nmage.256.H |Transp plane=23|Scale >a1.H
	Window3d < gtot.H |Transp plane=23|Scale >a2.H
	Add scale=1,-1 a1.H a2.H >b1.H
	< b1.H Grey eout=1 gainpanel=a clip=.42 |Cubeplot center=1 frame3=2  >a2.V  ${LAB3}
	< b1.H Grey eout=1 gainpanel=a clip=.042 |Cubeplot center=1 frame3=2  >a3.V ${LAB3}
	Window3d < nmage.1024.H |Transp plane=23 |Grey eout=1 gainpanel=a |Cubeplot center=1 frame3=2  >b1.V ${LAB3}
	Window3d < nmage.1024.H |Transp plane=23|Scale >a1.H
	Window3d < gtot.H |Transp plane=23|Scale >a2.H
	Add scale=1,-1 a1.H a2.H >b1.H
	< b1.H Grey eout=1 gainpanel=a clip=.42 |Cubeplot center=1 frame3=2  >b2.V  ${LAB3}
	< b1.H Grey eout=1 gainpanel=a clip=.042 |Cubeplot center=1 frame3=2  >b3.V ${LAB3}
	Window3d < nmage.2048.H |Transp plane=23 |Grey eout=1 gainpanel=a |Cubeplot center=1 frame3=2  >c1.V ${LAB3}
	Window3d < nmage.2048.H |Transp plane=23|Scale >a1.H
	Window3d < gtot.H |Transp plane=23|Scale >a2.H
	Add scale=1,-1 a1.H a2.H >b1.H
	< b1.H Grey eout=1 gainpanel=a clip=.42 |Cubeplot center=1 frame3=2  >c2.V  ${LAB3}
	< b1.H Grey eout=1 gainpanel=a clip=.042 |Cubeplot center=1 frame3=2  >c3.V ${LAB3}
	Vppen gridnum a1.V a2.V a3.V b1.V b2.V b3.V c1.V c2.V c3.V out=ang.v3  >c.V vpstyle=n
	Vppen gridnum a1.V a2.V a3.V b1.V b2.V b3.V c1.V c2.V c3.V out=ang.v gridnum=3,3  >c.V vpstyle=n 




gmage.%.v3 gmage.%.v: gmage.%.H gtot.H
	Window3d < gmage.$*.H |Transp plane=23 |Grey eout=1 gainpanel=a |Cubeplot center=1 frame3=2  >a1.V
	Window3d < gmage.$*.H |Transp plane=23|Scale >a1.H
	Window3d < gtot.H |Transp plane=23|Scale >a2.H
	Add scale=1,-1 a1.H a2.H >b1.H
	< b1.H Grey eout=1 gainpanel=a clip=.38 |Cubeplot center=1 frame3=2  >a2.V
	< b1.H Grey eout=1 gainpanel=a clip=.038 |Cubeplot center=1 frame3=2  >a3.V
	Vppen gridnum a1.V a2.V a3.V out=gmage.$*.v3  >c.V vpstyle=n
	Vppen gridnum a1.V a2.V a3.V out=gmage.$*.v gridnum=3,1  >c.V vpstyle=n
	

image_tot.H: marm.bfreq.H  ${BINDIR}/S_G_wem.x sref.H scale.x
	${BINDIR}/S_G_wem.x Data=marm.bfreq.H S=marmvel.H ref_slow=sref.H az__o=0 az__d=12 az__n=251 verb=y nw_tot=35 nzb=50 R=$@    nzb=1 npad_x=0 maxang=60. npad_mx=12 az__n=251 npad_hx=10

try.H:  input_cam_test.H S_G_wem.x new_vel.H
	Window3d < new_vel.H >vel.H j3=5 j2=4 j1=4 n3=200
	Lloyd_vel < vel.H >sref.H
#	${BINDIR}/S_G_wem.x Data=input_cam_test.H S=vel.H ref_slow=sref.H az__o=0 az__d=25 az__n=200 verb=y nw_tot=104 nzb=1 R=a1.H  npad_x=0 maxang=60. npad_mx=12  npad_hx=10 nzb=20
	${BINDIR}/S_G_wem.x Data=input_cam_test.H S=vel.H ref_slow=sref.H az__o=0 az__d=25 az__n=200 verb=y nw_tot=104 nzb=1 R=a2.H  npad_x=0 maxang=60. npad_mx=12  npad_hx=10 nzb=20 wem_type=CAM


	

mmage.%.H:  marm.freq.H ${BINDIR}/S_G_wem_scale.x sref.H scale.x
	${BINDIR}/scale.x < marm.freq.H >a.H mx=$*
	${BINDIR}/S_G_wem_scale.x Data=a.H S=marmvel.H ref_slow=sref.H az__o=0 az__d=12 az__n=251 verb=y nw_tot=35 nzb=50 R=$@    nzb=1 npad_x=0 maxang=60. npad_mx=12 az__n=251 npad_hx=10 sfact=1.

pmage.%.H:  marm.bfreq.H ${BINDIR}/S_G_wem_scale.x sref.H scale.x
	${BINDIR}/scale.x < marm.bfreq.H >a.H mx=$*
	${BINDIR}/S_G_wem_scale.x Data=a.H S=marmvel.H ref_slow=sref.H az__o=0 az__d=12 az__n=251 verb=y nw_tot=35 nzb=50 R=$@    nzb=1 npad_x=0 maxang=60. npad_mx=12 az__n=251 npad_hx=10 sfact=10.

fmage.%.H:  marm.bfreq.H ${BINDIR}/S_G_wem_scale.x sref.H scale.x
	${BINDIR}/scale.x < marm.bfreq.H >a.H mx=$*
	${BINDIR}/S_G_wem_scale.x Data=a.H S=marmvel.H ref_slow=sref.H az__o=0 az__d=12 az__n=251 verb=y nw_tot=35 nzb=50 R=$@    nzb=1 npad_x=0 maxang=60. npad_mx=12 az__n=251 npad_hx=10

mzero.%.H: mmage.%.H
	Window3d < mmage.$*.H  min3=0 |Transp>$@

pzero.%.H: pmage.%.H
	Window3d < pmage.$*.H  min3=0 |Transp>$@

fzero.%.H: fmage.%.H
	Window3d < fmage.$*.H  min3=0 |Transp>$@

cor.H: image_tot.H
	Window3d < image_tot.H min3=0 n3=1 |Transp >$@

LABS=label1="Depth(m)" label2="X Position(m)" title=" "
fzero.%.v3 fzero.%.v: fzero.%.H cor.H
	Grey < fzero.$*.H  >a1.V ${LABS}
	Scale < fzero.$*.H >a2.H
	Scale < cor.H >a3.H
	Add scale=1,-1 a2.H a3.H |Grey ${LABS} >a2.V clip=.38
	Add scale=1,-1 a2.H a3.H |Grey ${LABS} >a3.V clip=.038
	Vppen gridnum=3,1 a1.V a2.V a3.V out=fzero.$*.v vpstyle=n
	Vppen  a1.V a2.V a3.V out=fzero.$*.v3 vpstyle=n

bitinput.v bitinput.v3: fzero.4.H fzero.16.H fzero.64.H cor.H
	Grey < fzero.4.H  >a1.V ${LABS}
	Scale < fzero.4.H >a2.H
	Scale < cor.H >a3.H
	Add scale=1,-1 a2.H a3.H |Grey ${LABS} >a2.V clip=.38
	Add scale=1,-1 a2.H a3.H |Grey ${LABS} >a3.V clip=.038
	Grey < fzero.16.H  >b1.V ${LABS}
	Scale < fzero.16.H >a2.H
	Scale < cor.H >a3.H
	Add scale=1,-1 a2.H a3.H |Grey ${LABS} >b2.V clip=.38
	Add scale=1,-1 a2.H a3.H |Grey ${LABS} >b3.V clip=.038
	Grey < fzero.64.H  >c1.V ${LABS}
	Scale < fzero.64.H >a2.H
	Scale < cor.H >a3.H
	Add scale=1,-1 a2.H a3.H |Grey ${LABS} >c2.V clip=.38
	Add scale=1,-1 a2.H a3.H |Grey ${LABS} >c3.V clip=.038
	Vppen gridnum=3,3 a1.V a2.V a3.V b1.V b2.V b3.V c1.V c2.V c3.V out=bitinput.v vpstyle=n
	Vppen  a1.V a2.V a3.V b1.V b2.V b3.V c1.V c2.V c3.V out=bitinput.v3 vpstyle=n


pzero.%.v3 pzero.%.v: pzero.%.H cor.H
	Grey < pzero.$*.H  >a1.V ${LABS}
	Scale < pzero.$*.H >a2.H
	Scale < cor.H >a3.H
	Add scale=1,-1 a2.H a3.H |Grey ${LABS} >a2.V clip=.38
	Add scale=1,-1 a2.H a3.H |Grey ${LABS} >a3.V clip=.038
	Vppen gridnum=3,1 a1.V a2.V a3.V out=pzero.$*.v vpstyle=n
	Vppen  a1.V a2.V a3.V out=pzero.$*.v3 vpstyle=n

mzero.%.v3 mzero.%.v: mzero.%.H cor.H
	Grey < mzero.$*.H  >a1.V ${LABS}
	Scale < mzero.$*.H >a2.H
	Scale < cor.H >a3.H
	Add scale=1,-1 a2.H a3.H |Grey ${LABS} >a2.V clip=.38
	Add scale=1,-1 a2.H a3.H |Grey ${LABS} >a3.V clip=.038
	Vppen gridnum=3,1 a1.V a2.V a3.V out=mzero.$*.v vpstyle=n yscale=3
	Vppen  a1.V a2.V a3.V out=mzero.$*.v3 vpstyle=n

ints.v3 ints.v: mzero.32.H cor.H mzero.128.H mzero.256.H
	Grey < mzero.32.H  >a1.V ${LABS}
	Scale < mzero.32.H >a2.H
	Scale < cor.H >a3.H
	Add scale=1,-1 a2.H a3.H |Grey ${LABS} >a2.V clip=.38
	Add scale=1,-1 a2.H a3.H |Grey ${LABS} >a3.V clip=.038
	Grey < mzero.128.H  >b1.V ${LABS}
	Scale < mzero.128.H >a2.H
	Scale < cor.H >a3.H
	Add scale=1,-1 a2.H a3.H |Grey ${LABS} >b2.V clip=.38
	Add scale=1,-1 a2.H a3.H |Grey ${LABS} >b3.V clip=.038
	Grey < mzero.256.H  >c1.V ${LABS}
	Scale < mzero.256.H >a2.H
	Scale < cor.H >a3.H
	Add scale=1,-1 a2.H a3.H |Grey ${LABS} >c2.V clip=.38
	Add scale=1,-1 a2.H a3.H |Grey ${LABS} >c3.V clip=.038
	Vppen gridnum=3,3 a1.V a2.V a3.V b1.V b2.V b3.V c1.V c2.V c3.V >a.V out=ints.v vpstyle=n 
	Vppen  a1.V a2.V a3.V b1.V b2.V b3.V c1.V c2.V c3.V >a.V out=ints.v3 vpstyle=n 




imageit.%.H:  marm.freq.H ${BINDIR}/S_G_wem_scale.x sref.H scale.x
	Lloyd_vel < vel.H >a.H nref=$*.
	${BINDIR}/S_G_wem.x Data=marm.freq.H S=vel.H ref_slow=a.H  az__o=0 az__d=12 az__n=251 verb=y nw_tot=35 nzb=50 R=$@    nzb=1 npad_x=0 maxang=60 npad_x=12


image.%.H:  marm.freq.H ${BINDIR}/S_G_wem_scale.x sref.H scale.x
	${BINDIR}/scale.x < marm.freq.H >a.H mx=$*
	${BINDIR}/S_G_wem_scale.x Data=a.H S=vel.H ref_slow=sref.H az__o=0 az__d=12 az__n=251 verb=y nw_tot=35 nzb=50 R=$@    nzb=1 npad_x=0 maxang=60 npad_x=12 sfact=$*
#
image.H:  marm.freq.H ${BINDIR}/S_G_wem.x sref.H
	${BINDIR}/S_G_wem.x Data=marm.freq.H S=marmvel.H ref_slow=sref.H az__o=0 az__d=12 az__n=25 verb=y nw_tot=35 nzb=50 R=$@    nzb=1  az__n=251
#	${BINDIR}/S_G_wem.x Data=a.H S=vel.H ref_slow=sref.H az__o=0 az__d=12 az__n=251 verb=y nw_tot=35 nzb=50 R=image.small.H    nzb=1 npad_x=0 maxang=60 npad_x=12

img.H:   ${BINDIR}/S_G_wem.x
	Spike n2=512 o2=2500 d2=12.5  o1=0 d1=.008 n1=512 >t.H k1=300 k2=256
	Transf < t.H is2d=y >freq.H f_min=3 f_max=25
	Spike n1=700 o1=0 d1=12.5 d3=12 o3=0 n3=251 mag=2000 >v.H
	Lloyd_vel < v.H >ref.H
	${BINDIR}/S_G_wem.x Data=freq.H S=v.H ref_slow=ref.H az__o=0 az__d=12 az__n=251 verb=y nw_tot=35 nzb=50 R=i.H    nzb=1 npad_x=16
	Window3d < i.H |Transp >$@

sref.datum.H: vel_datum_10.H
	Cp vel_datum_10.H vel.datum.H
	Lloyd_vel < vel.datum.H >$@

input.H:
	Transf <input_infill_cmps_sub4_zoffs_w.H >a.H wei=y
	Transf < a.H >$@ f_min=3 f_max=55
	Cp input_infill_cmps_sub4_zoffs_w.H $@
	



datum.H:  marm.freq.H ${BINDIR}/S_G_datum.x sref.datum.H input.H
#	${BINDIR}/S_G_datum.x Data=input_cmps_zoffs_w.H S=vel.datum.H ref_slow=sref.datum.H az__o=0 az__d=50 az__n=10 verb=y nw_tot=35 nzb=50 Ddown=$@    nzb=1 
	${BINDIR}/S_G_datum.x Data=input.H S=vel.datum.H ref_slow=sref.datum.H az__o=0 az__d=50 az__n=10 verb=y nw_tot=35 nzb=50 Ddown=$@    nzb=1  npad_x=12

sref.3d.H: elfvel.H
	Window3d < elfvel.H  >vel.3d.H
	Lloyd_vel < vel.3d.H  >$@ nref=5

image.3d.H:  elf.freq.H ${BINDIR}/S_G_wem.x sref.3d.H
	${BINDIR}/S_G_wem.x Data=elf.freq.H S=vel.3d.H ref_slow=sref.3d.H az__o=0 az__d=30 az__n=2 verb=y nw_tot=35 nzb=1 R=$@   npad_x=16

image2.H:  marm.freq.H /net/koko/homes/sep/bob/Src/old_wei/wei_sg/Phase.x sref.H
	/net/koko/homes/sep/bob/Src/old_wei/wei_sg/Phase.x D=marm.freq.H S=vel.H schoice=sref.H az__o=0 az__d=30 az__n=10 verb=y nw_tot=35 R=$@ adj=y \
amx_n=512        amx_o=2100       amx_d=12.5        label1=\
amy_n=1          amy_o=0          amy_d=1           label2=\
ahx_n=1         ahx_o=0       ahx_d=1.          label3=\
ahy_n=1          ahy_o=0          ahy_d=1           label4=\
aw__n=73         aw__o=1.72414    aw__d=0.344828    label5=Frequency\
velocity=y

PATCH= nwind1=30 nwind2=30 npatch1=15 npatch2=30
patch.full.H: 
	Window3d  < image.full.H n3=1 |Transp |Scale>full.H
	Patch < full.H >$@  ${PATCH}

patch.full2.H: 
	Window3d  < imageit.8.H n3=1 |Transp |Scale>full2.H
	Patch < full2.H >$@  ${PATCH}

patch.8vel.H: imageit.8.H 
	Window3d  < imageit.$*.H n3=1 |Transp |Scale>aa.H
	Patch < aa.H >$@ ${PATCH}


LAB=title=" " label1="Depth(m)" label2="X Position(m)"
${RESDIR}/base.v:  pef.vel.8.H 
	Window3d < imageit.8.H n3=1 |Transp |Grey ${LAB} >a.V 
	Grey < pef.vel.8.H ${LAB} llpos=y >b.V clip=.03
	Vppen vpstyle=n a.V b.V >x.V out=$@ gridnum=2,1
	
${RESDIR}/different.v:  pef.vel.wave.H 
	Window3d < imageit.wave.H n3=1 |Transp |Grey ${LAB} >a.V 
	Grey < pef.vel.wave.H ${LAB} llpos=y >b.V clip=.03
	Vppen vpstyle=n a.V b.V >x.V out=$@ gridnum=2,1
	
${RESDIR}/onevel.v:  pef.vel.1.H 
	Window3d < imageit.1.H n3=1 |Transp |Grey ${LAB} >a.V 
	Grey < pef.vel.1.H ${LAB} llpos=y >b.V clip=.03
	Vppen vpstyle=n a.V b.V >x.V out=$@ gridnum=2,1

${RESDIR}/error.onevel.v: com.vel.1.H
	Grey <  com.vel.1.H out=$@ >a.V ${LAB} allpos=y pclip=100
	

PATCH= nwind1=25 nwind2=25 npatch1=25 npatch2=40
error3.%.H: char.x imageit.%.H patch.full2.H
	Window3d  < imageit.8.H n3=1 |Transp |Scale>bb1.H
	Patch < bb1.H >x1.H ${PATCH}
	Window3d  < imageit.$*.H n3=1 |Transp |Scale>aa1.H
	Patch < aa1.H >pat1.H ${PATCH}
#	./char.x < pat1.H  full=x1.H  >x11.H diff=x21.H a1=10 a2=4
	Patch < x11.H >$@ nout1=251 nout2=574 inv=1
	Patch < x21.H > diff21.$*.H nout1=251 nout2=574 inv=1
	Math file1=diff21.$*.H >a21.H exp="@ABS(file1)"
	Math file1=error3.$*.H >a11.H exp="@ABS(file1)"
	Smooth < a11.H >b11.H rect1=2 rect2=2
	Smooth < a21.H >b21.H rect1=2 rect2=2
	Window3d < imageit.8.H n3=1|Transp |Envelope  tc1=20 tc2=20 >s1.H
#	Math file1=b1.H file2=b2.H exp="@ABS((file1/file2-1.))" >com3a.$*.H file3=s1.H
	Math file1=b11.H file2=b21.H exp="@ABS(file3*(file1/file2-1.))" >gam1.H file3=s1.H
	Math file1=b11.H file2=b21.H exp="@ABS((file1/file2-1.))" >gam2.H file3=s1.H
	Math file1=a11.H file2=a21.H exp="@ABS(file3*(file1/(file2+0.01)))"  file3=s1.H |Smooth rect1=2 rect1=2 >gam3.H
	Math file1=a11.H file2=a21.H exp="@ABS((file1/(file2+0.01)))"  file3=s1.H |Smooth rect1=2 rect2=2 >gam4.$*.H
	Stack < com3.$*.H |Transp |Stack |Disfil


${RESDIR}/p.graph.v: com.bits.2.H com.bits.4.H com.bits.8.H com.bits.16.H com.bits.32.H com.bits.64.H com.bits.128.H com.bits.256.H com.bits.512.H \
       error2.2.H error2.4.H error2.8.H error2.16.H error2.32.H error2.64.H error2.128.H error2.256.H error2.512.H
	Cat com.bits.2.H com.bits.4.H com.bits.8.H com.bits.16.H com.bits.32.H com.bits.64.H com.bits.128.H com.bits.256.H com.bits.512.H axis=3 > cc.H
	Cat error2.2.H error2.4.H error2.8.H error2.16.H error2.32.H error2.64.H error2.128.H error2.256.H error2.512.H axis=3 > dd.H
	Math file1=dd.H exp="@ABS(file1)" >ee.H
	Stack < cc.H |Transp |Stack |Scale >c2.H
	Stack < ee.H |Transp |Stack |Scale >d2.H
	Cat  c2.H  d2.H axis=2|Graph o1=3 d1=1 label1="Bits"  label2="Error" legend=1 >a.V out=$@ legendloc=tr curvelabel="PEF:Histo" dash=0,1

${RESDIR}/v.graph.v: com.vel.1.H com.vel.2.H com.vel.3.H com.vel.4.H com.vel.5.H com.vel.6.H com.vel.7.H\
       histo.vel.1.H histo.vel.2.H histo.vel.3.H histo.vel.4.H histo.vel.5.H histo.vel.6.H histo.vel.7.H
	Cat  com.vel.1.H com.vel.2.H com.vel.3.H com.vel.4.H com.vel.5.H com.vel.6.H com.vel.7.H >cc.H
	Cat histo.vel.1.H histo.vel.2.H histo.vel.3.H histo.vel.4.H histo.vel.5.H histo.vel.6.H histo.vel.7.H  >dd.H
	Math file1=dd.H exp="@ABS(file1)" >ee.H
	Stack < cc.H |Transp |Stack |Scale >c2.H
	Stack < ee.H |Transp |Stack |Scale >d2.H
	Cat  c2.H  d2.H axis=2|Graph o1=1 d1=1 label1="Refernce velocities"  label2="Error" legend=1 >a.V out=$@ legendloc=tr curvelabel="PEF:Histo" dash=0,1

${RESDIR}/big.v.v: com.vel.1.H com.vel.3.H com.vel.7.H histo.vel.1.H histo.vel.3.H histo.vel.7.H
	Cat imageit.1.H imageit.3.H imageit.3.H axis=6 |Window3d n3=1 |Transp >a.H
	Window3d < a.H  f3=0 n3=1|Grey ${LAB} >a1.V
	Window3d < a.H  f3=1 n3=1|Grey ${LAB} >a2.V
	Window3d < a.H  f3=2 n3=1|Grey ${LAB} >a3.V
	Grey < com.vel.1.H  ${LAB3} clip=.001 >b1.V
	Grey < com.vel.3.H  ${LAB3} clip=.001 >b2.V
	Grey < com.vel.7.H  ${LAB3} clip=.001 >b3.V
	Envelope < histo.vel.1.H tc1=5 tc2=5   |Grey ${LAB3} >c1.V clip=30000
	Envelope < histo.vel.3.H tc1=5 tc2=5|Grey ${LAB3}  >c2.V clip=30000
	Envelope < histo.vel.7.H tc1=5 tc2=5 |Grey  ${LAB3} >c3.V clip=30000
	Vppen vpstyle=n a1.V b1.V c1.V a2.V b2.V c2.V a3.V b3.V c3.V gridnum=3,3 >x.V  out=$@


${RESDIR}/big.p.v: com.bits.2.H com.bits.8.H com.bits.512.H com.bits.2.H com.bits.8.H com.bits.512.H error2.2.H error2.8.H error2.512.H
	Cat image.2.H image.8.H image.512.H axis=6 |Window3d n3=1 |Transp >a.H
	Window3d < a.H  f3=0 n3=1|Grey ${LAB} >a1.V
	Window3d < a.H  f3=1 n3=1|Grey ${LAB} >a2.V
	Window3d < a.H  f3=2 n3=1|Grey ${LAB} >a3.V
	Grey < com.bits.2.H  ${LAB3} clip=.4 >b1.V
	Grey < com.bits.8.H  ${LAB3} clip=.4 >b2.V
	Grey < com.bits.512.H  ${LAB3} clip=.4 >b3.V
	Envelope < error2.2.H tc1=5 tc2=5   |Grey ${LAB3} >c1.V clip=38
	Envelope < error2.8.H tc1=5 tc2=5|Grey ${LAB3}  >c2.V clip=38
	Envelope < error2.512.H tc1=5 tc2=5 |Grey  ${LAB3} >c3.V clip=38
	Vppen vpstyle=n a1.V b1.V c1.V a2.V b2.V c2.V a3.V b3.V c3.V gridnum=3,3 >x.V  out=$@


error2.%.H:  image.%.H full.H histo.x
	Window3d < image.$*.H  min3=0  n3=1 |Transp >i.H
	${BINDIR}/histo.x < full.H >$@ other=i.H
	
histo.vel.%.H:  imageit.%.H imageit.8.H histo.x
	Window3d < imageit.8.H  min3=0  n3=1 |Transp >c.H
	Window3d < imageit.$*.H  min3=0  n3=1 |Transp >i.H
	${BINDIR}/histo.x < c.H >$@ other=i.H
	

error.histo.H:  notiltsame.H tilt.H full.H histo.x
	${BINDIR}/histo.x < tilt.H >$@ other=notiltsame.H
	
imageit.wave.H: do_shift.x imageit.8.H
	Window3d < imageit.8.H n3=1 |Transp >x.H
	Interp < x.H >y.H o1out=0 d1out=2 n1out=1501
	./do_shift.x < y.H >z.H
	Window3d < z.H j1=8 |Transp plane=12 |Transp plane=25 >$@
	

PATCH2= nwind1=30 nwind2=30 npatch1=18 npatch2=25 nwind3=30 npatch3=18
PATCH3= nwind1=30 nwind2=30 npatch1=18 npatch2=25 nwind3=30 npatch3=18
pef.error2 error.pef2.H: ${BINDIR}/char2.x  notiltsame.H tilt.H
#	Patch < tilt.H >a1.H ${PATCH2}
#	Patch < notiltsame.H >a2.H ${PATCH2}
	./char2.x < a1.H  full=a2.H  >x1.H diff=x2.H a1=8 a2=2 a3=2
	Patch < x1.H >error.pef2.H nout1=400 nout2=521 nout3=326 inv=1
	Patch < x2.H > diff.pef.H nout1=400 nout2=521 nout3=326 inv=1
	Math file1=diff.pef.H >a2.H exp="@ABS(file1)"
	Math file1=error.pef.H >a1.H exp="@ABS(file1)"
	Smooth < a1.H >b1.H rect1=4 rect2=4 rect3=4
	Smooth < a2.H >b2.H rect1=4 rect2=4 rect3=4
	Envelope < tilt.H  tc1=20 tc2=20  |Smooth rect3=3 >s.H
	Math file1=b1.H file2=b2.H exp="@ABS(file3*(file1/file2-1.))" >compare.H file3=s.H
#	Math file1=b1.H file2=b2.H exp="@ABS((file1/file2-1.))" >compare.H file3=s.H
#	Stack < compare.H |Transp |Stack |Disfil
	Scale < compare.H >compare3.H 


tilt.patch.H: tilt.H
	Patch < tilt.H >$@ ${PATCH2}

notilt.patch.H: notilt.H
	Patch < notiltsame.H >$@  ${PATCH2}

notilt.patch.2.H: notilt.patch.H
	Window3d <  notilt.patch.H f6=9 >$@

notilt.patch.1.H: notilt.patch.H
	Window3d <  notilt.patch.H n6=9 >$@

tilt.patch.2.H: tilt.patch.H
	Window3d <  tilt.patch.H f6=9 >$@

tilt.patch.1.H: tilt.patch.H
	Window3d <  tilt.patch.H n6=9 >$@

tilt.pef.%.H: tilt.patch.%.H notilt.patch.%.H ${BINDIR}/char2.x
	./char2.x < tilt.patch.$*.H  full=notilt.patch.$*.H  >$@ diff=dif.big.$*.H a1=10 a2=4 a3=4 
	

error.pef.H: tilt.pef.1.H tilt.pef.2.H
	Cat3d tilt.pef.1.H tilt.pef.2.H >x.H axis=6
	Cat3d dif.big.1.H dif.big.2.H > y.H axis=6
	Patch < x.H nout1=400 nout2=521 nout3=326 inv=1 >$@
	Patch < y.H nout1=400 nout2=521 nout3=326 inv=1 >diff.pef.H

env.tilt.H: tilt.H
	Envelope < tilt.H >$@ tc1=5 tc2=5

pef.error.H: error.pef.H env.tilt.H
	Math file1=diff.pef.H  exp="@ABS(file1)"  >a1.H
	Math file1=error.pef.H exp="@ABS(file1)"  >a2.H
	Smooth < a1.H >b1.H rect1=4 rect2=4 rect3=4
	Smooth < a2.H >b2.H rect1=4 rect2=4 rect3=4
#	Smooth < error.pef.H >x1.H rect1=3 rect2=3 rect3=3
#	Smooth < diff.pef.H >x2.H rect1=3 rect2=3 rect3=3
	Math file1=b1.H file2=b2.H exp="@ABS((file1-file2))" file3=env.tilt.H|Smooth rect1=4 rect2=4 >c1.H
	Math file1=b1.H file2=b2.H exp="file3*@ABS(file1/file2-1.)" file3=env.tilt.H|Smooth rect1=2 rect2=2 rect3=2 >c2.H
	Math file1=b1.H file2=b2.H exp="@ABS(((file2/file1))-1.)" file3=env.tilt.H|Smooth rect1=2 rect2=2 rect3=2 >c3.H
#	Math file1=x1.H file2=x2.H exp="@ABS((file2/file1))" file3=env.tilt.H|Smooth rect1=4 rect2=4 >c4.H

FR=frame2=298 frame3=126
a.V:#pef.error.H
	Grey  < c1.H  pclip=94 eout=1 gainpanel=a allpos=y |Cubeplot >1.V ${FR} frame1=120
	Grey  < c2.H  pclip=94 eout=1 gainpanel=a allpos=y |Cubeplot >2.V ${FR} frame1=120
	Transp  < c1.H plane=13 |Grey pclip=94 eout=1 gainpanel=e allpos=y |Transp plane=13| Cubeplot >3.V ${FR} frame1=120
	Transp  < c2.H plane=13 |Grey pclip=94 eout=1 gainpanel=e allpos=y |Transp plane=13|Cubeplot >4.V ${FR} frame1=120
	Vppen vpstyle=n 1.V 2.V 3.V 4.V >$@
	Tube pixmaps=y a.V



patch.vel.%.H: imageit.%.H
	Window3d  < imageit.$*.H n3=1 |Transp |Scale>aa.H
	Patch < aa.H >$@ ${PATCH}

patch.bits.%.H: image.%.H
	Window3d  < image.$*.H n3=1 |Transp |Scale>aa.H
	Patch < aa.H >$@ ${PATCH}

patch.full.H: imageit.8.H
	Window3d  < imageit.8.H n3=1 |Transp |Scale>aa.H
	Patch < aa.H >$@ ${PATCH}

pef.vel.%.H: patch.full.H patch.vel.%.H char.x
	./char.x < patch.vel.$*.H full=patch.full.H  >zx1.H diff=zx2.H a1=10 a2=4
	Patch < zx1.H >$@ nout1=251 nout2=574 inv=1
	Patch < zx2.H > diffv.$*.H nout1=251 nout2=574 inv=1;


pef.bits.%.H: patch.full.H patch.bits.%.H char.x
	./char.x < patch.bits.$*.H full=patch.full.H  >zx1.H diff=zx2.H a1=10 a2=4
	Patch < zx1.H >$@ nout1=251 nout2=574 inv=1
	Patch < zx2.H > diffz.$*.H nout1=251 nout2=574 inv=1


amp.env.H: imageit.8.H
	Window3d  < imageit.8.H n3=1 |Transp |Scale>aa.H
	Envelope < aa.H >$@ tc1=5 tc2=5

com.vel.%.H: pef.vel.%.H amp.env.H
	Math file1=pef.vel.$*.H   exp="@ABS(file1)" |Smooth rect1=2 rect2=2 >a1.H
	Math file1=diffv.$*.H   exp="@ABS(file1)"   |Smooth rect1=2 rect2=2 >a2.H
#	Math file1=a1.H file2=a2.H exp="@ABS(file3*(file1/file2)-1.)" file3=amp.env.H|Smooth rect1=4 rect2=4 >$@
	Math file1=a1.H file2=a2.H exp="@ABS(file3*(file1-file2))" file3=amp.env.H|Smooth rect1=4 rect2=4 >$@


com.bits.%.H: pef.bits.%.H amp.env.H
	Math file1=pef.bits.$*.H   exp="@ABS(file1)" |Smooth rect1=3 rect2=3 >a1.H
	Math file1=diffz.$*.H   exp="@ABS(file1)"   |Smooth rect1=3 rect2=3 >a2.H
	Math file1=a1.H file2=a2.H exp="@ABS(file3*(file1/file2))" file3=amp.env.H|Smooth rect1=1 rect2=1 >$@



	


error2.%.H:  image.%.H full.H histo.x
	Window3d < image.$*.H  min3=0  n3=1 |Transp >i.H
	${BINDIR}/histo.x < full.H >$@ other=i.H

error4.%.H:  imageit.%.H full.H histo.x
	Window3d < imageit.8.H  min3=0  n3=1 |Transp >full2.H
	Window3d < imageit.$*.H  min3=0  n3=1 |Transp >i.H
	${BINDIR}/histo.x < full2.H >$@ other=i.H
	
histo.H: histo.x imageit.8.H imageit.1.H
	Window3d < imageit.8.H  min3=0  n3=1 |Transp >full2.H
	Window3d < imageit.1.H  min3=0  n3=1 |Transp >i.H
	${BINDIR}/histo.x < full2.H >x.H map=$@ other=i.H

${RESDIR}/cdf.v: histo.H
	Graph < histo.H legendloc=tl legend=1 curvelabel="8 velocities:1 velocities" >x.V out=$@ title=" " label1="Percentile" label2="Amplitude" dash=0,1

${RESDIR}/onevel.diff.v: error4.1.H
	Envelope tc1=5 tc2=5 < error4.1.H|Grey ${LOC} >a.V out=$@ title=" " ${LAB}

cen.%.view:
	< tilt.T Cubeplot center=1 > b.V ${FR} frame1=$*
	< notiltsame.T  Cubeplot center=1 > c.V ${FR} frame1=$*
	< comp.good.T  Cubeplot center=1 frame1=$*  >a.V ${FR}
	Tube pixmaps=y < a.V b.V c.V

tilt.T: tilt.H
	Grey < tilt.H eout=1 gainpanel=a >$@ pclip=97

notiltsame.T: notiltsame.H
	Grey < notiltsame.H eout=1 gainpanel=a >$@ pclip=97

comp.good.T:  comp.good.H
	Grey < comp.good.H eout=1 gainpanel=a >$@

FR2=${FR} label1="Sample" label2="X position(m)" label3="Y Position(m)" title=" " o2=3000 o1=0 d1=1 o3=1790 d2=25 d3=30
${RESDIR}/tilt.v: tilt.T
	Cubeplot < tilt.T ${FR2} frame1=120 >a.V out=$@

${RESDIR}/notiltsame.v: notiltsame.T
	Cubeplot < notiltsame.T ${FR2} frame1=120 >a.V out=$@

${RESDIR}/comp.histo.v: error.histo.H
	Envelope < error.histo.H tc1=4 tc2=5 |Grey eout=1 gainpanel=a allpos=y >error.histo.T
	Cubeplot < error.histo.T ${FR2} frame1=120 >a.V out=$@

${RESDIR}/comp.g.v: comp.good.T
	Cubeplot < comp.good.T ${FR2} frame1=120 >a.V out=$@

${RESDIR}/comp.good.v: comp.good.T
	Cubeplot < comp.good.T ${FR2} frame1=120 >a.V out=$@


include ${SEPINC}/SEP.bottom
