function SensorData = readdata(filename)
% Parser for reading txt file generated by mfet and nanofet sensors.
% Code based on Joe Warren's parser. Written by Ben Werb 2/21/24.

% These steps will need to change to accomidate other boards
tbl = readtable(filename);
tbl = tbl(:,1:end-5); % bug in the firmware creates 5 extra columns

tbl.Properties.VariableNames = {
    'SampNum1','SampTime1','VbatMain1','VbatPos1','VbatNeg1',...
    'TC_Cont1','Humidity1','Vrse1','Vrse_std1','Vk1','Vk_std1',...
    'Ik1','Ib1','SampNum2','SampTime2','VBiasPos2','Vrse2',...
    'Vrse_std2','Vk2','Vk_std2','Ik2','Ib2'}; % remame variables
tbl.Properties.VariableDescriptions = {
    'Sample Number mFET', ' SampleTime mFET MMDDYYY HHMMSS',...
    'Main battery voltage', 'VbatPos', 'VbatNeg', 'Temperature (C)',...
    'Humidity', 'Vrse', 'Vrse std', 'Vk', 'Vk std', 'Ik', 'Ib',...
    'Sample Number Nano', 'Sample Time Nano', 'VBiasPos', 'Vrse',...
    'Vrse std','Vk','Vk std','Ik','Ib'};  % Some info about vars

tbl.SampTime1.TimeZone ="UTC";
tbl.SampTime2.TimeZone ="UTC";

tbl = tbl(~isnan(tbl.VbatMain1),:);  % remove nans that are created...
% when a user interups the sensor
ii = ~ismember(tbl.SampNum1, '#0000000'); % remove these samples
tbl = tbl(ii,:);
tbl.SampNum1 = (1:length(tbl.SampNum1))';  % samp nums are uniform now 1:n
tbl.SampNum2 = (1:length(tbl.SampNum2))';
SensorData = tbl;
end