function [data,failed] = load_accel (data)
% load_accel: loads processed accel 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;
[ACCELfilename,ACCELpathname]=uigetfile({'*.mat', 'MAT Files (*.mat)';
   '*.*', 'All Files (*.*)'},'Select Processed Accel File');
cd(pwdir);
warning off;
data.accel.MAT_file=strcat(ACCELpathname,ACCELfilename);      % concatinate strings for filename
warning on;
if ((isempty(data.accel.MAT_file)==1)|(exist(data.accel.MAT_file)==0))
   fprintf('MAT file does not exist!\n');
   return;
else
   data.current_path=ACCELpathname;
end;

% load saved file
whan=waitbar(0.10,'Loading ACCEL Data, Please wait...',...
   'Name','Loading',...
   'CloseRequestFcn','closereq',...
   'WindowStyle','Modal',...
   'Pointer','watch');
drawnow
clock_start=toc;
junk=[];
load(data.accel.MAT_file);
set(whan,'Pointer','arrow');
delete(whan);
fprintf(strcat('Accel 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,'ACCEL_file')==1));
   if (strcmp(junk.MAT_file,data.accel.MAT_file)==0)
      set_name=1;
      MAT_file=data.accel.MAT_file;
   else
      set_name=0;
   end;
   data.accel=[];
   data.accel=junk;
   clear junk;
   if (set_name==1)
      % change (update) directory names
      data.accel.MAT_file=MAT_file;
      j01=findstr(MAT_file,'\');
      directory=MAT_file(1:(j01(end)));
      
      j02=findstr(data.accel.ACCEL_file,'\');
      ACCEL_filename=data.accel.ACCEL_file((j02(end)+1):end);
      data.accel.ACCEL_file=[directory ACCEL_filename];
      
      if (isempty(data.accel.PPS_file)==0)
         j03=findstr(data.accel.PPS_file,'\');
         PPS_filename=data.accel.PPS_file((j03(end)+1):end);
         data.accel.PPS_file=[directory PPS_filename];
      end;
      
%       % 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;
   end;
else
   err_text=sprintf('Accel save file has been corrupted!\n');
   fault(err_text);
   return;
end;
data.accel.loaded=1;

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