XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Unitman XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX A comfortable unit manager for the HP48G[X] Integrates and removes units in the builtin UNITS menu system Permits renaming builtin Unit Dirs and adding new ones --------------------------------------------------------------------- NEW IN VERSION 7.2001 AddU accepts also a list of defined units. Proposed by Peter Karp. NEW IN VERSION 6.2001 Allows reorganizing the units in a UDir (Unit Directory), i.e. changing their order, purging unneeded ones and renaming in one step. Similarly, the whole UNITS menu can be reorganized, e.g, MONEY can be put at the first place, say. The lib number has changed to 360 since the former number 785 is overcrowded. Hence purge first any assignment at the UNITS key! Then add former units from HOME into suitable UDirs. They need not be redefined. Text below rewritten. ---------------------------------------------------------------------- Unitman is a one-page library whose first four commands will be explained in examples. Thanks to its powerful machinery, each user-defined unit can appear in a builtin UDir and is treated like a builtin unit. The menu can completely be reorganized by the command roUM and the order of units in it can be changed ad libitum. Some superflue units may be removed or perhaps renamed. Similarly, the whole UDir system can be reorganized with roUDs. The default UNITS menu is expanded by a UDir for converting currencies by the command ExpU or any other command. New UDirs may be added ad libitum. Most important is that the famous 3-fold functionality of unit keys works for user-units as well. A nice extra- service: The command menu of Unitman is invoked with rightshift-hold UNITS. Simply hold down the shift while pressing UNITS and you'll see the Unitman- commands. These will permanently be needed in the following examples. --------------------------------------------------------------------- 1. Let's first define the currency EUR in the new MONEY directory added to the builtin UNITS menu after pressing AddU. MONEY contains only the (US)$ after a first run of AddU. The dialog box of AddU should be filled in in accordance with the present example as follows: XXXXXXXXXX Add a Unit XXXXXXXXXX UnitDir MONEY UnitName "EUR" Define .85_$ Here the UDir MONEY was scrolled in with the CHOOSE option of the dialog menu. It may also be scrolled in by pressing alpha M. The UnitName must be entered as a string because it may be a not legal global name (like '$/yr' = Dollars per year). Define has to be answered in our example since the 48 does not know "EUR" as a unit name. Entries under Define must be units having always a real before the "_". Pressing OK, EUR appears in MONEY. Any sum of Dollars can now easily be converted into EUR and conversely (e.g. press $ on 10 on the stack, and then leftshift EUR which yields the value in EUR). $ and EUR do now also appear as names in HOME - provided the present example was executed in HOME. You may hide these small files lateron. Clearly, European currencies with a fixed exchange rate are best be defined in terms of EUR. 2. Next, we want the important unit ms (millisecond) to appear in TIME. For doing this the already filled in dialog box should look as follows: XXXXXXXXXX Add a Unit XXXXXXXXXX UnitDir TIME UnitName "ms" Define (can be skipped, need not be filled in!) The Define-option may safely be skipped because the system knows the prefix m and the unit s and hence ms, although a unit name ms did not show up in the builtin TIME menu. But with Unitman, it will. Generally, units which derive 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 appearing in the original menus. With AddU, we can force them to do so! They need not be defined and nothing is written in HOME in such a case. One may also add a list of strings of unitnames not needing a definition. For instance, the list { "ms" "ns" } (milliseconds and nanoseconds). 3. The order of the present TIME menu is somewhat unpleasant. Better an extra page for Frequency units like Hz, MHz etc. roUM reorganizes the entire menu of a UDir. Scroll in the UDir TIME and ENTER or press OK. Then the program's run will be suspended with a special stack which looks in our example as follows: 7: yr 6: d 5: h This is an exact copy of the present 4: min TIME menu with "ms" already added. 3: s Quotes are here omitted. 2: Hz 1: ms Drive into the stack with UpArrow, 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. Hence, after finishing the present example you may add, e.g., the unit rpm (revolutions/minute) to the Frequency page; this unit is known to the HP48 although it didn't occur in the menus! Leave the stack as usual, press CONT in the menu and your TIME menu has nicely changed. Being in the stack, use ROLL and ROLLD to reorder, the DEL-key to remove a unit, and the VIEW option to rename it (e.g., kW to KW which means the same). One may toggle the special stack and its list form with menu option ->{}->. It does not matter whether you press CONT with a list of units made from the stack or not. The list must contain only nonempty strings. If a mistake is made, abort with CANCL. Otherwise the whole menu must be reproduced. Besides CONT in the menu, also the CONT key continues the suspended state. All other keys work in this state as usual. But be careful as they may spoil the special stack. 4. We want to add another UDir, called InfU (Informatic Units), say. Simply press AddUD, write the name InfU (as a string) into the black field and press OK. That appends InfU to the UNITS but its menu is presently empty. Inf-units have in sequence to be defined with AddU. E.g., as follows: 1_bit = 1_$ (the price of a bit at the beginning of the computer area), 1_byte = 8_bit, 1_Kbyte = 1024_byte, etc. Note that if the last definition is jumped over, the HP49 will tacidly assume 1_Kbyte equals 1000 bytes! Similarly with Mbyte etc. 5. Some people may want to have the UDir MONEY at the first place. No problem. Simply press roUDs (reorganize UDirs). This creates a stack with all current UDirs. These may be reordered with ROLL and ROLLD as in Example 3, or perhaps removed. In our example just press ROLLD on LEN, thats it. Only renaming is a bit more involved. Let's consider an example. Assume a German wants to rename the UDir TIME into ZEIT. Press VIEW in the "TIME"- line which edits the "TIME" string. Append to it the new name ZEIT as follows: "TIME ZEIT" It is important 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. Now leave the stack and press CONT, and you'll see the UDir ZEIT. Also a user from US may try this example without any risk. Just re-rename ZEIT back to TIME. ---------------------------------------------------------------------- You may purge all units you're not pleased with, e.g, miUS^2. The operating system still remembers them. One should not hesitate to remove any unwanted unit or UDir. They are not lost. If you want to see the builtin units, simply press Reset. This returns temporarily to the builtins. A complete elimination of a customized UNITS system is possible only by purging the assignment on the UNITS-key 84.3 which was created by some Unitman commands. As stated above, user-defined units operate in the same way as builtin units. A unit key acts as follows - for details see Chapter 10 of the HP48 manual: Nonshift: Appends (or multiplies) the unit to the object in Level 1. E.g., if 10 is on the stack then the $-key in MONEY yields 10_$. Leftshift: Converts. E.g., if EUR appears in MONEY (see above) then pressing leftshift EUR applied to 10_$ in the stack yields 11.49..._EUR. Rightshift: Divides. Rightshift $ applied to 100_Hz leaves 100 in the stack. Rightshift s "converts" 100 from the stack into 100_1/s = 100_Hz. --------------------------------------------------------------------- REMARK 1. While a dialog-box is active one may quietly page through the unit menus, e.g., to get entries like miUS^2 into the black field. Return to the dialog menu by pressing 0 and ON, for instance. Be careful in chosing unit- names. E.g., the 48 reads a unit-name PS as 1_PegaSiemens=10^15_S. Although this unit was never in use, the name PS is blocked and cannot be redefined to denote any other unit (PS denotes in Germany also a horse-power unit). REMARK 2. The assignment on the rightshift UNITS key has at most a few hundred bytes even if many user-units are added. The assignment of the 49-unitman has several kilobytes because UNITS looks slightly different on this calculator. ----------------------------------------------------------------------------- Wolfgang Rautenberg raut@math.fu-berlin.de www.math.fu-berlin.de/usr/raut