home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume7 / un < prev    next >
Text File  |  1989-06-03  |  45KB  |  1,178 lines

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