#! /bin/sh
# Sueipofi - Demo shell script for SUEIPOFI
# Author: Nils Maercklin, GFZ Potsdam, Germany, 2001 

# 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=410
HEIGHTOFF1=50
HEIGHTOFF2=100
HEIGHTOFF3=150

# Filter settings:
wl=0.10   # SVD window length in seconds
pwr=1     # Exponent of weighting functions

# Look for data or run script MakeData:

if [ ! -f data3c.su ]
then
  if [ -f MakeData ]
  then
    MakeData
  else
    echo "Can't find data3c.su or script MakeData"
    exit 1
  fi
fi


# Apply eigenimage-based polarization filter:

echo "SVD based polarization filter, wl=$wl, pwr=$pwr"

sueipofi <data3c.su >pofi3c.su wl=$wl pwr=$pwr

# X display of results:

if [ $POSTSCRIPT -eq 0 ]
then

  echo "X display of results"
  
  # Display input and filtered data:
  
  suwind < data3c.su key=trid min=12 max=12 |
  suxwigb title="vertical component" windowtitle="Z" \
    label1="Time(SEC)" label2="Distance(KM)" \
    wbox=$WIDTH hbox=$HEIGHT xbox=$WIDTHOFF1 ybox=$HEIGHTOFF1 &

  suwind < pofi3c.su key=trid min=12 max=12 |
  suxwigb title="filtered vertical component" windowtitle="filtered Z" \
    label1="Time(SEC)" label2="Distance(KM)" \
    wbox=$WIDTH hbox=$HEIGHT xbox=$WIDTHOFF2 ybox=$HEIGHTOFF1 &

  sleep 1
  suwind < data3c.su key=trid min=13 max=13 |
  suxwigb title="horizontal component 1" windowtitle="H 1" \
    label1="Time(SEC)" label2="Distance(KM)" \
    wbox=$WIDTH hbox=$HEIGHT xbox=$WIDTHOFF1 ybox=$HEIGHTOFF2 &

  suwind < pofi3c.su key=trid min=13 max=13 |
  suxwigb title="filtered horizontal component 1" windowtitle="filtered H 1" \
    label1="Time(SEC)" label2="Distance(KM)" \
    wbox=$WIDTH hbox=$HEIGHT xbox=$WIDTHOFF2 ybox=$HEIGHTOFF2 &

  sleep 1
  suwind < data3c.su key=trid min=14 max=14 |
  suxwigb title="horizontal component 1" windowtitle="H 2" \
    label1="Time(SEC)" label2="Distance(KM)" \
    wbox=$WIDTH hbox=$HEIGHT xbox=$WIDTHOFF1 ybox=$HEIGHTOFF3 &

  suwind < pofi3c.su key=trid min=14 max=14 |
  suxwigb title="filtered horizontal component 2" windowtitle="filtered H 2" \
    label1="Time(SEC)" label2="Distance(KM)" \
    wbox=$WIDTH hbox=$HEIGHT xbox=$WIDTHOFF2 ybox=$HEIGHTOFF3 &


# PostScript plot of results:
else
  echo "PostScript plot of results"
  
  for component in 12 13 14
  do
    # Plot input data:
    suwind <data3c.su key=trid min=$component max=$component |
    supswigp linewidth=0 title="input data, trid=$component" \
      label1="Time(SEC)" label2="Distance(KM)" > data3c.eps
 
    # Plot filtered data:
    suwind <pofi3c.su key=trid min=$component max=$component |
    supswigp linewidth=0 title="filtered data, trid=$component" \
      label1="Time(SEC)" label2="Distance(KM)" > pofi3c.eps
    
    # Merge both plots:
    merge2 data3c.eps pofi3c.eps > sueipofi${component}.eps
    
    rm -f data3c.eps pofi3c.eps
  done
  
  echo "Output PostScript files: sueipofi43.eps  (vertical component)"
  echo "                         sueipofi44.eps  (horizontal component 1)"
  echo "                         sueipofi45.eps  (horizontal component 2)"
  echo " "
  echo "You may view these with your PostScript previewer"
fi

exit 0

