clear all

missions = ['2000.056.04/'; '2000.056.05/'; '2000.056.06/'; '2000.056.07/'; '2000.056.09/'];

[N x] = size(missions);

for M = 1:N;
 eval(['load ' missions(M,:) 'ctd']);
 if M==1;
  o2=O2; s=S; t=T; ph=pH; lat=startlat; lon=startlon;
 else
  o2=[o2;O2]; s=[s;S]; t=[t;T]; ph=[ph;pH]; lat=[lat;startlat]; lon=[lon;startlon];
 end
end
XL = [min(t) max(t)];
YL = [33.2 34.2]; idx = find(s > YL(2) | s < YL(1)); s(idx)=NaN*idx;
phL = [min(ph) max(ph)]; idx = find(ph < 7.51); ph(idx)=NaN*idx;
o2L = [.7 4.9]; idx = find(o2 > o2L(2) | o2 < o2L(1)); o2(idx)=NaN*idx;

figure(1); clf
load wcoastline.dat
plot(wcoastline(:,1),wcoastline(:,2),'g'); hold on
plot(lon,lat,'*');
title('Mission starting points');
axis([-122.5 -121.6 36.4 37]);

 figure(2); clf; 
 subplot(211); plot3(t,s,ph,'.');
  set(gca,'xlim',XL,'ylim',YL,'zlim',phL);
  grid on 
 subplot(212); plot3(t,s,o2,'.');
 set(gca,'xlim',XL,'ylim',YL,'zlim',o2L);
 grid on 

cmp = jet(256); phscale = linspace(phL(1), phL(2), length(cmp));

figure(3); clf
set(gcf,'units','pixels','position',[40 400 400 400],'menubar','none','color','w');
for n=1:length(ph);  
 [mn a]=min(abs(ph(n)-phscale)); 
 p=plot3(t(n),s(n),o2(n),'.');  set(p,'color',cmp(a,:));
 hold on
end

set(gca,'xlim',XL,'ylim',YL,'zlim',o2L);
set(gca,'cameraposition',[-30 30 10]);
set(gca,'fontweight','bold','fontsize',12,'box','on')
xlab=(['Temperature (' setstr(176) 'C)']);
ylab=(['Salinity (psu)']);
zlabel(['Oxygen (ml l^{-1})']);
grid

axes('position',[.91 .23 .02 .62]);
pcolor([0 1],phscale',[phscale' phscale']); shading interp; caxis(phL);
set(gca,'YaxisLocation','right','Ytick',[7.6:.1:8],'fontweight','bold','fontsize',12);
set(gca,'XTick',[]);
t=text(2,phL(2)+.03,'pH'); 
set(t,'fontweight','bold','fontsize',12,'horizontalalignment','center');

frame
t=text(.67,.02,xlab); set(t,'fontweight','bold','fontsize',12,'rotation',26);
t=text(.12,.04,ylab); set(t,'fontweight','bold','fontsize',12);
