#pragma mode( separator(.,;) integer(h64) )
EXPORT SIR()
//-----------------------------------
//   Solves the  equations   
//   for an epedemic model called
//   SIR. 
//   
//   Sources:
//  Essential mathematical biology
//  Nicolas F. Britton (Springer) 
// 
//  Growth and Diffusion Phenomena
//        Robert B.Banks
// 
//       
//    TA, 27.3.2020
//-------------------------------------



BEGIN
LOCAL S0,I0,R0;
LOCAL T,S,I,R,TI,TF;
LOCAL SP,IP,RP;
LOCAL DT,DS,DI,DR,K,NSTEP;
LOCAL BETA,GAMMA;

// Init. of some default values
TI:=0;
TF:=200;
//  default of 500 euler steps;
// change if  necessary
NSTEP:=500;

S0:=99;
I0:=1;
R0:=0;

GAMMA:=.1;
BETA:=GAMMA/100;

INPUT({S0,I0,R0,BETA,GAMMA,TF}, "Parameters of Simulation", {"S0=","I0=","R0=","BETA=","GAMMA=","TF="}, 
{"Number of SUSCEPTIBLES", "Number of INFECTIVES","Number of REMOVED","INFECTION RATE","REMOVAL RATE","TFINAL"});
DT:=(TF-TI)/NSTEP;
T:=TI;
S:=S0;
I:=I0;
R:=R0;
// clear canvas
PRINT();
PRINT("==Start values===============");
PRINT("T="+T);
PRINT("S="+S);
PRINT("I="+I);
PRINT("R="+R);

L1:={TI};
L2:={S};
L3:={I};
L4:={R};
// start over loop over Euler steps
FOR K FROM 1 TO NSTEP DO
//  the SIR-Equations 
  SP:=−BETA*S*I;
  IP:=BETA*S*I-GAMMA*I;
  RP:=GAMMA*I;
  DS:=SP*DT;
  DI:=IP*DT;
  DR:=RP*DT;
  T:=T+DT;
  S:=S+DS;
  I:=I+DI;
  R:=R+DR;

L1:=CONCAT(L1,{T});
L2:=CONCAT(L2,{S});
L3:=CONCAT(L3,{I});
L4:=CONCAT(L4,{R});
END;
//  storing the results in the tabular of Statistics 2Var App
C1:=L1;
C2:=L2;
C3:=L3;
C4:=L4;

  PRINT("==End values===============");
  PRINT("T="+T);
  PRINT("S="+S);
  PRINT("I="+I);
  PRINT("R="+R);
END;
