% ctd2.m
% trace les profiles de température et de salinité en fonction de la
% profondeur et le diagrammeTS pour 4 stations CTD
% fait appel à :
%   - tsdiagram.m

clear
path_mat='e:\Gatti2\golts\Survey\Survey081203\CTD\Data_extraites\asc';
[f_mat,p_mat]=uigetfile([path_mat,'\*.asc']);
path_mat_file=[p_mat,f_mat];
fichier=path_mat_file(findstr('stat',path_mat_file):findstr('_dc',path_mat_file)-1);
ctd=load(path_mat_file);

indf1=find(ctd(:,13)==0);
prof_min1=min(-ctd(indf1,6));
ctd=ctd(indf1,:);

path_mat2='e:\Gatti2\golts\Survey\Survey081203\CTD\Data_extraites\asc';
[f_mat2,p_mat2]=uigetfile([path_mat2,'\*.asc']);
path_mat_file2=[p_mat2,f_mat2];
fichier2=path_mat_file2(findstr('stat',path_mat_file2):findstr('_dc',path_mat_file2)-1);
ctd2=load(path_mat_file2);

indf2=find(ctd2(:,13)==0);
prof_min2=min(-ctd2(indf2,6));
prof_mina=min(prof_min1,prof_min2);
ctd2=ctd2(indf2,:);

path_mat3='e:\Gatti2\golts\Survey\Survey081203\CTD\Data_extraites\asc';
[f_mat3,p_mat3]=uigetfile([path_mat3,'\*.asc']);
path_mat_file3=[p_mat3,f_mat3];
fichier3=path_mat_file3(findstr('stat',path_mat_file3):findstr('_dc',path_mat_file3)-1);
ctd3=load(path_mat_file3);

indf3=find(ctd3(:,13)==0);
prof_min3=min(-ctd3(indf3,6));
ctd3=ctd3(indf3,:);

% path_mat4='e:\Gatti2\golts\Survey\Survey081203\CTD\Data_extraites\asc';
% [f_mat4,p_mat4]=uigetfile([path_mat4,'\*.asc']);
% path_mat_file4=[p_mat4,f_mat4];
% fichier4=path_mat_file4(findstr('stat',path_mat_file4):findstr('_dc',path_mat_file4)-1);
% ctd4=load(path_mat_file4);

% indf4=find(ctd4(:,13)==0);
% prof_min4=min(-ctd4(indf4,6));
% prof_minb=min(prof_min3,prof_min4);
% prof_min=min(prof_mina,prof_minb);
prof_min=min(prof_mina,prof_min3);
%ctd4=ctd4(indf4,:);

figure
%subplot(131)
axes('position',[0.1 0.11 0.18 0.81])
plot(ctd(1:100:end,2),-ctd(1:100:end,6),'-k',ctd2(1:100:end,2),-ctd2(1:100:end,6),'-+k',ctd3(1:100:end,2),-ctd3(1:100:end,6),'-ok')

% plot(ctd(:,2),-ctd(:,6),'b',ctd2(:,2),-ctd2(:,6),'r',ctd3(:,2),-ctd3(:,6),'g',ctd4(:,2),-ctd4(:,6),'k')
% hold on
% plot(ctd(1:2:end,2),-ctd(1:2:end,6),'+',ctd2(1:2:end,2),-ctd2(1:2:end,6),'o',ctd3(1:2:end,2),-ctd3(1:2:end,6),'<')
% plot(ctd(indf1,2),-ctd(indf1,6),'b',ctd2(indf2,2),-ctd2(indf2,6),'r',ctd3(indf3,2),-ctd3(indf3,6),'g')
% plot(ctd(indf1,2),-ctd(indf1,6),'b',ctd2(indf2,2),-ctd2(indf2,6),'r')
grid on;
set(gca,'ylim',[prof_min 0]);
%set(gca,'xlim',[13.5 16.5]);
xlabel(' Temperature [°C]','fontsize',12);
ylabel('Depth [m]','fontsize',12)
legend(fichier,fichier2,fichier3,0)
%legend(fichier,fichier2,fichier3,fichier4,0)
%legend(fichier,fichier2,0)

%subplot(132)
axes('position',[0.3 0.11 0.18 0.81])
plot(ctd(1:100:end,7),-ctd(1:100:end,6),'-k',ctd2(1:100:end,7),-ctd2(1:100:end,6),'-+k',ctd3(1:100:end,7),-ctd3(1:100:end,6),'-ok')
%plot(ctd(indf1,7),-ctd(indf1,6),'b',ctd2(indf2,7),-ctd2(indf2,6),'r',ctd3(indf3,7),-ctd3(indf3,6),'g')
%plot(ctd(indf1,7),-ctd(indf1,6),'b',ctd2(indf2,7),-ctd2(indf2,6),'r')
grid on;
set(gca,'YTickLabel',[])
set(gca,'ylim',[prof_min 0]);
%set(gca,'xlim',[37 38.4]);
xlabel(' Salinity ','fontsize',12);

% figure
% %diagramme TS
% hold on
% tsdiagram([37 38.5],[13.5 16.5],0)
% %plot(ctd(indf1,7),ctd(indf1,2),'b',ctd2(indf2,7),ctd2(indf2,2),'r',ctd3(indf3,7),ctd3(indf3,2),'g',ctd4(indf4,7),ctd4(indf4,2),'k')

hold off