I hope this will solve your problem, but not bash solution
Code:
[akshay@nio my_library]$ cat dis.awk
# Function to calculate the distance between two points
function atan(x) { return atan2(x,1) }
function acos(x) { return atan2(sqrt(1-x*x), x) }
function deg2rad(Deg){ return ( 4.0*atan(1.0)/180 ) * Deg }
function rad2deg(Rad){ return ( 45.0/atan(1.0) ) * Rad }
# Distance(lat1,lon1,lat2,lon2,unit)
# lat1, lon1 = Latitude and Longitude of point 1 (in decimal degrees)
# lat2, lon2 = Latitude and Longitude of point 2 (in decimal degrees)
# If 4th argument is not found then it returns distance in Miles
# ------- Units ----------
# "M" -> Miles (default)
# "K" -> Kilometers
# "N" -> Nautical Miles
function distance(lat1, lon1, lat2, lon2, unit) {
theta = lon1 - lon2
dist = sin(deg2rad(lat1)) * sin(deg2rad(lat2)) + cos(deg2rad(lat1)) * cos(deg2rad(lat2)) * cos(deg2rad(theta))
dist = acos(dist)
dist = rad2deg(dist)
miles = dist * 60 * 1.1515
unit = toupper(unit)
return ( unit == "K" ) ? (miles * 1.609344) : (unit == "N") ? ( miles * 0.8684) : miles
}
Usage :
1. On Terminal
Code:
[akshay@nio my_library]$ awk -f dis.awk --source 'BEGIN{ UNIT["M"]="Miles";
UNIT["K"]="Kilometers"; UNIT["N"]="Nautical Miles";
for(i in UNIT)print distance(32.9697, -96.80322, 29.46786, -98.53506, i),UNIT[i]}'
228.109 Nautical Miles
422.739 Kilometers
262.678 Miles
I amtrying to write a script that would compute the distance between an "x" number of points. This is what I have come up with so far and it is not working. Can anyone modify it to make it work?
A=34.16597 B=-84.33244
C=34.2344 D=-84.29189
test "$A" -eq "$C" -o "$B" -eq "$D"
then
echo... (3 Replies)
Need some advice and guidance for this UNIX beginner. Due to downsizing I have inherited the SysAdmin duties..(sigh). Please excuse and forgive me if I use the wrong terms below....
Situation:
We have UNIX ( Solaris 7/8/9( it varies) on Sun Ultra 10's) servers located at several global... (1 Reply)
Hi,
I need a shell script that when run should be able to find the geographical location of the system.
can anyone help me with this?
Thanks,
Sundeep (1 Reply)
Hi power user,
I have this type of data (distance list):
file1
A B 10
B C 20
C D 50I want output like this
# A B C D
A 0 10 30 80
B 10 0 20 70
C 30 20 0 50
D 80 70 50 0 Which is a distance matrix
I have tried... (0 Replies)
Hi all,
I have a data file like this
lat lon lat lon
12.000 25.125 14.235 25.012
14.200 81.000 25.584 25.014
45.023 25.365 25.152 35.222
I want to calculate distance and azimuth between this points
eg:- 12.000,25.125 and 14.235,25.012
I want to use awk programming... (3 Replies)
hi,
i have a pair of latitude and longitude and i want to calculate the distance between these two points. In vbscript i achieved in the following way...Now i want to implement this in unix shell scripting....
<%
Dim lat1, lon1, lat2, lon2
const pi = 3.14159265358979323846
... (8 Replies)
Hi,
I have a file as
ABC 1634230,1634284,1634349,1634468 1634272,1634301,1634356,1634534
What I want is to find distance between the numbers.. column 1 is the gene name and column 2 are starts and column 3 are their respective stops for the starts. So what I want is column 3 which has +1... (2 Replies)
Ksh is my default shell, but I want use the bash shell since its convenient to me.
When I type a long command line in a terminal, it does not wrap to the next line when I reach the end of the line and it wraps onto the same line, overwriting my prompt and the rest of what I typed.
$... (5 Replies)