include ${SEPINC}/SEP.top

BINDIR = /net/koko/tang/bin/LINUX
SRCDIR = ./
TESTDIR = /net/koko/tang/Research/WAzi/Dfr
#SEGDIR = /net/koko/tang/Research/WAzi
SEGDIR = /net/koko/tang/Research/SEG_EAGE_salt

LIBDIR=-L/usr/local/SEP6.4.2_INTEL/lib

UF90LIBS  = -lsepocf90 -lsupersetf90 -lsepgeef90 -lsuperset -lsepauxf90 -lsepmathf90 -lsep2df90 -lsep3df90 -lsep3d -lsepf90 -lsep ${LIBDIR} -lsvml
UF90FLAGS = -O3 -axW -static-libcxa -Bstatic


REC = ${TESTDIR}/ww.dfr3d.H
SOU = ${TESTDIR}/ww.dfr3d.source.H
VEL = ${TESTDIR}/dfr3d.vel.H

#SEGREC = ${SEGDIR}/CIGs/ww.data.fb.1.H
#SEGSOU = ${SEGDIR}/CIGs/ww.source.fb.1.H
SEGREC = ${SEGDIR}/ww.segsalt.data.test2.H
SEGSOU = ${SEGDIR}/ww.source.H
SEGHDS = ${SEGDIR}/segsalt.HD_d.H
SEGVEL = ${SEGDIR}/segsalt.vel.mig.H

HESSIAN = /homes/sep/alejandro/research/Src_Hessian/Bin/LINUX/Lt_L_reuse_3D_off_wave_2.x
HESSIAN2 = /homes/sep/alejandro/research/Src_Hessian/Bin/LINUX/Lt_L_old_3D_rela_off_wave_2_omp.x
HESSIAN3 = /homes/sep/alejandro/research/Src_Hessian/Bin/LINUX/Lt_L_old_3D_off_wave_2_omp.x
HESSIAN_OLD = /homes/sep/alejandro/research/Hessian_winter/Bin/LINUX/Lt_L_reorder_3D_off_wave.x
EXE = shotmig11.x

dfr2d.greens.transp.test.H: dfr2d.greens.H
	Transp < $< reshape=2,3,6 plane=23 maxsize=500 > $@

test2.H: dfr2d.greens.transp.test.H ${BINDIR}/hessian.x
	#Window3d < $< n6=10 f6=10 squeeze=n > junk1.$@
	Window3d < ww.dfr2d.sou.H | Window3d > junk2.$@
	${BINDIR}/hessian.x greens=$< wavelet=junk2.$@ hessian=$@ \
        ngx=301 ogx=-1500 dgx=10 nx_offd=5 nz_offd=17 nhx_offd=17 ox_offd=-20 oz_offd=-80 ohx_offd=-80 \
        nhx_modl=65 ohx_modl=-320 null_gxmin=-500 null_gxmax=500

dfr2d.hessian.full.H: dfr2d.greens.transp.test.H ${BINDIR}/hessian.x
	Window3d < ww.dfr2d.sou.H | Window3d > junk2.$@
	${BINDIR}/hessian.x greens=$< wavelet=junk2.$@ hessian=$@ \
	ngx=301 ogx=-1000 dgx=10 nhx_modl=33 ohx_modl=-160\

dfr2d.hessian.full.sub.H: dfr2d.greens.transp.test.H ${BINDIR}/hessian.x
	Window3d < ww.dfr2d.sou.H | Window3d > junk2.$@
	${BINDIR}/hessian.x greens=$< wavelet=junk2.$@ hessian=$@ \
        ngx=301 ogx=-1000 dgx=10 nhx_modl=33 ohx_modl=-160 null_gxmin=-500 null_gxmax=500\

ang.hes.H: t.H ${BINDIR}/hessian_off2ang2d.x
	Transp reshape=4,5,10 maxsize=500 < $< > junk1.$@
	Transp reshape=5,9,10 plane=23 maxsize=500 < junk1.$@ | Window3d > junk2.$@
	${BINDIR}/hessian_off2ang2d.x hessian_off=junk2.$@ hessian_ang=junk3.$@ step=1 #amin=-30 amax=30
	Transp reshape=3,6 maxsize=500< junk3.$@ > junk4.$@
	${BINDIR}/hessian_off2ang2d.x hessian_off=junk4.$@ hessian_ang=$@ step=2 #amin=-30 amax=30


ang.hes.sub.H: test.parallel.sub.H ${BINDIR}/hessian_off2ang2d.x
	Transp reshape=4,5,10 maxsize=500 < $< > junk1.$@
	Transp reshape=5,9,10 plane=23 maxsize=500 < junk1.$@ | Window3d > junk2.$@
	${BINDIR}/hessian_off2ang2d.x hessian_off=junk2.$@ hessian_ang=junk3.$@ step=1 #amin=-30 amax=30
	Transp reshape=3,6 maxsize=500< junk3.$@ > junk4.$@
	${BINDIR}/hessian_off2ang2d.x hessian_off=junk4.$@ hessian_ang=$@ step=2 #amin=-30 amax=30


test.H: dfr2d.greens.transp.test.H ${BINDIR}/hessian.x
	Window3d < $< n6=1 f6=35 squeeze=n > junk1.$@
	Window3d < ww.dfr2d.sou.H | Window3d n1=1 f1=35> junk2.$@
	${BINDIR}/hessian.x greens=junk1.$@ wavelet=junk2.$@ hessian=$@ \
        ngx=201 ogx=-1000 dgx=10 \
        nx_offd=15  ox_offd=-70\
        nz_offd=15  oz_offd=-70\
        nhx_offd=15 ohx_offd=-70\
        nhx_modl=33 ohx_modl=-160\
        xmin_modl=-50 xmax_modl=50 zmin_modl=600 zmax_modl=900\
        #nsx=161 osx=-800 dsx=10\

t.hsou.H t.hrec.H: ${BINDIR}/creat_header.x
	${BINDIR}/creat_header.x hdr_sou=t.hsou.H hdr_rec=t.hrec.H


t.H: dfr2d.greens.transp.test.H ${BINDIR}/hessian.x t.hsou.H t.hrec.H
	Window3d < $<  n6=1 f6=36  squeeze=n > junk1.$@
	Window3d < ww.dfr2d.sou.H | Window3d  n1=1 f1=36 > junk2.$@
	${BINDIR}/hessian.x greens=junk1.$@ hessian=$@ \
        ngx=201 ogx=-1000 dgx=10 \
        nx_offd=1  ox_offd=0\
        nz_offd=1  oz_offd=0\
        nhx_offd=1 ohx_offd=0\
        nhx_modl=33 ohx_modl=-160\
        xmin_modl=-1000 xmax_modl=1000 zmin_modl=0 zmax_modl=990\
        nsx=1 osx=0 dsx=10 offset=n

t.ang.H:
	Transp reshape=4,5,10 maxsize=500 < t.H > junk1.$@
	echo n6=11253 n7=1 n8=1 n9=1 n10=1>> junk1.$@
	OFF2ANG verb=y maxmem=500 amax=60< junk1.$@ > junk2.$@
	echo n6=33 n7=1 n8=11 n10=31 >> junk2.$@
	Transp reshape=5,10 maxsize=500 < junk2.$@ > junk3.$@
	Transp reshape=4,5,10 maxsize=500< junk3.$@ > junk4.$@
	echo n6=3375 n7=1 n8=1 n9=1 n10=1 >> junk4.$@
	OFF2ANG verb=y maxmem=500 amax=60< junk4.$@ > $@
	echo n6=15 n7=15 n8=1 n9=15 >> $@
	Rm junk*.$@

test.parallel.H: dfr2d.greens.transp.test.H 
	Window3d < ww.dfr2d.sou.H | Window3d > junk1.$@
	Parallel command=${BINDIR}/hessian.x \
        files="dfr2d.greens.transp.test.H,junk1.$@,$@" \
        tags="greens,wavelet,hessian" usage="INPUT,INPUT,OUTPUT" \
        axis=6,1,11 nblock=34 \
        file_type="DISTRIBUTE,DISTRIBUTE,COPY" \
        pverb=4 redo=y redo_collect=y mach_mfile=mfile \
        ngx=301 ogx=-1000 dgx=10 \
        nx_offd=15  ox_offd=-70\
        nz_offd=15  oz_offd=-70\
        nhx_offd=15 ohx_offd=-70\
        nhx_modl=33 ohx_modl=-160\
        xmin_modl=-50 xmax_modl=50 zmin_modl=600 zmax_modl=900\
        nsx=51 osx=-1000 dsx=40


test.parallel.sub.H: dfr2d.greens.transp.test.H 
	Window3d < ww.dfr2d.sou.H | Window3d > junk1.$@
	Parallel command=${BINDIR}/hessian.x \
        files="dfr2d.greens.transp.test.H,junk1.$@,$@" \
        tags="greens,wavelet,hessian" usage="INPUT,INPUT,OUTPUT" \
        axis=6,1,11 nblock=34 \
        file_type="DISTRIBUTE,DISTRIBUTE,COPY" \
        pverb=4 redo=y redo_collect=y mach_mfile=mfile \
        ngx=301 ogx=-1000 dgx=10 \
        nx_offd=15  ox_offd=-70\
        nz_offd=15  oz_offd=-70\
        nhx_offd=15 ohx_offd=-70\
        nhx_modl=33 ohx_modl=-160\
        xmin_modl=-50 xmax_modl=50 zmin_modl=600 zmax_modl=900\
        null_gxmin=-500 null_gxmax=500


test.ang.H:
	Transp reshape=4,5,10 maxsize=500 < test.parallel.H > junk1.$@
	echo n6=11253 n7=1 n8=1 n9=1 n10=1>> junk1.$@
	OFF2ANG verb=y maxmem=500 amax=60< junk1.$@ > junk2.$@
	echo n6=33 n7=1 n8=11 n10=31 >> junk2.$@
	Transp reshape=5,10 maxsize=500 < junk2.$@ > junk3.$@
	Transp reshape=4,5,10 maxsize=500< junk3.$@ > junk4.$@
	echo n6=3375 n7=1 n8=1 n9=1 n10=1 >> junk4.$@
	OFF2ANG verb=y maxmem=500 amax=60< junk4.$@ > $@
	echo n6=15 n7=15 n8=1 n9=15 >> $@
	Rm junk*.$@


test.ang.sub.H:
	Transp reshape=4,5,10 maxsize=500 < test.parallel.sub.H > junk1.$@
	echo n6=11253 n7=1 n8=1 n9=1 n10=1>> junk1.$@
	OFF2ANG verb=y maxmem=500 amax=60 < junk1.$@ > junk2.$@
	echo n6=33 n7=1 n8=11 n10=31 >> junk2.$@
	Transp reshape=5,10 maxsize=500 < junk2.$@ > junk3.$@
	Transp reshape=4,5,10 maxsize=500< junk3.$@ > junk4.$@
	echo n6=3375 n7=1 n8=1 n9=1 n10=1 >> junk4.$@
	OFF2ANG verb=y maxmem=500 amax=60 < junk4.$@ > $@
	echo n6=15 n7=15 n8=1 n9=15 >> $@
	Rm junk*.$@



test.ang2.H: test2.H
	Transp reshape=4,5,10 maxsize=500 < test2.H > junk1.$@
	echo n6=1956500 n7=1 n8=1 n9=1 n10=1>> junk1.$@
	OFF2ANG verb=y maxmem=500 < junk1.$@ > junk2.$@
	echo n6=65 n7=1 n8=301 n10=100 >> junk2.$@
	Transp reshape=5,10 maxsize=500 < junk2.$@ > junk3.$@
	Transp reshape=4,5,10 maxsize=500< junk3.$@ > junk4.$@
	echo n6=1445 n7=1 n8=1 n9=1 n10=1 >> junk4.$@
	OFF2ANG verb=y maxmem=500 < junk4.$@ > $@
	echo n6=17 n7=17 n8=1 n9=5 >> $@
	Rm junk*.$@
#====================== 2D ===============================

#   with the full data
ww.dfr2d.rec.H: ${BINDIR}/transf.x ${TESTDIR}/dfr2d.H
	${BINDIR}/transf.x data=${TESTDIR}/dfr2d.H adj=y modl=junk1.$@
	Transp reshape=1,3,5 plane=12 < junk1.$@ > $@
	Rm junk*.$@

ww.dfr2d.sou.H: ${BINDIR}/wei_transf.x ${TESTDIR}/dfr2d.source.H
	${BINDIR}/wei_transf.x < ${TESTDIR}/dfr2d.source.H adj=y > junk1.$@
	Transp reshape=1,3,5 plane=12 < junk1.$@ > $@
	Rm junk*.$@

dfr2d.vel.jpx.0.5.H: ${TESTDIR}/dfr2d.vel.H
	Interp < $< d1out=10 type=0 > $@

dfr2d.mig.H: ${BINDIR}/${EXE} ${TESTDIR}/dfr2d.vel.H ww.dfr2d.sou.H ww.dfr2d.rec.H
	${BINDIR}/${EXE} sou=ww.dfr2d.sou.H rec=ww.dfr2d.rec.H vel=${TESTDIR}/dfr2d.vel.H wfsd=junk1.$@ img=$@ \
        adj=y radian=y taper=y taper_type=1 taper_pct=0.25 nhx=1 jpx=1.

dfr2d.odcig.H: dfr2d.mig.H
	Transp reshape=2,4,5 plane=13 < $< > $@

dfr2d.adcig.H: dfr2d.odcig.H
	NewOFF2ANG.x nzpad=256 < $< > $@

# with subsampled data, middle offsets

ww.dfr2d.rec.sub.H: ${TESTDIR}/dfr2d.sub.H
	${BINDIR}/wei_transf.x < ${TESTDIR}/dfr2d.sub.H adj=y > junk1.$@
	Transp reshape=1,3,5 plane=12 < junk1.$@ > $@
	Rm junk*.$@

dfr2d.mig.sub.H: ${BINDIR}/${EXE} ${TESTDIR}/dfr2d.vel.H ww.dfr2d.sou.H ww.dfr2d.rec.sub.H
	${BINDIR}/${EXE} sou=ww.dfr2d.sou.H rec=ww.dfr2d.rec.sub.H vel=${TESTDIR}/dfr2d.vel.H wfld_d=junk1.$@ img=$@ \
        image_xmin=-1500 image_xmax=1500 adj=y radian=y taper=y taper_type=1 taper_pct=0.15 nhx=1 jpx=1

dfr2d.odcig.sub.H: dfr2d.mig.sub.H
	Transp reshape=2,4,5 plane=13 < $< > $@

dfr2d.adcig.sub.H: dfr2d.odcig.sub.H
	NewOFF2ANG.x nzpad=256 < $< > $@

# compute the Green's function
dfr2d.greens.H: 
	${BINDIR}/greens.x vel=${TESTDIR}/dfr2d.vel.H greens=$@ \
        ow=27.6117 nw=73 dw=3.06796 radian=y upward=y \
        surface_xmin=-1500 surface_xmax=1500 \
        taper=y taper_type=1 taper_pct=0.15 \
        nx_modl=301 ox_modl=-1500. dx_modl=10.\
        ny_modl=1   oy_modl=0.     dy_modl=1.\
        nz_modl=100 oz_modl=0.     dz_modl=10

dfr2d.greens.transp.H: dfr2d.greens.H
	Transp reshape=2,3,6 plane=23 maxsize=500 < $< | Transp reshape=2,5,6 plane=12 maxsize=500 > $@
       
dfr2d.hessian.H: dfr2d.greens.transp.H
	Window3d < ww.dfr2d.sou.H n3=1 f3=36 squeeze=n > junk1.$@
	Window3d < $< n6=1 f6=36 squeeze=n > junk2.$@
	date
	${HESSIAN3} < junk2.$@ wave=junk1.$@ outtag=$@ \
        nax=1 naz=1 nay=1 marine=n jsx=1 jsy=1 jrx=1 jry=1 noffx=15 noffy=1 \
        nrx=1 orx=-800. drx=10. nry=1 nsx=1 nsy=1 osx=800. osy=0. 
	date
# construct the Hessian via migration and demigration
dfr2d.mig.demig.sub.H: dfr2d.mig.sub.H
	${BINDIR}/${EXE} sou=ww.dfr2d.sou.H rec=$@ vel=${TESTDIR}/dfr2d.vel.H wfsd=junk1.$@ img=$< \
        image_xmin=-1500 image_xmax=1500 adj=n radian=y taper=y taper_type=1 taper_pct=0.15 \
        ngx=301 dgx=10. ogx=-1500. nsx=1 osx=0. 

dfr2d.mig.demig.mig.sub.H: dfr2d.mig.demig.sub.H
	${BINDIR}/${EXE} sou=ww.dfr2d.sou.H rec=$< vel=${TESTDIR}/dfr2d.vel.H wfsd=junk1.$@ img=$@ \
        image_xmin=-1500 image_xmax=1500 adj=y radian=y taper=y taper_type=1 taper_pct=0.15 nhx=128 jpx=1

dfr2d.hessian.odcig.approx.H: dfr2d.mig.sub.H dfr2d.mig.demig.mig.sub.H
	Window3d < dfr2d.mig.sub.H | Transp reshape=2,3 | ${BINDIR}/normalize3d.x > junk1.$@
	Window3d < dfr2d.mig.demig.mig.sub.H | Transp reshape=2,3 | ${BINDIR}/normalize3d.x > junk2.$@
	Envelope < junk1.$@ tc1=4 tc2=4 verb=y > junk3.$@
	#${BINDIR}/ref.x < junk1.$@ option=2 k=0.25 > junk3.$@
	Math exp="junk2.$@/(junk3.$@+0.1)" > $@

dfr2d.hessian.adcig.approx.H: dfr2d.hessian.odcig.approx.H
	Transp < $< plane=23 | Transp plane=34 > junk1.$@
	OFF2ANG < junk1.$@ verb=1 > $@
	Rm junk*.$@
   
#======================= 3D ==============================

test.greens.H: ${SOU} ${VEL}
	${BINDIR}/greens.x vel=${VEL} greens=$@ ow=27.6117 nw=10 dw=3.06796 radian=y upward=y\
        surface_xmin=-1000 surface_xmax=1000 surface_ymin=-1000 surface_ymax=1000 nzs=7 nws=7 taper=y taper_type=2 taper_pct=0.1\
        nx_modl=21 ny_modl=21 nz_modl=21 ox_modl=-200. oy_modl=-200. oz_modl=700. dx_modl=20 dy_modl=20 dz_modl=10\
        #nxpad_beg=25 nxpad_end=25 nypad_beg=25 nypad_end=25
test.greens.transp.H: test.greens.H
	Transp reshape=2,3,6 plane=23 maxsize=500 < $< | Transp reshape=2,5,6 plane=12 maxsize=500 > $@

test.hessian.H: test.greens.transp.H
	Window3d < ww.test.sou.H n1=10 | Transp reshape=1,3,5 plane=12   > junk1.$@
	${HESSIAN} < $< wave=junk1.$@ outtag=$@ \
        nax=5 naz=5 nay=5 marine=n jsx=1 jsy=1 jrx=1 jry=1 noffx=1 noffy=1 \
        nry=101 nrx=101 nsy=1 nsx=1



R.H: ${BINDIR}/shotmig7.x ${REC} ${SOU} ${VEL}
	${BINDIR}/shotmig7.x rec=${REC} sou=${SOU} vel=${VEL} img=$@ \
        image_xmin=-1000 image_xmax=1000 image_ymin=-1000 image_ymax=1000 nzs=1 nws=20 \
        true_ampli=n maxang=80. decon=n nref=1 nhx=1 nhy=1 num_report=100\


seg.tang.H:${BINDIR}/shotmig6.x
	Window3d < ${SEGREC} n3=5 squeeze=n > j1.H
	Window3d < ${SEGSOU} n3=5 squeeze=n > j2.H
	${BINDIR}/shotmig6.x rec=${SEGREC} sou=${SEGSOU} vel=${SEGVEL} hdr_sou=${SEGHDS} img=$@ \
        image_xmin=3000. image_xmax=10500. image_ymin=1000. image_ymax=12000. \
        offset=y nzs=1 nws=20


seg.tang.parallel.H: ${BINDIR}/shotmig6.x
	Parallel command=${BINDIR}/shotmig6.x \
        files="${SEGREC},${SEGSOU},${SEGHDS},${SEGVEL},$@,seg.illum.H" \
        tags="rec,sou,hdr_sou,vel,img,normd" usage="INPUT,INPUT,INPUT,INPUT,OUTPUT,OUTPUT" \
        axis=4,3,2,4,6,6 nblock=45  \
        file_type="DISTRIBUTE,COPY,DISTRIBUTE,COPY,COPY,COPY" \
        pverb=4 redo=y redo_collect=y mach_mfile=mfile restart=y\
        image_xmin=3000. image_xmax=10500. image_ymin=1000. image_ymax=12000. \
        offset=y nzs=1 nws=20 nref=3
	echo label1=x label2=y label3=hx label4=hy >> $@ 



R.demig.H: ${BINDIR}/shotmig7.x ${SOU} ${VEL} 
	${BINDIR}/shotmig7.x sou=${SOU} img=R.H vel=${VEL} rec=$@ wfsd=wfld_tmp.H\
        image_xmin=-1000 image_xmax=1000 image_ymin=-1000 image_ymax=1000 \
        adj=n ngx=101 ngy=101 dgx=20. dgy=20. ogx=-1000. ogy=-1000. nsx=1 nsy=1 osx=0. osy=0.\

R.demig.mig.H: ${BINDIR}/shotmig5.x R.demig.H dtw.H V.H
	${BINDIR}/shotmig5.x rec=R.demig.H sou=dtw.H vel=V.H img=$@ test=test_dt.H\
        image_xmin=-1000 image_xmax=1000 image_ymin=-1000 image_ymax=1000

R.demig.time.H: R.demig.H
	Transp plane=23 < $< | Transp plane=12 > junk1.$@
	Pad n1=512 < junk1.$@ > junk2.$@
	Ft3d sign1=-1 < junk2.$@ | Real > $@
dt.time.H: dt.H
	Transp plane=23 < $< | Transp plane=12 > junk1.$@
	Pad n1=512 < junk1.$@ > junk2.$@
	Ft3d sign1=-1 < junk2.$@ | Real > $@

R.brad.H: dt.H dtw.H V.H
	${BINDIR}/ShotMig.x D=dt.H D_d=dtw.H V=V.H R=$@ \
        minx=-500. maxx=500. miny=-500. maxy=500.  taper=n


ww.test.rec.H: ${TESTDIR}/dfr3d.H  ${BINDIR}/wei_transf.x
	${BINDIR}/wei_transf.x < $< adj=y > $@

ww.test.sou.H: ${TESTDIR}/dfr3d.source.H ${BINDIR}/wei_transf.x
	${BINDIR}/wei_transf.x < $< adj=y > $@

test.rec.H: ww.test.rec.H ${BINDIR}/wei_transf.x
	${BINDIR}/wei_transf.x < $< adj=n dt=0.004 nt=512 > $@


dot.fft.dat1.H: ${TESTDIR}/dfr3d.H
	Cp $< $@
	echo esize=4 >> $@
 
dot.fft.mod2.H: ww.test.rec.H
	Cp $< $@

dot.fft: ${BINDIR}/dptest.x ${BINDIR}/wei_transf.x dot.fft.dat1.H dot.fft.mod2.H
	${BINDIR}/wei_transf.x < dot.fft.dat1.H adj=y > dot.fft.mod1.H
	${BINDIR}/wei_transf.x < dot.fft.mod2.H adj=n > dot.fft.dat2.H
	${BINDIR}/dptest.x mod1=dot.fft.mod1.H mod2=dot.fft.mod2.H \
                           dat1=dot.fft.dat1.H dat2=dot.fft.dat2.H
	

dot.fft.cmplx: ${BINDIR}/dptest.x ${BINDIR}/wei_transf_cmplx.x
	Cp ${TESTDIR}/dfr3d.H junk1.$@
	Scale rscale=0. < junk1.$@ > junk2.$@
	Cmplx junk1.$@ junk2.$@ > dot.fft.cmplx.dat1.H
	Cp ww.test.rec.H dot.fft.cmplx.mod2.H
	${BINDIR}/wei_transf_cmplx.x < dot.fft.cmplx.dat1.H adj=y > dot.fft.cmplx.mod1.H
	${BINDIR}/wei_transf_cmplx.x < dot.fft.cmplx.mod2.H adj=n > dot.fft.cmplx.dat2.H
	${BINDIR}/dptest.x mod1=dot.fft.cmplx.mod1.H mod2=dot.fft.cmplx.mod2.H \
                           dat1=dot.fft.cmplx.dat1.H dat2=dot.fft.cmplx.dat2.H

test.mig.H: ww.test.rec.H ww.test.sou.H ${VEL} 
	Transp reshape=1,3 plane=12 < ww.test.rec.H > junk1.$@
	${BINDIR}/${EXE} sou=ww.test.sou.H rec=junk1.$@ vel=${VEL} img=$@ wfld_d=wfld_tmp_mig.H\
        image_xmin=-1000 image_xmax=1000 image_ymin=-1000 image_ymax=1000 nzs=1 nws=1 nhx=1 nhy=1\
        adj=y radian=y taper=y taper_type=2 taper_pct=0.1\

test.mig.demig.H: ${BINDIR}/${EXE} test.mig.H ww.test.sou.H ${VEL}
	Transp plane=13 < ww.test.sou.H > junk1.$@
	echo n1=1 d1=1 o1=0 n2=1 d2=1 o2=0 >> junk1.$@
	${BINDIR}/${EXE} sou=junk1.$@ img=test.mig.H vel=${VEL} rec=$@ wfld_d=wfld_tmp.H\
        image_xmin=-1000 image_xmax=1000 image_ymin=-1000 image_ymax=1000 nzs=1 nws=10 \
        adj=n radian=y ngx=101 ngy=101 dgx=20. dgy=20. ogx=-1000. ogy=-1000. nsx=2 nsy=1 osx=0. dsx=50. osy=0.\

test.mig.demig.time.H: test.mig.demig.H ${BINDIR}/wei_transf.x
	Transp reshape=2,3 plane=12 < $< > junk1.$@
	${BINDIR}/wei_transf.x < junk1.$@ adj=n dt=0.004 nt=512 > $@

test.mig.demig.mig.H: test.mig.demig.time.H ${BINDIR}/wei_transf.x
	${BINDIR}/wei_transf.x < $< adj=y > junk1.$@
	Transp reshape=1,3 plane=12 < junk1.$@ > junk2.$@
	${BINDIR}/${EXE} sou=ww.test.sou.H rec=junk2.$@ vel=${VEL} img=$@ \
        image_xmin=-1000 image_xmax=1000 image_ymin=-1000 image_ymax=1000 nzs=1 nws=1 \
        adj=y radian=y \


dot: ${TESTDIR}/dfr3d.H test.mig.demig.time.H test.mig.H test.mig.demig.mig.H
	dptest.x dat1=${TESTDIR}/dfr3d.H dat2=test.mig.demig.time.H mod1=test.mig.demig.mig.H mod2=test.mig.H

dot.dat1.H dot.mod2.H: ${BINDIR}/syn_dot.x
	${BINDIR}/syn_dot.x dat1=dot.dat1.H mod2=dot.mod2.H


dot.random: dot.dat1.H dot.mod2.H ${BINDIR}/wei_transf.x ${BINDIR}/dptest.x ${BINDIR}/${EXE}
	Transp plane=13 < ww.test.sou.H > junk0.$@
	echo n1=1 d1=1 o1=0 n2=1 d2=1 o2=0 >> junk0.$@
	# migration
	${BINDIR}/wei_transf.x < dot.dat1.H adj=y | Transp reshape=1,3 plane=12 >  junk1.$@
	${BINDIR}/${EXE} sou=junk0.$@ rec=junk1.$@ vel=${VEL} img=junk2.$@ wfsd=wfld.dot.mig.H\
        image_xmin=-1000 image_xmax=1000 image_ymin=-1000 image_ymax=1000 adj=y radian=y nzs=10 nws=5 nhx=5 nhy=5\
        taper=y taper_pct=0.1 taper_type=1 nref=3
	# demigration
	${BINDIR}/${EXE} sou=junk0.$@ vel=${VEL} img=dot.mod2.H rec=junk3.$@ wfsd=wfld.dot.demig.H \
        image_xmin=-1000 image_xmax=1000 image_ymin=-1000 image_ymax=1000 nzs=15 nws=7 \
        adj=n radian=y ngx=101 ngy=101 dgx=20. dgy=20. ogx=-1000. ogy=-1000. nsx=1 nsy=1 osx=0. osy=0.\
	taper=y taper_pct=0.1 taper_type=1 nref=3
	Transp reshape=2,3 plane=12 < junk3.$@ > junk4.$@
	${BINDIR}/wei_transf.x < junk4.$@ adj=n dt=0.004 nt=512 > junk5.$@
	${BINDIR}/dptest.x dat1=dot.dat1.H dat2=junk5.$@ mod1=junk2.$@ mod2=dot.mod2.H

#shotmig.x: 
#	make ${BINDIR}/shotmig.x
#==========================================================================================================

ww.hessian.dfr3d.H: ${TESTDIR}/dfr3d.H ${BINDIR}/wei_transf.x
	${BINDIR}/wei_transf.x < $< adj=y > junk1.$@
	Transp reshape=1,3,5 plane=12 < junk1.$@ >$@
	Rm junk*.$@

ww.hessian.dfr3d.sou.H: ${TESTDIR}/dfr3d.source.H ${BINDIR}/wei_transf.x
	${BINDIR}/wei_transf.x < $< adj=y > junk1.$@
	Transp reshape=1,3,5 plane=12 < junk1.$@ >$@
	Rm junk*.$@

hessian.dfr3d.mig.H: ${BINDIR}/${EXE} ww.hessian.dfr3d.H ww.hessian.dfr3d.sou.H ${VEL}
	${BINDIR}/${EXE} sou=ww.hessian.dfr3d.sou.H rec=ww.hessian.dfr3d.H vel=${VEL} wfsd=junk1.$@ img=$@ \
        image_xmin=-1000 image_xmax=1000 image_ymin=-1000 image_ymax=1000 adj=y radian=y nzs=1 nws=5 nhx=16 nhy=16\
        taper=y taper_pct=0.1 taper_type=1
	Rm junk*.$@

hessian.dfr3d.mig.demig.H: ${BINDIR}/${EXE} hessian.dfr3d.mig.H ww.hessian.dfr3d.sou.H ${VEL}
	${BINDIR}/${EXE} sou=ww.hessian.dfr3d.sou.H vel=${VEL} img=hessian.dfr3d.mig.H wfsd=junk1.$@ rec=$@ \
        image_xmin=-1000 image_xmax=1000 image_ymin=-1000 image_ymax=1000 nzs=1 nws=5 \
        adj=n radian=y ngx=101 ngy=101 dgx=20. dgy=20. ogx=-1000. ogy=-1000. nsx=1 nsy=1 osx=0. osy=0.\
        taper=y taper_pct=0.1 taper_type=1
	Rm junk*.$@

hessian.dfr3d.mig.demig.mig.H: ${BINDIR}/${EXE} hessian.dfr3d.mig.demig.H ww.hessian.dfr3d.sou.H ${VEL}
	${BINDIR}/${EXE} sou=ww.hessian.dfr3d.sou.H rec=hessian.dfr3d.mig.demig.H vel=${VEL} wfsd=junk1.$@ img=$@ \
        image_xmin=-1000 image_xmax=1000 image_ymin=-1000 image_ymax=1000 adj=y radian=y nzs=1 nws=5 nhx=16 nhy=16\
        taper=y taper_pct=0.1 taper_type=1
	Rm junk*.$@

hessian.dfr3d.H: hessian.dfr3d.mig.H hessian.dfr3d.mig.demig.mig.H
	Math file1=hessian.dfr3d.mig.H file2=hessian.dfr3d.mig.demig.mig.H exp="file2/(file1+0.0001)" > $@


default:${BINDIR}/${EXE}

clean:
	@rm -f *.o *.mod

cleanm:
	/net/koko/brad/bin/all/runall "rm -f /scr1/tang/*DFF* /tmp/*tang* "

DD = d0.H d1.H d2.H d3.H d4.H d5.H d6.H d7.H d8.H d9.H d10.H d11.H d12.H d13.H d14.H

d%.H: dfr2d.hessian.H
	Window3d < dfr2d.hessian.H n4=1 f4=$* n6=1 f6=$* > $@

diag.H: ${DD}
	Cat ${DD} axis=3 > $@


include ${SEPINC}/SEP.bottom
