
function [AUVlatlon] = bearing (ship, rng)

% bearing.m
% AUVlatlon = [latitude longitude] of AUV
% ship = [lat long] (both can be in DD.DDDD or DD MM.MMM)
% rng = [shiphead bearingToAUV rangeToAuv]
% expects longitude as a POSITIVE number and makes it negative
 
%used in auv_sectionP
%looks for data in missiondata file in each data directory
 
%-----------------
% DEFINE CONSTANTS
%-----------------

LAT2KM = 110978 ; % at 37 degrees N
LON2KM = 89012  ; % at 37 degrees N
DEG2RAD = (2*pi/360);
shipA=[NaN NaN];
totalangle =0;
AUVlatlon=[NaN NaN];

[mlat,nlat] = size(ship);
if nlat==4  % (they put in lat, long as degree min)
 % shipA(1) = ship(1)+ sign(ship(1))*ship(2)/60;
 % shipA(2) = ship(3)+ sign(ship(3))*ship(4)/60;  %% to use negative LL
   shipA(1) = ship(1)+ ship(2)/60;
   shipA(2) = -ship(3)- ship(4)/60;
else 
   shipA(1) = ship(1);
   shipA(2) = -ship(2);
end%if

totalangle = rng(1) + rng(2);
lonAdjust = (sin(DEG2RAD * totalangle) * rng(3)) / LON2KM;
latAdjust = (cos(DEG2RAD * totalangle) * rng(3)) / LAT2KM;

AUVlatlon(1) = shipA(1)+latAdjust;
AUVlatlon(2) = shipA(2)+lonAdjust;

return
%----------------------------------------------------------------