function varargout=sintrend_gui(varargin);
% Функция графического интерфейса для прогнозирования с помощью
% синус-трендов.


if (length(varargin)>0)
    infilename=varargin{1};
else
    infilename='';
end
if (length(varargin)>1)
    outfilename=varargin{2};
else
    outfilename='';
end

hfig=figure;
uicontrol('Style','text','Units','normalized','Position',[0.1 0.9 0.2 0.05],'String','Вхідний файл:');
ui_infilename=uicontrol('Style','edit','Units','normalized','Position',[0.3 0.9 0.48 0.05],'String',infilename,'Tag','infile');
ui_infilename_choose=uicontrol('Style','pushbutton','Units','normalized','Position',[0.8 0.9 0.16 0.05],'String','Вибрати','Callback',@guiInfileChoose_Callback);
uicontrol('Style','text','Units','normalized','Position',[0.1 0.2 0.2 0.05],'String','Вихідний файл:');
ui_infilename=uicontrol('Style','edit','Units','normalized','Position',[0.3 0.2 0.48 0.05],'String',outfilename);
ui_infilename_choose=uicontrol('Style','pushbutton','Units','normalized','Position',[0.8 0.2 0.16 0.05],'String','Вибрати','Callback',@guiOutfileChoose_Callback);

uicontrol('Style','text','Units','normalized','Position',[0.6 0.9 0.2 0.05],'String','Кількість ітерацій:');
ui_infilename=uicontrol('Style','edit','Units','normalized','Position',[0.6 0.9 0.48 0.05],'String','5','Tag','infile');

ui_ok=uicontrol('Style','pushbutton','Units','normalized','Position',[0.8 0.05 0.2 0.05],'String','Ok','Callback',@sintrendOkGUI);



function guiInfileChoose_Callback(hObject, eventdata, handles);
[file,path]=uigetfile;
fullpath=strcat(path,file);
par=get(hObject,'Parent');
childs=get(par,'Children');
set(childs(length(childs)-1),'String',fullpath);


function guiOutfileChoose_Callback(hObject, eventdata, handles);
[file,path]=uigetfile;
fullpath=strcat(path,file);

set(childs(length(childs)-4),'String',fullpath);


function sintrendOkGUI(hObject, eventdata, handles);
par=get(hObject,'Parent');
childs=get(par,'Children');
niter=str2double(get(childs(length(childs)-4),'String'));

sintrend_logabs(strcat(tempdir,'Series_SintrendMarkovPrognoz.txt'),strcat(tempdir,'Series_SintrendMarkovPrognoz.txt'),niter);
if (res_progn==1)
    RES=dlmread(strcat(tempdir,'Series_SintrendMarkovPrognoz.txt'));
    
    SERIESINDEX=SERIESINDEX+1;
    SERIES{SERIESINDEX}=RES;
    SERIESSTAT{SERIESINDEX}=getStat(RES);
    SERIESSTAT{SERIESINDEX}.fileName=SERIESSTAT{index}.fileName;
    SERIESTYPE{SERIESINDEX}=[char(SERIESTYPE{index}) ';ABS'];
    saveInfo(handles,SERIESSTAT{SERIESINDEX});
    CD=get(handles.listbox1,'String');
    [CDm,CDn]=size(CD);
    CD(CDm+1,:)='Логарифм';
    set(handles.listbox1,'String',CD);
    set(handles.listbox1,'Value',SERIESINDEX);
    
    if get(handles.checkbox1,'Value')==get(handles.checkbox1,'Max')
        figure;
        plot(RES);
    end
end
