function [data,failed] = plot_accel (data)
% plot_accel: plot accel data to get time-of-sync
failed=1;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

plotdata.fig_name=sprintf('set ACCEL time-of-sync');
plotdata.title=sprintf('set ACCEL time-of-sync');
plotdata.filename='';
plotdata.window='normal';
plotdata.plot_type=1;
%plotdata.gps_week=data.week;
%plotdata.time_zone=data.time_zone;
%plotdata.dAT=data.dAT;
plotdata.x_label_type=0;
plotdata.auto_print=0;
plotdata.auto_save=0;
plotdata.auto_close=0;
plotdata.path=data.current_path;
%plotdata.errfid=data.config.errfid;

% build plot data
xdata=data.accel.PPS(:,1);
xdata=[xdata(1,1);nan;xdata;nan;xdata(end,1)];

% 1PPS plot variables
ydata=data.accel.PPS(:,data.accel.PPS_field(2));
ydata=[ydata(1,1);nan;ydata;nan;ydata(end,1)];
plotdata.array{1}=[xdata  ydata];

% set y-axis limits, ticks, precision, & label
plotdata.yaxes{1}.label='1PPS signal';
plotdata.yaxes{1}.limits=[floor(min(ydata))  ceil(max(ydata))];
plotdata.yaxes{1}.ticks=[];
plotdata.yaxes{1}.prec=0;

% set colors & linetypes
plotdata.color{1}='b';         % plot colors
plotdata.linetype{1}='-';      % plot linetypes
clear ydata;

% Z-axis accel plot variables
ydata=data.accel.PPS(:,data.accel.sync_field(2));
ydata=[ydata(1,1);nan;ydata;nan;ydata(end,1)];
plotdata.array{2}=[xdata  ydata];

% set y-axis limits, ticks, precision, & label
plotdata.yaxes{2}.label='accel (G)';
plotdata.yaxes{2}.limits=[floor(min(ydata))  ceil(max(ydata))];
plotdata.yaxes{2}.ticks=[];
plotdata.yaxes{2}.prec=0;

% set colors & linetypes
plotdata.color{2}='b';         % plot colors
plotdata.linetype{2}='-';      % plot linetypes
clear ydata;

% set x-axis limits, ticks, precision, & label
plotdata.xaxes.label='Time (seconds)';
plotdata.xaxes.limits=[xdata(1,1)  xdata(end,1)];
plotdata.xaxes.ticks=[];
plotdata.xaxes.prec=1;
clear xdata ydata;

% pass plotdata to "zplot"
fig=zplot(plotdata);

% add buttons for editing
ACCEL_sync_point=[];
bhandle=sync_buttons(fig);
set(bhandle,'UserData',ACCEL_sync_point);
uiwait(fig);
if ~ishandle(fig)
   return;
else
   answer = get(bhandle,'UserData');
   delete(fig);
   if (isempty(answer)==1)
      data.accel.ACCEL_sync_point=[];
   else
      data.accel.ACCEL_sync_point=answer;
   end;
end;

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