function [data] = call_plot (data)
% call_plot: calls plot routine
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if ((data.GPS.loaded==0)&(data.accel.loaded==0))
   err_text=sprintf('Please load either GPS or accel data!\n');
   fault(err_text);
   return;
end;

% call figure to get elements to plot
fig=list_select(data);
uiwait(fig);
if ~ishandle(fig)
   return;
else
   dbhandles = guidata(fig);
   answer = get(dbhandles.figure1,'UserData');
   delete(fig);
   
   if (isempty(answer)==1)
      return;
   else
      data=answer;
   end;
end;

% add wait bar
whan=waitbar(0.10,'Generating Plot, Please wait...',...
   'Name','Plotting',...
   'CloseRequestFcn','closereq',...
   'WindowStyle','Modal',...
   'Pointer','watch');
drawnow;

% get loaded fields
column=[];
for (i=1:size(data.config.field_names,1))
   if (data.config.field_ranges(i,8)~=0)
      column(data.config.field_ranges(i,8))=i;
   end;
end;
if (isempty(column)==1)
   return;
end;

% file name string
if ((data.GPS.loaded==1)&(data.accel.loaded==0))
   % file name string
   j01=findstr(data.GPS.GPS_file,'.');
   filename01=data.GPS.GPS_file(1:(j01(end)-1));
   j02=findstr(filename01,'\');
   filename02=filename01((j02(end)+1):end);
   filename=sprintf('SV Tracking Plot (GPS file - %s)',filename02);
   titlename=sprintf('GPS & ACCEL Analysis (GPS file - %s)',dir_clip(data.GPS.GPS_file,50));
elseif ((data.GPS.loaded==0)&(data.accel.loaded==1))
   % file name string
   j01=findstr(data.accel.ACCEL_file,'.');
   filename01=data.accel.ACCEL_file(1:(j01(end)-1));
   j02=findstr(filename01,'\');
   filename02=filename01((j02(end)+1):end);
   filename=sprintf('SV Tracking Plot (ACCEL file - %s)',filename02);
   titlename=sprintf('GPS & ACCEL Analysis (ACCEL file - %s)',dir_clip(data.accel.ACCEL_file,50));
elseif ((data.GPS.loaded==1)&(data.accel.loaded==1))
   % file name string
   j01=findstr(data.GPS.GPS_file,'.');
   filename01=data.GPS.GPS_file(1:(j01(end)-1));
   j02=findstr(filename01,'\');
   filename02=filename01((j02(end)+1):end);
   filename=sprintf('SV Tracking Plot (GPS file - %s)',filename02);
   titlename=sprintf('GPS & ACCEL Analysis (GPS file - %s)\n(ACCEL file - %s)',dir_clip(data.GPS.GPS_file,50),dir_clip(data.accel.ACCEL_file,50));
else
   err_text=sprintf('Please load GPS or accel data!\n');
   fault(err_text);
   return;
end;

%  generate analysis plot
[data,fig]=analysis_plot(data,column,titlename,filename,1);
data.temp=[];
rmfield(data,'temp');

% add additional function buttons
if ((data.GPS.loaded==1)&(isempty(data.GPS.observables)==0)&(data.config.auto_close==0))
   bhandle=plot_buttons(fig);
   set(bhandle,'UserData',data.GPS.observables.cycle_slip.slips);
end;

% remove wait bar
set(whan,'Pointer','arrow');
delete(whan);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
return;
