function tpwsData = tpws_Convu(tpwsStandard)
% Description:      Converts a tpws data structure from the standard IAPWS
%                   units to the unit set defined by tpwsUnits
% -------------------------------------------------------------------------
% Syntax:           tpwsData = tpws_Convu(tpwsStandard)
%                   tpwsStandard    Data structure containing standardized
%                                   IAPWS units
% -------------------------------------------------------------------------
% Output:           tpwsData        Data structure containing values in
%                                   units defined by tpwsUnits

global tpwsUnits

tpwsData = tpwsStandard;

% ------------------------------------------------------------
% Convert Temperature from K into desired units
% ------------------------------------------------------------
switch tpwsUnits.T
    case {'K'}
        tpwsData.T = tpwsStandard.T;
    case {'C'}
        tpwsData.T = tpwsStandard.T - 273.15;
    case {'F'}
        tpwsData.T = (tpwsStandard.T * 1.8) - 459.67;
    case {'R'}
        tpwsData.T = tpwsStandard.T * 1.8;
end
% ------------------------------------------------------------
% Convert Pressure from MPa into desired units
% ------------------------------------------------------------
switch tpwsUnits.p
    case {'MPa'}
        tpwsData.p = tpwsStandard.p;
    case {'bar'}
        tpwsData.p = tpwsStandard.p * 10;
    case {'kPa'}
        tpwsData.p = tpwsStandard.p * 1000;
    case {'Pa'}
        tpwsData.p = tpwsStandard.p * 1000000;
    case {'atm'}
        tpwsData.p = tpwsStandard.p * 9.869232667160;
    case {'psia'}
        tpwsData.p = tpwsStandard.p * 145.0377377302;
end
% ------------------------------------------------------------
% Convert Specific Volume from m3/kg into desired units
% ------------------------------------------------------------
switch tpwsUnits.v
    case {'m3/kg'}
        tpwsData.v = tpwsStandard.v;
    case {'m3/mol'}
        tpwsData.v = tpwsStandard.v * 0.0180158;
    case {'L/mol'}
        tpwsData.v = tpwsStandard.v * 0.0180158 * 1000;
    case {'mL/g'}
        tpwsData.v = tpwsStandard.v * 1000;
    case {'ft3/lbm'}
        tpwsData.v = tpwsStandard.v * 16.01846337396;
    case {'ft3/lbmol'}
        tpwsData.v = tpwsStandard.v * 16.01846337396 * 18.0158;    
end
% ------------------------------------------------------------
% Convert Internal Energy/Enthalpy from kJ/kg into desired units
% ------------------------------------------------------------
switch tpwsUnits.e
    case {'kJ/kg'}
        tpwsData.u = tpwsStandard.u;
        tpwsData.h = tpwsStandard.h;
    case {'kJ/mol'}
        tpwsData.u = tpwsStandard.u * 0.0180158;
        tpwsData.h = tpwsStandard.h * 0.0180158;
    case {'kcal/g'}
        tpwsData.u = tpwsStandard.u * 0.0002390057361377;
        tpwsData.h = tpwsStandard.h * 0.0002390057361377;
    case {'kcal/mol'}
        tpwsData.u = tpwsStandard.u * 0.0002390057361377 * 18.0158;
        tpwsData.h = tpwsStandard.h * 0.0002390057361377 * 18.0158;
    case {'Btu/lbm'}
        tpwsData.u = tpwsStandard.u * 0.4299226139295;
        tpwsData.h = tpwsStandard.h * 0.4299226139295;
    case {'Btu/lbmol'}
        tpwsData.u = tpwsStandard.u * 0.4299226139295 * 18.0158;
        tpwsData.h = tpwsStandard.h * 0.4299226139295 * 18.0158;
end
% ------------------------------------------------------------
% Convert Entropy/Heat Capacity from kJ/kg K into desired units
% ------------------------------------------------------------
switch tpwsUnits.e2
    case {'kJ/kg K'}
        tpwsData.s = tpwsStandard.s;
        tpwsData.c_p = tpwsStandard.c_p;
        tpwsData.c_v = tpwsStandard.c_v;
    case {'kJ/mol K'}
        tpwsData.s = tpwsStandard.s * 0.0180158;
        tpwsData.c_p = tpwsStandard.c_p * 0.0180158;
        tpwsData.c_v = tpwsStandard.c_v * 0.0180158;
    case {'J/mol K'}
        tpwsData.s = tpwsStandard.s * 18.0158;
        tpwsData.c_p = tpwsStandard.c_p * 18.0158;
        tpwsData.c_v = tpwsStandard.c_v * 18.0158;
    case {'kcal/g C'}
        tpwsData.s = tpwsStandard.s * 0.0002390057361377;
        tpwsData.c_p = tpwsStandard.c_p * 0.0002390057361377;
        tpwsData.c_v = tpwsStandard.c_v * 0.0002390057361377;
    case {'kcal/mol C'}
        tpwsData.s = tpwsStandard.s * 0.0002390057361377 * 18.0158;
        tpwsData.c_p = tpwsStandard.c_p * 0.0002390057361377 * 18.0158;
        tpwsData.c_v = tpwsStandard.c_v * 0.0002390057361377 * 18.0158;
    case {'cal/mol C'}
        tpwsData.s = tpwsStandard.s * 0.0002390057361377 * 18015.8;
        tpwsData.c_p = tpwsStandard.c_p * 0.0002390057361377 * 18015.8;
        tpwsData.c_v = tpwsStandard.c_v * 0.0002390057361377 * 18015.8;
    case {'Btu/lbm F'}
        tpwsData.s = tpwsStandard.s * 0.2388458966275;
        tpwsData.c_p = tpwsStandard.c_p * 0.2388458966275;
        tpwsData.c_v = tpwsStandard.c_v * 0.2388458966275;
    case {'Btu/lbmol F'}
        tpwsData.s = tpwsStandard.s * 0.2388458966275 * 18.0158;
        tpwsData.c_p = tpwsStandard.c_p * 0.2388458966275 * 18.0158; 
        tpwsData.c_v = tpwsStandard.c_v * 0.2388458966275 * 18.0158; 
end