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

Last change on this file since 232 was 115, checked in by mmc, 19 years ago

Updated all copyright notices.

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