% this m file used to create parameter vs. date (at 900m) through time and parameter vs. date
    % by distinct depths.
% file loads float0005, which contains profile, date, lat, long, P, theta,
  % S, sigma, B_LSS_b_corr, Chl_b_corr, O2sat, O2
% No mat files are saved.    
    
% written by E. Boss
% UMaine
% 10/19/06    

clear all
close('all')

load float0005
% float0005 contains:
profileNum=float0005(:,1); % profile number
date=float0005(:,2); % date
lat=float0005(:,3); % latitue (degrees)
lon=float0005(:,4); % longitude (degrees)
P=float0005(:,5); % depth (dB)
theta=float0005(:,6); % potential temperature (degrees C)
S=float0005(:,7); % salinity (psu)
sigma=float0005(:,8); % sigma
B_LSS_b_corr=float0005(:,9); % bb (calibrated)
Chl_b_corr=float0005(:,10); % chlorophyll (calibrated) 
O2sat=float0005(:,11); % oxygen (% saturation) 
O2=float0005(:,12); % oxygen (um/kg) 
POC_b=float0005(:,13);
C_phy=float0005(:,14);
profile=float0005(:,15); % (in days from start)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%% PLOTS
%%%%%%%%%%%%%%%%%%%%% APEX TEMP VS DEPTH
% K=find(P>550 & P<1020);
% plot(T(K),-P(K),'.')
% title('Potential Temperature')
% ylabel('Depth [db]')
% xlabel('Potential Temperature [C]')

%%%%%%%%%%%%%%%%%%%%% APEX TEMP VS DEPTH THROUGH TIME
% scatter(tt,-P,5,theta,'filled'),colorbar
% axis([min(tt),max(tt),min(-P),-550])
% datetick('x','mmmyy')
% title('Potential temperature [C]')
% ylabel('depth [db]')
% xlabel('time [month] starting in 2004')

%%%%%%%%%%%%%%%%%%%%% APEX CHL VS DEPTH
% K=find(P>550 & P<1020);
% plot(Chl_b_corr(K),-P(K),'-')
% title('Chlorophyll')
% ylabel('Depth [db]')
% xlabel('Chlorophyll [mg/m^3]')

%%%%%%%%%%%%%%%%%%%%% APEX SAL VS DEPTH
% K=find(P>550 & P<1020);
% plot(S(K),-P(K),'.')
% title('Salinity')
% ylabel('Depth [db]')
% xlabel('Salinity [psu]')

%%%%%%%%%%%%%%%%%%%%% APEX SIDESCATTER VS DEPTH
% K=find(P>550 & P<1020);
% plot(B_LSS_b_corr(K),-P(K),'.')
% title('Side Scatter')
% ylabel('Depth [db]')
% xlabel('Side Scatter [m^{-1}]')

%%%%%%%%%%%%%%%%%%%%% APEX DENSITY VS DEPTH
% K=find(P>550 & P<1020);
% plot(sigma(K),-P(K),'.')
% title('Density')
% ylabel('Depth [db]')
% xlabel('Density-1000 [kg m^{-3}]')

%%%%%%%%%%%%%%%%%%%%% parameter vs. time and depth plots
figure(1);
% subplot(2,2,1) % density
scatter(tt,-P,5,sigma,'filled'),colorbar;
xlim([min(tt),max(tt)]);
ylim([-1050,max(-P)]);
set(gca,'FontName','Times New Roman');
set(gca,'FontSize',16);
set(gca,'XTick',[732099 732464 732829 733194 733621]);
datetick(gca,'x','mmmyy','keepticks');
title('density-1000 [kg m^{-3}]');
ylabel('depth [db]');

figure(2);
% subplot(3,3,2) % temperature
scatter(tt,-P,5,theta,'filled'),colorbar;
xlim([min(tt),max(tt)]);
ylim([-1050,max(-P)]);
set(gca,'FontName','Times New Roman');
set(gca,'FontSize',16);
set(gca,'XTick',[732099 732464 732829 733194 733621]);
datetick(gca,'x','mmmyy','keepticks');
title('Potential temperature [C]');
ylabel('depth [db]');

figure(3);
% subplot(2,2,2) % salinity
scatter(tt,-P,5,S,'filled'),colorbar;
xlim([min(tt),max(tt)]);
ylim([-1050,max(-P)]);
set(gca,'FontName','Times New Roman');
set(gca,'FontSize',16);
set(gca,'XTick',[732099 732464 732829 733194 733621]);
datetick(gca,'x','mmmyy','keepticks');
title('Salinity [PSU]');
ylabel('depth [db]');

figure(4);
% subplot(2,2,3) % chlorophyll
scatter(tt,-P,5,Chl_b_corr,'filled');
% caxis([0 2]);
colorbar
xlim([min(tt),max(tt)]);
ylim([-1050,max(-P)]);
set(gca,'FontName','Times New Roman');
set(gca,'FontSize',16);
set(gca,'XTick',[732099 732464 732829 733194 733621]);
datetick(gca,'x','mmmyy','keepticks');
title('Chlorophyll [mg/m^3]');
ylabel('depth [db]');

figure(5);
% subplot(2,2,4) % side scatter
scatter(tt,-P,5,B_LSS_b_corr,'filled');
caxis([0 0.005]);
colorbar
xlim([min(tt),max(tt)]);
ylim([-400,max(-P)]);
set(gca,'FontName','Times New Roman');
set(gca,'FontSize',16);
set(gca,'XTick',[732099 732464 732829 733194 733621]);
datetick(gca,'x','mmmyy','keepticks');
title('sidescatter [m^-1]');
ylabel('depth [db]');

% figure(6)
% % subplot(3,2,6) % oxygen (sensor no longer working)
% scatter(tt,-P,5,O2./O2sat*100,'filled'),colorbar
% caxis([90 120])
% colorbar
% axis([min(tt),max(tt),-1020,max(-P)])
% datetick('x','mmmyy')
% title('Oxygen saturation [%]')
% ylabel('depth [db]')
% xlabel('time [month] starting in 2004')

%%%%%%%%%%%%%%%%% figure 6: multi plot parameter vs. time
I0=find(P>5 & P<90);
I1=find(P>90 & P<100);
I2=find(P>200 & P<300);
I3=find(P>400 & P<500);
I4=find(P>600 & P<700);
I5=find(P>800 & P<900);
I6=find(P>950 & P<1050);
I7=find(P>5 & P<51);
I8=find(P>5 & P<101);
I9=find(P>149);
I10=find(P>119 & P<181);

figure(7);
plot(tt(I0),sigma(I0),'r.');
hold on
plot(tt(I1),sigma(I1),'b.');
plot(tt(I2),sigma(I2),'k.');
plot(tt(I3),sigma(I3),'g.');
plot(tt(I4),sigma(I4),'c.');
plot(tt(I5),sigma(I5),'y.');
plot(tt(I6),sigma(I6),'m.');
axis([min(tt),max(tt),min(sigma),max(sigma)]);
datetick('x','mmmyy');
ylabel('density-1000 [kg m^{-3}]');
title('Density');
legend('5-89m','90-100m', '200-300m', '400-500m', '600-700', '800-900', '>950');

figure(8);
plot(tt(I0),S(I0),'r.');
hold on
plot(tt(I1),S(I1),'b.');
plot(tt(I2),S(I2),'k.');
plot(tt(I3),S(I3),'g.');
plot(tt(I4),S(I4),'c.');
plot(tt(I5),S(I5),'y.');
plot(tt(I6),S(I6),'m.');
axis([min(tt),max(tt),min(S),max(S)]);
datetick('x','mmmyy');
ylabel('salinity [PSU]');
title('Salinity');
legend('5-89m','90-100m', '200-300m', '400-500m', '600-700', '800-900', '>950');

figure(9);
plot(tt(I0),theta(I0),'r.');
hold on
plot(tt(I1),theta(I1),'b.');
plot(tt(I2),theta(I2),'k.');
plot(tt(I3),theta(I3),'g.');
plot(tt(I4),theta(I4),'c.');
plot(tt(I5),theta(I5),'y.');
plot(tt(I6),theta(I6),'m.');
axis([min(tt),max(tt),min(theta),max(theta)]);
datetick('x','mmmyy');
ylabel('potential temperature [C]');
title('Potential Temperature');
legend('5-89m','90-100m', '200-300m', '400-500m', '600-700', '800-900', '>950');

figure(10);
plot(tt(I0),Chl_b_corr(I0),'r.');
hold on
% plot(tt(I1),Chl_b_corr(I1),'b.');
plot(tt(I2),Chl_b_corr(I2),'k.');
plot(tt(I3),Chl_b_corr(I3),'g.');
% plot(tt(I4),Chl_b_corr(I4),'c.');
% plot(tt(I5),Chl_b_corr(I5),'y.');
% plot(tt(I6),Chl_b_corr(I6),'m.');
axis([min(tt),max(tt),min(Chl_b_corr),max(Chl_b_corr)]);
datetick('x','mmmyy');
ylabel('chlorophyll [mg/m^3]');
title('Chlorophyll');
legend('5-89m','90-100m', '200-300m', '400-500m', '600-700', '800-900', '>950');

figure(11);
plot(tt(I0),B_LSS_b_corr(I0),'r.');
hold on
plot(tt(I1),B_LSS_b_corr(I1),'b.');
plot(tt(I2),B_LSS_b_corr(I2),'k.');
plot(tt(I3),B_LSS_b_corr(I3),'g.');
plot(tt(I4),B_LSS_b_corr(I4),'c.');
plot(tt(I5),B_LSS_b_corr(I5),'y.');
plot(tt(I6),B_LSS_b_corr(I6),'m.');
axis([min(tt),max(tt),min(B_LSS_b_corr),max(0.0015)]);
datetick('x','mmmyy');
ylabel('side scatter [m^{-1}]');
title('Side Scatter');
legend('5-89m','90-100m', '200-300m', '400-500m', '600-700', '800-900', '>950');

%%%%%%%%%% look at POC and Cphytoplankton
ratio_phy_50m=C_phy(I7)./Chl_b_corr(I7);
ratio_phy_100m=C_phy(I8)./Chl_b_corr(I8);
ratio_poc_50m=POC_b(I7)./Chl_b_corr(I7);
ratio_poc_100m=POC_b(I8)./Chl_b_corr(I8);

figure(12);
plot(C_phy(I7),Chl_b_corr(I7),'b.');
title({'C_{phy} vs Chlorophyll - Upper 50m'});
ylabel('C_{phy} [m^-1]');
xlabel('chlorophyll [mg/m^3]');

figure(13);
plot(C_phy(I8),Chl_b_corr(I8),'b.');
title({'C_{phy} vs Chlorophyll - Upper 100m'});
ylabel('C_{phy} [m^-1]');
xlabel('chlorophyll [mg/m^3]');

figure(14);
hist(ratio_phy_50m);
xlabel('C_{phy}:Chl - Upper 50m');
ylabel('Frequency');

figure(15);
hist(ratio_phy_100m);
xlabel('C_{phy}:Chl - Upper 100m');
ylabel('Frequency');

figure(16);
plot(POC_b(I7),Chl_b_corr(I7),'b.');
title({'POC vs Chlorophyll - Upper 50m'});
ylabel('POC');
xlabel('chlorophyll [mg/m^3]');

figure(17);
plot(POC_b(I8),Chl_b_corr(I8),'b.');
title({'POC vs Chlorophyll - Upper 100m'});
ylabel('POC');
xlabel('chlorophyll [mg/m^3]');

figure(18);
hist(ratio_poc_50m);
xlabel('POC:Chl - Upper 50m');
ylabel('Frequency');

figure(19);
hist(ratio_poc_100m);
xlabel('POC:Chl - Upper 100m');
ylabel('Frequency');

%%%%%%%%%% look at chl and bb vs depth
figure(20);
plot(Chl_b_corr(I9),-P(I9),'.');
title('Chlorophyll vs Depth');
ylabel('Depth [db]');
xlabel('Chlorophyll [mg/m^3]');

figure(21);
plot(B_LSS_b_corr(I9),-P(I9),'.');
title('B_b vs Depth');
ylabel('Depth [db]');
xlabel('B_b');

%%%%%%%%% average values from 120-180m
figure(22);
ratio_avgChl=Chl_b_corr(I10)./(mean(Chl_b_corr(I10)));
plot(ratio_avgChl,-P(I10),'-');

% figure
% % subplot(2,3,4) % chlorophyll
% plot(tt(I),Chl_b_corr(I),'r*');
% datetick('x','mmmyy')
% ylabel('chlorophyll [mg/m^3]')
% title('Chlorophyll [1000 ft]')

% figure
% % subplot(2,3,1) % density
% plot(tt(I),sigma(I),'o');
% datetick('x','mmmyy')
% ylabel('density-1000 [kg m^{-3}]');
 
% figure
% % subplot(2,3,2) % temperature
% plot(tt(I),theta(I),'o');
% datetick('x','mmmyy')
% ylabel('potential temperature [C]')
 
% figure
% % subplot(2,3,3) % salinity
% plot(tt(I),S(I),'o');
% datetick('x','mmmyy')
% ylabel('salinity [psu]')

% subplot(2,3,6) % oxygen INSTRUMENT NOT WORKING
% plot(tt(I),O2(I)./O2sat(I)*100,'o');
% datetick('x','mmmyy')
% ylabel('O2 saturation [%]')





