function range=dist2(lat,long)
% range=dist2(lat,long)  computes distance in km between lat(1), long(1)
%                        and the remainder of lat long for spherical
%                        earth (leaner and faster than dist.m)

% Dimitris Menemenlis, 21 oct 94

% radius of sphere having same volume as earth 6371 km
% (equatorial radius = 6378 km, polar radius = 6357 km) from Gill p. 597

R=6371;                                 % radius of earth in km

% convert to radians

lat=pi*lat/180;
p1=lat(1);
p2=lat(2:length(lat));
clear lat

long=pi*long/180;
l1=long(1);
l2=long(2:length(long));
clear long

% compute range by finding solid angle between two points using dot product

range=cos(p1)*cos(p2).*(cos(l1)*cos(l2)+sin(l1)*sin(l2))+sin(p1)*sin(p2);
ix=find(range>1); range(ix)=ones(size(ix));
range=R*acos(range);
