Changeset 76
- Timestamp:
- Sep 29, 2005 11:45:32 AM (15 years ago)
- Location:
- trunk
- Files:
-
- 6 added
- 6 deleted
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/cee/RpUnitsCInterface.h
r19 r76 30 30 31 31 // convert functions 32 const char* convert_str( RpUnits* fromUnits, 32 33 const char* convert ( const char* fromVal, 34 const char* toUnitsName, 35 int showUnits, 36 int* result ); 37 38 const char* convert_str ( const char* fromVal, 39 const char* toUnitsName, 40 int showUnits, 41 int* result ); 42 43 const char* convert_obj_str ( RpUnits* fromUnits, 44 RpUnits* toUnits, 45 double val, 46 int showUnits ); 47 48 const char* convert_obj_str_result( RpUnits* fromUnits, 49 RpUnits* toUnits, 50 double val, 51 int showUnits, 52 int* result ); 53 54 double convert_dbl ( const char* fromVal, 55 const char* toUnitsName, 56 int* result ); 57 58 double convert_obj_double ( RpUnits* fromUnits, 33 59 RpUnits* toUnits, 34 double val, 35 int showUnits ); 36 37 const char* convert_str_result( RpUnits* fromUnits, 38 RpUnits* toUnits, 39 double val, 40 int showUnits, 41 int* result ); 60 double val ); 42 61 43 double convert_double(RpUnits* fromUnits, RpUnits* toUnits, double val); 62 double convert_obj_double_result ( RpUnits* fromUnits, 63 RpUnits* toUnits, 64 double val, 65 int* result ); 44 66 45 double convert_double_result( RpUnits* fromUnits, 46 RpUnits* toUnits, 47 double val, 48 int* result ); 49 67 int add_presets(const char* presetName); 50 68 51 69 #ifdef __cplusplus -
trunk/include/core/RpUnits.h
r73 r76 321 321 322 322 }; 323 323 324 /* 325 RpUnits& operator= (const RpUnits& myRpUnit) { 326 327 if ( this != &myRpUnit ) { 328 delete head; 329 delete convList; 330 delete conv; 331 } 332 } 333 */ 334 324 335 private: 325 336 … … 348 359 349 360 // dictionary to store the units. 350 // dict pointer351 // static RpDict<std::string,RpUnits*> dict;352 361 static RpDict<std::string,RpUnits*>* dict; 353 362 … … 359 368 // of the units (the fundamental unit) 360 369 // 370 371 372 361 373 RpUnits ( 362 374 const std::string& units, … … 372 384 // create a conversion element 373 385 386 387 388 374 389 RpUnits ( 375 390 RpUnits* from, … … 389 404 }; 390 405 406 407 408 409 391 410 RpUnits ( 392 411 RpUnits* from, … … 414 433 // default destructor 415 434 // 416 //~RpUnits ();417 435 ~RpUnits () 418 436 { -
trunk/src/Makefile
r73 r76 27 27 # 28 28 CC = gcc 29 C PP= g++29 CXX = g++ 30 30 DEBUG = -g -Wall 31 31 DEBUG_PLUS = -g -DDEBUG … … 93 93 #### librappture shared object ########################################### 94 94 95 librappture: rappture_fortran.o rappture_interface.o RpUnitsCInterface.o RpUnits Std.o RpUnits.o96 $(C PP) $(DEGUG) -shared -Wl,-rpath,$(LIB_DIR)/ \95 librappture: rappture_fortran.o rappture_interface.o RpUnitsCInterface.o RpUnitsFInterface.o RpFortranCommon.o RpUnitsStd.o RpUnits.o 96 $(CXX) $(DEGUG) -shared -Wl,-rpath,$(LIB_DIR)/ \ 97 97 -Wl,-soname,$@.so -o $(LIB_DIR)/$@.so.0.0 $^ $(EMB_PY_FLAGS) 98 98 … … 102 102 #### libRpObjects ######################################################## 103 103 libRpObjects: RpVariable.o RpAbout.o RpNumber.o RpString.o RpBoolean.o RpChoice.o RpOption.o RpUnitsStd.o RpUnits.o 104 $(C PP) $(DEGUG) -shared -Wl,-rpath,$(LIB_DIR)/ \104 $(CXX) $(DEGUG) -shared -Wl,-rpath,$(LIB_DIR)/ \ 105 105 -Wl,-soname,$@.so -o $(LIB_DIR)/$@.so.0.0 $^ -lc 106 106 … … 110 110 # include core source files 111 111 112 Rp%.o: $(CORE_SRC)/Rp%.cc 113 $(CPP) -fPIC $(DEBUG) $(INCL_CORE) -o $@ -c $? 112 RpVariable.o: $(CORE_SRC)/RpVariable.cc 113 $(CXX) -fPIC $(DEBUG) $(INCL_CORE) -o $@ -c $? 114 115 RpAbout.o: $(CORE_SRC)/RpAbout.cc 116 $(CXX) -fPIC $(DEBUG) $(INCL_CORE) -o $@ -c $? 117 118 RpNumber.o: $(CORE_SRC)/RpNumber.cc 119 $(CXX) -fPIC $(DEBUG) $(INCL_CORE) -o $@ -c $? 120 121 RpString.o: $(CORE_SRC)/RpString.cc 122 $(CXX) -fPIC $(DEBUG) $(INCL_CORE) -o $@ -c $? 123 124 RpBoolean.o: $(CORE_SRC)/RpBoolean.cc 125 $(CXX) -fPIC $(DEBUG) $(INCL_CORE) -o $@ -c $? 126 127 RpChoice.o: $(CORE_SRC)/RpChoice.cc 128 $(CXX) -fPIC $(DEBUG) $(INCL_CORE) -o $@ -c $? 129 130 RpOption.o: $(CORE_SRC)/RpOption.cc 131 $(CXX) -fPIC $(DEBUG) $(INCL_CORE) -o $@ -c $? 132 133 RpUnitsStd.o: $(CORE_SRC)/RpUnitsStd.cc 134 $(CXX) -fPIC $(DEBUG) $(INCL_CORE) -o $@ -c $? 135 136 RpUnits.o: $(CORE_SRC)/RpUnits.cc 137 $(CXX) -fPIC $(DEBUG) $(INCL_CORE) -o $@ -c $? 138 139 140 114 141 115 142 # include cee binding definitions 116 143 117 144 rappture_interface.o: $(CEE_SRC)/rappture_interface.c 118 $(C PP) -fPIC $(DEBUG) $(INCL_CEE) $(INCL_PY) -o $@ -c $<145 $(CXX) -fPIC $(DEBUG) $(INCL_CEE) $(INCL_PY) -o $@ -c $< 119 146 120 147 RpUnitsCInterface.o: $(CEE_SRC)/RpUnitsCInterface.cc 121 $(CPP) $(CFLAGS) -fPIC $(DEBUG) $(INCL_CORE) $(INCL_CEE) -o $@ -c $? 148 $(CXX) $(CFLAGS) -fPIC $(DEBUG) $(INCL_CORE) $(INCL_CEE) -o $@ -c $? 149 150 151 122 152 123 153 # include fortran binding definitions 124 154 125 RpUnits_fortran.o: $(FORT_SRC)/RpUnits_fortran.c126 $(C PP) $(CFLAGS) -fPIC $(DEBUG) $(INCL_CORE) -o $@ -c $?155 rappture_fortran.o: $(FORT_SRC)/rappture_fortran.c 156 $(CXX) $(CFLAGS) -fPIC $(DEBUG) $(INCL_FORTRAN) $(INCL_CORE) $(INCL_CEE) $(INCL_PY) -o $@ -c $< 127 157 128 rappture_fortran.o: $(FORT_SRC)/rappture_fortran.c 129 $(CPP) $(CFLAGS) -fPIC $(DEBUG) $(INCL_CORE) $(INCL_CEE) $(INCL_PY) -o $@ -c $< 158 RpUnitsFInterface.o: $(FORT_SRC)/RpUnitsFInterface.cc 159 $(CXX) $(CFLAGS) -fPIC $(DEBUG) $(INCL_CORE) $(INCL_FORTRAN) -o $@ -c $? 160 161 RpFortranCommon.o: $(FORT_SRC)/RpFortranCommon.c 162 $(CC) $(CFLAGS) -fPIC $(DEBUG) $(INCL_FORTRAN) -o $@ -c $< 163 164 165 130 166 131 167 #### CLEAN UP ############################################################ -
trunk/src/cee/RpUnitsCInterface.cc
r21 r76 6 6 #endif 7 7 8 RpUnits* defineUnit(const char* unitSymbol, RpUnits* basis) 9 {8 RpUnits* defineUnit(const char* unitSymbol, RpUnits* basis) { 9 10 10 return RpUnits::define(unitSymbol, basis); 11 11 } … … 14 14 RpUnits* toUnit, 15 15 double (*convForwFxnPtr)(double), 16 double (*convBackFxnPtr)(double) ) 17 { 16 double (*convBackFxnPtr)(double) ) { 17 18 18 return RpUnits::define(fromUnit,toUnit,convForwFxnPtr,convBackFxnPtr); 19 19 } 20 20 21 RpUnits* find(const char* key) 22 {21 RpUnits* find(const char* key) { 22 23 23 return RpUnits::find(key); 24 24 } 25 25 26 const char* getUnits(RpUnits* unit) 27 { 28 return unit->getUnits().c_str(); 26 const char* getUnits(RpUnits* unit) { 27 28 static std::string retVal; 29 retVal = unit->getUnits(); 30 return retVal.c_str(); 29 31 } 30 32 31 const char* getUnitsName(RpUnits* unit) 32 { 33 return unit->getUnitsName().c_str(); 33 const char* getUnitsName(RpUnits* unit) { 34 35 static std::string retVal; 36 retVal = unit->getUnitsName(); 37 return retVal.c_str(); 34 38 } 35 39 36 double getExponent(RpUnits* unit) 37 { 40 double getExponent(RpUnits* unit) { 41 38 42 return unit->getExponent(); 39 43 } 40 44 41 RpUnits* getBasis(RpUnits* unit) 42 {45 RpUnits* getBasis(RpUnits* unit) { 46 43 47 return unit->getBasis(); 44 48 } 45 49 46 int makeMetric(RpUnits* basis) 47 { 50 int makeMetric(RpUnits* basis) { 51 48 52 return RpUnits::makeMetric(basis); 49 53 } 50 54 51 const char* convert_str( RpUnits* fromUnits, 52 RpUnits* toUnits, 53 double val, 54 int showUnits ) 55 { 56 return convert_str_result(fromUnits,toUnits,val,showUnits,NULL); 55 const char* convert ( const char* fromVal, 56 const char* toUnitsName, 57 int showUnits, 58 int* result ) { 59 60 static std::string retVal; 61 retVal = RpUnits::convert(fromVal,toUnitsName,showUnits,result); 62 return retVal.c_str(); 63 } 64 65 const char* convert_str ( const char* fromVal, 66 const char* toUnitsName, 67 int showUnits, 68 int* result ) { 69 70 static std::string retVal; 71 retVal = RpUnits::convert(fromVal,toUnitsName,showUnits,result); 72 return retVal.c_str(); 73 } 74 75 const char* convert_obj_str( RpUnits* fromUnits, 76 RpUnits* toUnits, 77 double val, 78 int showUnits ) { 79 80 return convert_obj_str_result(fromUnits,toUnits,val,showUnits,NULL); 57 81 } 58 82 59 const char* convert_str_result( RpUnits* fromUnits, 60 RpUnits* toUnits, 61 double val, 62 int showUnits, 63 int* result ) 64 { 65 return fromUnits->convert(toUnits,val,showUnits,result).c_str(); 83 const char* convert_obj_str_result( RpUnits* fromUnits, 84 RpUnits* toUnits, 85 double val, 86 int showUnits, 87 int* result ) { 88 89 static std::string retVal; 90 retVal = fromUnits->convert(toUnits,val,showUnits,result); 91 return retVal.c_str(); 66 92 } 67 93 68 double convert_double(RpUnits* fromUnits, RpUnits* toUnits, double val) 69 { 70 return convert_double_result(fromUnits,toUnits,val,NULL); 94 double convert_dbl ( const char* fromVal, 95 const char* toUnitsName, 96 int* result ) { 97 98 std::string convStr; 99 double retVal = 0.0; 100 101 convStr = RpUnits::convert(fromVal,toUnitsName,0,result); 102 103 if (!convStr.empty()) { 104 retVal = atof(convStr.c_str()); 105 } 106 107 return retVal; 71 108 } 72 109 73 double convert_double_result( RpUnits* fromUnits, 74 RpUnits* toUnits, 75 double val, 76 int* result ) 77 { 110 double convert_obj_double( RpUnits* fromUnits, 111 RpUnits* toUnits, 112 double val ) { 113 114 return convert_obj_double_result(fromUnits,toUnits,val,NULL); 115 } 116 117 double convert_obj_double_result( RpUnits* fromUnits, 118 RpUnits* toUnits, 119 double val, 120 int* result ) { 121 78 122 return fromUnits->convert(toUnits,val,result); 123 } 124 125 int add_presets ( const char* presetName ) { 126 127 return RpUnits::addPresets(presetName); 79 128 } 80 129 -
trunk/src/core/RpUnits.cc
r73 r76 511 511 { 512 512 return head->getExponent(); 513 return 0;514 513 } 515 514 … … 792 791 if (this->getUnits() == toUnit->getUnits()) { 793 792 if (result) { 794 *result = 1;793 *result = 0; 795 794 } 796 795 return val; … … 843 842 value = p->conv->convForwFxnPtr(value); 844 843 if (result) { 845 *result = 1;844 *result = 0; 846 845 } 847 846 break; … … 854 853 value = p->conv->convBackFxnPtr(value); 855 854 if (result) { 856 *result = 1;855 *result = 0; 857 856 } 858 857 break; … … 898 897 if (this->getUnits() == toUnit->getUnits()) { 899 898 if (result) { 900 *result = 1;899 *result = 0; 901 900 } 902 901 return val; … … 950 949 951 950 if (result) { 952 *result = 1;951 *result = 0; 953 952 } 954 953 break; … … 961 960 value = p->conv->convBackFxnPtrVoid(p->conv->convBackData,value); 962 961 if (result) { 963 *result = 1;962 *result = 0; 964 963 } 965 964 break; … … 1147 1146 int 1148 1147 RpUnits::addPresets (std::string group) { 1149 int retVal = 1;1148 int retVal = -1; 1150 1149 if (group.compare("all") == 0) { 1151 1150 retVal = addPresetAll(); … … 1171 1170 RpUnits::addPresetAll () { 1172 1171 1173 1174 addPresetTime(); 1175 addPresetTemp(); 1176 addPresetLength(); 1177 addPresetEnergy(); 1172 int result = 0; 1173 1174 result += addPresetTime(); 1175 result += addPresetTemp(); 1176 result += addPresetLength(); 1177 result += addPresetEnergy(); 1178 1178 1179 1179 return 0; -
trunk/src/fortran/rappture_fortran.c
r66 r76 1 1 #include "rappture_interface.h" 2 #include "RpFortranCommon.h" 2 3 #include "RpDict.h" 3 4 #include <string.h> … … 294 295 int storeObject(PyObject* objectName); 295 296 PyObject* getObject(int objKey); 296 char* null_terminate(char* inStr, int len);297 // char* null_terminate(char* inStr, int len); 297 298 298 299 // global vars … … 483 484 ) 484 485 { 485 int length_in = 0;486 int length_out = 0;487 int i = 0;486 // int length_in = 0; 487 // int length_out = 0; 488 // int i = 0; 488 489 const char* xmlText = NULL; 489 490 … … 509 510 xmlText = retObj; 510 511 512 fortranify(xmlText, retText, retText_len); 513 514 /* 511 515 length_in = strlen(xmlText); 512 516 length_out = retText_len; … … 521 525 } 522 526 *(retText+length_out-1) = ' '; 527 */ 523 528 524 529 free(retObj); … … 768 773 { 769 774 int retVal = 0; 770 int i = 0;771 int length_in = 0;775 // int i = 0; 776 // int length_in = 0; 772 777 773 778 PyObject* lib = NULL; … … 802 807 // printf("xmlChild = :%s:\n",xmlChild); 803 808 if (xmlChild) { 809 fortranify(xmlChild, retText, retText_len); 810 811 /* 804 812 strncpy(retText, xmlChild, retText_len); 805 813 length_in = strlen(xmlChild); … … 812 820 } 813 821 // *(retText+retText_len-1) = ' '; 822 */ 814 823 } 815 824 } … … 901 910 ) 902 911 { 903 int length_in = 0;904 int length_out = 0;905 int i = 0;912 // int length_in = 0; 913 // int length_out = 0; 914 // int i = 0; 906 915 const char* xmlText = NULL; 907 916 … … 923 932 if (xmlText) { 924 933 934 fortranify(xmlText, retText, retText_len); 935 936 /* 925 937 length_in = strlen(xmlText); 926 938 length_out = retText_len; … … 935 947 } 936 948 *(retText+length_out-1) = ' '; 949 */ 937 950 } 938 951 … … 1210 1223 void rp_lib_xml(int* handle, char* retText, int retText_len) 1211 1224 { 1212 int length_in = 0;1213 int length_out = 0;1214 int i = 0;1225 // int length_in = 0; 1226 // int length_out = 0; 1227 // int i = 0; 1215 1228 char* xmlText = NULL; 1216 1229 … … 1225 1238 1226 1239 if (xmlText) { 1240 1241 fortranify(xmlText, retText, retText_len); 1242 1243 /* 1227 1244 length_in = strlen(xmlText); 1228 1245 length_out = retText_len; … … 1237 1254 } 1238 1255 *(retText+length_out-1) = ' '; 1256 */ 1239 1257 1240 1258 free(xmlText); … … 1380 1398 1381 1399 } 1382 1383 /* fix buffer overflow possibility*/1384 char* null_terminate(char* inStr, int len)1385 {1386 int retVal = 0;1387 char* newStr = NULL;1388 char* current = NULL;1389 1390 if (inStr) {1391 1392 current = inStr+len-1;1393 1394 while ((len > 0) && (isspace(*(current)))) {1395 // dont strip off newlines1396 1397 if ( (*(current) == '\f')1398 || (*(current) == '\n')1399 || (*(current) == '\r')1400 || (*(current) == '\t')1401 || (*(current) == '\v') )1402 {1403 break;1404 }1405 1406 if (--len) {1407 current--;1408 }1409 }1410 1411 newStr = (char*) calloc(len+1,(sizeof(char)));1412 strncpy(newStr,inStr,len);1413 *(newStr+len) = '\0';1414 1415 retVal++;1416 }1417 1418 // return retVal;1419 1420 return newStr;1421 } -
trunk/test/src/RpUnitsC_test.c
r40 r76 1 //---------------------------------------------------------------------- 2 // TEST: Cee's interface to RpUnits. 3 // 4 // Basic units conversion tests for the RpUnits portion of Rappture 5 // written in Cee. 6 //====================================================================== 7 // AUTHOR: Derrick Kearney, Purdue University 8 // Copyright (c) 2004-2005 9 // Purdue Research Foundation, West Lafayette, IN 10 //====================================================================== 11 // 1 12 #include "RpUnitsCInterface.h" 2 13 #include <stdio.h> … … 63 74 int showUnits = 0; 64 75 65 const char* nm_conv_str; 76 const char* nm_conv_str = NULL; 77 const char* retStr = NULL; 66 78 67 79 makeMetric(meters); … … 92 104 if (nanometers) { 93 105 94 nm_conv = convert_ double_result(nanometers,meters,1.0e9,&result);106 nm_conv = convert_obj_double_result(nanometers,meters,1.0e9,&result); 95 107 printf("1.0e9 nm = %f m\tresult = %d\n",nm_conv,result); 96 108 97 nm_conv = convert_ double(nanometers,meters,1.0e9);109 nm_conv = convert_obj_double(nanometers,meters,1.0e9); 98 110 printf("1.0e9 nm = %f m\n",nm_conv); 99 111 100 112 showUnits = 1; 101 nm_conv_str = convert_ str(nanometers,meters,1.588e9,showUnits);113 nm_conv_str = convert_obj_str(nanometers,meters,1.588e9,showUnits); 102 114 printf("1.588e9 nm = %s\n",nm_conv_str); 103 115 104 116 showUnits = 0; 105 nm_conv_str = convert_ str(nanometers,meters,1.588e9,showUnits);117 nm_conv_str = convert_obj_str(nanometers,meters,1.588e9,showUnits); 106 118 printf("1.588e9 nm = %s\n",nm_conv_str); 107 119 } … … 111 123 112 124 if (meters && angstrom && centimeters) { 113 value = convert_ double_result(angstrom,meters,1.0,&result);125 value = convert_obj_double_result(angstrom,meters,1.0,&result); 114 126 printf("1 angstrom = %e meters\n",value); 115 127 116 value = convert_ double_result(centimeters,angstrom,1e-8,&result);128 value = convert_obj_double_result(centimeters,angstrom,1e-8,&result); 117 129 printf("1.0e-8 centimeter = %f angstroms\n",value); 118 130 } … … 123 135 124 136 if (fahrenheit && celcius) { 125 value = convert_ double_result(fahrenheit,celcius,72,&result);137 value = convert_obj_double_result(fahrenheit,celcius,72,&result); 126 138 printf("72 degrees fahrenheit = %f degrees celcius\n",value); 127 139 128 value = convert_ double_result(celcius,fahrenheit,value,&result);140 value = convert_obj_double_result(celcius,fahrenheit,value,&result); 129 141 printf("22.222 degrees celcius = %f degrees fahrenheit\n",value); 130 142 } … … 134 146 135 147 if (celcius && kelvin) { 136 value = convert_ double_result(celcius,kelvin,20,&result);148 value = convert_obj_double_result(celcius,kelvin,20,&result); 137 149 printf("20 degrees celcius = %f kelvin\n",value); 138 150 139 value = convert_ double_result(kelvin,celcius,300,&result);151 value = convert_obj_double_result(kelvin,celcius,300,&result); 140 152 printf("300 kelvin = %f degrees celcius\n", value); 141 153 } … … 144 156 } 145 157 158 printf("====== adding all preset units ======\n"); 159 add_presets("all"); 160 161 printf("====== TESTING STATIC CONVERT FXNS ======\n"); 162 163 retStr = convert("72F","C",1,&result); 164 printf("72F = %s\tresult = %d\n", retStr,result); 165 166 retStr = convert("300K","F",1,&result); 167 printf("300K = %s\tresult = %d\n", retStr,result); 168 169 retStr = convert("1eV","J",0,&result); 170 printf("1eV = %s (no units)\tresult = %d\n", retStr,result); 171 172 retStr = convert_str("300K","R",1,&result); 173 printf("300K = %s\tresult = %d\n", retStr,result); 174 175 retStr = convert_str("5m","ft",1,&result); 176 printf("5m = %s\tresult = %d\n", retStr,result); 177 178 value = convert_dbl("5000mV","V",&result); 179 printf("5V = %f (double value)\n", value); 180 181 146 182 return 0; 147 183 }
Note: See TracChangeset
for help on using the changeset viewer.