Exercise: Global Distances

Write a program to read in the data from the supplied file and then display a table of the minimum distances between each pair of cities in kilometres. The distance should be that measured along the surface of the earth. Assume that the earth is a sphere of radius 6000km.

Each line in the data file cities.dat is 35 characters long and consists of the name and global co-ordinates of a city. The format of each line is:

FieldStartEndWidthType
City Name11212String
Latitude degrees14152Unsigned Integer
Latitude minutes17182Unsigned Integer
Latitude seconds20212Unsigned Integer
Latitude direction2323 1Character - 'N' or 'S'
Longitude degrees25 27 3Unsigned Integer
Longitude minutes 29 30 2Unsigned Integer
Longitude seconds 32 33 2Unsigned Integer
Longitude direction 35 35 1Character - 'E' or 'W'

Hint

The angle, α, between two points on the surface of a sphere is given by  alpha = 2 * arcsin ( 0.5 * ( (sin theta_2 - sin theta_1)**2 + (cos theta_2 - cos theta_1)**2 + (cost theta_2 sin phi_2 - cos theta_1 sin phi_1)**2)**0.5) where the points have the polar angles (theta_1, phi_1) and (theta_2, phi_2) respectively - being latitiude and being longitude.

Solutions: Fortran, Perl.