Changeset 104
- Timestamp:
- Oct 14, 2005 9:43:27 AM (19 years ago)
- Location:
- trunk
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/examples/c-example/Makefile
r92 r104 18 18 INCL_RP_DEPS = -I $(RP_BASE)/include 19 19 20 INCL_FILES = $(INCL_CEE) $(INCL_CORE) $(INCL_RP_DEPS) 21 20 22 LIB_DIR = $(RP_BASE)/lib 21 23 LIB_INC_PREFIX = -Wl,-rpath,$(LIB_DIR) -L$(LIB_DIR) … … 25 27 26 28 plot: plot.cc 27 $(CXX) $(DEBUG) -DDEBUG $(INCL_ CEE) $(INCL_CORE) $(INCL_RP_DEPS) -o $@ $< $(LIB_RAPPTURE)29 $(CXX) $(DEBUG) -DDEBUG $(INCL_FILES) -o $@ $< $(LIB_RAPPTURE) 28 30 29 31 plotc: plotc.c 30 $(CC) $(DEBUG) -DDEBUG $(INCL_ CEE) $(INCL_CORE) $(INCL_RP_DEPS) -o $@ $< $(LIB_RAPPTURE)32 $(CC) $(DEBUG) -DDEBUG $(INCL_FILES) -o $@ $< $(LIB_RAPPTURE) -lm 31 33 32 34 #### CLEAN UP ############################################################ -
trunk/examples/c-example/plotc.c
r93 r104 1 1 #include "RpLibraryCInterface.h" 2 2 3 //#include <stdlib.h>3 #include <stdlib.h> 4 4 #include <string.h> 5 5 #include <stdio.h> 6 #include <math.h> 6 7 7 8 int main(int argc, char * argv[]) … … 10 11 RpLibrary* lib = NULL; 11 12 12 c har* filePath;13 c har* xmltext = NULL;13 const char* filePath; 14 const char* xmltext = NULL; 14 15 double fmin, fmax; 15 16 char strFormula[100]; … … 42 43 // cannot open file or out of memory 43 44 printf("FAILED creating Rappture Library\n"); 44 exit(1);45 return(1); 45 46 } 46 47 … … 54 55 else { 55 56 printf("xml(lib) failed\n"); 56 exit(1);57 return(1); 57 58 } 58 59 … … 62 63 if (! (xmltext) ) { 63 64 printf("getString(lib,input.number(xmin).current) returns null\n"); 64 exit(1);65 return(1); 65 66 } 66 67 -
trunk/examples/fermi_fortran/Makefile
r73 r104 49 49 #### CLEAN UP ############################################################ 50 50 clean: 51 - rm -f ${PROGS} 51 - rm -f ${PROGS} run*.xml -
trunk/include/cee/RpUnitsCInterface.h
r93 r104 17 17 18 18 // unit definition functions 19 RpUnits* rpDefineUnit ( const char* unitSymbol, RpUnits* basis ); 19 const RpUnits* rpDefineUnit ( const char* unitSymbol, 20 const RpUnits* basis ); 20 21 21 22 // conversion definition functions 22 RpUnits* rpDefineConv (RpUnits* fromUnit,23 RpUnits* toUnit,23 const RpUnits* rpDefineConv ( const RpUnits* fromUnit, 24 const RpUnits* toUnit, 24 25 double (*convForwFxnPtr)(double), 25 26 double (*convBackFxnPtr)(double) ); 26 27 27 28 // unit attribute access functions 28 const char* rpGetUnits ( RpUnits* unit );29 const char* rpGetUnits ( const RpUnits* unit ); 29 30 30 const char* rpGetUnitsName ( RpUnits* unit );31 const char* rpGetUnitsName ( const RpUnits* unit ); 31 32 32 double rpGetExponent ( RpUnits* unit );33 double rpGetExponent ( const RpUnits* unit ); 33 34 34 RpUnits* rpGetBasis (RpUnits* unit);35 const RpUnits* rpGetBasis ( const RpUnits* unit); 35 36 36 RpUnits* rpFind( const char* unitSymbol);37 const RpUnits* rpFind ( const char* unitSymbol); 37 38 38 int rpMakeMetric ( RpUnits* basis );39 int rpMakeMetric ( const RpUnits* basis ); 39 40 40 41 // convert functions … … 50 51 int* result ); 51 52 52 const char* rpConvert_ObjStr ( RpUnits* fromUnits,53 RpUnits* toUnits,53 const char* rpConvert_ObjStr ( const RpUnits* fromUnits, 54 const RpUnits* toUnits, 54 55 double val, 55 56 int showUnits, … … 60 61 int* result ); 61 62 62 double rpConvert_ObjDbl ( RpUnits* fromUnits,63 RpUnits* toUnits,63 double rpConvert_ObjDbl ( const RpUnits* fromUnits, 64 const RpUnits* toUnits, 64 65 double val, 65 66 int* result ); -
trunk/include/core/RpBindingsDict.h
r97 r104 41 41 42 42 RpLibrary* getObject_Lib(int objKey); 43 RpUnits* getObject_UnitsStr(int objKey);43 const RpUnits* getObject_UnitsStr(int objKey); 44 44 45 45 void cleanLibDict(); -
trunk/include/core/RpNumber.h
r38 r104 22 22 { 23 23 public: 24 24 25 25 // users member fxns 26 26 … … 51 51 int* result = NULL ); 52 52 double convert(std::string toUnitStr, int* result = NULL); 53 double convert( RpUnits* toUnit, int* result = NULL);54 53 double convert(const RpUnits* toUnit, int* result = NULL); 54 55 55 // place the information from this object into the xml library 'lib' 56 56 // virtual RpNumber& put(RpLibrary lib); 57 57 // RpNumber& put() const; 58 58 59 60 59 61 /* 60 61 /* 62 62 * user provides a 'path' for where this object lives in xml file 63 63 * user calls define with standard hints as described in Number docs … … 78 78 * 79 79 * 80 * 80 * 81 81 */ 82 82 83 83 /* what about unit-less numbers */ 84 84 RpNumber ( … … 135 135 136 136 } 137 137 138 138 // copy constructor 139 139 RpNumber ( const RpNumber& myRpNumber ) … … 155 155 156 156 // std::string units; 157 RpUnits* units;157 const RpUnits* units; 158 158 double min; 159 159 double max; -
trunk/include/core/RpUnits.h
r83 r104 36 36 const std::string getUnits(){ return units; }; 37 37 double getExponent() {return exponent;}; 38 RpUnits * getBasis() {return basis;};38 const RpUnits * getBasis() {return basis;}; 39 39 40 40 friend class RpUnits; … … 43 43 const std::string units; 44 44 double exponent; 45 RpUnits* basis;45 const RpUnits* basis; 46 46 47 47 unit* prev; … … 52 52 const std::string& units, 53 53 double& exponent, 54 RpUnits*basis,54 const RpUnits* basis, 55 55 unit* next 56 56 ) … … 109 109 private: 110 110 111 RpUnits* fromPtr;112 RpUnits* toPtr;111 const RpUnits* fromPtr; 112 const RpUnits* toPtr; 113 113 double (*convForwFxnPtr)(double); 114 114 double (*convBackFxnPtr)(double); 115 double (*convForwFxnPtrDD)(double,double); 116 double (*convBackFxnPtrDD)(double,double); 115 117 void* (*convForwFxnPtrVoid)(void*, void*); 116 118 void* convForwData; … … 125 127 // create a conversion 126 128 conversion ( 127 RpUnits* fromPtr,128 RpUnits* toPtr,129 const RpUnits* fromPtr, 130 const RpUnits* toPtr, 129 131 double (*convForwFxnPtr)(double), 130 132 double (*convBackFxnPtr)(double), … … 136 138 convForwFxnPtr (convForwFxnPtr), 137 139 convBackFxnPtr (convBackFxnPtr), 140 convForwFxnPtrDD (NULL), 141 convBackFxnPtrDD (NULL), 138 142 convForwFxnPtrVoid (NULL), 139 143 convForwData (NULL), … … 145 149 146 150 conversion ( 147 RpUnits* fromPtr, 148 RpUnits* toPtr, 151 const RpUnits* fromPtr, 152 const RpUnits* toPtr, 153 double (*convForwFxnPtr)(double,double), 154 double (*convBackFxnPtr)(double,double), 155 conversion* prev, 156 conversion* next 157 ) 158 : fromPtr (fromPtr), 159 toPtr (toPtr), 160 convForwFxnPtr (NULL), 161 convBackFxnPtr (NULL), 162 convForwFxnPtrDD (convForwFxnPtr), 163 convBackFxnPtrDD (convBackFxnPtr), 164 convForwFxnPtrVoid (NULL), 165 convForwData (NULL), 166 convBackFxnPtrVoid (NULL), 167 convBackData (NULL), 168 prev (prev), 169 next (next) 170 {}; 171 172 conversion ( 173 const RpUnits* fromPtr, 174 const RpUnits* toPtr, 149 175 void* (*convForwFxnPtrVoid)(void*, void*), 150 176 void* convForwData, … … 158 184 convForwFxnPtr (NULL), 159 185 convBackFxnPtr (NULL), 186 convForwFxnPtrDD (NULL), 187 convBackFxnPtrDD (NULL), 160 188 convForwFxnPtrVoid (convForwFxnPtrVoid), 161 189 convForwData (convForwData), … … 218 246 219 247 // users member fxns 220 std::string getUnits() ;221 std::string getUnitsName() ;222 double getExponent() ;223 RpUnits* getBasis();248 std::string getUnits() const; 249 std::string getUnitsName() const; 250 double getExponent() const; 251 const RpUnits* getBasis() const; 224 252 225 253 // convert from one RpUnits to another if the conversion is defined 226 double convert(RpUnits* toUnits, double val, int* result = NULL); 254 double convert( const RpUnits* toUnits, 255 double val, 256 int* result=NULL ) const; 227 257 // convert from one RpUnits to another if the conversion is defined 228 void* convert(RpUnits* toUnits, void* val, int* result = NULL); 258 void* convert( const RpUnits* toUnits, 259 void* val, 260 int* result=NULL) const; 229 261 // convert from one RpUnits to another if the conversion is defined 230 double convert(std::string, double val);262 // double convert(std::string, double val); 231 263 // convert from one RpUnits to another if the conversion is defined 232 std::string convert ( RpUnits* toUnits,264 std::string convert ( const RpUnits* toUnits, 233 265 double val, 234 266 int showUnits = 0, 235 int* result = NULL ) ;267 int* result = NULL ) const; 236 268 237 269 static std::string convert ( std::string val, … … 246 278 // this should only be used for units that are part of the 247 279 // metric system. doesnt deal with exponents, just prefixes 248 double makeBasis(double value, int* result = NULL) ;249 RpUnits & makeBasis(double* value, int* result = NULL);250 251 static int makeMetric( RpUnits * basis);280 double makeBasis(double value, int* result = NULL) const; 281 const RpUnits & makeBasis(double* value, int* result = NULL) const; 282 283 static int makeMetric(const RpUnits * basis); 252 284 253 285 // find a RpUnits object that should exist in RpUnitsTable 254 286 // returns 0 on success (object was found) 255 287 // returns !0 on failure (object not found) 256 static RpUnits* find(std::string key) 257 { 258 // dict.find seems to return a (RpUnits* const) so i had to 259 // cast it as a (RpUnits*) 260 261 // dict pointer 262 RpUnits* unitEntry = (RpUnits*) *(dict->find(key).getValue()); 263 264 // dict pointer 265 if (unitEntry == (RpUnits*)dict->getNullEntry().getValue()) { 266 unitEntry = NULL; 267 } 268 269 return unitEntry; 270 }; 288 static const RpUnits* find(std::string key); 271 289 272 290 // user calls define to add a RpUnits object or to add a relation rule 273 291 // 274 292 // add RpUnits Object 275 static RpUnits * define(const std::string units, RpUnits * basis); 276 static RpUnits * defineCmplx(const std::string units,RpUnits * basis); 293 static RpUnits * define(const std::string units, 294 const RpUnits* basis); 295 static RpUnits * defineCmplx( const std::string units, 296 const RpUnits* basis); 277 297 // 278 298 // add relation rule 279 299 280 static RpUnits * define( RpUnits* from,281 RpUnits* to,300 static RpUnits * define(const RpUnits* from, 301 const RpUnits* to, 282 302 double (*convForwFxnPtr)(double), 283 303 double (*convBackFxnPtr)(double)); 284 304 285 static RpUnits * define(RpUnits* from, 286 RpUnits* to, 305 static RpUnits * define(const RpUnits* from, 306 const RpUnits* to, 307 double (*convForwFxnPtr)(double,double), 308 double (*convBackFxnPtr)(double,double)); 309 310 static RpUnits * define(const RpUnits* from, 311 const RpUnits* to, 287 312 void* (*convForwFxnPtr)(void*, void*), 288 313 void* convForwData, … … 297 322 // "temp" load units related to temperature 298 323 // "time" load units related to time 324 // "volume" load units related to volume 299 325 // (no other groups have been created) 300 326 … … 384 410 385 411 // linked list of units this RpUnit can convert to 386 convEntry* convList; 412 // its mutable because the connectConversion function takes in a 413 // const RpUnits* and attempts to change the convList variable 414 // within the RpUnits Object 415 mutable convEntry* convList; 387 416 388 417 // used by the RpUnits when defining conversion elements … … 405 434 const std::string& units, 406 435 double& exponent, 407 RpUnits* basis436 const RpUnits* basis 408 437 ) 409 438 : head ( new unit( units, exponent, basis, NULL) ), … … 418 447 419 448 RpUnits ( 420 RpUnits* from,421 RpUnits* to,449 const RpUnits* from, 450 const RpUnits* to, 422 451 double (*convForwFxnPtr)(double), 423 452 double (*convBackFxnPtr)(double), … … 435 464 436 465 437 438 439 440 466 RpUnits ( 441 RpUnits* from, 442 RpUnits* to, 467 const RpUnits* from, 468 const RpUnits* to, 469 double (*convForwFxnPtr)(double,double), 470 double (*convBackFxnPtr)(double,double), 471 conversion* prev, 472 conversion* next 473 ) 474 : head (NULL), 475 convList (NULL), 476 conv (new conversion 477 (from,to,convForwFxnPtr,convBackFxnPtr,prev,next)) 478 { 479 connectConversion(from); 480 connectConversion(to); 481 }; 482 483 484 485 RpUnits ( 486 const RpUnits* from, 487 const RpUnits* to, 443 488 void* (*convForwFxnPtr)(void*, void*), 444 489 void* convForwData, … … 475 520 } 476 521 477 void RpUnits::connectConversion( RpUnits* myRpUnit);522 void RpUnits::connectConversion(const RpUnits* myRpUnit); 478 523 479 524 void RpUnits::fillMetricMap(); … … 495 540 496 541 497 static int pre_compare( std::string& units, RpUnits* basis = NULL); 542 static int pre_compare( std::string& units, 543 const RpUnits* basis = NULL); 544 498 545 void addUnit( const std::string& units, 499 546 double & exponent, 500 RpUnits * basis547 const RpUnits * basis 501 548 ); 502 549 … … 506 553 static int addPresetTemp(); 507 554 static int addPresetTime(); 555 static int addPresetVolume(); 508 556 509 557 -
trunk/include/core/RpUnitsStd.h
r68 r104 4 4 #endif 5 5 6 double centi2base (double centi); 7 double milli2base (double milli); 8 double micro2base (double micro); 9 double nano2base (double nano); 10 double pico2base (double pico); 11 double femto2base (double femto); 12 double atto2base (double atto); 13 double kilo2base (double kilo); 14 double mega2base (double mega); 15 double giga2base (double giga); 16 double tera2base (double tera); 17 double peta2base (double peta); 18 19 20 double base2centi (double base); 21 double base2milli (double base); 22 double base2micro (double base); 23 double base2nano (double base); 24 double base2pico (double base); 25 double base2femto (double base); 26 double base2atto (double base); 27 double base2kilo (double base); 28 double base2mega (double base); 29 double base2giga (double base); 30 double base2tera (double base); 31 double base2peta (double base); 6 double centi2base (double centi, double power); 7 double milli2base (double milli, double power); 8 double micro2base (double micro, double power); 9 double nano2base (double nano, double power); 10 double pico2base (double pico, double power); 11 double femto2base (double femto, double power); 12 double atto2base (double atto, double power); 13 double kilo2base (double kilo, double power); 14 double mega2base (double mega, double power); 15 double giga2base (double giga, double power); 16 double tera2base (double tera, double power); 17 double peta2base (double peta, double power); 32 18 33 19 34 20 35 double angstrom2meter (double angstrom); 36 double meter2angstrom (double meters); 37 double meter2inch (double m); 38 double inch2meter (double in); 39 double meter2feet (double m); 40 double feet2meter (double ft); 41 double meter2yard (double m); 42 double yard2meter (double yd); 21 double base2centi (double base, double power); 22 double base2milli (double base, double power); 23 double base2micro (double base, double power); 24 double base2nano (double base, double power); 25 double base2pico (double base, double power); 26 double base2femto (double base, double power); 27 double base2atto (double base, double power); 28 double base2kilo (double base, double power); 29 double base2mega (double base, double power); 30 double base2giga (double base, double power); 31 double base2tera (double base, double power); 32 double base2peta (double base, double power); 33 34 35 36 double angstrom2meter (double angstrom, double power); 37 double meter2angstrom (double meters, double power); 38 double meter2inch (double m, double power); 39 double inch2meter (double in, double power); 40 double meter2feet (double m, double power); 41 double feet2meter (double ft, double power); 42 double meter2yard (double m, double power); 43 double yard2meter (double yd, double power); 43 44 44 45 … … 62 63 63 64 65 double cubicMeter2usGallon (double m3, double none); 66 double usGallon2cubicMeter (double g, double none); 67 double cubicFeet2usGallon (double ft3, double none); 68 double usGallon2cubicFeet (double g, double none); 64 69 65 70 -
trunk/src/cee/RpUnitsCInterface.cc
r93 r104 17 17 #endif 18 18 19 RpUnits*20 rpDefineUnit(const char* unitSymbol, RpUnits* basis) {19 const RpUnits* 20 rpDefineUnit(const char* unitSymbol, const RpUnits* basis) { 21 21 22 22 return RpUnits::define(unitSymbol, basis); 23 23 } 24 24 25 RpUnits*26 rpDefineConv( 27 RpUnits* toUnit,25 const RpUnits* 26 rpDefineConv( const RpUnits* fromUnit, 27 const RpUnits* toUnit, 28 28 double (*convForwFxnPtr)(double), 29 29 double (*convBackFxnPtr)(double) ) { … … 32 32 } 33 33 34 RpUnits*34 const RpUnits* 35 35 rpFind ( const char* key ) { 36 36 … … 39 39 40 40 const char* 41 rpGetUnits ( RpUnits* unit ) {41 rpGetUnits ( const RpUnits* unit ) { 42 42 43 43 static std::string retVal; … … 47 47 48 48 const char* 49 rpGetUnitsName ( RpUnits* unit ) {49 rpGetUnitsName ( const RpUnits* unit ) { 50 50 51 51 static std::string retVal; … … 55 55 56 56 double 57 rpGetExponent ( RpUnits* unit ) {57 rpGetExponent ( const RpUnits* unit ) { 58 58 59 59 return unit->getExponent(); 60 60 } 61 61 62 RpUnits*63 rpGetBasis ( RpUnits* unit ) {62 const RpUnits* 63 rpGetBasis ( const RpUnits* unit ) { 64 64 65 65 return unit->getBasis(); … … 67 67 68 68 int 69 rpMakeMetric( RpUnits* basis) {69 rpMakeMetric(const RpUnits* basis) { 70 70 71 71 return RpUnits::makeMetric(basis); … … 95 95 96 96 const char* 97 rpConvert_ObjStr ( RpUnits* fromUnits,98 RpUnits* toUnits,97 rpConvert_ObjStr ( const RpUnits* fromUnits, 98 const RpUnits* toUnits, 99 99 double val, 100 100 int showUnits, … … 124 124 125 125 double 126 rpConvert_ObjDbl ( RpUnits* fromUnits,127 RpUnits* toUnits,126 rpConvert_ObjDbl ( const RpUnits* fromUnits, 127 const RpUnits* toUnits, 128 128 double val, 129 129 int* result ) { -
trunk/src/core/RpBindingsDict.cc
r97 r104 89 89 } 90 90 91 RpUnits*91 const RpUnits* 92 92 getObject_UnitsStr(int objKey) { 93 93 -
trunk/src/core/RpNumber.cc
r37 r104 4 4 5 5 /************************************************************************ 6 * 6 * 7 7 * set the default value of a RpNumber object 8 * 9 ************************************************************************/ 10 11 RpNumber& 12 RpNumber::setDefaultValue(double newDefaultVal) 13 { 8 * 9 ************************************************************************/ 10 11 RpNumber& 12 RpNumber::setDefaultValue(double newDefaultVal) { 13 14 14 double* def = NULL; 15 15 16 16 def = (double*) RpVariable::getDefaultValue(); 17 17 … … 27 27 28 28 /************************************************************************ 29 * 29 * 30 30 * set the current value of a RpNumber object 31 * 32 ************************************************************************/ 33 34 RpNumber& 35 RpNumber::setCurrentValue(double newCurrentVal) 36 { 31 * 32 ************************************************************************/ 33 34 RpNumber& 35 RpNumber::setCurrentValue(double newCurrentVal) { 36 37 37 double* cur = (double*) RpVariable::getCurrentValue(); 38 38 double* def = (double*) RpVariable::getDefaultValue(); … … 50 50 51 51 /************************************************************************ 52 * 52 * 53 53 * set the min value of a RpNumber object 54 * 55 ************************************************************************/ 56 RpNumber& 57 RpNumber::setMin(double newMin) 58 { 54 * 55 ************************************************************************/ 56 RpNumber& 57 RpNumber::setMin(double newMin) { 58 59 59 min = newMin; 60 60 return *this; 61 61 } 62 62 /************************************************************************ 63 * 63 * 64 64 * set the min value of a RpNumber object 65 * 66 ************************************************************************/ 67 RpNumber& 68 RpNumber::setMax(double newMax) 69 { 65 * 66 ************************************************************************/ 67 RpNumber& 68 RpNumber::setMax(double newMax) { 69 70 70 max = newMax; 71 71 return *this; 72 72 } 73 73 /************************************************************************ 74 * 74 * 75 75 * report the units of the object 76 * 76 * 77 77 ************************************************************************/ 78 78 79 79 std::string 80 RpNumber::getUnits() const 81 { 80 RpNumber::getUnits() const { 81 82 82 return units->getUnitsName(); 83 83 } … … 85 85 86 86 /************************************************************************ 87 * 87 * 88 88 * report the default value of the object 89 * 90 ************************************************************************/ 91 double 92 RpNumber::getDefaultValue(void* null_val) const 93 { 89 * 90 ************************************************************************/ 91 double 92 RpNumber::getDefaultValue(void* null_val) const { 93 94 94 return *((double*) RpVariable::getDefaultValue()); 95 95 } 96 96 97 97 /************************************************************************ 98 * 98 * 99 99 * report the current value of the object 100 * 101 ************************************************************************/ 102 double 103 RpNumber::getCurrentValue(void* null_val) const 104 { 100 * 101 ************************************************************************/ 102 double 103 RpNumber::getCurrentValue(void* null_val) const { 104 105 105 return *((double*) RpVariable::getCurrentValue()); 106 106 } 107 107 108 108 /************************************************************************ 109 * 109 * 110 110 * report the min of the object 111 * 112 ************************************************************************/ 113 double 114 RpNumber::getMin() const 115 { 116 return min; 117 } 118 119 /************************************************************************ 120 * 111 * 112 ************************************************************************/ 113 double 114 RpNumber::getMin() const { 115 116 return min; 117 } 118 119 /************************************************************************ 120 * 121 121 * report the max of the object 122 * 123 ************************************************************************/ 124 double 125 RpNumber::getMax() const 126 { 127 return max; 128 } 129 130 /************************************************************************ 131 * 122 * 123 ************************************************************************/ 124 double 125 RpNumber::getMax() const { 126 127 return max; 128 } 129 130 /************************************************************************ 131 * 132 132 * convert the number object to another unit from string 133 133 * store the result as the currentValue 134 * 135 ************************************************************************/ 136 double 137 RpNumber::convert(std::string toUnitStr, int storeResult, int* result) 138 { 139 RpUnits* toUnit = NULL;134 * 135 ************************************************************************/ 136 double 137 RpNumber::convert(std::string toUnitStr, int storeResult, int* result) { 138 139 const RpUnits* toUnit = NULL; 140 140 double retVal = 0; 141 141 int my_result = 0; … … 156 156 // perform the conversion 157 157 retVal = convert(toUnit,&my_result); 158 158 159 159 // check the result of the conversion and store if necessary 160 160 if (my_result) { … … 176 176 177 177 /************************************************************************ 178 * 178 * 179 179 * convert the number object to another unit from string 180 * 181 ************************************************************************/ 182 double 183 RpNumber::convert(std::string toUnitStr, int* result) 184 { 185 RpUnits* toUnit = NULL;180 * 181 ************************************************************************/ 182 double 183 RpNumber::convert(std::string toUnitStr, int* result) { 184 185 const RpUnits* toUnit = NULL; 186 186 toUnit = RpUnits::find(toUnitStr); 187 187 if (!toUnit) { … … 197 197 198 198 /************************************************************************ 199 * 199 * 200 200 * convert the number object to another unit from RpUnits object 201 * 202 ************************************************************************/ 203 double 204 RpNumber::convert( RpUnits* toUnit, int *result)205 { 201 * 202 ************************************************************************/ 203 double 204 RpNumber::convert(const RpUnits* toUnit, int *result) { 205 206 206 return units->convert(toUnit,getCurrentValue(), result); 207 207 } -
trunk/src/core/RpUnits.cc
r103 r104 23 23 ************************************************************************/ 24 24 25 RpUnits * RpUnits::define(const std::string units, RpUnits * basis) 26 { 25 RpUnits * 26 RpUnits::define(const std::string units, const RpUnits* basis) { 27 27 28 RpUnits * newRpUnit = NULL; 28 29 … … 187 188 ************************************************************************/ 188 189 189 RpUnits * RpUnits::defineCmplx ( const std::string units, RpUnits * basis ) 190 { 190 RpUnits * 191 RpUnits::defineCmplx ( const std::string units, const RpUnits* basis ) { 192 191 193 RpUnits * newRpUnit = NULL; 192 194 … … 427 429 * 428 430 ************************************************************************/ 429 RpUnits * RpUnits::define( RpUnits* from, 430 RpUnits* to, 431 double (*convForwFxnPtr)(double), 432 double (*convBackFxnPtr)(double)) 433 { 431 RpUnits * 432 RpUnits::define( const RpUnits* from, 433 const RpUnits* to, 434 double (*convForwFxnPtr)(double), 435 double (*convBackFxnPtr)(double)) { 436 434 437 RpUnits* conv = new RpUnits( from, 435 438 to, … … 442 445 } 443 446 444 RpUnits * RpUnits::define( RpUnits* from, 445 RpUnits* to, 446 double (*convForwFxnPtr)(double,double), 447 double (*convBackFxnPtr)(double,double)) 448 { 447 RpUnits * 448 RpUnits::define( const RpUnits* from, 449 const RpUnits* to, 450 double (*convForwFxnPtr)(double,double), 451 double (*convBackFxnPtr)(double,double)) { 452 449 453 RpUnits* conv = new RpUnits( from, 450 454 to, … … 457 461 } 458 462 459 RpUnits * RpUnits::define( RpUnits* from, 460 RpUnits* to, 461 void* (*convForwFxnPtr)(void*, void*), 462 void* convForwData, 463 void* (*convBackFxnPtr)(void*, void*), 464 void* convBackData) 465 { 463 RpUnits * 464 RpUnits::define( const RpUnits* from, 465 const RpUnits* to, 466 void* (*convForwFxnPtr)(void*, void*), 467 void* convForwData, 468 void* (*convBackFxnPtr)(void*, void*), 469 void* convBackData) { 470 466 471 RpUnits* conv = new RpUnits( from, 467 472 to, … … 480 485 * report the units this object represents back to the user 481 486 * 482 * **********************************************************************/ 483 std::string RpUnits::getUnits() 484 { 487 ************************************************************************/ 488 489 /**********************************************************************/ 490 // METHOD: getUnits() 491 // /// Report the text portion of the units of this object back to caller. 492 // /** 493 // * See Also getUnitsName(). 494 // */ 495 // 496 std::string 497 RpUnits::getUnits() const { 498 485 499 std::stringstream unitText; 486 500 unit* p = head; … … 498 512 * report the units this object represents back to the user 499 513 * 500 * **********************************************************************/ 501 std::string RpUnits::getUnitsName() 502 { 514 ************************************************************************/ 515 516 /**********************************************************************/ 517 // METHOD: getUnitsName() 518 // /// Report the full name of the units of this object back to caller. 519 // /** 520 // * Reports the full text and exponent of the units represented by this 521 // * object, back to the caller. Note that if the exponent == 1, no 522 // * exponent will be printed. 523 // */ 524 // 525 std::string 526 RpUnits::getUnitsName() const { 527 503 528 std::stringstream unitText; 504 529 unit* p = head; … … 527 552 * 528 553 * **********************************************************************/ 529 double RpUnits::getExponent() 530 { 554 /**********************************************************************/ 555 // METHOD: getExponent() 556 // /// Report the exponent of the units of this object back to caller. 557 // /** 558 // * Reports the exponent of the units represented by this 559 // * object, back to the caller. Note that if the exponent == 1, no 560 // * exponent will be printed. 561 // */ 562 // 563 double 564 RpUnits::getExponent() const { 565 531 566 return head->getExponent(); 532 567 } … … 537 572 * 538 573 * **********************************************************************/ 539 RpUnits * RpUnits::getBasis() 540 { 574 /**********************************************************************/ 575 // METHOD: getBasis() 576 // /// Retrieve the RpUnits object representing the basis of this object. 577 // /** 578 // * Returns a pointer to a RpUnits object which, on success, points to the 579 // * RpUnits object that is the basis of the calling object. 580 // */ 581 // 582 const RpUnits * 583 RpUnits::getBasis() const { 584 541 585 // check if head exists? 586 if (!head) { 587 // raise error for badly formed Rappture Units object 588 } 589 542 590 return head->getBasis(); 543 591 } … … 553 601 * 554 602 ************************************************************************/ 555 double RpUnits::makeBasis(double value, int* result)556 {557 558 RpUnits* basis = getBasis();603 double 604 RpUnits::makeBasis(double value, int* result) const { 605 606 const RpUnits* basis = getBasis(); 559 607 double retVal = value; 560 608 … … 567 615 // do nothing 568 616 569 if (result) {570 *result = 1;571 }617 // if (result) { 618 // *result = 1; 619 // } 572 620 } 573 621 else { … … 578 626 } 579 627 580 RpUnits& RpUnits::makeBasis(double* value, int* result) 581 {582 RpUnits* basis = getBasis();628 const RpUnits& 629 RpUnits::makeBasis(double* value, int* result) const { 630 const RpUnits* basis = getBasis(); 583 631 double retVal = *value; 584 632 int convResult = 0; … … 588 636 // do nothing 589 637 590 if (result) {591 *result = 1;592 }638 // if (result) { 639 // *result = 1; 640 // } 593 641 } 594 642 else { … … 603 651 *result = convResult; 604 652 } 605 606 607 653 608 654 return *this; … … 616 662 * 617 663 * **********************************************************************/ 618 /* 619 int RpUnits::makeMetric(RpUnits * basis) { 664 665 int 666 RpUnits::makeMetric(const RpUnits * basis) { 620 667 621 668 if (!basis) { … … 623 670 } 624 671 625 std::string basisName = basis->getUnits ();672 std::string basisName = basis->getUnitsName(); 626 673 std::string name; 627 674 std::string forw, back; … … 677 724 return (1); 678 725 } 679 */ 680 681 int RpUnits::makeMetric(RpUnits * basis) { 682 683 if (!basis) { 684 return 0; 685 } 686 687 std::string basisName = basis->getUnitsName(); 688 std::string name; 689 std::string forw, back; 690 691 name = "c" + basisName; 692 RpUnits * centi = RpUnits::define(name, basis); 693 RpUnits::define(centi, basis, centi2base, base2centi); 694 695 name = "m" + basisName; 696 RpUnits * milli = RpUnits::define(name, basis); 697 RpUnits::define(milli, basis, milli2base, base2milli); 698 699 name = "u" + basisName; 700 RpUnits * micro = RpUnits::define(name, basis); 701 RpUnits::define(micro, basis, micro2base, base2micro); 702 703 name = "n" + basisName; 704 RpUnits * nano = RpUnits::define(name, basis); 705 RpUnits::define(nano, basis, nano2base, base2nano); 706 707 name = "p" + basisName; 708 RpUnits * pico = RpUnits::define(name, basis); 709 RpUnits::define(pico, basis, pico2base, base2pico); 710 711 name = "f" + basisName; 712 RpUnits * femto = RpUnits::define(name, basis); 713 RpUnits::define(femto, basis, femto2base, base2femto); 714 715 name = "a" + basisName; 716 RpUnits * atto = RpUnits::define(name, basis); 717 RpUnits::define(atto, basis, atto2base, base2atto); 718 719 name = "k" + basisName; 720 RpUnits * kilo = RpUnits::define(name, basis); 721 RpUnits::define(kilo, basis, kilo2base, base2kilo); 722 723 name = "M" + basisName; 724 RpUnits * mega = RpUnits::define(name, basis); 725 RpUnits::define(mega, basis, mega2base, base2mega); 726 727 name = "G" + basisName; 728 RpUnits * giga = RpUnits::define(name, basis); 729 RpUnits::define(giga, basis, giga2base, base2giga); 730 731 name = "T" + basisName; 732 RpUnits * tera = RpUnits::define(name, basis); 733 RpUnits::define(tera, basis, tera2base, base2tera); 734 735 name = "P" + basisName; 736 RpUnits * peta = RpUnits::define(name, basis); 737 RpUnits::define(peta, basis, peta2base, base2peta); 738 739 return (1); 740 } 741 742 743 RpUnits* 744 RpUnits::find(std::string key) 745 { 726 727 728 const RpUnits* 729 RpUnits::find(std::string key) { 730 746 731 // dict.find seems to return a (RpUnits* const) so i had to 747 732 // cast it as a (RpUnits*) 748 733 749 734 // dict pointer 750 RpUnits* unitEntry = (RpUnits*)*(dict->find(key).getValue());735 const RpUnits* unitEntry = *(dict->find(key).getValue()); 751 736 752 737 // dict pointer 753 if (unitEntry == (RpUnits*)dict->getNullEntry().getValue()) {738 if (unitEntry == *(dict->getNullEntry().getValue()) ) { 754 739 unitEntry = NULL; 755 740 } … … 768 753 int* result ) { 769 754 770 RpUnits* toUnits = NULL;771 RpUnits* fromUnits = NULL;755 const RpUnits* toUnits = NULL; 756 const RpUnits* fromUnits = NULL; 772 757 std::string tmpNumVal = ""; 773 758 std::string fromUnitsName = ""; … … 849 834 if ( (result) && (*result == 0) ) { 850 835 *result = convResult; 851 }836 } 852 837 853 838 return convVal; … … 855 840 } 856 841 857 std::string RpUnits::convert ( RpUnits* toUnits, 858 double val, 859 int showUnits, 860 int* result ) 861 { 842 std::string 843 RpUnits::convert ( const RpUnits* toUnits, 844 double val, 845 int showUnits, 846 int* result ) const { 847 862 848 double retVal = convert(toUnits,val,result); 863 849 std::stringstream unitText; … … 880 866 // cm.convert(meter,10) 881 867 // cm.convert(angstrum,100) 882 double RpUnits::convert(RpUnits* toUnit, double val, int* result)883 {868 double 869 RpUnits::convert(const RpUnits* toUnit, double val, int* result) const { 884 870 885 871 // currently we convert this object to its basis and look for the … … 887 873 888 874 double value = val; 889 RpUnits* basis = this->getBasis();890 RpUnits* toBasis = toUnit->getBasis();891 RpUnits* fromUnit = this;892 RpUnits* dictToUnit = NULL;875 const RpUnits* basis = this->getBasis(); 876 const RpUnits* toBasis = toUnit->getBasis(); 877 const RpUnits* fromUnit = this; 878 const RpUnits* dictToUnit = NULL; 893 879 convEntry *p; 894 880 int my_result = 0; … … 1061 1047 1062 1048 1063 void* RpUnits::convert(RpUnits* toUnit, void* val, int* result)1064 {1049 void* 1050 RpUnits::convert(const RpUnits* toUnit, void* val, int* result) const { 1065 1051 1066 1052 // currently we convert this object to its basis and look for the … … 1068 1054 1069 1055 void* value = val; 1070 RpUnits* basis = this->getBasis();1071 RpUnits* toBasis = toUnit->getBasis();1072 RpUnits* fromUnit = this;1073 RpUnits* dictToUnit = NULL;1056 const RpUnits* basis = this->getBasis(); 1057 const RpUnits* toBasis = toUnit->getBasis(); 1058 const RpUnits* fromUnit = this; 1059 const RpUnits* dictToUnit = NULL; 1074 1060 convEntry *p; 1075 1061 int my_result = 0; … … 1211 1197 } 1212 1198 1213 void RpUnits::addUnit( const std::string& units,1214 double& exponent,1215 RpUnits* basis1216 )1217 { 1199 void 1200 RpUnits::addUnit( const std::string& units, 1201 double& exponent, 1202 const RpUnits* basis) { 1203 1218 1204 unit* p = NULL; 1219 1205 … … 1231 1217 } 1232 1218 1233 int RpUnits::insert(std::string key) 1234 { 1219 int 1220 RpUnits::insert(std::string key) { 1221 1235 1222 int newRecord = 0; 1236 1223 RpUnits* val = this; … … 1241 1228 1242 1229 1243 int RpUnits::pre_compare( std::string& units, RpUnits* basis )1244 {1230 int 1231 RpUnits::pre_compare( std::string& units, const RpUnits* basis ) { 1245 1232 1246 1233 // compare the incomming units with the previously defined units. … … 1356 1343 1357 1344 1358 void RpUnits::connectConversion(RpUnits* myRpUnit) 1359 { 1345 void 1346 RpUnits::connectConversion(const RpUnits* myRpUnit) { 1347 1360 1348 convEntry* p = myRpUnit->convList; 1361 1349 … … 1392 1380 retVal = addPresetTime(); 1393 1381 } 1382 else if (group.compare("volume") == 0) { 1383 retVal = addPresetTime(); 1384 } 1394 1385 1395 1386 return retVal; -
trunk/src/fortran/RpUnitsFInterface.cc
r93 r104 22 22 23 23 int result = -1; 24 RpUnits* newUnit = NULL;25 RpUnits* basis = NULL;24 const RpUnits* newUnit = NULL; 25 const RpUnits* basis = NULL; 26 26 std::string basisStrName = ""; 27 27 std::string newUnitName = ""; … … 64 64 65 65 // RpUnits* searchUnit = RpUnits::find(searchName); 66 RpUnits* searchUnit = RpUnits::find(inText);66 const RpUnits* searchUnit = RpUnits::find(inText); 67 67 68 68 if (searchUnit) { … … 81 81 { 82 82 int result = -1; 83 RpUnits* newBasis = NULL;83 const RpUnits* newBasis = NULL; 84 84 85 85 if (basis && *basis) { … … 97 97 rp_get_units(int* unitRefVal, char* retText, int retText_len) 98 98 { 99 RpUnits* unitObj = NULL;99 const RpUnits* unitObj = NULL; 100 100 std::string unitNameText = ""; 101 101 int result = 0; … … 115 115 rp_get_units_name(int* unitRefVal, char* retText, int retText_len) 116 116 { 117 RpUnits* unitObj = NULL;117 const RpUnits* unitObj = NULL; 118 118 std::string unitNameText = ""; 119 119 int result = 0; … … 133 133 rp_get_exponent(int* unitRefVal, double* retExponent) 134 134 { 135 RpUnits* unitObj = NULL;135 const RpUnits* unitObj = NULL; 136 136 int result = 0; 137 137 … … 149 149 rp_get_basis(int* unitRefVal) 150 150 { 151 RpUnits* unitObj = NULL;152 RpUnits* basisObj = NULL;151 const RpUnits* unitObj = NULL; 152 const RpUnits* basisObj = NULL; 153 153 int result = -1; 154 154 … … 170 170 int 171 171 rp_units_convert_dbl ( char* fromVal, 172 173 174 175 172 char* toUnitsName, 173 double* convResult, 174 int fromVal_len, 175 int toUnitsName_len ) { 176 176 177 177 char* inFromVal = NULL; … … 210 210 int 211 211 rp_units_convert_str ( char* fromVal, 212 213 214 215 216 212 char* toUnitsName, 213 char* retText, 214 int fromVal_len, 215 int toUnitsName_len, 216 int retText_len ) { 217 217 218 218 char* inFromVal = NULL; -
trunk/src/python/PyRpUnits.cc
r97 r104 6 6 typedef struct { 7 7 PyObject_HEAD 8 RpUnits* rp_unit;8 const RpUnits* rp_unit; 9 9 } RpUnitsObject; 10 10 … … 131 131 0, /*tp_as_buffer*/ 132 132 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ 133 "R pUnits Object",/*tp_doc*/133 "Rappture.Units Object", /*tp_doc*/ 134 134 0, /*tp_traverse*/ 135 135 0, /*tp_clear*/ … … 291 291 292 292 RpUnitsObject* newRpUnit = NULL; 293 RpUnits* newConv = NULL;293 const RpUnits* newConv = NULL; 294 294 295 295 if (PyTuple_Size(args) > 0) { … … 360 360 { 361 361 char* searchUnits = NULL; 362 RpUnits* foundUnits = NULL;362 const RpUnits* foundUnits = NULL; 363 363 RpUnitsObject* returnUnits = NULL; 364 364 -
trunk/test/src/RpNumber_test.cc
r40 r104 84 84 void define_some_units() 85 85 { 86 RpUnits * meters = RpUnits::define("m", NULL);86 const RpUnits * meters = RpUnits::define("m", NULL); 87 87 RpUnits::makeMetric(meters); 88 88 RpUnits::define("V", NULL); 89 89 RpUnits::define("s", NULL); 90 90 RpUnits::define("cm2/Vs", NULL); 91 RpUnits* angstrom = RpUnits::define("A", NULL);91 const RpUnits* angstrom = RpUnits::define("A", NULL); 92 92 RpUnits::define(angstrom, meters, angstrom2meter, meter2angstrom); 93 RpUnits* fahrenheit = RpUnits::define("F", NULL);94 RpUnits* celcius = RpUnits::define("C", NULL);95 RpUnits* kelvin = RpUnits::define("K", NULL);93 const RpUnits* fahrenheit = RpUnits::define("F", NULL); 94 const RpUnits* celcius = RpUnits::define("C", NULL); 95 const RpUnits* kelvin = RpUnits::define("K", NULL); 96 96 RpUnits::define(fahrenheit, celcius, fahrenheit2centigrade, centigrade2fahrenheit); 97 97 RpUnits::define(celcius, kelvin, centigrade2kelvin, kelvin2centigrade); -
trunk/test/src/RpUnitsC_test.c
r93 r104 51 51 { 52 52 53 RpUnits* meters = rpDefineUnit("m",NULL);53 const RpUnits* meters = rpDefineUnit("m",NULL); 54 54 55 RpUnits* centimeters = NULL;56 RpUnits* nanometers = NULL;57 RpUnits* cm_basis = NULL;55 const RpUnits* centimeters = NULL; 56 const RpUnits* nanometers = NULL; 57 const RpUnits* cm_basis = NULL; 58 58 59 RpUnits* angstrom = rpDefineUnit("A",NULL);60 RpUnits* fahrenheit = rpDefineUnit("F",NULL);61 RpUnits* celcius = rpDefineUnit("C",NULL);62 RpUnits* kelvin = rpDefineUnit("K",NULL);59 const RpUnits* angstrom = rpDefineUnit("A",NULL); 60 const RpUnits* fahrenheit = rpDefineUnit("F",NULL); 61 const RpUnits* celcius = rpDefineUnit("C",NULL); 62 const RpUnits* kelvin = rpDefineUnit("K",NULL); 63 63 64 64 rpDefineConv(angstrom, meters, angstrom2meter, meter2angstrom); -
trunk/test/src/RpUnits_test.cc
r73 r104 33 33 // 34 34 printf ("=============== TEST 1 ===============\n"); 35 RpUnits * meters = RpUnits::define("m", NULL);35 const RpUnits * meters = RpUnits::define("m", NULL); 36 36 // (meters) ? success() : fail(); 37 37 // RpUnits * centimeter = RpUnits::define("cm", NULL); … … 54 54 */ 55 55 56 RpUnits* mobility = RpUnits::define("cm2/Vs", NULL);56 const RpUnits* mobility = RpUnits::defineCmplx("cm2/Vs", NULL); 57 57 std::cout << "mobility = :" << mobility->getUnitsName() <<":"<< std::endl; 58 58 59 RpUnits* mobility2 = RpUnits::find("cm2V-1s-1");59 const RpUnits* mobility2 = RpUnits::find("cm2V-1s-1"); 60 60 if (mobility2) { 61 61 std::cout << "mobility2 exists" << std::endl; … … 67 67 } 68 68 69 RpUnits* cmeters = RpUnits::find("cm");70 RpUnits* angstrom = RpUnits::define("A", NULL);69 const RpUnits* cmeters = RpUnits::find("cm"); 70 const RpUnits* angstrom = RpUnits::define("A", NULL); 71 71 RpUnits::define(angstrom, meters, angstrom2meter, meter2angstrom); 72 72 … … 79 79 80 80 81 RpUnits* fahrenheit = RpUnits::define("F", NULL);82 RpUnits* celcius = RpUnits::define("C", NULL);83 RpUnits* kelvin = RpUnits::define("K", NULL);81 const RpUnits* fahrenheit = RpUnits::define("F", NULL); 82 const RpUnits* celcius = RpUnits::define("C", NULL); 83 const RpUnits* kelvin = RpUnits::define("K", NULL); 84 84 85 85 RpUnits::define(fahrenheit, celcius, fahrenheit2centigrade, centigrade2fahrenheit); … … 155 155 printf ("=============== TEST 4.4 ===============\n"); 156 156 157 RpUnits * millimeter = RpUnits::find("mm");158 RpUnits * micrometer = RpUnits::find("um");159 RpUnits * nanometer = RpUnits::find("nm");160 RpUnits * picometer = RpUnits::find("pm");161 RpUnits * femtometer = RpUnits::find("fm");162 RpUnits * attometer = RpUnits::find("am");163 RpUnits * kilometer = RpUnits::find("km");164 RpUnits * megameter = RpUnits::find("Mm");165 RpUnits * gigameter = RpUnits::find("Gm");166 RpUnits * terameter = RpUnits::find("Tm");167 RpUnits * petameter = RpUnits::find("Pm");157 const RpUnits * millimeter = RpUnits::find("mm"); 158 const RpUnits * micrometer = RpUnits::find("um"); 159 const RpUnits * nanometer = RpUnits::find("nm"); 160 const RpUnits * picometer = RpUnits::find("pm"); 161 const RpUnits * femtometer = RpUnits::find("fm"); 162 const RpUnits * attometer = RpUnits::find("am"); 163 const RpUnits * kilometer = RpUnits::find("km"); 164 const RpUnits * megameter = RpUnits::find("Mm"); 165 const RpUnits * gigameter = RpUnits::find("Gm"); 166 const RpUnits * terameter = RpUnits::find("Tm"); 167 const RpUnits * petameter = RpUnits::find("Pm"); 168 168 169 169 value = 1.0e+3; … … 256 256 257 257 258 RpUnits* eV = RpUnits::define("eV", NULL);259 RpUnits* joules = RpUnits::define("J", NULL);258 const RpUnits* eV = RpUnits::define("eV", NULL); 259 const RpUnits* joules = RpUnits::define("J", NULL); 260 260 261 261 RpUnits::define(eV, joules, electronVolt2joule, joule2electronVolt);
Note: See TracChangeset
for help on using the changeset viewer.