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

% Last Modified by GUIDE v2.5 12-Nov-2013 09:57:36

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @fit_OpeningFcn, ...
                   'gui_OutputFcn',  @fit_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 fit is made visible.
function fit_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   command line arguments to fit (see VARARGIN)


set(handles.irm,'Value',1);
set(handles.check_plotting,'Value',1);

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

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes fit wait for user response (see UIRESUME)
% uiwait(handles.figureIRM);


% --- Outputs from this function are returned to the command line.
function varargout = fit_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 pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

addpath ..

p.n_iter=str2double(get(handles.n_iter,'String'));
p.density=str2double(get(handles.edit_density,'String'));
p.plotting=get(handles.check_plotting,'Value');
p.sameEta =get(handles.sameEta,'Value');

mm=[];

if get(handles.irm,'Value')
    mm=[mm 1];
end
if get(handles.idm,'Value')
    mm=[mm 2];
end
if get(handles.ihw,'Value')
    mm=[mm 3];
end
if get(handles.bcd,'Value')
    mm=[mm 4];
end
p.mm          = mm;

p.datapth     = get(handles.datapth,'String');
p.roipth      = get(handles.roipth,'String');
p.outputroot  = get(handles.outputroot,'String');
p.extension   = get(handles.extension,'String');
p.prefix      = get(handles.prefix,'String');
p.projectname = get(handles.projectname,'String');

run_everything(p)



% --- Executes when selected object is changed in uipanel1.
function uipanel1_SelectionChangeFcn(hObject, eventdata, handles)
% hObject    handle to the selected object in uipanel1 
% eventdata  structure with the following fields (see UIBUTTONGROUP)
%	EventName: string 'SelectionChanged' (read only)
%	OldValue: handle of the previously selected object or empty if none was selected
%	NewValue: handle of the currently selected object
% handles    structure with handles and user data (see GUIDATA)

tmp1=get(handles.radiobutton1);
tmp2=get(handles.radiobutton2);
tmp3=get(handles.radiobutton3);
if tmp1.Value || tmp2.Value
    set(handles.datapth,'Visible','off')
    set(handles.roipth,'Visible','off')
    set(handles.outputroot,'Visible','off')
    set(handles.extension,'Visible','off')
    set(handles.prefix,'Visible','off')
    set(handles.projectname,'Visible','off')
    
    set(handles.text10,'Visible','off')    
    set(handles.text9,'Visible','off')
    set(handles.text8,'Visible','off')
    set(handles.datapath,'Visible','off')
    set(handles.text7,'Visible','off')
    set(handles.roi_pth_txt,'Visible','off')        
else
    set(handles.datapth,'Visible','on')    
    set(handles.roipth,'Visible','on')
    set(handles.outputroot,'Visible','on')
    set(handles.extension,'Visible','on')
    set(handles.prefix,'Visible','on')
    set(handles.projectname,'Visible','on')
    
    set(handles.text10,'Visible','on')
    set(handles.text9,'Visible','on')
    set(handles.text8,'Visible','on')
    set(handles.datapath,'Visible','on')
    set(handles.text7,'Visible','on')
    set(handles.roi_pth_txt,'Visible','on')
end

if tmp1.Value
    set(handles.datapth,'String','demo_beijing/data');
    set(handles.roipth,'String','aal_masks');
    set(handles.outputroot,'String','.');
    set(handles.extension,'String', 'nii');
    set(handles.prefix,'String','sfw');
    set(handles.projectname,'String','demo_beijing');
end
if tmp2.Value
    set(handles.datapth,'String','demo_leipzig/data');
    set(handles.roipth,'String','aal_masks');
    set(handles.outputroot,'String','.');
    set(handles.extension,'String', 'nii');
    set(handles.prefix,'String','sfw');
    set(handles.projectname,'String','demo_leipzig');
end



function n_iter_Callback(hObject, eventdata, handles)
% hObject    handle to n_iter (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of n_iter as text
%        str2double(get(hObject,'String')) returns contents of n_iter as a double


% --- Executes during object creation, after setting all properties.
function n_iter_CreateFcn(hObject, eventdata, handles)
% hObject    handle to n_iter (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit_density_Callback(hObject, eventdata, handles)
% hObject    handle to edit_density (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_density as text
%        str2double(get(hObject,'String')) returns contents of edit_density as a double


% --- Executes during object creation, after setting all properties.
function edit_density_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_density (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in check_plotting.
function check_plotting_Callback(hObject, eventdata, handles)
% hObject    handle to check_plotting (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 check_plotting


% --- Executes on button press in irm.
function irm_Callback(hObject, eventdata, handles)
% hObject    handle to irm (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 irm


% --- Executes on button press in bcd.
function bcd_Callback(hObject, eventdata, handles)
% hObject    handle to bcd (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 bcd


% --- Executes on button press in ihw.
function ihw_Callback(hObject, eventdata, handles)
% hObject    handle to ihw (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 ihw


% --- Executes on button press in idm.
function idm_Callback(hObject, eventdata, handles)
% hObject    handle to idm (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 idm


% --- Executes on button press in sameEta.
function sameEta_Callback(hObject, eventdata, handles)
% hObject    handle to sameEta (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 sameEta



function datapth_Callback(hObject, eventdata, handles)
% hObject    handle to datapth (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of datapth as text
%        str2double(get(hObject,'String')) returns contents of datapth as a double


% --- Executes during object creation, after setting all properties.
function datapth_CreateFcn(hObject, eventdata, handles)
% hObject    handle to datapth (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function roipth_Callback(hObject, eventdata, handles)
% hObject    handle to roipth (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of roipth as text
%        str2double(get(hObject,'String')) returns contents of roipth as a double


% --- Executes during object creation, after setting all properties.
function roipth_CreateFcn(hObject, eventdata, handles)
% hObject    handle to roipth (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function outputroot_Callback(hObject, eventdata, handles)
% hObject    handle to outputroot (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of outputroot as text
%        str2double(get(hObject,'String')) returns contents of outputroot as a double


% --- Executes during object creation, after setting all properties.
function outputroot_CreateFcn(hObject, eventdata, handles)
% hObject    handle to outputroot (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function extension_Callback(hObject, eventdata, handles)
% hObject    handle to extension (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of extension as text
%        str2double(get(hObject,'String')) returns contents of extension as a double


% --- Executes during object creation, after setting all properties.
function extension_CreateFcn(hObject, eventdata, handles)
% hObject    handle to extension (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function prefix_Callback(hObject, eventdata, handles)
% hObject    handle to prefix (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of prefix as text
%        str2double(get(hObject,'String')) returns contents of prefix as a double


% --- Executes during object creation, after setting all properties.
function prefix_CreateFcn(hObject, eventdata, handles)
% hObject    handle to prefix (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function projectname_Callback(hObject, eventdata, handles)
% hObject    handle to projectname (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of projectname as text
%        str2double(get(hObject,'String')) returns contents of projectname as a double


% --- Executes during object creation, after setting all properties.
function projectname_CreateFcn(hObject, eventdata, handles)
% hObject    handle to projectname (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end




% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over radiobutton1.
function radiobutton1_ButtonDownFcn(hObject, eventdata, handles)
% hObject    handle to radiobutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
