% concat_fo3_coefs.m

% concatenates the countrate to ozone conc calib coefficients for all legs.

%% initialize
clear
close all
warning('off','MATLAB:MKDIR:DirectoryExists');

%% adjust these parameters as desired, then run

root_data_path = '/Users/byronb/Raw_Data_Files.noindex/MOSAIC_2019';
path_prog = fullfile(root_data_path,'_matlab');
data_path = fullfile(root_data_path,'_scientific_analysis','raw_1min');
save_path = fullfile(root_data_path,'_processed','ship_flux_V1','flux_8192');
sfl = fullfile(save_path,'fo3_cal_coefs_all_legs.mat');

%% set matlab script path
restoredefaultpath
cd(path_prog);
addpath(genpath(path_prog));
rehash toolboxcache;

%% load p_coef arrays for each leg and concatenate

files = dir(fullfile(data_path,'*fo3_calib.mat'));

for ii=1:length(files)
    load(fullfile(data_path,files(ii).name));  % load p_coef
    if ii==1
        fco2_coef = p_coef;
    else
        fco2_coef = [fco2_coef;p_coef];
    end
end

% insert average for leg2a and leg2b coefs
fco2_coef(2,:) = (fco2_coef(2,:)+fco2_coef(3,:))/2;
fco2_coef = fco2_coef([1,2,4,5,6],:);

save(sfl,'fco2_coef');
