home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / misc / volume07 / un < prev    next >
Encoding:
Internet Message Format  |  1991-08-27  |  44.4 KB

  1. From decwrl!sun-barr!cs.utexas.edu!uunet!allbery Sun Jun  4 14:44:05 PDT 1989
  2. Article 895 of comp.sources.misc:
  3. Path: decwrl!sun-barr!cs.utexas.edu!uunet!allbery
  4. From: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  5. Newsgroups: comp.sources.misc
  6. Subject: v07i006: Units conversion program (better than Unix "units")
  7. Message-ID: <56707@uunet.UU.NET>
  8. Date: 4 Jun 89 01:31:30 GMT
  9. Sender: allbery@uunet.UU.NET
  10. Reply-To: simpsong@NCoast.ORG (Gregory R. Simpson)
  11. Organization: International Society of Lamp Gam'ers.
  12. Lines: 1171
  13. Approved: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  14.  
  15. Posting-number: Volume 7, Issue 6
  16. Submitted-by: simpsong@NCoast.ORG (Gregory R. Simpson)
  17. Archive-name: un
  18.  
  19. Here's a submission for comp.sources.misc. It should compile
  20. on almost any machine,  unix, turboc, vms... It's a units
  21. conversion program. It was first posted in April 1987... It's
  22. expanded and improved... Comments welcome,
  23.  
  24. Greg
  25.  
  26. Gregory R. Simpson
  27. simpsong%ltd2.decnet@crd.ge.com
  28.  
  29.  
  30. # This is a shell archive.  Save this into a file, edit it
  31. # and delete all lines above this comment.  Then give this
  32. # file to sh by executing the command "sh file".  The files
  33. # will be extracted into the current directory owned by
  34. # you with default permissions.
  35. #
  36. # The files contained herein are:
  37. #         read.me       manifest           un.n       makefile
  38. #         un.h          unit_table.h       cons.c     control.c
  39. #         getit.c       temp.c             u.c
  40. #
  41. echo 'x - read.me'
  42. sed 's/^X//' <<'________This_Is_The_END________' >>read.me
  43. XUn is a units conversion program. It converts a unit from one particular
  44. Xunit group to all the other units in that group. It also has a chart option.
  45. XThe best explaination is an example session, both the standard conversion
  46. Xmode and the chart mode are demonstrated below... a manual page is included.
  47. XUn was originally released in April 1987 as "u"... it is easily
  48. Xexpandable... Since the '87 version, I've added more british units, made
  49. Xthe program easy to quit, and broken the code into modules. My thanks to
  50. XTodd Ogasawara, U. of Hawaii Computing Center for writing a manual page.
  51. XIt currently has a total of 196 different unit conversions in 21 catagories.
  52. X(and a prefix and constant section).
  53. X
  54. XEnjoy,
  55. X
  56. XGreg
  57. X
  58. XGregory R. Simpson
  59. X
  60. XPlease send any comments/suggestions/new unit types to:
  61. X
  62. XInternet: simpsong%ltd2.decnet@crd.ge.com
  63. XUUCP:     uunet!steinmetz!ltd2.decnet!simpsong
  64. XVOICE:    (216)-381-6789
  65. X
  66. X----------------------- Example Session ---------------------
  67. X
  68. X                    Unit Group Selection
  69. X-------------------------------------------------------------
  70. X 1. Length                                    2. Mass                  
  71. X 3. Speed                                     4. Volume                
  72. X 5. Area                                      6. Density               
  73. X 7. Time                                      8. Force                 
  74. X 9. Energy/Heat/Work                         10. Pressure              
  75. X11. Angle                                    12. Power                 
  76. X13. Electric Charge                          14. Magnetic Induction    
  77. X15. Light                                    16. Thermal Conductivity  
  78. X17. Coeff of Heat Transfer                   18. Heat Flux             
  79. X19. Viscosity                                20. Cooking Volumes       
  80. X21. Temperature                              22. Prefix List           
  81. X23. Constants                                24.                       
  82. X              Enter 'q' at anytime to (Q)uit
  83. X---------------------------------------------------(C)grs----
  84. XWhich Type of Unit? 1
  85. X
  86. X                      Unit Selection
  87. X-------------------------------------------------------------
  88. X 1. feet                                      2. inches            
  89. X 3. yards                                     4. centimeters       
  90. X 5. meters                                    6. kilometers        
  91. X 7. statute miles                             8. nautical miles    
  92. X 9. par-secs                                 10. light-years       
  93. X11. mils                                     12. microns           
  94. X13. millimicrons                             14. angstroms         
  95. X15. x-units                                  16. rods              
  96. X17. fathoms                                  18. chains            
  97. X19. ropes (Brit.)                            20. furlongs          
  98. X              Enter 'q' at anytime to (Q)uit
  99. X-------------------------------------------------------------
  100. XYour Unit? 1
  101. X
  102. XHow many feet ? 2
  103. X
  104. X     ============================================================
  105. X                    2 feet is equivalent to:
  106. X     ------------------------------------------------------------
  107. X
  108. X                         0.0030303 furlongs          
  109. X                               0.1 ropes (Brit.)     
  110. X                         0.0030303 chains            
  111. X                        0.33333334 fathoms           
  112. X                          0.121212 rods              
  113. X                        6.096e+012 x-units           
  114. X                        6.096e+009 angstroms         
  115. X                         609600000 millimicrons      
  116. X                            609600 microns           
  117. X                             24000 mils              
  118. X                    6.4436602e-017 light-years       
  119. X                    1.9765572e-017 par-secs          
  120. X                      0.0003291585 nautical miles    
  121. X                         0.0003788 statute miles     
  122. X                         0.0006096 kilometers        
  123. X                            0.6096 meters            
  124. X                             60.96 centimeters       
  125. X                        0.66666666 yards             
  126. X                                24 inches            
  127. X     ============================================================
  128. X
  129. X      (R)erun Unit type, (N)ew Unit type, (Q)uit, or (C)hart: c
  130. X
  131. X                          Unit Group Selection
  132. X-------------------------------------------------------------
  133. X 1. Length                                    2. Mass                  
  134. X 3. Speed                                     4. Volume                
  135. X 5. Area                                      6. Density               
  136. X 7. Time                                      8. Force                 
  137. X 9. Energy/Heat/Work                         10. Pressure              
  138. X11. Angle                                    12. Power                 
  139. X13. Electric Charge                          14. Magnetic Induction    
  140. X15. Light                                    16. Thermal Conductivity  
  141. X17. Coeff of Heat Transfer                   18. Heat Flux             
  142. X19. Viscosity                                20. Cooking Volumes       
  143. X21. Temperature                              22. Prefix List           
  144. X23. Constants                                24.                       
  145. X              Enter 'q' at anytime to (Q)uit
  146. X---------------------------------------------------(C)grs----
  147. XWhich Type of Unit? 2
  148. X                          Unit Selection
  149. X-------------------------------------------------------------
  150. X 1. pounds                                    2. grams             
  151. X 3. kilograms                                 4. tons              
  152. X 5. amus                                      6. ounces            
  153. X 7. stones                                    8.                   
  154. X              Enter 'q' at anytime to (Q)uit
  155. X-------------------------------------------------------------
  156. X
  157. XYour Reference Unit?  1
  158. XYour Comparison Unit? 2
  159. X
  160. XFrom How Many pounds?  1
  161. XTo How Many pounds?    10
  162. XBy what increment? 1
  163. X
  164. XFilename for chart? (<CR> for screen): 
  165. X------------------------------------------------------------------------------
  166. X|                1 pounds             |            453.6 grams              |
  167. X------------------------------------------------------------------------------
  168. X|                2 pounds             |            907.2 grams              |
  169. X------------------------------------------------------------------------------
  170. X|                3 pounds             |           1360.8 grams              |
  171. X------------------------------------------------------------------------------
  172. X|                4 pounds             |           1814.4 grams              |
  173. X------------------------------------------------------------------------------
  174. X|                5 pounds             |             2268 grams              |
  175. X------------------------------------------------------------------------------
  176. X|                6 pounds             |           2721.6 grams              |
  177. X------------------------------------------------------------------------------
  178. X|                7 pounds             |           3175.2 grams              |
  179. X------------------------------------------------------------------------------
  180. X|                8 pounds             |           3628.8 grams              |
  181. X------------------------------------------------------------------------------
  182. X|                9 pounds             |           4082.4 grams              |
  183. X------------------------------------------------------------------------------
  184. X|               10 pounds             |             4536 grams              |
  185. X------------------------------------------------------------------------------
  186. X
  187. X (R)erun Unit type, (N)ew Unit type, (Q)uit, or (S)tandard Conversions: q
  188. X
  189. X    U... Unit Conversion, by Gregory R. Simpson - Copyright 1988 
  190. X
  191. X
  192. ________This_Is_The_END________
  193. echo 'x - manifest'
  194. sed 's/^X//' <<'________This_Is_The_END________' >>manifest
  195. Xmanifest       - this file
  196. Xu.c            - Main Program    
  197. Xcons.c         - Constants
  198. Xgetit.c        - Input routines
  199. Xcontrol.c      - Control funtions
  200. Xtemp.c         - Temperature Conversion
  201. Xun.h           - General Include File
  202. Xunit_table.h   - Unit Conversion Factor include file
  203. Xmakefile       - Makefile
  204. Xun.n           - Manual Page
  205. Xread.me        - A read.me file
  206. ________This_Is_The_END________
  207. echo 'x - un.n'
  208. sed 's/^X//' <<'________This_Is_The_END________' >>un.n
  209. X.tr ~ \ 
  210. X.TH un l LOCAL
  211. X.SH NAME
  212. X\fIun\fR \- convert from one unit of measurement to another
  213. X.SH SYNOPSIS
  214. X.BR "\fIun\fR
  215. Xis a menu driven program that lets you convert values
  216. Xfrom one unit of measurement to another unit of measurement.
  217. XA simple example is using \fIun\fR to find that 1 inch is
  218. Xequivalent to 2.54 centimeters.
  219. X
  220. X.PP
  221. X.SH DESCRIPTION
  222. X.I un
  223. Xfirst asks you for the group of measurement units you want to use.
  224. XThe table below lists the measurement groups available.
  225. X.sp
  226. X.nf
  227. X                Unit Group Selection
  228. X-------------------------------------------------------------
  229. X 1. Length                                    2. Mass                  
  230. X 3. Speed                                     4. Volume                
  231. X 5. Area                                      6. Density               
  232. X 7. Time                                      8. Force                 
  233. X 9. Energy/Heat/Work                         10. Pressure              
  234. X11. Angle                                    12. Power                 
  235. X13. Electric Charge                          14. Magnetic Induction    
  236. X15. Light                                    16. Thermal Conductivity  
  237. X17. Coeff of Heat Transfer                   18. Heat Flux             
  238. X19. Viscosity                                20. Cooking Volumes       
  239. X21. Temperature                              22. Prefix List           
  240. X23. Constants                                24.                       
  241. X              Enter 'q' at anytime to (Q)uit
  242. X---------------------------------------------------(C)grs----
  243. X.fi
  244. X.sp
  245. XIt then asks you for the specific unit you are interested in; "inches"
  246. Xfor example.
  247. X\fIun\fR then displays the converted value for each of the related
  248. Xunits of measurement.
  249. XOne of the menu options that follows the conversion of one unit to
  250. Xanother allows you to produce a text chart that shows you value
  251. Xconversions in some specified increment.
  252. XFor example, you can ask \fIun\fR to show you the converted
  253. Xcentimeter value of 1 inch to 12 inches in 1 inch increments.
  254. X
  255. X.SH AUTHOR
  256. X.nf
  257. X\fIun\fR was written by:
  258. XGregory R. Simpson
  259. XUUCP:  uunet!steinmetz!ltd2.decnet!simpsong
  260. XARPA:  simpsong%ltd2.decnet@crd.ge.com
  261. XAT&T:  (216)-381-6789
  262. X.fi
  263. X.PP
  264. X.SH BUGS AND CAVEATS
  265. X(1) The values produced are subject to rounding error.  For example,
  266. X61 seconds is converted to 1 minutes and 1.66 seconds.
  267. X.SH SEE ALSO
  268. Xunits(1)
  269. ________This_Is_The_END________
  270. echo 'x - makefile'
  271. sed 's/^X//' <<'________This_Is_The_END________' >>makefile
  272. X# UN.C
  273. X# Unit conversion program
  274. X
  275. XBIN = /usr/local
  276. XCC = cc -O
  277. XMAN = /usr/man/manl
  278. XPROG = un
  279. XOBJ = u.o cons.o control.o getit.o temp.o 
  280. XINC = un.h unit_table.h
  281. X
  282. X$(PROG): $(OBJ) $(INC)
  283. X    $(CC) -o $(PROG) $(OBJ)
  284. X
  285. Xu.o: u.c
  286. X    $(CC) -c u.c
  287. X
  288. Xcons.o: cons.c
  289. X    $(CC) -c cons.c
  290. X
  291. Xcontrol.o: control.c
  292. X    $(CC) -c control.c
  293. X
  294. Xgetit.o: getit.c
  295. X    $(CC) -c getit.c
  296. X
  297. Xtemp.o: temp.c
  298. X    $(CC) -c temp.c
  299. X
  300. Xinstall:
  301. X    cp $(PROG) $(BIN)
  302. X    chmod a+rx $(BIN)/$(PROG)
  303. X    strip $(BIN)/$(PROG)
  304. X    cp $(PROG).n $(MAN)/$(PROG).l
  305. X    chmod a+r $(MAN)/$(PROG).l
  306. ________This_Is_The_END________
  307. echo 'x - un.h'
  308. sed 's/^X//' <<'________This_Is_The_END________' >>un.h
  309. X/* un.h - 1/17/87 */
  310. X
  311. X#include <stdio.h>
  312. X
  313. X#define ESC '\033'
  314. X#define True 1
  315. X
  316. X/* Definition for clearing Screen */
  317. X
  318. X#ifdef MSDOS
  319. X#define Clear printf("%c[2J%c[1;1f",ESC,ESC)
  320. X#else
  321. X#define Clear printf("\n\n");
  322. X#endif
  323. ________This_Is_The_END________
  324. echo 'x - unit_table.h'
  325. sed 's/^X//' <<'________This_Is_The_END________' >>unit_table.h
  326. X/* unit_table.h - Copyright 1987 - Gregory R. Simpson */
  327. X/* subject to the same conditions outlined in u.c's copyright */
  328. X
  329. X/* ************ a table of the form: ************** 
  330. X
  331. X    struct of_units {
  332. X           char  *name;        Name of Unit 
  333. X           float value;        Value - Initially set to 0 
  334. X           float conversion;   Conversion factor to Primary Unit 
  335. X           int   counter;      Number of units in this group 
  336. X    } 
  337. X
  338. XThe primary unit is the first unit listed in the unit group.
  339. XAlways include an even number of entries in the group even
  340. Xif this means that the last entry is blank. Then, set the
  341. Xnumber of entries to the correct odd number...this is to
  342. Xhandle displays correctly... For example, see the mass
  343. Xentry below.
  344. X
  345. XThere are currently: 196 unit conversion in 21 catagories.
  346. X
  347. X20 Length, 15 Mass, 6 Speed, 18 Volume, 14 Area, 5 Density, 12 Time,
  348. X5 Force, 20 Energy, 12 Pressure, 6 Plane Angles, 10 Power, 6 Electric Charge
  349. X6 Magnetic Induction, 12 Light, 4 Thermal Conductivity, 4 Coeff. of Heat
  350. XTransfer, 6 Viscosity, 8 Cooking volumes, 8 Computer Media.
  351. X
  352. X************************************************** */
  353. X
  354. X#define MAXGROUP 23       /* Maximum Number of Unit Groups - 1 */
  355. X
  356. Xstatic char *unitype[MAXGROUP+2] = {
  357. X                  "Length"                , "Mass"               
  358. X              ,  "Speed"                 , "Volume"    
  359. X               ,  "Area"                  , "Density"   
  360. X              ,  "Time"                  , "Force"     
  361. X              ,  "Energy/Heat/Work"      , "Pressure"  
  362. X              , "Angle"                  , "Power"               
  363. X              , "Electric Charge"        , "Magnetic Induction"
  364. X              , "Light"                  , "Thermal Conductivity"
  365. X              , "Coeff of Heat Transfer" , "Heat Flux"           
  366. X              , "Viscosity"              , "Cooking Volumes"
  367. X              , "Computer Media"
  368. X
  369. X/* Temperature, Prefix, and Constants are always the last 3 
  370. X   Add New Unit Types above this point. */
  371. X              
  372. X               , "Temperature"          , "Prefix List"  
  373. X              , "Constants"            , " "         
  374. X          };
  375. X
  376. Xstruct of_units {
  377. X       char  *name;         /* Name of Unit */
  378. X       double value;        /* Value - Initially set to 0 */
  379. X       double conversion;   /* Conversion factor to Primary Unit */
  380. X       int   counter;       /* Number of units in this group */
  381. X}
  382. Xunit[30][20] = {
  383. X       {
  384. X              {"feet",0,1,20},                      /* length */
  385. X              {"inches",0,12,20},
  386. X              {"yards",0,.33333333,20},
  387. X              {"centimeters",0,30.48,20},
  388. X              {"meters",0,.3048,20}, 
  389. X              {"kilometers",0,3.048e-04,20},
  390. X              {"statute miles",0,1.894e-04,20},
  391. X              {"nautical miles",0,1.6457925e-04,20},
  392. X              {"par-secs",0,9.8827862e-18,20},
  393. X              {"light-years",0,3.2218301e-17,20},
  394. X              {"mils",0,12000.,20},
  395. X              {"microns",0,304800.,20},
  396. X              {"millimicrons",0,3.048e08,20},
  397. X              {"angstroms",0,3.048e09,20},
  398. X              {"x-units",0,3.048e12,20},
  399. X              {"rods",0,.060606,20},
  400. X              {"fathoms",0,.16666667,20},
  401. X              {"chains",0,.00151515,20},
  402. X              {"ropes (Brit.)",0,.05,20},
  403. X              {"furlongs",0,1.51515e-03,20}
  404. X       },
  405. X       {
  406. X              {"pounds (avdp.)",0,1,15},                    /* mass */
  407. X              {"grams",0,453.59237,15},
  408. X              {"kilograms",0,.45359237,15},
  409. X              {"tons (short)",0,5.0e-04,15},
  410. X              {"tons (long)",0,.00044642857,15},
  411. X              {"tons (metric)",0,.00045359237,15},
  412. X              {"pennyweights",0,291.6666,15},
  413. X              {"scruples (apoth)",0,350,15},
  414. X              {"drams (apoth/troy)",0,116.6666,15},
  415. X              {"drams (avdp.)",0,256.0,15},
  416. X              {"amus",0,2.732e26,15},
  417. X              {"ounces (avdp.)",0,16,15},
  418. X              {"stones",0,.0714285,15},
  419. X              {"grains",0,7000.0,15},
  420. X              {"slugs",0,.0310810,15},
  421. X              {"",0,0,15}
  422. X       },
  423. X       {
  424. X              {"m/sec",0,1,6},                     /* speed */
  425. X              {"ft/sec",0,3.2808399,6},
  426. X              {"ft/min",0,196.85039,6},
  427. X              {"km/hr",0,3.6,6},
  428. X              {"km/min",0,.06,6},
  429. X              {"cm/sec",0,100,6},
  430. X              {"knots",0,1.944,6},
  431. X              {"miles/hr",0,2.2369363,6}
  432. X       },
  433. X       {
  434. X              {"cubic meters",0,1,18},                          /* Volume */
  435. X              {"cubic cms",0,1e06,18},
  436. X              {"liters",0,1000,18},
  437. X              {"gallons (U.S. Liq)",0,264.17205,18},
  438. X              {"gallons (Brit.)",0,219.9694,18},
  439. X              {"quarts (U.S. Liq)",0,1056.6882,18},
  440. X              {"quarts (Brit.)",0,879.87753,18},
  441. X              {"pints (U.S. Liq)",0,2113.3764,18},
  442. X              {"cubic feet",0,35.314667,18},
  443. X              {"cubic inches",0,6.102374e04,18},
  444. X              {"barrels (U.S. liq)",0,8.3864145,18},
  445. X              {"barrels (U.S. dry)",0,8.648490,18},
  446. X              {"barrels (Brit.)",0,6.110261,18},
  447. X              {"hogsheads",0,4.1932072,18},
  448. X              {"boardfeet",0,8786880.,18},
  449. X              {"acre-feet",0,.00081071319,18},
  450. X              {"cords",0,4519.68,18},
  451. X              {"steres",0,1.0,18}
  452. X       },
  453. X       {
  454. X              {"square meters",0,1,14},                          /* Area */
  455. X              {"square kilometers",0,1.0e-6,14},      
  456. X              {"square cms",0,1e04,14},
  457. X              {"square miles",0,3.8610216e-07,14},
  458. X              {"square feet",0,10.76,14},
  459. X              {"square inches",0,1550,14},
  460. X              {"sq. links (Gunter)",0,24.710538,14},
  461. X              {"sq. links (Ramden)",0,10.763910,14},
  462. X              {"square mm",0,1e06,14},
  463. X              {"square rods",0,.039536861,14},
  464. X              {"sq. perches (Brit)",0,.039536861,14},
  465. X              {"hectares",0,.0001,14},
  466. X              {"circular mills",0,1.974e09,14},
  467. X              {"acres",0,2.4710538e-04,14}
  468. X       },
  469. X       {
  470. X              {"kg/m3",0,1,5},                          /* Density */
  471. X              {"slug/ft3",0,1.940e-03,5},
  472. X              {"gm/cm3",0,.001,5},
  473. X              {"lb/ft3",0,6.243e-02,5},
  474. X              {"lb/in3",0,3.613e-05,5},
  475. X              {"",0,0,5}
  476. X       },
  477. X       {
  478. X              {"days",0,1,12},                          /* Time */
  479. X              {"years",0,2.738e-03,12},
  480. X              {"month",0,.0328767,12},
  481. X              {"week",0,.1428571,12},
  482. X              {"hours",0,24,12},
  483. X              {"minutes",0,1440,12},
  484. X              {"seconds",0,8.640e04,12},
  485. X              {"decades",0,2.738e-04,12},
  486. X              {"score",0,1.369e-04,12},
  487. X              {"centuries",0,2.738e-05,12},
  488. X              {"millenia",0,2.738e-06,12},
  489. X              {"fortnights",0,.0714285,12}
  490. X       },
  491. X       {
  492. X              {"newtons",0,1,5},                          /* Force */
  493. X              {"dynes",0,1e05,5},
  494. X              {"pounds",0,.2248,5},
  495. X              {"gram-force",0,102.0,5},
  496. X              {"kilogram-force",0,.1020,5},
  497. X              {"",0,0,5}
  498. X       },
  499. X       {
  500. X              {"btus",0,1,20},                          /* Energy */
  501. X              {"btus (Int.Stm.Tab.)",0,.999346,20},
  502. X              {"btus (mean)",0,.998563,20},
  503. X              {"ergs",0,1.05435e10,20},
  504. X              {"ft-lbs",0,777.649,20},
  505. X              {"hp-hr",0,3.92752e-04,20},
  506. X              {"Joules",0,1054.35,20},
  507. X              {"Joules (int.)",0,1054.18,20},
  508. X              {"Watt-sec",0,1054.35,20},
  509. X              {"Watt-sec (int.)",0,1054.18,20},
  510. X              {"calories",0,251.99576,20},
  511. X              {"calories (I.S.T)",0,251.831,20},
  512. X              {"calories (mean)",0,251.634,20},
  513. X              {"kilowatt-hours",0,2.92875e-04,20},
  514. X              {"kilowatt-hours int",0,2.92827e-04,20},
  515. X              {"electron volts",0,6.585e21,20},
  516. X              {"MeV",0,6.585e15,20},
  517. X              {"liter-atm",0,10.4053,20},
  518. X               {"tons of refrig",0,3.46995e-06,20},
  519. X              {"kg-m",0,107.514,20}
  520. X       },
  521. X       {
  522. X              {"atmospheres",0,1,12},                  /* Pressure */
  523. X              {"dynes/cm2",0,1.01325e06,12},
  524. X              {"inches of water",0,406.8,12},
  525. X              {"cms Hg",0,76.,12},
  526. X              {"torr",0,760.,12},
  527. X              {"mms Hg",0,760.,12},
  528. X              {"inches Hg",0,29.92126,12},
  529. X              {"lbs/in2",0,14.6960,12},
  530. X              {"lbs/ft2",0,2116,12},
  531. X              {"newtons/m2",0,1.01325e05,12},
  532. X              {"bars",0,1.01325,12},
  533. X              {"pascals",0,1.01325e05,12}
  534. X       },
  535. X       {
  536. X              {"degrees",0,1,6},                          /* Plane Angles */
  537. X              {"minutes",0,60,6},
  538. X              {"seconds",0,3600,6},
  539. X              {"radians",0,1.745e-02,6},
  540. X              {"revolutions",0,2.77777778e-03,6},
  541. X              {"quadrants",0,.0111111,6}
  542. X       },
  543. X       {
  544. X              {"btus/hour",0,1,10},                          /* Power */
  545. X              {"ft-lbs/min",0,12.97,10},
  546. X              {"ft-lbs/sec",0,.2161,10},
  547. X              {"horsepower",0,3.929e-04,10},
  548. X              {"kilowatts",0,2.930e-04,10},
  549. X              {"watts",0,.292875,10},
  550. X              {"calories/sec",0,7.000,10},
  551. X              {"ergs/sec",0,2.928751e06,10},
  552. X              {"lb. ice melted/hr",0,.0069714,10},
  553. X              {"tons of refrig.",0,8.32789e-05,10}
  554. X       },
  555. X       {
  556. X              {"coulombs",0,1,6},                        /* Electric Charge */
  557. X              {"abcoulombs",0,.1,6},
  558. X              {"amp-hrs",0,2.778e-04,6},
  559. X              {"faradays",0,1.036e-05,6},
  560. X              {"statcoulombs",0,2.998e9,6},
  561. X              {"electron charges",0,6.2414181e18,6}
  562. X       },
  563. X       {
  564. X              {"Gauss",0,1,6},                      /* Magnetic Induction */
  565. X              {"kilolines/in2",0,6.452e-03,6},
  566. X              {"Webers/m2",0,1e-04,6},
  567. X              {"Tesla",0,1e-04,6},
  568. X              {"gamma",0,1e05,6},
  569. X              {"Maxwells/sq.cm",0,1,6}
  570. X       },
  571. X       {
  572. X              {"Footlamberts",0,1,12},                          /* Light */
  573. X              {"Nit",0,.2919,12},
  574. X              {"Millilamberts",0,.929,12},
  575. X              {"Candelas/in2",0,452,12},
  576. X              {"Candelas/ft2",0,3.142,12},
  577. X              {"Candelas/m2",0,.2919,12},
  578. X              {"Stilb",0,2919,12},
  579. X              {"lumens/ft2",0,1,12},
  580. X              {"foot-candles",0,1,12},
  581. X              {"lux",0,10.763190,12},
  582. X              {"lumens/m2",0,10.763190,12},
  583. X              {"Milliphots",0,1.0763190,12}
  584. X       },
  585. X       {
  586. X              {"Btu/(hr-ft2-F/ft)",0,1,4},          /* thermal conductivity */
  587. X              {"gm-cal/(sec-cm2-C/cm)",0,.004134,4},
  588. X              {"watts/(cm2-C/cm)",0,.01731,4},
  589. X              {"kg-cal/(hr-m2-C/m)",0,1.488,4}
  590. X       },
  591. X       {
  592. X              {"Btu/hr-ft2-F",0,1,4},     /* coeff. of heat trans. */
  593. X              {"gm-cal/sec-cm2-C",0,.0001355,4},
  594. X              {"watts/cm2-C",0,.0005678,4},
  595. X              {"kg-cal/hr-m2-C",0,4.882,4}
  596. X       },
  597. X       {
  598. X              {"Btu/hr-ft2",0,1,4},                          /* heat Flux */
  599. X              {"gm-cal/sec-cm2",0,.00007535,4},
  600. X              {"watts/cm2",0,.0003154,4},
  601. X              {"kg-cal/hr-m2",0,2.712,4}
  602. X       },
  603. X       {
  604. X              {"Centipoises",0,1,6},             /* viscosity */
  605. X              {"lb/sec-ft",0,.000672,6}, 
  606. X              {"lb force-sec/ft2",0,.0000209,6},
  607. X              {"lb/hr-ft",0,2.42,6},
  608. X              {"kg/hr-m",0,3.60,6},
  609. X              {"grams/cm-sec",0,.01,6}
  610. X       },       
  611. X       {
  612. X              {"teaspoons",0,1,8},             /* cooking volumes */
  613. X              {"tablespoons",0,.33333333,8}, 
  614. X              {"cups",0,.0208333,8},
  615. X              {"pints",0,.0104166,8},
  616. X              {"quarts",0,5.2083333e-03,8},
  617. X              {"gallons",0,1.3020833e-03,8},
  618. X              {"fluid ounce",0,.1666666,8},
  619. X              {"jigger",0,.11111111,8}
  620. X       },
  621. X       {
  622. X              {"bytes",0,1,8},             /* computer media */
  623. X              {"kilobytes",0,9.765625e-04,8}, 
  624. X              {"megabytes",0,9.765625e-07,8},
  625. X              {"blocks",0,1.953125e-03,8},
  626. X              {"360K Floppies",0,2.7126736e-06,8},
  627. X              {"1.2 Meg Floppies",0,8.1380208e-07,8},
  628. X              {"1.44 Meg Floppies",0,6.781684e-07,8},
  629. X              {"20 Meg Hard Disk",0,4.8828125e-08,8}
  630. X       },
  631. X};
  632. X
  633. ________This_Is_The_END________
  634. echo 'x - cons.c'
  635. sed 's/^X//' <<'________This_Is_The_END________' >>cons.c
  636. X
  637. X/* constants - G.R.Simpson */
  638. X
  639. X#include "un.h"
  640. X
  641. Xconstants()
  642. X{
  643. X        char c[10];
  644. X
  645. X        Clear;         
  646. X        printf("\npi                      =  3.141592653589793238462643\n");
  647. X        printf("e                       =  2.718281828459045235360287\n");
  648. X        printf("atomic mass unit        =  1.66053 e-27 kg, e-24 gm \n");
  649. X        printf("Avogadro's number N     =  6.02217 e23 mole^-1 \n");
  650. X        printf("Boltzmann's constant    =  R/N = 1.3806 e-23 J/K, e-16 erg/K = 8.61708 e-5 eV/K \n");
  651. X        printf("gas constant            =  8.3143 J/mole-K = 0.082054 l-atm/mole-K\n");
  652. X        printf("gravitational constant  =  6.673 e-11 N-m^2/kg^2, J-m/kg^2, \n");
  653. X        printf("mass of electron        =  9.10956 e-31 kg, e-28 gm =  5.48593 e-4 amu \n");
  654. X        printf("mass of proton          =  1.67261 e-27 kg, e-24 gm =  1.0072766 amu \n");
  655. X        printf("Planck's constant       =  h =  6.62620 e-34 J-sec,  e-27 erg-sec \n");
  656. X        printf("h bar                   =  h/2*pi = 1.05459 e-34 J-sec, e-27 erg-sec \n");
  657. X        printf("speed of light          =  2.997925 e8 m/sec, e10 cm/sec \n");
  658. X        printf("Stefan-Boltzmann constant =  5.670 e-8 W/m^2-K^4 \n");
  659. X        printf("\n      <CR> to continue or (Q)uit: ");
  660. X        gets(c);
  661. X        if ( c[0] == 'Q' || c[0] == 'q' ) {
  662. X           quit_it();
  663. X        } else {
  664. X        c[0] = '\0';
  665. X        return;
  666. X        }
  667. X}
  668. X
  669. X
  670. X/* prefix - G.R.Simpson */
  671. X
  672. Xprefix()
  673. X{
  674. X        char c[10];
  675. X
  676. X        Clear;         
  677. X        printf("tera   =  1,000,000,000,000 = 10e12\n");
  678. X        printf("giga   =      1,000,000,000 = 10e09\n");
  679. X        printf("mega   =          1,000,000 = 10e06\n");
  680. X        printf("kilo   =              1,000 = 10e03\n");
  681. X        printf("centi  =               0.01 = 10e-02\n");
  682. X        printf("milli  =              0.001 = 10e-03\n");
  683. X        printf("micro  =           0.000001 = 10e-06\n");
  684. X        printf("nano   =        0.000000001 = 10e-09\n");
  685. X        printf("pico   =     0.000000000001 = 10e-12\n");
  686. X        printf("\n      <CR> to continue or (Q)uit: ");
  687. X        gets(c);
  688. X        if ( c[0] == 'Q' || c[0] == 'q' ) {
  689. X           quit_it();
  690. X        } else {
  691. X        c[0] = '\0';
  692. X        return;
  693. X        }
  694. X}
  695. ________This_Is_The_END________
  696. echo 'x - control.c'
  697. sed 's/^X//' <<'________This_Is_The_END________' >>control.c
  698. X
  699. X/* usage - Print a usage message - G.R.Simpson */
  700. X
  701. X#include "un.h"
  702. X
  703. Xusage()
  704. X{
  705. X        printf("\nusage: u [-c] \n");
  706. X        printf("-c : unit chart option \n\n");
  707. X        printf("Un... Unit conversions; Copyright, Gregory R. Simpson 1987,1988,1989\n");
  708. X        exit(0);
  709. X}
  710. X
  711. X/* action - G.R.Simpson */
  712. X
  713. Xaction(sameu,charts)
  714. Xint *sameu, *charts;
  715. X{
  716. X     char c[10];
  717. X     int tryagain = 1;
  718. X
  719. X     while (tryagain) {
  720. X    if (*charts != 1) {
  721. X           printf("\n      (R)erun Unit type, (N)ew Unit type, (Q)uit, or (C)hart: ");
  722. X        } else {
  723. X       printf("\n (R)erun Unit type, (N)ew Unit type, (Q)uit, or (S)tandard Conversions: ");
  724. X        }
  725. X    scanf("%s",c);
  726. X        if ( c[0] == 'Q' || c[0] == 'q' ) {
  727. X             quit_it();
  728. X        } 
  729. X        else if ( c[0] == 'R' || c[0] == 'r' ) {
  730. X             *sameu = 1;
  731. X         tryagain = 0;
  732. X        } 
  733. X        else if ( c[0] == 'N' || c[0] == 'n' ) {
  734. X             *sameu = 0;
  735. X         tryagain = 0;
  736. X        } 
  737. X        else if ( c[0] == 'C' || c[0] == 'c' ) {
  738. X         *charts = 1;
  739. X             *sameu = 0;
  740. X         tryagain = 0;
  741. X        }
  742. X    else if ( c[0] == 'S' || c[0] == 's' ) {
  743. X         *charts = 0;
  744. X             *sameu = 0;
  745. X         tryagain = 0;
  746. X        }
  747. X        else {
  748. X         printf("\n             Invalid Response, please try again: \n");
  749. X        }
  750. X   }
  751. X    return;
  752. X}
  753. X
  754. X/* quit_it - G.R.Simpson */
  755. X
  756. Xquit_it()
  757. X{
  758. X    printf("\n Un... Unit Conversion, by Gregory R. Simpson - Copyright 1987,1988,1989 \n");
  759. X        exit(0);
  760. X}
  761. ________This_Is_The_END________
  762. echo 'x - getit.c'
  763. sed 's/^X//' <<'________This_Is_The_END________' >>getit.c
  764. X
  765. X/* getinteger - Get Positive Integer Routine - G.R.Simpson */
  766. X
  767. X#include "un.h"
  768. X
  769. Xint getinteger(choice, max)
  770. X
  771. Xint *choice;
  772. Xint max;
  773. X{
  774. X       char quit[80];
  775. X       char junk[80];
  776. X       int status, c;
  777. X       while(1) { 
  778. X              scanf("%s",quit);
  779. X          if ( quit[0] == 'Q' || quit[0] == 'q' ) {
  780. X                   quit_it();
  781. X          }
  782. X          status = sscanf(quit, "%d", choice);
  783. X              if (status == 0)
  784. X              {
  785. X             scanf("%*s",junk);
  786. X             printf("Please Use Positive Integers,\n");
  787. X                     printf("or 'q' to (Q)uit; try again: ");
  788. X              }
  789. X              else if (status == 1)
  790. X              {
  791. X                     while ((c = getchar()) != '\n' && c != EOF)
  792. X                            ;
  793. X                     if ( c == EOF )
  794. X                     {
  795. X                            ungetc(c, stdin);
  796. X                     }
  797. X                     if ( *choice > 0 && *choice <= max+1 ) 
  798. X                     {
  799. X                             return status;
  800. X                     }
  801. X                     printf("Please use a number from 1 to %d : ", max+1);
  802. X              }
  803. X              else  /* status is -1 */
  804. X              {
  805. X              printf("End of file encountered... \n");
  806. X              *choice = 1;
  807. X              return status;
  808. X              }
  809. X}
  810. X}
  811. X
  812. X/* getdouble - Get Double Precision Number - G.R.Simpson */
  813. X
  814. Xgetnumber(fchoice)
  815. X
  816. Xdouble *fchoice;
  817. X{
  818. X       char quit[80];
  819. X       char junk[80];
  820. X       int status, c;
  821. X       while(1) {
  822. X              scanf("%s",quit);
  823. X          if ( quit[0] == 'Q' || quit[0] == 'q' ) {
  824. X                   quit_it();
  825. X              }
  826. X          status = sscanf(quit, "%lf", fchoice);
  827. X       if (status == 0)
  828. X       {
  829. X              scanf("%*s",junk);
  830. X              printf("Please Use Numeric Input,\n");
  831. X              printf("or 'q' to (Q)uit; try again: ");
  832. X       } 
  833. X       else if (status == 1)
  834. X       {
  835. X              while ((c = getchar()) != '\n' && c != EOF)
  836. X                     ;
  837. X              if ( c == EOF )
  838. X                     ungetc(c, stdin);
  839. X       }
  840. X       else  /* status is -1 */
  841. X       printf("End of file encountered... \n");
  842. X       return status;
  843. X       }
  844. X}
  845. X
  846. ________This_Is_The_END________
  847. echo 'x - temp.c'
  848. sed 's/^X//' <<'________This_Is_The_END________' >>temp.c
  849. X
  850. X/* temperature - G.R.Simpson */
  851. X
  852. X#include "un.h"
  853. X
  854. Xtemperature()
  855. X{
  856. Xstatic char *scale[4] = { "Fahrenheit", "Celsius", "Rankine", "Kelvin" };
  857. Xdouble fahrenheit, celsius, rankine, kelvin;
  858. Xdouble temp;
  859. Xchar c[2];
  860. Xint    choice, tempagain;
  861. X
  862. X        tempagain = 1;
  863. X
  864. X        while(tempagain) {
  865. X              Clear;
  866. X              printf("                     Unit Selection\n");
  867. X              printf("-------------------------------------------------------------\n");
  868. X                     printf("1. Fahrenheit                    2. Celsius \n");
  869. X                     printf("3. Rankine                       4. Kelvin \n");
  870. X              printf("-------------------------------------------------------------\n");
  871. X
  872. X        printf("Your Temperature Scale? ");
  873. X        getinteger(&choice,3);
  874. X        printf("\n How many degrees %s? ", scale[choice-1]);
  875. X        getnumber(&temp);
  876. X        switch(choice) {
  877. X              case 1 :
  878. X                    fahrenheit = temp;
  879. X                    break;
  880. X              case 2 :
  881. X                    fahrenheit = temp*(9.0/5.0) + 32.0;
  882. X                    break;
  883. X              case 3 :
  884. X                    fahrenheit = temp - 459.67;
  885. X                    break;
  886. X              case 4 :
  887. X                    fahrenheit = ((temp-273.15)*(9.0/5.0)) + 32.0;
  888. X                    break;
  889. X        }
  890. X        celsius = (fahrenheit - 32) * (5.0/9.0);
  891. X        rankine = fahrenheit + 459.67;
  892. X        kelvin  = celsius + 273.15;
  893. X
  894. X        Clear;
  895. X        printf("     %16.8g degrees %s is equivalent to:\n",
  896. X                     temp,scale[choice-1]);
  897. X        printf("                  ------------------------------------\n");
  898. X        if (choice != 1) printf("                  %16.8g degrees Fahrenheit\n", fahrenheit);
  899. X        if (choice != 2) printf("                  %16.8g degrees Celsius\n",    celsius);
  900. X        if (choice != 3) printf("                  %16.8g degrees Rankine\n",    rankine);
  901. X        if (choice != 4) printf("                  %16.8g degrees Kelvin\n",     kelvin);
  902. X
  903. X        printf("                  ------------------------------------\n");
  904. X        printf("\n (R)erun Unit type, (N)ew Unit type, or (Q)uit: ");
  905. X        scanf("%s",c);
  906. X        if ( c[0] == 'Q' || c[0] == 'q' ) {
  907. X           quit_it();
  908. X        } 
  909. X        else if ( c[0] == 'R' || c[0] == 'r' ) {
  910. X           tempagain = 1;
  911. X        } 
  912. X        else if ( c[0] == 'N' || c[0] == 'n' ) {
  913. X           tempagain = 0;
  914. X        } 
  915. X  } /* end while(tempagain) */
  916. X        c[0] = '\0';
  917. X        return;
  918. X}
  919. ________This_Is_The_END________
  920. echo 'x - u.c'
  921. sed 's/^X//' <<'________This_Is_The_END________' >>u.c
  922. X/* un.c -  A Units Conversion Program
  923. X
  924. X   Written 1/17/87 
  925. X   Updated 1/09/89,1/23/89 
  926. X
  927. X*/
  928. X
  929. X/*
  930. X        Copyright 1987,1988,1989 Gregory R. Simpson
  931. X
  932. XUUCP:  uunet!steinmetz!ltd2.decnet!simpsong
  933. XARPA:  simpsong%ltd2.decnet@crd.ge.com
  934. XAT&T:  (216)-381-6789
  935. X
  936. X    This notice and any statement of authorship must be reproduced
  937. X    on all copies.  The author does not make any warranty expressed
  938. X    or implied, or assumes any liability or responsiblity for the
  939. X    use of this software.
  940. X
  941. X    Any distributor of copies of this software shall grant the
  942. X    recipient permission for further redistribution as permitted
  943. X    by this notice.     Any distributor must distribute this software
  944. X    without any fee or other monetary gains, unless expressed written
  945. X    permission is granted by the author.
  946. X
  947. X    This software or its use shall not be: sold, rented, leased,
  948. X    traded, or otherwise marketed without the expressed written
  949. X    permission of the author.
  950. X
  951. X    If the software is modified in a manner creating derivative
  952. X    copyrights, appropriate legends may be placed on derivative
  953. X    work in addition to that set forth above.
  954. X
  955. X    Permission is hereby granted to copy, reproduce, redistribute or
  956. X    otherwise use this software as long as the conditions above
  957. X    are meet.
  958. X
  959. X    All rights not granted by this notice are reserved.
  960. X
  961. X (This copyright notice was written by, Kurt Zeilenga (zeilenga@hc.dspo.gov)
  962. X  thanks Kurt... -greg)
  963. X
  964. X*/
  965. X/* This program is for Unit Conversion... */
  966. X
  967. X#include "un.h"
  968. X
  969. X/*
  970. Xstruct of_units {
  971. X       char  *name;         Name of Unit 
  972. X       double value;        Value - Initially set to 0 
  973. X       double conversion;   Conversion factor to Primary Unit 
  974. X       int   counter;       Number of units in this group 
  975. X} 
  976. X*/
  977. X
  978. X#include "unit_table.h"
  979. X
  980. X/* ------------ main program ------------ */
  981. X
  982. Xmain(argc, argv)
  983. Xint argc;
  984. Xchar *argv[];
  985. X{
  986. X       int   group, user_unit, counter, unit_counter, sameunit;
  987. X       int   comp_unit, ref_unit, chart, screen;
  988. X       double user_value, from_value, to_value, temp_value, value, increment;
  989. X       double primary;
  990. X       char c[10], *cfile, chartfile[100];
  991. X       FILE *fpchart;
  992. X
  993. X       /* default values */
  994. X
  995. X       group      = 1;
  996. X       user_unit  = 1;
  997. X       user_value = 1; 
  998. X
  999. X       sameunit   = 0;  /* New Unit Group */
  1000. X       chart      = 0;  /* Default is standard conversion */
  1001. X
  1002. X       /* check for chart option */
  1003. X
  1004. X       if (argc > 2)   /* usage message if extra command line arguments */
  1005. X       {
  1006. X          usage();
  1007. X       } else if (argc > 1) {
  1008. X          if ( argv[1][0] == '-' ) {
  1009. X             if ( argv[1][1] == 'C' || argv[1][1] == 'c' ) {
  1010. X                chart = 1;
  1011. X             } else {
  1012. X                usage();
  1013. X             }
  1014. X          } else {
  1015. X            usage();
  1016. X          }
  1017. X       }
  1018. X       while(True)        /* loop forever... */
  1019. X       {
  1020. X           if ( sameunit == 0 ) 
  1021. X           {
  1022. X              Clear;
  1023. X              printf("                Unit Group Selection\n");
  1024. X              printf("-------------------------------------------------------------\n");
  1025. X
  1026. X          for (counter = 0; counter <= MAXGROUP; counter = counter+2)
  1027. X              {
  1028. X                     printf("%2d. %-22s                   %2d. %-22s\n",
  1029. X                     (counter + 1), unitype[counter], 
  1030. X                     (counter + 2), unitype[counter + 1]);
  1031. X              }
  1032. X
  1033. X              printf("              Enter 'q' at anytime to (Q)uit\n");
  1034. X              printf("---------------------------------------------------(C)grs----\n");
  1035. X
  1036. X
  1037. X              printf("Which Type of Unit? ");
  1038. X              getinteger(&group, MAXGROUP);
  1039. X              group = group - 1;   /* since array starts at 0 */
  1040. X              
  1041. X              unit_counter = unit[group][1].counter - 1;
  1042. X        
  1043. X           } /* end of sameunit if */
  1044. X
  1045. X              switch (group)
  1046. X              {
  1047. X                 case MAXGROUP-2:
  1048. X                          temperature();
  1049. X                          sameunit = 0;
  1050. X                          break;
  1051. X         case MAXGROUP-1:
  1052. X                          prefix();
  1053. X                          sameunit = 0;
  1054. X                          break;
  1055. X                 case MAXGROUP:
  1056. X                          constants();
  1057. X                          sameunit = 0;
  1058. X                          break;
  1059. X                 default:
  1060. X
  1061. X              Clear;
  1062. X              printf("                     Unit Selection\n");
  1063. X              printf("-------------------------------------------------------------\n");
  1064. X              for (counter = 0; counter <= unit_counter; counter = counter+2)
  1065. X              {
  1066. X                     printf("%2d. %-18s                       %2d. %-18s\n",
  1067. X                     (counter + 1), unit[group][counter].name, 
  1068. X                     (counter + 2), unit[group][counter + 1].name);
  1069. X              }
  1070. X              printf("              Enter 'q' at anytime to (Q)uit\n");
  1071. X              printf("-------------------------------------------------------------\n");
  1072. X
  1073. X/* --------------------   Standard Unit Conversion   ----------------  */
  1074. X
  1075. X              if (chart == 0) {
  1076. X
  1077. X                     printf("Your Unit? ");
  1078. X                     getinteger(&user_unit, unit_counter);
  1079. X                     user_unit = user_unit - 1;
  1080. X
  1081. X                     printf("\nHow many %s ? ", unit[group][user_unit].name );
  1082. X                     getnumber(&user_value, unit_counter);
  1083. X
  1084. X                     Clear;
  1085. X                     printf("\n     ============================================================\n");
  1086. X
  1087. X                     primary=user_value*(1/unit[group][user_unit].conversion);
  1088. X
  1089. X                     printf("     %16.8g %s is equivalent to:\n",
  1090. X                     user_value, unit[group][user_unit].name);
  1091. X                     printf("     ------------------------------------------------------------\n");
  1092. X                     for (counter = unit_counter; counter >= 0; counter--) 
  1093. X                     {
  1094. X                            if (counter != user_unit) 
  1095. X                            {
  1096. X                                   unit[group][counter].value = 
  1097. X                                   primary * unit[group][counter].conversion;
  1098. X                                   printf("                  %16.8g %-18s\n",
  1099. X                                   unit[group][counter].value,
  1100. X                                   unit[group][counter].name);
  1101. X                            }
  1102. X                 }
  1103. X                     printf("     ============================================================\n");
  1104. X                     action(&sameunit, &chart);
  1105. X              } 
  1106. X
  1107. X/* ---------------------  Chart Option   --------------------- */
  1108. X
  1109. X              else {    
  1110. X
  1111. X                     printf("\nYour Reference Unit?  ");
  1112. X                     getinteger(&ref_unit, unit_counter);
  1113. X                     ref_unit = ref_unit - 1;
  1114. X                     printf("Your Comparison Unit? ");
  1115. X                     getinteger(&comp_unit, unit_counter);
  1116. X                     comp_unit = comp_unit - 1;
  1117. X
  1118. X                     printf("\nFrom How Many %s?  ", unit[group][ref_unit].name);
  1119. X                     getnumber(&from_value);
  1120. X                     printf("To How Many %s?    ", unit[group][ref_unit].name);
  1121. X                     getnumber(&to_value);
  1122. X                     printf("By what increment? ");
  1123. X                     getnumber(&increment);
  1124. X
  1125. X                     screen = 0;
  1126. X                     printf("\nFilename for chart? (<CR> for screen): ");
  1127. X                     cfile = gets(chartfile);
  1128. X                     if (cfile[0] == '\0') {
  1129. X                        fpchart = stdout;
  1130. X                        screen  = 1;
  1131. X                     } 
  1132. X                     else if ( ( fpchart = fopen(cfile,"a") ) == NULL ) {
  1133. X                        fprintf(stderr, "Can't open Chartfile.");
  1134. X                        exit(1);
  1135. X                     }                      
  1136. X
  1137. X                     Clear;
  1138. X                     /* ----- Error Checking and Correction... ----- */
  1139. X
  1140. X                     if ( from_value > to_value )
  1141. X                     {
  1142. X                        fprintf(fpchart,
  1143. X                        "Your From value is Greater than your To value.\n");
  1144. X                        fprintf(fpchart,"Therefore, I swapped them.\n");
  1145. X                        temp_value = from_value;
  1146. X                        from_value = to_value;
  1147. X                        to_value   = temp_value;
  1148. X                     }
  1149. X                     if ( increment < 0 )
  1150. X                     {
  1151. X                       fprintf(fpchart,
  1152. X                       "Since your From value is Less than your To value,\n");
  1153. X                       fprintf(fpchart,
  1154. X                       "I will make your increment positive.\n");
  1155. X                       increment = -increment;
  1156. X                     }
  1157. X
  1158. X                     fprintf(fpchart,
  1159. X"------------------------------------------------------------------------------\n");
  1160. X
  1161. X                     for (value = from_value; value <= to_value; 
  1162. X                          value = value + increment) 
  1163. X                         {
  1164. X                           primary=value*(1/unit[group][ref_unit].conversion);
  1165. X                            unit[group][comp_unit].value = 
  1166. X                             primary * unit[group][comp_unit].conversion;
  1167. X                             fprintf(fpchart,
  1168. X                             "| %16.8g %-18s | %16.8g %-18s |\n",
  1169. X                             value,unit[group][ref_unit].name,
  1170. X                             unit[group][comp_unit].value,
  1171. X                             unit[group][comp_unit].name);
  1172. X                             fprintf(fpchart,
  1173. X"------------------------------------------------------------------------------\n");
  1174. X                     }
  1175. X                     if (screen == 0) {
  1176. X                         fclose(fpchart);
  1177. X                     }
  1178. X                     action(&sameunit, &chart);
  1179. X              } /* end of chart if else */
  1180. X          } /* end of switch */
  1181. X       } /* end of while */
  1182. X} /* ---- end of main program ---- */
  1183. ________This_Is_The_END________
  1184. exit
  1185.  
  1186.  
  1187.