% Exported Harry's files as .CVS with header.  
% Opened, stripped off header, saved as .xlxs format (excel workbook)  
% Added a C to each new filename.

filename=[
    'C11E102236_20160624_141812' % Clay Bank Mud
    'C11E102236_20160701_115959' % Near VIMS Mud
    'C11E102236_20160706_142607' % Pamunkey Mud
    'C11E102236_20160714_134158' % Clay Bank Sand
    'C11E102236_20160721_122816'] % Pamunkey Sand

[r,c]=size(filename)

station=['CB'
    'GP'
    'PM'
    'cb'
    'pm']
    
for i=1:r
%% Import the data
[~, ~, raw] = xlsread([filename(i,:) '.xls']);
raw = raw(1:end,:);

%% Create output variable
data = reshape([raw{:}],size(raw));

%% Allocate imported array to column variable names
%Pressure  is column 1
%Depth is column 2
%Temp is col 3
%Cond is col 4
%Specificcond is col 5
%Salinity is col 6
%Soundvelocityis col 7
%Density is col 8

eval([ station(i,:) '=data'])
eval(['save ' station(i,:) '.asc data -ascii'])
%% Clear temporary variables
clearvars data raw;

end

figure(1)

subplot(2,1,1)

plot(CB(:,6), -CB(:,2), 'b-')
hold on
plot(GP(:,6), -GP(:,2), 'g--')
plot(PM(:,6), -PM(:,2), 'r-')
plot(cb(:,6), -cb(:,2), 'c--')
plot(pm(:,6), -pm(:,2), 'm-')

xlabel('Salinity (PSU)')
ylabel('Depth (m)')


subplot(2,1,2)

plot(CB(:,3), -CB(:,2), 'b-')
hold on
plot(GP(:,3), -GP(:,2), 'g--')
plot(PM(:,3), -PM(:,2), 'r-')
plot(cb(:,3), -cb(:,2), 'c--')
plot(pm(:,3), -pm(:,2), 'm-')

xlabel('Temp (deg C)')
ylabel('Depth (m)')
legend ('CB','GP','PM','cb','pm')
% Upper case abbreviations are muddy sites
% Lower case abbreviations are sandy sites

print (figure(1), '-dpdf',   'AllStations_Temp_Sal_CTD_Harry')

figure (2)

subplot(2,1,1)

plot(CB(:,4)/10000, -CB(:,2), 'b-')
hold on
plot(GP(:,4)/10000, -GP(:,2), 'g--')
plot(PM(:,4)/10000, -PM(:,2), 'r-')
plot(cb(:,4)/10000, -cb(:,2), 'c--')
plot(pm(:,4)/10000, -pm(:,2), 'm-')

xlabel('Conductivity (S/m)')
ylabel('Depth (m)')


subplot(2,1,2)

plot(1./(CB(:,4)/10000), -CB(:,2), 'b-')
hold on
plot(1./(GP(:,4)/10000), -GP(:,2), 'g--')
plot(1./(PM(:,4)/10000), -PM(:,2), 'r-')
plot(1./(cb(:,4)/10000), -cb(:,2), 'c--')
plot(1./(pm(:,4)/10000), -pm(:,2), 'm-')

xlabel('Calculated Resistivity (Ohm.m)')
ylabel('Depth (m)')
legend ('CB','GP','PM','cb','pm')

print (figure(2), '-dpdf',   'AllStations_Cond_Res_CTD_Harry')
