close all
clear all

Directories = dir('./Copy*');

TotalCycles = 0;
for j = 1:length(Directories)
    ResultsPath = [Directories(j).name '\'];
    
    LogFile = [ResultsPath 'TestLog.txt'];
    
    %Find High Rate Values
    [fl, p] = grep('-u -n', {'High Rate'}, LogFile);
    CycleNum = zeros(length(p.match),1);
    for i = 1:length(p.match)
        tmp = p.match{i};
        idx = strfind(tmp,'#');  jdx = strfind(tmp,':  ');  HighRateData.CycleNum(TotalCycles+i) = TotalCycles+str2double(tmp(idx+1:jdx-1));
        idx = strfind(tmp,'=');  jdx = strfind(tmp,'A-Hr');  HighRateData.Capacity(TotalCycles+i) = str2double(tmp(idx+1:jdx-1));
    end
    
    %Find Low Rate Values
    [fl, p] = grep('-u -n', {'Low Rate'}, LogFile);
    CycleNum = zeros(length(p.match),1);
    for i = 1:length(p.match)
        tmp = p.match{i};
        idx = strfind(tmp,'#');  jdx = strfind(tmp,':  ');  LowRateData.CycleNum(TotalCycles+i) = TotalCycles+str2double(tmp(idx+1:jdx-1));
        idx = strfind(tmp,'=');  jdx = strfind(tmp,'A-Hr');  LowRateData.Capacity(TotalCycles+i) = str2double(tmp(idx+1:jdx-1));
    end
    
    TotalCycles = max([LowRateData.CycleNum HighRateData.CycleNum])   
end

n = 5;
b = ones(n,1)/n;
SmoothedHighRateCapacity = filtfilt(b,1,HighRateData.Capacity);

figure('Position',[ 1000         589        1366         909],'PaperPositionMode','manual','PaperOrientation','landscape','PaperType','usletter','PaperPosition',[0 0 11 8.5]);
plot(LowRateData.CycleNum,LowRateData.Capacity,HighRateData.CycleNum,HighRateData.Capacity,HighRateData.CycleNum,SmoothedHighRateCapacity,'--');
xlabel('Cycle Number')
ylabel('Capacity (A-Hr)')
idx = strfind(tmp,' to ');
title(['Capacity to 10.5V at 1.4A']);
legend('Low-Rate Charging (C/4)','Pulsed High-Rate Charging (mean = C/4)');
print('-dpdf','CapacityTrend');

