% sarah_adcp.m
% oc404_4
addpath /home/valery/bin/
% load data file -- the output from get_adcp_xxxx.m 
load adcp4quoddy
% get average over depth
bscat=nanmean(Sv);
% find and delete NaNs
ff=find(isnan(bscat)==1);
time(ff)=[];
nav(:,ff)=[];
bscat(ff)=[];
bt_depth(ff)=[];
zc(:,ff)=[];
% find Inf data ( from dividing by zero )
gg=find(isinf(bscat)==1);
time(gg)=[];
nav(:,gg)=[];
bscat(gg)=[];
bt_depth(gg)=[];
zc(:,gg)=[];
% set limits for C1 survey 
%n1=20;n2=length(Sv);%n2=3530;
% find nigthtime stations (00:00 gmt --09:00 gmt)
% 9/24=0.375
ntime=(164:183);
m1=length(ntime)
% get loop from day 164 to day 183
% =====================================================
%          NIGHTTIME 00:00 GMT -- 09:00 GMT
% =====================================================
for i=[1:m1] 
 ff=find(time > ntime(i) & time < ntime(i)+0.375);
 mbs(i)=nanmean(bscat(ff));
 end
%
% normalize

mbsn=abs(mbs-min(mbs));
mbsn=mbsn/max(mbsn)*20;
mbsn=round(mbsn);
mbsn(find(mbsn==0))=1;
[Y,I]=sort(mbsn);
j=flipud(I');
% minimal circle size -- 5
p=mbsn+7;
% draw nighttime data 
figure(1)
colormap(jet(20));
cc=colormap;
set(gcf,'color','w')
% plot whole track
plot(nav(1,:),nav(2,:),'-','color',[.7 .7 .7]);
hold on
for k=[1:m1]
ff=find(time > ntime(j(k)) & time < ntime(j(k))+0.375);
% plot that part of track which drops to nighttime
plot(nav(1,ff),nav(2,ff),'r-');
% find lo/la which corresponds to ntime
mtime=nanmean(time(ff));
gg=find(abs(time-mtime) < 0.007);
[mm,ii]=min(abs(time(gg)-mtime));
% Plot data
plot(nav(1,gg(ii)),nav(2,gg(ii)),'o','markersize',p(j(k)),'markerfacecolor',cc(mbsn(j(k)),:),'markeredgecolor','b');
text(nav(1,gg(ii))+0.2,nav(2,gg(ii)),[num2str(ntime(j(k)))]);
end
hold off
grid
setaxis
xlabel('time, yearday since 1 Jan, 2004')
ylabel('integrated zooplankton biomass, units')
title('OC404-1; Zooplankton biomass: night stations, 00:00-09:00 am')
h1=colorbar('horiz');
set(h1,'position',[0.2300    0.1100    0.5750    0.025]);
set(h1,'xtick',[1:21]);
set(h1,'xticklabel','0||2||4||6||8||10||12||14||16||18||20');
set(h1,'ticklength',[.025 .25]);
input('?')
fig2jpeg('backsc_night.jpg');

% =====================================================
%          DAYTIME EVERY 3 HOURS
% =====================================================
%m1=m1-1;
dt=3/24;
    ntime=164:183;
 for n=[1:8]
   z1=3*(n-1);z2=3*n
for i=[1:m1] 
 ff=find(time > ntime(i)+dt*(n-1) & time < ntime(i)+dt*n);
 mbs(i)=nanmean(bscat(ff));
 end
%
% normalize

mbsn=abs(mbs-min(mbs));
mbsn=mbsn/max(mbsn)*20;
mbsn=round(mbsn);
mbsn(find(mbsn==0))=1;
[Y,I]=sort(mbsn);
j=flipud(I');
% minimal circle size -- 5
p=mbsn+7;
% draw nighttime data 
figure(2)
colormap(jet(20));
cc=colormap;
set(gcf,'color','w')
% plot whole track
plot(nav(1,:),nav(2,:),'-','color',[.7 .7 .7]);
hold on
for k=[1:m1]
ff=find(time > ntime(k)+dt*(n-1) & time < ntime(k)+dt*n);
% plot that part of track which drops to nighttime
plot(nav(1,ff),nav(2,ff),'r-');
% find lo/la which corresponds to ntime
mtime=nanmean(time(ff));
gg=find(abs(time-mtime) < 0.007);
[mm,ii]=min(abs(time(gg)-mtime));

% Plot data
plot(nav(1,gg(ii)),nav(2,gg(ii)),'o','markersize',p(j(k)),'markerfacecolor',cc(mbsn(j(k)),:),'markeredgecolor','b');
text(nav(1,gg(ii))+0.2,nav(2,gg(ii)),[num2str(ntime(j(k)))]);
end
hold off
grid
setaxis
xlabel('time, yearday since 1 Jan, 2004')
ylabel('integrated zooplankton biomass, units')
title(['OC404-1; Zooplankton biomass averaged over 3 hrs: ',num2str(z1),':00 -- ',num2str(z2),':00'])
h1=colorbar('horiz');
set(h1,'position',[0.2300    0.1100    0.5750    0.025]);
set(h1,'xtick',[1:21]);
set(h1,'xticklabel','0||2||4||6||8||10||12||14||16||18||20');
set(h1,'ticklength',[.025 .25]);
input('?')
jj=sprintf('bacsc_%i',n);
pp1=['fig2jpeg(''' jj '.jpg'')'];
eval(pp1);
clf

   end
   







