CAD CAM EDM DRO - Yahoo Group Archive

Conversion for Linux/Unix

Posted by Bill Vance
on 2002-06-21 12:16:09 UTC
Hi Gang;

Sorry about spacing it off, but A while back I mentioned posting a conversion
util to the list that could be used as an example in how to create something
that could do CNC calculations on the fly. Basically it's just another, "pipe
it through special".

"Conv", takes two parameters; A conversion function name, and a decimal number
value. Then, through the piping mechanism, it calls up it's function list,
passes the named conversion function the numeric value, and prints out, (or
passes along), the answer. The names of the functions follow the word,
"define", in the ConvFunc file, and are abreviations.

"Bc", is the Calculater Language used to accomplish this, and for you Hewlett
Packard/Forth fans, there's even a Reverse Polish Notation version. The two
files needed for the example follow between the, "****************", lines.
Note: I typed the equations in from a commercial give away sheet, and not being
familiar with all the measurement units, I must admit that there may be more
accurate equations for said conversions.

Bill

PS: There's several versions of bc out there, and if you have dificulties
making yours work with this, I have the latest, greatest, Copylefted virgin.



******************************************
The Conv file, (program).
******************************************

#!bash
# bc unit conversion util
# ( ConvFunc contains the actual conversion functions )
# On the last line, I could have just put, 'echo "$1 ($2)"', but this way it's
# much clearer as to what's going on.


FuncNam="$1"
NumVal="$2"

echo "$FuncNam ($NumVal)" | bc -q ConvFunc

*********************************************



*********************************************
The ConvFunc file, (function data).
*********************************************

# Unit conversion function definitions

# Centimeters to inches

define c2i (cent) {
scale = 4
return (cent * .3937)
}

# inches to centimeters

define i2c (inch) {
scale = 4
return (inch / .3937)
}

# feet to inches

define f2i (feet) {
scale = 4
return (feet * 12.0000)
}

# inches to feet

define i2f (inch) {
scale = 4
return (inch / 12.0000)
}

# inches to yards

define i2y (inch) {
scale = 4
return (inch / 36.0000)
}

# yards to inches

define y2i (yard) {
scale = 4
return (yard * 36.0000)
}

# inches to microns

define i2mic (inch) {
scale = 4
return (inch * 25.4000)
}

# microns to inches

define mic2i (micron) {
scale = 4
return (micron / 25.4000)
}

# inches to millimeters

define i2mm (inch) {
scale = 5
return (inch / .03937)
}

# millimeters to inches

define mm2i (millimeter) {
scale = 5
return (millimeter * .03937)
}

# kilometers to miles

define k2m (kilometer) {
scale = 4
return (kilometer * .621)
}

# miles to kilometers

define m2k (mile) {
scale = 4
return (mile * 1.609)
}

# meters to feet

define m2f (meter) {
scale = 4
return (meter * 3.281)
}

# feet to meters

define f2m (feet) {
scale = 4
return (feet / 3.281)
}

# meters to inches

define m2i (meter) {
scale = 4
return (meter * 39.37)
}

# inches to meters

define i2m (inch) {
scale = 4
return (inch / 39.37)
}

# meters to yards

define m2y (meter) {
scale = 4
return (meter * 1.093)
}

# yards to meters

define y2m (yard) {
scale = 4
return (yard * .9144)
}

# microns to mils

define mic2mil (micron) {
scale = 5
return (micron * .03937)
}

# mils to microns

define mil2mic (mil) {
scale = 5
return (mil / .03937)
}

# mils to millimeters

define m2mm (mil) {
scale = 4
return (mil * .0254)
}

# millimeters to mils

define mm2m (millimeter) {
scale = 4
return (millimeter / .0254)
}

**************************************

--
----------------------------------------------------------------------------
RKBA! ***** Blessings On Thee, Oh Israel! ***** 4-19!
----------------+----------+--------------------------+---------------------
An _EFFECTIVE_ | Insured | All matter is vibration. | Let he who hath no
weapon in every | by COLT; | -- Max Plank | weapon sell his
hand = Freedom | DIAL | In the beginning was the | garment and buy a
on every side! | 1911-A1. | word. -- The Bible | sword.--Jesus Christ
----------------+----------+--------------------------+---------------------

Constitutional Government is dead, LONG LIVE THE CONSTITUTION!!!!!

----------------------------------------------------------------------------

Discussion Thread

Bill Vance 2002-06-21 12:16:09 UTC Conversion for Linux/Unix