Trying to write a script which uses Charles Karney's GeodSolve
to solve a straight-forward geodesic problem. GeodSolve takes the input: lat1 lon1 azi1 dist1, and outputs: lat2 lon2 azi2.
I have a file ("azi_dist_file") containing azimuths and distances in the first and second column respectively. In the below simple script the user is asked to provide the initial position, lat1 and lon1, while azi1 and dist1 are fetched from azi_dist_file. The programme GeodSolve
will then solve the direct geodesic problem and return the endpoint position, lat2 lon2 (and azi2 which is irrelevant here); I'd like this second position to be used as the initial position in a further invocation of GeodSolve
, but fetching azi2 and dist2 from the 2nd row of azi_dist_file; repeated until the last row in that file is reached. Finally, I'd like all the lat,lon,azi,dist values written to a new file.
So far I have managed to write the following.
#!/bin/bash
echo "Enter starting latitude: "
read lat1
echo "Enter starting longitude: "
read lon1
alpha1=`awk 'NR==1{print;exit}' azi_dist_file|cut -f1 -d$'\t'`
dist1=`awk 'NR==1{print;exit}' azi_dist_file|cut -f2 -d$'\t'`
echo "$lat1 $lon1 $alpha1 $dist1" >> lat_lon_azi_dist_file
echo $lat1 $lon1 $alpha1 $dist1 | GeodSolve
lat2=`echo $lat1 $lon1 $alpha1 $dist1 | GeodSolve | cut -f1 -d' '`
lon2=`echo $lat1 $lon1 $alpha1 $dist1 | GeodSolve | cut -f2 -d' '`
echo "$lat2 $lon2"
script.sh lat1 lat2
). The values will then be available to the script as$1
and$2
respectively.