source: branches/1.3/src/core/RpUnitsStd.cc @ 5734

Last change on this file since 5734 was 5675, checked in by ldelgass, 9 years ago

merge r5673 from trunk (eol-style)

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