% plots six panel figure for EOS article of:
  % float and satellite chl and bb vs time
  % float chl and bb vs time and depth
  % float chl and bb vs time at 900m

% loads:
  % float0005 (generated by applyCalProfile.m)
  % MLD.txt for adding the mixed layer depth line
  % float0005Surface (generated by applyCalSurface.m)
  % modis_chl, containing satellite chl data (downloaded 01/17/08 by Peter Brickley)
  % apexModis_bb, containing satellite bb data (downloaded 01/11/08 by Peter Brickley)

% no mat files are saved

% written by E. Boss, UMaine, 2007
% email: emmanuel.boss@maine.edu

clear all
close('all')

% get float data
load float0005 % float0005 contains:
profileNum=float0005(:,1); %profile number
date=float0005(:,2); %date
lat=float0005(:,3); %latitude (degrees)
lon=float0005(:,4); %longitude (degrees)
P=float0005(:,5); %depth (m)
theta=float0005(:,6); %potential temperature (degrees C)
S=float0005(:,7); %salinity (psu)
sigma=float0005(:,8); %density-1000 (kg/m3)
B_LSS_b_corr=float0005(:,9); %bb (m-1, calibrated using MODIS data downloaded 01/11/08)
Chl_b_corr=float0005(:,10); %chlorophyll (mg/m3, calibrated using MODIS data downloaded 01/11/08) 
O2sat=float0005(:,11); %oxygen (% saturation) !oxygen sensor not working
O2=float0005(:,12); %oxygen (um/kg) !oxygen sensor not working
POC_b=float0005(:,13);
C_phy=float0005(:,14);
profile=float0005(:,15); % (in days from start)

% get surface data
load 'C:\Documents and Settings\Lisa Taylor\My Documents\Data\0005\ARGOS\float0005Surface'
% float0005Surface contains date, lat, lon, P, Chl_b_corr, B_LSS_b_corr, stat

% get first reading of the day
I=find(diff(float0005Surface(:,1))>4);
time_surf=[float0005Surface(1,1);float0005Surface(I+1,1)];
chl_surf=[float0005Surface(1,5);float0005Surface(I+1,5)];

% get modis chl data
load 'C:\Documents and Settings\Lisa Taylor\My Documents\Data\0005\MODIS\modis_chl'
% modis_chl contains:
  % modis_chl_ts (2116x2601) - chl data only from 06/13/04 - 01/01/07 THIS IS A 51X51 GRID
  % modisChl [date, chl] (2116x2602)
  % distgrid (2116x2601) grid of distance around float
modis_date=modisChl(:,1);

% get mean and median modis values within 7.5km of float
[uu vv]=size(modis_chl_ts); % 2116x2601
I7km_modis=find(distgrid(1,:)<7.5); 
for i=1:uu
   dist_7km_A_modis(i)=nanmean(modis_chl_ts(i,I7km_modis),2);
   dist_7km_B_modis(i)=nanmedian(modis_chl_ts(i,I7km_modis),2);
end

dist_7km_mean_modis=dist_7km_A_modis';
dist_7km_median_modis=dist_7km_B_modis';

% remove zeros for plots
I7k_modis=find(dist_7km_mean_modis>0);
I7kk_modis=find(dist_7km_median_modis>0);

% correlation calculation
float_sat_median_chl=interp1(modis_date(I7kk_modis), dist_7km_median_modis(I7kk_modis), time_surf, 'linear');
I=finite(float_sat_median_chl);
A1=corrcoef(float_sat_median_chl(I), chl_surf(I)); %0.8531
size(float_sat_median_chl(I)); %208

% get modis bb data to put on same figure w/chl
load 'C:\Documents and Settings\Lisa Taylor\My Documents\Data\0005\APEX\apexModis_bb.mat'

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% PLOTS
h=figure('Units','inches','Resize','on','position',[0 0 7.25 6],'paperposition',[0.5 3 7.25 6]);
figure(h); %upper left chlorophyll
% set(gcf,'position',[0 0 4.75 3.75]); %sets window location and size on figure for printing eos figure
subplot('Position',[0.11 0.72 0.31 0.15]);
plot(time_surf, chl_surf, 'bo', 'MarkerSize',3);
hold on;
plot(modis_date(I7kk_modis),dist_7km_median_modis(I7kk_modis),'k*','MarkerSize',3);
hold off;
set(gca,'FontName','Times');
set(gca,'FontSize',10);
set(gca,'LineWidth',0.75);
set(gca,'XTick',[]);
axis([min(time_surf-1) max(time_surf) 0 3.5]);
ylabel('Chl [m^{-3}]');

figure(h); %upper right bb
subplot('Position',[0.55 0.72 0.305 0.152]);
plot(floatDate, floatBb, 'bo','MarkerSize',3);
hold on;
plot(time_MODIS,b_bp,'k*','MarkerSize',3);
plot(732720,0.0122,'Marker','o','MarkerSize',[3],'MarkerFaceColor',[1 1 1],'MarkerEdgeColor','b');
plot(732720,0.009,'Marker','+','MarkerSize',[3],'MarkerFaceColor',[1 1 1],'MarkerEdgeColor','k');
hold off
set(gca,'FontName','Times');
set(gca,'FontSize',10);
set(gca,'LineWidth',0.75);
set(gca,'XTick',[]);
axis([min(floatDate-1) max(floatDate) -0.001 0.015]);
ylabel('b_{bp} [m^{-3}]');
annotation('textbox',...
  'Position',[0.72 0.78 0.1 0.1],'LineStyle','none','FitHeightToText','off',...
  'FontName','Times','FontSize',9,'String',{'Float 0005'});
annotation('textbox',...
  'Position',[0.72 0.78 0.07 0.07],'LineStyle','none','FitHeightToText','off',...
  'FontName','Times','FontSize',9,'String',{'MODIS'});

% load mixed layer depth
MLD=load('MLD.txt');
I=find(P>2);

figure(h); %middle left chlorophyll
subplot('Position',[0.1 0.33 0.36 0.35]);
scatter(date(I),-P(I),5,log10(Chl_b_corr(I)),'filled');
hold on 
plot(unique(tt),-MLD,'k','LineWidth',1)
hold off
colorbar
xlim([min(tt),max(tt)]);
ylim([-400,max(-P)]);
set(gca,'FontName','Times');
set(gca,'FontSize',10);
set(gca,'LineWidth',0.75);
set(gca,'XTick',[732115 732480 732850 733215]);
set(gca,'XTick',[]);
ylabel('Depth [db]');
annotation('textbox',...
  'Position',[0.14 0.34 0.13 0.045],'BackgroundColor',[1 1 1],'FitHeightToText','off',...
  'FontName','Times','HorizontalAlignment','center','String',{'Log_{10}\{Chl\}'});

figure(h); %middle right bb
subplot('Position',[0.55 0.33 0.36 0.35]);
scatter(tt(I),-P(I),5,log10(B_LSS_b_corr(I)),'filled');
hold on 
plot(unique(tt),-MLD,'k','LineWidth',1)
hold off
colorbar
xlim([min(tt),max(tt)]);
ylim([-400,max(-P)]);
set(gca,'FontName','Times');
set(gca,'FontSize',10);
set(gca,'LineWidth',0.75);
set(gca,'XTick',[732115 732480 732850 733215]);
set(gca,'XTick',[]);
set(gca,'YTick',[]);
annotation('textbox',...
  'Position',[0.57 0.34 0.13 0.045],'BackgroundColor',[1 1 1],'FitHeightToText','off',...
  'FontName','Times','HorizontalAlignment','center','String',{'Log_{10}\{b_{bp}\}'});

I6=find(P>899 & P<1050);

figure(h); %bottom left chlorophyll
subplot('Position',[0.115 0.14 0.305 0.15]);
plot(tt(I6),Chl_b_corr(I6),'k.');
axis([min(tt),max(tt),min(Chl_b_corr),0.05]);
set(gca,'FontName','Times');
set(gca,'FontSize',10);
set(gca,'LineWidth',0.75);
set(gca,'XTick',[732115 732480 732850 733215]);
datetick(gca,'x','mmmyy','keepticks');
ylabel('Chl [m^{-3}]');

figure(h); %bottom right bb
subplot('Position',[0.55 0.14 0.3 0.152]);
semilogy(tt(I6),B_LSS_b_corr(I6),'k.');
axis([min(tt),max(tt),0.0001,0.01]);
set(gca,'FontName','Times');
set(gca,'FontSize',10);
set(gca,'LineWidth',0.75);
set(gca,'XTick',[732115 732480 732850 733215]);
set(gca,'YTick',[0.0001 0.001 0.01]);
datetick(gca,'x','mmmyy','keepticks');
ylabel('Log_{10}\{b_{bp}\}');
set(gca,'yMinorTick','off');


