% Blocking out the parser one function at a time
%

filename = '20240306.txt'; % Input to the function

%

% Split filename into two distinct files that contain data and meta data
DataStart(filename);
MetaStart(filename);

%

% Create a table and format correctly
data = readtable('datafile.txt');
data = data(:,1:end-5); % bug in the firmware creates 5 extra columns
data.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
data.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 meta data.
data.SampTime1.TimeZone ="UTC"; % Set timezone
data.SampTime2.TimeZone ="UTC"; 

data = data(~isnan(data.VbatMain1),:);  % remove nans that are created...
% when a user interups the sensor
ii = ~ismember(data.SampNum1, '#0000000'); % remove these samples because
% they are off the standardized grid time
data = data(ii,:);
data.SampNum1 = (1:length(data.SampNum1))';  % samp nums are uniform now 1:n
data.SampNum2 = (1:length(data.SampNum2))';

%

meta = readtable('metafile.txt'); % not correct

%

delete('datafile.txt') % removes file created by DataStart
delete('metafile.txt') % removes file created by MetaStart

%

