%% Automating processing of data for spray calibration
specdata = '20240404_034_k0_SpecpH.txt';
spraydata = '20240404_034_TT_k0.txt';
%% spec pH
% Read the table from the spec pH text file
specpH = readtable(specdata);

% Filter out rows where the 'Comments' column contains 'junk'
filteredSpecpH = specpH(~contains(specpH.Comments, 'junk'), :);

% Select the first row from the filtered data
firstRow = filteredSpecpH(1, :);

% Extract the pH value
spec_pH = firstRow.pH_tot;
spec_T = firstRow.Temp_used;

[indices, selectedLines] = indexLinesWithPattern(spraydata, 'Z_1>');
data = cellstr(selectedLines);
data = data(~contains(data,'SBE'));

for i = 1:height(data)
    data(i,1:3) = strsplit(char(data(i)),'  ');
end

data = str2double(data);

mn = mean(data);

CTD_T = mn(1,2);
CTD_Sal = mn(1,3);
%%
[indices, selectedLines] = indexLinesWithPattern(spraydata, 'A_1>');
vrsedata = cellstr(selectedLines);
vrsedata = vrsedata(contains(vrsedata,':'));
for i = 1:height(vrsedata)
    vrsedata(i,1:9) = strsplit(char(vrsedata(i)),'\t');
end

vrse = str2double(vrsedata(:,4)); % 4 is vrse, 5 is vrse std. date, time imports as datetime (1 col not 2)
vrse = mean(vrse);