#! /bin/sh

# 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######
echo "Data made, making postscript figures"

# Plot the model 
supsimage <modeldata perc=99 title="Shot Gathers"\
	label1="Time (sec)" label2="Shot Gather" f2=1 d2=0.166667 >model.eps
 
 
######SORTING EXAMPLES######

# Get a stacking chart
suchart <modeldata |                     
psgraph n=72 title="Stacking Chart" label1="sx" label2="gx" \
 linewidth=0 marksize=2 mark=8 >chart.eps                     

# Create receiver gathers from shot gathers
susort <modeldata gx offset |
supsimage perc=99 title="Receiver Gathers"\
	label1="Time (sec)" label2="Receiver Gather" f2=1 d2=1 >receiver.eps

# Sort by cdp and offset
# If we CARE about offset order, we must specify it for most compilers
susort<modeldata cdp offset |
supsimage perc=99 title="CDPs with +Offset"\
	label1="Time (sec)" label2="CDP Gather" f2=1 d2=0.333333 >cdpplus.eps

# Sort data by cdp and within each cdp by decreasing offset
susort <modeldata cdp -offset | 
supsimage perc=99\
	title="CDPs with -Offset"\
 	label1="Time (sec)" label2="CDP Gather" f2=1 d2=0.333333 >cdpminus.eps

# application: stacking (no nmo, just brute stack)
# notice that default sort key is cdp for both susort and sustack
susort <modeldata |
sustack |
supswigp perc=99 title="Brute Stack CDPs"\
	label1="Time (sec)" label2="CDP Location" f2=1100 d2=20 >stack.eps

echo 
echo "Output PostScript files:  model.eps chart.eps receiver.eps"
echo "    cdpplus.eps cdpminus.eps stack.eps"
echo 
echo "You may view these with your PostScript Previewer"

#rm modeldata
exit
