function [sys,x0,str,ts] = s_sep(t,x,u,flag,ID,L,rho_L,RTmg,h0,P0,mode,FlowBasis)
switch flag

  %%%%%%%%%%%%%%%%%%
  % Initialization %
  %%%%%%%%%%%%%%%%%%
  case 0,

    [sys,x0,str,ts]=Initialize(ID,L,rho_L,RTmg,h0,P0,mode);


  %%%%%%%%%%%%%%%
  % Derivatives %
  %%%%%%%%%%%%%%%
  case 1,
   
    sys=sepmod(x,u,'derivatives',ID,L,rho_L,RTmg,mode,FlowBasis);

  %%%%%%%%%%
  % Update %
  %%%%%%%%%%
  case 2,
    % sys=mdlUpdate(t,x,u);

  %%%%%%%%%%%
  % Outputs %
  %%%%%%%%%%%
  case 3,
   
    sys=sepmod(x,u,'measurements',ID,L,rho_L,RTmg,mode,FlowBasis);


  %%%%%%%%%%%%%%%%%%%%%%%
  % GetTimeOfNextVarHit %
  %%%%%%%%%%%%%%%%%%%%%%%
  case 4,
    % sys=mdlGetTimeOfNextVarHit(t,x,u);

  %%%%%%%%%%%%%
  % Terminate %
  %%%%%%%%%%%%%
  case 9,
    % sys=mdlTerminate(t,x,u);

  %%%%%%%%%%%%%%%%%%%%
  % Unexpected flags %
  %%%%%%%%%%%%%%%%%%%%
  otherwise
    error(['Unhandled flag = ',num2str(flag)]);

end

% end sfuntmpl

%
%=============================================================================
% mdlInitializeSizes
% Return the sizes, initial conditions, and sample times for the S-function.
%=============================================================================
%

function [sys,x0,str,ts,data]=Initialize(ID,L,rho_L,RTmg,h0,P0,mode)

%
% call simsizes for a sizes structure, fill it in and convert it to a
% sizes array.
%
% Note that in this example, the values are hard coded.  This is not a
% recommended practice as the characteristics of the block are typically
% defined by the S-function parameters.
%
sizes = simsizes;

sizes.NumContStates  = 2;
sizes.NumDiscStates  = 0;
sizes.NumOutputs     = 3;
sizes.NumInputs      = 4;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 1;   % at least one sample time is needed

sys = simsizes(sizes);

%
% initialize the initial conditions
%
A=ID^2*pi/4;
V=A*L;
if mode
    phi=acos((ID-2*h0)/ID);
    AL=A*phi/pi-ID^2*cos(phi).*sin(phi)/4;
    VL=AL*L;
else
    VL=h0*A;
end
mL=rho_L*VL;
mG=P0*(V-VL)/RTmg;
x0=[mL;mG];
%
% str is always an empty matrix
%
str = [];
%
% initialize the array of sample times
%
ts  = [0 0];
%data=initialize;
% end mdlInitializeSizes



