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

% Last Modified by GUIDE v2.5 22-May-2004 16:42:39

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @smoothFigure_OpeningFcn, ...
                   'gui_OutputFcn',  @smoothFigure_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 smoothFigure is made visible.
function smoothFigure_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 smoothFigure (see VARARGIN)

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

handles.baseFigure=varargin{1};
% Update handles structure
guidata(hObject, handles);

% UIWAIT makes smoothFigure wait for user response (see UIRESUME)
% uiwait(handles.aCorrfigure1);


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

global SERIES
global SERIESINDEX
global SERIESTYPE
global SERIESSTAT

handles2=guidata(handles.baseFigure);

% Вычисляем автокорреляцию матрицы, выделенной в ListBox
index=get(handles2.listbox1,'Value');
SRC=SERIES{index};

RESX=smoothing(SRC,str2num(get(handles.smoothFigureedit1,'String')), ...
                   str2num(get(handles.smoothFigureedit2,'String')));

SERIESINDEX=SERIESINDEX+1;
SERIES{SERIESINDEX}  =RESX;
SERIESTYPE{SERIESINDEX}=[char(SERIESTYPE{index}) ';SMTH'];
SERIESSTAT{SERIESINDEX}=getStat(RESX);
SERIESSTAT{SERIESINDEX}.fileName=SERIESSTAT{index}.fileName;
CD=get(handles2.listbox1,'String');
[CDm,CDn]=size(CD);
CD(CDm+1,:)='Сглажив.';
set(handles2.listbox1,'String',CD);

if get(handles.checkbox2,'Value')==get(hObject,'Max')
    if get(handles.checkbox3,'Value')==get(hObject,'Max')
        loglog(RESX,'.-');
    else
        semilogx(RESX,'.-');
    end
else
    if get(handles.checkbox3,'Value')==get(hObject,'Max')
        semilogy(RESX,'.-');
    else
        plot(RESX,'.-');
    end
end

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

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

%========================================================================================================================
% --- 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
if get(hObject,'Value')==get(hObject,'Max')
    set(handles.axes1,'XScale','log');
else
    set(handles.axes1,'XScale','linear');
end

%========================================================================================================================
% --- 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
if get(hObject,'Value')==get(hObject,'Max')
    set(handles.axes1,'YScale','log');
else
    set(handles.axes1,'YScale','linear');
end
