close all
clear all

addpath(genpath('/Volumes/Chem/ARGO_PROCESSING/MFILES/FLOATS/'));
addpath(genpath('/Users/Mau/Documents/MBARIprojects/CPF/CPFPROCESSING'));
addpath(genpath('/Users/Mau/Documents/MATLABhelp_new/ARGO_PROCESSING-master/')); %

%% PURPOSE: Process all CPF profile data from a mission. Calculates BGC
% parameters and saves each profile in .mat file
% under the same directory tree. All done in calc_BGC.m
% Here, I'm just looping through al profiles.

% Specify path to data/mission
% % ='/Volumes/CPF/CPF003/Data/TankTests/2021-8-25T21-57-38/'; % latest tank test
% path_data='/Volumes/CPF/CPF003/Data/TankTests/2021-8-31T16-23-33/';
% path_data='/Volumes/CPF/CPF003/Data/TankTests/2021-9-3T18-48-26/';

% mission='BenchTests/2021Sep22/2021-9-22T21-58-0/';
% 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-23T21-25-36/'
% mission='TankTests/2021-9-23T19-41-56/'
% mission='ParagonTests/2021Sep27/2021-9-27T18-12-43/'; % Turn BC off
% mission='ParagonTests/2021Sep27/2021-9-27T16-2-37'; % Turn BC off
% mission='ParagonTests/2021-10-1T16-3-9/'; % Deep Dive, 100m

% mission='TankTests/MICRORIDERTESTS/2021-10-4T22-43-27/'; % TankTest CPF+MR, Test Probes
% mission='TankTests/MICRORIDERTESTS/2021-10-5T22-38-16/'; % TankTest CPF+MR, SH1 & T1 probes

% mission='ParagonTests/MICRORIDER/2021-10-8T16-19-7/'; % 1st Test on the Paragon of CPF+MR, T1 and SH1 probes in. 4 profiles

% mission='ParagonTests/MICRORIDER/2021-10-8T16-19-7/'; % 1st Test on the Paragon of CPF+MR, T1 and SH1 probes in. 4 profiles

% mission='ParagonTests/MICRORIDER/2021-10-13T15-59-3/';
% mission='ParagonTests/MICRORIDER/2021-10-13/';

% mission='ParagonTests/MICRORIDER/2021-10-15T16-10-6/'; % CPF-MR PV 0.15m/s
% mission='ParagonTests/MICRORIDER/2021-10-19T16-3-9/'; % 6h mission CPF_topo1, 8 profiles

% reprocessed (% copied to root, when originally sabed in subfolder named differently)
% such that INFO structure contains float_type
% mission='ParagonTests/2021-9-16T16-33-30/';
% mission='ParagonTests/2021-10-21T18-34-19/'; % Folder within /2021-10-21OvernigthMission (failed overnight, 8profiles)
% mission='ParagonTests/2021-11-12T18-28-7/'; % Park@Depth Tests
% mission='ParagonTests/2021-11-2T17-7-28/'; % 16 profiles

% mission='TankTests/2021-10-29T0-1-23/'; % to fix SBDs

% mission='ParagonTests/MICRORIDER/2021-11-2T17-7-28/'; % Overnight Mission, attempt n2
% mission='ParagonTests/MICRORIDER/2021-11-12T18-28-7/'; % Park@Depth Tests
% mission='ParagonTests/MICRORIDER/2021-11-16T19-16-49/'; % Overnight Mission, south Bay, 19 profiles.

% mission='TankTests/2022-2-17T21-11-1/'; % TankTest, week of Feb 14
% mission='ParagonTests/2022-2-23T16-59-6/'; % Paragon Test
% mission='ParagonTests/MICRORIDER/2021-10-19T16-3-9/';
mission='ParagonTests/2022-3-14T16-30-13/'; % 6h cycle mission, failed to profile every 6h
path_data=['/Volumes/CPF/CPF003/Data/',mission];


% Reprocessed all mission directories under /ParagonTests
CPF_ID='CPF003';
dirs.root=['/Volumes/CPF/',CPF_ID,'/Data/'];

files=dir([dirs.root,'ParagonTests/2022-*']);
nf=length(files);

for f=1; %nf; % 2:nf;
path_data=[files(f).folder,'/',files(f).name,'/'];

dirs.temp=path_data;
msg_list   = dir([dirs.temp,'*.msg']); % get list of file names to process

nP=length(msg_list);

PARK=cell(nP-1,1);
% LR=cell(nP,1);

for p=1:nP-1
    msg_file=msg_list(p).name;
    cast=regexp(msg_file,'\d+(?=\.msg)','once','match');

    % filename=['CPF003_',cast,'.msg'];
    % [PARK{p}]=
    [PARK{p}]=calc_BGC_anchor(path_data,cast)
    % this function APPENDS in .mat files a data structure PARK
    % analogous to LR profile data
    % '/Volumes/CPF/CPF003/Data/matfiles/...
    % using the same directory tree as input
end

end
% NOTE: should add a line to copy or save .mat files from atlas into my local directory, as
% plot_cpf_HRctd.m will attempt to read matfiles in my local directory
