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