% depthsurvey.m
% grabs and maps 1-sec ship depth data
% saves z,y,z data in depth*.mat file

%for ii=1:1000 
clf;clear all
npts=36;

load deptha1.dat
z=deptha1;z(1:1075,:)=[];
%z=boxave(z,1,10);
%z=sio8;
x=z(:,1);y=z(:,2);z=z(:,3);
l=length(z(:,1));
[ l z(l)]
%save depthA1raw  x y z


%edit raw data
n=find(z<10);z(n)=nan;
x(n)=[];y(n)=[];z(n)=[];
n=find(z>1500);z(n)=nan;
x(n)=[];y(n)=[];z(n)=[];
nb=12;
z=boxave(z,1,nb);x=boxave(x,1,nb);y=boxave(y,1,nb);




% delete outside points for A1
% Lon1=-69.0353;Lat1=-67.0309;
% Lon2=-68.9918;Lat2=-66.9931;
% ppp=find(x>Lon1 & x<Lon2 & y>Lat1 & y<Lat2);
% x=x(ppp);y=y(ppp);z=z(ppp);

% interpolate it to a regular grid
xi=linspace(min(x),max(x),npts);
yi=linspace(min(y),max(y),npts);
[Xi,Yi]=meshgrid(xi,yi); % create meshgrid
Zi=griddata(x,y,z,Xi,Yi); % grid the scattered data at Xi and Yi points
[cs,hh]=contour(Xi,Yi,Zi,'l','k');hold on;
clabel(cs,hh,'fontsize',10,'color','k','rotation',0)
hold on;

% enter station location
 stnloc=[-69 -67;-69.0198 -67.0187]; %A1
%stnloc=[            ]; % sio8
%plot station location
h=plot(stnloc(:,1),stnloc(:,2),'.b');set(h,'markersize',24);
set(gca,'fontw','bold')


% plot ships track
h=plot(x,y,'r.');set(h,'markersize',.5)
%grid
aspect5(-65);
figure(gcf)
mapax(1,2,.5,2);

%Color contour
figure(2);clf;
%axis([-69.0342  -68.9821  -67.0304  -66.9993]);%a1
pcolor(xi,yi,Zi);shading interp;hold on
set(gca,'fontw','bold')
colormap(flipud(jet));colorbar;
[cs,hh]=contour(Xi,Yi,Zi,'col','w');hold on;
clabel(cs,hh,'fontsize',10,'color','w','rotation',0)

h=plot(x,y,'r.');set(h,'markersize',.5,'linew',3);hold on;
h=plot(stnloc(2,1),stnloc(2,2),'.r');set(h,'markersize',24);hold on;
mapax(1,2,.5,2);
title('A1 Mooring Bathymetry - Depth M')
figure(gcf)
figure(1)
clear
%pause(10)
%end