load('codePaths.mat')
load([path_data,'\MGN_Data.mat'])

navDates = allNavData(:,6);
gravDates = allGravData(:,6);


if exist ([path_data,'\Grav_Nav_Data.mat'],'file')
    load([path_data,'\Grav_Nav_Data.mat'])
    tmp = gravLLData;
    gravNavData = allNavData;
    gravNavData((navDates(:,1) >= tmp(end,6))==0,:) = [];
else
    gravLLData = [];
    gravLLDataTitles = {'Year','Day','Hour','Minute','Second','Serial Date','Time Difference (s)','Latitude','Longitude','Raw Counts'};
    gravNavData = allNavData;
    gravNavData((navDates(:,1) >= gravDates(1,1))==0,:) = [];
end

sGN = size(gravNavData);
if sGN(1,1) < 2
    sGN(1,1) = 0;
end
tt = zeros(sGN,10);
for i = 1:sGN(1,1)
    disp(sprintf('Processing Grav %d / %d',i,sGN(1,1)))
    mm = abs(gravDates-gravNavData(i,6));
    [index,~] = find(mm == min(mm),1);
%     gravLLData = [gravLLData;allGravData(index,1:7),gravNavData(i,10:11),allGravData(index,9)];
    tt(i,:) = [allGravData(index,1:7),gravNavData(i,10:11),allGravData(index,9)];
end
tt = [gravLLData;tt];

dif = diff(gravLLData(:,6),1,1);
dif = [0;dif];
gravLLData(:,7) = dif;

save([path_data,'\Grav_Nav_Data.mat'],'gravLLData','gravLLDataTitles','-v7')