%main program file

function Main(nd,j1,j2,j3,b1,b2,qcap,VC);

global MatrixIn;
global j01 j02 betta1 betta2 ValueCount numdev numpr pi
global NextDepart NextArrive Devices numfinished numinput Queue
global systime time alltimeinqueue alltimeatwork TimeCount muA muS
global amountinqueue amountinwork amountinsystem
global sysusing averagedelay averagewait averagequeueamount averagesysamount
global numrefused queuecapacity dynamicsysusing dynamicalltimeinqueue dynamicalltimeatwork
global pusnbutton2 

    numpr = 6;

    pi = zeros(1,numpr);

    numdev = nd;
    j01 = j1;
    j02 = j2;
    betta1 = b1;
    betta2 = b2;
    ValueCount = VC;
    queuecapacity = qcap;

    systime = 0;

    time = zeros (1,2*ValueCount);
    alltimeinqueue = 0;
    alltimeatwork = 0;
    TimeCount = 0;

    dynamicalltimeinqueue = zeros(1,2*ValueCount);
    dynamicalltimeatwork = zeros(1,2*ValueCount);
    amountinqueue = zeros(1,2*ValueCount);
    amountinwork = zeros(1,2*ValueCount);
    amountinsystem = zeros(1,2*ValueCount);
    dynamicsysusing = zeros(1,2*ValueCount);

    MatrixIn = zeros(4,ValueCount);

    NextDepart = zeros(1,numdev);
    for i=1:numdev
        NextDepart(i) = 10^30;
    end;

    NextArrive = MatrixIn(2,1);

    numfinished = 0;
    numinput = 0;
    numrefused = 0;

    Devices = zeros(1,numdev);

    Queue = zeros(1,1);

    Generate;

    Priority(j3);

    while numfinished<ValueCount
        if min(NextDepart)<NextArrive
            Departure;
        else 
            Arrival;
        end;
    end;

    Resulter;