source: trunk/src/core/RpUnitsCInterface.cc @ 1030

Last change on this file since 1030 was 1018, checked in by gah, 16 years ago

Massive changes: New directory/file layout

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) 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
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    retVal = RpUnits::convert(fromVal,toUnitsName,showUnits,result);
74    return retVal.c_str();
75}
76
77const char*
78rpConvertStr (   const char* fromVal,
79                  const char* toUnitsName,
80                  int showUnits,
81                  int* result ) {
82
83    static std::string retVal;
84    retVal = RpUnits::convert(fromVal,toUnitsName,showUnits,result);
85    return retVal.c_str();
86}
87
88const char*
89rpConvert_ObjStr ( const RpUnits* fromUnits,
90                   const RpUnits* toUnits,
91                   double val,
92                   int showUnits,
93                   int* result ) {
94
95    static std::string retVal;
96    retVal = fromUnits->convert(toUnits,val,showUnits,result);
97    return retVal.c_str();
98}
99
100double
101rpConvertDbl (    const char* fromVal,
102                  const char* toUnitsName,
103                  int* result ) {
104
105    std::string convStr;
106    double retVal = 0.0;
107
108    convStr = RpUnits::convert(fromVal,toUnitsName,0,result);
109
110    if (!convStr.empty()) {
111        retVal = atof(convStr.c_str());
112    }
113
114    return retVal;
115}
116
117double
118rpConvert_ObjDbl (   const RpUnits* fromUnits,
119                     const RpUnits* toUnits,
120                     double val,
121                     int* result ) {
122
123    return fromUnits->convert(toUnits,val,result);
124}
125
126int rpAddPresets ( const char* presetName ) {
127
128    return RpUnits::addPresets(presetName);
129}
130
Note: See TracBrowser for help on using the repository browser.