clear all
close all

header=char(71,53);data=NaN.*ones(2320,4);
fid=fopen('pne11_uctd_002.asc','r');
n=0;nn=0;
while feof(fid)==0
      L=fgets(fid);
      if L(1)=='*' | length(L)==2
         n=n+1;
         header(n,1:length(L))=L;
      else
         nn=nn+1;
         data(nn,:)=str2num(L);
      end
      clear L
end
fclose(fid);

ip=find(data(:,4)>=2);
P=data(ip,4);
T=data(ip,3);
S=gsw_SP_from_C(data(ip,2).*10,gsw_t90_from_t68(T),P);

figure(1)
clf
orient portrait

imax=find(P==max(P));

subplot(1,2,1);
hold on;
plot(T(1:imax),P(1:imax),'b-','linewidth',1);
plot(T(imax+1:end),P(imax+1:end),'r-','linewidth',1);
legend('downcast','upcast','location','southeast');
set(gca,'box','on','xlim',[18 28],'xtick',[18:2:28],...
        'ylim',[0 275],'ytick',[0:50:250],'ydir','reverse');
grid on;
xlabel('T [{\circ}C]');
ylabel('P [dbar]');
title('PNE11: uCTD - Test','fontweight','bold');

subplot(1,2,2);
hold on;
plot(S(1:imax),P(1:imax),'b-','linewidth',1);
plot(S(imax+1:end),P(imax+1:end),'r-','linewidth',1);
legend('downcast','upcast','location','southwest');
set(gca,'box','on','xlim',[36.0 37.0],'xtick',[36.0:0.2:37.0],...
        'ylim',[0 275],'ytick',[0:50:250],'ydir','reverse');
grid on;
xlabel('Salinity');
ylabel('P [dbar]');
title('PNE11: uCTD - Test','fontweight','bold');

%print -depsc uctdtest.eps
