function varargout = accel_select(varargin)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ACCEL_SELECT M-file for accel_select.fig
%      ACCEL_SELECT, by itself, creates a new ACCEL_SELECT or raises the existing
%      singleton*.
%
%      H = ACCEL_SELECT returns the handle to a new ACCEL_SELECT or the handle to
%      the existing singleton*.
%
%      ACCEL_SELECT('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in ACCEL_SELECT.M with the given input arguments.
%
%      ACCEL_SELECT('Property','Value',...) creates a new ACCEL_SELECT or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before accel_select_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to accel_select_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 accel_select

% Last Modified by GUIDE v2.5 19-Mar-2003 15:20:33

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @accel_select_OpeningFcn, ...
                   'gui_OutputFcn',  @accel_select_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 accel_select is made visible.
function accel_select_OpeningFcn(hObject, eventdata, handles, varargin)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Choose default command line output for accel_select
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% load input variables
data=varargin{1};

% update GUI
data=update_GUI(handles,data);

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


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


% --- Executes on button press in checkbox1.
function checkbox1_Callback(hObject, eventdata, handles)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
data=get(handles.figure1,'UserData');
value=get(hObject,'Value');
if (data.temp.plot_type==1)
   data.config.accel.time.plot_by_location=value;
elseif (data.temp.plot_type==3)
   data.config.accel.amp.plot_by_location=value;
end;
data=update_GUI(handles,data);
set(handles.figure1,'UserData',data);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
return;


% --- Executes on button press in checkbox2.
function checkbox2_Callback(hObject, eventdata, handles)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
data=get(handles.figure1,'UserData');
value=get(hObject,'Value');
if (data.temp.plot_type==1)
   data.config.accel.time.single_axes=value;
elseif (data.temp.plot_type==3)
   data.config.accel.amp.single_axes=value;
end;
data=update_GUI(handles,data);
set(handles.figure1,'UserData',data);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
return;

% --- Executes on button press in checkbox3.
function checkbox3_Callback(hObject, eventdata, handles)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
data=get(handles.figure1,'UserData');
value=get(hObject,'Value');
if (data.temp.plot_type==1)
   data.config.accel.time.plot_mag=value;
elseif (data.temp.plot_type==3)
   data.config.accel.amp.plot_mag=value;
end;
data=update_GUI(handles,data);
set(handles.figure1,'UserData',data);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
return;

% --- Executes on button press in checkbox4.
function checkbox4_Callback(hObject, eventdata, handles)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
data=get(handles.figure1,'UserData');
value=get(hObject,'Value');
if (data.temp.plot_type==1)
   data.config.accel.time.plot_mag=value;
elseif (data.temp.plot_type==3)
   data.config.accel.amp.mag_sort=value;
end;
data=update_GUI(handles,data);
set(handles.figure1,'UserData',data);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
return;


function edit1_Callback(hObject, eventdata, handles)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
data=get(handles.figure1,'UserData');
value=round(str2double(get(hObject,'string')));
if (data.temp.plot_type==1)
   data.config.accel.time.y_limits(1)=value;
elseif (data.temp.plot_type==3)
   data.config.accel.amp.x_limits(1)=value;
end;
data=update_GUI(handles,data);
set(handles.figure1,'UserData',data);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
return;


function edit2_Callback(hObject, eventdata, handles)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
data=get(handles.figure1,'UserData');
value=round(str2double(get(hObject,'string')));
if (data.temp.plot_type==1)
   data.config.accel.time.y_limits(2)=value;
elseif (data.temp.plot_type==3)
   data.config.accel.amp.x_limits(2)=value;
end;
data=update_GUI(handles,data);
set(handles.figure1,'UserData',data);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
return;


function edit3_Callback(hObject, eventdata, handles)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
data=get(handles.figure1,'UserData');
value=abs(round(str2double(get(hObject,'string'))));
if (data.temp.plot_type==1)
   data.config.accel.time.y_limits(3)=value;
elseif (data.temp.plot_type==3)
   data.config.accel.amp.x_limits(3)=value;
end;
data=update_GUI(handles,data);
set(handles.figure1,'UserData',data);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
return;


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
uiresume(handles.figure1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
return;


% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
set(handles.figure1,'UserData','');
uiresume(handles.figure1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
return;


% --------------------------------------------------------------------
function varargout = CloseReq_Callback(h, eventdata, handles)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
pushbutton2_Callback(h, eventdata, handles);
%closereq;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
return;


function [data] = update_GUI (handles,data)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if (data.temp.plot_type==1)
   set(handles.text1,'string','Accel Time Plot Setup');
   set(handles.edit1,'string',sprintf('%.0f',data.config.accel.time.y_limits(1)));
   set(handles.edit2,'string',sprintf('%.0f',data.config.accel.time.y_limits(2)));
   set(handles.edit3,'string',sprintf('%.0f',data.config.accel.time.y_limits(3)));
   set(handles.checkbox1,'Value',data.config.accel.time.plot_by_location);
   set(handles.checkbox2,'Value',data.config.accel.time.single_axes);
   set(handles.checkbox3,'Value',data.config.accel.time.plot_mag);
   if (ishandle(handles.checkbox4)==1)
      delete(handles.checkbox4);
   end;
   if (ishandle(handles.text9)==1)
      delete(handles.text9);
   end;
elseif (data.temp.plot_type==3)
   set(handles.text1,'string','Accel Amp Plot Setup');
   set(handles.edit1,'string',sprintf('%.0f',data.config.accel.amp.x_limits(1)));
   set(handles.edit2,'string',sprintf('%.0f',data.config.accel.amp.x_limits(2)));
   set(handles.edit3,'string',sprintf('%.0f',data.config.accel.amp.x_limits(3)));
   set(handles.checkbox1,'Value',data.config.accel.amp.plot_by_location);
   set(handles.checkbox2,'Value',data.config.accel.amp.single_axes);
   set(handles.checkbox3,'Value',data.config.accel.amp.plot_mag);
   set(handles.checkbox4,'Value',data.config.accel.amp.mag_sort);
end;

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