function [out] = latlon2km(lat1,lon1,lat2,lon2)
%[out] = latlon2km(lat1,lon1,lat2,lon2)
% 
% calculates the distance in km between a pair of points whose positions
% are given in latitude and longitude (degrees, N/E being positive, S/W
% being negative)

R = 6371; % Radius of the Earth
out = R * acos( sin(deg2rad(lat1)) * sin(deg2rad(lat2))  +  cos(deg2rad(lat1)) * cos(deg2rad(lat2)) * cos(deg2rad(lon2-lon1)) );