Post Reply 
(42) Conversions
02-10-2018, 04:27 PM
Post: #1
(42) Conversions
Conversions

Using the Dynamic Menu DMENU from a previous post, and defining a matrix per units
category, and one with all categories, this program will allow you to do unit conversions like Dave Britten's Unit Conversion Suite

Code:
 { 133-Byte Prgm }
>LBL "CONV"
 1
>LBL 12            -- browse categories
 CLA
 INDEX "CCAT"
 1
 STOIJ
 XEQ 13
 FC?C 25
 GTO 00
 CLV ".C"
 CLV ".B"
 EXITALL
 RTN
>LBL 00            -- save cat page index
 RCLIJ
 Rv
 STO ".C"
 RCLEL
 INDEX IND ST X        -- and INDEX unit category matrix
 CF 22

>LBL 11            -- units within a category
 XEQ 13
 FC?C 25
 GTO 00
 RCL ".C"        -- when EXITed, return to categories menu
 GTO 12
>LBL 00
 RCLEL
 J+
 RCLEL
 J+
 RCLEL
 FS? 76            -- when only two columns, additive constant is zero.
 CLX
 J-
 J-
 FC?C 22
 GTO 00
 +/-            -- number entry
 RCL+ ST T
 *
 STO ".B"
 X<> ST T
 GTO 01
>LBL 00            -- no entry
 X<>Y
 RCL ".B"
 X<>Y
 /
 +
>LBL 01
 CLA
 ARCL ST X
 +" "
 ARCL ST Y
 AVIEW
 GTO 11

>LBL 13            -- Matrix Menu
 GTO "DMENU"
 END

Below are the matrix definitions. In Free42 windows, you can just paste them to the stack and store them in the appropriate variable. For iOS (and I guess, Android), you can paste them into Google sheets first.
(The ENERG matrix does not work since the J for Joule is considered the imaginary unit, i. So, put anything else, copy the matrix and correct it afterwards.)
But for the DM42, those are not an option. So attached you'll find a 2700-Byte program CRMATS to create these matrices. That is probably the easiest option for all platforms. And before you ask, no, I did not type these in, I generated them with two utility programs:
- PRMP Print Matrix Program: given a matrix, will print out the instructions to generate the matrix as a program.
- CRCRM Create the Create Matrices program: loops over the matrix of categories and prints out each matrix in succession.
I've attached these, too, in case anyone's interested.

"CCAT" -- 12x1 MATRIX
LENG
AREA
VOL
TIME
SPEED
ACCEL
MASS
FORCE
ENERG
POWER
PRESS
TEMP

"LENG" -- 22x2 MATRIX
m 1
cm 0.01
mm 0.001
yd 0.9144
ft 0.3048
in 0.0254
Mpc 3.08567818585e22
pc 3.08567818585e16
ly 946052840488E4
au 1495979E5
km 1000
mi 1609.344
nmi 1852
miUS 1609.34721869
chain 20.1168402337
rd 5.02921005842
fath 1.82880365761
ftUS 3.04800609601E-1
mil 254E-7
μ 1E-6
Ä 1E-10
fermi 1E-15

"AREA"
m↑2 1
cm↑2 1ᴇ-4
b 1ᴇ-28
yd↑2 0.83612736
ft↑2 0.09290304
in↑2 64516ᴇ-8
km↑2 1ᴇ6
ha 1ᴇ4
a 100
mi↑2 2589988.11034
miUS↑2 2589998.47032
acre 4046.87260987

"VOL"
m↑3 1
st 1
cm↑3 1ᴇ-6
yd↑3 0.764554857984
ft↑3 0.028316846592
in↑3 1.6387064ᴇ-5
l 1ᴇ-3
galUK 4546092ᴇ-9
galC 454609ᴇ-8
gal 0.003785411784
qt 9.46352946ᴇ-4
pt 4.73176473ᴇ-4
ml 1ᴇ-6
cu 2.365882365ᴇ-4
ozfl 2.95735295625ᴇ-5
ozUK 2.8413075ᴇ-5
tbsp 1.47867647813ᴇ-5
tsp 4.92892159375ᴇ-6
bbl 0.158987294928
bu 0.03523907
pk 0.0088097675
fbm 0.002359737216

"TIME"
yrCal 31536ᴇ3
yrSol 31556925.9747
d 86400
h 3600
min 60
s 1

"SPEED"
m/s 1
cm/s 0.01
ft/s 0.3048
kph 2.777777777777777777777777777777778e-1
mph 0.44704
kn 5.144444444444444444444444444444444e-1
c 299792458

"ACCEL"
m/s↑2 1
ft/s↑2 0.3048
g 9.80665
Gal 0.01

"MASS"
kg 1
g 0.001
lb 0.45359237
oz 0.028349523125
slug 14.5939029372
lbt 0.3732417
ton 907.18474
tonUK 1016.0469088
t 1000
ozt 0.031103475
ct 0.0002
grain 0.00006479891
u 1.66057E-27

"FORCE"
N 1
dyn 1ᴇ-5
gf 980665ᴇ-8
kip 4448.22161526
lbf 4.44822161526
pdl 0.138254954376

"ENERG"
JJ 1
erg 1ᴇ-7
Kcal 4186.8
cal 4.1868
Btu 1055.05585262
ft×lbf 1.35581794833
therm 105506ᴇ3
MeV 160219ᴇ-18
eV 160219ᴇ-24

"POWER"
W 1
hp 745.699871582
Btu/h 0.29307107

"PRESS"
Pa 1
atm 101325
bar 1.0E5
psi 6894.75729317
torr 133.322368421
mmHg 133.322368421
inHg 3386.38815789
inH2O 248.84
cmH2O 97.968503937

"TEMP" -- 4x3 Matrix
°C 1 0
°F 5.555555555555555555555555555555556e-1 32
K 1 273.15
R 5.555555555555555555555555555555556e-1 491.67

Cheers, Werner


Attached File(s)
.zip  CONV.zip (Size: 3.51 KB / Downloads: 87)

41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE
Find all posts by this user
Quote this message in a reply
10-20-2020, 12:27 PM
Post: #2
RE: (42) Conversions
(02-10-2018 04:27 PM)Werner Wrote:  Conversions

Using the Dynamic Menu DMENU from a previous post, and defining a matrix per units
category, and one with all categories, this program will allow you to do unit conversions like Dave Britten's Unit Conversion Suite

Hi Werner,
i am using your program with customized uom for my needs.
It works very well, thank you!

I have one question: is there a way to take the number to be "converted" from X register and have the result on the stack?

Thank you
Marco Polo
Find all posts by this user
Quote this message in a reply
10-20-2020, 03:22 PM
Post: #3
RE: (42) Conversions
It's a change I wanted to make myself, so I'll look into it ;-)
Werner

41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE
Find all posts by this user
Quote this message in a reply
06-25-2021, 02:52 AM
Post: #4
RE: (42) Conversions

Has this idea been implimented? Just curious, like the flexibility of Werner's matrix version, but functionality..... :/

-MFelzien
Find all posts by this user
Quote this message in a reply
Post Reply 




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