#!/bin/sh

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

MYPWD=`pwd`

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 

do
rm -f file96

#####
#	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
#####
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
#####


#####
#	for this distance and source depth get the ray parameter
#	and define the phase velocity limits
#####
	

	hudson96 -TEL tak135sph.mod -GCARC ${GCARC} -HS ${HS} -DT 0.05 -NPTS 8192
	hpulse96 -p -V -l 1 >> file96
	
#####
#	end of GCARC loop
#####

done
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
#####
#       also annotate the files with the pP sP times and ray parameter
#####
        ../ANN
	cd ..


#####
#    clean up
#####
       rm -f file96 hspec96.grn
done
#####
#	end of HS loop 
#####

#####
#    create the master index for the D.CTL file
#####
DODCTL
date > date.end


