function [ndot,mdot] = MassFlow_Ver5(wNH3,wIn,in)

% This function calculates the mass and molar flowrates for the chemicals
% in the respective streams based on the given mass fractions/ratio.
% 
% The independent variables for this are
%   wNH3    Ammonia
%   wIn     Inerts
%
% Hydrogen and nitrogen are assumed to have a fixed ratio of 3.

% The required input is given by
%   in      Array containing the flowrate, the ammonia mass fraction and
%           the H2/N2 ratio of the stream

% Import of CASADI
import casadi.*

% Calculation of the mass fractions of the streams
if isa(wNH3,'casadi.MX')
    m = MX.zeros(4,max(numel(wNH3)));
else
    m = zeros(4,max(numel(wNH3)));
end
m(1,:) = (1-wNH3(:)'-wIn).*2.*3./(28+2*3); 
m(2,:) = (1-wNH3(:)'-wIn).*28./(28+2*3); 
m(3,:) = wNH3(:)';
m(4,:) = wIn*ones(1,numel(wNH3));

% Calculation of the mass and molar flow of the streams
mdot = m*in(1);
ndot = mdot./([2 28 17 18]'*ones(1,numel(wNH3)));
A = 0;