ARCH = LINUX
SEP_ARCH = LINUX
include ${SEPINC}/SEP.top

BINDIR = /net/koko/tang/bin/LINUX
RESDIR = ./Fig
SRCDIR = ./Src
TXTDIR = ./Txt

# for pompei
FFTWLIB = -L/opt/FFTW/lib -lfftw3f
# for kook
#FFTWLIB = -L/usr/local/FFTW/FFTW3/lib -lfftw3f

#YLIBDIR = /net/koko/tang/lib/ylib/ia64
#YLIB    = -I${YLIBDIR} -L${YLIBDIR} -lylibbas -lylibwem

SEPLIBDIR = /net/koko/tang/Research/SEP6.4.6/SEP6.4.6_INTEL/lib

UF90LIBS  = -lsupersetf90 -lsepgeef90 -lsuperset -lsepauxf90 -lsepmathf90 -lsep2df90 -lsep3df90 -lsep3d -lsepf90 -lsep -openmp -lsvml ${FFTWLIB}

# for pompei
UF90FLAGS = -O3 -axP -openmp -static-libcxa -Bstatic
# for kook
#UF90FLAGS = -O3 -axW -openmp -static-libcxa -Bstatic



MIG_PARA = pdip=45 offset=n ntpx=25 nws=106 oper="foufd" nxpad_beg=50 nxpad_end=50 #image_xmin=-2000 image_xmax=2000
OFF_PARA = nhx=33 ohx=-160
BSC_PARA = typbsc=2 nopbsc=3
twin.vmod.H: ${BINDIR}/lens_twin.x
	${BINDIR}/lens_twin.x ox=-5000 dx=10 nx=1001 oz=0 dz=10 nz=201 x11=-800. x13=800. x21=800. x23=800. > $@ refl=junk1.H nref=1 zref=1500. fm=0.02 bvel=twin.bvel.H
	echo n4=1 n5=1 n6=1 d4=1. d5=1. d6=1. o4=0. o5=0. o6=0. >> junk1.H
	Transp < junk1.H reshape=3,5,6 plane=12 > twin.refl.H
	Rm junk1.H

twin.slow.H: twin.vmod.H
	Math file1=$< exp="1./file1" > $@

twin.bslw.H: twin.vmod.H
	Math file1=twin.bvel.H exp="1./file1" > $@

twin.dslw.H: twin.slow.H twin.bslw.H
	Math file1=twin.slow.H file2=twin.bslw.H exp="file1-file2" > $@

twin.tsou.H:
	Wavelet n1=1500 o1=0 d1=0.002 domain=time fund=15 wavelet=ricker2 | Add scale=-1 > $@

twin.csou.H: twin.tsou.H
	echo d2=1 d3=1 d4=1 d5=1 o2=0 o3=0 o4=0 o5=0 n2=1 n3=1 n4=1 n5=1 >> $<
	${BINDIR}/wei_transf.x < $< adj=y ${FREQ} > junk1.H
	Transp plane=13 < junk1.H > $@
	Rm junk1.H

twin.crec.H: twin.csou.H twin.vmod.H
	${BINDIR}/wem3d.x csou=twin.csou.H vmod=twin.vmod.H imag=twin.refl.H crec=$@ \
        adj=n ngx=801 ogx=-4000 dgx=10 nsx=401 offset=n dsx=20 osx=-4000 ${MIG_PARA}

twin.imag.H: ${BINDIR}/wem3d.x twin.csou.H twin.vmod.H twin.crec.H
	${BINDIR}/wem3d.x csou=twin.csou.H vmod=twin.vmod.H crec=twin.crec.H imag=$@ \
        adj=y ${MIG_PARA} ${OFF_PARA}

twin.imag.bvel.H: ${BINDIR}/wem3d.x twin.csou.H twin.vmod.H twin.crec.H
	${BINDIR}/wem3d.x csou=twin.csou.H vmod=twin.bvel.H crec=twin.crec.H imag=$@ \
        adj=y ${MIG_PARA} ${OFF_PARA}


twin.dimg.forward.H: ${BINDIR}/wemva3d_baspix.x twin.bslw.H twin.csou.H twin.crec.H twin.dslw.H
	${BINDIR}/wemva3d_baspix.x csou=twin.csou.H crec=twin.crec.H bslw=twin.bslw.H \
                                   dslw=twin.dslw.H dimg=$@ adj=n add=n\
                                   comsou=n ${MIG_PARA} ${BSC_PARA} ${OFF_PARA}

twin.dslw.adjoint.H: ${BINDIR}/wemva3d_baspix.x twin.bslw.H twin.csou.H twin.crec.H twin.dimg.forward.H
	${BINDIR}/wemva3d_baspix.x csou=twin.csou.H crec=twin.crec.H bslw=twin.bslw.H \
                                   dslw=$@ dimg=twin.dimg.forward.H adj=y add=n\
                                   comsou=n ${MIG_PARA} ${BSC_PARA} ${OFF_PARA}

twin.dimg.offdso.H: ${BINDIR}/offdso.x twin.imag.bvel.H
	${BINDIR}/offdso.x modl=$@ data=twin.imag.bvel.H adj=y add=n hcut=0. hord=2.

twin.dslw.offdso.H: ${BINDIR}/wemva3d_baspix.x twin.bslw.H twin.csou.H twin.crec.H twin.dimg.offdso.H
	${BINDIR}/wemva3d_baspix.x csou=twin.csou.H crec=twin.crec.H bslw=twin.bslw.H \
                                   dslw=$@ dimg=twin.dimg.offdso.H adj=y add=n\
                                   comsou=n ${MIG_PARA} ${BSC_PARA} ${OFF_PARA}

# plane-waves

twin.plane.all.csou.H: ${BINDIR}/plane_source.x twin.csou.H twin.crec.H
	${BINDIR}/plane_source.x soufnc=twin.csou.H data=twin.crec.H sx0=0 npsx=61 psx_min=-0.000453153 psx_max=0.000453153 offset=n \
                                 plane_sou=$@ plane_rec=twin.plane.all.crec.H

twin.plane.all.imag.H: ${BINDIR}/wem3d.x twin.plane.all.csou.H twin.vmod.H
	${BINDIR}/wem3d.x crec=twin.plane.all.crec.H csou=twin.plane.all.csou.H vmod=twin.vmod.H imag=$@ \
        comsou=y adj=y ${MIG_PARA} ${OFF_PARA}

twin.plane.all.imag.bvel.H: ${BINDIR}/wem3d.x twin.plane.all.csou.H twin.bvel.H
	${BINDIR}/wem3d.x crec=twin.plane.all.crec.H csou=twin.plane.all.csou.H vmod=twin.bvel.H imag=$@ \
        comsou=y adj=y ${MIG_PARA} ${OFF_PARA}

twin.plane.all.dimg.forward.H: ${BINDIR}/wemva3d_baspix.x twin.plane.all.csou.H twin.dslw.H twin.bslw.H
	${BINDIR}/wemva3d_baspix.x csou=twin.plane.all.csou.H crec=twin.plane.all.crec.H bslw=twin.bslw.H dslw=twin.dslw.H dimg=$@ \
        comsou=y adj=n ${MIG_PARA} ${OFF_PARA} ${BSC_PARA}

twin.plane.all.dslw.adjoint.H: ${BINDIR}/wemva3d_baspix.x twin.plane.all.csou.H twin.bslw.H twin.plane.all.dimg.forward.H
	${BINDIR}/wemva3d_baspix.x csou=twin.plane.all.csou.H crec=twin.plane.all.crec.H bslw=twin.bslw.H dslw=$@ dimg=twin.plane.all.dimg.forward.H \
        comsou=y adj=y ${MIG_PARA} ${OFF_PARA} ${BSC_PARA}

twin.plane.all.dimg.offdso.H: ${BINDIR}/offdso.x twin.plane.all.imag.bvel.H
	${BINDIR}/offdso.x modl=$@ data=twin.plane.all.imag.bvel.H adj=y add=n hcut=0. hord=2.

twin.plane.all.dslw.offdso.H: ${BINDIR}/wemva3d_baspix.x twin.plane.all.csou.H twin.bslw.H twin.plane.all.dimg.offdso.H
	${BINDIR}/wemva3d_baspix.x csou=twin.plane.all.csou.H crec=twin.plane.all.crec.H bslw=twin.bslw.H dslw=$@ dimg=twin.plane.all.dimg.offdso.H \
        comsou=y adj=y ${MIG_PARA} ${OFF_PARA} ${BSC_PARA}




# image-space phase encoding
PERM_CSOU = /net/koko/claudio/Research/report/sep136/tang1/0001twin_sou_encw_bvel_tr1.H
PERM_CREC = /net/koko/claudio/Research/report/sep136/tang1/0001twin_rec_encw_bvel_tr1.H
PERM_CSOU2 = /net/koko/claudio/Research/report/sep136/tang1/1111twin_sou_encw_bvel_tr.H
PERM_CREC2 = /net/koko/claudio/Research/report/sep136/tang1/1111twin_rec_encw_bvel_tr.H

PERM_RESIZE = n1=801 min1=-4000

twin.perm.csou.H: ${PERM_CSOU2}
	Window3d < $< squeeze=n ${PERM_RESIZE} > $@

twin.perm.crec.H: ${PERM_CREC2}
	Window3d < $< squeeze=n ${PERM_RESIZE} > $@

twin.perm.imag.H: ${BINDIR}/wem3d.x twin.perm.csou.H twin.perm.crec.H twin.vmod.H
	${BINDIR}/wem3d.x crec=twin.perm.crec.H csou=twin.perm.csou.H vmod=twin.vmod.H imag=$@ \
        comsou=y adj=y radian=n ${MIG_PARA} ${OFF_PARA}

twin.perm.imag.bvel.H: ${BINDIR}/wem3d.x twin.perm.csou.H twin.perm.crec.H twin.vmod.H
	${BINDIR}/wem3d.x crec=twin.perm.crec.H csou=twin.perm.csou.H vmod=twin.bvel.H imag=$@ \
        comsou=y adj=y radian=n ${MIG_PARA} ${OFF_PARA}

twin.perm.dimg.forward.H: ${BINDIR}/wemva3d_baspix.x twin.perm.csou.H twin.perm.crec.H twin.dslw.H twin.bslw.H
	${BINDIR}/wemva3d_baspix.x csou=twin.perm.csou.H crec=twin.perm.crec.H bslw=twin.bslw.H dslw=twin.dslw.H dimg=$@ \
        comsou=y adj=n radian=n ${MIG_PARA} ${BSC_PARA} ${OFF_PARA}

twin.perm.dslw.adjoint.H: ${BINDIR}/wemva3d_baspix.x twin.perm.csou.H twin.perm.crec.H twin.bslw.H twin.perm.dimg.forward.H
	${BINDIR}/wemva3d_baspix.x csou=twin.perm.csou.H crec=twin.perm.crec.H bslw=twin.bslw.H dslw=$@ dimg=twin.perm.dimg.forward.H \
        comsou=y adj=y radian=n ${MIG_PARA} ${BSC_PARA} ${OFF_PARA}


twin.perm.dimg.offdso.H: ${BINDIR}/offdso.x twin.perm.imag.bvel.H
	${BINDIR}/offdso.x modl=$@ data=twin.perm.imag.bvel.H adj=y add=n hcut=0. hord=2.

twin.perm.dslw.offdso.H: ${BINDIR}/wemva3d_baspix.x twin.perm.csou.H twin.perm.crec.H twin.bslw.H twin.perm.dimg.offdso.H
	${BINDIR}/wemva3d_baspix.x csou=twin.perm.csou.H crec=twin.perm.crec.H bslw=twin.bslw.H dslw=$@ dimg=twin.perm.dimg.offdso.H \
        comsou=y adj=y radian=n ${MIG_PARA} ${OFF_PARA} ${BSC_PARA}



# Figures
LABEL_PARA = label1="z[m]" label2="x[m]" title=" " labelfat=1 titlefat=1 labelsz=11 titlesz=12
PCLIP_PARA = newclip=1
COLOR_PARA = color= j 
SCALE_PARA = wantscalebar=n barlabel=" "
RSIZE_SLOW_PARA = min1=-4000 max1=4010
RSIZE_IMAG_PARA = min3=-4000 max3=4010 min5=1000
LABEL_IMAG_PARA = label1="z[m]" label2="x[m]" label3="hx[m]" title=" " labelfat=1 titlefat=1 labelsz=8 point1=0.8 point2=0.85 wantcoordlabel=-1
${RESDIR}/twin-slow.v: twin.slow.H
	Window3d < $< ${RSIZE_SLOW_PARA}| Transp | Grey color=j out=$@ ${PCLIP_PARA} ${LABEL_PARA} ${COLOR_PARA} ${SCALE_PARA} labelsz= > /dev/null

${RESDIR}/twin-bslw.v: twin.bslw.H
	Window3d < $< ${RSIZE_SLOW_PARA}| Transp | Grey color=j out=$@ ${PCLIP_PARA} ${LABEL_PARA} ${COLOR_PARA} ${SCALE_PARA}> /dev/null

${RESDIR}/twin-dslw.v: twin.dslw.H
	Window3d < $< ${RSIZE_SLOW_PARA}| Transp | Grey color=j out=$@ ${PCLIP_PARA} ${LABEL_PARA} ${COLOR_PARA} ${SCALE_PARA} title="(a)"> /dev/null

# shot-profile domain
${RESDIR}/twin-imag-bvel.v: twin.imag.bvel.H
	Window3d < $< ${RSIZE_IMAG_PARA}| Transp plane=13 | Grey eout=1 gainpanel=a > junk1.T
	Cubeplot < junk1.T flat=1 frame1=50 frame2=400 frame3=16 out=junk1.v ${LABEL_IMAG_PARA}> /dev/null
	vp_annotate < junk1.v batch=y text=${TXTDIR}/text_filt_a > $@
	Rm junk1.T
	rm -f junk1.v

${RESDIR}/twin-dimg-forward.v: twin.dimg.forward.H
	Window3d < $< ${RSIZE_IMAG_PARA}| Transp plane=13 | Grey eout=1 gainpanel=a > junk1.T
	Cubeplot < junk1.T flat=1 frame1=50 frame2=400 frame3=16 out=junk1.v ${LABEL_IMAG_PARA}> /dev/null
	vp_annotate < junk1.v batch=y text=${TXTDIR}/text_filt_a > $@
	Rm junk1.T
	rm -f junk1.v

${RESDIR}/twin-dimg-offdso.v: twin.dimg.offdso.H
	Window3d < $< ${RSIZE_IMAG_PARA}| Transp plane=13 | Grey eout=1 gainpanel=a > junk1.T
	Cubeplot < junk1.T flat=1 frame1=50 frame2=400 frame3=16 out=junk1.v ${LABEL_IMAG_PARA}> /dev/null
	vp_annotate < junk1.v batch=y text=${TXTDIR}/text_filt_a > $@
	Rm junk1.T
	rm -f junk1.v

${RESDIR}/twin-dslw-adjoint.v: twin.dslw.adjoint.H
	Window3d < $< ${RSIZE_SLOW_PARA}| Transp | Grey color=j out=$@ ${PCLIP_PARA} ${LABEL_PARA} ${COLOR_PARA} ${SCALE_PARA} title="(b)"> /dev/null

${RESDIR}/twin-dslw-offdso.v: twin.dslw.offdso.H
	Math file1=$< exp="-1*file1" > junk1.H
	Window3d < junk1.H ${RSIZE_SLOW_PARA}| Transp | Grey color=j out=$@ ${PCLIP_PARA} ${LABEL_PARA} ${COLOR_PARA} ${SCALE_PARA} title="(b)"> /dev/null
	Rm junk1.H

# plane-wave domain
${RESDIR}/twin-plane-all-imag-bvel.v: twin.plane.all.imag.bvel.H
	Window3d < $< ${RSIZE_IMAG_PARA}| Transp plane=13 | Grey eout=1 gainpanel=a > junk1.T
	Cubeplot < junk1.T flat=1 frame1=50 frame2=400 frame3=16 out=junk1.v ${LABEL_IMAG_PARA} > /dev/null
	vp_annotate < junk1.v batch=y text=${TXTDIR}/text_filt_b > $@
	Rm junk1.T
	rm -f junk1.v

${RESDIR}/twin-plane-all-dimg-forward.v: twin.plane.all.dimg.forward.H
	Window3d < $< ${RSIZE_IMAG_PARA}| Transp plane=13 | Grey eout=1 gainpanel=a > junk1.T
	Cubeplot < junk1.T flat=1 frame1=50 frame2=400 frame3=16 out=junk1.v ${LABEL_IMAG_PARA}> /dev/null
	vp_annotate < junk1.v batch=y text=${TXTDIR}/text_filt_b > $@
	Rm junk1.T
	rm -f junk1.v

${RESDIR}/twin-plane-all-dimg-offdso.v: twin.plane.all.dimg.offdso.H
	Window3d < $< ${RSIZE_IMAG_PARA}| Transp plane=13 | Grey eout=1 gainpanel=a > junk1.T
	Cubeplot < junk1.T flat=1 frame1=50 frame2=400 frame3=16 out=junk1.v ${LABEL_IMAG_PARA}> /dev/null
	vp_annotate < junk1.v batch=y text=${TXTDIR}/text_filt_b > $@
	Rm junk1.T
	rm -f junk1.v

${RESDIR}/twin-plane-all-dslw-adjoint.v: twin.plane.all.dslw.adjoint.H
	Window3d < $< ${RSIZE_SLOW_PARA}| Transp | Grey color=j out=$@ ${PCLIP_PARA} ${LABEL_PARA} ${COLOR_PARA} ${SCALE_PARA} title="(c)"> /dev/null

${RESDIR}/twin-plane-all-dslw-offdso.v: twin.plane.all.dslw.offdso.H
	Math file1=$< exp="-1*file1" > junk1.H
	Window3d < junk1.H ${RSIZE_SLOW_PARA}| Transp | Grey color=j out=$@ ${PCLIP_PARA} ${LABEL_PARA} ${COLOR_PARA} ${SCALE_PARA} title="(c)"> /dev/null
	Rm junk1.H

# image-space encoding
${RESDIR}/twin-perm-imag-bvel.v: twin.perm.imag.bvel.H
	Window3d < $< ${RSIZE_IMAG_PARA}| Transp plane=13 | Grey eout=1 gainpanel=a > junk1.T
	Cubeplot < junk1.T flat=1 frame1=50 frame2=400 frame3=16 out=junk1.v ${LABEL_IMAG_PARA} > /dev/null
	vp_annotate < junk1.v batch=y text=${TXTDIR}/text_filt_c > $@
	Rm junk1.T
	rm -f junk1.v

${RESDIR}/twin-perm-dimg-forward.v: twin.perm.dimg.forward.H
	Window3d < $< ${RSIZE_IMAG_PARA}| Transp plane=13 | Grey eout=1 gainpanel=a > junk1.T
	Cubeplot < junk1.T flat=1 frame1=50 frame2=400 frame3=16 out=junk1.v ${LABEL_IMAG_PARA}> /dev/null
	vp_annotate < junk1.v batch=y text=${TXTDIR}/text_filt_c > $@
	Rm junk1.T
	rm -f junk1.v

${RESDIR}/twin-perm-dimg-offdso.v: twin.perm.dimg.offdso.H
	Window3d < $< ${RSIZE_IMAG_PARA}| Transp plane=13 | Grey eout=1 gainpanel=a > junk1.T
	Cubeplot < junk1.T flat=1 frame1=50 frame2=400 frame3=16 out=junk1.v ${LABEL_IMAG_PARA}> /dev/null
	vp_annotate < junk1.v batch=y text=${TXTDIR}/text_filt_c > $@
	Rm junk1.T
	rm -f junk1.v

${RESDIR}/twin-perm-dslw-adjoint.v: twin.perm.dslw.adjoint.H
	Window3d < $< ${RSIZE_SLOW_PARA}| Transp | Grey color=j out=$@ ${PCLIP_PARA} ${LABEL_PARA} ${COLOR_PARA} ${SCALE_PARA} title="(d)"> /dev/null

${RESDIR}/twin-perm-dslw-offdso.v: twin.perm.dslw.offdso.H
	Math file1=$< exp="-1*file1" > junk1.H
	Window3d < junk1.H ${RSIZE_SLOW_PARA}| Transp | Grey color=j out=$@ ${PCLIP_PARA} ${LABEL_PARA} ${COLOR_PARA} ${SCALE_PARA} title="(d)"> /dev/null
	Rm junk1.H

# 
${RESDIR}/twin-bimg-all.v: ${RESDIR}/twin-imag-bvel.v ${RESDIR}/twin-plane-all-imag-bvel.v ${RESDIR}/twin-perm-imag-bvel.v
	vp_OverUnderAniso ${RESDIR}/twin-imag-bvel.v ${RESDIR}/twin-plane-all-imag-bvel.v ${RESDIR}/twin-perm-imag-bvel.v > $@

${RESDIR}/twin-dimg-all.v: ${RESDIR}/twin-dimg-forward.v ${RESDIR}/twin-plane-all-dimg-forward.v ${RESDIR}/twin-perm-dimg-forward.v
	vp_OverUnderAniso ${RESDIR}/twin-dimg-forward.v ${RESDIR}/twin-plane-all-dimg-forward.v ${RESDIR}/twin-perm-dimg-forward.v > $@

${RESDIR}/twin-dslw-all.v: ${RESDIR}/twin-dslw.v ${RESDIR}/twin-dslw-adjoint.v ${RESDIR}/twin-plane-all-dslw-adjoint.v ${RESDIR}/twin-perm-dslw-adjoint.v
	vp_OverUnderAniso ${RESDIR}/twin-dslw.v ${RESDIR}/twin-dslw-adjoint.v ${RESDIR}/twin-plane-all-dslw-adjoint.v ${RESDIR}/twin-perm-dslw-adjoint.v > $@

${RESDIR}/twin-dimg-offdso-all.v: ${RESDIR}/twin-dimg-offdso.v ${RESDIR}/twin-plane-all-dimg-offdso.v ${RESDIR}/twin-perm-dimg-offdso.v
	vp_OverUnderAniso ${RESDIR}/twin-dimg-offdso.v ${RESDIR}/twin-plane-all-dimg-offdso.v ${RESDIR}/twin-perm-dimg-offdso.v > $@

${RESDIR}/twin-dslw-offdso-all.v: ${RESDIR}/twin-dslw.v ${RESDIR}/twin-dslw-offdso.v ${RESDIR}/twin-plane-all-dslw-offdso.v ${RESDIR}/twin-perm-dslw-offdso.v
	vp_OverUnderAniso ${RESDIR}/twin-dslw.v ${RESDIR}/twin-dslw-offdso.v ${RESDIR}/twin-plane-all-dslw-offdso.v ${RESDIR}/twin-perm-dslw-offdso.v > $@



${RESDIR}/%.pdf:${RESDIR}/%.v
	pstexpen $< ${RESDIR}/$*.ps color=y fat=1 fatmult=1.5 invras=n force=  invras=y
	epstopdf ${RESDIR}/$*.ps --outfile=$@


include ${SEPINC}/SEP.bottom
