(11C) Pressure Units Conversion (ATM, PSI and PSF)
06-13-2018, 08:53 AM (This post was last modified: 06-13-2018 09:15 AM by Gamo.)
Post: #1
 Gamo Senior Member Posts: 458 Joined: Dec 2016
(11C) Pressure Units Conversion (ATM, PSI and PSF)
Program to convert three type of pressure units between any one of ATM, PSI and PSF.

[A] ATM (Atmospheric Pressure)
[B] PSI (Pound-force per square inch)
[C] PSF (Pound-force per square foot)

Example: Using FIX 4 and on User Mode f [USER]

Convert 1 ATM to PSI
1 [A] display 0.0000
[B] display 14.6959

Convert 40 PSI to ATM
40 [B] display 0.0000
[A] display 2.7218

Convert 1100 PSF to ATM
1100 [C] display 0.0000
[A] display 0.5198

Program: Pressure Units Conversion (ATM, PSI and PSF)
Code:
 LBL A  // ATM 101325 x 0 X=Y GTO 1 R↓ STO 0 CLx RTN --------------------------------------------------------------------------- LBL B  //  PSI 6894.7572   // Decimal point between 4 and 7 x 0 X=Y GTO 1 R↓ STO 0 CLx RTN ----------------------------------------------------------------------------- LBL C  //  PSF 47.88   // Decimal point between 7 and 8 x 0 X=Y GTO 1 R↓ STO 0 CLx RTN --------------------------------------------------------------------------- LBL 1 RCL 0 LSTx ÷ RTN

Gamo
06-13-2018, 12:55 PM (This post was last modified: 06-13-2018 06:50 PM by Dieter.)
Post: #2
 Dieter Senior Member Posts: 2,401 Joined: Dec 2013
RE: (11C) Pressure Units Conversion (ATM, PSI and PSF)
(06-13-2018 08:53 AM)Gamo Wrote:  Program to convert three type of pressure units between any one of ATM, PSI and PSF.

That's a nice little program that can even do more than you said. ;-)
Here is the general idea:

Enter a number and press A, B or C to input the known pressure.
Enter zero and press A, B or C to output the converted unit.
The zero is automatically set after an input, so you can directly press the key for the target unit.

(06-13-2018 08:53 AM)Gamo Wrote:  Convert 1 ATM to PSI
1 [A] display 0.0000
[B] display 14.6959

Here you can continue and get all possible units – just enter zero:

0 [C] => 2116,2166 psf
0 [B] => 14,6959 psi
0 [A] => 1,0000 atm

(note: these results are obtained with the exact conversion factors, i.e. with 6894,757293 and 47,88025898 instead of the rounded values)

The idea is simple: all input is converted to a common unit, in this case it's Pascal:
1 atm = 101325 Pa
1 psi = 6894,757... Pa
1 psf = 47,88... Pa

The Pascal-value is stored in R0. From there it is divided by the respective factor to get the desired unit.

So you can use this program for conversions to and from other units as well. Just change the constants.

You can even select one of the units as the "common unit" to which all input is converted. This way one of the constants becomes 1. Here for instance one could do so by dividing all constants by 47,88... so that the common unit now is psf instead of Pascal. This way the constants become

LBL A: 2116,216624  (psf per atm)
LBL B: 144  (psf per psi)
LBL C: 1  (psf per psf)

Re. programming: The program can be much shorter as most of the commands following LBL A B and C are identical.

Here's a version that implements both the unit change as well as the shorter code:

Code:
LBL A 2116,216624 GTO 0 LBL B 144 GTO 0 LBL C 1 LBL 0 x x=0? GTO 1 STO 0 CLX RTN LBL 1 R↓     // not required, but keeps previous results on the stack RCL 0 LastX ÷ RTN

Of course this gives the same results:

1 [A] => 0,0000
[B] => 14,6959
0 [C] => 2116,2166

Check:

0 [B] => 14,6959
0 [A] => 1,0000

Likewise you use the same program for conversions between, say, kilometers, miles and feet. Simply change the three constants:

LBL A: 3280,839895  (feet per kilometer)
LBL B: 5280  (feet per mile)
LBL C: 1  (feet per foot)

Convert 1 mile to kilometers and feet:

1 [B] => 0,0000
[A] => 1,6093
0 [C] => 5280,0000

So this is indeed a handy program that can be used for much more than just pressure conversions.

Dieter

Edit: corrected some units, hoping everything is OK now. ;-)
06-14-2018, 01:20 AM
Post: #3
 Gamo Senior Member Posts: 458 Joined: Dec 2016
RE: (11C) Pressure Units Conversion (ATM, PSI and PSF)
Thank You Dieter your program version is more streamline and easier to adapt to other units type.

Gamo
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)