#! /bin/sh
WIDTH=420
XOFF1=0
XOFF2=430
XOFF3=860
HEIGHT=400
YOFF1=50
YOFF2=500

# First make the synthetic data for the sorting demo.
# This data was kludged so gathers would show some lateral variation.
echo "Making synthetic data for demo"
######START OF MODEL######
REF1="1.0:-2,0.2;4,0.2"
REF2="1.0:-2,2.0199;3.5495,0"
REF3="1.0:-2,4.3955;3.2384,0"
REF4="1.0:-2,8.8603;3.1155,0"

dvdz=.015  # velocity gradient (dv/dz)
dvdx=-0.2  # velocity gradient (dv/dx)
v00=5.0    # P-wave velocity at surface in km/s
nxo=6 fxo=0.04 dxo=0.04 # offset information: number, first and spacing
nxs=12 fxs=1.0 dxs=0.04 # shot information: number, first and spacing
nt=200 dt=0.004         # time information: number and spacing

susynlv v00=$v00 ndpfz=10 dvdz=$dvdz dvdx=$dvdx \
		dt=$dt nt=$nt verbose=0 \
		ref=$REF1 ref=$REF2 ref=$REF3 ref=$REF4 \
		nxo=$nxo fxo=$fxo dxo=$dxo \
		nxs=$nxs fxs=$fxs dxs=$dxs  |
suchw key1=cdp key2=gx key3=sx b=1 c=1 d=2 >modeldata
######END OF MODEL######

# Plot the model 
suximage <modeldata perc=99 title="Shot Gathers" \
	label1="Time (sec)" label2="Shot Gather" f2=1 d2=0.166667   \
	wbox=${WIDTH} hbox=${HEIGHT} xbox=${XOFF1} ybox=${YOFF1} &
 
 
######SORTING EXAMPLES######

# Get a stacking chart
suchart <modeldata |                     
xgraph n=72 title="Stacking Chart" label1="sx" label2="gx" \
	 linewidth=0 marksize=3 mark=8 linecolor=2 \
	wbox=${WIDTH} hbox=${HEIGHT} xbox=${XOFF2} ybox=${YOFF1} &

# Create receiver gathers from shot gathers
susort <modeldata gx offset  > sortdata
suximage < sortdata perc=99 title="Receiver Gathers"\
	label1="Time (sec)" label2="Receiver Gather" f2=1 d2=1 \
	wbox=${WIDTH} hbox=${HEIGHT} xbox=${XOFF3} ybox=${YOFF1} &

# Sort by cdp and offset
# If we CARE about offset order, we must specify it for most compilers
susort <modeldata cdp offset > sortdata
suximage < sortdata perc=99 title="CDPs with +Offset"\
	label1="Time (sec)" label2="CDP Gather" f2=1 d2=0.333333 \
	wbox=${WIDTH} hbox=${HEIGHT} xbox=${XOFF1} ybox=${YOFF2} &

# Sort data by cdp and within each cdp by decreasing offset
susort <modeldata cdp -offset > sortdata
suximage < sortdata perc=99\
	title="CDPs with -Offset"\
 	label1="Time (sec)" label2="CDP Gather" f2=1 d2=0.333333 \
	wbox=${WIDTH} hbox=${HEIGHT} xbox=${XOFF2} ybox=${YOFF2} &


# application: stacking (no nmo, just brute stack)
# notice that default sort key is cdp for both susort and sustack
susort <modeldata > sortdata
sustack < sortdata |
suxwigb perc=99 title="Brute Stack CDPs"\
	label1="Time (sec)" label2="CDP Location" f2=1100 d2=20 \
	wbox=$WIDTH hbox=$HEIGHT xbox=$XOFF3 ybox=$YOFF2 &

exit 0
