source: branches/1.7/src/core/RpUnitsCInterface.cc @ 6716

Last change on this file since 6716 was 5679, checked in by ldelgass, 9 years ago

Full merge 1.3 branch to uq branch to sync. Fixed partial subdirectory merge
by removing mergeinfo from lang/python/Rappture directory.

  • Property svn:eol-style set to native
File size: 3.4 KB
Line 
1/*
2 * ----------------------------------------------------------------------
3 *  INTERFACE: C Rappture Units Source
4 *
5 * ======================================================================
6 *  AUTHOR:  Derrick Kearney, Purdue University
7 *  Copyright (c) 2004-2012  HUBzero Foundation, LLC
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
17const RpUnits*
18rpDefineUnit(const char* unitSymbol, const RpUnits* basis) {
19
20    return RpUnits::define(unitSymbol, basis);
21}
22
23const RpUnits*
24rpDefineConv(  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
32const RpUnits*
33rpFind ( const char* key ) {
34
35    return RpUnits::find(key);
36}
37
38const char*
39rpGetUnits ( const RpUnits* unit ) {
40
41    static std::string retVal;
42    retVal = unit->getUnits();
43    return retVal.c_str();
44}
45
46const char*
47rpGetUnitsName ( const RpUnits* unit ) {
48
49    static std::string retVal;
50    retVal = unit->getUnitsName();
51    return retVal.c_str();
52}
53
54double
55rpGetExponent ( const RpUnits* unit ) {
56
57    return unit->getExponent();
58}
59
60const RpUnits*
61rpGetBasis ( const RpUnits* unit ) {
62
63    return unit->getBasis();
64}
65
66const char*
67rpConvert (   const char* fromVal,
68               const char* toUnitsName,
69               int showUnits,
70               int* result ) {
71
72    static std::string retVal;
73    const char *empty = "";
74
75    if (fromVal == NULL) {
76        return retVal.c_str();
77    }
78
79    if (toUnitsName == NULL) {
80        toUnitsName = empty;
81    }
82
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    const char *empty = "";
95
96    if (fromVal == NULL) {
97        return retVal.c_str();
98    }
99
100    if (toUnitsName == NULL) {
101        toUnitsName = empty;
102    }
103
104    retVal = RpUnits::convert(fromVal,toUnitsName,showUnits,result);
105    return retVal.c_str();
106}
107
108const char*
109rpConvert_ObjStr ( const RpUnits* fromUnits,
110                   const RpUnits* toUnits,
111                   double val,
112                   int showUnits,
113                   int* result ) {
114
115    static std::string retVal;
116    retVal = fromUnits->convert(toUnits,val,showUnits,result);
117    return retVal.c_str();
118}
119
120double
121rpConvertDbl (    const char* fromVal,
122                  const char* toUnitsName,
123                  int* result ) {
124
125    std::string convStr;
126    double retVal = 0.0;
127    const char *empty = "";
128
129    if (fromVal == NULL) {
130        return retVal;
131    }
132
133    if (toUnitsName == NULL) {
134        toUnitsName = empty;
135    }
136
137    convStr = RpUnits::convert(fromVal,toUnitsName,0,result);
138
139    if (!convStr.empty()) {
140        retVal = atof(convStr.c_str());
141    }
142
143    return retVal;
144}
145
146double
147rpConvert_ObjDbl (   const RpUnits* fromUnits,
148                     const RpUnits* toUnits,
149                     double val,
150                     int* result ) {
151
152    return fromUnits->convert(toUnits,val,result);
153}
154
155int rpAddPresets ( const char* presetName ) {
156
157    return RpUnits::addPresets(presetName);
158}
159
Note: See TracBrowser for help on using the repository browser.