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

% Last Modified by GUIDE v2.5 24-Jan-2009 20:40:47

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @MarkovChains_OpeningFcn, ...
                   'gui_OutputFcn',  @MarkovChains_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
global limitdt;
limitdt=inf;
global hlogfile;
global limitdt_min;
limitdt_min=0;
hlogfile=1;

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

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

% Update handles structure
guidata(hObject, handles);

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


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

% Hint: popupmenu 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 popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu1 (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 popupmenu1 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu1


% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit1 (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 edit1_Callback(hObject, eventdata, handles)
% hObject    handle to edit1 (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 edit1 as text
%        str2double(get(hObject,'String')) returns contents of edit1 as a double
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)
[filename,pathname]=uigetfile('*.*');
fullname=strcat(pathname,filename);
set(handles.edit1,'String',fullname);
global in_series;
in_series=dlmread(fullname);
global in_series_len;
ss=size(in_series);
if (ss(1)>ss(2))
    in_series=transpose(in_series);
end
in_series_len=length(in_series);
set(handles.edit2,'String',num2str(in_series_len));
set(handles.edit3,'String','1');
set(handles.edit4,'String',num2str(in_series_len));
set(handles.edit6,'String',num2str(in_series_len));
set(handles.edit17,'String',num2str(in_series_len));
generate_hier(handles);


% --- Executes on button press in pushbutton2.
function pushbutton2_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)
generate(handles);


% --- 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)
global hierarchy_params;
global in_series_urez;
global type_prirash;
type_prirash=get(handles.radiobutton6,'Value');
global type_raspr; % Тип распределения
%0-tradic (delim otsortir masiv) 1 - delim interwal znacheniy dy 2- Делим
%массив, оценивая количество наиболее часто встр єлементов 3- 
%4 - Новый вариант. Выделение S1 части в средине равномерно, а хвосты - отдельные 2 состояния.
%5- Задаем процент в хвостах, остальное делится на равные по состоянию
%части
if (get(handles.radiobutton7,'Value')==1) % Равномерное по количеству
    type_raspr=2;
else 
    if (get(handles.radiobutton8,'Value')==1) %Равномерное по отклонению
        type_raspr=1;
        global ksigma; %Количество сигм (станд отклонений) в диапазоне состояний.
        ksigma=str2num(get(handles.edit12,'String'));

    else
        if (get(handles.radiobutton11,'Value')==1)%Распределение по количеству (новый вариант)
            type_raspr=0;
        else %Равномерное по отклонению, Часть хвоста
            if (get(handles.radiobutton16,'Value')==1)%Распределение по количеству (новый вариант)
                type_raspr=4;
                global chast_hwosta;
                chast_hwosta=str2num(get(handles.edit11,'String'));
            else
                type_raspr=5;
            end
        end
    end
end
global graphs;
if (get(handles.checkbox2,'Value')==1)
    graphs=1;
else
    graphs=[];
end
global graphs_raspr;
if (get(handles.checkbox3,'Value')==1)
    graphs_raspr=1;
else
    graphs_raspr=[];
end
global logs_skleyka;
logs_skleyka=get(handles.checkbox1,'Value');
global porog_smax;
porog_smax=str2num(get(handles.edit13,'String'));

[yprogn,masdtparam]=MarkovPrognozOptimize(in_series_urez,hierarchy_params);
hierarchy_params=masdtparam;
global in_series;

figure;
plot(yprogn,'b');
nyprogn=length(yprogn);
hold on;
plot(in_series_urez,'r');


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

% --- Executes on button press in radiobutton1.
function radiobutton1_Callback(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)

% Hint: get(hObject,'Value') returns toggle state of radiobutton1
generate(handles);

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

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


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


% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit2 (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 edit2_Callback(hObject, eventdata, handles)
% hObject    handle to edit2 (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 edit2 as text
%        str2double(get(hObject,'String')) returns contents of edit2 as a double


% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit3 (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 edit3_Callback(hObject, eventdata, handles)
% hObject    handle to edit3 (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 edit3 as text
%        str2double(get(hObject,'String')) returns contents of edit3 as a double
generate_hier(handles);

% --- Executes during object creation, after setting all properties.
function edit4_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit4 (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 edit4_Callback(hObject, eventdata, handles)
% hObject    handle to edit4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
s=get(handles.edit4,'String');
set(handles.edit6,'String',s);
generate_hier(handles);
% Hints: get(hObject,'String') returns contents of edit4 as text
%        str2double(get(hObject,'String')) returns contents of edit4 as a double


% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% Оценить погрешность без прогноза
global in_series_urez;
global hierarchy_params;
%generate_hier(handles); % происх при изменениях границ!
%pushbutton2_Callback(hObject, eventdata, handles);
global logs_skleyka;
logs_skleyka=get(handles.checkbox1,'Value');
global type_prirash;
type_prirash=get(handles.radiobutton6,'Value');
global type_raspr; % Тип распределения
%0-tradic (delim otsortir masiv) 1 - delim interwal znacheniy dy 2- Делим
%массив, оценивая количество наиболее часто встр єлементов 3- 
%4 - Новый вариант. Выделение S1 части в средине равномерно, а хвосты - отдельные 2 состояния.
%5- Задаем процент в хвостах, остальное делится на равные по состоянию
%части
if (get(handles.radiobutton7,'Value')==1) % Равномерное по количеству
    type_raspr=2;
else 
    if (get(handles.radiobutton8,'Value')==1) %Равномерное по отклонению
        type_raspr=1;
        global ksigma; %Количество сигм (станд отклонений) в диапазоне состояний.
        ksigma=str2num(get(handles.edit12,'String'));

    else
        if (get(handles.radiobutton11,'Value')==1)%Распределение по количеству (новый вариант)
            type_raspr=0;
        else %Равномерное по отклонению, Часть хвоста
            if (get(handles.radiobutton16,'Value')==1)%Распределение по количеству (новый вариант)
                type_raspr=4;
                global chast_hwosta;
                chast_hwosta=str2num(get(handles.edit11,'String'));
            else
                type_raspr=5;
            end
        end
    end
end
global graphs;
if (get(handles.checkbox2,'Value')==1)
    graphs=1;
else
    graphs=[];
end
global graphs_raspr;
if (get(handles.checkbox3,'Value')==1)
    graphs_raspr=1;
else
    graphs_raspr=[];
end
global type_s;
if (get(handles.radiobutton13,'Value')==1)
    type_s=1;
end
if (get(handles.radiobutton14,'Value')==1)
    type_s=2;
end
if (get(handles.radiobutton15,'Value')==1)
    type_s=3;
end

global s_const;
s_const=str2num(get(handles.edit7,'String'));
global porog_smax;
porog_smax=str2num(get(handles.edit13,'String'));

test_skleyka(in_series_urez,hierarchy_params);


% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton6 (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;
global in_series_len;
global in_series;
global in_series_urez;
global type_prirash;
type_prirash=get(handles.radiobutton6,'Value');
global type_raspr; % Тип распределения
%0-tradic (delim otsortir masiv) 1 - delim interwal znacheniy dy 2- Делим
%массив, оценивая количество наиболее часто встр єлементов 3- 
%4 - Новый вариант. Выделение S1 части в средине равномерно, а хвосты - отдельные 2 состояния.
%5- Задаем процент в хвостах, остальное делится на равные по состоянию
%части
%0-tradic (delim otsortir masiv) 1 - delim interwal znacheniy dy 2- Делим
%массив, оценивая количество наиболее часто встр єлементов 3- 
%4 - Новый вариант. Выделение S1 части в средине равномерно, а хвосты - отдельные 2 состояния.
%5- Задаем процент в хвостах, остальное делится на равные по состоянию
%части
if (get(handles.radiobutton7,'Value')==1) % Равномерное по количеству
    type_raspr=2;
else 
    if (get(handles.radiobutton8,'Value')==1) %Равномерное по отклонению
        type_raspr=1;
        global ksigma; %Количество сигм (станд отклонений) в диапазоне состояний.
        ksigma=str2num(get(handles.edit12,'String'));
    else
        if (get(handles.radiobutton11,'Value')==1)%Распределение по количеству (новый вариант)
            type_raspr=0;
        else %Равномерное по отклонению, Часть хвоста
            if (get(handles.radiobutton16,'Value')==1)%Распределение по количеству (новый вариант)
                type_raspr=4;
                global chast_hwosta;
                chast_hwosta=str2num(get(handles.edit11,'String'));
            else
                type_raspr=5;
            end
        end
    end
end
global graphs;
if (get(handles.checkbox2,'Value')==1)
    graphs=1;
else
    graphs=[];
end
global graphs_raspr;
if (get(handles.checkbox3,'Value')==1)
    graphs_raspr=1;
else
    graphs_raspr=[];
end
global type_s;
if (get(handles.radiobutton13,'Value')==1)
    type_s=1;
end
if (get(handles.radiobutton14,'Value')==1)
    type_s=2;
end
if (get(handles.radiobutton15,'Value')==1)
    type_s=3;
end

global s_const;
s_const=str2num(get(handles.edit7,'String'));

global logs_skleyka;
logs_skleyka=get(handles.checkbox1,'Value');
global sigma;
sigma=str2num(get(handles.edit10,'String'));
nbegprognoz=str2num(get(handles.edit6,'String'))-str2num(get(handles.edit3,'String')); %tbegprogn-tbeg_otrezok
global porog_smax;
porog_smax=str2num(get(handles.edit13,'String'));
nprognoz=str2num(get(handles.edit17,'String'));
global bif_flag; %Выбираем одну из бифуркаций, в зависимости от глобальных настроек (значения глобальной переменной bif_flag)
bif_flag=[];
flag_up=get(handles.checkbox6,'Value');
flag_down=get(handles.checkbox7,'Value');
resfilename=get(handles.edit8,'String');
if (flag_down==1)% Пусто - выбирается левая бифуркация - нижняя граница
    [yprogn1,masdtparamnew]=MarkovPrognozMain(in_series_urez,hierarchy_params,nbegprognoz,nprognoz);
    %nyprogn1=length(yprogn1);
    %yprogn1=yprogn1(2:nyprogn1); % урезается, выявлена ошибка!
    yprogn=yprogn1;
    
end
global hlogfile;
if (flag_up==1)
    bif_flag=[1];
    [yprogn2,masdtparamnew]=MarkovPrognozMain(in_series_urez,hierarchy_params,nbegprognoz,nprognoz);
    %nyprogn2=length(yprogn2);
    %yprogn2=yprogn2(2:nyprogn2); % урезается, выявлена ошибка!
    yprogn=yprogn2;
end

hierarchy_params=masdtparamnew;
figure;

beg=str2num(get(handles.edit3,'String'));
in_series4plot=in_series(beg:in_series_len); %!!!
tbeg_pogreshn=str2num(get(handles.edit18,'String'))+nbegprognoz;
if (tbeg_pogreshn>length(in_series4plot))
    tbeg_pogreshn=length(in_series4plot);
end;
if (tbeg_pogreshn>length(yprogn))
    tbeg_pogreshn=length(yprogn);
end;
tend_pogreshn=str2num(get(handles.edit19,'String'))+nbegprognoz;
if (tend_pogreshn>length(in_series4plot))
    tend_pogreshn=length(in_series4plot);
end;
if (tend_pogreshn>length(yprogn))
    tend_pogreshn=length(yprogn);
end;


if (flag_down==1)
    plot(yprogn1,'b');
    %lenresult=min(length(in_series4plot),min(length(yprogn1),nbegprognoz+nprognoz));
    razn=sum(abs(in_series4plot(tbeg_pogreshn:tend_pogreshn)-yprogn1(tbeg_pogreshn:tend_pogreshn)))/(tend_pogreshn-tbeg_pogreshn);
    fprintf(hlogfile,'srednkw otklon rezultata(progn1) na promezhutke(%d..%d) =%d \n',tbeg_pogreshn,tend_pogreshn,razn);
end
hold on;
if (flag_up==1)
    plot(yprogn2,'b');
    %lenresult=min(length(in_series4plot),min(length(yprogn2),nbegprognoz+nprognoz));
    razn=sum(abs(in_series4plot(tbeg_pogreshn:tend_pogreshn)-yprogn2(tbeg_pogreshn:tend_pogreshn)))/(tend_pogreshn-tbeg_pogreshn);
    fprintf(hlogfile,'srednkw otklon rezultata(progn2) na promezhutke(%d..%d) =%d \n',tbeg_pogreshn,tend_pogreshn,razn);
end
plot(in_series4plot,'r');

if length(resfilename)>0
    dlmwrite(resfilename,yprogn,'\n');
end



% --- Executes on button press in radiobutton5.
function radiobutton5_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton5 (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 radiobutton5
set(handles.radiobutton6,'Value',0);


% --- Executes on button press in radiobutton6.
function radiobutton6_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton6 (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 radiobutton6
set(handles.radiobutton5,'Value',0);

% --- Executes on button press in radiobutton7.
function radiobutton7_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton7 (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 radiobutton7
set(handles.radiobutton8,'Value',0);
set(handles.radiobutton11,'Value',0);
set(handles.radiobutton12,'Value',0);
set(handles.radiobutton16,'Value',0);

% --- Executes on button press in radiobutton8.
function radiobutton8_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton8 (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 radiobutton8
set(handles.radiobutton7,'Value',0);
set(handles.radiobutton11,'Value',0);
set(handles.radiobutton12,'Value',0);
set(handles.radiobutton16,'Value',0);

% --- Executes on button press in radiobutton9.
function radiobutton9_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton9 (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 radiobutton9
set(handles.radiobutton10,'Value',0);
generate_hier(handles);
% --- Executes on button press in radiobutton10.
function radiobutton10_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton10 (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 radiobutton10
set(handles.radiobutton9,'Value',0);
generate_hier(handles);
% --- Executes on button press in checkbox1.
function checkbox1_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox1 (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 checkbox1


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


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


% --- Executes on button press in checkbox4.
function checkbox4_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox4 (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 checkbox4
fullname=get(handles.edit5,'String');
global hlogfile;
logcheck=get(handles.checkbox4,'Value');
if (isempty(hlogfile))
    hlogfile=1;
end
if (logcheck==1)
    hlogfile=fopen(fullname,'a');
else
    if (hlogfile>2)
        fclose(hlogfile);
        hlogfile=1;
    end
    set(handles.edit5,'String','');
end



% --- Executes during object creation, after setting all properties.
function edit5_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit5 (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 edit5_Callback(hObject, eventdata, handles)
% hObject    handle to edit5 (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 edit5 as text
%        str2double(get(hObject,'String')) returns contents of edit5 as a double


% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton7 (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('*.*');
fullname=strcat(pathname,filename);
set(handles.edit5,'String',fullname);
global hlogfile;
logcheck=get(handles.checkbox1,'Value');
hlogfile=fopen(fullname,'a');
set(handles.checkbox4,'Value',1);


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


% --- Executes on button press in radiobutton11.
function radiobutton11_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton11 (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 radiobutton11
set(handles.radiobutton7,'Value',0);
set(handles.radiobutton8,'Value',0);
set(handles.radiobutton12,'Value',0);
set(handles.radiobutton16,'Value',0);
% --- Executes on button press in radiobutton12.
function radiobutton12_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton12 (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 radiobutton12
set(handles.radiobutton7,'Value',0);
set(handles.radiobutton8,'Value',0);
set(handles.radiobutton11,'Value',0);
set(handles.radiobutton16,'Value',0);

% --- Executes during object creation, after setting all properties.
function edit6_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit6 (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 edit6_Callback(hObject, eventdata, handles)
% hObject    handle to edit6 (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 edit6 as text
%        str2double(get(hObject,'String')) returns contents of edit6 as a double
nbegprogn=str2num(get(handles.edit6,'String'));
nend=str2num(get(handles.edit4,'String'));
if (nbegprogn~=nend)
    nbegprogn=nend;
    set(handles.edit6,'String',num2str(nbegprogn));
end


% --- Executes during object creation, after setting all properties.
function edit7_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit7 (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 edit7_Callback(hObject, eventdata, handles)
% hObject    handle to edit7 (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 edit7 as text
%        str2double(get(hObject,'String')) returns contents of edit7 as a double
generate_hier(handles);

% --- Executes on button press in radiobutton13.
function radiobutton13_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton13 (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 radiobutton13
set(handles.radiobutton13,'Value',1);
set(handles.radiobutton14,'Value',0);
set(handles.radiobutton15,'Value',0);

% --- Executes on button press in radiobutton14.
function radiobutton14_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton14 (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 radiobutton14
set(handles.radiobutton13,'Value',0);
set(handles.radiobutton14,'Value',1);
set(handles.radiobutton15,'Value',0);


% --- Executes on button press in radiobutton15.
function radiobutton15_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton15 (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 radiobutton15
set(handles.radiobutton13,'Value',0);
set(handles.radiobutton14,'Value',0);
set(handles.radiobutton15,'Value',1);


% --- Executes during object creation, after setting all properties.
function edit8_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit8 (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 edit8_Callback(hObject, eventdata, handles)
% hObject    handle to edit8 (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 edit8 as text
%        str2double(get(hObject,'String')) returns contents of edit8 as a double


% --- Executes on button press in pushbutton9.
function pushbutton9_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton9 (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('*.*');
fullname=strcat(pathname,filename);
set(handles.edit8,'String',fullname);


% --- Executes during object creation, after setting all properties.
function edit9_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit9 (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 edit9_Callback(hObject, eventdata, handles)
% hObject    handle to edit9 (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 edit9 as text
%        str2double(get(hObject,'String')) returns contents of edit9 as a double
generate_hier(handles);

% --- Executes during object creation, after setting all properties.
function edit10_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit10 (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 edit10_Callback(hObject, eventdata, handles)
% hObject    handle to edit10 (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 edit10 as text
%        str2double(get(hObject,'String')) returns contents of edit10 as a double


% --- Executes on button press in radiobutton16.
function radiobutton16_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton16 (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 radiobutton16
set(handles.radiobutton7,'Value',0);
set(handles.radiobutton8,'Value',0);
set(handles.radiobutton11,'Value',0);
set(handles.radiobutton12,'Value',0);


% --- Executes during object creation, after setting all properties.
function edit11_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit11 (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 edit11_Callback(hObject, eventdata, handles)
% hObject    handle to edit11 (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 edit11 as text
%        str2double(get(hObject,'String')) returns contents of edit11 as a double


% --- Executes during object creation, after setting all properties.
function edit12_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit12 (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 edit12_Callback(hObject, eventdata, handles)
% hObject    handle to edit12 (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 edit12 as text
%        str2double(get(hObject,'String')) returns contents of edit12 as a double


% --- Executes during object creation, after setting all properties.
function edit13_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit13 (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 edit13_Callback(hObject, eventdata, handles)
% hObject    handle to edit13 (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 edit13 as text
%        str2double(get(hObject,'String')) returns contents of edit13 as a double


% --- Executes during object creation, after setting all properties.
function edit_limitdt_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_limitdt (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_limitdt_Callback(hObject, eventdata, handles)
% hObject    handle to edit_limitdt (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_limitdt as text
%        str2double(get(hObject,'String')) returns contents of edit_limitdt as a double
global limitdt;
if (get(handles.checkbox_limitdt,'Value')==1)
    limitdt=str2num(get(handles.edit_limitdt,'String'));
else
    limitdt=inf;
end
generate_hier(handles);

% --- Executes on button press in checkbox_limitdt.
function checkbox_limitdt_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox_limitdt (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_limitdt
global limitdt;
%    limitdt=inf;
if (get(handles.checkbox_limitdt,'Value')==1)
    limitdt=str2num(get(handles.edit_limitdt,'String'));
else
    limitdt=inf;
end
generate_hier(handles);


% --- Executes during object creation, after setting all properties.
function edit15_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit15 (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 edit15_Callback(hObject, eventdata, handles)
% hObject    handle to edit15 (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 edit15 as text
%        str2double(get(hObject,'String')) returns contents of edit15 as a double


% --- Executes during object creation, after setting all properties.
function edit16_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit16 (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 edit16_Callback(hObject, eventdata, handles)
% hObject    handle to edit16 (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 edit16 as text
%        str2double(get(hObject,'String')) returns contents of edit16 as a double


% --- Executes during object creation, after setting all properties.
function edit17_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit17 (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 edit17_Callback(hObject, eventdata, handles)
% hObject    handle to edit17 (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 edit17 as text
%        str2double(get(hObject,'String')) returns contents of edit17 as a double
global limitdt;
if (get(handles.checkbox_limitdt,'Value')==1)
    limitdt=str2num(get(handles.edit_limitdt,'String'));
else
    limitdt=inf;
end
generate_hier(handles);
%set(handles.edit19,'String',get(handles.edit17,'String'));


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


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


% --- Executes on button press in pushbutton10.
function pushbutton10_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton10 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% Сохранить настройки
filename=get(handles.edit1,'String');
% Активируем глобальные переменные
global hierarchy_params;
global in_series;
global in_series_len;
global in_series_urez;
global type_prirash;
type_prirash=get(handles.radiobutton6,'Value');
global type_raspr; % Тип распределения
%0-tradic (delim otsortir masiv) 1 - delim interwal znacheniy dy 2- Делим
%массив, оценивая количество наиболее часто встр єлементов 3- 
%4 - Новый вариант. Выделение S1 части в средине равномерно, а хвосты - отдельные 2 состояния.
%5- Задаем процент в хвостах, остальное делится на равные по состоянию
%части
%0-tradic (delim otsortir masiv) 1 - delim interwal znacheniy dy 2- Делим
%массив, оценивая количество наиболее часто встр єлементов 3- 
%4 - Новый вариант. Выделение S1 части в средине равномерно, а хвосты - отдельные 2 состояния.
%5- Задаем процент в хвостах, остальное делится на равные по состоянию
%части
if (get(handles.radiobutton7,'Value')==1) % Равномерное по количеству
    type_raspr=2;
else 
    if (get(handles.radiobutton8,'Value')==1) %Равномерное по отклонению
        type_raspr=1;
        global ksigma; %Количество сигм (станд отклонений) в диапазоне состояний.
        ksigma=str2num(get(handles.edit12,'String'));
    else
        if (get(handles.radiobutton11,'Value')==1)%Распределение по количеству (новый вариант)
            type_raspr=0;
        else %Равномерное по отклонению, Часть хвоста
            if (get(handles.radiobutton16,'Value')==1)%Распределение по количеству (новый вариант)
                type_raspr=4;
                global chast_hwosta;
                chast_hwosta=str2num(get(handles.edit11,'String'));
            else
                type_raspr=5;
            end
        end
    end
end
global graphs;
if (get(handles.checkbox2,'Value')==1)
    graphs=1;
else
    graphs=[];
end
global graphs_raspr;
if (get(handles.checkbox3,'Value')==1)
    graphs_raspr=1;
else
    graphs_raspr=[];
end
global type_s;
if (get(handles.radiobutton13,'Value')==1)
    type_s=1;
end
if (get(handles.radiobutton14,'Value')==1)
    type_s=2;
end
if (get(handles.radiobutton15,'Value')==1)
    type_s=3;
end

global s_const;
s_const=str2num(get(handles.edit7,'String'));

global logs_skleyka;
logs_skleyka=get(handles.checkbox1,'Value');
global sigma;
sigma=str2num(get(handles.edit10,'String'));
nbegprognoz=str2num(get(handles.edit6,'String'))-str2num(get(handles.edit3,'String')); %tbegprogn-tbeg_otrezok
global porog_smax;
porog_smax=str2num(get(handles.edit13,'String'));
nprognoz=str2num(get(handles.edit17,'String'));
global bif_flag; %Выбираем одну из бифуркаций, в зависимости от глобальных настроек (значения глобальной переменной bif_flag)
bif_flag=[];
flag_up=get(handles.checkbox6,'Value');
flag_down=get(handles.checkbox7,'Value');
beg=str2num(get(handles.edit3,'String'))+1;
resfilename=get(handles.edit8,'String');
%% Параметры, добавленные 20090123
tbeg_pogreshn=str2num(get(handles.edit18,'String'))+nbegprognoz;
tend_pogreshn=str2num(get(handles.edit19,'String'))+nbegprognoz;

%%Параметры добавленные 20090124
globalk=str2num(get(handles.edit9,'String'));
globalrmin=str2num(get(handles.edit15,'String'));
globalrmax=str2num(get(handles.edit16,'String'));
simplehier=get(handles.radiobutton9,'Value'); % Флаг простой иерархии
OgranichDT=get(handles.checkbox_limitdt,'Value'); % Флаг простой иерархии

uisave;

% --- Executes on button press in pushbutton11.
function pushbutton11_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton11 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
hObject1=hObject;
eventdata1=eventdata;
handles1=handles;
% Глобальніе
global hierarchy_params;
global in_series;
global in_series_len;
global in_series_urez;
global type_prirash;
global type_raspr; % Тип распределения
global ksigma; %Количество сигм (станд отклонений) в диапазоне состояний.
global chast_hwosta;
global graphs;
global graphs_raspr;
global type_s;
global s_const;
global logs_skleyka;
global sigma;
global porog_smax;
global bif_flag; %Выбираем одну из бифуркаций, в зависимости от глобальных настроек (значения глобальной переменной bif_flag)
%конец глобальнім

uiload;
hObject=hObject1;
eventdata=eventdata1;
handles=handles1;

set(handles.edit1,'String','Neizwestno(zagruzheno iz mat-faila)');
n=length(in_series);
set(handles.edit2,'String',num2str(n));
set(handles.edit3,'String',n-nbegprognoz); %Начало промежутка
set(handles.edit4,'String',nbegprognoz); %Конец промежутка
set(handles.edit6,'String',nbegprognoz); %Начало прогноза
set(handles.edit17,'String',nprognoz); %Начало прогноза
if type_prirash==1
    set(handles.radiobutton6,'Value',1);
    set(handles.radiobutton5,'Value',0);
else
    set(handles.radiobutton6,'Value',0);
    set(handles.radiobutton5,'Value',1);
end
if type_raspr==1
    set(handles.radiobutton8,'Value',1);
    set(handles.edit12,'String',num2str(ksigma));
    set(handles.radiobutton7,'Value',0);
    set(handles.radiobutton11,'Value',0);
    set(handles.radiobutton16,'Value',0)
    set(handles.radiobutton12,'Value',0)
else
    if type_raspr==2
        set(handles.radiobutton7,'Value',1);
        set(handles.radiobutton8,'Value',0)
        set(handles.radiobutton11,'Value',0)
        set(handles.radiobutton12,'Value',0)
        set(handles.radiobutton16,'Value',0)
    else
        if type_raspr==0
            set(handles.radiobutton11,'Value',1);
            set(handles.radiobutton8,'Value',0)
            set(handles.radiobutton7,'Value',0)
            set(handles.radiobutton12,'Value',0)
            set(handles.radiobutton16,'Value',0)
        else
            if type_raspr==4
                set(handles.radiobutton16,'Value',1)
                set(handles.radiobutton11,'Value',0);
                set(handles.radiobutton8,'Value',0)
                set(handles.radiobutton7,'Value',0)
                set(handles.radiobutton12,'Value',0)
                set(handles.edit11,'String',num2str(chast_hwosta));
            else
                set(handles.radiobutton12,'Value',1)
                set(handles.radiobutton16,'Value',0)
                set(handles.radiobutton11,'Value',0);
                set(handles.radiobutton8,'Value',0)
                set(handles.radiobutton7,'Value',0)
            end
        end
    end
end
if isempty(graphs)
    set(handles.checkbox2,'Value',0);
else
    set(handles.checkbox2,'Value',1);
end

set(handles.checkbox2,'Value',graphs);
if isempty(graphs_raspr)
    set(handles.checkbox3,'Value',0);
else
    set(handles.checkbox3,'Value',1);
end
if type_s==1
    set(handles.radiobutton13,'Value',1);
    set(handles.radiobutton14,'Value',0);
    set(handles.radiobutton15,'Value',0);
else
    if type_s==1
        set(handles.radiobutton14,'Value',1);
        set(handles.radiobutton15,'Value',0);
        set(handles.radiobutton13,'Value',0);
    else
        set(handles.radiobutton15,'Value',1)
        set(handles.radiobutton14,'Value',0);
        set(handles.radiobutton13,'Value',0);
    end
end
set(handles.edit7,'String',num2str(s_const));
if isempty(logs_skleyka)
    set(handles.checkbox1,'Value',0);
else
    set(handles.checkbox1,'Value',1);
end
%nbegprognoz=str2num(get(handles.edit6,'String'))-str2num(get(handles.edit3,'String')); %tbegprogn-tbeg_otrezok
set(handles.edit13,'String',num2str(porog_smax));
%nprognoz=str2num(get(handles.edit17,'String'));
%global bif_flag; %Выбираем одну из бифуркаций, в зависимости от глобальных настроек (значения глобальной переменной bif_flag)
%bif_flag=[];
set(handles.checkbox6,'Value',flag_up);
set(handles.checkbox7,'Value',flag_down);
set(handles.edit3,'String',num2str(beg-1));
set(handles.edit8,'String',resfilename);
set(handles.edit18,'String',num2str(tbeg_pogreshn-nbegprognoz));
set(handles.edit19,'String',num2str(tend_pogreshn-nbegprognoz));

% Новые добавленные возможности. Выполняются после старых и могут вызвать
% ошибки при импорте старых файлов заданий.
%set(handles.edit10,'String',num2str(sygma)); % Проблема из-за совпадения
%функции сигма!!!
%% Имя входного файла
%% Простая, сложная иерархия
%% Ограничить дт и поле ввода
%% к
%% рмин, рмакс


% --- Executes during object creation, after setting all properties.
function edit18_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit18 (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 edit18_Callback(hObject, eventdata, handles)
% hObject    handle to edit18 (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 edit18 as text
%        str2double(get(hObject,'String')) returns contents of edit18 as a double


% --- Executes during object creation, after setting all properties.
function edit19_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit19 (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 edit19_Callback(hObject, eventdata, handles)
% hObject    handle to edit19 (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 edit19 as text
%        str2double(get(hObject,'String')) returns contents of edit19 as a double

