1 | /* |
---|
2 | * ---------------------------------------------------------------------- |
---|
3 | * INTERFACE: C Rappture Units Source |
---|
4 | * |
---|
5 | * ====================================================================== |
---|
6 | * AUTHOR: Derrick Kearney, Purdue University |
---|
7 | * Copyright (c) 2004-2005 Purdue Research Foundation |
---|
8 | * |
---|
9 | * See the file "license.terms" for information on usage and |
---|
10 | * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
11 | * ====================================================================== |
---|
12 | */ |
---|
13 | |
---|
14 | #include "RpUnits.h" |
---|
15 | #include "RpUnitsCInterface.h" |
---|
16 | |
---|
17 | const RpUnits* |
---|
18 | rpDefineUnit(const char* unitSymbol, const RpUnits* basis) { |
---|
19 | |
---|
20 | return RpUnits::define(unitSymbol, basis); |
---|
21 | } |
---|
22 | |
---|
23 | const RpUnits* |
---|
24 | rpDefineConv( const RpUnits* fromUnit, |
---|
25 | const RpUnits* toUnit, |
---|
26 | double (*convForwFxnPtr)(double), |
---|
27 | double (*convBackFxnPtr)(double) ) { |
---|
28 | |
---|
29 | return RpUnits::define(fromUnit,toUnit,convForwFxnPtr,convBackFxnPtr); |
---|
30 | } |
---|
31 | |
---|
32 | const RpUnits* |
---|
33 | rpFind ( const char* key ) { |
---|
34 | |
---|
35 | return RpUnits::find(key); |
---|
36 | } |
---|
37 | |
---|
38 | const char* |
---|
39 | rpGetUnits ( const RpUnits* unit ) { |
---|
40 | |
---|
41 | static std::string retVal; |
---|
42 | retVal = unit->getUnits(); |
---|
43 | return retVal.c_str(); |
---|
44 | } |
---|
45 | |
---|
46 | const char* |
---|
47 | rpGetUnitsName ( const RpUnits* unit ) { |
---|
48 | |
---|
49 | static std::string retVal; |
---|
50 | retVal = unit->getUnitsName(); |
---|
51 | return retVal.c_str(); |
---|
52 | } |
---|
53 | |
---|
54 | double |
---|
55 | rpGetExponent ( const RpUnits* unit ) { |
---|
56 | |
---|
57 | return unit->getExponent(); |
---|
58 | } |
---|
59 | |
---|
60 | const RpUnits* |
---|
61 | rpGetBasis ( const RpUnits* unit ) { |
---|
62 | |
---|
63 | return unit->getBasis(); |
---|
64 | } |
---|
65 | |
---|
66 | const char* |
---|
67 | rpConvert ( const char* fromVal, |
---|
68 | const char* toUnitsName, |
---|
69 | int showUnits, |
---|
70 | int* result ) { |
---|
71 | |
---|
72 | static std::string retVal; |
---|
73 | retVal = RpUnits::convert(fromVal,toUnitsName,showUnits,result); |
---|
74 | return retVal.c_str(); |
---|
75 | } |
---|
76 | |
---|
77 | const char* |
---|
78 | rpConvertStr ( const char* fromVal, |
---|
79 | const char* toUnitsName, |
---|
80 | int showUnits, |
---|
81 | int* result ) { |
---|
82 | |
---|
83 | static std::string retVal; |
---|
84 | retVal = RpUnits::convert(fromVal,toUnitsName,showUnits,result); |
---|
85 | return retVal.c_str(); |
---|
86 | } |
---|
87 | |
---|
88 | const char* |
---|
89 | rpConvert_ObjStr ( const RpUnits* fromUnits, |
---|
90 | const RpUnits* toUnits, |
---|
91 | double val, |
---|
92 | int showUnits, |
---|
93 | int* result ) { |
---|
94 | |
---|
95 | static std::string retVal; |
---|
96 | retVal = fromUnits->convert(toUnits,val,showUnits,result); |
---|
97 | return retVal.c_str(); |
---|
98 | } |
---|
99 | |
---|
100 | double |
---|
101 | rpConvertDbl ( const char* fromVal, |
---|
102 | const char* toUnitsName, |
---|
103 | int* result ) { |
---|
104 | |
---|
105 | std::string convStr; |
---|
106 | double retVal = 0.0; |
---|
107 | |
---|
108 | convStr = RpUnits::convert(fromVal,toUnitsName,0,result); |
---|
109 | |
---|
110 | if (!convStr.empty()) { |
---|
111 | retVal = atof(convStr.c_str()); |
---|
112 | } |
---|
113 | |
---|
114 | return retVal; |
---|
115 | } |
---|
116 | |
---|
117 | double |
---|
118 | rpConvert_ObjDbl ( const RpUnits* fromUnits, |
---|
119 | const RpUnits* toUnits, |
---|
120 | double val, |
---|
121 | int* result ) { |
---|
122 | |
---|
123 | return fromUnits->convert(toUnits,val,result); |
---|
124 | } |
---|
125 | |
---|
126 | int rpAddPresets ( const char* presetName ) { |
---|
127 | |
---|
128 | return RpUnits::addPresets(presetName); |
---|
129 | } |
---|
130 | |
---|