%% Get the names of all files in the directory
folder = 'C:\Users\bwerb\Documents\thoon_ww\ncfiles';
fileList = dir(folder);
fileNames = {fileList.name};
fileNames = fileNames(~ismember(fileNames, {'.', '..'}));
savefile = 1;
% Loop through to get the k0 for each nc file
n = length(fileNames);
for i = 1:n

    file = char(fileNames(i));
    
    [ww] = readncTHOON(file,-9.66638e-04,-4.11e-06,0); % read nc file, don't save
    
    % dir = char('C:\Users\bwerb\Documents\thoon_ww\mat files');
    filename = file(1:end-3);
    if savefile == 1
        % save([dir, filesep, filename,'.mat'], 'ww'); % Save the struct as a .mat file
        save([filename,'.mat'], 'ww'); % Save the struct as a .mat file
    end

end

folder = 'C:\Users\bwerb\Documents\thoon_ww\mat files';
fileList = dir(folder);
fileNames = {fileList.name};
fileNames = fileNames(~ismember(fileNames, {'.', '..'}));

[wwf] = stitchFiles(folder, fileNames,0);
    
% [wwf] = THOONK0Calc(wwf); % recalculate k0 with CanyonB estimated pH
% 
% [wwf] = THOONpH_adj(wwf); % recalculate pH with adjusted k0 value and Pcoefs.
% 
% disp({['k0_adj: ', num2str(wwf.k0_adj)],...
%     ['k0_std: ', num2str(wwf.k0_adj_std)],...
%     ['pH uncertainty: ', num2str(wwf.pH_uncertainty)]})