function [sys,x0,str,ts] = s1(t,x,u,flag,qv1s,s1,k1)

switch flag,
case 0
   [sys,x0,str,ts] = mdlInitializeSizes(qv1s,s1,k1); % Initialization
case 1
   sys = mdlDerivatives(t,x,u,qv1s,s1,k1); % Calculate derivatives
case 3
   sys = mdlOutputs(t,x,u); % Calculate outputs
case {2, 4, 9} % Unused flags
   sys = [];
otherwise
   error(['unhandled flag = ',num2str(flag)]); % Error handling
end


function [sys,x0,str,ts] = mdlInitializeSizes(qv1s,s1,k1)
sizes = simsizes;
sizes.NumContStates  = 1;
sizes.NumDiscStates  = 0;
sizes.NumOutputs     = 1;
sizes.NumInputs      = 1;
sizes.DirFeedthrough = 0; % Matrix D is empty.
sizes.NumSampleTimes = 1;
sys = simsizes(sizes); 
h1s=((qv1s)/k1)^2;
x0(1)=h1s;
str = []; 
ts = [0];   

function sys = mdlDerivatives(t,x,u,qv1s,s1,k1)
if x(1)<0
x(1)=0;
end
sys=1/s1*u(1)-k1/s1*sqrt(x(1));

function sys = mdlOutputs(t,x,u)
sys=x+(0.025-0.01*rand);   
