%contourOcCTD.m
%
%Program to take the cast data from the Oceanus Cruise and create contour
%plots of temperature and salinity vs. distance from station 10 and depth
%
%4/4/02

load C:\NewYork\NewYorkCD\Data_Files\CTD_Data\Mat_Files\oc_ctd_mat.mat

Tlimits = [10 16];
Tdelim = [10:0.5:16];
temp_conts = [10:0.25:16];
Slimits = [28 36];
Sdelim = [28:0.5:36];
sal_conts = [28:0.25:36.0];
Flimits = [0 10];
Fdelim = [0:2:10];
F_conts = [0:1:10];
attnlimits = [0 5];
attndelim = [0:0.5:5];
attn_conts = [0:0.25:5];
sigmatlimits = [22 27];
sigmatdelim = [22:0.5:27];
sigmat_conts = [22:0.25:27];
OBSlimits = [0 100];
OBSdelim = [0:10:100];
OBS_conts = [0:5:100];

%Along axis of canyon
figure(1)

along_casts = [9:25];

%Set up empty matrices of the data
temp_along = repmat(NaN,165,length(along_casts));
sal_along = repmat(NaN,165,length(along_casts));
F = repmat(NaN,165,length(along_casts));
attn = repmat(NaN,165,length(along_casts));
OBS = repmat(NaN,165,length(along_casts));
sigmat = repmat(NaN,165,length(along_casts));
lat_along = repmat(NaN,1,length(along_casts));
lon_along = repmat(NaN,1,length(along_casts));
depth_along = repmat(NaN,165,length(along_casts));

for index_cast = 1:length(along_casts);
    index = along_casts(index_cast);
    cast = evalin('base',['ctd' num2str(index,'%02d') 'b']);
    [m,n] = size(cast);
    temp_along(1:m,index_cast) = cast(:,7);
    sal_along(1:m,index_cast) = cast(:,9);
    F_along(1:m,index_cast) = cast(:,15);
    attn_along(1:m,index_cast) = -4*log((cast(:,16)./100));
    sigmat_along(1:m,index_cast) = cast(:,14);
    OBS_along(1:m,index_cast) = 100*cast(:,11);
    lat_along(1,index_cast) = nanmean(cast(:,5));
    lon_along(1,index_cast) = nanmean(cast(:,6));
    depth_along(1:m,index_cast) = cast(:,17);
end

%Set up the distance matrix
dist1_along = repmat(NaN,1,length(along_casts));
dist1_along(1) = 0;

dist_along = repmat(NaN,1,length(along_casts));
dist_along(1) = 0;

for index = 2:length(along_casts);
    dist1_along(index) = latlon2dist(lat_along(index),...
        lon_along(index),lat_along(index-1),lon_along(index-1));
end

for index = 2:length(along_casts);
    dist_along(index) = sum(dist1_along(1:index));
end

%Convert distances to kilometers
distkm_along = dist_along./1000;

%Grid the temperature and salinity data (i.e., line up depth bins
depth_mat = 1:0.5:83;
temp_grid_along = repmat(NaN,length(depth_mat),length(along_casts));
sal_grid_along = repmat(NaN,length(depth_mat),length(along_casts));
F_grid_along = repmat(NaN,length(depth_mat),length(along_casts));
attn_grid_along = repmat(NaN,length(depth_mat),length(along_casts));
sigmat_grid_along = repmat(NaN,length(depth_mat),length(along_casts));
OBS_grid_along = repmat(NaN,length(depth_mat),length(along_casts));

for index = 1:length(along_casts);
    for index2 = 1:length(depth_mat);
        clear in
        in = value2Index(depth_along(:,index),depth_mat(index2),0.4);
        if isnan(in) == 0;
        temp_grid_along(index2,index) = temp_along(in,index);
        sal_grid_along(index2,index) = sal_along(in,index);
        F_grid_along(index2,index) = F_along(in,index);
        attn_grid_along(index2,index) = attn_along(in,index);
        OBS_grid_along(index2,index) = OBS_along(in,index);
        sigmat_grid_along(index2,index) = sigmat_along(in,index);
        end    
    end
end

depth_grid_along = repmat(depth_mat',1,length(along_casts));
distkm_grid_along = repmat(distkm_along,165,1);


[c,h] = contourf(distkm_grid_along,depth_grid_along,...
    temp_grid_along,temp_conts);
shading flat
set(gca,'fontsize',12)
xlabel('Distance to Station 9 (km)')
ylabel('Depth (m)')
title('Temperature Contours of CTD Data from Oceanus, Along Axis','fontsize',14)
axis ij
hold on
[c2,h2] = contour(distkm_grid_along,depth_grid_along,...
    temp_grid_along,Tdelim,'k');
clabel(c2,h2,'rotation',0)
for index = 1:length(along_casts);
    l = line([distkm_along(index) distkm_along(index)],[0 85]);
    set(l,'color',[0.25 0.25 0.25],'linestyle','-.');
    t = text(distkm_along(index)+0.5,80,[num2str(along_casts(index))]);
    set(t,'color',[0.25 0.25 0.25]);
end
axis([-1 max(max(distkm_grid_along))+1 0 85])
fig = gca;

cb = colorbar;
axes(cb)
ylabel('Temperature (^o C)')
axes(cb)
set(gca,'ytick',temp_conts)
set(gca,'dataaspectratio',[9 2 2])
axes(fig)
set(gca,'plotboxaspectratio',[1 0.5 1])
orient landscape

figure(2)
[c,h] = contourf(distkm_grid_along,depth_grid_along,...
    sal_grid_along,sal_conts);
shading flat
set(gca,'fontsize',12)
xlabel('Distance to Station 9 (km)')
ylabel('Depth (m)')
title('Salinity Contours of CTD Data from Oceanus, Along Axis','fontsize',14)
axis ij
hold on
[c2,h2] = contour(distkm_grid_along,depth_grid_along,...
    sal_grid_along,Sdelim,'k');
clabel(c2,h2,'rotation',0)
for index = 1:length(along_casts);
    l = line([distkm_along(index) distkm_along(index)],[0 85]);
    set(l,'color',[0.25 0.25 0.25],'linestyle','-.');
    t = text(distkm_along(index)+0.5,80,[num2str(along_casts(index))]);
    set(t,'color',[0.25 0.25 0.25]);
end
axis([-1 max(max(distkm_grid_along))+1 0 85])
fig = gca;
cb = colorbar;
axes(cb)
ylabel('Salinity (o/oo)')
set(gca,'ytick',min(Sdelim):1:max(Sdelim))
set(gca,'dataaspectratio',[4.5 2 1])
axes(fig)
set(gca,'plotboxaspectratio',[1 0.5 1])
orient landscape

figure(3)
[c,h] = contourf(distkm_grid_along,depth_grid_along,...
    F_grid_along,F_conts);
shading flat
set(gca,'fontsize',12)
xlabel('Distance to Station 9 (km)')
ylabel('Depth (m)')
title('Fluorescence Contours of CTD Data from Oceanus, Along Axis','fontsize',14)
axis ij
hold on
[c2,h2] = contour(distkm_grid_along,depth_grid_along,...
    F_grid_along,Fdelim,'k');
clabel(c2,h2,'rotation',0)
for index = 1:length(along_casts);
    l = line([distkm_along(index) distkm_along(index)],[0 85]);
    set(l,'color',[0.25 0.25 0.25],'linestyle','-.');
    t = text(distkm_along(index)+0.5,80,[num2str(along_casts(index))]);
    set(t,'color',[0.25 0.25 0.25]);
end
axis([-1 max(max(distkm_grid_along))+1 0 85])
fig = gca;
cb = colorbar;
axes(cb)
ylabel('Fluorescence')
set(gca,'ytick',min(Fdelim):1:max(Fdelim))
set(gca,'dataaspectratio',[4.5 2 1])
axes(fig)
set(gca,'plotboxaspectratio',[1 0.5 1])
orient landscape

figure(4)
[c,h] = contourf(distkm_grid_along,depth_grid_along,...
    attn_grid_along,attn_conts);
shading flat
set(gca,'fontsize',12)
xlabel('Distance to Station 9 (km)')
ylabel('Depth (m)')
title('Beam Attenuation Contours of CTD Data from Oceanus, Along Axis','fontsize',14)
axis ij
hold on
[c2,h2] = contour(distkm_grid_along,depth_grid_along,...
    attn_grid_along,attndelim,'k');
clabel(c2,h2,'rotation',0)
for index = 1:length(along_casts);
    l = line([distkm_along(index) distkm_along(index)],[0 85]);
    set(l,'color',[0.25 0.25 0.25],'linestyle','-.');
    t = text(distkm_along(index)+0.5,80,[num2str(along_casts(index))]);
    set(t,'color',[0.25 0.25 0.25]);
end
axis([-1 max(max(distkm_grid_along))+1 0 85])
fig = gca;
cb = colorbar;
axes(cb)
ylabel('Beam Attenuation (m-1)')
set(gca,'ytick',min(attndelim):1:max(attndelim))
set(gca,'dataaspectratio',[4.5 2 1])
axes(fig)
set(gca,'plotboxaspectratio',[1 0.5 1])
orient landscape

figure(5)
[c,h] = contourf(distkm_grid_along,depth_grid_along,...
    OBS_grid_along,OBS_conts);
shading flat
set(gca,'fontsize',12)
xlabel('Distance to Station 9 (km)')
ylabel('Depth (m)')
title('Optical Backscatter Contours of CTD Data from Oceanus, Along Axis','fontsize',14)
axis ij
hold on
[c2,h2] = contour(distkm_grid_along,depth_grid_along,...
    OBS_grid_along,OBSdelim,'k');
clabel(c2,h2,'rotation',0)
for index = 1:length(along_casts);
    l = line([distkm_along(index) distkm_along(index)],[0 85]);
    set(l,'color',[0.25 0.25 0.25],'linestyle','-.');
    t = text(distkm_along(index)+0.5,80,[num2str(along_casts(index))]);
    set(t,'color',[0.25 0.25 0.25]);
end
axis([-1 max(max(distkm_grid_along))+1 0 85])
fig = gca;
cb = colorbar;
axes(cb)
ylabel('Optical Backscatter (mV)')
set(gca,'ytick',min(OBSdelim):10:max(OBSdelim))
set(gca,'dataaspectratio',[1 5 1])
axes(fig)
set(gca,'plotboxaspectratio',[1 0.5 1])
orient landscape

figure(6)
[c,h] = contourf(distkm_grid_along,depth_grid_along,...
    sigmat_grid_along,sigmat_conts);
shading flat
set(gca,'fontsize',12)
xlabel('Distance to Station 9 (km)')
ylabel('Depth (m)')
title('Sigma T Contours of CTD Data from Oceanus, Along Axis','fontsize',14)
axis ij
hold on
[c2,h2] = contour(distkm_grid_along,depth_grid_along,...
    sigmat_grid_along,sigmatdelim,'k');
clabel(c2,h2,'rotation',0)
for index = 1:length(along_casts);
    l = line([distkm_along(index) distkm_along(index)],[0 85]);
    set(l,'color',[0.25 0.25 0.25],'linestyle','-.');
    t = text(distkm_along(index)+0.5,80,[num2str(along_casts(index))]);
    set(t,'color',[0.25 0.25 0.25]);
end
axis([-1 max(max(distkm_grid_along))+1 0 85])
fig = gca;
cb = colorbar;
axes(cb)
ylabel('Sigma T (mg/cm^3)')
set(gca,'ytick',min(sigmatdelim):1:max(sigmatdelim))
set(gca,'dataaspectratio',[4.5 2 1])
axes(fig)
set(gca,'plotboxaspectratio',[1 0.5 1])
orient landscape

%East Shelf
figure(7)

east_casts = [33; 34; 1; 35; 36; 37; 38; 39;];

%Set up empty matrices of the data
temp_east = repmat(NaN,165,length(east_casts));
sal_east = repmat(NaN,165,length(east_casts));
F_east = repmat(NaN,165,length(east_casts));
attn_east = repmat(NaN,165,length(east_casts));
sigmat_east = repmat(NaN,165,length(east_casts));
OBS_east = repmat(NaN,165,length(east_casts));
lat_east = repmat(NaN,1,length(east_casts));
lon_east = repmat(NaN,1,length(east_casts));
depth_east = repmat(NaN,165,length(east_casts));

for index_cast = 1:length(east_casts);
    index = east_casts(index_cast);
    cast = evalin('base',['ctd' num2str(index,'%02d') 'b']);
    [m,n] = size(cast);
    temp_east(1:m,index_cast) = cast(:,7);
    sal_east(1:m,index_cast) = cast(:,9);
    F_east(1:m,index_cast) = cast(:,15);
    OBS_east(1:m,index_cast) = 100*cast(:,11);
    attn_east(1:m,index_cast) = -4*log((cast(:,16)./100));
    sigmat_east(1:m,index_cast) = cast(:,14);
    lat_east(1,index_cast) = nanmean(cast(:,5));
    lon_east(1,index_cast) = nanmean(cast(:,6));
    depth_east(1:m,index_cast) = cast(:,17);
end

%Set up the distance matrix
dist1_east = repmat(NaN,1,length(east_casts));
dist1_east(1) = 0;

dist_east = repmat(NaN,1,length(east_casts));
dist_east(1) = 0;

for index = 2:length(east_casts);
    dist1_east(index) = latlon2dist(lat_east(index),...
        lon_east(index),lat_east(index-1),lon_east(index-1));
end

for index = 2:length(east_casts);
    dist_east(index) = sum(dist1_east(1:index));
end

%Convert distances to kilometers
distkm_east = dist_east./1000;

%Grid the temperature and salinity data (i.e., line up depth bins
depth_mat = 1:0.5:83;
temp_grid_east = repmat(NaN,length(depth_mat),length(east_casts));
sal_grid_east = repmat(NaN,length(depth_mat),length(east_casts));
F_grid_east = repmat(NaN,length(depth_mat),length(east_casts));
attn_grid_east = repmat(NaN,length(depth_mat),length(east_casts));
sigmat_grid_east = repmat(NaN,length(depth_mat),length(east_casts));
OBS_grid_east = repmat(NaN,length(depth_mat),length(east_casts));
for index = 1:length(east_casts);
    for index2 = 1:length(depth_mat);
        clear in
        in = value2Index(depth_east(:,index),depth_mat(index2),0.4);
        if isnan(in) == 0;
        temp_grid_east(index2,index) = temp_east(in,index);
        sal_grid_east(index2,index) = sal_east(in,index);
        F_grid_east(index2,index) = F_east(in,index);
        attn_grid_east(index2,index) = attn_east(in,index);
        OBS_grid_east(index2,index) = OBS_east(in,index);
        sigmat_grid_east(index2,index) = sigmat_east(in,index);
        end    
    end
end

depth_grid_east = repmat(depth_mat',1,length(east_casts));
distkm_grid_east = repmat(distkm_east,165,1);


[c,h] = contourf(distkm_grid_east,depth_grid_east,...
    temp_grid_east,temp_conts);
shading flat
set(gca,'fontsize',12)
xlabel('Distance to Station 33 (km)')
ylabel('Depth (m)')
title('Temperature Contours of CTD Data from Oceanus, East Shelf','fontsize',14)
axis ij
hold on
[c2,h2] = contour(distkm_grid_east,depth_grid_east,...
    temp_grid_east,Tdelim,'k');
clabel(c2,h2,'rotation',0)
for index = 1:length(east_casts);
    l = line([distkm_east(index) distkm_east(index)],[0 85]);
    set(l,'color',[0.25 0.25 0.25],'linestyle','-.');
    t = text(distkm_east(index)+0.5,80,[num2str(east_casts(index))]);
    set(t,'color',[0.25 0.25 0.25]);
end
axis([-1 max(max(distkm_grid_east))+1 0 85])
fig = gca;

cb = colorbar;
axes(cb)
ylabel('Temperature (^o C)')
axes(cb)
set(gca,'ytick',temp_conts)
set(gca,'dataaspectratio',[12 2 2])
axes(fig)
set(gca,'plotboxaspectratio',[1 0.5 1])
orient landscape

figure(8)
[c,h] = contourf(distkm_grid_east,depth_grid_east,...
    sal_grid_east,sal_conts);
shading flat
set(gca,'fontsize',12)
xlabel('Distance to Station 33 (km)')
ylabel('Depth (m)')
title('Salinity Contours of CTD Data from Oceanus, East Shelf','fontsize',14)
axis ij
hold on
[c2,h2] = contour(distkm_grid_east,depth_grid_east,...
    sal_grid_east,Sdelim,'k');
clabel(c2,h2,'rotation',0)
for index = 1:length(east_casts);
    l = line([distkm_east(index) distkm_east(index)],[0 85]);
    set(l,'color',[0.25 0.25 0.25],'linestyle','-.');
    t = text(distkm_east(index)+0.5,80,[num2str(east_casts(index))]);
    set(t,'color',[0.25 0.25 0.25]);
end
axis([-1 max(max(distkm_grid_east))+1 0 85])
fig = gca;
cb = colorbar;
axes(cb)
ylabel('Salinity (o/oo)')
set(gca,'ytick',min(Sdelim):1:max(Sdelim))
set(gca,'dataaspectratio',[6 2 1])
axes(fig)
set(gca,'plotboxaspectratio',[1 0.5 1])
orient landscape

figure(9)
[c,h] = contourf(distkm_grid_east,depth_grid_east,...
    F_grid_east,F_conts);
shading flat
set(gca,'fontsize',12)
xlabel('Distance to Station 33 (km)')
ylabel('Depth (m)')
title('Fluorescence Contours of CTD Data from Oceanus, East Shelf','fontsize',14)
axis ij
hold on
[c2,h2] = contour(distkm_grid_east,depth_grid_east,...
    F_grid_east,Fdelim,'k');
clabel(c2,h2,'rotation',0)
for index = 1:length(east_casts);
    l = line([distkm_east(index) distkm_east(index)],[0 85]);
    set(l,'color',[0.25 0.25 0.25],'linestyle','-.');
    t = text(distkm_east(index)+0.5,80,[num2str(east_casts(index))]);
    set(t,'color',[0.25 0.25 0.25]);
end
axis([-1 max(max(distkm_grid_east))+1 0 85])
fig = gca;
cb = colorbar;
axes(cb)
ylabel('Fluorescence')
set(gca,'ytick',min(Fdelim):1:max(Fdelim))
set(gca,'dataaspectratio',[6 2 1])
axes(fig)
set(gca,'plotboxaspectratio',[1 0.5 1])
orient landscape

figure(10)
[c,h] = contourf(distkm_grid_east,depth_grid_east,...
    attn_grid_east,attn_conts);
shading flat
set(gca,'fontsize',12)
xlabel('Distance to Station 33 (km)')
ylabel('Depth (m)')
title('Beam Attenuation Contours of CTD Data from Oceanus, East Shelf','fontsize',14)
axis ij
hold on
[c2,h2] = contour(distkm_grid_east,depth_grid_east,...
    attn_grid_east,attndelim,'k');
clabel(c2,h2,'rotation',0)
for index = 1:length(east_casts);
    l = line([distkm_east(index) distkm_east(index)],[0 85]);
    set(l,'color',[0.25 0.25 0.25],'linestyle','-.');
    t = text(distkm_east(index)+0.5,80,[num2str(east_casts(index))]);
    set(t,'color',[0.25 0.25 0.25]);
end
axis([-1 max(max(distkm_grid_east))+1 0 85])
fig = gca;
cb = colorbar;
axes(cb)
ylabel('Beam Attenuation (m-1)')
set(gca,'ytick',min(attndelim):1:max(attndelim))
set(gca,'dataaspectratio',[6 2 1])
axes(fig)
set(gca,'plotboxaspectratio',[1 0.5 1])
orient landscape

figure(11)
[c,h] = contourf(distkm_grid_east,depth_grid_east,...
    OBS_grid_east,OBS_conts);
shading flat
set(gca,'fontsize',12)
xlabel('Distance to Station 33 (km)')
ylabel('Depth (m)')
title('Optical Backscatter Contours of CTD Data from Oceanus, East Shelf','fontsize',14)
axis ij
hold on
[c2,h2] = contour(distkm_grid_east,depth_grid_east,...
    OBS_grid_east,OBSdelim,'k');
clabel(c2,h2,'rotation',0)
for index = 1:length(east_casts);
    l = line([distkm_east(index) distkm_east(index)],[0 85]);
    set(l,'color',[0.25 0.25 0.25],'linestyle','-.');
    t = text(distkm_east(index)+0.5,80,[num2str(east_casts(index))]);
    set(t,'color',[0.25 0.25 0.25]);
end
axis([-1 max(max(distkm_grid_east))+1 0 85])
fig = gca;
cb = colorbar;
axes(cb)
ylabel('Optical Backscatter (mV)')
set(gca,'ytick',min(OBSdelim):10:max(OBSdelim))
set(gca,'dataaspectratio',[1 4 1])
axes(fig)
set(gca,'plotboxaspectratio',[1 0.5 1])
orient landscape

figure(12)
[c,h] = contourf(distkm_grid_east,depth_grid_east,...
    sigmat_grid_east,sigmat_conts);
shading flat
set(gca,'fontsize',12)
xlabel('Distance to Station 33 (km)')
ylabel('Depth (m)')
title('Sigma T Contours of CTD Data from Oceanus, East Shelf','fontsize',14)
axis ij
hold on
[c2,h2] = contour(distkm_grid_east,depth_grid_east,...
    sigmat_grid_east,sigmatdelim,'k');
clabel(c2,h2,'rotation',0)
for index = 1:length(east_casts);
    l = line([distkm_east(index) distkm_east(index)],[0 85]);
    set(l,'color',[0.25 0.25 0.25],'linestyle','-.');
    t = text(distkm_east(index)+0.5,80,[num2str(east_casts(index))]);
    set(t,'color',[0.25 0.25 0.25]);
end
axis([-1 max(max(distkm_grid_east))+1 0 85])
fig = gca;
cb = colorbar;
axes(cb)
ylabel('Sigma T (mg/cm^3)')
set(gca,'ytick',min(sigmatdelim):1:max(sigmatdelim))
set(gca,'dataaspectratio',[6 2 1])
axes(fig)
set(gca,'plotboxaspectratio',[1 0.5 1])
orient landscape

%West Shelf
figure(13)

west_casts = [7; 30; 29; 28; 27; 26;];

%Set up empty matrices of the data
temp_west = repmat(NaN,165,length(west_casts));
sal_west = repmat(NaN,165,length(west_casts));
F_west = repmat(NaN,165,length(west_casts));
attn_west = repmat(NaN,165,length(west_casts));
sigmat_west = repmat(NaN,165,length(west_casts));
OBS_west = repmat(NaN,165,length(west_casts));
lat_west = repmat(NaN,1,length(west_casts));
lon_west = repmat(NaN,1,length(west_casts));
depth_west = repmat(NaN,165,length(west_casts));

for index_cast = 1:length(west_casts);
    index = west_casts(index_cast);
    cast = evalin('base',['ctd' num2str(index,'%02d') 'b']);
    [m,n] = size(cast);
    temp_west(1:m,index_cast) = cast(:,7);
    sal_west(1:m,index_cast) = cast(:,9);
    F_west(1:m,index_cast) = cast(:,15);
    attn_west(1:m,index_cast) = -4*log((cast(:,16)./100));
    OBS_west(1:m,index_cast) = 100*cast(:,11);
    sigmat_west(1:m,index_cast) = cast(:,14);
    lat_west(1,index_cast) = nanmean(cast(:,5));
    lon_west(1,index_cast) = nanmean(cast(:,6));
    depth_west(1:m,index_cast) = cast(:,17);
end

%Set up the distance matrix
dist1_west = repmat(NaN,1,length(west_casts));
dist1_west(1) = 0;

dist_west = repmat(NaN,1,length(west_casts));
dist_west(1) = 0;

for index = 2:length(west_casts);
    dist1_west(index) = latlon2dist(lat_west(index),...
        lon_west(index),lat_west(index-1),lon_west(index-1));
end

for index = 2:length(west_casts);
    dist_west(index) = sum(dist1_west(1:index));
end

%Convert distances to kilometers
distkm_west = dist_west./1000;

%Grid the temperature and salinity data (i.e., line up depth bins
depth_mat = 1:0.5:83;
temp_grid_west = repmat(NaN,length(depth_mat),length(west_casts));
sal_grid_west = repmat(NaN,length(depth_mat),length(west_casts));
attn_grid_west = repmat(NaN,length(depth_mat),length(west_casts));
OBS_grid_west = repmat(NaN,length(depth_mat),length(west_casts));
F_grid_west = repmat(NaN,length(depth_mat),length(west_casts));
sigmat_grid_west = repmat(NaN,length(depth_mat),length(west_casts));

for index = 1:length(west_casts);
    for index2 = 1:length(depth_mat);
        clear in
        in = value2Index(depth_west(:,index),depth_mat(index2),0.4);
        if isnan(in) == 0;
        temp_grid_west(index2,index) = temp_west(in,index);
        sal_grid_west(index2,index) = sal_west(in,index);
        F_grid_west(index2,index) = F_west(in,index);
        attn_grid_west(index2,index) = attn_west(in,index);
        OBS_grid_west(index2,index) = OBS_west(in,index);
        sigmat_grid_west(index2,index) = sigmat_west(in,index);
        end    
    end
end

depth_grid_west = repmat(depth_mat',1,length(west_casts));
distkm_grid_west = repmat(distkm_west,165,1);


[c,h] = contourf(distkm_grid_west,depth_grid_west,...
    temp_grid_west,temp_conts);
shading flat
set(gca,'fontsize',12)
xlabel('Distance to Station 7 (km)')
ylabel('Depth (m)')
title('Temperature Contours of CTD Data from Oceanus, West Shelf','fontsize',14)
axis ij
hold on
[c2,h2] = contour(distkm_grid_west,depth_grid_west,...
    temp_grid_west,Tdelim,'k');
clabel(c2,h2,'rotation',0)
for index = 1:length(west_casts);
    l = line([distkm_west(index) distkm_west(index)],[0 85]);
    set(l,'color',[0.25 0.25 0.25],'linestyle','-.');
    t = text(distkm_west(index)+0.5,80,[num2str(west_casts(index))]);
    set(t,'color',[0.25 0.25 0.25]);
end
axis([-1 max(max(distkm_grid_west))+1 0 85])
fig = gca;

cb = colorbar;
axes(cb)
ylabel('Temperature (^o C)')
axes(cb)
set(gca,'ytick',temp_conts)
set(gca,'dataaspectratio',[14 2 2])
axes(fig)
set(gca,'plotboxaspectratio',[1 0.5 1])
orient landscape

figure(14)
[c,h] = contourf(distkm_grid_west,depth_grid_west,...
    sal_grid_west,sal_conts);
shading flat
set(gca,'fontsize',12)
xlabel('Distance to Station 7 (km)')
ylabel('Depth (m)')
title('Salinity Contours of CTD Data from Oceanus, West Shelf','fontsize',14)
axis ij
hold on
[c2,h2] = contour(distkm_grid_west,depth_grid_west,...
    sal_grid_west,Sdelim,'k');
clabel(c2,h2,'rotation',0)
for index = 1:length(west_casts);
    l = line([distkm_west(index) distkm_west(index)],[0 85]);
    set(l,'color',[0.25 0.25 0.25],'linestyle','-.');
    t = text(distkm_west(index)+0.5,80,[num2str(west_casts(index))]);
    set(t,'color',[0.25 0.25 0.25]);
end
axis([-1 max(max(distkm_grid_west))+1 0 85])
fig = gca;
cb = colorbar;
axes(cb)
ylabel('Salinity (o/oo)')
set(gca,'ytick',min(Sdelim):1:max(Sdelim))
set(gca,'dataaspectratio',[6.5 2 1])
axes(fig)
set(gca,'plotboxaspectratio',[1 0.5 1])
orient landscape

figure(15)
[c,h] = contourf(distkm_grid_west,depth_grid_west,...
    F_grid_west,F_conts);
shading flat
set(gca,'fontsize',12)
xlabel('Distance to Station 7 (km)')
ylabel('Depth (m)')
title('Fluorescence Contours of CTD Data from Oceanus, West Shelf','fontsize',14)
axis ij
hold on
[c2,h2] = contour(distkm_grid_west,depth_grid_west,...
    F_grid_west,Fdelim,'k');
clabel(c2,h2,'rotation',0)
for index = 1:length(west_casts);
    l = line([distkm_west(index) distkm_west(index)],[0 85]);
    set(l,'color',[0.25 0.25 0.25],'linestyle','-.');
    t = text(distkm_west(index)+0.5,80,[num2str(west_casts(index))]);
    set(t,'color',[0.25 0.25 0.25]);
end
axis([-1 max(max(distkm_grid_west))+1 0 85])
fig = gca;
cb = colorbar;
axes(cb)
ylabel('Fluorescence')
set(gca,'ytick',min(Fdelim):1:max(Fdelim))
set(gca,'dataaspectratio',[6.5 2 1])
axes(fig)
set(gca,'plotboxaspectratio',[1 0.5 1])
orient landscape

figure(16)
[c,h] = contourf(distkm_grid_west,depth_grid_west,...
    attn_grid_west,attn_conts);
shading flat
set(gca,'fontsize',12)
xlabel('Distance to Station 7 (km)')
ylabel('Depth (m)')
title('Beam Attenuation Contours of CTD Data from Oceanus, West Shelf','fontsize',14)
axis ij
hold on
[c2,h2] = contour(distkm_grid_west,depth_grid_west,...
    attn_grid_west,attndelim,'k');
clabel(c2,h2,'rotation',0)
for index = 1:length(west_casts);
    l = line([distkm_west(index) distkm_west(index)],[0 85]);
    set(l,'color',[0.25 0.25 0.25],'linestyle','-.');
    t = text(distkm_west(index)+0.5,80,[num2str(west_casts(index))]);
    set(t,'color',[0.25 0.25 0.25]);
end
axis([-1 max(max(distkm_grid_west))+1 0 85])
fig = gca;
cb = colorbar;
axes(cb)
ylabel('Beam Attenuation (m-1)')
set(gca,'ytick',min(attndelim):1:max(attndelim))
set(gca,'dataaspectratio',[6.5 2 1])
axes(fig)
set(gca,'plotboxaspectratio',[1 0.5 1])
orient landscape

figure(17)
[c,h] = contourf(distkm_grid_west,depth_grid_west,...
    OBS_grid_west,OBS_conts);
shading flat
set(gca,'fontsize',12)
xlabel('Distance to Station 7 (km)')
ylabel('Depth (m)')
title('Optical Backscatter Contours of CTD Data from Oceanus, West Shelf','fontsize',14)
axis ij
hold on
[c2,h2] = contour(distkm_grid_west,depth_grid_west,...
    OBS_grid_west,OBSdelim,'k');
clabel(c2,h2,'rotation',0)
for index = 1:length(west_casts);
    l = line([distkm_west(index) distkm_west(index)],[0 85]);
    set(l,'color',[0.25 0.25 0.25],'linestyle','-.');
    t = text(distkm_west(index)+0.5,80,[num2str(west_casts(index))]);
    set(t,'color',[0.25 0.25 0.25]);
end
axis([-1 max(max(distkm_grid_west))+1 0 85])
fig = gca;
cb = colorbar;
axes(cb)
ylabel('Optical Backscatter (mV)')
set(gca,'ytick',min(OBSdelim):10:max(OBSdelim))
set(gca,'dataaspectratio',[6.5 2 1])
axes(fig)
set(gca,'plotboxaspectratio',[1 0.5 1])
orient landscape

figure(18)
[c,h] = contourf(distkm_grid_west,depth_grid_west,...
    sigmat_grid_west,sigmat_conts);
shading flat
set(gca,'fontsize',12)
xlabel('Distance to Station 7 (km)')
ylabel('Depth (m)')
title('Sigma T Contours of CTD Data from Oceanus, West Shelf','fontsize',14)
axis ij
hold on
[c2,h2] = contour(distkm_grid_west,depth_grid_west,...
    sigmat_grid_west,sigmatdelim,'k');
clabel(c2,h2,'rotation',0)
for index = 1:length(west_casts);
    l = line([distkm_west(index) distkm_west(index)],[0 85]);
    set(l,'color',[0.25 0.25 0.25],'linestyle','-.');
    t = text(distkm_west(index)+0.5,80,[num2str(west_casts(index))]);
    set(t,'color',[0.25 0.25 0.25]);
end
axis([-1 max(max(distkm_grid_west))+1 0 85])
fig = gca;
cb = colorbar;
axes(cb)
ylabel('Sigma T (mg/cm^3)')
set(gca,'ytick',min(sigmatdelim):1:max(sigmatdelim))
set(gca,'dataaspectratio',[6.5 2 1])
axes(fig)
set(gca,'plotboxaspectratio',[1 0.5 1])
orient landscape

%Across axis of canyon
figure(19)

across_casts = [8; 7; 6; 5; 4; 3; 1; 2;];

%Set up empty matrices of the data
temp_across = repmat(NaN,165,length(across_casts));
sal_across = repmat(NaN,165,length(across_casts));
attn_across = repmat(NaN,165,length(across_casts));
F_across = repmat(NaN,165,length(across_casts));
OBS_across = repmat(NaN,165,length(across_casts));
sigmat_across = repmat(NaN,165,length(across_casts));
lat_across = repmat(NaN,1,length(across_casts));
lon_across = repmat(NaN,1,length(across_casts));
depth_across = repmat(NaN,165,length(across_casts));

for index_cast = 1:length(across_casts);
    index = across_casts(index_cast);
    cast = evalin('base',['ctd' num2str(index,'%02d') 'b']);
    [m,n] = size(cast);
    temp_across(1:m,index_cast) = cast(:,7);
    sal_across(1:m,index_cast) = cast(:,9);
    F_across(1:m,index_cast) = cast(:,15);
    attn_across(1:m,index_cast) = -4*log((cast(:,16)./100));
    OBS_across(1:m,index_cast) = cast(:,11)*100;
    sigmat_across(1:m,index_cast) = cast(:,14);
    lat_across(1,index_cast) = nanmean(cast(:,5));
    lon_across(1,index_cast) = nanmean(cast(:,6));
    depth_across(1:m,index_cast) = cast(:,17);
end

%Set up the distance matrix
dist1_across = repmat(NaN,1,length(across_casts));
dist1_across(1) = 0;

dist_across = repmat(NaN,1,length(across_casts));
dist_across(1) = 0;

for index = 2:length(across_casts);
    dist1_across(index) = latlon2dist(lat_across(index),...
        lon_across(index),lat_across(index-1),lon_across(index-1));
end

for index = 2:length(across_casts);
    dist_across(index) = sum(dist1_across(1:index));
end

%Convert distances to kilometers
distkm_across = dist_across./1000;

%Grid the temperature and salinity data (i.e., line up depth bins
depth_mat = 1:0.5:83;
temp_grid_across = repmat(NaN,length(depth_mat),length(across_casts));
sal_grid_across = repmat(NaN,length(depth_mat),length(across_casts));
attn_grid_across = repmat(NaN,length(depth_mat),length(across_casts));
F_grid_across = repmat(NaN,length(depth_mat),length(across_casts));
OBS_grid_across = repmat(NaN,length(depth_mat),length(across_casts));
sigmat_grid_across = repmat(NaN,length(depth_mat),length(across_casts));

for index = 1:length(across_casts);
    for index2 = 1:length(depth_mat);
        clear in
        in = value2Index(depth_across(:,index),depth_mat(index2),0.4);
        if isnan(in) == 0;
        temp_grid_across(index2,index) = temp_across(in,index);
        sal_grid_across(index2,index) = sal_across(in,index);
        F_grid_across(index2,index) = F_across(in,index);
        attn_grid_across(index2,index) = attn_across(in,index);
        OBS_grid_across(index2,index) =  OBS_across(in,index);
        sigmat_grid_across(index2,index) = sigmat_across(in,index);
        end    
    end
end

depth_grid_across = repmat(depth_mat',1,length(across_casts));
distkm_grid_across = repmat(distkm_across,165,1);


[c,h] = contourf(distkm_grid_across,depth_grid_across,...
    temp_grid_across,temp_conts);
shading flat
set(gca,'fontsize',12)
xlabel('Distance to Station 8 (km)')
ylabel('Depth (m)')
title('Temperature Contours of CTD Data from Oceanus, Cross Axis','fontsize',14)
axis ij
hold on
[c2,h2] = contour(distkm_grid_across,depth_grid_across,...
    temp_grid_across,Tdelim,'k');
clabel(c2,h2,'rotation',0)
for index = 1:length(across_casts);
    l = line([distkm_across(index) distkm_across(index)],[0 85]);
    set(l,'color',[0.25 0.25 0.25],'linestyle','-.');
    t = text(distkm_across(index)+0.5,80,[num2str(across_casts(index))]);
    set(t,'color',[0.25 0.25 0.25]);
end
axis([-1 max(max(distkm_grid_across))+1 0 85])
fig = gca;

cb = colorbar;
axes(cb)
ylabel('Temperature (^o C)')
axes(cb)
set(gca,'ytick',temp_conts)
set(gca,'dataaspectratio',[14 2 2])
axes(fig)
set(gca,'plotboxaspectratio',[1 0.5 1])
orient landscape

figure(20)
[c,h] = contourf(distkm_grid_across,depth_grid_across,...
    sal_grid_across,sal_conts);
shading flat
set(gca,'fontsize',12)
xlabel('Distance to Station 8 (km)')
ylabel('Depth (m)')
title('Salinity Contours of CTD Data from Oceanus, Across Axis','fontsize',14)
axis ij
hold on
[c2,h2] = contour(distkm_grid_across,depth_grid_across,...
    sal_grid_across,Sdelim,'k');
clabel(c2,h2,'rotation',0)
for index = 1:length(across_casts);
    l = line([distkm_across(index) distkm_across(index)],[0 85]);
    set(l,'color',[0.25 0.25 0.25],'linestyle','-.');
    t = text(distkm_across(index)+0.5,80,[num2str(across_casts(index))]);
    set(t,'color',[0.25 0.25 0.25]);
end
axis([-1 max(max(distkm_grid_across))+1 0 85])
fig = gca;
cb = colorbar;
axes(cb)
ylabel('Salinity (o/oo)')
set(gca,'ytick',min(Sdelim):1:max(Sdelim))
set(gca,'dataaspectratio',[6 2 1])
axes(fig)
set(gca,'plotboxaspectratio',[1 0.5 1])
orient landscape

figure(21)
[c,h] = contourf(distkm_grid_across,depth_grid_across,...
    F_grid_across,F_conts);
shading flat
set(gca,'fontsize',12)
xlabel('Distance to Station 8 (km)')
ylabel('Depth (m)')
title('Fluorescence Contours of CTD Data from Oceanus, Across Axis','fontsize',14)
axis ij
hold on
[c2,h2] = contour(distkm_grid_across,depth_grid_across,...
    F_grid_across,Fdelim,'k');
clabel(c2,h2,'rotation',0)
for index = 1:length(across_casts);
    l = line([distkm_across(index) distkm_across(index)],[0 85]);
    set(l,'color',[0.25 0.25 0.25],'linestyle','-.');
    t = text(distkm_across(index)+0.5,80,[num2str(across_casts(index))]);
    set(t,'color',[0.25 0.25 0.25]);
end
axis([-1 max(max(distkm_grid_across))+1 0 85])
fig = gca;
cb = colorbar;
axes(cb)
ylabel('Fluorescence')
set(gca,'ytick',min(Fdelim):1:max(Fdelim))
set(gca,'dataaspectratio',[6 2 1])
axes(fig)
set(gca,'plotboxaspectratio',[1 0.5 1])
orient landscape

figure(22)
[c,h] = contourf(distkm_grid_across,depth_grid_across,...
    attn_grid_across,attn_conts);
shading flat
set(gca,'fontsize',12)
xlabel('Distance to Station 8 (km)')
ylabel('Depth (m)')
title('Beam Attenuation Contours of CTD Data from Oceanus, Across Axis','fontsize',14)
axis ij
hold on
[c2,h2] = contour(distkm_grid_across,depth_grid_across,...
    attn_grid_across,attndelim,'k');
clabel(c2,h2,'rotation',0)
for index = 1:length(across_casts);
    l = line([distkm_across(index) distkm_across(index)],[0 85]);
    set(l,'color',[0.25 0.25 0.25],'linestyle','-.');
    t = text(distkm_across(index)+0.5,80,[num2str(across_casts(index))]);
    set(t,'color',[0.25 0.25 0.25]);
end
axis([-1 max(max(distkm_grid_across))+1 0 85])
fig = gca;
cb = colorbar;
axes(cb)
ylabel('Beam Attenuation (m-1)')
set(gca,'ytick',min(attndelim):1:max(attndelim))
set(gca,'dataaspectratio',[6 2 1])
axes(fig)
set(gca,'plotboxaspectratio',[1 0.5 1])
orient landscape

figure(23)
[c,h] = contourf(distkm_grid_across,depth_grid_across,...
    OBS_grid_across,OBS_conts);
shading flat
set(gca,'fontsize',12)
xlabel('Distance to Station 8 (km)')
ylabel('Depth (m)')
title('Optical Backscatter Contours of CTD Data from Oceanus, Across Axis','fontsize',14)
axis ij
hold on
[c2,h2] = contour(distkm_grid_across,depth_grid_across,...
    OBS_grid_across,OBSdelim,'k');
clabel(c2,h2,'rotation',0)
for index = 1:length(across_casts);
    l = line([distkm_across(index) distkm_across(index)],[0 85]);
    set(l,'color',[0.25 0.25 0.25],'linestyle','-.');
    t = text(distkm_across(index)+0.5,80,[num2str(across_casts(index))]);
    set(t,'color',[0.25 0.25 0.25]);
end
axis([-1 max(max(distkm_grid_across))+1 0 85])
fig = gca;
cb = colorbar;
axes(cb)
ylabel('Optical Backscatter (mV)')
set(gca,'ytick',min(OBSdelim):10:max(OBSdelim))
set(gca,'dataaspectratio',[6 2 1])
axes(fig)
set(gca,'plotboxaspectratio',[1 0.5 1])
orient landscape

figure(24)
[c,h] = contourf(distkm_grid_across,depth_grid_across,...
    sigmat_grid_across,sigmat_conts);
shading flat
set(gca,'fontsize',12)
xlabel('Distance to Station 8 (km)')
ylabel('Depth (m)')
title('Sigma T Contours of CTD Data from Oceanus, Across Axis','fontsize',14)
axis ij
hold on
[c2,h2] = contour(distkm_grid_across,depth_grid_across,...
    sigmat_grid_across,sigmatdelim,'k');
clabel(c2,h2,'rotation',0)
for index = 1:length(across_casts);
    l = line([distkm_across(index) distkm_across(index)],[0 85]);
    set(l,'color',[0.25 0.25 0.25],'linestyle','-.');
    t = text(distkm_across(index)+0.5,80,[num2str(across_casts(index))]);
    set(t,'color',[0.25 0.25 0.25]);
end
axis([-1 max(max(distkm_grid_across))+1 0 85])
fig = gca;
cb = colorbar;
axes(cb)
ylabel('Sigma T (mg/cm^3)')
set(gca,'ytick',min(sigmatdelim):1:max(sigmatdelim))
set(gca,'dataaspectratio',[6 2 1])
axes(fig)
set(gca,'plotboxaspectratio',[1 0.5 1])
orient landscape