

if( exist('filename') )
   
else
  filename = input('Please enter a filename including path in single quotes (or set var fileName prior to running):');
end

delimiter = ',';
startRow = 2;

%% Format string for each line of text:
%   column1: text (%s)
%	column2: double (%f)
% For more information, see the TEXTSCAN documentation.
formatSpec = '%s%f%[^\n\r]';

%% Open the text file.
fileID = fopen(filename,'r');

%% Read columns of data according to format string.
% This call is based on the structure of the file used to generate this
% code. If an error occurs for a different file, try regenerating the code
% from the Import Tool.
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'HeaderLines' ,startRow-1, 'ReturnOnError', false);

%% Close the text file.
fclose(fileID);

%% Post processing for unimportable data.
% No unimportable data rules were applied during the import, so no post
% processing code is included. To generate code which works for
% unimportable data, select unimportable cells in a file and regenerate the
% script.

%% Allocate imported array to column variable names
RoverTime = dataArray{:, 1};
VoltageV = dataArray{:, 2};

%% Clear temporary variables
clearvars filename delimiter startRow formatSpec fileID dataArray ans;

%put time string in useful format
[date,time]=strtok(RoverTime,'T');
time=strtok(time,'T');
Roverdatetime=strcat(date,',',time);

EpochSecs=(datenum(Roverdatetime)-719529)*86400;
RvrElapsedTime=zeros(size(EpochSecs));
for i=1:size(EpochSecs,1),
        RvrElapsedTime(i,1)=(EpochSecs(i,1)-EpochSecs(1,1))/60/60; %time in dec hours
end

figure; plot(RvrElapsedTime,VoltageV,'bx');
xlabel('Elapsed Time (hr)');ylabel('Battery Voltage(V)');
% figure;plot(datenum(Roverdatetime),VoltageV,'rx')
% datetick('x','HH:MM','keepticks','keeplimits')
% 
break;
save('Pulse60', 'Roverdatetime', 'RvrElapsedTime','VoltageV');
save('Pulse61', 'Roverdatetime', 'RvrElapsedTime','VoltageV');

save('Pulse62', 'Roverdatetime', 'RvrElapsedTime','VoltageV');

load Pulse61
P61time=RvrElapsedTime;
P61V=VoltageV;
load Pulse62
P62time=RvrElapsedTime;
P62V=VoltageV;
load Pulse60
P60time=RvrElapsedTime;
P60V=VoltageV;
figure;plot(P62time,P62V,'bx',P60time,P60V,'rx',P61time,P61V,'gx');
legend('Pulse62','Pulse60','Pulse61');
xlabel('Elapsed Hours');ylabel('Battery Voltage (Volts)')