#!/bin/bash
# Calculating moveout corrections for each RF trace using iasp91 as reference model
#     psmove by Xiaohui Yuan is called
#     script by Mei Feng, CAGS
#	2023/01/05

if [ $# -lt 2 ]; then
	echo "argv1: stn"
	echo "argv2: alpha"
	exit
fi
stn=$1
alpha=$2

str=${stn}.g${alpha}

cp -f ~/bin/iasp91.dat .
cat<<end >psmove.in
rfi
rfo
end


for file in decon.[rt].*.${str}; do
	[[ ! -f $file ]] && continue
	read filename npts <<< `saclst npts f $file`
	[[ $npts -lt 500 ]]  && continue
	sac<<eof >/dev/null
cut -5 15
r ${file}
w rfi
quit
eof
	psmove  < psmove.in >/dev/null; \mv rfo ${file}.m0

	sac<<eof >/dev/null
cut 5 30
r ${file}
w rfi
quit
eof
	psmove2 < psmove.in >/dev/null; \mv rfo ${file}.m1

	sac<<eof >/dev/null
cut 10 55
r ${file}
w rfi
quit
eof
	psmove3 < psmove.in >/dev/null; \mv rfo ${file}.m2
	rm -f rfi rfo 
done

rm -f iasp91.dat psmove.in

