function [data,failed] = load_GPS (data)
% load_GPS: loads processed GPS data
failed=1;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

pwdir=pwd;
if ((exist(data.current_path)==7)|(exist(data.current_path(1:end-1))==7))
   cd(data.current_path);
else
   data.current_path=pwd;
end;
[GPSfilename,GPSpathname]=uigetfile({'*.mat', 'MAT Files (*.mat)';
   '*.*', 'All Files (*.*)'},'Select Processed GPS File');
cd(pwdir);
warning off;
data.GPS.MAT_file=strcat(GPSpathname,GPSfilename);      % concatinate strings for filename
warning on;
if ((isempty(data.GPS.MAT_file)==1)|(exist(data.GPS.MAT_file)==0))
   fprintf('MAT file does not exist!\n');
   return;
else
   data.current_path=GPSpathname;
end;

% load saved file
whan=waitbar(0.10,'Loading GPS Data, Please wait...',...
   'Name','Loading',...
   'CloseRequestFcn','closereq',...
   'WindowStyle','Modal',...
   'Pointer','watch');
drawnow
clock_start=toc;
junk=[];
load(data.GPS.MAT_file);
set(whan,'Pointer','arrow');
delete(whan);
fprintf(strcat('GPS Load Completed, Runtime: %.1f seconds (%.1f minutes)\n'),(toc-clock_start),(toc-clock_start)/60);
drawnow;

if ((isempty('junk')==0)&(isfield(junk,'MAT_file')==1)&(isfield(junk,'GPS_file')==1));  %&(strcmp(junk.MAT_file,data.GPS.MAT_file)==1)&(exist(junk.GPS_file)==2))
   if (strcmp(junk.MAT_file,data.GPS.MAT_file)==0)
      set_name=1;
      MAT_file=data.GPS.MAT_file;
   else
      set_name=0;
   end;
   data.GPS=[];
   data.GPS=junk;
   clear junk;
   if (set_name==1)
      % change directory names
      j01=findstr(MAT_file,'\');
      directory=MAT_file(1:(j01(end)));
      j02=findstr(data.GPS.GPS_file,'\');
      filename=data.GPS.GPS_file((j02(end)+1):end);
      data.GPS.MAT_file=MAT_file;
      data.GPS.GPS_file=[directory filename];
      
%       % save file
%       whan=waitbar(0.10,'Saving GPS Data, Please wait...',...
%          'Name','Saving',...
%          'CloseRequestFcn','closereq',...
%          'WindowStyle','Modal',...
%          'Pointer','watch');
%       drawnow
%       clock_start=toc;
%       junk=data.GPS;
%       save(data.GPS.MAT_file,'junk');
%       set(whan,'Pointer','arrow');
%       delete(whan);
%       drawnow;
%       fprintf(strcat('GPS Save Completed, Runtime: %.1f seconds (%.1f minutes)\n'),(toc-clock_start),(toc-clock_start)/60);
%       clear junk;
   end;
else
   err_text=sprintf('GPS save file has been corrupted!\n');
   fault(err_text);
   return;
end;
data.GPS.loaded=1;

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