[net.sources] u.c, a Unit conversion program

simpsong@ncoast.UUCP (Gregory R. Simpson @ The North Coast) (04/25/87)

Below is a unit conversion program... I hope you like it.
Read the "readme.u" file for more info... Feel Free to 
drop me mail with comments, bugs, enhancements... (I love
mail. (-: )

Enjoy!

Greg
----

      Gregory R. Simpson       

UUCP: {ihnp4, seismo, decwrl, philabs, ucbvax}!decvax!cwruecmp!ncoast!simpsong
CSNET: ncoast!simpsong@case.CSNET     
ARPA:  ncoast!simpsong%case.CSNET@Csnet-Relay.ARPA
AT&T (216)-473-1019

# 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:
#        readme.u            u.c   unit_table.h
#
echo 'x - readme.u'
sed 's/^X//' <<'________This_Is_The_END________' >>readme.u
XHello, sorry, but no formal man page at this time...
XEnclosed, however, is a units conversion program I wrote.
XIt allows you to convert lots of units to lots of other units...
XIt is fairly self explainatory. It inquires which type of unit
Xconversion you are interested in, such as length etc... and then
Xasks for the specific unit such as "inches". Then, it asks
Xhow many inches.... the result is a table converting n number of
Xinches to every other unit of length the program is familiar with.
X
XIt also has a chart option, which allows you to create charts
Xof say... mph vs m/sec for 23 mph through 45 mph in increments of
X2 mph etc...
X
XIt includes lots of units... even things like footcandles, stones
Xetc... It also does error-checking (and correction if possible) of
Xuser inputs.
X
XIt is easily expandable to include more unit types, by editing
Xthe include file unit_table.h.
X
XI hope lots of people will use this, and send me all sorts of
Xenhancement requests/bug reports etc... so I will be motivated
Xto improve it, and add a real man page a re-post it with all
Xthe fixes/enhancements from the net.  I like it, and I hope
Xyou do to. The biggest bug is that it uses an ansi escape sequence
Xto clear the screen before each menu... this is obviously a big
Xkludge since I obviously should have used curses, but my pc doesn't
Xhave curses! 
X
XOne other bug is that the main menu is hardwired into u.c, it should
X(for ease of enhancement) be loaded in from the data in unit_table.h...
X
XI have tested the program under 4.3BSD, Sun 3.0, MS-DOS, VMS 4.5
Xand Plexus System III.... it should be portable to just about
Xanything...
X
XEnjoy, 
X
XGreg
X
X
X----
X      Gregory R. Simpson       
X
XUUCP: {ihnp4, seismo, decwrl, philabs, ucbvax}!decvax!cwruecmp!ncoast!simpsong
XCSNET: ncoast!simpsong@case.CSNET     
XARPA:  ncoast!simpsong%case.CSNET@Csnet-Relay.ARPA
________This_Is_The_END________
echo 'x - u.c'
sed 's/^X//' <<'________This_Is_The_END________' >>u.c
X/* unit.c - 1/17/87 */
X
X/*
X        Copyright 1987 Gregory R. Simpson
X
XUUCP: {ihnp4, seismo, decwrl, philabs, ucbvax}!decvax!cwruecmp!ncoast!simpsong
XCSNET: ncoast!simpsong@case.CSNET     
XARPA:  ncoast!simpsong%case.CSNET@Csnet-Relay.ARPA
XAT&T:  (216)-473-1019
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 <stdio.h>
X
X#define ESC '\033'
X#define True 1
X
X/* Definition for clearing Screen */
X
X#define Clear printf("%c[2J%c[1;1f",ESC,ESC)
X
X#define MAXGROUP 20       /* Maximum Number of Unit Groups - 1 */
X
Xstruct 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
X#include "unit_table.h"
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       float user_value, from_value, to_value, temp_value, value, increment;
X       float 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              printf("1.  Length                  2. Mass                \n");
X              printf("3.  Speed                   4. Volume              \n");
X              printf("5.  Area                    6. Density             \n");
X              printf("7.  Time                    8. Force               \n");
X              printf("9.  Energy/Heat/Work       10. Pressure            \n");
X              printf("11. Angle                  12. Power               \n");
X              printf("13. Electric Charge        14. Magnetic Induction  \n");
X              printf("15. Light                  16. Thermal Conductivity\n");
X              printf("17. Coeff of Heat Transfer 18. Heat Flux           \n");
X              printf("19. Viscosity              20. Temperature         \n");
X              printf("21. Constants                                      \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 19:
X                          temperature();
X                          sameunit = 0;
X                          break;
X                 case 20:
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("-------------------------------------------------------------\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\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
X                     printf("     ============================================================\n");
X                     printf("\n      (R)erun Unit type, (N)ew Unit type, (Q)uit, or (C)hart: ");
X                     scanf("%s",c);
X                     if ( c[0] == 'Q' || c[0] == 'q' ) {
X                            printf("\n    U... Units conversion, by Gregory R. Simpson - Copyright 1987 \n");
X                            exit();
X                     } 
X                     else if ( c[0] == 'R' || c[0] == 'r' ) {
X                            sameunit = 1;
X                     } 
X                     else if ( c[0] == 'N' || c[0] == 'n' ) {
X                            sameunit = 0;
X                     } 
X                     else if ( c[0] == 'C' || c[0] == 'c' ) {
X                            chart = 1;
X                            sameunit = 0;
X                     }
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                     printf("\n (R)erun Unit type, (N)ew Unit type, (Q)uit, or (S)tandard Conversions: ");
X                     scanf("%s",c);
X                     if ( c[0] == 'Q' || c[0] == 'q' ) {
X                            printf("\n    U... Unit Conversion, by Gregory R. Simpson - Copyright 1987 \n");
X                            exit();
X                     } 
X                     else if ( c[0] == 'R' || c[0] == 'r' ) {
X                            sameunit = 1;
X                     } 
X                     else if ( c[0] == 'N' || c[0] == 'n' ) {
X                            sameunit = 0;
X                     } 
X                     else if ( c[0] == 'S' || c[0] == 's' ) {
X                            chart = 0;
X                            sameunit = 0;
X                     }
X
X              } /* end of chart if else */
X          } /* end of switch */
X       } /* end of while */
X} /* ---- end of main program ---- */
X
X/* getinteger - Get Positive Integer Routine - G.R.Simpson */
X
Xint getinteger(choice, max)
X
Xint *choice;
Xint max;
X{
X       int status, c;
X       while(1) { 
X              status = scanf("%d", choice);
X              if (status == 0)
X              {
X                     scanf("%*s");
X                     printf("Please Use Positive Integers; 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/* getfloat - Get Floating Point Number - G.R.Simpson */
X
Xgetnumber(fchoice)
X
Xfloat *fchoice;
X{
X       int status, c;
X       while( (status = scanf("%f", fchoice)) == 0)
X       {
X              scanf("%*s");
X              printf("Please Use Numeric Input; try again: ");
X       }
X       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/* usage - Print a usage message - G.R.Simpson */
X
Xusage()
X{
X        printf("\nusage: u [-c] \n");
X        printf("-c : unit chart option \n\n");
X        printf("U... Unit conversions; Copyright, Gregory R. Simpson 1987\n");
X        exit();
X}
X
X/* temperature - G.R.Simpson */
X
Xtemperature()
X{
Xstatic char *scale[4] = { "Fahrenheit", "Celsius", "Rankine", "Kelvin" };
Xfloat fahrenheit, celsius, rankine, kelvin;
Xfloat 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           printf("\n    U... Unit Conversion, by Gregory R. Simpson - Copyright 1987 \n");
X           exit();
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}
X
X/* constants - G.R.Simpson */
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           printf("\n    U... Unit Conversion, by Gregory R. Simpson - Copyright 1987 \n");
X           exit();
X        } else {
X        c[0] = '\0';
X        return;
X        }
X}
________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
XBug... I should include the Unit Group Menu info in this
Xfile in order to make it easier to include more unit types.
X     -simpsong
X************************************************** */
X
Xunit[30][20] = {
X       {
X              {"feet",0,1,18},                      /* length */
X              {"inches",0,12,18},
X              {"yards",0,.33333333,18},
X              {"centimeters",0,30.48,18},
X              {"meters",0,.3048,18}, 
X              {"kilometers",0,3.048e-04,18},
X              {"statute miles",0,1.894e-04,18},
X              {"nautical miles",0,1.6457925e-04,18},
X              {"par-secs",0,9.8827862e-18,18},
X              {"light-years",0,3.2218301e-17,18},
X              {"mils",0,12000.,18},
X              {"microns",0,304800.,18},
X              {"millimicrons",0,3.048e08,18},
X              {"angstroms",0,3.048e09,18},
X              {"x-units",0,3.048e12,18},
X              {"rods",0,.060606,18},
X              {"fathoms",0,.16666667,18},
X              {"furlongs",0,1.51515e-03,18}
X       },
X       {
X              {"pounds",0,1,7},                    /* mass */
X              {"grams",0,453.6,7},
X              {"kilograms",0,.4536,7},
X              {"tons",0,5.0e-04,7},
X              {"amus",0,2.732e26,7},
X              {"ounces",0,16,7},
X              {"stones",0,.0714285,7},
X              {"",0,0,7}
X       },
X       {
X              {"m/sec",0,1,6},                     /* speed */
X              {"ft/sec",0,3.281,6},
X              {"km/hr",0,3.6,6},
X              {"cm/sec",0,100,6},
X              {"knots",0,1.944,6},
X              {"miles/hr",0,2.237,6},
X              {"",0,0,7}
X       },
X       {
X              {"cubic meters",0,1,10},                          /* Volume */
X              {"cubic cms",0,1e06,10},
X              {"liters",0,1000,10},
X              {"gallons",0,264.20079,10},
X              {"cubic feet",0,35.31,10},
X              {"cubic inches",0,6.102e04,10},
X              {"barrels",0,11096.433,10},
X              {"hogsheads",0,5548.2166,10},
X              {"boardfeet",0,8786880.,10},
X              {"cords",0,4519.68,10}
X       },
X       {
X              {"square meters",0,1,6},                          /* Area */
X              {"square cms",0,1e04,6},
X              {"square feet",0,10.76,6},
X              {"square inches",0,1550,6},
X              {"circular mills",0,1.974e09,6},
X              {"acres",0,2.4709661e-04,6}
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,10},                          /* Time */
X              {"years",0,2.738e-03,10},
X              {"hours",0,24,10},
X              {"minutes",0,1440,10},
X              {"seconds",0,8.640e04,10},
X              {"decades",0,2.738e-04,10},
X              {"score",0,1.369e-04,10},
X              {"centuries",0,2.738e-05,10},
X              {"millenia",0,2.738e-06,10},
X              {"fortnights",0,.0714285,10}
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,9},                          /* Energy */
X              {"ergs",0,1.055e10,9},
X              {"ft-lbs",0,777.9,9},
X              {"hp-hr",0,3.929e-04,9},
X              {"joules",0,1055,9},
X              {"calories",0,252.0,9},
X              {"kilowatt-hours",0,2.930e-04,9},
X              {"electron volts",0,6.585e21,9},
X              {"MeV",0,6.585e15,9},
X              {"",0,0,9}
X       },
X       {
X              {"atmospheres",0,1,12},                  /* Pressure */
X              {"dynes/cm2",0,1.013e06,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.70,12},
X              {"lbs/ft2",0,2116,12},
X              {"newtons/m2",0,1.013e05,12},
X              {"bars",0,1.0133,12},
X              {"pascals",0,1.013e05,12}
X       },
X       {
X              {"degrees",0,1,5},                          /* Plane Angles */
X              {"minutes",0,60,5},
X              {"seconds",0,3600,5},
X              {"radians",0,1.745e-02,5},
X              {"revolutions",0,2.77777778e-03,5},
X              {"",0,0,5}
X       },
X       {
X              {"btus/hour",0,1,7},                          /* Power */
X              {"ft-lbs/min",0,12.97,7},
X              {"ft-lbs/sec",0,.2161,7},
X              {"horsepower",0,3.929e-04,7},
X              {"kilowatts",0,2.930e-04,7},
X              {"watts",0,.2930,7},
X              {"calories/sec",0,7.000,7},
X              {"",0,0,7}
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,5},                        /* Magnetic Induction */
X              {"kilolines/in2",0,6.452e-03,5},
X              {"webers/m2",0,1e-04,5},
X              {"tesla",0,1e-04,5},
X              {"gamma",0,1e05,5},
X              {"",0,0,5}
X       },
X       {
X              {"Footlamberts",0,1,7},                          /* Light */
X              {"Nit",0,.2919,7},
X              {"Millilamberts",0,.929,7},
X              {"Candelas/in2",0,452,7},
X              {"Candelas/ft2",0,3.142,7},
X              {"Candelas/m2",0,.2919,7},
X              {"Stilb",0,2919,7},
X              {"",0,1,7}
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,5},             /* viscosity */
X              {"lb/sec-ft",0,.000672,5}, 
X              {"lb force-sec/ft2",0,.0000209,5},
X              {"lb/hr-ft",0,2.42,5},
X              {"kg/hr-m",0,3.60,5},
X              {"",0,1,5}
X       },
X};
X
________This_Is_The_END________
exit
-- 
      Gregory R. Simpson       

UUCP: {ihnp4, seismo, decwrl, philabs, ucbvax}!decvax!cwruecmp!ncoast!simpsong
CSNET: ncoast!simpsong@case.CSNET     
ARPA:  ncoast!simpsong%case.CSNET@Csnet-Relay.ARPA

ubi@sri-unix.UUCP (04/28/87)

Greg forgot to do one thing:  make his floating points double
precision.  This is somewhat annoying when you find that 1000 mils =
.999994 inches, or that -40 degrees F = -39.99996 degrees C.

To fix, simply use a global replace such as (for vi or ex):

	:%s/float/double/g

and then change the %f tag of the scanf() in getnumber() to %F or %lf,
whichever you prefer.

A useful little program!