Changeset 103
- Timestamp:
- Oct 13, 2005 3:25:45 PM (19 years ago)
- Location:
- trunk/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/Makefile
r101 r103 87 87 librappture: $(RP_IO_DEPS) $(RP_UNITS_DEPS) $(RP_OTHER_DEPS) 88 88 $(CXX) $(DEGUG) -shared -Wl,-rpath,$(LIB_DIR)/ \ 89 -Wl,-soname,$@.so -o $(LIB_DIR)/$@.so.0.0 $^ $(LIB_SCEW_FLAG) 89 -Wl,-soname,$@.so -o $(LIB_DIR)/$@.so.0.0 $^ $(LIB_SCEW_FLAG) -lm 90 90 91 91 /sbin/ldconfig -n $(LIB_DIR) -
trunk/src/core/RpUnits.cc
r102 r103 444 444 RpUnits * RpUnits::define( RpUnits* from, 445 445 RpUnits* to, 446 double (*convForwFxnPtr)(double,double), 447 double (*convBackFxnPtr)(double,double)) 448 { 449 RpUnits* conv = new RpUnits( from, 450 to, 451 convForwFxnPtr, 452 convBackFxnPtr, 453 NULL, 454 NULL); 455 456 return conv; 457 } 458 459 RpUnits * RpUnits::define( RpUnits* from, 460 RpUnits* to, 446 461 void* (*convForwFxnPtr)(void*, void*), 447 462 void* convForwData, … … 601 616 * 602 617 * **********************************************************************/ 618 /* 603 619 int RpUnits::makeMetric(RpUnits * basis) { 604 620 … … 661 677 return (1); 662 678 } 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 { 746 // dict.find seems to return a (RpUnits* const) so i had to 747 // cast it as a (RpUnits*) 748 749 // dict pointer 750 RpUnits* unitEntry = (RpUnits*) *(dict->find(key).getValue()); 751 752 // dict pointer 753 if (unitEntry == (RpUnits*)dict->getNullEntry().getValue()) { 754 unitEntry = NULL; 755 } 756 757 return unitEntry; 758 } 759 663 760 664 761 // convert function so people can just send in two strings and … … 768 865 769 866 if (showUnits) { 770 unitText << retVal << toUnits->getUnits ();867 unitText << retVal << toUnits->getUnitsName(); 771 868 } 772 869 else { … … 804 901 // guard against converting to the units you are converting from... 805 902 // ie. meters->meters 806 if (this->getUnits () == toUnit->getUnits()) {903 if (this->getUnitsName() == toUnit->getUnitsName()) { 807 904 if (result) { 808 905 *result = 0; … … 816 913 // need to rethink this. 817 914 // 818 if ( (basis) && (basis->getUnits () != toUnit->getUnits()) ) {915 if ( (basis) && (basis->getUnitsName() != toUnit->getUnitsName()) ) { 819 916 value = convert(basis,value,&my_result); 820 917 if (my_result == 0) { … … 827 924 // and convert between basis' and then convert again back to the 828 925 // original unit. 829 if ( (toBasis) && (toBasis->getUnits () != fromUnit->getUnits()) ) {830 dictToUnit = find(toBasis->getUnits ());926 if ( (toBasis) && (toBasis->getUnitsName() != fromUnit->getUnitsName()) ) { 927 dictToUnit = find(toBasis->getUnitsName()); 831 928 } 832 929 else { 833 dictToUnit = find(toUnit->getUnits ());930 dictToUnit = find(toUnit->getUnitsName()); 834 931 } 835 932 … … 862 959 // call the function pointer with value 863 960 864 value = p->conv->convForwFxnPtr(value); 961 // this should probably be re thought out 962 // the problem is that convForwFxnPtr has the conversion for a 963 // one arg conv function pointer and convForwFxnPtrDD has the 964 // conversion for a two arg conv function pointer 965 // need to make this simpler, more logical maybe only allow 2 arg 966 if ( (p->conv->convForwFxnPtr) 967 && (! p->conv->convForwFxnPtrDD) ) { 968 969 value = p->conv->convForwFxnPtr(value); 970 } 971 else if ( (p->conv->convForwFxnPtrDD) 972 && (! p->conv->convForwFxnPtr) ) { 973 974 value = 975 p->conv->convForwFxnPtrDD(value, fromUnit->getExponent()); 976 } 865 977 866 978 // check to see if we converted to the actual requested unit … … 869 981 // do one last conversion from the requested unit's basis back 870 982 // to the requested unit. 871 if ( (toBasis) && (toBasis->getUnits () != fromUnit->getUnits()) ) {983 if ( (toBasis) && (toBasis->getUnitsName() != fromUnit->getUnitsName()) ) { 872 984 my_result = 0; 873 985 value = toBasis->convert(toUnit,value,&my_result); … … 890 1002 // call the function pointer with value 891 1003 892 value = p->conv->convBackFxnPtr(value); 1004 // this should probably be re thought out 1005 // the problem is that convForwFxnPtr has the conversion for a 1006 // one arg conv function pointer and convForwFxnPtrDD has the 1007 // conversion for a two arg conv function pointer 1008 // need to make this simpler, more logical maybe only allow 2 arg 1009 if ( (p->conv->convBackFxnPtr) 1010 && (! p->conv->convBackFxnPtrDD) ) { 1011 1012 value = p->conv->convBackFxnPtr(value); 1013 } 1014 else if ( (p->conv->convBackFxnPtrDD) 1015 && (! p->conv->convBackFxnPtr) ) { 1016 1017 value = 1018 p->conv->convBackFxnPtrDD(value, fromUnit->getExponent()); 1019 } 893 1020 894 1021 // check to see if we converted to the actual requested unit … … 897 1024 // do one last conversion from the requested unit's basis back 898 1025 // to the requested unit. 899 if ( (toBasis) && (toBasis->getUnits () != fromUnit->getUnits()) ) {1026 if ( (toBasis) && (toBasis->getUnitsName() != fromUnit->getUnitsName()) ) { 900 1027 my_result = 0; 901 1028 value = toBasis->convert(toUnit,value,&my_result); … … 955 1082 // guard against converting to the units you are converting from... 956 1083 // ie. meters->meters 957 if (this->getUnits () == toUnit->getUnits()) {1084 if (this->getUnitsName() == toUnit->getUnitsName()) { 958 1085 if (result) { 959 1086 *result = 0; … … 967 1094 // need to rethink this. 968 1095 // 969 if ( (basis) && (basis->getUnits () != toUnit->getUnits()) ) {1096 if ( (basis) && (basis->getUnitsName() != toUnit->getUnitsName()) ) { 970 1097 value = convert(basis,value,&my_result); 971 1098 if (my_result == 0) { … … 978 1105 // and convert between basis' and then convert again back to the 979 1106 // original unit. 980 if ( (toBasis) && (toBasis->getUnits () != fromUnit->getUnits()) ) {981 dictToUnit = find(toBasis->getUnits ());1107 if ( (toBasis) && (toBasis->getUnitsName() != fromUnit->getUnitsName()) ) { 1108 dictToUnit = find(toBasis->getUnitsName()); 982 1109 } 983 1110 else { 984 dictToUnit = find(toUnit->getUnits ());1111 dictToUnit = find(toUnit->getUnitsName()); 985 1112 } 986 1113 … … 1020 1147 // do one last conversion from the requested unit's basis back 1021 1148 // to the requested unit. 1022 if ( (toBasis) && (toBasis->getUnits () != fromUnit->getUnits()) ) {1149 if ( (toBasis) && (toBasis->getUnitsName() != fromUnit->getUnitsName()) ) { 1023 1150 my_result = 0; 1024 1151 value = toBasis->convert(toUnit,value,&my_result); … … 1048 1175 // do one last conversion from the requested unit's basis back 1049 1176 // to the requested unit. 1050 if ( (toBasis) && (toBasis->getUnits () != fromUnit->getUnits()) ) {1177 if ( (toBasis) && (toBasis->getUnitsName() != fromUnit->getUnitsName()) ) { 1051 1178 my_result = 0; 1052 1179 value = toBasis->convert(toUnit,value,&my_result); … … 1279 1406 result += addPresetLength(); 1280 1407 result += addPresetEnergy(); 1408 result += addPresetVolume(); 1281 1409 1282 1410 return 0; … … 1353 1481 } 1354 1482 1483 // return codes: 0 success, anything else is error 1484 int 1485 RpUnits::addPresetVolume () { 1486 1487 RpUnits* cubic_meter = RpUnits::define("m3", NULL); 1488 RpUnits* cubic_feet = RpUnits::define("ft3", NULL); 1489 RpUnits* us_gallon = RpUnits::define("gal", NULL); 1490 1491 RpUnits::makeMetric(cubic_meter); 1492 1493 // add energy definitions 1494 RpUnits::define(cubic_meter,cubic_feet,meter2feet,feet2meter); 1495 RpUnits::define(cubic_meter,us_gallon,cubicMeter2usGallon,usGallon2cubicMeter); 1496 RpUnits::define(cubic_feet,us_gallon,cubicFeet2usGallon,usGallon2cubicFeet); 1497 1498 return 0; 1499 } 1500 1355 1501 // -------------------------------------------------------------------- // 1356 1502 -
trunk/src/core/RpUnitsStd.cc
r83 r103 1 #include <RpUnitsStd.h> 2 #include <math.h> 3 1 4 #ifdef __cplusplus 2 5 extern "C" { … … 7 10 ****************************************/ 8 11 9 double centi2base (double centi) 10 { 11 return centi*1e-2; 12 } 13 14 double milli2base (double milli) 15 { 16 return milli*1e-3; 17 } 18 19 double micro2base (double micro) 20 { 21 return micro*1e-6; 22 } 23 24 double nano2base (double nano) 25 { 26 return nano*1e-9; 27 } 28 29 double pico2base (double pico) 30 { 31 return pico*1e-12; 32 } 33 34 double femto2base (double femto) 35 { 36 return femto*1e-15; 37 } 38 39 double atto2base (double atto) 40 { 41 return atto*1e-18; 42 } 43 44 double kilo2base (double kilo) 45 { 46 return kilo*1e3; 47 } 48 49 double mega2base (double mega) 50 { 51 return mega*1e6; 52 } 53 54 double giga2base (double giga) 55 { 56 return giga*1e9; 57 } 58 59 double tera2base (double tera) 60 { 61 return tera*1e12; 62 } 63 64 double peta2base (double peta) 65 { 66 return peta*1e15; 67 } 68 69 double base2centi (double base) 70 { 71 return base*1e2; 72 } 73 74 double base2milli (double base) 75 { 76 return base*1e3; 77 } 78 79 double base2micro (double base) 80 { 81 return base*1e6; 82 } 83 84 double base2nano (double base) 85 { 86 return base*1e9; 87 } 88 89 double base2pico (double base) 90 { 91 return base*1e12; 92 } 93 94 double base2femto (double base) 95 { 96 return base*1e15; 97 } 98 99 double base2atto (double base) 100 { 101 return base*1e18; 102 } 103 104 double base2kilo (double base) 105 { 106 return base*1e-3; 107 } 108 109 double base2mega (double base) 110 { 111 return base*1e-6; 112 } 113 114 double base2giga (double base) 115 { 116 return base*1e-9; 117 } 118 119 double base2tera (double base) 120 { 121 return base*1e-12; 122 } 123 124 double base2peta (double base) 125 { 126 return base*1e-15; 127 } 128 129 12 13 double centi2base (double centi, double power) 14 { 15 return centi*pow(1e-2,power); 16 } 17 18 double milli2base (double milli, double power) 19 { 20 return milli*pow(1e-3,power); 21 } 22 23 double micro2base (double micro, double power) 24 { 25 return micro*pow(1e-6,power); 26 } 27 28 double nano2base (double nano, double power) 29 { 30 return nano*pow(1e-9,power); 31 } 32 33 double pico2base (double pico, double power) 34 { 35 return pico*pow(1e-12,power); 36 } 37 38 double femto2base (double femto, double power) 39 { 40 return femto*pow(1e-15,power); 41 } 42 43 double atto2base (double atto, double power) 44 { 45 return atto*pow(1e-18,power); 46 } 47 48 double kilo2base (double kilo, double power) 49 { 50 return kilo*pow(1e3,power); 51 } 52 53 double mega2base (double mega, double power) 54 { 55 return mega*pow(1e6,power); 56 } 57 58 double giga2base (double giga, double power) 59 { 60 return giga*pow(1e9,power); 61 } 62 63 double tera2base (double tera, double power) 64 { 65 return tera*pow(1e12,power); 66 } 67 68 double peta2base (double peta, double power) 69 { 70 return peta*pow(1e15,power); 71 } 72 73 double base2centi (double base, double power) 74 { 75 return base*pow(1e2,power); 76 } 77 78 double base2milli (double base, double power) 79 { 80 return base*pow(1e3,power); 81 } 82 83 double base2micro (double base, double power) 84 { 85 return base*pow(1e6,power); 86 } 87 88 double base2nano (double base, double power) 89 { 90 return base*pow(1e9,power); 91 } 92 93 double base2pico (double base, double power) 94 { 95 return base*pow(1e12,power); 96 } 97 98 double base2femto (double base, double power) 99 { 100 return base*pow(1e15,power); 101 } 102 103 double base2atto (double base, double power) 104 { 105 return base*pow(1e18,power); 106 } 107 108 double base2kilo (double base, double power) 109 { 110 return base*pow(1e-3,power); 111 } 112 113 double base2mega (double base, double power) 114 { 115 return base*pow(1e-6,power); 116 } 117 118 double base2giga (double base, double power) 119 { 120 return base*pow(1e-9,power); 121 } 122 123 double base2tera (double base, double power) 124 { 125 return base*pow(1e-12,power); 126 } 127 128 double base2peta (double base, double power) 129 { 130 return base*pow(1e-15,power); 131 } 130 132 131 133 /**************************************** … … 135 137 ****************************************/ 136 138 137 double angstrom2meter (double angstrom )138 { 139 return angstrom* 1.0e-10;140 } 141 142 double meter2angstrom (double meters )143 { 144 return meters* 1.0e10;145 } 146 147 double meter2inch (double m )148 { 149 return (m* 39.37008);150 } 151 152 double inch2meter (double in )153 { 154 return (in/ 39.37008);155 } 156 157 double meter2feet (double m )158 { 159 return (m* 3.280840);160 } 161 162 double feet2meter (double ft )163 { 164 return (ft/ 3.280840);165 } 166 167 double meter2yard (double m )168 { 169 return (m* 1.093613);170 } 171 172 double yard2meter (double yd )173 { 174 return (yd/ 1.093613);139 double angstrom2meter (double angstrom, double power) 140 { 141 return angstrom*(pow(1.0e-10,power)); 142 } 143 144 double meter2angstrom (double meters, double power) 145 { 146 return meters*(pow(1.0e10,power)); 147 } 148 149 double meter2inch (double m, double power) 150 { 151 return (m*(pow(39.37008,power))); 152 } 153 154 double inch2meter (double in, double power) 155 { 156 return (in/(pow(39.37008,power))); 157 } 158 159 double meter2feet (double m, double power) 160 { 161 return (m*(pow(3.280840,power))); 162 } 163 164 double feet2meter (double ft, double power) 165 { 166 return (ft/(pow(3.280840,power))); 167 } 168 169 double meter2yard (double m, double power) 170 { 171 return (m*(pow(1.093613,power))); 172 } 173 174 double yard2meter (double yd, double power) 175 { 176 return (yd/(pow(1.093613,power))); 175 177 } 176 178 … … 233 235 } 234 236 237 /**************************************** 238 * MISC VOLUME CONVERSIONS 239 ****************************************/ 240 241 double cubicMeter2usGallon (double m3, double none) 242 { 243 return (m3*264.1721); 244 } 245 246 double usGallon2cubicMeter (double g, double none) 247 { 248 return (g/264.1721); 249 } 250 251 double cubicFeet2usGallon (double ft3, double none) 252 { 253 return (ft3*7.48051); 254 } 255 256 double usGallon2cubicFeet (double g, double none) 257 { 258 return (g/7.48051); 259 } 260 261 235 262 #ifdef __cplusplus 236 263 }
Note: See TracChangeset
for help on using the changeset viewer.