source: trunk/src/cee/RpUnitsCInterface.cc @ 104

Last change on this file since 104 was 104, checked in by dkearney, 19 years ago

This update brings us one step closer to being const correct in the RpUnits
class. Added a few more comments. All other files touched were made to
comply with the new const correct RpUnits.[h,cc]

File size: 3.0 KB
Line 
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
16extern "C" {
17#endif
18
19const RpUnits*
20rpDefineUnit(const char* unitSymbol, const RpUnits* basis) {
21
22    return RpUnits::define(unitSymbol, basis);
23}
24
25const RpUnits*
26rpDefineConv(  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
34const RpUnits*
35rpFind ( const char* key ) {
36
37    return RpUnits::find(key);
38}
39
40const char*
41rpGetUnits ( const RpUnits* unit ) {
42
43    static std::string retVal;
44    retVal = unit->getUnits();
45    return retVal.c_str();
46}
47
48const char*
49rpGetUnitsName ( const RpUnits* unit ) {
50
51    static std::string retVal;
52    retVal = unit->getUnitsName();
53    return retVal.c_str();
54}
55
56double
57rpGetExponent ( const RpUnits* unit ) {
58
59    return unit->getExponent();
60}
61
62const RpUnits*
63rpGetBasis ( const RpUnits* unit ) {
64
65    return unit->getBasis();
66}
67
68int
69rpMakeMetric(const RpUnits* basis) {
70
71    return RpUnits::makeMetric(basis);
72}
73
74const char*
75rpConvert (   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
85const char*
86rpConvertStr (   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
96const char*
97rpConvert_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
108double
109rpConvertDbl (    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
125double
126rpConvert_ObjDbl (   const RpUnits* fromUnits,
127                     const RpUnits* toUnits,
128                     double val,
129                     int* result ) {
130
131    return fromUnits->convert(toUnits,val,result);
132}
133
134int rpAddPresets ( const char* presetName ) {
135
136    return RpUnits::addPresets(presetName);
137}
138
139#ifdef __cplusplus
140}
141#endif
Note: See TracBrowser for help on using the repository browser.