function varargout = bns_analysis(varargin)
%BNS_ANALYSIS M-file for bns_analysis.fig
%      BNS_ANALYSIS, by itself, creates a new BNS_ANALYSIS or raises the existing
%      singleton*.
%
%      H = BNS_ANALYSIS returns the handle to a new BNS_ANALYSIS or the handle to
%      the existing singleton*.
%
%      BNS_ANALYSIS('Property','Value',...) creates a new BNS_ANALYSIS using the
%      given property value pairs. Unrecognized properties are passed via
%      varargin to bns_analysis_OpeningFcn.  This calling syntax produces a
%      warning when there is an existing singleton*.
%
%      BNS_ANALYSIS('CALLBACK') and BNS_ANALYSIS('CALLBACK',hObject,...) call the
%      local function named CALLBACK in BNS_ANALYSIS.M with the given input
%      arguments.
%
%      *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 bns_analysis

% Last Modified by GUIDE v2.5 14-Aug-2006 14:36:46

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @bns_analysis_OpeningFcn, ...
                   'gui_OutputFcn',  @bns_analysis_OutputFcn, ...
                   'gui_LayoutFcn',  [], ...
                   'gui_Callback',   []);
if nargin && ischar(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


% --- Executes just before bns_analysis is made visible.
function bns_analysis_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   unrecognized PropertyName/PropertyValue pairs from the
%            command line (see VARARGIN)

handles.analysis_choice = 0;
set(handles.nextbutton,'Enable','on');
set(handles.radio_plot,'Value',1);

% Choose default command line output for bns_analysis
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes bns_analysis wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = bns_analysis_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in nextbutton.
function nextbutton_Callback(hObject, eventdata, handles)
% hObject    handle to nextbutton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

if handles.analysis_choice == 0
    close(bns_analysis)
    analyze_olddata
elseif handles.analysis_choice == 1
    close(bns_analysis)
    view_old_analysis
elseif handles.analysis_choice == 2
    close(bns_analysis)
    analyze_newsims
end

% --- Executes on button press in exitbutton.
function exitbutton_Callback(hObject, eventdata, handles)
% hObject    handle to exitbutton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

close(bns_analysis);

% --- Executes on button press in radio_plot.
function radio_plot_Callback(hObject, eventdata, handles)
% hObject    handle to radio_plot (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radio_plot

        handles.analysis_choice = 0;
        set(handles.nextbutton,'Enable','on');
        
        off = [handles.radio_view, handles.radio_newsim];
        mutual_exclude(off);
        
        guidata(hObject, handles);
       
% --- Executes on button press in radio_view.
function radio_view_Callback(hObject, eventdata, handles)
% hObject    handle to radio_view (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radio_view

        handles.analysis_choice = 1;
        set(handles.nextbutton,'Enable','on');
        
        off = [handles.radio_plot, handles.radio_newsim];
        mutual_exclude(off);
        
        guidata(hObject, handles);
% --- Executes on button press in radio_newsim.
function radio_newsim_Callback(hObject, eventdata, handles)
% hObject    handle to radio_newsim (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radio_newsim

        handles.analysis_choice = 2;
        set(handles.nextbutton,'Enable','off');
        
        off = [handles.radio_view, handles.radio_plot];
        mutual_exclude(off);
        
        guidata(hObject, handles);

    function mutual_exclude(off)
        set(off, 'Value', 0)