- Timestamp:
- Dec 14, 2006, 9:10:14 AM (18 years ago)
- Location:
- trunk/src/tcl
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/tcl/src/RpUnitsTclInterface.cc
r549 r560 53 53 54 54 55 static int list2str (std::list<std::string>& inList, std::string& outString);56 55 57 56 … … 113 112 { 114 113 std::string inValue = ""; // value provided by the user 114 std::string origUnitsName = ""; 115 115 std::string fromUnitsName = ""; // name of the units for user's value 116 116 std::string toUnitsName = ""; // name of the units to convert to … … 158 158 fromUnitsName = std::string(argv[nextarg]); 159 159 err = 0; 160 origUnitsName = fromUnitsName; 160 161 err = RpUnits::validate(fromUnitsName,type,&compatList); 161 162 if ( err != 0) { 162 163 Tcl_AppendResult(interp, 163 "bad value \"", fromUnitsName.c_str(),164 "bad value \"", origUnitsName.c_str(), 164 165 "\": should be a recognized unit for Rappture", 165 166 (char*)NULL); … … 178 179 toUnitsName = std::string(argv[nextarg]); 179 180 err = 0; 181 origUnitsName = toUnitsName; 180 182 err = RpUnits::validate(toUnitsName,type); 181 183 if (err != 0) { 182 184 Tcl_AppendResult(interp, 183 "bad value \"", toUnitsName.c_str(),185 "bad value \"", origUnitsName.c_str(), 184 186 "\": should be a recognized unit for Rappture", 185 187 (char*)NULL); … … 317 319 // const RpUnits* unitsObj = NULL; 318 320 std::list<std::string> compatList; 319 std::list<std::string>::iterator compatListIter;320 321 321 322 int nextarg = 1; // start parsing using the '2'th argument … … 536 537 return TCL_OK; 537 538 } 538 539 /**********************************************************************/540 // FUNCTION: list2str()541 /// Convert a std::list<std::string> into a comma delimited std::string542 /**543 * Iterates through a std::list<std::string> and returns a comma544 * delimited std::string containing the elements of the inputted std::list.545 *546 * Returns 0 on success, anything else is error547 */548 549 int550 list2str (std::list<std::string>& inList, std::string& outString)551 {552 int retVal = 1; // return Value 0 is success, everything else is failure553 unsigned int counter = 0; // check if we hit all elements of inList554 std::list<std::string>::iterator inListIter; // list interator555 556 inListIter = inList.begin();557 558 while (inListIter != inList.end()) {559 if ( outString.empty() ) {560 outString = *inListIter;561 }562 else {563 outString = outString + "," + *inListIter;564 }565 566 // increment the iterator and loop counter567 inListIter++;568 counter++;569 }570 571 if (counter == inList.size()) {572 retVal = 0;573 }574 575 return retVal;576 } -
trunk/src/tcl/tests/units.test
r549 r560 168 168 test convert-1.8.0 {Rappture::Units::convert, convert undefined unit} { 169 169 list [catch {Rappture::Units::convert 33Q -to nm } msg] $msg 170 } {1 {unrecognized units: "Q"}} 170 } {1 {Unrecognized units: "Q". 171 Should be units of type length (A,in,m,nm)}} 171 172 172 173 #---------------------------------------------------------- … … 465 466 test convert_units-5.4.4.2 {Rappture::Units::convert, cm2nZ/Vs->m2/us} { 466 467 list [catch {Rappture::Units::convert 2cm2nZ/Vs -to m2/us} msg] $msg 467 } {1 {unrecognized units: "cm2nZ/Vs"}} 468 } {1 {Unrecognized units: "cm2nZ/Vs". 469 Should be units of type length/time (/s,/us,A2,in2,m2)}} 468 470 469 471 test convert_units-5.4.4.3 {Rappture::Units::convert, cm2/s->m2/kVus} { 470 472 list [catch {Rappture::Units::convert 2cm2/s -to m2/kVus} msg] $msg 471 } {1 {unmatched units in conversion: (kV-1)}} 473 } {1 {unmatched units in conversion: (kV-1) 474 Please enter units of type length/electric_potential*time (/V,/kV,/s,/us,A2,in2,m2)}} 472 475 473 476 test convert_units-5.4.4.4 {Rappture::Units::convert, cm2/s->m2/uskV} { 474 477 list [catch {Rappture::Units::convert 2cm2/s -to m2/uskV} msg] $msg 475 } {1 {unmatched units in conversion: (kV-1)}} 478 } {1 {unmatched units in conversion: (kV-1) 479 Please enter units of type length/time*electric_potential (/V,/kV,/s,/us,A2,in2,m2)}} 476 480 477 481 test convert_units-5.4.4.5 {Rappture::Units::convert, cm2V/s->m2/us} { 478 482 list [catch {Rappture::Units::convert 2cm2V/s -to m2/us} msg] $msg 479 } {1 {unmatched units in conversion: (V1)}} 483 } {1 {unmatched units in conversion: (V) 484 Please enter units of type length/time (/s,/us,A2,in2,m2)}} 480 485 481 486 test convert_units-5.4.4.6 {Rappture::Units::convert, cm2V/s->m2/us} { 482 487 list [catch {Rappture::Units::convert 2cm2V/s -to m2/us} msg] $msg 483 } {1 {unmatched units in conversion: (V1)}} 488 } {1 {unmatched units in conversion: (V) 489 Please enter units of type length/time (/s,/us,A2,in2,m2)}} 484 490 485 491 test convert_units-5.4.4.7 {Rappture::Units::convert, cm2V->m2} { 486 492 list [catch {Rappture::Units::convert 2cm2V -to m2} msg] $msg 487 } {1 {unmatched units in conversion: (V1)}} 493 } {1 {unmatched units in conversion: (V) 494 Please enter units of type length (A2,in2,m2)}} 488 495 489 496 test convert_units-5.4.4.8 {Rappture::Units::convert, Vcm2->m2} { 490 497 list [catch {Rappture::Units::convert 2Vcm2 -to m2} msg] $msg 491 } {1 {unmatched units in conversion: (V1)}} 498 } {1 {unmatched units in conversion: (V) 499 Please enter units of type length (A2,in2,m2)}} 492 500 493 501 test convert_units-5.4.4.9 {Rappture::Units::convert, cm2->Vm2} { 494 502 list [catch {Rappture::Units::convert 2cm2 -to Vm2} msg] $msg 495 } {1 {unmatched units in conversion: (V1)}} 503 } {1 {unmatched units in conversion: (V) 504 Please enter units of type electric_potential*length (A2,V,in2,m2)}} 496 505 497 506 test convert_units-5.4.4.10 {Rappture::Units::convert, cm2->m2V} { 498 507 list [catch {Rappture::Units::convert 2cm2 -to m2V} msg] $msg 499 } {1 {unmatched units in conversion: (V1)}} 508 } {1 {unmatched units in conversion: (V) 509 Please enter units of type length*electric_potential (A2,V,in2,m2)}} 500 510 501 511 test convert_units-5.4.4.11 {Rappture::Units::convert, cm2A->Vm2} { 502 512 list [catch {Rappture::Units::convert 2cm2A -to Vm2} msg] $msg 503 } {1 {unmatched units in conversion: (A1) -> (V1)}} 513 } {1 {unmatched units in conversion: (A) -> (V) 514 Please enter units of type electric_potential*length (A2,V,in2,m2)}} 504 515 505 516 test convert_units-5.4.4.12 {Rappture::Units::convert, cm2A->m2V} { 506 517 list [catch {Rappture::Units::convert 2cm2A -to m2V} msg] $msg 507 } {1 {conversion unavailable: (A1) -> (V1)}} 518 } {1 {Conversion unavailable: (A) -> (V) 519 Please enter units of type length*electric_potential (A2,V,in2,m2)}} 508 520 509 521 test convert_units-5.4.4.13 {Rappture::Units::convert, Acm2->Vm2} { 510 522 list [catch {Rappture::Units::convert 2Acm2 -to Vm2} msg] $msg 511 } {1 {unmatched units in conversion: (A1) -> (V1)}} 523 } {1 {unmatched units in conversion: (A) -> (V) 524 Please enter units of type electric_potential*length (A2,V,in2,m2)}} 512 525 513 526 test convert_units-5.4.4.14 {Rappture::Units::convert, Acm2->m2V} { 514 527 list [catch {Rappture::Units::convert 2Acm2 -to m2V} msg] $msg 515 } {1 {conversion unavailable: (A1) -> (V1)}} 528 } {1 {Conversion unavailable: (A) -> (V) 529 Please enter units of type length*electric_potential (A2,V,in2,m2)}} 516 530 517 531 #-------------------------------------------------------------------- … … 525 539 test convert_units-5.4.5.1 {Rappture::Units::convert, cm2->/m2} { 526 540 list [catch {Rappture::Units::convert 1cm -to /m2} msg] $msg 527 } {1 {conversion unavailable: (cm1) -> (m-2)}} 541 } {1 {Conversion unavailable: (cm) -> (m-2) 542 Please enter units of type /length (/A2,/in2,/m2)}} 528 543 529 544 #-------------------------------------------------------------------- … … 785 800 test convert_units-5.4.10.1 {Rappture::Units::convert, torr->mmhg} { 786 801 list [catch {Rappture::Units::convert 5torr -to mmhg} msg] $msg 787 } {0 5mm hg}802 } {0 5mmHg} 788 803 789 804 test convert_units-5.4.10.2 {Rappture::Units::convert, ToRr->mmhg} { 790 805 list [catch {Rappture::Units::convert 5ToRr -to mmhg} msg] $msg 791 } {0 5mm hg}806 } {0 5mmHg} 792 807 793 808 test convert_units-5.4.10.3 {Rappture::Units::convert, kpa->PSI} { 794 809 list [catch {Rappture::Units::convert 5kpa -to PSI} msg] $msg 795 } {0 0.7252 PSI}810 } {0 0.7252psi} 796 811 797 812 test convert_units-5.4.10.4 {Rappture::Units::convert, KPA->PsI} { 798 813 list [catch {Rappture::Units::convert 5KPA -to PsI} msg] $msg 799 } {0 0.7252 PsI}814 } {0 0.7252psi} 800 815 801 816 test convert_units-5.4.10.5 {Rappture::Units::convert, Cm2/vS->M2/KVUS} { 802 817 list [catch {Rappture::Units::convert 2Cm2/vS -to M2/KVUS} msg] $msg 803 } {0 2e-07 M2/KVUS}818 } {0 2e-07m2/kVus} 804 819 805 820 #--------------------------------------------------------------------
Note: See TracChangeset
for help on using the changeset viewer.