#!/bin/bash
#
# Combined PostScript plot from Poynting vector directions and amplitudes
# snapshots of elastic numerical modelling.
# Snapshots are plain unformatted C-style files of size 231x231
# sn_pt is the normalized Poynting vector modulus file.
# sn_ang is the Poynting vector directions file given in radians.
#

WID=4.
HEI=4.

BHLS="1.000,0.500,1.000"
GHLS="0.500,0.500,1.000"
WHLS="0.000,0.500,1.000"

NS=231

# amplitudes in file sn_pt range from 0..1
# amplitudes in file sn_ang range from -pi..pi

# ascii to binary
a2b n1=1 < sn_pt.ascii > sn_pt
a2b n1=1 < sn_ang.ascii > sn_ang

# make SU-files from plain files
suaddhead < sn_pt ns=$NS | \
sushw key=trid,d1,d2 a=130,1,1 > sn_pt.su

suaddhead < sn_ang ns=$NS | \
sushw key=trid,d1,d2 a=130,1,1 > sn_ang.su

# amplify and clip to range 0..1
cat sn_pt.su | sushw key=dt a=1 | \
sugain scale=10 | sugain pclip=1. nclip=0. > tmp.su
sustrip < tmp.su > tmp

# make plot: Poynting vector angles
supsimage < sn_ang.su width=$WID height=$HEI \
    bhls=$BHLS ghls=$GHLS whls=$WHLS \
    legend=1 lstyle=vertright units="degrees" lheight=3.5 \
    lbeg=-180 lend=180 ldnum=60 wclip=-3.142593 bclip=3.142593 \
    label1="gridpoint #" label2="gridpoint #" \
    d1num=50 d2num=50 titlesize=12  bps=24 \
    title="Poynting vector directions" \
    bps=24 > ang.ps

gv ang.ps &

# make plot: Poynting vector amplitudes
supsimage < tmp.su width=$WID height=$HEI \
    label1="gridpoint #" label2="gridpoint #" \
    d1num=50 d2num=50 titlesize=12  bps=24 \
    title="Poynting vector amplitudes" \
    bps=24 > amp.ps

gv amp.ps &

# make combined plot: Poynting vector angles weighted by amplitudes
supsimage < sn_ang.su width=$WID height=$HEI \
    bhls=$BHLS ghls=$GHLS whls=$WHLS \
    legend=1 lstyle=vertright units="degrees" lheight=3.5 \
    lbeg=-180 lend=180 ldnum=60 \
    label1="gridpoint #" label2="gridpoint #" \
    d1num=50 d2num=50 titlesize=12  bps=24 \
    title="Poynting vector directions weighted by amplitudes" \
    infile=tmp bckgr=0.4 bps=24 > comb.ps

gv comb.ps &

# rm *.su *.ps tmp
