function [u,vc] = CalcBlock(x,v,d,p)
% static calculation block to solve for u = q = f(v,x,d,p)
% and calculate v (vc)

V1    = p(1);                                            % [m3] tank volume
V2    = p(2);                                          % [m3] tank 2 volume
rho   = p(3);                                             % [m3/kg] density
cp    = p(4);                                     % [kJ/kg/C] specific heat
A1    = p(5);                    %[1/s] tuning param gen linear transf (vL)
A2    = p(6);                    %[1/s] tuning param gen linear transf (vL)
tau01 = p(7);                                % [s] tuning param IFAC. (vL0)
tau02 = p(8);                                % [s] tuning param IFAC. (vL0)

T    = x;                                         % [degC] tank temperature
T0   = d(1);                                % [degC] inlet flow temperature
TD   = d(2);                   % [degC] temperature of flow added to tank 2
qD   = d(3);                                  % [m3/s] flow added to tank 2 
Q    = d(4);                                    % [kW] heat added to tank 1

% switch variables to change between case
transf = p(9); % switch trasformations: 0=static; 1=lin; 2= IFAC; 3=fb lin
f2 = 1/V2*(q*(T(1)-T(2))+qD*(TD-T(2)));     % tank 2 dynamic energy balance
                               
switch transf                                  % select transformation type
     case 0                                         % static transformation
          u  = -(qD*(TD-v))/(T(1)-v);                               % u = q
          vc = (q*T(1)+qD*TD)/(q+qD);
     case 1                                         % linear trasnformation
          u = (V2*(v+A2*T(2))-qD*(TD-T(2)))/(T(1)-T(2));            % u = q
          vc = f2-A2*T2;
     case 2                                                     % IFAC. vL0
          u = (V2/tau02*(v-T(2))-qD*(TD-T(2)))/(T(1)-T(2));           % u=q
          vc = tau02*f2+T2;
     case 3           % integrating transformation. similar to feedback lin
          u  = (V2*v-qD*(TD-T(2)))/(T(1)-T(2));                     % u = q
          vc = f2;
     otherwise
end

end
