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

plotdata.fig_name=sprintf('set GPS time-of-sync');
plotdata.title=sprintf('set GPS time-of-sync');
plotdata.filename='';
plotdata.window='normal';
plotdata.plot_type=1;
plotdata.gps_week=data.GPS.week;
plotdata.time_zone=data.GPS.time_zone;
plotdata.dAT=data.GPS.dAT;
plotdata.x_label_type=4;
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
% plot variables
xdata=data.GPS.position(:,1);
ydata=data.GPS.position(:,14);
xdata=[xdata(1,1);nan;xdata;nan;xdata(end,1)];
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='GPS Vel (m/s)';
plotdata.yaxes{1}.limits=[floor(min(ydata))  ceil(max(ydata))];
plotdata.yaxes{1}.ticks=[];
plotdata.yaxes{1}.prec=3;

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

% set x-axis limits, ticks, precision, & label
if (data.GPS.time_zone==0)
   plotdata.xaxes.label=sprintf('GPS seconds (week %.f) & UTC Time',data.GPS.week);
else
   plotdata.xaxes.label=sprintf('GPS seconds (week %.f) & Local Time (UTC + %.0f)',data.GPS.week,data.GPS.time_zone);
end;
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
GPS_sync_point=[];
bhandle=sync_buttons(fig);
set(bhandle,'UserData',GPS_sync_point);
uiwait(fig);
if ~ishandle(fig)
   return;
else
   answer = get(bhandle,'UserData');
   delete(fig);
   if (isempty(answer)==1)
      data.accel.GPS_sync_point=[];
   else
      data.accel.GPS_sync_point=answer;
   end;
end;

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