function varargout = start_gui(varargin)

gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @start_gui_OpeningFcn, ...
                   'gui_OutputFcn',  @start_gui_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



function start_gui_OpeningFcn(hObject, eventdata, handles, varargin)
global pushbutton2

handles.output = hObject;

guidata(hObject, handles);


function varargout = start_gui_OutputFcn(hObject, eventdata, handles) 
clc;
varargout{1} = handles.output;


function pushbutton1_Callback(hObject, eventdata, handles)
global quant number devices A S rand1 rand2 qc;
global sysusage avgwaittime avglivetime avgqueueamount avgsysamount muA muS;
global text10 text11 text12 text13 text14 text27 text28
global pushbutton2 pushbutton7 pushbutton5 pushbutton6 pushbutton8 pushbutton9 pushbutton1
global pushbutton10 pushbutton11 pushbutton15 pushbutton19 pushbutton16 pushbutton20

set(pushbutton10, 'Enable', 'off');
set(pushbutton1, 'Enable', 'off');

Main(quant,devices,rand1,rand2,A,S,qc,number);

set(pushbutton1, 'Enable', 'on');
set(pushbutton10, 'Enable', 'on');

set(pushbutton2, 'Enable', 'on');
set(pushbutton7, 'Enable', 'on');
set(pushbutton6, 'Enable', 'on');
set(pushbutton5, 'Enable', 'on');
set(pushbutton8, 'Enable', 'on');
set(pushbutton9, 'Enable', 'on');
set(pushbutton11, 'Enable', 'on');
set(pushbutton15, 'Enable', 'on');
set(pushbutton19, 'Enable', 'on');
set(pushbutton16, 'Enable', 'on');
set(pushbutton20, 'Enable', 'on');

set(text10, 'String', num2str(sysusage));
set(text11, 'String', num2str(avgwaittime));
set(text12, 'String', num2str(avglivetime));
set(text13, 'String', num2str(avgqueueamount));
set(text14, 'String', num2str(avgsysamount));
set(text27, 'String', num2str(muA));
set(text28, 'String', num2str(muS));


function edit1_Callback(hObject, eventdata, handles)
global number edit1;
number=str2num(get(edit1,'String'));
K=size(number);

if(K(1)==0) 
    number=1;
    set(edit1,'String',num2str(number));
end;
if(number<=0) 
    number=1;
    set(edit1,'String',num2str(number));
end;


function edit1_CreateFcn(hObject, eventdata, handles)

global number edit1
edit1 = gcbo;
number=str2num(get(edit1,'String'));

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function edit2_Callback(hObject, eventdata, handles)

global devices edit2;
devices = str2num(get(edit2,'String'));
K=size(devices);

if(K(1)==0) 
    devices=1;
    set(edit2,'String',num2str(devices));
end;
if(devices<=0) 
    devices=1;
    set(edit2,'String',num2str(devices));
end;


function edit2_CreateFcn(hObject, eventdata, handles)

global devices edit2
edit2 = gcbo;
devices=str2num(get(edit2,'String'));

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function edit3_Callback(hObject, eventdata, handles)

global A edit3;
A = str2num(get(edit3,'String'));
K=size(A);

if(K(1)==0) 
    A=1;
    set(edit3,'String',num2str(A));
end;
if(A<=0) 
    A=1;
    set(edit3,'String',num2str(A));
end;


function edit3_CreateFcn(hObject, eventdata, handles)

global A edit3
edit3 = gcbo;
A=str2num(get(edit3,'String'));

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit4_Callback(hObject, eventdata, handles)

global S edit4;
S = str2num(get(edit4,'String'));
K=size(S);

if(K(1)==0) 
    S=1;
    set(edit4,'String',num2str(S));
end;
if(S<=0) 
    S=1;
    set(edit4,'String',num2str(S));
end;


function edit4_CreateFcn(hObject, eventdata, handles)
global S edit4
edit4 = gcbo;
S=str2num(get(edit4,'String'));

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function edit5_Callback(hObject, eventdata, handles)

global rand1 edit5;
rand1=str2num(get(edit5,'String'));
K=size(rand1);

if(K(1)==0) 
    rand1=1;
    set(edit5,'String',num2str(rand1));
end;
if(rand1<=0) 
    rand1=1;
    set(edit5,'String',num2str(rand1));
end;


function edit5_CreateFcn(hObject, eventdata, handles)

global rand1 edit5
edit5 = gcbo;
rand1=str2num(get(edit5,'String'));

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit6_Callback(hObject, eventdata, handles)

global rand2 edit6;
rand2=str2num(get(edit6,'String'));
K=size(rand2);

if(K(1)==0) 
    rand2=1;
    set(edit6,'String',num2str(rand2));
end;
if(rand2<=0) 
    rand2=1;
    set(edit6,'String',num2str(rand2));
end;


function edit6_CreateFcn(hObject, eventdata, handles)

global rand2 edit6
edit6 = gcbo;
rand2=str2num(get(edit6,'String'));

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function pushbutton2_Callback(hObject, eventdata, handles)

global betta1 muA pushbutton2

pushbutton2 = gcbo;

plotDistribution(betta1,muA);


function pushbutton5_Callback(hObject, eventdata, handles)

global betta2 muS

plotDensity(betta2,muS);


function pushbutton6_Callback(hObject, eventdata, handles)

global betta1 muA

plotDensity(betta1,muA);


function pushbutton7_Callback(hObject, eventdata, handles)

global betta2 muS

plotDistribution(betta2,muS);


function pushbutton8_Callback(hObject, eventdata, handles)
plotTime;


function pushbutton9_Callback(hObject, eventdata, handles)
plotUsage;


function pushbutton15_Callback(hObject, eventdata, handles)
global muA
plotCorrelation(2,muA);


function pushbutton19_Callback(hObject, eventdata, handles)
global muS
plotCorrelation(3,muS);


function pushbutton16_Callback(hObject, eventdata, handles)
plotPrevFunction(2);


function pushbutton20_Callback(hObject, eventdata, handles)
plotPrevFunction(3);

function text10_CreateFcn(hObject, eventdata, handles)
global text10
text10 = gcbo;


function text11_CreateFcn(hObject, eventdata, handles)
global text11
text11 = gcbo;


function text12_CreateFcn(hObject, eventdata, handles)
global text12
text12 = gcbo;


function text13_CreateFcn(hObject, eventdata, handles)
global text13
text13 = gcbo;


function text14_CreateFcn(hObject, eventdata, handles)
global text14
text14 = gcbo;

function text27_CreateFcn(hObject, eventdata, handles)
global text27
text27 = gcbo;

function text28_CreateFcn(hObject, eventdata, handles)
global text28
text28 = gcbo;


function pushbutton2_CreateFcn(hObject, eventdata, handles)
global pushbutton2
pushbutton2 = gcbo;


function pushbutton7_CreateFcn(hObject, eventdata, handles)
global pushbutton7
pushbutton7 = gcbo;


function pushbutton6_CreateFcn(hObject, eventdata, handles)
global pushbutton6
pushbutton6 = gcbo;


function pushbutton5_CreateFcn(hObject, eventdata, handles)
global pushbutton5
pushbutton5 = gcbo;


function pushbutton8_CreateFcn(hObject, eventdata, handles)
global pushbutton8
pushbutton8 = gcbo;


function pushbutton9_CreateFcn(hObject, eventdata, handles)
global pushbutton9 
pushbutton9 = gcbo;

function pushbutton15_CreateFcn(hObject, eventdata, handles)
global pushbutton15 
pushbutton15 = gcbo;

function pushbutton19_CreateFcn(hObject, eventdata, handles)
global pushbutton19 
pushbutton19 = gcbo;


function pushbutton16_CreateFcn(hObject, eventdata, handles)
global pushbutton16 
pushbutton16 = gcbo;

function pushbutton20_CreateFcn(hObject, eventdata, handles)
global pushbutton20 
pushbutton20 = gcbo;

function pushbutton1_CreateFcn(hObject, eventdata, handles)
global pushbutton1
pushbutton1 = gcbo;


function pushbutton10_Callback(hObject, eventdata, handles)
global pushbutton10 rand1 edit5 rand2 edit6

Randomizer;

set(edit5,'String',num2str(rand1));
set(edit6,'String',num2str(rand2));


function pushbutton10_CreateFcn(hObject, eventdata, handles)
global pushbutton10 
pushbutton10 = gcbo;


function pushbutton11_Callback(hObject, eventdata, handles)
plotAvgTime;


function pushbutton11_CreateFcn(hObject, eventdata, handles)
global pushbutton11
pushbutton11 = gcbo;




function edit21_Callback(hObject, eventdata, handles)
global quant edit21

quant = str2num(get(edit21,'String'));
K=size(quant);

if(K(1)==0) 
    quant=1;
    set(edit21,'String',num2str(quant));
end;
if(quant<=0) 
    quant=1;
    set(edit21,'String',num2str(quant));
end;


function edit21_CreateFcn(hObject, eventdata, handles)
global edit21 quant
edit21 = gcbo;
quant=str2num(get(edit21,'String'));


if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit22_Callback(hObject, eventdata, handles)

global qc edit22;
qc = str2num(get(edit22,'String'));
K=size(qc);



if(K(1)==0) 
    qc=1;
    set(edit22,'String',num2str(qc));
end;
qc = round(qc);
set(edit22,'String',num2str(qc));
if(qc<0) 
    qc=1;
    set(edit22,'String',num2str(qc));
end;

function edit22_CreateFcn(hObject, eventdata, handles)

global qc edit22
edit22 = gcbo;
qc=str2num(get(edit22,'String'));

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

