function varargout = vibration(varargin)
% VIBRATION M-file for vibration.fig
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%      VIBRATION, by itself, creates a new VIBRATION or raises the existing
%      singleton*.
%
%      H = VIBRATION returns the handle to a new VIBRATION or the handle to
%      the existing singleton*.
%
%      VIBRATION('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in VIBRATION.M with the given input arguments.
%
%      VIBRATION('Property','Value',...) creates a new VIBRATION or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before vibration_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to vibration_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help vibration

% Last Modified by GUIDE v2.5 11-Mar-2003 15:25:56

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
   'gui_Singleton',  gui_Singleton, ...
   'gui_OpeningFcn', @vibration_OpeningFcn, ...
   'gui_OutputFcn',  @vibration_OutputFcn, ...
   'gui_LayoutFcn',  [] , ...
   'gui_Callback',   []);
if nargin & isstr(varargin{1})
   gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
   [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
   gui_mainfcn(gui_State, varargin{:});
end

% End initialization code - DO NOT EDIT
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
return;


% --- Executes just before vibration is made visible.
function vibration_OpeningFcn(hObject, eventdata, handles, varargin)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Choose default command line output for vibration
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

clc;
tic;
set(0,'ShowHiddenHandles','on');
set(handles.figure1,'units','pixels');
data=[];
data.config.version='1.24';
data.config.GPS_min_version='1.22';
data.config.ACCEL_min_version='1.20';

% load option file
opt_file='vibration.opt';
if (exist(opt_file)~=2)
   err_text=sprintf('Option file "%s" is missing!',opt_file)';
   fault(err_text);
   closereq;
   return;
else
   [data,fail]=read_opt(data,opt_file);
   if (fail==1)
      closereq;
      return;
   end;
end;

restore_defaults=1;
if (exist('user.mat')==2)
   % load GUI inputs to files
   load('user.mat');
   
   % check the version
   if ((isfield(settings.config,'version')==0)|(strcmp(settings.config.version,data.config.version)==0))
      err_text='The saved configurations are from a previous version of Vibration & cannot be restored!  Defaults will be restored.';
      fault(err_text);
      delete('user.mat');
   else
      restore_defaults=0;
   end;
   
   if (restore_defaults==0)
      % reposition figure
      position=get(handles.figure1,'Position');
      screen=get(0,'ScreenSize');
      if (((settings.position(1)+settings.position(3))<screen(3))&...
            ((settings.position(2)+settings.position(4))<screen(4)))
         set(handles.figure1,'Position',[settings.position(1:2) position(3:4)]);
      end;
      
      % get current directory
      data.current_path=settings.current_path;
      
      % plot settings
      data.config.single_axes=settings.config.single_axes;
      data.config.disp_position=settings.config.disp_position;
      data.config.single_label=settings.config.single_label;
      
      % reset radiobuttons
      data.config.auto_close=settings.config.auto_close;
      data.config.file_save=settings.config.file_save;
      data.config.print=settings.config.print;
      
      % time settings
      data.config.week=settings.config.week;
      data.config.time_zone=settings.config.time_zone;
      data.config.dAT=settings.config.dAT;
      data.config.rate=settings.config.rate;
      
      % accel plot settings
      data.config.accel.time.plot_by_location=settings.config.accel.time.plot_by_location;
      data.config.accel.time.single_axes=settings.config.accel.time.single_axes;
      data.config.accel.time.plot_mag=settings.config.accel.time.plot_mag;
      data.config.accel.time.y_limits=settings.config.accel.time.y_limits;
      data.config.accel.freq.n_fft=settings.config.accel.freq.n_fft;
      data.config.accel.freq.sample_rate=settings.config.accel.freq.sample_rate;
      data.config.accel.freq.backtracking=settings.config.accel.freq.backtracking;
      data.config.accel.freq.windowing=settings.config.accel.freq.windowing;
      data.config.accel.freq.max_hold=settings.config.accel.freq.max_hold;
      data.config.accel.freq.show_EC1=settings.config.accel.freq.show_EC1;
      data.config.accel.freq.plot_by_location=settings.config.accel.freq.plot_by_location;
      data.config.accel.freq.single_axes=settings.config.accel.freq.single_axes;
      data.config.accel.freq.plot_mag=settings.config.accel.freq.plot_mag;
      data.config.accel.freq.y_limits=settings.config.accel.freq.y_limits;
      data.config.accel.freq.x_limits=settings.config.accel.freq.x_limits;
      data.config.accel.amp.plot_by_location=settings.config.accel.amp.plot_by_location;
      data.config.accel.amp.single_axes=settings.config.accel.amp.single_axes;
      data.config.accel.amp.plot_mag=settings.config.accel.amp.plot_mag;
      data.config.accel.amp.x_limits=settings.config.accel.amp.x_limits;
      data.config.accel.amp.mag_sort=settings.config.accel.amp.mag_sort;
   end;
end;

if (restore_defaults==1)
   % get current directory
   data.current_path=pwd;
   
   % plot settings
   data.config.single_axes=0;
   data.config.disp_position=0;
   data.config.single_label='';
   
   % initialize radio buttons
   data.config.auto_close=0;
   data.config.file_save=0;
   data.config.print=0;
   
   % time inputs
   data.config.week=0;
   data.config.time_zone=-6;
   data.config.dAT=32;
   data.config.rate=0.1;
   
   % accel plot defaults
   data.config.accel.time.plot_by_location=1;
   data.config.accel.time.single_axes=0;
   data.config.accel.time.plot_mag=1;
   data.config.accel.time.y_limits=[-150 150 50];
   data.config.accel.freq.n_fft=4096;            % FFT step
   data.config.accel.freq.sample_rate=1000;      % sample rate
   data.config.accel.freq.backtracking=[0 1000]; % number of samples to backtrack (advances at 4000 samples per computation)
   data.config.accel.freq.windowing=1;           % boolean (Hanning)
   data.config.accel.freq.max_hold=0;
   data.config.accel.freq.show_EC1=1;            % show the EC1 vibration curve
   data.config.accel.freq.plot_by_location=1;    % plot by location vs. axes
   data.config.accel.freq.single_axes=1;         % plot in a single axis
   data.config.accel.freq.plot_mag=1;            % plot vector magnitude
   data.config.accel.freq.y_limits=[0.001 100];
   data.config.accel.freq.x_limits=[1 500];
   data.config.accel.amp.plot_by_location=1;
   data.config.accel.amp.single_axes=1;
   data.config.accel.amp.plot_mag=1;
   data.config.accel.amp.x_limits=[0 150 25];
   data.config.accel.amp.mag_sort=0;
end;
set(handles.checkbox1,'value',data.config.auto_close);
set(handles.checkbox2,'value',data.config.file_save);
set(handles.checkbox3,'value',data.config.print);
set(handles.text7,'string','GPS/Accel Data Synchronized: false');

% initialize variables
data.GPS=[];
data.GPS.loaded=0;
data.GPS.field_names={};
data.GPS.field_location=[];
data.GPS.field_ranges=[];
data.accel=[];
data.accel.loaded=0;

set(handles.figure1,'UserData',data);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
return;


% --- Outputs from this function are returned to the command line.
function varargout = vibration_OutputFcn(hObject, eventdata, handles)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
varargout{1} = handles.output;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
return;


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
data=get(handles.figure1,'UserData');

[data,failed]=process_GPS(data);
if (failed==1)
   return;
end;

% build data fields
[data,failed]=build_fields(data);
if (failed==1)
   return;
end;

set(handles.text3,'string',sprintf('GPS File: %s',dir_clip(data.GPS.GPS_file,40)));
if ((isfield(data.accel,'GPS_sync_point')==1)&(isempty(data.accel.GPS_sync_point)==0)&...
      (isfield(data.accel,'ACCEL_sync_point')==1)&(isempty(data.accel.ACCEL_sync_point)==0)&...
      (data.GPS.loaded==1)&(data.accel.loaded==1))
   value='true';
else
   value='false';
end;
set(handles.text7,'string',sprintf('GPS/Accel Data Synchronized: %s',value));
set(handles.figure1,'UserData',data);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
return;


% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
data=get(handles.figure1,'UserData');

[data,failed]=load_GPS(data);
if (failed==1)
   return;
end;

% check the version
if ((isfield(data.GPS,'version')==0)|(str2double(data.GPS.version)<str2double(data.config.GPS_min_version)))
   err_text='This data was processed with a previous version of Vibration & cannot be reloaded!  You must reprocess this data (using the NEW button).';
   fault(err_text);
   return;
elseif (str2double(data.config.GPS_min_version)>str2double(data.config.version))
   err_text='This data was processed with a newer version of Vibration & cannot be reloaded!  You must update your software.';
   fault(err_text);
   return;
elseif (str2double(data.GPS.version)>str2double(data.config.version))
   err_text='This data was processed with a newer version of Vibration, it will be loaded; however, it is recommended that you update your software.';
   fault(err_text);
end;

% build data fields
[data,failed]=build_fields(data);
if (failed==1)
   return;
end;

set(handles.text3,'string',sprintf('GPS File: %s',dir_clip(data.GPS.GPS_file,40)));
if ((isfield(data.accel,'GPS_sync_point')==1)&(isempty(data.accel.GPS_sync_point)==0)&...
      (isfield(data.accel,'ACCEL_sync_point')==1)&(isempty(data.accel.ACCEL_sync_point)==0)&...
      (data.GPS.loaded==1)&(data.accel.loaded==1))
   value='true';
else
   value='false';
end;
set(handles.text7,'string',sprintf('GPS/Accel Data Synchronized: %s',value));
set(handles.figure1,'UserData',data);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
return;


% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
data=get(handles.figure1,'UserData');

if (data.GPS.loaded==0)
   err_text=sprintf('No GPS data was loaded!\n');
   fault(err_text);
   return;
end;

set(handles.text3,'string','GPS File: ');
data.GPS=[];
data.GPS.loaded=0;

% build data fields
[data,failed]=build_fields(data);
if (failed==1)
   return;
end;

set(handles.figure1,'UserData',data);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
return;


% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
data=get(handles.figure1,'UserData');

[data,failed]=process_accel(data);
if (failed==1)
   return;
end;

% build data fields
[data,failed]=build_fields(data);
if (failed==1)
   return;
end;

set(handles.text5,'string',sprintf('1PPS File: %s',dir_clip(data.accel.PPS_file,40)));
set(handles.text6,'string',sprintf('Accel File: %s',dir_clip(data.accel.ACCEL_file,40)));
if ((isempty(data.accel.GPS_sync_point)==0)&(isempty(data.accel.ACCEL_sync_point)==0)&(data.GPS.loaded==1)&(data.accel.loaded==1))
   value='true';
else
   value='false';
end;
set(handles.text7,'string',sprintf('GPS/Accel Data Synchronized: %s',value));
set(handles.figure1,'UserData',data);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
return;


% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
data=get(handles.figure1,'UserData');

[data,failed]=load_accel(data);
if (failed==1)
   return;
end;

% check the version
if ((isfield(data.accel,'version')==0)|(str2double(data.accel.version)<str2double(data.config.ACCEL_min_version)))
   err_text='This data was processed with a previous version of Vibration & cannot be reloaded!  You must reprocess this data (using the NEW button).';
   fault(err_text);
   return;
elseif (str2double(data.accel.version)>str2double(data.config.version))
   err_text='This data was processed with a newer version of Vibration & cannot be reloaded!  You should update your software.';
   fault(err_text);
   return;
end;

% build data fields
[data,failed]=build_fields(data);
if (failed==1)
   return;
end;

set(handles.text5,'string',sprintf('1PPS File: %s',dir_clip(data.accel.PPS_file,40)));
set(handles.text6,'string',sprintf('Accel File: %s',dir_clip(data.accel.ACCEL_file,40)));
if ((isempty(data.accel.GPS_sync_point)==0)&(isempty(data.accel.ACCEL_sync_point)==0)&(data.GPS.loaded==1)&(data.accel.loaded==1))
   value='true';
else
   value='false';
end;
set(handles.text7,'string',sprintf('GPS/Accel Data Synchronized: %s',value));
set(handles.figure1,'UserData',data);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
return;


% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
data=get(handles.figure1,'UserData');

if (data.accel.loaded==0)
   err_text=sprintf('No Accel data was loaded!\n');
   fault(err_text);
   return;
end;

set(handles.text5,'string','1PPS File: ');
set(handles.text6,'string','Accel File: ');
data.accel=[];
data.accel.loaded=0;

% build data fields
[data,failed]=build_fields(data);
if (failed==1)
   return;
end;

set(handles.figure1,'UserData',data);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
return;


% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
data=get(handles.figure1,'UserData');

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

if ((strcmp(data.GPS.type,'RT17')==1)|(strcmp(data.GPS.type,'PreRT17')==1)|(strcmp(data.GPS.type,'DAT')==1))
   if (isempty(data.GPS.position)==1)
      err_text=sprintf('The loaded GPS data does not contain position data!\n');
      fault(err_text);
      return;
   end;
end;

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

[data,failed]=sync_accel(data);
if (failed==1)
   return;
end;

% build data fields
[data,failed]=build_fields(data);
if (failed==1)
   return;
end;

if ((isempty(data.accel.GPS_sync_point)==0)&(isempty(data.accel.ACCEL_sync_point)==0)&(data.GPS.loaded==1)&(data.accel.loaded==1))
   value='true';
else
   value='false';
end;
set(handles.text7,'string',sprintf('GPS/Accel Data Synchronized: %s',value));
set(handles.figure1,'UserData',data);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
return;


% --- Executes on button press in pushbutton8.
function pushbutton8_Callback(hObject, eventdata, handles)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
data=get(handles.figure1,'UserData');

% call plot routine
data=call_plot(data);

set(handles.figure1,'UserData',data);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
return;


% --- Executes on button press in pushbutton9.
function pushbutton9_Callback(hObject, eventdata, handles)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
data=get(handles.figure1,'UserData');

% call plot routine
GPS_plots(data);

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


% --- Executes on button press in pushbutton10.
function pushbutton10_Callback(hObject, eventdata, handles)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
data=get(handles.figure1,'UserData');

if (data.GPS.loaded==0)
   err_text=sprintf('Please load GPS data!\n');
   fault(err_text);
   return;
else
   if (((strcmp(data.GPS.type,'RT17')==1)|(strcmp(data.GPS.type,'PreRT17')==1)|(strcmp(data.GPS.type,'DAT')==1))&(isempty(data.GPS.observables)==0))
      % call plot routine
      sv_plots(data);
   else
      err_text=sprintf('The loaded GPS data does not contain SV Observable data!\n');
      fault(err_text);
      return;
   end;
end;

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


% --- Executes on button press in pushbutton11.
function pushbutton11_Callback(hObject, eventdata, handles)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
data=get(handles.figure1,'UserData');

% call plot routine
[plot_switches,fail]=accel_plots(data,1);
if (fail==1)
   return;
end;

% reassign variables
data.config.accel=plot_switches;

set(handles.figure1,'UserData',data);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
return;

% --- Executes on button press in pushbutton12.
function pushbutton12_Callback(hObject, eventdata, handles)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
data=get(handles.figure1,'UserData');

% call plot routine
[plot_switches,fail]=accel_plots(data,2);
if (fail==1)
   return;
end;

% reassign variables
data.config.accel=plot_switches;

set(handles.figure1,'UserData',data);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
return;

% --- Executes on button press in pushbutton13.
function pushbutton13_Callback(hObject, eventdata, handles)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
data=get(handles.figure1,'UserData');

% call plot routine
[plot_switches,fail]=accel_plots(data,3);
if (fail==1)
   return;
end;

% reassign variables
data.config.accel=plot_switches;

set(handles.figure1,'UserData',data);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
return;

% --- Executes on button press in pushbutton14.
function pushbutton14_Callback(hObject, eventdata, handles)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
data=get(handles.figure1,'UserData');

if (data.GPS.loaded==0)
   err_text=sprintf('Please load GPS data!\n');
   fault(err_text);
   return;
else
   if (((strcmp(data.GPS.type,'RT17')==1)|(strcmp(data.GPS.type,'PreRT17')==1)|(strcmp(data.GPS.type,'DAT')==1))&(isempty(data.GPS.observables)==0))
      % call plot routine
      slip_report(data,1);
   else
      err_text=sprintf('The loaded GPS data does not contain SV Observable data!\n');
      fault(err_text);
      return;
   end;
end;

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


% --- Executes on button press in pushbutton15.
function pushbutton15_Callback(hObject, eventdata, handles)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
data=get(handles.figure1,'UserData');

if (data.GPS.loaded==0)
   err_text=sprintf('Please load GPS data!\n');
   fault(err_text);
   return;
else
   if (((strcmp(data.GPS.type,'RT17')==1)|(strcmp(data.GPS.type,'PreRT17')==1)|(strcmp(data.GPS.type,'DAT')==1))&(isempty(data.GPS.observables)==0))
      % call plot routine
      slip_report(data,2);
   else
      err_text=sprintf('The loaded GPS data does not contain SV Observable data!\n');
      fault(err_text);
      return;
   end;
end;

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


% --- Executes on button press in radiobutton1.
function checkbox1_Callback(hObject, eventdata, handles)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
data=get(handles.figure1,'UserData');

data.config.auto_close=get(handles.checkbox1,'value');

set(handles.figure1,'UserData',data);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
return;


% --- Executes on button press in radiobutton1.
function checkbox2_Callback(hObject, eventdata, handles)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
data=get(handles.figure1,'UserData');

data.config.file_save=get(handles.checkbox2,'value');

set(handles.figure1,'UserData',data);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
return;


% --- Executes on button press in radiobutton2.
function checkbox3_Callback(hObject, eventdata, handles)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
data=get(handles.figure1,'UserData');

data.config.print=get(handles.checkbox3,'value');

set(handles.figure1,'UserData',data);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
return;


% --- Executes on button press in pushbutton16.
function pushbutton16_Callback(hObject, eventdata, handles)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if (exist('vibration.hlp')==2)
   dos(sprintf('write.exe "%s" &',strcat(pwd,'\vibration.hlp')));
else
   err_text=sprintf('"Vibration" help file does not exist!\n');
   fault(err_text);
   return;
end;

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


% --- Executes on button press in pushbutton17.
function pushbutton17_Callback(hObject, eventdata, handles)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

data=get(handles.figure1,'UserData');
string01=sprintf('"Vibration" version %s\nTrimble Navigation Ltd.\nby Dave Vanden Berg\nNov 2002\n',data.config.version);
string02=sprintf('Disclaimer:  This program is intended only for \nTrimble internal use.  This program is not \nguaranteed to do what you want, nor is it \nguaranteed to do it right.\n');
string03=sprintf('If you have questions, comments, or find an error \nin "Vibration", please email Dave at: \n      Dave_Vanden_Berg@Trimble.com');
uiwait(msgbox({string01,string02,string03},'About "Vibration"','modal'));

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


% --- Executes on button press in pushbutton18.
function pushbutton18_Callback(hObject, eventdata, handles)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% save settings to files
data=get(handles.figure1,'UserData');

settings.config.version=data.config.version;
settings.current_path=data.current_path;
settings.position=get(handles.figure1,'Position');
settings.config.single_axes=data.config.single_axes;
settings.config.disp_position=data.config.disp_position;
settings.config.single_label=data.config.single_label;
settings.config.auto_close=get(handles.checkbox1,'value');
settings.config.file_save=get(handles.checkbox2,'value');
settings.config.print=get(handles.checkbox3,'value');
settings.config.week=data.config.week;
settings.config.time_zone=data.config.time_zone;
settings.config.dAT=data.config.dAT;
settings.config.rate=data.config.rate;
settings.config.accel.time.plot_by_location=data.config.accel.time.plot_by_location;
settings.config.accel.time.single_axes=data.config.accel.time.single_axes;
settings.config.accel.time.plot_mag=data.config.accel.time.plot_mag;
settings.config.accel.time.y_limits=data.config.accel.time.y_limits;
settings.config.accel.freq.n_fft=data.config.accel.freq.n_fft;
settings.config.accel.freq.sample_rate=data.config.accel.freq.sample_rate;
settings.config.accel.freq.backtracking=data.config.accel.freq.backtracking;
settings.config.accel.freq.windowing=data.config.accel.freq.windowing;
settings.config.accel.freq.max_hold=data.config.accel.freq.max_hold;
settings.config.accel.freq.show_EC1=data.config.accel.freq.show_EC1;
settings.config.accel.freq.plot_by_location=data.config.accel.freq.plot_by_location;
settings.config.accel.freq.single_axes=data.config.accel.freq.single_axes;
settings.config.accel.freq.plot_mag=data.config.accel.freq.plot_mag;
settings.config.accel.freq.y_limits=data.config.accel.freq.y_limits;
settings.config.accel.freq.x_limits=data.config.accel.freq.x_limits;
settings.config.accel.amp.plot_by_location=data.config.accel.amp.plot_by_location;
settings.config.accel.amp.single_axes=data.config.accel.amp.single_axes;
settings.config.accel.amp.plot_mag=data.config.accel.amp.plot_mag;
settings.config.accel.amp.x_limits=data.config.accel.amp.x_limits;
settings.config.accel.amp.mag_sort=data.config.accel.amp.mag_sort;
user=[];
save 'user' settings;

closereq;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
return;


% --------------------------------------------------------------------
function CloseReq_Callback(hObject, eventdata, handles)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
pushbutton18_Callback(hObject, eventdata, handles);
%closereq;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
return
