%function mission = surveyArea(lat0,lon0,lat1,lon1,lat2,lon2, ...
%	rng1,rng2,rng3,depth,rpm,nGps,transittime)
%  lat0			first corner latitude
%  lon0			first corner longitude
%  lat1			second corner latitude
%  lon1			second corner longitude
%  lat2			third corner latitude
%  lon2			third corner longitude
%  rng1			trackline lead-in length (meters)
%  rng2			trackline spacing 1 (meters)
%  rng3			trackline spacing 2 (meters(
%  depth		depth of survey
%  rpm			rpm of tailcone
%  nGps			GPS hits per trackline (-n,...-2,-1,0,1,2,...,n)
%				where negative values skip n legs between fixes
%  transittime  time to transit to first waypoint
function mission = surveyAreaOneway(lat0,lon0,lat1,lon1,lat2,lon2, ...
	rng1,rng2,rng3,depth,rpm,nGps,transittime)

mission = [];

if rng1 <= 0,
	errorbox('Can not use negative track lead-in.')
	return
end

if rng2 <= 0 | rng3 <= 0,
	errorbox('Can not use negative track spacing with this survey.')
	return
end

geoid = selectGeoid;
d1 = distance('rh',lat0,lon0,lat1,lon1,geoid);
d2 = distance('rh',lat1,lon1,lat2,lon2,geoid);

rng = d1;
az = azimuth('rh',lat0,lon0,lat1,lon1,geoid);
az2 = azimuth('rh',lat1,lon1,lat2,lon2,geoid);
nLegs = ceil(d2/(rng2+rng3)*2);

% check tolerances and negative track spacings
angleTolerance = 5; %degrees
azd = mod(az2-az+360,360);
if azd >= 270-angleTolerance & azd <= 270+angleTolerance,
	rng2 = -rng2;
	rng3 = -rng3;
elseif ~(azd >= 90-angleTolerance & azd <= 90+angleTolerance)
	errorbox('SurveyArea must have perpendicular sides!');
	return
end

if mod(nLegs,2), nLegs = nLegs+1; end
averspacing = (rng2+rng3)/2;
nLegs = checkNLegs(nLegs,rng1,rng,averspacing,depth,nGps,180,rpm);
if isempty(nLegs), return, end

mission = surveyOneway(lat0,lon0,rng1,rng,rng2,rng3,az,depth,rpm,nGps, ...
	nLegs,transittime);
