# . . for the EXXON GOM data set
XOM_WPAR = min5=5 max5=45
XB = ./Bin/


Xline%.v:  FULLRWE.HH FULLCART.HH
	< FULLRWE.HH Window min3=$(min3) max3=$(max3) min2=$(min2) max2=$(max2) | Window3d n3=1 f3=$*|\
		Grey pclip=96.5 tpow=0.75 out=c1.v $(dn) title=" " titlesz=12\
		labelsz=10 label1="Depth (m)" label2="Inline distance (m)"
	< FULLCART.HH Window  min3=$(min3) max3=$(max3) min2=$(min2) max2=$(max2) |Window3d n3=1 f3=$*|\
		Grey pclip=96.5 tpow=1  out=c2.v $(dn) title=" " titlesz=12\
		labelsz=10 label1="Depth (m)" label2="Inline distance (m)"
	vp_OverUnderAniso c1.v c2.v>$@
	rm -f c1.v c2.v

Yline%.v: FULLRWE.HH FULLCART.HH
	< FULLRWE.HH  Window min3=$(min3) max3=$(max3) min2=$(min2) max2=$(max2) | Window3d n2=1 f2=$*|\
		Grey pclip=96.5 tpow=1 out=c1.v $(dn) title=" " titlesz=12  \
		labelsz=10 crowd2=0.70 crowd1=0.6 label1="Depth (m)" label2="Crossline distance (m)"
	< FULLCART.HH Window min3=$(min3) max3=$(max3)  min2=$(min2) max2=$(max2)| Window3d n2=1 f2=$*|\
		 Grey pclip=95 tpow=1 out=c2.v $(dn) title=" " titlesz=12  \
		labelsz=10 crowd2=0.7 crowd1=0.6 label1="Depth (m)" label2="Crossline distance (m)"
	vp_OverUnderAniso c1.v c2.v >$@
	rm -f c1.v c2.v

# . . Depth slice
Depth%.v: FUYLLRWE.HH FULLCART.HH
	echo "label1='Depth (m)' label2='Inline distance (m)' label3='Crossline distance (m)' d1=30" >> FULLRWE.T
	< FULLRWE.HH Window3d n1=1 f1=$* min2=$(min2) max2=$(max2) min3=$(min3) max3=$(max3) max2=14000  > x1.H
	< x1.H Transp | Grey pclip=98 yreverse=n out=c1.v $(dn) title=" " \
		titlesz=12 \
		labelsz=10 crowd1=0.7 crowd2=0.75 label1="Crossline distance (m)" label2="Inline distance (m)"
	echo "label1='Depth (m)' label2='Inline distance (m)' label3='Crossline distance (m)'  d1=30 " >> FULLCART.T
	< FULLCART.HH Window3d n1=1 f1=$* min2=$(min2) max2=$(max2) min3=$(min3) max3=$(max3) max2=14000 > x2.H
	< x2.H Transp | Grey pclip=97 yreverse=n out=c2.v $(dn) title=" "   \
		titlesz=12 labelsz=10 crowd1=0.7 crowd2=0.75 label1="Crossline distance (m)" label2="Inline distance (m)"
	vp_OverUnderAniso c1.v c2.v > $@
	vp_Movie c1.v c2.v >$@
	rm -f x1.H x2.H c1.v c2.v

# . . CR Figure 5.14
RFIG1.v: Xline188.v
	vp_annotate < $< batch=y text=ann/FIG1.txt | vppen vpstyle=n > $@
	rm -f Xline188.v

# . . CR Figure 5.15
RFIG3.v: Yline183.v
	vp_annotate < $< batch=y text=ann/FIG3.txt | vppen vpstyle=n > $@
	rm -f Yline183.v

# . . CR Figure 5.16
RFIG5.v: Depth83.v
	vp_annotate < $< batch=y text=ann/FIG5.txt | vppen vpstyle=n > $@
	rm -f Depth83.v

######################
#
# . . Velocity model for migration
ENS.H: 
	Window3d < $(EXXON311)/Vel/ExxonNoSalt.H j1=2 > $@
ENS2.H:   ENS.H
        < ENS.H Transp plane=12 | Window3d max2=4500 | Transp plane=12 > $@

#######################################
#
# . . Sort data
# . . start at 1600 and go in increments of 80
# . . make plane-wave sections
# . . Receiver wavefield
exxon311-planewave-%.H: EXXON311a.H $(XB)/S2P.x
	time < EXXON311a.H Sort3d synch=1 par=sort.p verb=1 max_size=10 \
		key4=s_y og4=$* dg4=80 ng4=1 > t1-$*.H
	time < t1-$*.H Infill3d  axes=2 maxsize=10 verb=1> t2-$*.H
	< t2-$*.H Transf wei=y shotmig=y f_min=3 f_min1=6 f_max1=25 f_max=30 verb=1 maxmem=50 > t3-$*.H
	$(XB)/S2P.x dx=25 opx=-0.002 dpx=0.0001 npx=41 opy=0 dpy=0.1 npy=1 \
		Shot=t3-$*.H Plane=$@ yint=2 minx=-275 
	rm -f t1-$*.H* t2-$*.H* t3-$*.H* 

# . . Source wavefield - individual shots
swf3D-shots.H:
	Wavelet n1=2253 d1=0.004 o1=-0.02 tdelay=0.04 domain=time \
		wavelet=ricker1 fund=20 | Scale rscale=0.000001 > t0.H
	echo "d2=25 o2=0. n3=1 o3=1000 d3=50 n4=1 o4=-75 d4=25" >> t0.H
	< t0.H Transf verb=n shotmig=y f_min=3. f_min1=6. f_max1=25. f_max=30. | Window3d  > t1.H
	< t1.H Transp plane=12| Transp plane=23  | Pad beg1=149 end1=150 beg2=16 end2=12> $@
	echo "o2=-400 d2=25 o4=1000 d4=50" >> $@
	rm -f t0.H t1.H 

# . . Source wavefield as planewaves
swf3D-pw.H: swf3D-shots.H $(XB)/Source2P.x
	$(XB)/Source2P.x dx=25 opx=${opx} npx=41 nshots=300 minx=-275\
		dpx=${dpx} opy=0. npy=1 dpy=0.1 Shot=swf3D-shots.H Plane=$@ yint=2

#####################
#
# . . Cartesian Migrations
rrr%.H:   rwf3D-pw-%.H
	< rwf3D-pw-$*.H Window3d j2=2 f2=0 > $@

sss.H: swf3D-pw.H
	< $< Window3d j2=2 f2=0 > $@

# . . Run on cees
BIGCSL-%.H: rrr%.H sss.H ENS2.H
	cp base.sh RunCSL$*.sh
	echo 'Parallel command=~/Bin/x86_64/ConicalRWE3D.x files="rrr$*.H,sss.H,ENS2.H,$@" \
		tags="rwf,swf,vel,image"\
		usage="INPUT,INPUT,INPUT,OUTPUT" nblock=41 axis="4,4,3,3" \
		file_type="DISTRIBUTE,DISTRIBUTE,COPY,COPY"\
		pverb=2 mach_mfile=mfile verbose=1 verb=1 norm=1 nsx=1 nsy=1 nsz=1 minang=1\
		maxang=179 nxtap=40 nytap=40 nxint=1 method=1 ne3=300 de3=15 oe3=0. \
		source_norm=0 logdir="CSTAT" ntilt=41 otilt=0 dtilt=0. n1end=0 n1beg=0 
		n2beg=135 n2end=136 newimage=1 wix=2 wiy=2 device=ib0' >> RunCSL$*.sh
	qsub RunCSL$*.sh 

###########################
#
# . . Riemannian Migrations

rwf3D-pw-%.H: exxon311-planewave-%.H
	cp $< $@

BIGRSL-%.H: rwf3D-pw-%.H swf3D-pw.H ENS2.H
	echo "o4=10.000001 d4=-0.5" >> swf3D-pw.H
	echo "o4=10.000001 d4=-0.5" >> rwf3D-pw-$*.H
	cp base.sh RunRSL$*.sh
	echo 'Parallel command=~/Bin/x86_64/ConicalRWE3D.x files="rwf3D-pw-$*.H,swf3D-pw.H,ENS2.H,$@"\
		tags="rwf,swf,vel,image" usage="INPUT,INPUT,INPUT,OUTPUT" nblock=41 \
		axis="4,4,3,3" file_type="DISTRIBUTE,DISTRIBUTE,COPY,COPY" pverb=2 \
		mach_mfile=mfile verbose=1 verb=1 norm=1 nsx=1 nsy=1 nsz=1 minang=2 \
		maxang=178 nxtap=40 nytap=40 nxint=1 method=2 ne3=400 de3=0.0045 oe3=0.\
		source_norm=0 logdir="RSTAT" ntilt=41 otilt=0 dtilt=0. n1end=0 n1beg=0 \
		n2beg=121 n2end=121 newimage=1 wix=1 wiy=1 device=ib0' >> RunRSL$*.sh
	qsub RunRSL$*.sh
################
#

INFILL = 2800 2880 2960 3040 3120 3200 3280 3360 3440 3520 3600 3680 3760 3840 3920 \
	 4000 4080 4160 4240 4320 4400 4480 4560 4640 4720 4800 4880 4960 5040 5120 \
	 5200 5280 5360 5440 5520 5600 5680 5760 5840 5920 6000 6080 6160 6240 6320 \
	 6400 6480 6560 6640 6720 6800 6880 6960 7040 7120 7200 7280 7360 7440 7520 \
	 7600 7680 7760 7840 7920 8000 8080 8160 8240 8320 8400 8480 8560 8640 8720 \
	 8800 8880 8960 9040 9120 9200 9280 9360 9440 9520 9600 9680 9760 9840 9920 \
	 10000 10080 10160 10240 10320 10480 10640 10800 10960 11120 
# . . Make all of the sail line migration volumes

FULLRWE.HH: $(addsuffix .H,$(addprefix BIGRSL-,${INFILL}))
	Add BIGRSL-*.H > $@


FULLCART.HH: $(addsuffix .H,$(addprefix BIGCSL-,${INFILL}))
	Add BIGCSL-*.H > $@

############
#
# . . view stuff

BIGCSL-%.T:
	Byte < BIGCSL-$*.H pclip=96 tpow=0.75 gainpanel=a  |\
		Window3d min2=$(min2) max2=$(max2) min3=$(min3) max3=$(max3) > $@

BIGRSL-%.T:
	Byte < BIGRSL-$*.H pclip=96 tpow=0.75 gainpanel=a |\
		Window3d min2=$(min2) max2=$(max2) min3=$(min3) max3=$(max3)> $@
ESL2.T:
	Byte < ESL2.H allpos=y pclip=100 gainpanel=a |\
		Window3d min2=$(min2) max2=$(max2) min3=$(min3) max3=$(max3)> $@
OLD%.T:
	Byte < OLD$*.H pclip=96 tpow=1.25 gainpanel=a |\
		Window3d min2=$(min2) max2=$(max2) min3=$(min3) max3=$(max3)> $@
RSEE%:BIGRSL-%.T ESL2.T
	~bob/Src/cpp/qt_cube/cube BIGRSL-$*.T ESL2.T
CSEE%:BIGCSL-%.T ESL2.T
	~bob/Src/cpp/qt_cube/cube BIGCSL-$*.T ESL2.T

SEE%: BIGRSL-%.T BIGCSL-%.T
	echo "label1='Depth (m)' label2='Inline distance (m)' label3='Crossline distance (m)'" >> BIGRSL-$*.T
	echo "label1='Depth (m)' label2='Inline distance (m)' label3='Crossline distance (m)'" >> BIGCSL-$*.T
	< ESL2.H 	Window3d min2=$(min2) max2=$(max2) min3=$(min3) max3=$(max3) |\
		Byte bclip=1505 eclip=4419 newclip=1  > crap.T
	~bob/Src/cpp/qt_cube/cube BIGRSL-$*.T nviews=2 BIGCSL-$*.T crap.T
SOLD%: BIGRSL-%.T OLD%.T BIGCSL-%.T
	echo "label1='Depth (m)' label2='Inline distance (m)' label3='Crossline distance (m)'" >> BIGRSL-$*.T
	echo "label1='Depth (m)' label2='Inline distance (m)' label3='Crossline distance (m)'" >> OLD$*.T
	< ESL2.H 	Window3d min2=$(min2) max2=$(max2) min3=$(min3) max3=$(max3) |\
		Byte bclip=1505 eclip=4419 newclip=1  > crap.T
	~bob/Src/cpp/qt_cube/cube OLD$*.T nvieww=2 BIGRSL-$*.T BIGCSL-$*.T crap.T

CC1.H:
	Math file1=BIGCSL-2960.H file2=BIGCSL-3360.H file3=BIGCSL-3680.H file4=BIGCSL-4000.H file5=BIGCSL-4320.H \
		exp="file1+file2+file3+file4+file5"> CC1.H
CC2.H:
	Math file1=BIGCSL-4640.H file2=BIGCSL-4960.H file3=BIGCSL-5280.H file4=BIGCSL-5600.H file5=BIGCSL-5920.H \
		file6=BIGCSL-6240.H file7=BIGCSL-6560.H file8=BIGCSL-6880.H\
		exp="2*file1+0.125*file2+3*file3+1.5*file4+1.*file5+3*file6+3*file7+0.5*file8" > CC2.H
CC3.H:
	Math  file1=BIGCSL-7200.H file2=BIGCSL-7520.H file3=BIGCSL-7840.H \
		file4=BIGCSL-8160.H file5=BIGCSL-8480.H file6=BIGCSL-8800.H file7=BIGCSL-9120.H \
		exp="0.75*file1+0.5*file2+2*file3+1.25*file4+1.5*file5+1.25*file6+2*file7" > CC3.H
CC4.H:
	Math file1=BIGCSL-8960.H file2=BIGCSL-8640.H file3=BIGCSL-8320.H file4=BIGCSL-8000.H \
		file5=BIGCSL-7680.H file6=BIGCSL-7360.H file7=BIGCSL-7040.H\
	 	exp="file1+0.5*file2+file3+file4+file5+file6+0.75*file7"  >CC4.H
CC5.H:
	Math file1=BIGCSL-3200.H file2=BIGCSL-3520.H file3=BIGCSL-3840.H file4=BIGCSL-4160.H file5=BIGCSL-4480.H\
		exp="file1+file2+file3+file4+file5" > CC5.H
CC6.H: 
	Math file1=BIGCSL-6720.H file2=BIGCSL-6400.H file3=BIGCSL-4800.H file4=BIGCSL-5760.H file5=BIGCSL-9600.H\
		exp="file1+file2+file3+file4+0.5*file5" > $@
CC7.H: 
	Math file1=BIGCSL-10000.H file2=BIGCSL-10160.H file3=BIGCSL-10320.H file4=BIGCSL-10480.H file5=BIGCSL-10640.H\
		file6=BIGCSL-10800.H file7=BIGCSL-9760.H\
		exp="2.5*file1+file2+file3+file4+file5+file6+0.5*file7" > $@
CC8.H:
	Math file1=BIGCSL-9820.H file2=BIGCSL-5120.H file3=BIGCSL-5440.H file4=BIGCSL-2880.H file5=BIGCSL-6080.H\
		exp="0.75*file1+1.5*file2+file3+file4+1.25*file5" > $@

FULLCART1.H: CC1.H CC2.H CC3.H CC4.H CC5.H CC6.H CC7.H CC8.H
	Add  CC1.H CC2.H CC3.H CC4.H CC5.H CC6.H CC7.H CC8.H > $@
##########
#
# . . Stacking for TEC image
RR1.H: 
	Math file1=BIGRSL-3040.H file2=BIGRSL-3360.H file3=BIGRSL-3680.H file4=BIGRSL-4000.H file5=BIGRSL-4320.H \
		exp="file1+file2+file3+0.14*file4+0.6*file5" > RR1.H
RR2.H:
	Math file1=BIGRSL-4640.H file2=BIGRSL-4960.H file3=BIGRSL-5280.H file4=BIGRSL-5600.H file5=BIGRSL-5920.H \
		file6=BIGRSL-6240.H file7=BIGRSL-6560.H  \
		exp="0.75*file1+0.075*file2+1.4*file3+0.1*file4+0.035*file5+1.5*file6+1*1.5*file7" > RR2.H
RR3.H:
	Math file1=BIGRSL-6880.H file2=BIGRSL-7200.H file3=BIGRSL-7520.H file4=BIGRSL-7840.H file5=BIGRSL-8160.H \
		file6=BIGRSL-8480.H file7=BIGRSL-8800.H file8=BIGRSL-9120.H\
		exp="1.125*file1+0.175*file2+0.08*file3+0.25*file4+1.25*file5+0.6*file6+0.15*file7+0.125*file8" > RR3.H
RR4.H:
	Math file1=BIGRSL-8960.H file2=BIGRSL-8640.H file3=BIGRSL-8320.H file4=BIGRSL-8000.H file5=BIGRSL-7680.H \
		file6=BIGRSL-7360.H file7=BIGRSL-7040.H \
		exp="0.675*file1+0.5*file2+2*file3+1*file4+1.35*file5+1.25*file6+0.75*file7" > RR4.H
RR5.H:
	Math file1=BIGRSL-3200.H file2=BIGRSL-3520.H file3=BIGRSL-3840.H file4=BIGRSL-4160.H file5=BIGRSL-4480.H\
		file6=BIGRSL-4800.H file7=BIGRSL-5120.H exp="file1+file2+file3+file4+0.75*file5+1.5*file6+1.25*file7" > RR5.H
RR6.H:
	Math file1=BIGRSL-6080.H file2=BIGRSL-9120.H file3=BIGRSL-9280.H file4=BIGRSL-9440.H file5=BIGRSL-9600.H\
		file6=BIGRSL-9820.H file7=BIGRSL-10000.H file8=BIGRSL-10160.H file9=BIGRSL-10320.H \
		exp="1.25*file1+0.04*file2+2*file3+0.75*file4+0.625*file5+1*file6+file7+0.75*file8+0.75*file9" > RR6.H
RR7.H:
	Math file1=BIGRSL-6720.H file2=BIGRSL-6400.H file3=BIGRSL-5760.H file4=BIGRSL-5440.H file5=BIGRSL-10480.H \
		file6=BIGRSL-10640.H file7=BIGRSL-10800.H file8=BIGRSL-10960.H file9=BIGRSL-11120.H\
		exp="file1+0.5*file2+0.6*file3+1.75*file4+0.5*file5+file6+0.5*file7+0.75*file8+file9" > RR7.H
RR8.H:
	Math file1=BIGRSL-11280.H file2=BIGRSL-2880.H file3=BIGRSL-9760.H\
		file4=BIGRSL-9040.H file5=BIGRSL-9200.H file6=BIGRSL-6480.H\
		exp="file1+0.5*file2+0.5*file3+file4+file5+0.5*file6" > $@
RR9.H:
	Math file1=BIGRSL-9520.H file2=BIGRSL-9680.H file3=BIGRSL-4560.H\
		exp="0.5*file1+0.5*file2+0.75*file3" > $@
###########
# 
# . . Stacked Cartesian Image
CR1.H: 
	Math file1=BIGCSL-3040.H file2=BIGCSL-3360.H file3=BIGCSL-3680.H file4=BIGCSL-4000.H file5=BIGCSL-4320.H \
		exp="1*file1+0.75*file2+0.75*file3+0.15*file4+0.6*file5" > $@
CR2.H:
	Math file1=BIGCSL-4640.H file2=BIGCSL-4960.H file3=BIGCSL-5280.H file4=BIGCSL-5600.H file5=BIGCSL-5920.H \
		file6=BIGCSL-6240.H file7=BIGCSL-6560.H  \
		exp="0.75*file1+0.1*file2+1.65*file3+0.1*file4+0.025*file5+1.75*file6+1*1.5*file7" >$@
CR3.H:
	Math file1=BIGCSL-6880.H file2=BIGCSL-7200.H file3=BIGCSL-7520.H file4=BIGCSL-7840.H file5=BIGCSL-8160.H \
		file6=BIGCSL-8480.H file7=BIGCSL-8800.H file8=BIGCSL-9120.H\
		exp="1.125*file1+0.175*file2+0.10*file3+0.25*file4+1.25*file5+0.5*file6+0.15*file7+0.125*file8" > $@
CR4.H:
	Math file1=BIGCSL-8960.H file2=BIGCSL-8640.H file3=BIGCSL-8320.H file4=BIGCSL-8000.H file5=BIGCSL-7680.H \
		file6=BIGCSL-7360.H file7=BIGCSL-7040.H \
		exp="0.675*file1+0.5*file2+2*file3+1*file4+1.5*file5+1*file6+1.*file7" > $@
CR5.H:
	Math file1=BIGCSL-3200.H file2=BIGCSL-3520.H file3=BIGCSL-3840.H file4=BIGCSL-4160.H file5=BIGCSL-4480.H\
		file6=BIGCSL-4800.H file7=BIGCSL-5120.H exp="1.25*file1+file2+file3+1.125*file4+file5+1.5*file6+file7">$@
CR6.H:
	Math file1=BIGCSL-9120.H file2=BIGCSL-9280.H file3=BIGCSL-9440.H file4=BIGCSL-9600.H\
		file5=BIGCSL-9820.H file6=BIGCSL-10000.H file7=BIGCSL-10160.H file8=BIGCSL-10320.H \
		exp="0.04*file1+2*file2+1*file3+1.*file4+1*file5+0.5*file6+0.5*file7+0.5*file8" > $@
CR7.H:
	Math file1=BIGCSL-6720.H file2=BIGCSL-6400.H file3=BIGCSL-5760.H file4=BIGCSL-5440.H file5=BIGCSL-10480.H \
		file6=BIGCSL-10640.H file7=BIGCSL-10800.H \
		exp="1.2*file1+0.5*file2+0.6*file3+1.75*file4+0.5*file5+0.5*file6+0.25*file7" > $@
CR8.H:
	Math file1=BIGCSL-9760.H file2=BIGCSL-2880.H file3=BIGCSL-9200.H file4=BIGCSL-9040.H file5=BIGCSL-6080.H\
		exp="file1+file2+file3+file4+file5" > $@


FULLRWE1.H: RR1.H RR2.H RR3.H RR4.H RR5.H RR6.H RR7.H RR8.H RR9.H
	Add RR1.H RR2.H RR3.H RR4.H RR5.H RR6.H RR7.H RR8.H RR9.H > $@

FULLCR.H:   CR1.H CR2.H CR3.H CR4.H CR5.H CR6.H CR7.H CR8.H
	Add CR1.H CR2.H CR3.H CR4.H CR5.H CR6.H CR7.H CR8.H  > $@

FULLCART%.T:    FULLCART%.H
	< FULLCART$*.H  Byte pclip=97.5 tpow=0.75 gainpanel=a > $@
FULLCR.T:    FULLCR.H
	< FULLCR.H  Byte pclip=97.5 tpow=0.75 gainpanel=a > $@
FULLRWE%.T:     FULLRWE%.H
	< FULLRWE$*.H   Byte pclip=97.5 tpow=0.75 gainpanel=a > $@

BOTH%:    FULLCART%.T FULLRWE%.T ESL2.H
	< FULLCART$*.T Window3d min2=$(min2) max2=$(max2) min3=$(min3) max3=$(max3) > ZZ2.T
	< FULLRWE$*.T  Window3d min2=$(min2) max2=$(max2) min3=$(min3) max3=$(max3) > ZZ1.T
	< ESL2.H     Window3d min2=$(min2) max2=$(max2) min3=$(min3) max3=$(max3) > ZZ3.H
	~bob/Src/cpp/qt_cube/cube ZZ1.T ZZ2.T ZZ3.H nviews=2

minB2=3000
maxB2=15000
minB3=3000
maxB3=10500


min2=2500
max2=16500
min3=3000
max3=11000


point = point1=$(p1) point2=$(p2) crowd1=0.8
p1=0.5
p2=0.6


#########################
#
# . . Velocity model
#

EXXON=/data/exxon-311/

ExxonVel.H: 
	Cp ${EXXON}/exxon-velocity.H $@ 
	echo "d1=15 d2=25 d3=30" >> $@

ExxonNoSalt.H:  
	Cp /net/koko/shan/Thesis/plane3d/velnosalt3d.HH $@
	echo "d1=15 d2=25 d3=30" >> $@

