Home
Generals
Unit converter
Periodic table
Molecular weight
Properties
Hydrocarbon properties
Steam properties
Psychrometric properties
Fuel gas LHV
Flue gas enthalpy
Dynamics
Equation of state
Flow convert (mass - volume)
Energy to emission
Flow rate
Darcy friction factor
Mean pressure
Flow compensation
Orifice sizing
Bernoulli equation
Steam pinhone
Control valve CV
Sizing
LMTD
Flash steam
Pump BHP
Performance
Cooling tower capability
Heater efficiency
Compressor efficiency
Turbine efficiency
About
ID
Name
Title
Keyword
Description
<div style="color: rgb(68, 68, 68); font-family: Consolas; font-size: 15px;"><div>For engineers, unit conversion is the most basic of basics. In the field, there are gauge units and absolute units, so minor mistakes can lead to very different calculation results. Also, there are times when you want to verify your unit conversion.</div><div><br></div><h2 style="margin: 0px; position: relative; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-variant-position: normal; font-weight: bold; font-stretch: normal; font-size: 14px; line-height: normal; font-family: "Trebuchet MS", Trebuchet, sans-serif; color: rgb(0, 0, 0);"><span style="font-family: Consolas;">Python code of unit converter</span></h2><div><br>The Python code below is an example of temperature and pressure engineering unit conversion.<br><span style="color: rgb(43, 0, 254);">dbUnit = [</span><br><span style="color: rgb(43, 0, 254);"> ['C', 'Temperature', 1.0, 0.0],</span><br><span style="color: rgb(43, 0, 254);"> ['K', 'Temperature', 1.0, 273.15],</span><br><span style="color: rgb(43, 0, 254);"> ['F', 'Temperature', 1.8, 32.0],</span><br><span style="color: rgb(43, 0, 254);"> ['R', 'Temperature', 1.8, 491.67],</span><br><span style="color: rgb(43, 0, 254);"> ['kPa', 'Pressure', 1.0, 0.0],</span><br><span style="color: rgb(43, 0, 254);"> ['MPa', 'Pressure', 0.001, 0.0],</span><br><span style="color: rgb(43, 0, 254);"> ['bar', 'Pressure', 0.01, 0.0],</span><br><span style="color: rgb(43, 0, 254);"> ['N/m2', 'Pressure', 1000.0, 0.0],</span><br><span style="color: rgb(43, 0, 254);"> ['atm', 'Pressure', 0.009869233, 0.0],</span><br><span style="color: rgb(43, 0, 254);"> ['at', 'Pressure', 0.01019716, 0.0],</span><br><span style="color: rgb(43, 0, 254);"> ['kg/cm2', 'Pressure', 0.01019716, 0.0],</span><br><span style="color: rgb(43, 0, 254);"> ['psia', 'Pressure', 0.1450377, 0.0],</span><br><span style="color: rgb(43, 0, 254);"> ['lbf/ft2', 'Pressure', 20.88543, 0.0],</span><br><span style="color: rgb(43, 0, 254);"> ['torr', 'Pressure', 7.500615, 0.0],</span><br><span style="color: rgb(43, 0, 254);"> ['kPag', 'Pressure', 1.0, -101.325],</span><br><span style="color: rgb(43, 0, 254);"> ['MPag', 'Pressure', 0.001, -0.101325],</span><br><span style="color: rgb(43, 0, 254);"> ['bar_g', 'Pressure', 0.01, -1.01325],</span><br><span style="color: rgb(43, 0, 254);"> ['N/m2_g', 'Pressure', 1000.0, -101325.0],</span><br><span style="color: rgb(43, 0, 254);"> ['atm_g', 'Pressure', 0.009869, -1.0],</span><br><span style="color: rgb(43, 0, 254);"> ['ate', 'Pressure', 0.01019716, -1.033227],</span><br><span style="color: rgb(43, 0, 254);"> ['kg/cm2_g', 'Pressure', 0.01019716, -1.033227],</span><br><span style="color: rgb(43, 0, 254);"> ['psig', 'Pressure', 0.1450377, -14.696],</span><br><span style="color: rgb(43, 0, 254);"> ['lbf/ft2_g', 'Pressure', 20.88543, -2116.216],</span><br><span style="color: rgb(43, 0, 254);"> ['torr_g', 'Pressure', 7.500615, -760.0],</span><br><span style="color: rgb(43, 0, 254);"> ]</span></div><div><br></div><span style="color: rgb(43, 0, 254);">def loadUnit(search):<br> for i in range(len(dbUnit)):<br> if dbUnit[i][0] == search:<br> UnitGroup = dbUnit[i][1]<br> UnitScale = float(dbUnit[i][2])<br> UnitOffset = float(dbUnit[i][3])<br><br> return UnitGroup, UnitScale , UnitOffset<br><br>def unitconv(number, Unit_old, Unit_new):<br> <br> Group_old, Scale_old, Offset_old = loadUnit(Unit_old)<br> Group_new, Scale_new, Offset_new = loadUnit(Unit_new)<br><br> if Scale_old == 0 or Group_old != Group_new: <br> return None<br><br> return ((number - Offset_old) / Scale_old) * Scale_new + Offset_new<br><br>print(unitconv(50, "C", "R")) # 50 C = 581.67 R<br>print(unitconv(10, "bar_g", "kPa")) # 10 bar_g = 1101.325 kPA</span><br></div>