 function u = CalcBlock1(x,v,d,p)
% static calculation block to invert the transformation for tank 1 and
% solve for u = Q = f(v,x,d,p)

V1    = p(1);                                            % [m3] tank 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)
tau01 = p(7);                                % [s] tuning param IFAC. (vL0)
% states
T    = x;                                         % [degC] tank temperature
%disturbances
T0   = d(1);                                % [degC] inlet flow temperature
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

switch transf
     case 0                                         % static transformation
          u = q*rho*cp*(v-T0);                                        % u=Q
     case 1                                         % linear trasnformation
          u = rho*cp*(V1*(v+A1*T(1))-q*(T0-T(1)));                  % u = Q
     case 2                                                     % IFAC. vL0
          u = rho*cp*(V1/tau01*(v-T(1))-q*(T0-T(1)));                 % u=Q
     case 3           % integrating transformation. similar to feedback lin
          u = rho*cp*(V1*v-q*(T0-T(1)));                            % u = Q
     otherwise
end

end
