%function mission = surveyBox(lat0,lon0,lat1,lon1,rng1,rng2,rng3,depth, ...
%   rpm,nGps,transittime)
%  lat0         northwest latitude
%  lon0         northwest longitude
%  lat1         southeast latitude
%  lon1         southeast 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 = surveyBox(lat0,lon0,lat1,lon1,rng1,rng2,rng3,depth, ...
	rpm,nGps,transittime)

mission = [];

if lat1 > lat0 | lon1 < lon0,
	errorbox('Bad latitude and longitude inputs')
	return
end

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

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

dlat = lat0-lat1;
dlon = lon1-lon0;

if dlat > dlon, vertical = 1;
else vertical = 0; end

geoid = selectGeoid;
if vertical,
	rng = distance('rh',lat0,lon0,lat1,lon0,geoid);
	az = azimuth('rh',lat0,lon0,lat1,lon0,geoid);
	nLegs = ceil(distance('rh',lat0,lon0,lat0,lon1,geoid)/rng2);
else
	rng = distance('rh',lat0,lon0,lat0,lon1,geoid);
	az = azimuth('rh',lat0,lon0,lat0,lon1,geoid);
	nLegs = ceil(distance('rh',lat0,lon0,lat1,lon0,geoid)/rng2);
end

if mod(nLegs,2), nLegs = nLegs+1; end
str = ['Calculate box survey with ' int2str(nLegs) ' legs?'];
button=lower(questdlg(str,'','Yes'));
if strcmp(button,'no') | strcmp(button,'cancel'), return, end
pause(0.1)
mission = survey(lat0,lon0,rng1,rng,rng2,rng3,az,depth,rpm,nGps, ...
	nLegs,transittime);