function [ndot,mdot] = MassFlow(wNH3,R,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
%   R       Hydrogen/nitrogen ratio.

% 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(3,max(numel(wNH3),numel(R)));
else
    m = zeros(3,max(numel(wNH3),numel(R)));
end
m(1,:) = (1-wNH3(:)').*2.*R(:)'./(28+2*R(:)'); 
m(2,:) = (1-wNH3(:)').*28./(28+2*R(:)'); 
m(3,:) = wNH3(:)';

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