function [data,failed] = sync_accel (data)
% sync_accel: syncronizes acceloration data
failed=1;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% plot GPS data to get the time-of-sync
[data,fail]=plot_gps(data);
if ((fail==1)|(isempty(data.accel.GPS_sync_point)==1))
   fprintf('No GPS sync point to proceed with!\n');
   return;
end;

% plot ACCEL data to get the time-of-sync
[data,fail]=plot_accel(data);
if ((fail==1)|(isempty(data.accel.ACCEL_sync_point)==1))
   fprintf('No ACCEL sync point to proceed with!\n');
   return;
end;

% ACCEL data time conversions
data.accel.accel(:,1)=data.accel.accel(:,1)-data.accel.accel(1,1)-data.accel.ACCEL_sync_point+data.accel.GPS_sync_point;

% save file
whan=waitbar(0.10,'Saving Accel Data, Please wait...',...
   'Name','Saving',...
   'CloseRequestFcn','closereq',...
   'WindowStyle','Modal',...
   'Pointer','watch');
drawnow
clock_start=toc;
junk=data.accel;
save(data.accel.MAT_file,'junk');
set(whan,'Pointer','arrow');
delete(whan);
drawnow;
fprintf(strcat('Accel Save Completed, Runtime: %.1f seconds (%.1f minutes)\n'),(toc-clock_start),(toc-clock_start)/60);
clear junk;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
failed=0;
return;
