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

% Last Modified by GUIDE v2.5 12-Oct-2008 16:06:01

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @Hierarhy_OpeningFcn, ...
                   'gui_OutputFcn',  @Hierarhy_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


% --- Executes just before Hierarhy is made visible.
function Hierarhy_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 Hierarhy (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes Hierarhy wait for user response (see UIRESUME)
% uiwait(handles.figure1);
global hierarchy_params;
n_hier=length(hierarchy_params);
str=cell(n_hier,1);
for i=1:n_hier
    str(i)={num2str(hierarchy_params(i).dt)};
end
set(handles.listbox1,'String',str);
current=5;
set(handles.listbox1,'Value',current);
set(handles.edit_smin,'String',num2str(hierarchy_params(current).smin));
set(handles.edit_smax,'String',num2str(hierarchy_params(current).smax));
set(handles.edit_s,'String',num2str(hierarchy_params(current).s));

set(handles.edit_rmin,'String',num2str(hierarchy_params(current).rmin));
set(handles.edit_rmax,'String',num2str(hierarchy_params(current).rmax));
set(handles.edit_r,'String',num2str(hierarchy_params(current).r));

set(handles.edit_kmin,'String',num2str(hierarchy_params(current).kmin));
set(handles.edit_kmax,'String',num2str(hierarchy_params(current).kmax));
set(handles.edit_k,'String',num2str(hierarchy_params(current).k));

set(handles.checkbox_tests,'Value',hierarchy_params(current).tests);
set(handles.checkbox_testr,'Value',hierarchy_params(current).testr);
set(handles.checkbox_testk,'Value',hierarchy_params(current).testk);
set(handles.checkbox_use,'Value',hierarchy_params(current).use);

set(handles.edit_tbeg,'String',num2str(hierarchy_params(current).tbeg));
set(handles.edit_tend,'String',num2str(hierarchy_params(current).tend));
set(handles.edit_tbeg_sost,'String',num2str(hierarchy_params(current).tbeg_sost));
set(handles.edit_tend_sost,'String',num2str(hierarchy_params(current).tend_sost));


% --- Outputs from this function are returned to the command line.
function varargout = Hierarhy_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 during object creation, after setting all properties.
function listbox1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to listbox1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

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


% --- Executes on selection change in listbox1.
function listbox1_Callback(hObject, eventdata, handles)
% hObject    handle to listbox1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns listbox1 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from listbox1
global hierarchy_params;
current=get(handles.listbox1,'Value');
set(handles.edit_smin,'String',num2str(hierarchy_params(current).smin));
set(handles.edit_smax,'String',num2str(hierarchy_params(current).smax));
set(handles.edit_s,'String',num2str(hierarchy_params(current).s));

set(handles.edit_rmin,'String',num2str(hierarchy_params(current).rmin));
set(handles.edit_rmax,'String',num2str(hierarchy_params(current).rmax));
set(handles.edit_r,'String',num2str(hierarchy_params(current).r));

set(handles.edit_kmin,'String',num2str(hierarchy_params(current).kmin));
set(handles.edit_kmax,'String',num2str(hierarchy_params(current).kmax));
set(handles.edit_k,'String',num2str(hierarchy_params(current).k));

set(handles.checkbox_tests,'Value',hierarchy_params(current).tests);
set(handles.checkbox_testr,'Value',hierarchy_params(current).testr);
set(handles.checkbox_testk,'Value',hierarchy_params(current).testk);
set(handles.checkbox_use,'Value',hierarchy_params(current).use);

set(handles.edit_tbeg,'String',num2str(hierarchy_params(current).tbeg));
set(handles.edit_tend,'String',num2str(hierarchy_params(current).tend));
set(handles.edit_tbeg_sost,'String',num2str(hierarchy_params(current).tbeg_sost));
set(handles.edit_tend_sost,'String',num2str(hierarchy_params(current).tend_sost));




% --- Executes during object creation, after setting all properties.
function edit_smin_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_smin (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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



function edit_smin_Callback(hObject, eventdata, handles)
% hObject    handle to edit_smin (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_smin as text
%        str2double(get(hObject,'String')) returns contents of edit_smin as a double


% --- Executes during object creation, after setting all properties.
function edit_smax_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_smax (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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



function edit_smax_Callback(hObject, eventdata, handles)
% hObject    handle to edit_smax (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_smax as text
%        str2double(get(hObject,'String')) returns contents of edit_smax as a double


% --- Executes during object creation, after setting all properties.
function edit_s_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_s (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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



function edit_s_Callback(hObject, eventdata, handles)
% hObject    handle to edit_s (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_s as text
%        str2double(get(hObject,'String')) returns contents of edit_s as a double


% --- Executes during object creation, after setting all properties.
function edit_rmin_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_rmin (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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



function edit_rmin_Callback(hObject, eventdata, handles)
% hObject    handle to edit_rmin (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_rmin as text
%        str2double(get(hObject,'String')) returns contents of edit_rmin as a double


% --- Executes during object creation, after setting all properties.
function edit_rmax_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_rmax (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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



function edit_rmax_Callback(hObject, eventdata, handles)
% hObject    handle to edit_rmax (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_rmax as text
%        str2double(get(hObject,'String')) returns contents of edit_rmax as a double


% --- Executes during object creation, after setting all properties.
function edit_r_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_r (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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



function edit_r_Callback(hObject, eventdata, handles)
% hObject    handle to edit_r (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_r as text
%        str2double(get(hObject,'String')) returns contents of edit_r as a double


% --- Executes during object creation, after setting all properties.
function edit_kmin_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_kmin (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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



function edit_kmin_Callback(hObject, eventdata, handles)
% hObject    handle to edit_kmin (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_kmin as text
%        str2double(get(hObject,'String')) returns contents of edit_kmin as a double


% --- Executes during object creation, after setting all properties.
function edit_kmax_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_kmax (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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



function edit_kmax_Callback(hObject, eventdata, handles)
% hObject    handle to edit_kmax (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_kmax as text
%        str2double(get(hObject,'String')) returns contents of edit_kmax as a double


% --- Executes during object creation, after setting all properties.
function edit_k_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_k (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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



function edit_k_Callback(hObject, eventdata, handles)
% hObject    handle to edit_k (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_k as text
%        str2double(get(hObject,'String')) returns contents of edit_k as a double


% --- 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)
global hierarchy_params;
current=get(handles.listbox1,'Value');
hierarchy_params(current).smin=get(handles.edit_smin,'String');
hierarchy_params(current).smax=get(handles.edit_smax,'String');
hierarchy_params(current).s=get(handles.edit_s,'String');

hierarchy_params(current).rmin=get(handles.edit_rmin,'String');
hierarchy_params(current).rmax=get(handles.edit_rmax,'String');
hierarchy_params(current).r=get(handles.edit_r,'String');

hierarchy_params(current).kmin=get(handles.edit_kmin,'String');
hierarchy_params(current).kmax=get(handles.edit_kmax,'String');
hierarchy_params(current).k=get(handles.edit_k,'String');

hierarchy_params(current).tests=get(handles.checkbox_tests,'Value');
hierarchy_params(current).testk=get(handles.checkbox_testk,'Value');
hierarchy_params(current).testr=get(handles.checkbox_testr,'Value');
hierarchy_params(current).use=get(handles.checkbox_use,'Value');
hierarchy_params(current).tbeg=get(handles.edit_tbeg,'String',num2str(hierarchy_params(current).tbeg));
hierarchy_params(current).tbeg=get(handles.edit_tend,'String',num2str(hierarchy_params(current).tend));
get(handles.edit_tbeg_sost,'String',num2str(hierarchy_params(current).tbeg_sost));
get(handles.edit_tend_sost,'String',num2str(hierarchy_params(current).tend_sost));


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


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


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


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


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


% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
%[filename,pathname]=uiputfile('*.ier');
%fullname=strcat(pathname,filename);
global hierarchy_params; 
uisave;


% --- Executes during object creation, after setting all properties.
function edit_tbeg_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_tbeg (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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



function edit_tbeg_Callback(hObject, eventdata, handles)
% hObject    handle to edit_tbeg (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_tbeg as text
%        str2double(get(hObject,'String')) returns contents of edit_tbeg as a double


% --- Executes during object creation, after setting all properties.
function edit_tend_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_tend (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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



function edit_tend_Callback(hObject, eventdata, handles)
% hObject    handle to edit_tend (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_tend as text
%        str2double(get(hObject,'String')) returns contents of edit_tend as a double


% --- Executes during object creation, after setting all properties.
function edit_tbeg_sost_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_tbeg_sost (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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



function edit_tbeg_sost_Callback(hObject, eventdata, handles)
% hObject    handle to edit_tbeg_sost (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_tbeg_sost as text
%        str2double(get(hObject,'String')) returns contents of edit_tbeg_sost as a double


% --- Executes during object creation, after setting all properties.
function edit_tend_sost_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_tend_sost (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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



function edit_tend_sost_Callback(hObject, eventdata, handles)
% hObject    handle to edit_tend_sost (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_tend_sost as text
%        str2double(get(hObject,'String')) returns contents of edit_tend_sost as a double


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

