Post Reply 
(42S, Free42) Unit Conversion Suite
02-05-2018, 02:00 PM (This post was last modified: 02-05-2018 03:27 PM by Werner.)
Post: #5
RE: (42S, Free42) Unit Conversion Suite
(edited twice already to fix bugs in the printout ;-)
I'm almost done rewriting this completely, just to see if it could be done.
I define each unit category as a matrix. First column is the alpha data; second is the multiplier, in case of TEMP the third column is the additive constant.
So eg. TEMP will look like

Code:
"TEMP" [ 4x3 Matrix ]
[[ "°C" 1 0 ]
 [ "°F" 5.55555555556E-1 32 ]
 [ "K" 1 273.15 ]
 [ "R" 5.55555555556E-1 491.67 ]
]

Then I have a single column matrix with all categories that I call CCAT, so

Code:
"CCAT" [ 12x1 MATRIX  ]
[[ "LENG"  ]
 [ "AREA"  ]
 [ "VOL"   ]
 [ "TIME"  ]
 [ "SPEED" ]
 [ "ACCEL" ]
 [ "MASS"  ]
 [ "FORCE" ]
 [ "ENERG" ]
 [ "POWER" ]
 [ "PRESS" ]
 [ "TEMP"  ]
]

Then all we need is a routine that will build a menu (with paging if necessary) out of the first column of a matrix, and treats the item chosen.
And so I end up with a single program that can treat as many conversions as you like - just define new matrices as you go along and add categories.
The routine is not 100% finished, but it already works as it is, so yes, it can be done ;-). The only drawback is that Free42 does not allow you to export a matrix, only programs. So I'll have to provide a one-shot program that creates the matrices. Here's the current to-be-worked-on version for the interested:

Code:
>LBL "CONV"
 CLX
>LBL 12
 INDEX "CCAT"
 XEQ 13
 RCL ".I"
 X>=0?
 GTO 00
 CLV ".I"
 CLV ".C"
 CLV ".B"
 EXITALL
 RTN
>LBL 00
 STO ".C"
 RCLEL
 INDEX IND ST X
 CLX
 CF 22
>LBL 11
 XEQ 13
 RCL ".I"
 X>=0?
 GTO 00
 RCL ".C"
 GTO 12
>LBL 00
 Rv
 RCLEL
 J+
 RCLEL
 J+
 RCLEL
 FS? 76
 CLX
 FC?C 22
 GTO 00
 +/-
 RCL+ ST T
 x
 STO ".B"
 X<> ST T
 GTO 01
>LBL 00
 X<>Y
 RCL ".B"
 X<>Y
 /
 +
>LBL 01
 CLA
 ARCL ST X
 +" "
 ARCL ST Y
 AVIEW
 RCL ".I"
 GTO 11
>LBL 13        -- Matrix Menu
 STO ".I"
 CLMENU
 1
 STO+ ST Y
 STOIJ
 -
 KEY 9 GTO 09
 XEQ 14
 KEY 1 GTO 01
 FS? 76
 GTO 00
 XEQ 14
 KEY 2 GTO 02
 FS? 76
 GTO 00
 XEQ 14
 KEY 3 GTO 03
 FS? 76
 GTO 00
 XEQ 14
 KEY 4 GTO 04
 FS? 76
 GTO 00
 XEQ 14
 KEY 5 GTO 05
 FS? 76
 GTO 00
 XEQ 14
 KEY 6 GTO 06
-- key 7 and 8 only when 7 or more items
 FC? 76
 GTO 07
>LBL 00
-- we reached the end. We have more than 6 items when index>0
 X=0?
 GTO 10
>LBL 07
 KEY 7 GTO 07
 KEY 8 GTO 08
>LBL 10
 MENU
 STOP
 GTO 10
>LBL 01
 1
 GTO 00
>LBL 02
 2
 GTO 00
>LBL 03
 3
 GTO 00
>LBL 04
 4
 GTO 00
>LBL 05
 5
 GTO 00
>LBL 06
 6
>LBL 00
 RCL+ ".I"
 1
 STOIJ
 Rv
 Rv
 RTN
>LBL 07        -- previous page
 RCL ".I"
 6
 -
 X>=0?
 GTO 13
         -- last page
 1
 ENTER
 STOIJ
 I-
 RCLIJ
 SIGN
 -
 STO ST Y
 6
 MOD
 -
 GTO 13 
>LBL 08        -- next page
 6
 RCL+ ".I"
 FS? 76
 CLX
 GTO 13        -- first page
>LBL 09
 -1
 STO ".I"
 RTN

>LBL 14
 CLA
 RCLEL
 Rv
 ARCL ST T
 I+
 END


No .raw file as yet though.

Cheers, Werner

41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: (42S, Free42) Unit Conversion Suite - Werner - 02-05-2018 02:00 PM



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