-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadCalkulateResultFile.m
123 lines (112 loc) · 5.3 KB
/
readCalkulateResultFile.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
function T = readCalkulateResultFile(file)
% readCalkulateResultFile Reads a result file from AlkalinityAnalysis
% READCALKULATERESULTFILE reads the .csv result file from an
% AlkalinityAnalysis export (via calkulateDatasetToCSV) and returns the data
% as a table.
%
% Syntax
% T = READCALKULATERESULTFILE(file)
%
% Description
% T = READCALKULATERESULTFILE(file) reads the .csv file at the fullpath file
% and returns it as a table T.
%
% Example(s)
% T = READCALKULATERESULTFILE('~/TA-measurement.results.csv')
%
%
% Input Arguments
% file - absolute path to file
% char
% The absolute path to the .csv file to read.
%
%
% Output Arguments
% T - output table
% table
% The data from the .csv file returned as a table.
%
%
% Name-Value Pair Arguments
%
%
% See also READTABLE
%
% Copyright (c) 2022-2022 David Clemens ([email protected])
%
if exist(file,'file') ~= 2
error('Utilities:readCalkulateResultFile:FileNotExisting',...
'The file ''%s'' is does not exist.',file)
end
% Define attributes
% Name Description Units formatSpec
variableAttributes = {...
'Index', '', '', '%f';...
'AnalysisBatch', '', '', '%C';...
'MeasurementType', '', '', '%C';...
'FilePath', '', '', '%s';...
'FileName', '', '', '%s';...
'FileGood', '', '', '%s';...
'ReferenceGood', '', '', '%s';...
'Salinity', '', 'PSU', '%f';...
'AnalyteVolume', '', 'mL', '%f';...
'DIC', '', 'µmol kg-1', '%f';...
'Titrant', '', '', '%C';...
'TitrantAmountUnit', '', '', '%C';...
'MolinityHCl', '', 'mol L-1', '%f';...
'MolinityNaCl', '', 'mol L-1', '%f';...
'AlkalinityCertified', '', 'µmol kg-1', '%f';...
'Emf0Guess', '', 'mV', '%f';...
'SampleId', '', '', '%s';...
'TitrationStart', '', '', '%D';...
'TitrationDuration', '', 'min', '%s';...
'AnalyteMass', '', 'kg', '%f';...
'TitrantMolinity_here', '', 'mol L-1', '%f';...
'TitrantMolinity', '', 'mol L-1', '%f';...
'Status', '', '', '%C';...
'Alkalinity', '', 'µmol kg-1', '%f';...
'AlkalinityGran', '', 'µmol kg-1', '%f';...
'AlkalinityGran_estimate', '', 'µmol kg-1', '%f';...
'AlkalinityNPoints', '', '', '%f';...
'AlkalinityStd', '', 'µmol kg-1', '%f';...
'Emf0', '', 'mV', '%f';...
'Emf0Gran', '', 'mV', '%f';...
'Emf0GranEstimate', '', 'mV', '%f';...
'PHInitial', '', '', '%f';...
'TemperatureInitial', '', '°C', '%f';...
'AlkalinityOffset', '', 'µmol kg-1', '%f'};
% The column format spec
formatSpec = cat(2,variableAttributes{:,4});
% Read the data
T = readtable(file,...
'FileType', 'text',...
'Delimiter', ';',...
'Encoding', 'ISO-8859-2',...
'Format', formatSpec,...
'ReadVariableNames', true);
% Assign attributes
T.Properties.VariableNames = variableAttributes(:,1);
T.Properties.VariableDescriptions = variableAttributes(:,2);
T.Properties.VariableUnits = variableAttributes(:,3);
% Modify time format
T.TitrationStart.Format = 'dd.MM.yyyy HH:mm:ss';
% Modify duration
tokens = regexp(T{:,'TitrationDuration'},'^(\d+)\sdays\s(\d{2}):(\d{2}):(\d{2})$','tokens','forceCellOutput');
tokens = cat(1,tokens{:});
tokens = str2double(cat(1,tokens{:}));
T.TitrationDuration = duration(24.*tokens(:,1) + tokens(:,2),tokens(:,3),tokens(:,4));
% Modify booleans
T.FileGood = str2logical(T{:,'FileGood'});
T.ReferenceGood = str2logical(T{:,'ReferenceGood'});
% Modify status
tokens = regexp(cellstr(T{:,'Status'}),'\[[\d;]+m([A-Za-z]+)','tokens','forceCellOutput');
tokens = cat(1,tokens{:});
T.Status = categorical(cat(1,tokens{:}));
% Add sampleType column
sampleType = repmat({'Standard'},size(T,1),1);
sampleType(isnan(T{:,'AlkalinityCertified'})) = {'Sample'};
T.SampleType = categorical(sampleType);
function l = str2logical(str)
l = cellfun(@(x) strcmp(x,'True'),str);
end
end