home *** CD-ROM | disk | FTP | other *** search
- From decwrl!sun-barr!cs.utexas.edu!uunet!allbery Sun Jun 4 14:44:05 PDT 1989
- Article 895 of comp.sources.misc:
- Path: decwrl!sun-barr!cs.utexas.edu!uunet!allbery
- From: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
- Newsgroups: comp.sources.misc
- Subject: v07i006: Units conversion program (better than Unix "units")
- Message-ID: <56707@uunet.UU.NET>
- Date: 4 Jun 89 01:31:30 GMT
- Sender: allbery@uunet.UU.NET
- Reply-To: simpsong@NCoast.ORG (Gregory R. Simpson)
- Organization: International Society of Lamp Gam'ers.
- Lines: 1171
- Approved: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
-
- Posting-number: Volume 7, Issue 6
- Submitted-by: simpsong@NCoast.ORG (Gregory R. Simpson)
- Archive-name: un
-
- Here's a submission for comp.sources.misc. It should compile
- on almost any machine, unix, turboc, vms... It's a units
- conversion program. It was first posted in April 1987... It's
- expanded and improved... Comments welcome,
-
- Greg
-
- Gregory R. Simpson
- simpsong%ltd2.decnet@crd.ge.com
-
-
- # This is a shell archive. Save this into a file, edit it
- # and delete all lines above this comment. Then give this
- # file to sh by executing the command "sh file". The files
- # will be extracted into the current directory owned by
- # you with default permissions.
- #
- # The files contained herein are:
- # read.me manifest un.n makefile
- # un.h unit_table.h cons.c control.c
- # getit.c temp.c u.c
- #
- echo 'x - read.me'
- sed 's/^X//' <<'________This_Is_The_END________' >>read.me
- XUn is a units conversion program. It converts a unit from one particular
- Xunit group to all the other units in that group. It also has a chart option.
- XThe best explaination is an example session, both the standard conversion
- Xmode and the chart mode are demonstrated below... a manual page is included.
- XUn was originally released in April 1987 as "u"... it is easily
- Xexpandable... Since the '87 version, I've added more british units, made
- Xthe program easy to quit, and broken the code into modules. My thanks to
- XTodd Ogasawara, U. of Hawaii Computing Center for writing a manual page.
- XIt currently has a total of 196 different unit conversions in 21 catagories.
- X(and a prefix and constant section).
- X
- XEnjoy,
- X
- XGreg
- X
- XGregory R. Simpson
- X
- XPlease send any comments/suggestions/new unit types to:
- X
- XInternet: simpsong%ltd2.decnet@crd.ge.com
- XUUCP: uunet!steinmetz!ltd2.decnet!simpsong
- XVOICE: (216)-381-6789
- X
- X----------------------- Example Session ---------------------
- X
- X Unit Group Selection
- X-------------------------------------------------------------
- X 1. Length 2. Mass
- X 3. Speed 4. Volume
- X 5. Area 6. Density
- X 7. Time 8. Force
- X 9. Energy/Heat/Work 10. Pressure
- X11. Angle 12. Power
- X13. Electric Charge 14. Magnetic Induction
- X15. Light 16. Thermal Conductivity
- X17. Coeff of Heat Transfer 18. Heat Flux
- X19. Viscosity 20. Cooking Volumes
- X21. Temperature 22. Prefix List
- X23. Constants 24.
- X Enter 'q' at anytime to (Q)uit
- X---------------------------------------------------(C)grs----
- XWhich Type of Unit? 1
- X
- X Unit Selection
- X-------------------------------------------------------------
- X 1. feet 2. inches
- X 3. yards 4. centimeters
- X 5. meters 6. kilometers
- X 7. statute miles 8. nautical miles
- X 9. par-secs 10. light-years
- X11. mils 12. microns
- X13. millimicrons 14. angstroms
- X15. x-units 16. rods
- X17. fathoms 18. chains
- X19. ropes (Brit.) 20. furlongs
- X Enter 'q' at anytime to (Q)uit
- X-------------------------------------------------------------
- XYour Unit? 1
- X
- XHow many feet ? 2
- X
- X ============================================================
- X 2 feet is equivalent to:
- X ------------------------------------------------------------
- X
- X 0.0030303 furlongs
- X 0.1 ropes (Brit.)
- X 0.0030303 chains
- X 0.33333334 fathoms
- X 0.121212 rods
- X 6.096e+012 x-units
- X 6.096e+009 angstroms
- X 609600000 millimicrons
- X 609600 microns
- X 24000 mils
- X 6.4436602e-017 light-years
- X 1.9765572e-017 par-secs
- X 0.0003291585 nautical miles
- X 0.0003788 statute miles
- X 0.0006096 kilometers
- X 0.6096 meters
- X 60.96 centimeters
- X 0.66666666 yards
- X 24 inches
- X ============================================================
- X
- X (R)erun Unit type, (N)ew Unit type, (Q)uit, or (C)hart: c
- X
- X Unit Group Selection
- X-------------------------------------------------------------
- X 1. Length 2. Mass
- X 3. Speed 4. Volume
- X 5. Area 6. Density
- X 7. Time 8. Force
- X 9. Energy/Heat/Work 10. Pressure
- X11. Angle 12. Power
- X13. Electric Charge 14. Magnetic Induction
- X15. Light 16. Thermal Conductivity
- X17. Coeff of Heat Transfer 18. Heat Flux
- X19. Viscosity 20. Cooking Volumes
- X21. Temperature 22. Prefix List
- X23. Constants 24.
- X Enter 'q' at anytime to (Q)uit
- X---------------------------------------------------(C)grs----
- XWhich Type of Unit? 2
- X Unit Selection
- X-------------------------------------------------------------
- X 1. pounds 2. grams
- X 3. kilograms 4. tons
- X 5. amus 6. ounces
- X 7. stones 8.
- X Enter 'q' at anytime to (Q)uit
- X-------------------------------------------------------------
- X
- XYour Reference Unit? 1
- XYour Comparison Unit? 2
- X
- XFrom How Many pounds? 1
- XTo How Many pounds? 10
- XBy what increment? 1
- X
- XFilename for chart? (<CR> for screen):
- X------------------------------------------------------------------------------
- X| 1 pounds | 453.6 grams |
- X------------------------------------------------------------------------------
- X| 2 pounds | 907.2 grams |
- X------------------------------------------------------------------------------
- X| 3 pounds | 1360.8 grams |
- X------------------------------------------------------------------------------
- X| 4 pounds | 1814.4 grams |
- X------------------------------------------------------------------------------
- X| 5 pounds | 2268 grams |
- X------------------------------------------------------------------------------
- X| 6 pounds | 2721.6 grams |
- X------------------------------------------------------------------------------
- X| 7 pounds | 3175.2 grams |
- X------------------------------------------------------------------------------
- X| 8 pounds | 3628.8 grams |
- X------------------------------------------------------------------------------
- X| 9 pounds | 4082.4 grams |
- X------------------------------------------------------------------------------
- X| 10 pounds | 4536 grams |
- X------------------------------------------------------------------------------
- X
- X (R)erun Unit type, (N)ew Unit type, (Q)uit, or (S)tandard Conversions: q
- X
- X U... Unit Conversion, by Gregory R. Simpson - Copyright 1988
- X
- X
- ________This_Is_The_END________
- echo 'x - manifest'
- sed 's/^X//' <<'________This_Is_The_END________' >>manifest
- Xmanifest - this file
- Xu.c - Main Program
- Xcons.c - Constants
- Xgetit.c - Input routines
- Xcontrol.c - Control funtions
- Xtemp.c - Temperature Conversion
- Xun.h - General Include File
- Xunit_table.h - Unit Conversion Factor include file
- Xmakefile - Makefile
- Xun.n - Manual Page
- Xread.me - A read.me file
- ________This_Is_The_END________
- echo 'x - un.n'
- sed 's/^X//' <<'________This_Is_The_END________' >>un.n
- X.tr ~ \
- X.TH un l LOCAL
- X.SH NAME
- X\fIun\fR \- convert from one unit of measurement to another
- X.SH SYNOPSIS
- X.BR "\fIun\fR
- Xis a menu driven program that lets you convert values
- Xfrom one unit of measurement to another unit of measurement.
- XA simple example is using \fIun\fR to find that 1 inch is
- Xequivalent to 2.54 centimeters.
- X
- X.PP
- X.SH DESCRIPTION
- X.I un
- Xfirst asks you for the group of measurement units you want to use.
- XThe table below lists the measurement groups available.
- X.sp
- X.nf
- X Unit Group Selection
- X-------------------------------------------------------------
- X 1. Length 2. Mass
- X 3. Speed 4. Volume
- X 5. Area 6. Density
- X 7. Time 8. Force
- X 9. Energy/Heat/Work 10. Pressure
- X11. Angle 12. Power
- X13. Electric Charge 14. Magnetic Induction
- X15. Light 16. Thermal Conductivity
- X17. Coeff of Heat Transfer 18. Heat Flux
- X19. Viscosity 20. Cooking Volumes
- X21. Temperature 22. Prefix List
- X23. Constants 24.
- X Enter 'q' at anytime to (Q)uit
- X---------------------------------------------------(C)grs----
- X.fi
- X.sp
- XIt then asks you for the specific unit you are interested in; "inches"
- Xfor example.
- X\fIun\fR then displays the converted value for each of the related
- Xunits of measurement.
- XOne of the menu options that follows the conversion of one unit to
- Xanother allows you to produce a text chart that shows you value
- Xconversions in some specified increment.
- XFor example, you can ask \fIun\fR to show you the converted
- Xcentimeter value of 1 inch to 12 inches in 1 inch increments.
- X
- X.SH AUTHOR
- X.nf
- X\fIun\fR was written by:
- XGregory R. Simpson
- XUUCP: uunet!steinmetz!ltd2.decnet!simpsong
- XARPA: simpsong%ltd2.decnet@crd.ge.com
- XAT&T: (216)-381-6789
- X.fi
- X.PP
- X.SH BUGS AND CAVEATS
- X(1) The values produced are subject to rounding error. For example,
- X61 seconds is converted to 1 minutes and 1.66 seconds.
- X.SH SEE ALSO
- Xunits(1)
- ________This_Is_The_END________
- echo 'x - makefile'
- sed 's/^X//' <<'________This_Is_The_END________' >>makefile
- X# UN.C
- X# Unit conversion program
- X
- XBIN = /usr/local
- XCC = cc -O
- XMAN = /usr/man/manl
- XPROG = un
- XOBJ = u.o cons.o control.o getit.o temp.o
- XINC = un.h unit_table.h
- X
- X$(PROG): $(OBJ) $(INC)
- X $(CC) -o $(PROG) $(OBJ)
- X
- Xu.o: u.c
- X $(CC) -c u.c
- X
- Xcons.o: cons.c
- X $(CC) -c cons.c
- X
- Xcontrol.o: control.c
- X $(CC) -c control.c
- X
- Xgetit.o: getit.c
- X $(CC) -c getit.c
- X
- Xtemp.o: temp.c
- X $(CC) -c temp.c
- X
- Xinstall:
- X cp $(PROG) $(BIN)
- X chmod a+rx $(BIN)/$(PROG)
- X strip $(BIN)/$(PROG)
- X cp $(PROG).n $(MAN)/$(PROG).l
- X chmod a+r $(MAN)/$(PROG).l
- ________This_Is_The_END________
- echo 'x - un.h'
- sed 's/^X//' <<'________This_Is_The_END________' >>un.h
- X/* un.h - 1/17/87 */
- X
- X#include <stdio.h>
- X
- X#define ESC '\033'
- X#define True 1
- X
- X/* Definition for clearing Screen */
- X
- X#ifdef MSDOS
- X#define Clear printf("%c[2J%c[1;1f",ESC,ESC)
- X#else
- X#define Clear printf("\n\n");
- X#endif
- ________This_Is_The_END________
- echo 'x - unit_table.h'
- sed 's/^X//' <<'________This_Is_The_END________' >>unit_table.h
- X/* unit_table.h - Copyright 1987 - Gregory R. Simpson */
- X/* subject to the same conditions outlined in u.c's copyright */
- X
- X/* ************ a table of the form: **************
- X
- X struct of_units {
- X char *name; Name of Unit
- X float value; Value - Initially set to 0
- X float conversion; Conversion factor to Primary Unit
- X int counter; Number of units in this group
- X }
- X
- XThe primary unit is the first unit listed in the unit group.
- XAlways include an even number of entries in the group even
- Xif this means that the last entry is blank. Then, set the
- Xnumber of entries to the correct odd number...this is to
- Xhandle displays correctly... For example, see the mass
- Xentry below.
- X
- XThere are currently: 196 unit conversion in 21 catagories.
- X
- X20 Length, 15 Mass, 6 Speed, 18 Volume, 14 Area, 5 Density, 12 Time,
- X5 Force, 20 Energy, 12 Pressure, 6 Plane Angles, 10 Power, 6 Electric Charge
- X6 Magnetic Induction, 12 Light, 4 Thermal Conductivity, 4 Coeff. of Heat
- XTransfer, 6 Viscosity, 8 Cooking volumes, 8 Computer Media.
- X
- X************************************************** */
- X
- X#define MAXGROUP 23 /* Maximum Number of Unit Groups - 1 */
- X
- Xstatic char *unitype[MAXGROUP+2] = {
- X "Length" , "Mass"
- X , "Speed" , "Volume"
- X , "Area" , "Density"
- X , "Time" , "Force"
- X , "Energy/Heat/Work" , "Pressure"
- X , "Angle" , "Power"
- X , "Electric Charge" , "Magnetic Induction"
- X , "Light" , "Thermal Conductivity"
- X , "Coeff of Heat Transfer" , "Heat Flux"
- X , "Viscosity" , "Cooking Volumes"
- X , "Computer Media"
- X
- X/* Temperature, Prefix, and Constants are always the last 3
- X Add New Unit Types above this point. */
- X
- X , "Temperature" , "Prefix List"
- X , "Constants" , " "
- X };
- X
- Xstruct of_units {
- X char *name; /* Name of Unit */
- X double value; /* Value - Initially set to 0 */
- X double conversion; /* Conversion factor to Primary Unit */
- X int counter; /* Number of units in this group */
- X}
- Xunit[30][20] = {
- X {
- X {"feet",0,1,20}, /* length */
- X {"inches",0,12,20},
- X {"yards",0,.33333333,20},
- X {"centimeters",0,30.48,20},
- X {"meters",0,.3048,20},
- X {"kilometers",0,3.048e-04,20},
- X {"statute miles",0,1.894e-04,20},
- X {"nautical miles",0,1.6457925e-04,20},
- X {"par-secs",0,9.8827862e-18,20},
- X {"light-years",0,3.2218301e-17,20},
- X {"mils",0,12000.,20},
- X {"microns",0,304800.,20},
- X {"millimicrons",0,3.048e08,20},
- X {"angstroms",0,3.048e09,20},
- X {"x-units",0,3.048e12,20},
- X {"rods",0,.060606,20},
- X {"fathoms",0,.16666667,20},
- X {"chains",0,.00151515,20},
- X {"ropes (Brit.)",0,.05,20},
- X {"furlongs",0,1.51515e-03,20}
- X },
- X {
- X {"pounds (avdp.)",0,1,15}, /* mass */
- X {"grams",0,453.59237,15},
- X {"kilograms",0,.45359237,15},
- X {"tons (short)",0,5.0e-04,15},
- X {"tons (long)",0,.00044642857,15},
- X {"tons (metric)",0,.00045359237,15},
- X {"pennyweights",0,291.6666,15},
- X {"scruples (apoth)",0,350,15},
- X {"drams (apoth/troy)",0,116.6666,15},
- X {"drams (avdp.)",0,256.0,15},
- X {"amus",0,2.732e26,15},
- X {"ounces (avdp.)",0,16,15},
- X {"stones",0,.0714285,15},
- X {"grains",0,7000.0,15},
- X {"slugs",0,.0310810,15},
- X {"",0,0,15}
- X },
- X {
- X {"m/sec",0,1,6}, /* speed */
- X {"ft/sec",0,3.2808399,6},
- X {"ft/min",0,196.85039,6},
- X {"km/hr",0,3.6,6},
- X {"km/min",0,.06,6},
- X {"cm/sec",0,100,6},
- X {"knots",0,1.944,6},
- X {"miles/hr",0,2.2369363,6}
- X },
- X {
- X {"cubic meters",0,1,18}, /* Volume */
- X {"cubic cms",0,1e06,18},
- X {"liters",0,1000,18},
- X {"gallons (U.S. Liq)",0,264.17205,18},
- X {"gallons (Brit.)",0,219.9694,18},
- X {"quarts (U.S. Liq)",0,1056.6882,18},
- X {"quarts (Brit.)",0,879.87753,18},
- X {"pints (U.S. Liq)",0,2113.3764,18},
- X {"cubic feet",0,35.314667,18},
- X {"cubic inches",0,6.102374e04,18},
- X {"barrels (U.S. liq)",0,8.3864145,18},
- X {"barrels (U.S. dry)",0,8.648490,18},
- X {"barrels (Brit.)",0,6.110261,18},
- X {"hogsheads",0,4.1932072,18},
- X {"boardfeet",0,8786880.,18},
- X {"acre-feet",0,.00081071319,18},
- X {"cords",0,4519.68,18},
- X {"steres",0,1.0,18}
- X },
- X {
- X {"square meters",0,1,14}, /* Area */
- X {"square kilometers",0,1.0e-6,14},
- X {"square cms",0,1e04,14},
- X {"square miles",0,3.8610216e-07,14},
- X {"square feet",0,10.76,14},
- X {"square inches",0,1550,14},
- X {"sq. links (Gunter)",0,24.710538,14},
- X {"sq. links (Ramden)",0,10.763910,14},
- X {"square mm",0,1e06,14},
- X {"square rods",0,.039536861,14},
- X {"sq. perches (Brit)",0,.039536861,14},
- X {"hectares",0,.0001,14},
- X {"circular mills",0,1.974e09,14},
- X {"acres",0,2.4710538e-04,14}
- X },
- X {
- X {"kg/m3",0,1,5}, /* Density */
- X {"slug/ft3",0,1.940e-03,5},
- X {"gm/cm3",0,.001,5},
- X {"lb/ft3",0,6.243e-02,5},
- X {"lb/in3",0,3.613e-05,5},
- X {"",0,0,5}
- X },
- X {
- X {"days",0,1,12}, /* Time */
- X {"years",0,2.738e-03,12},
- X {"month",0,.0328767,12},
- X {"week",0,.1428571,12},
- X {"hours",0,24,12},
- X {"minutes",0,1440,12},
- X {"seconds",0,8.640e04,12},
- X {"decades",0,2.738e-04,12},
- X {"score",0,1.369e-04,12},
- X {"centuries",0,2.738e-05,12},
- X {"millenia",0,2.738e-06,12},
- X {"fortnights",0,.0714285,12}
- X },
- X {
- X {"newtons",0,1,5}, /* Force */
- X {"dynes",0,1e05,5},
- X {"pounds",0,.2248,5},
- X {"gram-force",0,102.0,5},
- X {"kilogram-force",0,.1020,5},
- X {"",0,0,5}
- X },
- X {
- X {"btus",0,1,20}, /* Energy */
- X {"btus (Int.Stm.Tab.)",0,.999346,20},
- X {"btus (mean)",0,.998563,20},
- X {"ergs",0,1.05435e10,20},
- X {"ft-lbs",0,777.649,20},
- X {"hp-hr",0,3.92752e-04,20},
- X {"Joules",0,1054.35,20},
- X {"Joules (int.)",0,1054.18,20},
- X {"Watt-sec",0,1054.35,20},
- X {"Watt-sec (int.)",0,1054.18,20},
- X {"calories",0,251.99576,20},
- X {"calories (I.S.T)",0,251.831,20},
- X {"calories (mean)",0,251.634,20},
- X {"kilowatt-hours",0,2.92875e-04,20},
- X {"kilowatt-hours int",0,2.92827e-04,20},
- X {"electron volts",0,6.585e21,20},
- X {"MeV",0,6.585e15,20},
- X {"liter-atm",0,10.4053,20},
- X {"tons of refrig",0,3.46995e-06,20},
- X {"kg-m",0,107.514,20}
- X },
- X {
- X {"atmospheres",0,1,12}, /* Pressure */
- X {"dynes/cm2",0,1.01325e06,12},
- X {"inches of water",0,406.8,12},
- X {"cms Hg",0,76.,12},
- X {"torr",0,760.,12},
- X {"mms Hg",0,760.,12},
- X {"inches Hg",0,29.92126,12},
- X {"lbs/in2",0,14.6960,12},
- X {"lbs/ft2",0,2116,12},
- X {"newtons/m2",0,1.01325e05,12},
- X {"bars",0,1.01325,12},
- X {"pascals",0,1.01325e05,12}
- X },
- X {
- X {"degrees",0,1,6}, /* Plane Angles */
- X {"minutes",0,60,6},
- X {"seconds",0,3600,6},
- X {"radians",0,1.745e-02,6},
- X {"revolutions",0,2.77777778e-03,6},
- X {"quadrants",0,.0111111,6}
- X },
- X {
- X {"btus/hour",0,1,10}, /* Power */
- X {"ft-lbs/min",0,12.97,10},
- X {"ft-lbs/sec",0,.2161,10},
- X {"horsepower",0,3.929e-04,10},
- X {"kilowatts",0,2.930e-04,10},
- X {"watts",0,.292875,10},
- X {"calories/sec",0,7.000,10},
- X {"ergs/sec",0,2.928751e06,10},
- X {"lb. ice melted/hr",0,.0069714,10},
- X {"tons of refrig.",0,8.32789e-05,10}
- X },
- X {
- X {"coulombs",0,1,6}, /* Electric Charge */
- X {"abcoulombs",0,.1,6},
- X {"amp-hrs",0,2.778e-04,6},
- X {"faradays",0,1.036e-05,6},
- X {"statcoulombs",0,2.998e9,6},
- X {"electron charges",0,6.2414181e18,6}
- X },
- X {
- X {"Gauss",0,1,6}, /* Magnetic Induction */
- X {"kilolines/in2",0,6.452e-03,6},
- X {"Webers/m2",0,1e-04,6},
- X {"Tesla",0,1e-04,6},
- X {"gamma",0,1e05,6},
- X {"Maxwells/sq.cm",0,1,6}
- X },
- X {
- X {"Footlamberts",0,1,12}, /* Light */
- X {"Nit",0,.2919,12},
- X {"Millilamberts",0,.929,12},
- X {"Candelas/in2",0,452,12},
- X {"Candelas/ft2",0,3.142,12},
- X {"Candelas/m2",0,.2919,12},
- X {"Stilb",0,2919,12},
- X {"lumens/ft2",0,1,12},
- X {"foot-candles",0,1,12},
- X {"lux",0,10.763190,12},
- X {"lumens/m2",0,10.763190,12},
- X {"Milliphots",0,1.0763190,12}
- X },
- X {
- X {"Btu/(hr-ft2-F/ft)",0,1,4}, /* thermal conductivity */
- X {"gm-cal/(sec-cm2-C/cm)",0,.004134,4},
- X {"watts/(cm2-C/cm)",0,.01731,4},
- X {"kg-cal/(hr-m2-C/m)",0,1.488,4}
- X },
- X {
- X {"Btu/hr-ft2-F",0,1,4}, /* coeff. of heat trans. */
- X {"gm-cal/sec-cm2-C",0,.0001355,4},
- X {"watts/cm2-C",0,.0005678,4},
- X {"kg-cal/hr-m2-C",0,4.882,4}
- X },
- X {
- X {"Btu/hr-ft2",0,1,4}, /* heat Flux */
- X {"gm-cal/sec-cm2",0,.00007535,4},
- X {"watts/cm2",0,.0003154,4},
- X {"kg-cal/hr-m2",0,2.712,4}
- X },
- X {
- X {"Centipoises",0,1,6}, /* viscosity */
- X {"lb/sec-ft",0,.000672,6},
- X {"lb force-sec/ft2",0,.0000209,6},
- X {"lb/hr-ft",0,2.42,6},
- X {"kg/hr-m",0,3.60,6},
- X {"grams/cm-sec",0,.01,6}
- X },
- X {
- X {"teaspoons",0,1,8}, /* cooking volumes */
- X {"tablespoons",0,.33333333,8},
- X {"cups",0,.0208333,8},
- X {"pints",0,.0104166,8},
- X {"quarts",0,5.2083333e-03,8},
- X {"gallons",0,1.3020833e-03,8},
- X {"fluid ounce",0,.1666666,8},
- X {"jigger",0,.11111111,8}
- X },
- X {
- X {"bytes",0,1,8}, /* computer media */
- X {"kilobytes",0,9.765625e-04,8},
- X {"megabytes",0,9.765625e-07,8},
- X {"blocks",0,1.953125e-03,8},
- X {"360K Floppies",0,2.7126736e-06,8},
- X {"1.2 Meg Floppies",0,8.1380208e-07,8},
- X {"1.44 Meg Floppies",0,6.781684e-07,8},
- X {"20 Meg Hard Disk",0,4.8828125e-08,8}
- X },
- X};
- X
- ________This_Is_The_END________
- echo 'x - cons.c'
- sed 's/^X//' <<'________This_Is_The_END________' >>cons.c
- X
- X/* constants - G.R.Simpson */
- X
- X#include "un.h"
- X
- Xconstants()
- X{
- X char c[10];
- X
- X Clear;
- X printf("\npi = 3.141592653589793238462643\n");
- X printf("e = 2.718281828459045235360287\n");
- X printf("atomic mass unit = 1.66053 e-27 kg, e-24 gm \n");
- X printf("Avogadro's number N = 6.02217 e23 mole^-1 \n");
- X printf("Boltzmann's constant = R/N = 1.3806 e-23 J/K, e-16 erg/K = 8.61708 e-5 eV/K \n");
- X printf("gas constant = 8.3143 J/mole-K = 0.082054 l-atm/mole-K\n");
- X printf("gravitational constant = 6.673 e-11 N-m^2/kg^2, J-m/kg^2, \n");
- X printf("mass of electron = 9.10956 e-31 kg, e-28 gm = 5.48593 e-4 amu \n");
- X printf("mass of proton = 1.67261 e-27 kg, e-24 gm = 1.0072766 amu \n");
- X printf("Planck's constant = h = 6.62620 e-34 J-sec, e-27 erg-sec \n");
- X printf("h bar = h/2*pi = 1.05459 e-34 J-sec, e-27 erg-sec \n");
- X printf("speed of light = 2.997925 e8 m/sec, e10 cm/sec \n");
- X printf("Stefan-Boltzmann constant = 5.670 e-8 W/m^2-K^4 \n");
- X printf("\n <CR> to continue or (Q)uit: ");
- X gets(c);
- X if ( c[0] == 'Q' || c[0] == 'q' ) {
- X quit_it();
- X } else {
- X c[0] = '\0';
- X return;
- X }
- X}
- X
- X
- X/* prefix - G.R.Simpson */
- X
- Xprefix()
- X{
- X char c[10];
- X
- X Clear;
- X printf("tera = 1,000,000,000,000 = 10e12\n");
- X printf("giga = 1,000,000,000 = 10e09\n");
- X printf("mega = 1,000,000 = 10e06\n");
- X printf("kilo = 1,000 = 10e03\n");
- X printf("centi = 0.01 = 10e-02\n");
- X printf("milli = 0.001 = 10e-03\n");
- X printf("micro = 0.000001 = 10e-06\n");
- X printf("nano = 0.000000001 = 10e-09\n");
- X printf("pico = 0.000000000001 = 10e-12\n");
- X printf("\n <CR> to continue or (Q)uit: ");
- X gets(c);
- X if ( c[0] == 'Q' || c[0] == 'q' ) {
- X quit_it();
- X } else {
- X c[0] = '\0';
- X return;
- X }
- X}
- ________This_Is_The_END________
- echo 'x - control.c'
- sed 's/^X//' <<'________This_Is_The_END________' >>control.c
- X
- X/* usage - Print a usage message - G.R.Simpson */
- X
- X#include "un.h"
- X
- Xusage()
- X{
- X printf("\nusage: u [-c] \n");
- X printf("-c : unit chart option \n\n");
- X printf("Un... Unit conversions; Copyright, Gregory R. Simpson 1987,1988,1989\n");
- X exit(0);
- X}
- X
- X/* action - G.R.Simpson */
- X
- Xaction(sameu,charts)
- Xint *sameu, *charts;
- X{
- X char c[10];
- X int tryagain = 1;
- X
- X while (tryagain) {
- X if (*charts != 1) {
- X printf("\n (R)erun Unit type, (N)ew Unit type, (Q)uit, or (C)hart: ");
- X } else {
- X printf("\n (R)erun Unit type, (N)ew Unit type, (Q)uit, or (S)tandard Conversions: ");
- X }
- X scanf("%s",c);
- X if ( c[0] == 'Q' || c[0] == 'q' ) {
- X quit_it();
- X }
- X else if ( c[0] == 'R' || c[0] == 'r' ) {
- X *sameu = 1;
- X tryagain = 0;
- X }
- X else if ( c[0] == 'N' || c[0] == 'n' ) {
- X *sameu = 0;
- X tryagain = 0;
- X }
- X else if ( c[0] == 'C' || c[0] == 'c' ) {
- X *charts = 1;
- X *sameu = 0;
- X tryagain = 0;
- X }
- X else if ( c[0] == 'S' || c[0] == 's' ) {
- X *charts = 0;
- X *sameu = 0;
- X tryagain = 0;
- X }
- X else {
- X printf("\n Invalid Response, please try again: \n");
- X }
- X }
- X return;
- X}
- X
- X/* quit_it - G.R.Simpson */
- X
- Xquit_it()
- X{
- X printf("\n Un... Unit Conversion, by Gregory R. Simpson - Copyright 1987,1988,1989 \n");
- X exit(0);
- X}
- ________This_Is_The_END________
- echo 'x - getit.c'
- sed 's/^X//' <<'________This_Is_The_END________' >>getit.c
- X
- X/* getinteger - Get Positive Integer Routine - G.R.Simpson */
- X
- X#include "un.h"
- X
- Xint getinteger(choice, max)
- X
- Xint *choice;
- Xint max;
- X{
- X char quit[80];
- X char junk[80];
- X int status, c;
- X while(1) {
- X scanf("%s",quit);
- X if ( quit[0] == 'Q' || quit[0] == 'q' ) {
- X quit_it();
- X }
- X status = sscanf(quit, "%d", choice);
- X if (status == 0)
- X {
- X scanf("%*s",junk);
- X printf("Please Use Positive Integers,\n");
- X printf("or 'q' to (Q)uit; try again: ");
- X }
- X else if (status == 1)
- X {
- X while ((c = getchar()) != '\n' && c != EOF)
- X ;
- X if ( c == EOF )
- X {
- X ungetc(c, stdin);
- X }
- X if ( *choice > 0 && *choice <= max+1 )
- X {
- X return status;
- X }
- X printf("Please use a number from 1 to %d : ", max+1);
- X }
- X else /* status is -1 */
- X {
- X printf("End of file encountered... \n");
- X *choice = 1;
- X return status;
- X }
- X}
- X}
- X
- X/* getdouble - Get Double Precision Number - G.R.Simpson */
- X
- Xgetnumber(fchoice)
- X
- Xdouble *fchoice;
- X{
- X char quit[80];
- X char junk[80];
- X int status, c;
- X while(1) {
- X scanf("%s",quit);
- X if ( quit[0] == 'Q' || quit[0] == 'q' ) {
- X quit_it();
- X }
- X status = sscanf(quit, "%lf", fchoice);
- X if (status == 0)
- X {
- X scanf("%*s",junk);
- X printf("Please Use Numeric Input,\n");
- X printf("or 'q' to (Q)uit; try again: ");
- X }
- X else if (status == 1)
- X {
- X while ((c = getchar()) != '\n' && c != EOF)
- X ;
- X if ( c == EOF )
- X ungetc(c, stdin);
- X }
- X else /* status is -1 */
- X printf("End of file encountered... \n");
- X return status;
- X }
- X}
- X
- ________This_Is_The_END________
- echo 'x - temp.c'
- sed 's/^X//' <<'________This_Is_The_END________' >>temp.c
- X
- X/* temperature - G.R.Simpson */
- X
- X#include "un.h"
- X
- Xtemperature()
- X{
- Xstatic char *scale[4] = { "Fahrenheit", "Celsius", "Rankine", "Kelvin" };
- Xdouble fahrenheit, celsius, rankine, kelvin;
- Xdouble temp;
- Xchar c[2];
- Xint choice, tempagain;
- X
- X tempagain = 1;
- X
- X while(tempagain) {
- X Clear;
- X printf(" Unit Selection\n");
- X printf("-------------------------------------------------------------\n");
- X printf("1. Fahrenheit 2. Celsius \n");
- X printf("3. Rankine 4. Kelvin \n");
- X printf("-------------------------------------------------------------\n");
- X
- X printf("Your Temperature Scale? ");
- X getinteger(&choice,3);
- X printf("\n How many degrees %s? ", scale[choice-1]);
- X getnumber(&temp);
- X switch(choice) {
- X case 1 :
- X fahrenheit = temp;
- X break;
- X case 2 :
- X fahrenheit = temp*(9.0/5.0) + 32.0;
- X break;
- X case 3 :
- X fahrenheit = temp - 459.67;
- X break;
- X case 4 :
- X fahrenheit = ((temp-273.15)*(9.0/5.0)) + 32.0;
- X break;
- X }
- X celsius = (fahrenheit - 32) * (5.0/9.0);
- X rankine = fahrenheit + 459.67;
- X kelvin = celsius + 273.15;
- X
- X Clear;
- X printf(" %16.8g degrees %s is equivalent to:\n",
- X temp,scale[choice-1]);
- X printf(" ------------------------------------\n");
- X if (choice != 1) printf(" %16.8g degrees Fahrenheit\n", fahrenheit);
- X if (choice != 2) printf(" %16.8g degrees Celsius\n", celsius);
- X if (choice != 3) printf(" %16.8g degrees Rankine\n", rankine);
- X if (choice != 4) printf(" %16.8g degrees Kelvin\n", kelvin);
- X
- X printf(" ------------------------------------\n");
- X printf("\n (R)erun Unit type, (N)ew Unit type, or (Q)uit: ");
- X scanf("%s",c);
- X if ( c[0] == 'Q' || c[0] == 'q' ) {
- X quit_it();
- X }
- X else if ( c[0] == 'R' || c[0] == 'r' ) {
- X tempagain = 1;
- X }
- X else if ( c[0] == 'N' || c[0] == 'n' ) {
- X tempagain = 0;
- X }
- X } /* end while(tempagain) */
- X c[0] = '\0';
- X return;
- X}
- ________This_Is_The_END________
- echo 'x - u.c'
- sed 's/^X//' <<'________This_Is_The_END________' >>u.c
- X/* un.c - A Units Conversion Program
- X
- X Written 1/17/87
- X Updated 1/09/89,1/23/89
- X
- X*/
- X
- X/*
- X Copyright 1987,1988,1989 Gregory R. Simpson
- X
- XUUCP: uunet!steinmetz!ltd2.decnet!simpsong
- XARPA: simpsong%ltd2.decnet@crd.ge.com
- XAT&T: (216)-381-6789
- X
- X This notice and any statement of authorship must be reproduced
- X on all copies. The author does not make any warranty expressed
- X or implied, or assumes any liability or responsiblity for the
- X use of this software.
- X
- X Any distributor of copies of this software shall grant the
- X recipient permission for further redistribution as permitted
- X by this notice. Any distributor must distribute this software
- X without any fee or other monetary gains, unless expressed written
- X permission is granted by the author.
- X
- X This software or its use shall not be: sold, rented, leased,
- X traded, or otherwise marketed without the expressed written
- X permission of the author.
- X
- X If the software is modified in a manner creating derivative
- X copyrights, appropriate legends may be placed on derivative
- X work in addition to that set forth above.
- X
- X Permission is hereby granted to copy, reproduce, redistribute or
- X otherwise use this software as long as the conditions above
- X are meet.
- X
- X All rights not granted by this notice are reserved.
- X
- X (This copyright notice was written by, Kurt Zeilenga (zeilenga@hc.dspo.gov)
- X thanks Kurt... -greg)
- X
- X*/
- X/* This program is for Unit Conversion... */
- X
- X#include "un.h"
- X
- X/*
- Xstruct of_units {
- X char *name; Name of Unit
- X double value; Value - Initially set to 0
- X double conversion; Conversion factor to Primary Unit
- X int counter; Number of units in this group
- X}
- X*/
- X
- X#include "unit_table.h"
- X
- X/* ------------ main program ------------ */
- X
- Xmain(argc, argv)
- Xint argc;
- Xchar *argv[];
- X{
- X int group, user_unit, counter, unit_counter, sameunit;
- X int comp_unit, ref_unit, chart, screen;
- X double user_value, from_value, to_value, temp_value, value, increment;
- X double primary;
- X char c[10], *cfile, chartfile[100];
- X FILE *fpchart;
- X
- X /* default values */
- X
- X group = 1;
- X user_unit = 1;
- X user_value = 1;
- X
- X sameunit = 0; /* New Unit Group */
- X chart = 0; /* Default is standard conversion */
- X
- X /* check for chart option */
- X
- X if (argc > 2) /* usage message if extra command line arguments */
- X {
- X usage();
- X } else if (argc > 1) {
- X if ( argv[1][0] == '-' ) {
- X if ( argv[1][1] == 'C' || argv[1][1] == 'c' ) {
- X chart = 1;
- X } else {
- X usage();
- X }
- X } else {
- X usage();
- X }
- X }
- X while(True) /* loop forever... */
- X {
- X if ( sameunit == 0 )
- X {
- X Clear;
- X printf(" Unit Group Selection\n");
- X printf("-------------------------------------------------------------\n");
- X
- X for (counter = 0; counter <= MAXGROUP; counter = counter+2)
- X {
- X printf("%2d. %-22s %2d. %-22s\n",
- X (counter + 1), unitype[counter],
- X (counter + 2), unitype[counter + 1]);
- X }
- X
- X printf(" Enter 'q' at anytime to (Q)uit\n");
- X printf("---------------------------------------------------(C)grs----\n");
- X
- X
- X printf("Which Type of Unit? ");
- X getinteger(&group, MAXGROUP);
- X group = group - 1; /* since array starts at 0 */
- X
- X unit_counter = unit[group][1].counter - 1;
- X
- X } /* end of sameunit if */
- X
- X switch (group)
- X {
- X case MAXGROUP-2:
- X temperature();
- X sameunit = 0;
- X break;
- X case MAXGROUP-1:
- X prefix();
- X sameunit = 0;
- X break;
- X case MAXGROUP:
- X constants();
- X sameunit = 0;
- X break;
- X default:
- X
- X Clear;
- X printf(" Unit Selection\n");
- X printf("-------------------------------------------------------------\n");
- X for (counter = 0; counter <= unit_counter; counter = counter+2)
- X {
- X printf("%2d. %-18s %2d. %-18s\n",
- X (counter + 1), unit[group][counter].name,
- X (counter + 2), unit[group][counter + 1].name);
- X }
- X printf(" Enter 'q' at anytime to (Q)uit\n");
- X printf("-------------------------------------------------------------\n");
- X
- X/* -------------------- Standard Unit Conversion ---------------- */
- X
- X if (chart == 0) {
- X
- X printf("Your Unit? ");
- X getinteger(&user_unit, unit_counter);
- X user_unit = user_unit - 1;
- X
- X printf("\nHow many %s ? ", unit[group][user_unit].name );
- X getnumber(&user_value, unit_counter);
- X
- X Clear;
- X printf("\n ============================================================\n");
- X
- X primary=user_value*(1/unit[group][user_unit].conversion);
- X
- X printf(" %16.8g %s is equivalent to:\n",
- X user_value, unit[group][user_unit].name);
- X printf(" ------------------------------------------------------------\n");
- X for (counter = unit_counter; counter >= 0; counter--)
- X {
- X if (counter != user_unit)
- X {
- X unit[group][counter].value =
- X primary * unit[group][counter].conversion;
- X printf(" %16.8g %-18s\n",
- X unit[group][counter].value,
- X unit[group][counter].name);
- X }
- X }
- X printf(" ============================================================\n");
- X action(&sameunit, &chart);
- X }
- X
- X/* --------------------- Chart Option --------------------- */
- X
- X else {
- X
- X printf("\nYour Reference Unit? ");
- X getinteger(&ref_unit, unit_counter);
- X ref_unit = ref_unit - 1;
- X printf("Your Comparison Unit? ");
- X getinteger(&comp_unit, unit_counter);
- X comp_unit = comp_unit - 1;
- X
- X printf("\nFrom How Many %s? ", unit[group][ref_unit].name);
- X getnumber(&from_value);
- X printf("To How Many %s? ", unit[group][ref_unit].name);
- X getnumber(&to_value);
- X printf("By what increment? ");
- X getnumber(&increment);
- X
- X screen = 0;
- X printf("\nFilename for chart? (<CR> for screen): ");
- X cfile = gets(chartfile);
- X if (cfile[0] == '\0') {
- X fpchart = stdout;
- X screen = 1;
- X }
- X else if ( ( fpchart = fopen(cfile,"a") ) == NULL ) {
- X fprintf(stderr, "Can't open Chartfile.");
- X exit(1);
- X }
- X
- X Clear;
- X
- X /* ----- Error Checking and Correction... ----- */
- X
- X if ( from_value > to_value )
- X {
- X fprintf(fpchart,
- X "Your From value is Greater than your To value.\n");
- X fprintf(fpchart,"Therefore, I swapped them.\n");
- X temp_value = from_value;
- X from_value = to_value;
- X to_value = temp_value;
- X }
- X if ( increment < 0 )
- X {
- X fprintf(fpchart,
- X "Since your From value is Less than your To value,\n");
- X fprintf(fpchart,
- X "I will make your increment positive.\n");
- X increment = -increment;
- X }
- X
- X fprintf(fpchart,
- X"------------------------------------------------------------------------------\n");
- X
- X for (value = from_value; value <= to_value;
- X value = value + increment)
- X {
- X primary=value*(1/unit[group][ref_unit].conversion);
- X unit[group][comp_unit].value =
- X primary * unit[group][comp_unit].conversion;
- X fprintf(fpchart,
- X "| %16.8g %-18s | %16.8g %-18s |\n",
- X value,unit[group][ref_unit].name,
- X unit[group][comp_unit].value,
- X unit[group][comp_unit].name);
- X fprintf(fpchart,
- X"------------------------------------------------------------------------------\n");
- X }
- X if (screen == 0) {
- X fclose(fpchart);
- X }
- X action(&sameunit, &chart);
- X } /* end of chart if else */
- X } /* end of switch */
- X } /* end of while */
- X} /* ---- end of main program ---- */
- ________This_Is_The_END________
- exit
-
-
-