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

global tpwsUnits

tpwsStandard = tpwsData;

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