Changeset 73 for trunk/src/python


Ignore:
Timestamp:
Sep 28, 2005 12:09:43 AM (17 years ago)
Author:
dkearney
Message:
  1. changes to RpUnits, modified RpUnits::define() function not to look for base units.
  2. changed python RpUnits to return string when units!="off" and a number when units=="off"
  3. modified make files, hopefully making them easier to read, removing vpaths,

cleaning up the make process, combining smaller libraries into one library,
librappture, and putting the core objects into one library - libRpObjects,
for testing.

  1. copied rpResult function into rappture_interface.c to stop compiler from

complaining about undefined references ot the function. trying to use the
function probably won't work. but that can be fixed after the repository is
reorganized.

  1. in example/app-fermi/python/fermi.py, changed exit() to sys.exit() to

stop python from complaining about no function called exit().

  1. examples/app-fermi/fortran still does not run, but new rappture parser

should take care of these problems. (same with examples/fermi_fortran)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/python/PyRpUnits.cc

    r71 r73  
    428428    char* to = NULL;
    429429    char* units = NULL;
     430    char* tmpRetStr = NULL;
    430431    std::string fromVal_S = "";
    431432    std::string to_S = "";
     
    434435    int result = 0;
    435436    std::string retStr = "";
     437    PyObject* retVal = NULL;
    436438
    437439    static char *kwlist[] = {"fromVal", "to", "units", NULL};
     
    462464    retStr = RpUnits::convert(fromVal_S,to_S,unitsVal,&result);
    463465
    464     if (!retStr.empty()) {
    465 
    466     }
    467        
    468     return PyString_FromString(retStr.c_str());
     466    if ( (!retStr.empty()) && (result == 1) ) {
     467        if (unitsVal) {
     468            retVal = PyString_FromString(retStr.c_str());   
     469        }
     470        else {
     471            // convert to an integer and return that if
     472            // the units were turned off
     473            tmpRetStr = (char*) calloc(retStr.length(), sizeof(char));
     474            if (tmpRetStr) {
     475                strncpy(tmpRetStr,retStr.c_str(),retStr.length());
     476                retVal = PyInt_FromString(tmpRetStr, NULL, 0);
     477                free(tmpRetStr);
     478                tmpRetStr = NULL;
     479            }
     480        }
     481    }
     482    else {
     483        //keeping this around in case you want string returned instead of None
     484        //if (fromVal) {
     485        //    retVal = PyString_FromString(fromVal);   
     486        //}
     487        //else {
     488        retVal = Py_None;
     489        Py_INCREF(retVal);
     490        //}
     491    }
     492   
     493    return retVal;
    469494}
    470495
Note: See TracChangeset for help on using the changeset viewer.