function [distance,angle]=lonlat2km(point1,point2)

% LONLAT2KM : gives the distance (in km) between 2 points defined by their lon/lat (Haversine formula)
% from http://www.movable-type.co.uk/scripts/latlong.html
%
% [distance,angle]=lonlat2km(point1,point2);
% point1, point2 as [lon,lat] or [lon,lat] columns (if several points, in which case distance is a column too)
%
%  Monique, mai 2007, MBARI

R = 6378137/1000;		% Earth radius in km
nb_pts=size(point1,1);
if size(point2,1)==1, point2=colonne(point2,nb_pts);, end
d=ones(nb_pts,1)*NaN;, angle=ones(nb_pts,1)*NaN;

for i=1:nb_pts

	point1_encours=deg2rad(point1(i,:));
	point2_encours=deg2rad(point2(i,:));
	xlon=point2_encours(1)-point1_encours(1);
	xlat=point2_encours(2)-point1_encours(2);

	a = (sin(xlat/2))^2 + cos(point1_encours(2))*cos(point2_encours(2))*(sin(xlon/2))^2;
	c = 2*atan2(sqrt(a),sqrt(1-a));
	distance(i) = R*c;

	angle(i)=rad2deg(atan2(sin(xlon)*cos(point2(2)), cos(point1(2))*sin(point2(2))-sin(point1(2))*cos(point2(2))*cos(xlon)));

end
  	
%R = earth’s radius (mean radius = 6,371km)
%?lat = lat2- lat1
%?long = long2- long1
%a = sin²(?lat/2) + cos(lat1).cos(lat2).sin²(?long/2)
%c = 2.atan2(va, v(1-a))
%d = R.c


return
