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