#!/bin/sh

#####
#	BOURNE SHELL SCRIPT FOR PLOTTING DISPLACEMENT VECTORS
#####

#####
#	INPUT/OUTPUT FILES FROM O92UTIL
#####
# Input source fault file
FLT_FILE="fault.dat" # EVLO EVLA EVDP STR DIP RAK SLIP WID LEN
# Output displacement file
DISP_FILE="disp.out" # STLO STLA STDP AZ UH UZ

#####
#	GMT PLOTTING VARIABLES
#####
# Map projection (use 'man psbasemap' to see options)
PROJ="-JM4i -P"
# Map limits (-RXMIN/XMAX/YMIN/YMAX)
LIMS="-R95/97/20/22"
# Output PostScript file name
PSFILE="displacement.ps"

#####
#	GMT PLOTTING COMMANDS
#####
# Draw coastline (-W) and national boundaries (-N1)
# (-Scolor is water color, -Gcolor is land color)
pscoast $PROJ $LIMS -Dh -W0.75p -N1/0.5p -Slightblue -Gtan -K > $PSFILE

# Plot focal mechanisms of input faults
awk '{print $1,$2,$3,$4,$5,$6,5}' $FLT_FILE |\
    psmeca $PROJ $LIMS -Sa0.5i -W1p -L1p -Ggrey -K -O >> $PSFILE
# Plot horizontal projection of rectangular input faults
# To convert degrees to radians, multiply by pi/180 = 0.01745
awk '{print $1,$2,$4,$9,$8*cos($5*0.017)}' $FLT_FILE |\
    psxy $PROJ $LIMS -SJ -W3p,red -K -O >> $PSFILE

# Plot receiver locations
awk '{print $1,$2}' $DISP_FILE |\
    psxy $PROJ $LIMS -Sc0.05i -W1p -Glightblue -K -O >> $PSFILE
# Plot displacement vectors, with vector amplitudes scaled
# Options after -SV specify arrow tail_width/head_length/head_width
SCALE="10"
awk '{print $1,$2,$4,'"$SCALE"'*$5}' $DISP_FILE |\
    psxy $PROJ $LIMS -SV0.03i/0.08i/0.05i -Gblack -K -O >> $PSFILE

# Draw map outline and label axes
psbasemap $PROJ $LIMS -Ba1WeSn -O >> $PSFILE

