Rautenberg Logo

Unitman

A flexible unit manager for the HP49G/HP49+
Integrates and removes units and unit directories in the UNITS menu system

Unitman is a small library whose most important first four commands will be explained in examples. Thanks to a powerful machinery, each user-defined unit can appear in a builtin unit directory and is treated like a builtin unit. This is done with AddU. Each unit menu can completely be reorganized by the command roUM (reorganize Unit Menu). That is, units can be reordered, some dispensable units removed or perhaps renamed. Similarly, roUD (reorganize Unit Directories) reorganizes the entire UNITS directory system. You may add a new UDir (Unit Directory) or  reorder, rename and purge. The builitin system expands itself by the UDir MONEY for converting currencies when pressing ExpU (expand Units system) or any other command. ExpU also sets the new UNITS menu and is run by all other commands, no need for separate execution.

A main advantage of Unitman is that the famous and highly efficient 3-fold functionality of unit keys known from the 48 (see Remark 1 below) works for user-defined units as well. Most Unitman commands set RPN mode. There is no smart unit management in algebraic mode. Unitman commands also set USR and soft-menu mode to operate properly. Assign «359 MENU» to the rightshift-hold key 84.31 because we'll need the Unitman commands permanently in the examples below. You may assign it also to any other key except 84.3 which is handled by Unitman itself. EditU edits a user-defined unit for updating as explaind in Example 7. DelUK deletes the assignment and puts it on the stack, e.g. for compression and  reassignment. Your HP49 ROM must not be older than 19-3. Tested also in ROM 1.22 on the HP49+.

Abreviations: NS = nonshift, RS =  rightshift, LS = leftshift, LS+ = Leftshift hold.


What is New?

Version 4.2004. EditU and the corresponding Example 7 below revised

VERSION 3.2003. Command EditU modified. See Example 7

VERSION 2.2003. Command EditU added. Allows to edit a user-defined unit for redefinition, see below. Examples 6 und 7 added. This document updated

VERSION 1.2003: DelUK not only deletes the Unit Key assignment but recalls it for a later reassignment. This document is a revised html version of Unitman.txt. There exist also a German version UnitmanD.htm. The euro symbol is a graphic object to avoid outprint problems. Setting the cursor on the pictures yields some additional information.

VERSION 1.2002: Since Unitman becomes still more important in the EURO-age this text has thoroughly been revised.

VERSION 9.2001: Minor change in ROMPTR 167 D (the only one occurring in the assignment at the UNITS key). No change in functionality.

VERSION 8.2001: Command Upgrd replaced by DelUK. Should only be used for making a completely new customization. Previously defined units need not be redefined if the corresponding global names still exist. Simply put them back into their categories with AddU (Add Unit) in a list.


1. Let's first define the currency EUR in the new MONEY dir which contains only the (US)$ after a first run of AddU or ExpU. Pressing ExpU is not mandatory.Defining a new unit It  is run automatically by AddU and other commands. Simply press AddU and fill in the AddU dialog box after choosing the name MONEY in the dialog box. EUR may be printed as it stands, but better you choose the euro-symbol € on ALPHA Rigthshift 4. A unit name must be entered as a string because its global name may be a illegal, 'kg/m^2', say. Define has to be answered here since EUR or € is not known to the HP49 as a unit. The Define field accepts units only. These generally start with a real followed by an underscore as shown in the screen-shot. Type ALPHA Leftshift 4 to get the $ sign and finally, press OK. Then € appear indeed in MONEY! Any amount of Dollars is now readily converted to EUR and conversely. For instance, print 100, press € and then leftshift $. This results in 107_$.

Attention: Both $ and € now also appear as names in HOME provided the example is executed in HOME. We recommend to hide small unit-files, the easiest with a filer from the Filers package or Filer6 for the 49+. If a name like '$' was already used in another context, it is not overwritten but the new created unit name has priority in execution. $ and hence all currencies based on it are dimensionless but you may easily redefine the $, see Example 7.

2. Next, we want the important unit ms (millisecond) to appear in TIME. We did already fill in the dialog box which should look as shown. The Define-option may now safely be skipped. An input is not necessary Adding a unit known to the system because the system knows the prefix m and the unit s, and hence ms, although a unit name ms does not show up in the builtin TIME menu. With AddU, we force it to appear! Generally, units deriving from existing unit names by prefixing with D (Deco), h (hecto), ... or d (deci), m (milli), ... as listed in the manual, are known to CONVERT and other commands, even if not occurring in the builtin menus. Nothing is written in HOME in such a case. The UnitName field does accept also a list of strings of unitnames. But all of these must be well-defined units, either builtin or user-defined in a previous version of Unitman, say. E.g., after creating the extra page for frequency units as proposed in the next example, one may add {"KHz" "rpm"} in one stroke to the page of frequencies without writing anything in the Define field. Both units are known to the HP49. The unit rpm (revolutions per minute) occurs in 117 MENU. The conversion here is 1_Hz = 60_rpm.


3. The order of the present TIME menu is somewhat unpleasant. It seems better to open an extra page for frequency units like Hz, MHz etc. This can be done with roUM (reorgenize Unit Menu).The special stack for reorder, rename and delete Press roUM, choose the UDir TIME and press OK. That creates a special stack (similar to the interactive stack) which looks as in the screen-shot. This is a copy of the current TIME menu with "ms" already added. The initial cursor position is located at "ms". Now move the cursor to Hz and press ROLL which rolls Hz to position 1. The new TIME menu will have yr, d, h, min, s, ms on page 1, and Hz on page 2. Finally, press ENTER or ON to leave the stack and convince yourself by visiting TIME. The special stack cannot be aborted, program execution continues no matter whether ENTER or CANCEL is pressed. Hence, take care in changes. A unit is always closely related to its inverse. For instance, pressing 1/x on 440_Hz (concert pitch)  you get 0.00227..._1/Hz  = 0.0027.._s  as is confirmed by pressing UBASE. See also Example 6. The 2nd TIME page may be completed by adding the units KHz, KHz, GHz which need no definition, and a frequency unit tic defined as 1_tic = 8192_Hz. This is the mumber of internal clock tics of the HP4x calculators in a second. If you like to understand the clock tic as time unit you may edit and redefine it as in Example 7 to get 1_s = 8192_tic.You may also create a separate frequency directory, FREQ say, as in Example 4.

Important: In the special stack use only the menu options ROLL and ROLLD to reorder, the backspace key 45.1 for deleting (e.g, "st" in VOL, 1_st equals 1_m^3) and perhaps EDIT to rename an item (e.g., kW to KW). If you rename in this way with EDIT, e.g., "€" into "EUR", you must also change the global name '€' into 'EUR' (best with the filer in case it is hidden). A user-defined unit name in a unit menu must coincide with its global name.

4. We want to add another UDir named InfU (Informatic Units), for instance. Simply press AddUD and write InfU (as a string) in the Edit line as shown by the next screen-shot. Adding a new Informatics Udir A closing string delimiter is not important. Then press OK (or ENTER, to avoid typing "F" if you forgot to turn off the ALPHA in time). That appends InfU to the unit dirs, first without any unit. These may be defined with AddU as follows: 1_bit = 1_$, 1_byte = 8_bit, 1_Kbyte = 1024_byte, etc. You should not jump over the Define-field for Kbyte after the byte-unit has been created, otherwise the HP49 would think 1_Kbyte equals 1000 bytes! The above definition of 1_bit is not quite voluntary. 1_$ is a dimensionless unit, hence so is 1_bit. But the user is free to define 1_bit differently. A possible definition would be to define 1_bit by a tiny lenght unit corresponding to the packing of information in a compact disk, say. Others may prefer to choose the still more tiny lenght corresponding to the information packing in a DNS sequence. Converting money or informatic units is independent on their dimension. Here an application of the InfU units. Unitman 4.2004 has 1669 bytes. How many Kilobytes are this? Launch InfU, put 1669 the stack and press byte which results in 1669_byte. Now press LS Kbytes and voilá, 1.629...Kbyte appears. This rounds to 1.6 Kbyte, not to 1.7 Kbyte as one might think at the first glance.

5. Some people may want to have the UDir MONEY at the first place. No problem. Simply press roUDs (reorganize UDirs). The special stack of all UDir namesThis creates a special stack with the names of all current UDirs. Now you may reorder with ROLL and ROLLD as in Example 3. Just move the curcor to "LENG" (which probably is in Level 17) and press ROLLD 4, and you're done. You may also remove a UDir with backspace, e.g. RAD, if you never deal with radiation. Only renaming is a bit more involvedly. Let's consider an example. A German may want to rename the UDir TIME into ZEIT. We press the EDIT option (while still beeing in the roUDs-environement) with the cursor on "TIME". That edits the string "TIME". Now we add the new name ZEIT as shown in the left-hand screen-shot.Renaming TIME into ZEIT It is important here to have the old name and the new name in just one string, but on different lines, with no blanks before or after the names. Leave the editor with ENTER and return to the special stack environement. Then simply ENTER and TIME has indeed been renamed into ZEIT. Also an English speaking user may try the example without risking anything. Just rename ZEIT back to TIME. Clearly, renaming a UDir could be done in an extra browser but that wouldn't  pay. With roUDs, reordering the unit categories and renaming or purging some of them can be done in just one step.

6. Most Europeans measure fuel consumption of their cars in litres pro 100 km. In the UK it is measured in mi/galUK, the distance (in miles) one comes along with 1_galUK. How to convert these inconvertible units? Simply create a UDir CAR, say. The unit "1 litre pro 100 km" is the same as 1_cl/km. Press AddU and put {"cl/km" "km/l" "mi/gaUK"} into the UDirName field. No definition of these units is necessary since they are all known to the operating system. Thus, nothing is written in HOME. Under CAR appears now the menu  

     cl/km           km/l      mi/galUK                                        UNITS    
km/l is a very nice fuel consumption unit, perhaps the best one. It just tells us how many km we come along with one litre fuel. It directly convertible to mi/galUK. For example, 12_km/l converts to 33.9_mi/galUK. To get this, just press leftshift mi/galŮK on 12_km/l on the stack. That's all. Converting to the traditional unit, press 1/x on one the result which tells us that this means 8.3_cl/km.

7.  Assume that both, $ and € are in MONEY and the € exchange rate need updating. No problem with the new command EditU. The EditU screen in MONEYPress this command which sets the UDir menu, drive to MONEY and open its menu.While EditU is still running and displaying "EditU", simply press on €. This creates an edit line as shown in the screen-shot. You may safely change 1.07_$ to 1.17_$, say. Pressing ENTER overwrites the unitname '€' with the new exchange rate. Not only it's numerical value but also the definition of the editited unit may be changed  The EditU environment can only be left with CANCEL or ENTER, with the latter only from the command line. Besides these two keys, NXT for paging, and menu keys all other keys will beep.

Important: Editing a unit by directly pressing the unit key works only in the EditU environment, and only for a user-made unit whose name is found on the path. There is no need to edit the hard coded built-in units. Outside EditU a unit key operates as described in Remark 1. EditU may also be used to redefine the $. Press EditU and navigate to MONEY. When pressing $, the empty string is blinking. If you don't want a change, leave with CANCEL. Otherwise print a suitable unit in front of the cursor, e.g., 1_s. Then all money units will become time units and conversely, true to the phrase Time is Money.  

Remark 1. User-defined units added with AddU operate in the same manner as builtin units. A unit key acts in RPN mode as follows - for details see Chapter 10 of the HP48 (!) manual. It is not explained in the 49 or 49+ documents.
NS: Appends (multiplies) the unit to the Level 1 object. E.g., $ from MONEY applied to 100 yields 100_$.
LS:
Converts. E.g., LS € in MONEY as defined above applied to 100_$ in the stack yields 93.45..._€.
RS: Divides. RS $ applied to 100_Hz yields 100. RS s "converts" 100 into 100_1/s (= 100_Hz).

Remark 2. While a dialog-box is active one may quietly leaf through the unit menus to see what they contain or to get string fragments of units. Be careful in chosing a unit-name. For instance, the unitname PS (PetaSiemens) cannot be redefined although it was never in use. Unit names starting with an operation sign or the empty string may cause serious problems when using them as explained in Remark 1. You should create a HOME backup before making serious changes in the UNIT system. Note also that a unit name 'e' for an electron's charge may cause problems since e (Euler's number) is a constant on.the HP49.

Remark 3. You may remove all units you're not pleased with, e.g. miUS^2 or galUK. The operating system still remembers them. One should not hesitate to purge any unwanted unit or even whole directories. These aren't lost. If you want temporarily the builtin units, simply leave the USR mode. UNITS customization is active in USR mode only. Units can be used even context-sensitive, i.e., dependent on the current directory. E.g., in a directory USA you may have another definition of a gallon than in the directory UK.

Remark 4. If you lost the assignment on the UNITS key (e.g. by pressing DelUK and deleting the assignment from the stack) and no HOME backup is available, you are not completely lost. MONEY reappears at the first run of any command. But clearly, you have to recreate your self-made unit directories. Now, the definitions of  its entries should still be in HOME. In this case it suffices to feed the UnitName field in AddU with a single list of the lost unit name strings. Since these are still known to your system, no redefinition is needed.   

Remark 5. The assignment on the rightshift UNITS key 84.3 may become very large. But can be compressed to about 1 KB with BZ. Recall the assignment with S?UA from OT49, compress it with OT49's BZ-toggler ~ (high compression rate). Then press BZCE from the menu which converts the assignment into a self-evaluating code object  Assign it to 84.3. Clearly, this should be done after a UNITS customization has become sufficiently stable. Be aware that each change in the UNITS structure reassigns key 84.3 uncompressed. Unitman is supported by the library UTOOL.


Wolfgang Rautenberg

Credits. Thanks to Heiko Arnemann and Otto Praxl for help in creating this html-document, and for hints and beta-testing in ROM 19-6.