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 | #ifdef __cplusplus |
---|
18 | extern "C" { |
---|
19 | #endif |
---|
20 | |
---|
21 | const RpUnits* |
---|
22 | rpDefineUnit(const char* unitSymbol, const RpUnits* basis) { |
---|
23 | |
---|
24 | return RpUnits::define(unitSymbol, basis); |
---|
25 | } |
---|
26 | |
---|
27 | const RpUnits* |
---|
28 | rpDefineConv( const RpUnits* fromUnit, |
---|
29 | const RpUnits* toUnit, |
---|
30 | double (*convForwFxnPtr)(double), |
---|
31 | double (*convBackFxnPtr)(double) ) { |
---|
32 | |
---|
33 | return RpUnits::define(fromUnit,toUnit,convForwFxnPtr,convBackFxnPtr); |
---|
34 | } |
---|
35 | |
---|
36 | const RpUnits* |
---|
37 | rpFind ( const char* key ) { |
---|
38 | |
---|
39 | return RpUnits::find(key); |
---|
40 | } |
---|
41 | |
---|
42 | const char* |
---|
43 | rpGetUnits ( const RpUnits* unit ) { |
---|
44 | |
---|
45 | static std::string retVal; |
---|
46 | retVal = unit->getUnits(); |
---|
47 | return retVal.c_str(); |
---|
48 | } |
---|
49 | |
---|
50 | const char* |
---|
51 | rpGetUnitsName ( const RpUnits* unit ) { |
---|
52 | |
---|
53 | static std::string retVal; |
---|
54 | retVal = unit->getUnitsName(); |
---|
55 | return retVal.c_str(); |
---|
56 | } |
---|
57 | |
---|
58 | double |
---|
59 | rpGetExponent ( const RpUnits* unit ) { |
---|
60 | |
---|
61 | return unit->getExponent(); |
---|
62 | } |
---|
63 | |
---|
64 | const RpUnits* |
---|
65 | rpGetBasis ( const RpUnits* unit ) { |
---|
66 | |
---|
67 | return unit->getBasis(); |
---|
68 | } |
---|
69 | |
---|
70 | int |
---|
71 | rpMakeMetric(const RpUnits* basis) { |
---|
72 | |
---|
73 | return RpUnits::makeMetric(basis); |
---|
74 | } |
---|
75 | |
---|
76 | const char* |
---|
77 | rpConvert ( const char* fromVal, |
---|
78 | const char* toUnitsName, |
---|
79 | int showUnits, |
---|
80 | int* result ) { |
---|
81 | |
---|
82 | static std::string retVal; |
---|
83 | retVal = RpUnits::convert(fromVal,toUnitsName,showUnits,result); |
---|
84 | return retVal.c_str(); |
---|
85 | } |
---|
86 | |
---|
87 | const char* |
---|
88 | rpConvertStr ( const char* fromVal, |
---|
89 | const char* toUnitsName, |
---|
90 | int showUnits, |
---|
91 | int* result ) { |
---|
92 | |
---|
93 | static std::string retVal; |
---|
94 | retVal = RpUnits::convert(fromVal,toUnitsName,showUnits,result); |
---|
95 | return retVal.c_str(); |
---|
96 | } |
---|
97 | |
---|
98 | const char* |
---|
99 | rpConvert_ObjStr ( const RpUnits* fromUnits, |
---|
100 | const RpUnits* toUnits, |
---|
101 | double val, |
---|
102 | int showUnits, |
---|
103 | int* result ) { |
---|
104 | |
---|
105 | static std::string retVal; |
---|
106 | retVal = fromUnits->convert(toUnits,val,showUnits,result); |
---|
107 | return retVal.c_str(); |
---|
108 | } |
---|
109 | |
---|
110 | double |
---|
111 | rpConvertDbl ( const char* fromVal, |
---|
112 | const char* toUnitsName, |
---|
113 | int* result ) { |
---|
114 | |
---|
115 | std::string convStr; |
---|
116 | double retVal = 0.0; |
---|
117 | |
---|
118 | convStr = RpUnits::convert(fromVal,toUnitsName,0,result); |
---|
119 | |
---|
120 | if (!convStr.empty()) { |
---|
121 | retVal = atof(convStr.c_str()); |
---|
122 | } |
---|
123 | |
---|
124 | return retVal; |
---|
125 | } |
---|
126 | |
---|
127 | double |
---|
128 | rpConvert_ObjDbl ( const RpUnits* fromUnits, |
---|
129 | const RpUnits* toUnits, |
---|
130 | double val, |
---|
131 | int* result ) { |
---|
132 | |
---|
133 | return fromUnits->convert(toUnits,val,result); |
---|
134 | } |
---|
135 | |
---|
136 | int rpAddPresets ( const char* presetName ) { |
---|
137 | |
---|
138 | return RpUnits::addPresets(presetName); |
---|
139 | } |
---|
140 | |
---|
141 | #ifdef __cplusplus |
---|
142 | } |
---|
143 | #endif |
---|