close all
clear all

StartDateNum = datenum('2-Oct-2017 09:00:00');
EndDateNum = datenum('2-Oct-2017 17:00:00');


DecodedFilesPath = '../DecodedResults/';

MatlabFilename = 'AllData.mat';


files = dir([DecodedFilesPath '*.mat']);

idx = [];    %Find indices that are interpolated data 
for i = 1:length(files)
   if(isempty(strfind(files(i).name,'_raw')))
       filenameDateNum = datenum(files(i).name(1:end-4),'yyyy.mm.ddTHH.MM.SS');
       if((filenameDateNum > StartDateNum) && (filenameDateNum < EndDateNum))
            idx = [idx i];   
       end
   end
end
foo = load([DecodedFilesPath files(idx(1)).name]);
load([DecodedFilesPath files(idx(1)).name]);
VarList = who('Time_DateNum','PC*','BC*','XB*','RC*','SC*');

for i = 2:length(idx)
  disp(files(idx(i)).name);
  data = load([DecodedFilesPath files(idx(i)).name]);
    for j = 1:length(VarList)
        cmd = [VarList{j} ' = [' VarList{j} ' ;  data.' VarList{j} '];'];
        eval(cmd);
    end
end

save([MatlabFilename],'Time_DateNum','PC_*','BC_*','SC_*','RC_*','XB_*');

