1 | /* |
---|
2 | * ====================================================================== |
---|
3 | * Copyright (c) 2004-2012 HUBzero Foundation, LLC |
---|
4 | * |
---|
5 | * See the file "license.terms" for information on usage and |
---|
6 | * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
7 | * ====================================================================== |
---|
8 | */ |
---|
9 | #include <RpUnitsStd.h> |
---|
10 | #include <math.h> |
---|
11 | |
---|
12 | double invert (double inVal) |
---|
13 | { |
---|
14 | return (1.0/inVal); |
---|
15 | } |
---|
16 | |
---|
17 | /**************************************** |
---|
18 | * METRIC CONVERSIONS |
---|
19 | ****************************************/ |
---|
20 | |
---|
21 | double deci2base (double deci) |
---|
22 | { |
---|
23 | return deci*1e-1; |
---|
24 | } |
---|
25 | |
---|
26 | double centi2base (double centi) |
---|
27 | { |
---|
28 | return centi*1e-2; |
---|
29 | } |
---|
30 | |
---|
31 | double milli2base (double milli) |
---|
32 | { |
---|
33 | return milli*1e-3; |
---|
34 | } |
---|
35 | |
---|
36 | double micro2base (double micro) |
---|
37 | { |
---|
38 | return micro*1e-6; |
---|
39 | } |
---|
40 | |
---|
41 | double nano2base (double nano) |
---|
42 | { |
---|
43 | return nano*1e-9; |
---|
44 | } |
---|
45 | |
---|
46 | double pico2base (double pico) |
---|
47 | { |
---|
48 | return pico*1e-12; |
---|
49 | } |
---|
50 | |
---|
51 | double femto2base (double femto) |
---|
52 | { |
---|
53 | return femto*1e-15; |
---|
54 | } |
---|
55 | |
---|
56 | double atto2base (double atto) |
---|
57 | { |
---|
58 | return atto*1e-18; |
---|
59 | } |
---|
60 | |
---|
61 | double deca2base (double deca) |
---|
62 | { |
---|
63 | return deca*1e1; |
---|
64 | } |
---|
65 | |
---|
66 | double hecto2base (double hecto) |
---|
67 | { |
---|
68 | return hecto*1e2; |
---|
69 | } |
---|
70 | |
---|
71 | double kilo2base (double kilo) |
---|
72 | { |
---|
73 | return kilo*1e3; |
---|
74 | } |
---|
75 | |
---|
76 | double mega2base (double mega) |
---|
77 | { |
---|
78 | return mega*1e6; |
---|
79 | } |
---|
80 | |
---|
81 | double giga2base (double giga) |
---|
82 | { |
---|
83 | return giga*1e9; |
---|
84 | } |
---|
85 | |
---|
86 | double tera2base (double tera) |
---|
87 | { |
---|
88 | return tera*1e12; |
---|
89 | } |
---|
90 | |
---|
91 | double peta2base (double peta) |
---|
92 | { |
---|
93 | return peta*1e15; |
---|
94 | } |
---|
95 | |
---|
96 | double exa2base (double exa) |
---|
97 | { |
---|
98 | return exa*1e18; |
---|
99 | } |
---|
100 | |
---|
101 | double base2deci (double base) |
---|
102 | { |
---|
103 | return base*1e1; |
---|
104 | } |
---|
105 | |
---|
106 | double base2centi (double base) |
---|
107 | { |
---|
108 | return base*1e2; |
---|
109 | } |
---|
110 | |
---|
111 | double base2milli (double base) |
---|
112 | { |
---|
113 | return base*1e3; |
---|
114 | } |
---|
115 | |
---|
116 | double base2micro (double base) |
---|
117 | { |
---|
118 | return base*1e6; |
---|
119 | } |
---|
120 | |
---|
121 | double base2nano (double base) |
---|
122 | { |
---|
123 | return base*1e9; |
---|
124 | } |
---|
125 | |
---|
126 | double base2pico (double base) |
---|
127 | { |
---|
128 | return base*1e12; |
---|
129 | } |
---|
130 | |
---|
131 | double base2femto (double base) |
---|
132 | { |
---|
133 | return base*1e15; |
---|
134 | } |
---|
135 | |
---|
136 | double base2atto (double base) |
---|
137 | { |
---|
138 | return base*1e18; |
---|
139 | } |
---|
140 | |
---|
141 | double base2deca (double base) |
---|
142 | { |
---|
143 | return base*1e-1; |
---|
144 | } |
---|
145 | |
---|
146 | double base2hecto (double base) |
---|
147 | { |
---|
148 | return base*1e-2; |
---|
149 | } |
---|
150 | |
---|
151 | double base2kilo (double base) |
---|
152 | { |
---|
153 | return base*1e-3; |
---|
154 | } |
---|
155 | |
---|
156 | double base2mega (double base) |
---|
157 | { |
---|
158 | return base*1e-6; |
---|
159 | } |
---|
160 | |
---|
161 | double base2giga (double base) |
---|
162 | { |
---|
163 | return base*1e-9; |
---|
164 | } |
---|
165 | |
---|
166 | double base2tera (double base) |
---|
167 | { |
---|
168 | return base*1e-12; |
---|
169 | } |
---|
170 | |
---|
171 | double base2peta (double base) |
---|
172 | { |
---|
173 | return base*1e-15; |
---|
174 | } |
---|
175 | |
---|
176 | double base2exa (double base) |
---|
177 | { |
---|
178 | return base*1e-18; |
---|
179 | } |
---|
180 | |
---|
181 | /**************************************** |
---|
182 | * METRIC TO NON-METRIC CONVERSIONS |
---|
183 | * LENGTH CONVERSIONS |
---|
184 | * http://www.nodc.noaa.gov/dsdt/ucg/ |
---|
185 | ****************************************/ |
---|
186 | |
---|
187 | double angstrom2meter (double angstrom) |
---|
188 | { |
---|
189 | return angstrom*(1.0e-10); |
---|
190 | } |
---|
191 | |
---|
192 | double meter2angstrom (double meter) |
---|
193 | { |
---|
194 | return meter*(1.0e10); |
---|
195 | } |
---|
196 | |
---|
197 | double bohr2meter (double bohr) |
---|
198 | { |
---|
199 | return bohr*(52.9177e-12); |
---|
200 | } |
---|
201 | |
---|
202 | double meter2bohr (double meter) |
---|
203 | { |
---|
204 | return meter*(52.9177e12); |
---|
205 | } |
---|
206 | |
---|
207 | double meter2inch (double meter) |
---|
208 | { |
---|
209 | return meter*(39.37008); |
---|
210 | } |
---|
211 | |
---|
212 | double inch2meter (double inch) |
---|
213 | { |
---|
214 | return (inch/(39.37008)); |
---|
215 | } |
---|
216 | |
---|
217 | double inch2feet (double inch) |
---|
218 | { |
---|
219 | return (inch/(12.00)); |
---|
220 | } |
---|
221 | |
---|
222 | double feet2inch (double ft) |
---|
223 | { |
---|
224 | return (ft*(12.00)); |
---|
225 | } |
---|
226 | |
---|
227 | double inch2yard (double inch) |
---|
228 | { |
---|
229 | return (inch/(36.00)); |
---|
230 | } |
---|
231 | |
---|
232 | double yard2inch (double yd) |
---|
233 | { |
---|
234 | return (yd*(36.00)); |
---|
235 | } |
---|
236 | |
---|
237 | double inch2mile (double inch) |
---|
238 | { |
---|
239 | return (inch/(63360)); |
---|
240 | } |
---|
241 | |
---|
242 | double mile2inch (double mi) |
---|
243 | { |
---|
244 | return (mi*(63360)); |
---|
245 | } |
---|
246 | |
---|
247 | /**************************************** |
---|
248 | * TEMPERATURE CONVERSIONS |
---|
249 | ****************************************/ |
---|
250 | |
---|
251 | double fahrenheit2centigrade (double F) |
---|
252 | { |
---|
253 | return ((F-32.0)/(9.0/5.0)); |
---|
254 | } |
---|
255 | |
---|
256 | double centigrade2fahrenheit (double C) |
---|
257 | { |
---|
258 | return ((C*(9.0/5.0))+32.0); |
---|
259 | } |
---|
260 | |
---|
261 | double centigrade2kelvin (double C) |
---|
262 | { |
---|
263 | return (C+273.15); |
---|
264 | } |
---|
265 | |
---|
266 | double kelvin2centigrade (double K) |
---|
267 | { |
---|
268 | return (K-273.15); |
---|
269 | } |
---|
270 | |
---|
271 | double rankine2kelvin (double R) |
---|
272 | { |
---|
273 | return ((5.0/9.0)*R); |
---|
274 | } |
---|
275 | |
---|
276 | double kelvin2rankine (double K) |
---|
277 | { |
---|
278 | return ((9.0/5.0)*K); |
---|
279 | } |
---|
280 | |
---|
281 | double fahrenheit2kelvin (double F) |
---|
282 | { |
---|
283 | return ((F+459.67)*(5.0/9.0)); |
---|
284 | } |
---|
285 | |
---|
286 | double kelvin2fahrenheit (double K) |
---|
287 | { |
---|
288 | return (((9.0/5.0)*K)-459.67); |
---|
289 | } |
---|
290 | |
---|
291 | double fahrenheit2rankine (double F) |
---|
292 | { |
---|
293 | return (F+459.67); |
---|
294 | } |
---|
295 | |
---|
296 | double rankine2fahrenheit (double R) |
---|
297 | { |
---|
298 | return (R-459.67); |
---|
299 | } |
---|
300 | |
---|
301 | double rankine2celcius (double R) |
---|
302 | { |
---|
303 | return ((R*(5.0/9.0))-273.15); |
---|
304 | } |
---|
305 | |
---|
306 | double celcius2rankine (double C) |
---|
307 | { |
---|
308 | return ((C + 273.15)*(9.0/5.0)); |
---|
309 | } |
---|
310 | |
---|
311 | /**************************************** |
---|
312 | * ENERGY CONVERSIONS |
---|
313 | ****************************************/ |
---|
314 | |
---|
315 | double electronVolt2joule (double eV) |
---|
316 | { |
---|
317 | return (eV*1.602177e-19); |
---|
318 | } |
---|
319 | |
---|
320 | double joule2electronVolt (double J) |
---|
321 | { |
---|
322 | return (J/1.602177e-19); |
---|
323 | } |
---|
324 | |
---|
325 | /**************************************** |
---|
326 | * MISC VOLUME CONVERSIONS |
---|
327 | ****************************************/ |
---|
328 | |
---|
329 | double cubicMeter2usGallon (double m3) |
---|
330 | { |
---|
331 | return (m3*264.1721); |
---|
332 | } |
---|
333 | |
---|
334 | double usGallon2cubicMeter (double gal) |
---|
335 | { |
---|
336 | return (gal/264.1721); |
---|
337 | } |
---|
338 | |
---|
339 | double cubicFeet2usGallon (double ft3) |
---|
340 | { |
---|
341 | return (ft3*7.48051); |
---|
342 | } |
---|
343 | |
---|
344 | double usGallon2cubicFeet (double gal) |
---|
345 | { |
---|
346 | return (gal/7.48051); |
---|
347 | } |
---|
348 | |
---|
349 | double cubicMeter2liter (double m3) |
---|
350 | { |
---|
351 | return (m3*1e3); |
---|
352 | } |
---|
353 | |
---|
354 | double liter2cubicMeter (double L) |
---|
355 | { |
---|
356 | return (L*1e-3); |
---|
357 | } |
---|
358 | |
---|
359 | /**************************************** |
---|
360 | * ANGLE CONVERSIONS |
---|
361 | * http://www.metrication.com/ |
---|
362 | ****************************************/ |
---|
363 | |
---|
364 | double rad2deg (double rad) |
---|
365 | { |
---|
366 | return (rad*(180.00/M_PI)); |
---|
367 | } |
---|
368 | |
---|
369 | double deg2rad (double deg) |
---|
370 | { |
---|
371 | return (deg*(M_PI/180.00)); |
---|
372 | } |
---|
373 | |
---|
374 | double rad2grad (double rad) |
---|
375 | { |
---|
376 | return (rad*(200.00/M_PI)); |
---|
377 | } |
---|
378 | |
---|
379 | double grad2rad (double grad) |
---|
380 | { |
---|
381 | return (grad*(M_PI/200.00)); |
---|
382 | } |
---|
383 | |
---|
384 | double deg2grad (double deg) |
---|
385 | { |
---|
386 | return (deg*(10.00/9.00)); |
---|
387 | } |
---|
388 | |
---|
389 | double grad2deg (double grad) |
---|
390 | { |
---|
391 | return (grad*(9.00/10.00)); |
---|
392 | } |
---|
393 | |
---|
394 | /**************************************** |
---|
395 | * TIME CONVERSIONS |
---|
396 | ****************************************/ |
---|
397 | |
---|
398 | double sec2min (double sec) |
---|
399 | { |
---|
400 | return (sec/60.00); |
---|
401 | } |
---|
402 | |
---|
403 | double min2sec (double min) |
---|
404 | { |
---|
405 | return (min*60.00); |
---|
406 | } |
---|
407 | |
---|
408 | double sec2hour (double sec) |
---|
409 | { |
---|
410 | return (sec/3600.00); |
---|
411 | } |
---|
412 | |
---|
413 | double hour2sec (double hour) |
---|
414 | { |
---|
415 | return (hour*3600.00); |
---|
416 | } |
---|
417 | |
---|
418 | double sec2day (double sec) |
---|
419 | { |
---|
420 | return (sec/86400.00); |
---|
421 | } |
---|
422 | |
---|
423 | double day2sec (double day) |
---|
424 | { |
---|
425 | return (day*86400.00); |
---|
426 | } |
---|
427 | |
---|
428 | /**************************************** |
---|
429 | * PRESSURE CONVERSIONS |
---|
430 | * http://www.ilpi.com/msds/ref/pressureunits.html |
---|
431 | * http://en.wikipedia.org/wiki/Bar_%28unit%29 |
---|
432 | ****************************************/ |
---|
433 | |
---|
434 | double bar2Pa (double bar) |
---|
435 | { |
---|
436 | return (bar*100000.00); |
---|
437 | } |
---|
438 | |
---|
439 | double Pa2bar (double Pa) |
---|
440 | { |
---|
441 | return (Pa/100000.00); |
---|
442 | } |
---|
443 | |
---|
444 | double bar2atm (double bar) |
---|
445 | { |
---|
446 | return (bar*0.98692); |
---|
447 | } |
---|
448 | |
---|
449 | double atm2bar (double atm) |
---|
450 | { |
---|
451 | return (atm/0.98692); |
---|
452 | } |
---|
453 | |
---|
454 | double bar2torr (double bar) |
---|
455 | { |
---|
456 | return (bar*750.06); |
---|
457 | } |
---|
458 | |
---|
459 | double torr2bar (double torr) |
---|
460 | { |
---|
461 | return (torr/750.06); |
---|
462 | } |
---|
463 | |
---|
464 | double bar2psi (double bar) |
---|
465 | { |
---|
466 | return (bar*14.504); |
---|
467 | } |
---|
468 | |
---|
469 | double psi2bar (double psi) |
---|
470 | { |
---|
471 | return (psi*0.0689476); |
---|
472 | } |
---|
473 | |
---|
474 | double Pa2atm (double Pa) |
---|
475 | { |
---|
476 | return (Pa*9.8692e-6); |
---|
477 | } |
---|
478 | |
---|
479 | double atm2Pa (double atm) |
---|
480 | { |
---|
481 | // need to check this conversion |
---|
482 | // tests fail |
---|
483 | return (atm*101325.024); |
---|
484 | } |
---|
485 | |
---|
486 | double Pa2torr (double Pa) |
---|
487 | { |
---|
488 | return (Pa*7.5006e-3); |
---|
489 | } |
---|
490 | |
---|
491 | double torr2Pa (double torr) |
---|
492 | { |
---|
493 | return (torr/7.5006e-3); |
---|
494 | } |
---|
495 | |
---|
496 | double Pa2psi (double Pa) |
---|
497 | { |
---|
498 | return (Pa*145.04e-6); |
---|
499 | } |
---|
500 | |
---|
501 | double psi2Pa (double psi) |
---|
502 | { |
---|
503 | // need to check this conversion |
---|
504 | // test fails because of truncation |
---|
505 | return (psi*6894.7625831); |
---|
506 | } |
---|
507 | |
---|
508 | double torr2atm (double torr) |
---|
509 | { |
---|
510 | return (torr*1.3158e-3); |
---|
511 | } |
---|
512 | |
---|
513 | double atm2torr (double atm) |
---|
514 | { |
---|
515 | return (atm*760); |
---|
516 | } |
---|
517 | |
---|
518 | double torr2psi (double torr) |
---|
519 | { |
---|
520 | return (torr*19.337e-3); |
---|
521 | } |
---|
522 | |
---|
523 | double psi2torr (double psi) |
---|
524 | { |
---|
525 | return (psi*51.71496); |
---|
526 | } |
---|
527 | |
---|
528 | double torr2mmHg (double torr) |
---|
529 | { |
---|
530 | return (torr); |
---|
531 | } |
---|
532 | |
---|
533 | double mmHg2torr (double mmHg) |
---|
534 | { |
---|
535 | return (mmHg); |
---|
536 | } |
---|
537 | |
---|
538 | double psi2atm (double psi) |
---|
539 | { |
---|
540 | return (psi*68.046e-3); |
---|
541 | } |
---|
542 | |
---|
543 | double atm2psi (double atm) |
---|
544 | { |
---|
545 | return (atm*14.696); |
---|
546 | } |
---|
547 | |
---|
548 | /**************************************** |
---|
549 | * CONCENTRATION CONVERSIONS |
---|
550 | * http://en.wikipedia.org/wiki/PH |
---|
551 | ****************************************/ |
---|
552 | |
---|
553 | double pH2pOH (double pH) |
---|
554 | { |
---|
555 | // This formula is valid exactly for |
---|
556 | // temperature = 298.15 K (25 °C) only, |
---|
557 | // but is acceptable for most lab calculations |
---|
558 | return (14.00 - pH); |
---|
559 | } |
---|
560 | |
---|
561 | double pOH2pH (double pOH) |
---|
562 | { |
---|
563 | // This formula is valid exactly for |
---|
564 | // temperature = 298.15 K (25 °C) only, |
---|
565 | // but is acceptable for most lab calculations |
---|
566 | return (14.00 - pOH); |
---|
567 | } |
---|
568 | |
---|
569 | /**************************************** |
---|
570 | * MAGNETIC CONVERSIONS |
---|
571 | * http://en.wikipedia.org/wiki/Tesla_(unit) |
---|
572 | * http://en.wikipedia.org/wiki/Gauss_(unit) |
---|
573 | * http://en.wikipedia.org/wiki/Maxwell_(unit) |
---|
574 | * http://en.wikipedia.org/wiki/Weber_(unit) |
---|
575 | ****************************************/ |
---|
576 | |
---|
577 | double tesla2gauss (double tesla) |
---|
578 | { |
---|
579 | return (tesla*1e4); |
---|
580 | } |
---|
581 | |
---|
582 | double gauss2tesla (double gauss) |
---|
583 | { |
---|
584 | return (gauss*1e-4); |
---|
585 | } |
---|
586 | |
---|
587 | double maxwell2weber (double maxwell) |
---|
588 | { |
---|
589 | return (maxwell*1e-8); |
---|
590 | } |
---|
591 | |
---|
592 | double weber2maxwell (double weber) |
---|
593 | { |
---|
594 | return (weber*1e8); |
---|
595 | } |
---|
596 | |
---|