function [sys,x0] = incins(t,x,u,flag)

% Simulink interface to incin.m
%
% Inputs:    t    - time in [s].
%            X    - States. A total of 2*N states.
%                   Temperatures of gas (1-N) and catalyst (N+1 -
%                   2*N) in each mixing tank
%            U(1) - Inlet gas temperature, T0 [K]
%            U(2) - Mass flow of process gas, m [kg/s]
%            U(3) - Mass flow of air fed to process, mair [kg/s]
%            U(4) - Mass fraction of VOC, w


% Outputs:   sys and x0 as described in the SIMULINK manual.
%            when flag is 0 sys contains sizes and x0 contains 
%            initial condition. 
%            when flag is 1, sys contains the derivatives,
%            and when flag is 3 sys contains outputs; 
%            y(1:N)      -  Gas temperature in element 1 to N [C]
%            y(N+1:2*N)  -  Catalyst temperature in element 1 to N [C]

global par T0incin

if abs(flag) == 1
  % Return state derivatives.
  sys = incin(t,x,u);
  
elseif abs(flag) == 3
  % Return system outputs.
  N = par.N;
  sys(1:2*N,1) = x(1:2*N);         % Gas and catalyst temperatures in elements 1 to N.
 
elseif flag == 0
  % Ininitalize the system
  %ssvaluesinit
  parameters
  x0 = T0incin;
  N = par.N;
  sys = [2*N, 0, 2*N, 4, 0, 0];
  
else
  sys = [];  
  
end
  
