function [sys,x0,str,ts] = fun(t,x,u,flag)
A = 10; % 横截面积 A
C = 2.21359; % 根号下g/k
iniState = 10; % 初始水位
switch flag,
    case 0,
    [sys,x0,str,ts]=mdlInitializeSizes(iniState);
    case 1,
    sys=mdlDerivatives(t,x,u,A,C);
    case 2,
    sys=mdlUpdate(t,x,u);
    case 3,
    sys=mdlOutputs(t,x,u);
    case 4,
    sys=mdlGetTimeOfNextVarHit(t,x,u);
    case 9,
    sys=mdlTerminate(t,x,u);
    otherwise
    DAStudio.error('Simulink:blocks:unhandledFlag', num2str(flag));
end

function [sys,x0,str,ts]=mdlInitializeSizes(iniState)

sizes = simsizes;
sizes.NumContStates  = 1; %连续状态的数量
sizes.NumDiscStates  = 0; %离散状态的数量
sizes.NumOutputs     = 1;
sizes.NumInputs      = 1;
sizes.DirFeedthrough = 0; %输出y和输入u是否是直通（直接调用）
sizes.NumSampleTimes = 1;

sys = simsizes(sizes);
x0  = iniState;
str = [];
ts  = [0 0];

function sys=mdlUpdate(t,x,u)
% update state variable
sys = [];

function sys=mdlDerivatives(t,x,u,A,C)

sys = (u - C*sqrt(x))/A;

function sys=mdlOutputs(t,x,u)

sys = x;

function sys=mdlGetTimeOfNextVarHit(t,x,u)
 % 每隔 1s 采一次样
sampleTime = 1;
sys = t + sampleTime;

function sys=mdlTerminate(t,x,u)
 
sys = [];