From comp.sys.handhelds Thu Jan 31 11:07:42 1991
Path: mentor.cc.purdue.edu!purdue!news.cs.indiana.edu!know!zaphod.mps.ohio-state.edu!julius.cs.uiuc.edu!psuvax1!rutgers!njin!princeton!phoenix.Princeton.EDU
From: woodhams@phoenix.Princeton.EDU (Michael Woodhams)
Newsgroups: comp.sys.handhelds
Subject: HP48SX: conversion to cgs units program.
Message-ID: <5810@idunno.Princeton.EDU>
Date: 30 Jan 91 18:48:07 GMT
Sender: news@idunno.Princeton.EDU
Organization: Princeton University Observatory
Lines: 52

For some strange, dark reason, astrophysicists normally work in cgs
units rather than S.I. like the rest of the universe. Although I am
fighting this when I can, there are times when one has to express
results in cgs units. (SI = simple and intuitive. cgs = confuses
graduate students.) Therefore I have written the following little
program to act like the built in function "UBASE" except it reduces
units to cm instead of m, and g instead of kg. The following is
hand-entered, but I hope the format will be directly loadable by those
with cables to computers.

\<<
 IF DUP TYPE 13 \/= THEN	@ if top of stack is not a unit object
  KILL				@ quit program
 END
 UBASE				@ convert top of stack to SI
 DUP \->STR			@ make copy of SI unit object as a string
 DUP SIZE			@ find size of this string
 \-> ustr len			@ store string and length in local variables
  \<<
   ustr "m" POS			@ find position of "m" in string
   IF DUP 0 \/= THEN		@ if it is found, then
    \-> pos			@ store position of "m" in pos
     \<<
      ustr 1 pos 1 - SUB	@ extract all of string before "m"
      "c" +			@ concatanate "c"
      ustr pos len SUB +	@ concatanate all of string from "m" on
				@ (changes first "m" found into "cm")
      'ustr' STO		@ store back in string
     \>>
   ELSE				@ else ("m" not found)
    DROP			@ drop 0
   END
   ustr "k" POS			@ find position of "k" in string
   IF DUP 0 \/= THEN		@ if "k" found
    \-> pos			@ store position of "k" in pos
     \<<
      ustr 1 pos 1 - SUB	@ extract all of string before "k"
      ustr pos 1 + len SUB +	@ concatanate all of string after "k"
				@ (removes the first "k" from string,
				@ to change kg into g.)
      'ustr' STO		@ store back in string
     \>>
   ELSE				@ else ("k" not found)
    DROP			@ drop 0
   END
   ustr OBJ\->			@ turn string back into a unit object
				@ (this has correct units but not correct
				@ value for cgs version of original object)
   UFACT			@ convert original to new units.
 \>>
\>>
checksum #4718d, bytes 337.    

