#! /bin/sh
# Supws - Demo shell script for SUPWS (compares sustack, sudivstack, and supws)
# Author: Nils Maercklin, GFZ Potsdam, Germany, 2001 
# Credit: Mary Palen-Murphy, CSM Dept of Geophysics, 1995
#         (uses parts of demo script "Sudivstack")

# PostScript flag (set to 1 to generate PS output instead of X display):
POSTSCRIPT=0

# X window sizes and positions:
WIDTH=400
HEIGHT=500
WIDTHOFF1=0
WIDTHOFF2=280
WIDTHOFF3=560
WIDTHOFF4=840
HEIGHTOFF=100


# Create one shot record:

echo "Create one Shot Record"

susynlv nt=630 dt=0.008 ft=0.0 nxo=81 dxo=.05 fxo=0.05 nxs=1 dxs=.05 fxs=0 \
er=0 ob=1 v00=0.75 dvdz=1.5 dvdx=0 smooth=1 \
ref="0.5:0.0,0.10;4.0,0.10" \
ref="0.5:0.0,0.25;4.0,0.25" \
ref="0.5:0.0,0.35;4.0,0.35" \
ref="0.5:0.0,0.50;4.0,0.50" \
ref="0.5:0.0,0.75;4.0,0.75" \
ref="0.5:0.0,1.3;4.0,1.3" \
ref="0.5:0.0,2.0;4.0,2.0" \
ref="0.5:0.0,3.0;4.0,3.0" \
ref="0.5:0.0,3.8;4.0,3.8" \
ref="0.5:0.0,5.0;4.0,5.0" \
ref="0.5:0.0,6.0;4.0,6.0" \
ref="0.5:0.0,7.2;4.0,7.2" \
ref="0.5:0.0,9.0;4.0,9.0" \
ref="0.5:0.0,12.0;4.0,12.0" \
ref="0.5:0.0,15.0;4.0,15.0" \
ref="0.5:0.0,19.0;4.0,19.0" |
sushw key=d2 a=.05 |
sudivcor trms=0.0,1.0,3.0,5.0 \
  vrms=900,1050,1500,2000 > record.su

# Duplicate record and add different noise:

echo "Duplicate record and add noise with different S/N ratios"
suaddnoise < record.su sn=2   > record.noise
suaddnoise < record.su sn=3  >> record.noise
suaddnoise < record.su sn=1  >> record.noise
suaddnoise < record.su sn=4 >> record.noise
sugain <record.su scale=3 | suaddnoise sn=9 >> record.noise


# Sort by key header word tracf:

echo "Sort by tracf"
susort < record.noise tracf > record.tracf

# Stack data using 4 different techniques:

echo "Equally weighted stack with sustack"
sustack < record.tracf key=tracf > stack.su

echo "Computing Diversity Stack with sudivstack" 
sudivstack < record.tracf > divstack.su

echo "Computing Phase Weighted Stack with supws" 
supws <record.tracf key=tracf sl=0.05 > pwstack.su

# X display of stacking results:

if [ $POSTSCRIPT -eq 0 ]
then

  echo "X display of stacking results"
  
  # Display shot record:
  suxwigb < record.su f2=0.05 title="shot record" windowtitle="shot record" \
    label1="Time(SEC)" label2="Distance(KM)" f2=0.05 \
	wbox=$WIDTH hbox=$HEIGHT xbox=$WIDTHOFF1 ybox=$HEIGHTOFF &
  sleep 1

  # Display stack:
  suxwigb < stack.su title="equally weighted stack" windowtitle="equal weights" \
    label1="Time(SEC)" label2="Distance(KM)" f2=0.05 \
    wbox=$WIDTH hbox=$HEIGHT xbox=$WIDTHOFF2 ybox=$HEIGHTOFF &
  sleep 1

  # Display diversity stack:
  suxwigb < divstack.su title="diversity stack" windowtitle="diversity stack" \
    label1="Time(SEC)" label2="Distance(KM)" f2=0.05 \
    wbox=$WIDTH hbox=$HEIGHT xbox=$WIDTHOFF3 ybox=$HEIGHTOFF &
  sleep 1

  # Display phase weighted stack:
  suxwigb < pwstack.su title="phase weighted stack" windowtitle="phase weighted stack" \
    label1="Time(SEC)" label2="Distance(KM)" f2=0.05 \
    wbox=$WIDTH hbox=$HEIGHT xbox=$WIDTHOFF4 ybox=$HEIGHTOFF &

# PostScript plot of stacking results:
else

  echo "PostScript plot of stacking results"
  
  # PostScript plots of 4 datasets:
  supswigp < record.su title="shot record" f2=0.05 linewidth=0 \
    label1="Time(SEC)" label2="Distance(KM)" > record.eps
    
  supswigp < stack.su title="equally weighted stack" f2=0.05 linewidth=0 \
    label1="Time(SEC)" label2="Distance(KM)" > stack.eps

  supswigp < divstack.su title="diversity stack" linewidth=0 \
    label1="Time(SEC)" label2="Distance(KM)" f2=0.05 > divstack.eps

  supswigp < pwstack.su title="phase weighted stack" linewidth=0 \
    label1="Time(SEC)" label2="Distance(KM)" f2=0.05 > pwstack.eps

  # Merge 4 plots into one:
  merge4 record.eps stack.eps divstack.eps pwstack.eps > supws.eps
  
  # Remove single plots:
  rm -f record.eps stack.eps divstack.eps pwstack.eps

  echo "Output PostScript file: supws.eps"
  echo " "
  echo "You may view this with your PostScript previewer"

fi

exit 0
