clear all
close all

%% PURPOSE: Plot low res BGC data from CPF .mat files 
%  NOTE: .mat files saved from process_CPFprofiles.m
%  Magdalena Carranza

%% Path to data (CPF mission)

mission='\ParagonTests\MICRORIDER\OvernightMission\2021-10-21T18-34-19\';
% mission='ParagonTests/2021-9-16T16-33-30/';
% mission='TankTests/2021-9-9T21-6-13/';
% mission='TankTests/2021-9-9T17-33-2/';
% mission=['TankTests/2021-9-3T18-48-26/'];
% mission='TankTests/2021-8-25T21-57-38/';
% % mission='TankTests/2021-8-31T16-23-33/';

maxp=100; % set for plotting

data_root='/Volumes/CPF/CPF003/Data/';
dir_plots=['/Volumes/CPF/CPF003/Data/data_processing/plots/'];

data_root=['\\atlas\ProjectLibrary\CPF\CPF003\Data\'];% from local folder on windows
dir_plots=[data_root,'data_processing\plots'];

path_data=[data_root,'matfiles',mission]; % 
dirs.mat=path_data;

%% Create directory to save plots (if it doesn't exist already)
% subdir=mission;
% path_plots=[dir_plots,subdir];
% % plots_root='/Users/Mau/Documents/MBARIprojects/w_ctd/cpf/plots/';
% % path_plots=['/Users/Mau/Documents/MBARIprojects/w_ctd/cpf/plots/',subdir];

path_plots=[dir_plots,mission];
if isfolder(path_plots)==0 && numel(dir(path_plots))<=2 % will create directory only if it is empty!
    mkdir(path_plots)
end

%% List .mat files (output from process_CPF_profiles)
mat_list=dir([dirs.mat,'*.mat']);
% mat_file=[dirs.mat,'CPF003.001.mat'];
% load(mat_file)

%% Loop through files
nf=length(mat_list); % number of files to process

% Preallocate memory
PRES=nan(50,nf); TEMP=PRES; PSAL=PRES;
DOXY=PRES;
CHLA=PRES;
BBP=PRES;
NO3=PRES;
PH=PRES;
OCR1=PRES;
OCR2=PRES;
OCR3=PRES;
OCR4=PRES;

for f=1:nf
    mat_file=mat_list(f).name;
    load([path_data,mat_file])
    
    % arrange in matrix for plotting
    nz=length(LR.PRES);
                                           
    DOXY(1:nz,f)=LR.DOXY; 
    NO3(1:nz,f)=LR.NITRATE;
    CHLA(1:nz,f)=LR.CHLA;
    BBP(1:nz,f)=LR.BBP700;
    PH(1:nz,f)=LR.PH_IN_SITU_TOTAL;
    
    OCR1(1:nz,f)=LR.OCR1;  
    OCR2(1:nz,f)=LR.OCR2;
    OCR3(1:nz,f)=LR.OCR3;
    OCR4(1:nz,f)=LR.OCR4;
    
    PRES(1:nz,f)=LR.PRES;
    TEMP(1:nz,f)=LR.TEMP;
    PSAL(1:nz,f)=LR.PSAL;
end
%% ------------  PLOT LOW RES BGC DATA ------------------------------------
tname=mission; % mission name for plot labels

%% T & S

figure(1)
% Sal
subplot(121)
plot(PSAL,PRES,'-o')
axis ij
ylim([0 maxp])
xlabel('Sal')

title(tname);

% Temp
subplot(122)
plot(TEMP,PRES,'-o')
axis ij
ylim([0 maxp])
xlabel('Temp')

print_setup(20,30)
% print([path_plots,'TS_allprofiles.eps'],'-depsc2');
print([path_plots,'TS_allprofiles.jpg'],'-djpeg');

%% Oxygen Concentration

figure(2)

% subplot(131)
plot(DOXY,PRES,'-o')
axis ij
ylim([0 maxp])
ylabel('Pressure [dbar]')
xlabel('[O_2]')

% subplot(132)
% plot(O2data(:,6),O2data(:,3),'-o')
% axis ij
% xlabel('O2_{sol}')
% 
% subplot(133)
% plot(O2data(:,7),O2data(:,3),'-o')
% axis ij
% xlabel('pO2')

title(tname);

print_setup(20,30)
% print([path_plots,'DOXY_allprofiles.eps'],'-depsc2');
print([path_plots,'DOXY_allprofiles.jpg'],'-djpeg');

%% NO3

figure(3)

plot(NO3,PRES,'-o')
axis ij
ylim([0 maxp])
ylabel('Pressure [dbar]')
xlabel('NO_3')

title(tname);

print_setup(20,30)
% print([path_plots,'NITRATE_allprofiles.eps'],'-depsc2');
print([path_plots,'NITRATE_allprofiles.jpg'],'-djpeg');

%% PH

figure(4)

plot(PH,PRES,'-o')
axis ij
ylim([0 maxp])
ylabel('Pressure [dbar]')
xlabel('PH')

title(tname);

print_setup(20,30)
%print([path_plots,'PH_allprofiles.eps'],'-depsc2');
print([path_plots,'PH_allprofiles.jpg'],'-djpeg');

%% FLBB

figure(5)

subplot(121)
plot(CHLA,PRES,'-o')
axis ij
ylim([0 maxp])
ylabel('Pressure [dbar]')
xlabel('Chla')

title(tname);

subplot(122)
plot(BBP,PRES,'-o')
axis ij
ylim([0 maxp])
ylabel('Pressure [dbar]')

xlabel('Bbp_{700}')

print_setup(40,30)
% print([path_plots,'FLBB_allprofiles.eps'],'-depsc2');
print([path_plots,'FLBB_allprofiles.jpg'],'-djpeg');

%% OCR

figure(6)

subplot(141)
semilogx(OCR1,PRES,'-o')
axis ij
ylim([0 maxp])
xlim([0 6])
ylabel('Pressure [dbar]')
xlabel('OCR_{1}')

title(tname);

subplot(142)
semilogx(OCR2,PRES,'-o')
axis ij
ylim([0 maxp])
xlim([0 6])
ylabel('Pressure [dbar]')
xlabel('OCR_{2}')


subplot(143)
semilogx(OCR3,PRES,'-o')
axis ij
ylim([0 maxp])
xlim([0 6])
ylabel('Pressure [dbar]')
xlabel('OCR_{3}')

subplot(144)
semilogx(OCR4,PRES,'-o')
axis ij
ylim([0 maxp])
% xlim([0 1])
ylabel('Pressure [dbar]')
xlabel('OCR_{4}')

print_setup(60,30)
% print([path_plots,'OCR_allprofiles.eps'],'-depsc2');
print([path_plots,'OCR_allprofiles.jpg'],'-djpeg');
