%plotEnCTD.m
%
%Program which takes all of the CTD data saved in the file "en_ctd_mat" from 
%the Endeavor cruise and plots the various parameters of T, S, Sigma T,
%beam attenuation, optical backscatter, and fluorescence.
%
%Soupy Alexander, 03/26/02

load en_ctd_mat

%Set up the plot parameters
Tlimits = [5 15];
Tdelim = [5:1:10];
Slimits = [29 34];
Sdelim = [29:1:34];
Siglimits = [22 27];
Sigdelim = [22:1:27];
ATlimits = [0 5];
ATdelim = [0:1:5];
OBSlimits = [0 0];
OBSdelim = [0:1:1];
Flimits = [0 10];
Fdelim = [0:2:10];
depthlimits = [0 100];

color_list = ['r';'y';'g';'b';'m';'r';'y';'g';'b';'m';];

for index = 1:10;
    
    cast = evalin('base',['ctd' num2str(index,'%02d') 'b']);
    
    %Plot the salinity, temperature, and sigma T on one plot
    figure(index*2-1)
    
    %Temperature
    T = plot(cast(:,6),cast(:,25));
    axis ij
    Taxis = gca;
    xlabel('Temperature (^oC)')
    ylabel('Depth (m)')
    set(Taxis,'xlim',Tlimits);
    set(Taxis,'ylim',depthlimits);
    set(Taxis,'xtick',Tdelim);
    set(Taxis,'xcolor','b');
    set(Taxis,'fontsize',12);
    set(Taxis,'xaxislocation','top')
    grid on
    
    %Salinity
    Saxis = axes('Position',get(Taxis,'Position'));
    S = plot(cast(:,10),cast(:,25),'r')
    xlabel('Salinity (o/oo)')
    axis ij
    set(Saxis,'xlim',Slimits);
    set(Saxis,'ylim',depthlimits);
    set(Saxis,'xtick',Sdelim);
    set(Saxis,'xcolor','r');
    set(Saxis,'Color','none')
    set(Saxis,'fontsize',12);
    grid on
    
    %SigmaT
    Sigaxis = axes('Position',get(Taxis,'Position'));
    Sig = plot(cast(:,22),cast(:,25))
    set(Sig,'color',[0.2 0.7 0.6])
    xlabel('Sigma T (mg/cm^3)')
    axis ij
    set(Sigaxis,'xlim',Siglimits);
    set(Sigaxis,'ylim',depthlimits);
    set(Sigaxis,'xtick',Sigdelim);
    set(Sigaxis,'xcolor',[0.2 0.7 0.6]);
    set(Sigaxis,'Color','none')
    set(Sigaxis,'fontsize',12);
    grid on
    
    titlename = ['ctd' num2str(index,'%02d') '_TSSig'];
    title(titlename)
    command = ['print -depsc ' num2str(titlename)];
    evalin('base',command)
    
    %Add each cast to a waterfall plot of the data of all stations
    figure(100)
    hold on
    T = plot(cast(:,6),cast(:,25),color_list(index));
    Taxis = gca;
    axis ij
    xlabel('Temperature (^oC)')
    ylabel('Depth (m)')
    set(Taxis,'xlim',Tlimits);
    set(Taxis,'ylim',depthlimits);
    set(Taxis,'xtick',Tdelim);
    set(Taxis,'fontsize',12);
    grid on
    title('Temperature, All Casts, Endeavor Cruise')
    print -depsc en_T_wfall
    
    figure(101)
    hold on
    S = plot(cast(:,10),cast(:,25),color_list(index))
    Saxis = gca;
    xlabel('Salinity (o/oo)')
    ylabel('Depth (m)')
    title('Salinity, All Casts, Endeavor Cruise')
    axis ij
    set(Saxis,'xlim',Slimits);
    set(Saxis,'ylim',depthlimits);
    set(Saxis,'xtick',Sdelim);
    set(Saxis,'fontsize',12);
    grid on
    print -depsc en_S_wfall
    
    figure(102)
    hold on
    Sig = plot(cast(:,22),cast(:,25),color_list(index))
    Sigaxis = gca;
    xlabel('Sigma T (mg/cm^3)')
        ylabel('Depth (m)')
    title('Sigma T, All Casts, Endeavor Cruise')
    axis ij
    set(Sigaxis,'xlim',Siglimits);
    set(Sigaxis,'ylim',depthlimits);
    set(Sigaxis,'xtick',Sigdelim);
    set(Sigaxis,'fontsize',12);
    grid on    
    print -depsc en_Sig_wfall
    
    %Plot Beam Attenuation, backscatter, and flouresencse
    
    figure(index*2)
    
    ATTN = -4*log((cast(:,24)./100));
    
    %Beam attenuation
    AT = plot(ATTN,cast(:,25))
    xlabel('Beam Attenuation (m^-1)')
    ylabel('Depth (m)')
    axis ij
    ATaxis = gca;
    set(ATaxis,'xlim',ATlimits);
    set(ATaxis,'ylim',depthlimits);
    set(ATaxis,'xtick',ATdelim);
    set(ATaxis,'xcolor','b');
    set(ATaxis,'fontsize',12);    
    set(ATaxis,'xaxislocation','top')
    grid on

    
    %%%%%Endeavor has no OBS data
    %OBS
    %OBSaxis = axes('Position',get(ATaxis,'Position'));
    %OBS = plot(cast(:,10),cast(:,25),'r')
    %set(OBS,'linewidth',2)
    %axis ij
    %set(OBSaxis,'xlim',OBSlimits);
    %set(OBSaxis,'ylim',depthlimits);
    %set(OBSaxis,'xtick',OBSdelim);
    %set(OBSaxis,'xcolor','r');
    %set(OBSaxis,'Color','none')
    %set(OBSaxis,'fontsize',12);
    
    %fluorescence
    Faxis = axes('Position',get(ATaxis,'Position'));
    F = plot(cast(:,23),cast(:,25),'r')
    xlabel('Fluorescence')
    axis ij
    set(Faxis,'xlim',Flimits);
    set(Faxis,'ylim',depthlimits);
    set(Faxis,'xtick',Fdelim);
    set(Faxis,'xcolor','r');
    set(Faxis,'Color','none')   
    set(Faxis,'fontsize',12);
    
    titlename = ['ctd' num2str(index,'%02d') '_OPT'];
    title(titlename)
    command = ['print -depsc ' num2str(titlename)];
    evalin('base',command)
    grid on
    
    figure(104)
    hold on
    AT = plot(ATTN,cast(:,25),color_list(index))
    xlabel('Beam Attenuation (m^-1)')
    ylabel('Depth (m)')
    title('Beam Attenuation, All Casts, Endeavor Cruise')
    axis ij
    ATaxis = gca;
    set(ATaxis,'xlim',ATlimits);
    set(ATaxis,'ylim',depthlimits);
    set(ATaxis,'xtick',ATdelim);
    set(ATaxis,'fontsize',12);    
    set(ATaxis,'xaxislocation','top')
    grid on
    print -depsc en_AT_wfall
    
    figure(105)
    hold on
    F = plot(cast(:,23),cast(:,25),color_list(index))
    Faxis = gca;
    xlabel('Fluorescence')
    ylabel('Depth (m)')
    title('Fluorescence, All Casts, Endeavor Cruise')
    axis ij
    set(Faxis,'xlim',Flimits);
    set(Faxis,'ylim',depthlimits);
    set(Faxis,'xtick',Fdelim); 
    set(Faxis,'fontsize',12);
    grid on
    print -depsc en_F_wfall
    
end