function [sys,x0,str,ts] = hs11m(t,x,u,flag)
% Deviation model of the level tank;

% F1*(dx1/dt) + c1*x1 + c2*(x1+h1s)^(1/2) - c2*(h1s)^(1/2) = u1 ;
% h1s =1.5 dm, q0s= 0.006359 dm^3/s    ;
% c1= 0.00153322 dm^2/s ,  c2 = 0.00331442 (dm^5/2)/s      ;  

% F1 = 1.44dm^2,  Step change q00s = new value for t>=0;
% u1 is constrained as <-0.006359, 0.004161 dm^3/s>;
  
  switch flag,
   case 0     
    [sys,x0,str,ts] = mdlInitializeSizes;
   case 1,
    sys = mdlDerivatives(t,x,u);
   case 3,
    sys = mdlOutputs(t,x,u);
   case 9                                                
    sys = [];
  end
  
function [sys,x0,str,ts] = mdlInitializeSizes()
  sizes = simsizes;
  
  sizes.NumContStates  = 1;
  sizes.NumDiscStates  = 0;
  sizes.NumOutputs     = 1;
  sizes.NumInputs      = 1;
  sizes.DirFeedthrough = 0;
  sizes.NumSampleTimes = 1;
  
  sys = simsizes(sizes);
  x0  = [0];
  str = [];
  ts  = [0 0];
  
function sys = mdlDerivatives(t,x,u)
        c1 = 0.00153322;
        f1 = 1.44;
        a1 = -(c1/f1);
        c2 = 0.00331442;
        a2 = -(c2/f1);
        b1 = 1/f1;
        h1s = 1.5; 
% Right hand sides;
        x1 = x(1)+h1s;
        if x1 < 0 
          x1 = 0;
        end
        sys(1) = a1*x(1) + a2*sqrt(x1) - a2*sqrt(h1s) + b1*u(1);

function sys = mdlOutputs(t,x,u)
  sys = x;
