#!/bin/sh

#####
#	attempt to make synthetic teleseismic P for Harley
#	using revised hspec96 with earth flattening
#####
rm -f hspec96*

date > date.start

#####
#	PARAMETERS FOR SYNTHETIC
#####
DT=1
NPTS=4096
NDEC=1

#####
#	LOOP OVER THE SOURCE DEPTH
#	NOTE: The depth must be given as 3 digits for depths > 0.5 km
#	this is for the naming convention
#####
for HS in \
	    001 002 003 004 005 006 007 008 009 \
	010 011 012 013 014 015 016 017 018 019 \
	020 021 022 023 024 025 026 027 028 029 \
	030 031 032 033 034 035 036 037 038 039 \
	040 041 042 043 044 045 046 047 048 049 \
	050 051 052 053 054 055 056 057 058 059 \
	060 061 062 063 064 065 066 067 068 069 \
	070 071 072 073 074 075 076 077 078 079 \
	080 081 082 083 084 085 086 087 088 089 \
	090 091 092 093 094 095 096 097 098 099 \
	100 110 120 130 140 150 160 170 180 190 \
	200 210 220 230 240 250 260 270 280 290 \
	300 310 320 330 340 350 360 370 380 390 \
	400 410 420 430 440 450 460 470 480 490 \
	500 510 520 530 540 550 560 570 580 590 \
	600 610 620 630 640 650 660 670 680 690 \
	700 710 720 730 740 750 760 770 780 790 

do

#####
#	define the DIRECTORY NAME FOR THIS SOURCE DEPTH
#	THE CONVENTION IS A 5 DIGIT NUMBER SUCH THAT
#	1234  means a depth of 123.4 km
#####

case $HS 
in
	0.5) DIRNAME=0005 ;;
	0.1) DIRNAME=0001 ;;
	*) DIRNAME=${HS}0 ;;
esac
#####
#	create the directory for this source depth
#####
if [ ! -d  ${DIRNAME} ]
then
	echo creating the Green s Function depth directory 
	echo $DIRNAME for depth $HS
	mkdir ${DIRNAME}
fi
#####
#	LOOP OVER THE GREAT CIRCLE DISTANCES
#####
rm -f dfile
for GCARC in \
	    030 031 032 033 034 035 036 037 038 039 \
	    040 041 042 043 044 045 046 047 048 049 \
	    050 051 052 053 054 055 056 057 058 059 \
	    060 061 062 063 064 065 066 067 068 069 \
	    070 071 072 073 074 075 076 077 078 079 \
	    080 081 082 083 084 085 086 087 088 089 \
	    090 091 092 093 094 095 
do

#####
#	FOR THIS EXERCISE THE DISTANCE IN KILOMETERS WILL BE TO THE
#	NEAREST 1 KM
#	WE NEED km for the synthetics and GCARC for the travel time
#	D is set to be a 5 digit integer such that 12345
#####

DIST=`echo ${GCARC} | awk '{printf "%7.1f",   111.195*$1}' `	
GCARC=`echo ${DIST} | awk '{printf "%f", $1/111.195}' `

#####
#	for this distance and source depth get the ray parameter
#	and define the phase velocity limits
#####
#####
#	get P travel time == arrival time
#####
	A=`time96 -M tak135sph.mod -GCARC ${GCARC} -T -EVDP ${HS}`
	T0=`echo $A | awk '{printf "%f", $1 - 100}' `
cat >> dfile << EOF
${DIST} ${DT} ${NPTS} ${T0} 0.0
EOF
	
done
#####
#	end of GCARC loop
#####
	

	hprep96 -M tak135sph.mod -HS ${HS} -HR 0.0 -EQEX -TF -BH  -d dfile \
		-NDEC ${NDEC}
	hspec96 
	hpulse96 -p -V -l 1 > file96

cd ${DIRNAME}
cat ../file96 | f96tosac -T
cd ..

#####
#	now that all computations are done, create the final
#	W.CTL since the above efforts do not match the naming
#	created by the FORTRAN code in f96tosac
#
######
	cd ${DIRNAME}
	../MKW > W.CTL
	cd ..


done
#####
#	end of HS loop 
#####
date > date.end


