function u = calculationBlock(x,v,d,p)
T      = x;                                  % [K] temperature of cold side

T0     = d(1);                            % [K] cold side inlet temperature
w      = d(2);                                      % [kg/s] cold side flow
pd0    = d(3);                            % [Bar] steam uppstreams pressure

m      = p(1);                                  % [kg] hold up og cold side
cp     = p(2);                        % [kJ/kgK] heat capacity of cold side
U      = p(3);                         % [kW/m2K] heat transfer coefficient 
A      = p(4);                                 % [m2] Area of heat transfer
lambda = p(5); % [kJ/kg] The enthalpy of vaporization of medium in hot side
k      = p(6);                               % [kg/Bar*s] valve coefficient
R      = p(7);                              % [kJ/kmolK] ideal gas constant
pdref  = p(8);                  % [Bar] saturated steam refference pressure
Tdref  = p(9);                 % [K] saturated steam refference temperature
Mm     = p(10);                             % [Kg/kmol] Molar mass of steam

As     = p(11);                   % [some unit] df/dt|* linearized constant
 
structure = p(12);
cascade   = p(13);
Rs = R/Mm;


switch structure
    case 0
        u = v;
    case {1,2,3,4,5,6,7,8,9,10} 
        switch structure
            case 1 %%no cascade z
                Q = cp*(v*m + (w + As*m)*T - w*T0);
                Td = Q/(U*A) + T;
            case 2 %%cascade with wd
                Q = cp*(v*m - w*T0 + (w-10)*T);
                Td = Q/(U*A) + T;
            case 3 %%cascade with Td
                Td = cp*( v*m - w*T0 + (w-10)*T )/(U*A);
                Q = U*A*(Td-T);
        end
        switch cascade
            case 0 %no cascade
                pd = pdref*exp(-(lambda/Rs)*(1/Td - 1/Tdref));
                if((pd0-pd)>1e-4)
                    u = Q/(lambda*k*(pd0-pd));
                elseif pd > pd0
                    u=1;
                else
                    u=1;
                end
            case 1 %cascade and wd is used as inner output
                u = Q/lambda;
            case 2
                u = Td;
        end
    otherwise
        u = 0.1;
end

end