Changeset 73 for trunk/src


Ignore:
Timestamp:
Sep 28, 2005 12:09:43 AM (19 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)

Location:
trunk/src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/Makefile

    r41 r73  
     1# you need to change this to where your version of python is installed.
     2# tell make where to find python header files
     3PY_SRC_HEADERS  = /opt/rappture/include/python2.4
     4
     5# tell make where to find the python shared library
     6EMB_PY_LIB_FLAG = -lpython2.4
     7EMB_PY_LIB_DIR  = /opt/rappture/lib
     8
     9EMB_PY_FLAGS    = -Wl,-rpath,$(EMB_PY_LIB_DIR) -L$(EMB_PY_LIB_DIR) $(EMB_PY_LIB_FLAG)
     10
     11# everything below should be ok, but check to make sure
     12# especially check the fortran flags, if youre using fortran
     13#
    114# define the top of our directory structure
    215# replace this with the full path of the directory
     
    821
    922# define which programs can be made
    10 PROGS                   =       libRpUnits_CInterface   \
    11                                         libRpUnits_FInterface   \
    12                                         librappture                             \
    13                                         libRapptureIO                   \
    14                                         libRpUnits                              \
    15                                         libRpVariable                   \
    16                                         libRpNumber                             \
    17                                         libRpString                             \
    18                                         libRpBoolean                    \
    19                                         libRpChoice                             \
    20                                         libRpOption                             
    21                                        
     23PROGS                   =       librappture                             \
     24                                        libRpObjects                    \
    2225
    2326# define our compiling environment
    2427#
    25 AR                              = ar
    2628CC                              = gcc
    2729CPP                             = g++
     
    6264# define our directories
    6365#
    64 WORK_DIR                = $(RP_BASE)/work
    6566INCLUDES_DIR    = $(RP_BASE)/include
    6667BIN_DIR                 = $(RP_BASE)/bin
    67 LIB_DIR                 = $(RP_BASE)/lib
     68LIB_DIR                 = $(RP_BASE)/src
    6869SRC_DIR                 = $(RP_BASE)/src
    6970TEST_DIR                = $(RP_BASE)/test
     
    7475PY_SRC                  = $(SRC_DIR)/python
    7576
    76 #LIB_RPUNITS    = -Wl,-rpath,$(LIB_DIR) -L$(LIB_DIR) -lRpUnits
    77 #LIB_RPDICT             = -Wl,-rpath,$(LIB_DIR) -L$(LIB_DIR) -lRpDict
    78 
    7977LIB_INC_PREFIX  = -Wl,-rpath,$(LIB_DIR) -L$(LIB_DIR)
    80 
    81 #LIB_RPUNITS_C   = $(LIB_INC_PREFIX) -lRpUnits_CInterface
    82 #LIB_RAPPTUREIO  = $(LIB_INC_PREFIX) -lrappture
    83 
    84 LIB_RP_UNITS    = $(LIB_INC_PREFIX) -lRpUnits
    85 LIB_RP_VARIABLE = $(LIB_INC_PREFIX) -lRpVariable
    86 LIB_RP_NUMBER   = $(LIB_INC_PREFIX) -lRpNumber
    87 LIB_RP_STRING   = $(LIB_INC_PREFIX) -lRpString
    88 LIB_RP_BOOLEAN  = $(LIB_INC_PREFIX) -lRpBoolean
    89 LIB_RP_OPTION   = $(LIB_INC_PREFIX) -lRpOption
    90 LIB_RP_CHOICE   = $(LIB_INC_PREFIX) -lRpChoice
    91 LIB_RP_PRESET   = $(LIB_INC_PREFIX) -lRpPreset
    92 
    93 
    94 LIB_RPUNITS_C   = -Wl,-rpath,$(LIB_DIR) -L$(LIB_DIR) -lRpUnits_CInterface
    95 LIB_RPUNITS_F   = -Wl,-rpath,$(LIB_DIR) -L$(LIB_DIR) -lRpUnits_FInterface
     78LIB_RP_OBJECTS  = $(LIB_INC_PREFIX) -lRpObjects
    9679LIB_RAPPTURE    = -Wl,-rpath,$(LIB_DIR) -L$(LIB_DIR) -lrappture
    97 LIB_RAPPTUREIO  = -Wl,-rpath,$(LIB_DIR) -L$(LIB_DIR) -lRapptureIO
    9880
    9981INCL_CORE               = -I $(INCLUDES_DIR)/core
    100 INCL_CEE                = -I $(INCLUDES_DIR)/cee
     82INCL_CEE                = -I $(INCLUDES_DIR)/cee -I $(PY_SRC_HEADERS)
    10183INCL_FORTRAN    = -I $(INCLUDES_DIR)/fortran
    10284INCL_PY                 = -I $(INCLUDES_DIR)/python
    103 
    104 # you need to change this to where your version of python is installed.
    105 EMB_PY_FLAGS    = -L$(LIB_DIR) -lpython2.4
    106 
    107 # tell make where to find files of each specific type
    108 #
    109 vpath %.o $(WORK_DIR)
    110 vpath %.so $(LIB_DIR)
    111 vpath %.h $(INCLUDES_DIR)
    112 #vpath %.c $(CORE_SRC)
    113 #vpath %.cc $(CORE_SRC)
    114 #vpath %.tcc $(CORE_SRC)
    115 #vpath %.cpp $(CORE_SRC)
    11685
    11786
     
    12190
    12291# include rappture library definitions
    123 include $(SRC_DIR)/make.inc
     92
     93#### librappture shared object ###########################################
     94
     95librappture: rappture_fortran.o rappture_interface.o RpUnitsCInterface.o RpUnitsStd.o RpUnits.o
     96        $(CPP) $(DEGUG) -shared -Wl,-rpath,$(LIB_DIR)/ \
     97                -Wl,-soname,$@.so -o $(LIB_DIR)/$@.so.0.0 $^ $(EMB_PY_FLAGS)
     98
     99        /sbin/ldconfig -n $(LIB_DIR)
     100
     101
     102#### libRpObjects ########################################################
     103libRpObjects: RpVariable.o RpAbout.o RpNumber.o RpString.o RpBoolean.o RpChoice.o RpOption.o RpUnitsStd.o RpUnits.o
     104        $(CPP) $(DEGUG) -shared -Wl,-rpath,$(LIB_DIR)/ \
     105                -Wl,-soname,$@.so -o $(LIB_DIR)/$@.so.0.0 $^ -lc
     106       
     107        /sbin/ldconfig -n $(LIB_DIR)
     108
    124109
    125110# include core source files
    126 include $(CORE_SRC)/make.inc
     111
     112Rp%.o: $(CORE_SRC)/Rp%.cc
     113        $(CPP) -fPIC $(DEBUG) $(INCL_CORE) -o $@ -c $?
    127114
    128115# include cee binding definitions
    129 include $(CEE_SRC)/make.inc
     116
     117rappture_interface.o: $(CEE_SRC)/rappture_interface.c
     118        $(CPP) -fPIC $(DEBUG) $(INCL_CEE) $(INCL_PY) -o $@ -c $<
     119
     120RpUnitsCInterface.o: $(CEE_SRC)/RpUnitsCInterface.cc
     121        $(CPP) $(CFLAGS) -fPIC $(DEBUG) $(INCL_CORE) $(INCL_CEE) -o $@ -c $?
    130122
    131123# include fortran binding definitions
    132 include $(FORT_SRC)/make.inc
    133124
    134 # include test programs
    135 include $(TEST_DIR)/make.inc
     125RpUnits_fortran.o: $(FORT_SRC)/RpUnits_fortran.c
     126        $(CPP) $(CFLAGS) -fPIC $(DEBUG) $(INCL_CORE) -o $@ -c $?
     127
     128rappture_fortran.o: $(FORT_SRC)/rappture_fortran.c
     129        $(CPP) $(CFLAGS) -fPIC $(DEBUG) $(INCL_CORE) $(INCL_CEE) $(INCL_PY) -o $@ -c $<
    136130
    137131#### CLEAN UP ############################################################
    138132clean:
    139         - rm -f $(BIN_DIR)/* $(WORK_DIR)/*.o $(LIB_DIR)/librappture.* $(LIB_DIR)/libR*.so*
     133        - rm -f $(BIN_DIR)/* *.o librappture.* libR*.so*
  • trunk/src/cee/make.inc

    r33 r73  
    11
    2 $(WORK_DIR)/rappture_interface.o: $(CEE_SRC)/rappture_interface.c
     2rappture_interface.o: $(CEE_SRC)/rappture_interface.c
    33        $(CPP) -fPIC $(DEBUG) $(INCL_CEE) $(INCL_PY) -o $@ -c $<
    44
    5 $(WORK_DIR)/RpUnitsCInterface.o: $(CEE_SRC)/RpUnitsCInterface.cc
     5RpUnitsCInterface.o: $(CEE_SRC)/RpUnitsCInterface.cc
    66        $(CPP) $(CFLAGS) -fPIC $(DEBUG) $(INCL_CORE) $(INCL_CEE) -o $@ -c $?
  • trunk/src/cee/rappture_interface.c

    r49 r73  
    829829   
    830830}
     831
     832/*
     833 * ----------------------------------------------------------------------
     834 *  FUNCTION: rpResult
     835 *
     836 *  Clients call this function at the end of their simulation, to
     837 *  pass the simulation result back to the Rappture GUI.  It writes
     838 *  out the given XML object to a runXXX.xml file, and then writes
     839 *  out the name of that file to stdout.
     840 * ======================================================================
     841 *  AUTHOR:  Michael McLennan, Purdue University
     842 *  Copyright (c) 2004-2005
     843 *  Purdue Research Foundation, West Lafayette, IN
     844 * ======================================================================
     845 */
     846// #include <stdlib.h>
     847// #include <time.h>
     848
     849void
     850rpResult(PyObject* lib) {
     851    char outputFile[100];
     852    char* xtext;
     853    FILE* fp;
     854    time_t t;
     855
     856    xtext = rpXml(lib);
     857
     858    // create output filename
     859    snprintf(outputFile, 50, "run%d.xml", (int)time(&t));
     860
     861    // write out the result file
     862    fp = fopen(outputFile, "w");
     863    if(!fp) {
     864        fprintf(stderr,"can't save results (err=%d)\n", errno);
     865        return;
     866    }
     867    int fsize = fwrite(xtext, strlen(xtext), sizeof(char), fp);
     868    fclose(fp);
     869
     870    // tell Rappture the file name
     871    printf("=RAPPTURE-RUN=>%s\n", outputFile);
     872}
  • trunk/src/core/RpUnits.cc

    r68 r73  
    1  #ifndef _RpUNITS_H
    2      #include "RpUnits.h"
    3  #endif
     1/*
     2 * ----------------------------------------------------------------------
     3 *  RpUnits.cc
     4 *
     5 * Data Members and member functions for the RpUnits class
     6 *
     7 * ======================================================================
     8 *  AUTHOR:  Derrick Kearney, Purdue University
     9 *  Copyright (c) 2004-2005
     10 *  Purdue Research Foundation, West Lafayette, IN
     11 * ======================================================================
     12 */
     13
     14#include "RpUnits.h"
    415
    516// dict pointer
    6 // RpDict<std::string,RpUnits*> RpUnits::dict = RpDict<std::string,RpUnits*>();
    717RpDict<std::string,RpUnits*>* RpUnits::dict = new RpDict<std::string,RpUnits*>();
    8 
    918
    1019/************************************************************************
     
    2938    }
    3039
    31     // char * cmpPtr = NULL;
     40    double exp = 0.0;
     41    double oldExponent = 0;
     42    double newExponent = 0;
     43    int digiSearch = 0; // flag to show we are searching digits
     44    int alphaSearch = 0; // flag to show we are searching chars
     45
     46    std::string cmpStr = "";
     47
     48    std::string::size_type length = units.length();
     49    int srchIndex = length;
     50    std::string srchStr = units;
     51
     52    while ((srchStr.length() > 0)) {
     53
     54        srchIndex--;
     55 
     56        if (srchIndex < 0) {
     57            break;
     58        }
     59 
     60        if     ( isdigit(srchStr[srchIndex]) && !digiSearch && !alphaSearch) {
     61            digiSearch = 1;
     62        }
     63        else if(!isdigit(srchStr[srchIndex]) &&  digiSearch && !alphaSearch) {
     64 
     65            // convert our exponent to integer
     66 
     67            // check to see if there is a + or - sign
     68            if (  ( srchStr[srchIndex] == '+' )
     69               || ( srchStr[srchIndex] == '-' ) ) {
     70 
     71                // evaluate a '+' or '-' sign with the value
     72                srchIndex--;
     73            }
     74 
     75            srchIndex++;
     76 
     77            exp = atoi(&srchStr[srchIndex]);
     78 
     79            // we are no longer in a digit search
     80            digiSearch = 0;
     81 
     82            // place null character where the number starts
     83            // so we know what we've already parsed
     84 
     85            srchStr.erase(srchIndex);
     86            length = srchStr.length();
     87 
     88        }
     89        else if( isalpha(srchStr[srchIndex]) && !digiSearch && !alphaSearch) {
     90            alphaSearch = 1;
     91        }
     92        else if(!isalpha(srchStr[srchIndex]) && !digiSearch && alphaSearch) {
     93           
     94            // adjust the exponent if none was provided
     95            if (exp == 0) {
     96                exp = 1;
     97            }
     98 
     99            // compare unit string to see if it is a recognized system
     100 
     101 
     102            std::string cmpStr = srchStr.substr(srchIndex+1,length-srchIndex-1);
     103            if (newRpUnit) {
     104                 newRpUnit->addUnit( cmpStr, exp, basis);
     105            }
     106            else {
     107                 newRpUnit= new RpUnits(cmpStr, exp, basis);
     108            }
     109
     110            // place a null character at the end of the string
     111            // so we know what we've parsed so far.
     112         
     113            srchStr.erase(srchIndex);
     114            length = srchStr.length();
     115 
     116            // fix our searching flag
     117            alphaSearch = 0;
     118
     119        }
     120        else if( srchStr[srchIndex] == '/' ) {
     121            // have to go back to all of the objects created and
     122            // multiply their exponents by -1.
     123 
     124            if (newRpUnit) {
     125                unit* p = newRpUnit->head;
     126                while (p) {
     127                    oldExponent = p->getExponent();
     128                    newExponent = oldExponent*-1;
     129                    p->newExponent(newExponent);
     130                    p = p->next;
     131                }
     132            }
     133
     134            // place a null character at the end of the string
     135            // so we know what we've parsed so far.
     136       
     137            srchStr.erase(srchIndex);
     138            length = srchStr.length();
     139
     140        }
     141        else {
     142            continue;
     143        }
     144
     145
     146    } // end while loop
     147       
     148
     149    // complete the last iteration
     150    if (srchIndex < 0) {
     151
     152
     153        if (digiSearch) {
     154            // convert whatever is left
     155            exp = atoi(&srchStr[srchIndex+1]);
     156           
     157            // if we get here, that means units name starts with a digit
     158            // normally we wont get here, but if we do, should we place
     159            // the unit into the dictionary? i think not since digits are
     160            // always considered exponents.
     161        }
     162        else if (alphaSearch) {
     163            // adjust the exponent if none was provided
     164            if (exp == 0) {
     165                exp = 1;
     166            }
     167
     168            // compare unit string to see if it is a recognized system
     169
     170            std::string cmpStr = srchStr.substr(srchIndex+1,length-srchIndex-1);
     171            newRpUnit= new RpUnits(cmpStr, exp, basis);
     172            newRpUnit->insert(newRpUnit->getUnitsName());
     173        }
     174    }
     175
     176    // place the new object into the dictionary
     177   
     178    // return a copy of the new object to user
     179    return newRpUnit;
     180}
     181
     182
     183/************************************************************************
     184 *                                                                     
     185 * add a complex RpUnits Object                                                   
     186 *                                                                     
     187 ************************************************************************/
     188
     189RpUnits * RpUnits::defineCmplx ( const std::string units,
     190                            RpUnits * basis )
     191{
     192    RpUnits * newRpUnit = NULL;
     193
     194    if (units == "") {
     195        // raise error, user sent null units!
     196        return NULL;
     197    }
     198
     199    // check to see if the user is trying to trick me!
     200    if ( (basis) && (units == basis->getUnits()) ) {
     201        // dont trick me!
     202        return NULL;
     203    }
     204
    32205    double exp = 0.0;
    33206    double oldExponent = 0;
     
    44217    std::string srchStr = units;
    45218
    46     // unit* p = NULL;
    47219
    48220    while ((srchStr.length() > 0)) {
     
    82254            length = srchStr.length();
    83255 
    84             /*
    85             // shortcut so we dont have to go through an additional while
    86             // loop iteration.
    87             if (isalpha(srchStr[srchIndex-1])) {
    88                 dbText = "alphaSearch = 1";
    89                 dbprint(1,dbText);
    90                 alphaSearch = 1;
    91                 srchIndex--;
    92             }
    93             */
    94256        }
    95257        else if( isalpha(srchStr[srchIndex]) && !digiSearch && !alphaSearch) {
     
    117279                // we may want to deal with them differntly in the future
    118280 
    119                 // srchStr.erase(srchIndex+1);
    120281                // erase only the last character and reprocess the string
    121282                // because our precompare doesnt take care of this yet.
     
    142303 
    143304            // we need pre-compare to return the basis of what it found.
    144             // addUnit( newUnit, exp, basis)
    145305            if (newRpUnit) {
    146                  // newRpUnit->addUnit( newUnitText, exp, NULL);
    147306                 newRpUnit->addUnit( newUnitText, exp, basis);
    148307            }
    149308            else {
    150                  // newRpUnit= new RpUnits(newUnitText, exp, NULL);
    151309                 newRpUnit= new RpUnits(newUnitText, exp, basis);
    152310            }
    153311 
    154             // sprintf(dbText,"creating unit: %s,%d\n\0", newUnit.c_str(),exp);
    155312 
    156313            // place a null character at the end of the string
     
    163320            alphaSearch = 0;
    164321
    165             // shortcut so we dont have to go through an additional while
    166             // loop iteration.
    167             // this doesnt work out so well, maybe need to reconsider
    168             // if (isdigit(*(search--))) {
    169             //    dbprint(1,"digiSearch = 1");
    170             //    digiSearch = 1;
    171             // }
    172         }
    173         // else if ( *search == '/' ) {
     322        }
    174323        else if( srchStr[srchIndex] == '/' ) {
    175324            // have to go back to all of the objects created and
     
    189338            // so we know what we've parsed so far.
    190339       
    191             /*
    192             end = (search);
    193             *end = '\0';
    194             */
    195  
    196             // srchStr.erase(srchIndex+1);
    197340            srchStr.erase(srchIndex);
    198341            length = srchStr.length();
     
    235378
    236379                // there are units we did not recognize,
    237                 // right now we ignore them,
    238                 // we may want to deal with them differntly in the future
    239                 // ignoring unit
    240 
    241                 // break out of creating the last unit.
    242380
    243381                // create a new unit with basis of null to show its a
    244382                // fundamental type
    245                 // newRpUnit = new RpUnits(cmpStr, exp, NULL);
    246383                newRpUnit = new RpUnits(cmpStr, exp, basis);
    247384               
    248385                // put the unit into the dictionary
    249                 // newRpUnit->insert(cmpStr);
    250386                //
    251387                newRpUnit->insert(newRpUnit->getUnitsName());
    252388               
    253                 // RpUnits::dict.set(cmpStr,newRpUnit);
    254389
    255390            }
     
    265400
    266401                // we need pre-compare to return the basis of what it found.
    267                 // addUnit( newUnit, exp, basis)
    268402                if (newRpUnit) {
    269                      // newRpUnit->addUnit( newUnitText, exp, NULL );
    270403                     newRpUnit->addUnit( newUnitText, exp, basis );
    271404                }
    272405                else {
    273                      // newRpUnit = new RpUnits(newUnitText, exp, NULL);
    274406                     newRpUnit = new RpUnits(newUnitText, exp, basis);
    275407                }
     
    332464std::string RpUnits::getUnits()
    333465{
    334     // return units;
    335 
    336466    std::stringstream unitText;
    337467    unit* p = head;
    338468   
    339469    while (p) {
    340         // unitText << p->getUnits() << p->getExponent();
    341470        unitText << p->getUnits() ;
    342471        p = p->next;
     
    353482std::string RpUnits::getUnitsName()
    354483{
    355     // return units;
    356 
    357484    std::stringstream unitText;
    358485    unit* p = head;
     
    383510double RpUnits::getExponent()
    384511{
    385     // return exponent;
    386 
    387512    return head->getExponent();
    388 
    389513    return 0;
    390514}
     
    397521RpUnits * RpUnits::getBasis()
    398522{
    399     // return basis;
    400 
    401523    // check if head exists?
    402 
    403524    return head->getBasis();
    404525}
     
    477598 *                                                                     
    478599 * **********************************************************************/
    479 //static int RpUnits::makeMetric(RpUnits * basis) {
    480600int RpUnits::makeMetric(RpUnits * basis) {
    481601
     
    536656    RpUnits::define(peta, basis, peta2base, base2peta);
    537657   
    538     //
    539658    return (1);
    540659}
     
    599718            }
    600719        }
    601         fromUnitsName = val.substr(idx, valLen-idx+1);
     720        fromUnitsName = val.substr(idx, valLen-idx);
    602721    }
    603722    else {
     
    655774
    656775    // currently we convert this object to its basis and look for the
    657     // connection ot the toUnit object from the basis.
     776    // connection to the toUnit object from the basis.
    658777
    659778    double value = val;
     
    8881007    RpUnits* val = this;
    8891008    // dict pointer
    890     // RpUnits::dict.set(key,val,&newRecord);
    8911009    RpUnits::dict->set(key,val,&newRecord);
    892     // std::cout << "key = :" << key << ":" << std::endl;
    8931010    return newRecord;
    8941011}
     
    9231040            (searchStr.length() > 0) ) {
    9241041
    925         // std::cout << "units = :" << units << ":" << std::endl;
    926         // std::cout << "searchStr = :" << searchStr << ":" << std::endl;
    927        
    928 //         if (!compare(searchStr)) {
    9291042        // dict pointer
    930         // if (dict.find(searchStr) == dict.getNullEntry()) {
    9311043        if (dict->find(searchStr) == dict->getNullEntry()) {
    9321044            // the string was not found,
     
    9691081        }
    9701082
    971 //        if (!compare(searchStr)) {
    9721083        // dict pointer
    973         // if (dict.find(searchStr) == dict.getNullEntry()) {
    9741084        if (dict->find(searchStr) == dict->getNullEntry()) {
    9751085            // the string was not found,
     
    10141124    return retIndex;
    10151125
    1016     /*
    1017     if (retIndex) {
    1018         // if we found a match return a
    1019         // pointer to where the matching units
    1020         // string can be found.
    1021         dbText = "pre_compare returning an index";
    1022         dbprint(1, dbText);
    1023         return retIndex;
    1024     }
    1025     else {
    1026         // if there was no match, return a negative value.
    1027         dbText = "pre_compare returning -1";
    1028         dbprint(1, dbText);
    1029         return -1;
    1030     }
    1031     */
    10321126}
    10331127
     
    10351129void RpUnits::connectConversion(RpUnits* myRpUnit)
    10361130{
    1037 
    1038     /*
    1039     int index = 0;
    1040 
    1041     while   ( (myRpUnit->staticConvArr[index] != NULL)
    1042          &&   (index < myRpUnit->numBuckets) ){
    1043 
    1044         index++;
    1045     }
    1046 
    1047     if      ( (myRpUnit->staticConvArr[index] == NULL)
    1048         &&    (index < myRpUnit->numBuckets) ) {
    1049            
    1050         myRpUnit->staticConvArr[index] = this->conv;
    1051     }
    1052     */
    1053 
    10541131    convEntry* p = myRpUnit->convList;
    10551132
     
    10941171RpUnits::addPresetAll () {
    10951172
    1096     // RpUnits* volt       = RpUnits::define("V", NULL);
    1097    
    1098     RpUnits::define("V", NULL);
    10991173
    11001174    addPresetTime();
     
    11621236RpUnits::addPresetEnergy () {
    11631237
     1238    RpUnits* volt       = RpUnits::define("V", NULL);
    11641239    RpUnits* electrVolt = RpUnits::define("eV", NULL);
    11651240    RpUnits* joule      = RpUnits::define("J", NULL);
    11661241   
     1242    RpUnits::makeMetric(volt);
     1243
    11671244    // add energy definitions
    11681245    RpUnits::define(electrVolt,joule,electronVolt2joule,joule2electronVolt);
  • trunk/src/core/make.inc

    r39 r73  
    1 $(WORK_DIR)/Rp%.o: $(CORE_SRC)/Rp%.cc
     1Rp%.o: $(CORE_SRC)/Rp%.cc
    22        $(CPP) -fPIC $(DEBUG) $(INCL_CORE) -o $@ -c $?
  • trunk/src/fortran/make.inc

    r33 r73  
    1 
    2 $(WORK_DIR)/RpUnits_fortran.o: $(FORT_SRC)/RpUnits_fortran.c
     1RpUnits_fortran.o: $(FORT_SRC)/RpUnits_fortran.c
    32        $(CPP) $(CFLAGS) -fPIC $(DEBUG) $(INCL_CORE) -o $@ -c $?
    43
    5 $(WORK_DIR)/rappture_fortran.o: $(FORT_SRC)/rappture_fortran.c
     4rappture_fortran.o: $(FORT_SRC)/rappture_fortran.c
    65        $(CPP) $(CFLAGS) -fPIC $(DEBUG) $(INCL_CORE) $(INCL_CEE) $(INCL_PY) -o $@ -c $<
  • trunk/src/make.inc

    r39 r73  
    11#### librappture shared object ###########################################
    22
    3 libRpUnits_CInterface: $(WORK_DIR)/RpUnitsCInterface.o $(WORK_DIR)/RpUnitsStd.o $(WORK_DIR)/RpUnits.o
    4         $(CPP) $(DEGUG) -shared -Wl,-rpath,../lib \
    5                 -Wl,-soname,$@.so -o $(LIB_DIR)/$@.so.0.0 $^ -lc
     3libRpUnits_CInterface: RpUnitsCInterface.o RpUnitsStd.o RpUnits.o
     4        $(CPP) $(DEGUG) -shared -Wl,-rpath,./ \
     5                -Wl,-soname,$@.so -o $@.so.0.0 $^ -lc
    66       
    7         /sbin/ldconfig -n $(LIB_DIR)
     7        /sbin/ldconfig -n ./
    88
    9 libRpUnits_FInterface: $(WORK_DIR)/RpUnitsStd.o $(WORK_DIR)/RpUnits.o $(WORK_DIR)/RpUnits_fortran.o
    10         $(CPP) $(DEBUG) -shared -Wl,-rpath,../lib \
    11         -Wl,-soname,$@.so -o $(LIB_DIR)/$@.so.0.0 $^ -lstdc++
     9libRpUnits_FInterface: RpUnitsStd.o RpUnits.o RpUnits_fortran.o
     10        $(CPP) $(DEBUG) -shared -Wl,-rpath,./ \
     11        -Wl,-soname,$@.so -o $@.so.0.0 $^ -lstdc++
    1212       
    13         /sbin/ldconfig -n $(LIB_DIR)
     13        /sbin/ldconfig -n ./
    1414
    15 librappture: $(WORK_DIR)/rappture_fortran.o $(WORK_DIR)/rappture_interface.o
    16         $(CC) $(DEGUG) -shared -Wl,-rpath,../lib \
    17                 -Wl,-soname,$@.so -o $(LIB_DIR)/$@.so.0.0 $^ $(EMB_PY_FLAGS) -lstdc++
     15librappture: rappture_fortran.o rappture_interface.o
     16        $(CC) $(DEGUG) -shared -Wl,-rpath,./ \
     17                -Wl,-soname,$@.so -o $@.so.0.0 $^ $(EMB_PY_FLAGS) -lstdc++
    1818               
    19         /sbin/ldconfig -n $(LIB_DIR)
     19        /sbin/ldconfig -n ./
    2020   
    21 libRapptureIO: $(WORK_DIR)/rappture_fortran.o $(WORK_DIR)/rappture_interface.o
    22         $(CC) $(DEGUG) -shared -Wl,-rpath,../lib \
    23                 -Wl,-soname,$@.so -o $(LIB_DIR)/$@.so.0.0 $^ $(EMB_PY_FLAGS) -lstdc++
     21libRapptureIO: rappture_fortran.o rappture_interface.o
     22        $(CC) $(DEGUG) -shared -Wl,-rpath,./ \
     23                -Wl,-soname,$@.so -o $@.so.0.0 $^ $(EMB_PY_FLAGS) -lstdc++
    2424               
    25         /sbin/ldconfig -n $(LIB_DIR)
     25        /sbin/ldconfig -n ./
    2626
    2727
    2828#### libRpUnits ###########################################################
    29 libRpUnits: $(WORK_DIR)/RpUnits.o $(WORK_DIR)/RpUnitsStd.o
    30         $(CPP) $(DEGUG) -shared -Wl,-rpath,../lib \
    31                 -Wl,-soname,$@.so -o $(LIB_DIR)/$@.so.0.0 $^ -lc
     29libRpUnits: RpUnits.o RpUnitsStd.o
     30        $(CPP) $(DEGUG) -shared -Wl,-rpath,./ \
     31                -Wl,-soname,$@.so -o $@.so.0.0 $^ -lc
    3232                           
    33         /sbin/ldconfig -n $(LIB_DIR)
     33        /sbin/ldconfig -n ./
    3434
    3535#### libRpVariable ########################################################
    36 libRpVariable: $(WORK_DIR)/RpVariable.o $(WORK_DIR)/RpAbout.o
    37         $(CPP) $(DEGUG) -shared -Wl,-rpath,../lib \
    38                 -Wl,-soname,$@.so -o $(LIB_DIR)/$@.so.0.0 $^ -lc
     36libRpVariable: RpVariable.o RpAbout.o
     37        $(CPP) $(DEGUG) -shared -Wl,-rpath,./ \
     38                -Wl,-soname,$@.so -o $@.so.0.0 $^ -lc
    3939                           
    40         /sbin/ldconfig -n $(LIB_DIR)
     40        /sbin/ldconfig -n ./
    4141
    4242#### libRpNumber ##########################################################
    43 libRpNumber: $(WORK_DIR)/RpNumber.o libRpUnits libRpVariable
    44         $(CPP) $(DEGUG) -shared -Wl,-rpath,../lib \
    45                 -Wl,-soname,$@.so -o $(LIB_DIR)/$@.so.0.0 $< -lc $(LIB_RP_UNITS) $(LIB_RP_VARIABLE)
     43libRpNumber: RpNumber.o libRpUnits libRpVariable
     44        $(CPP) $(DEGUG) -shared -Wl,-rpath,./ \
     45                -Wl,-soname,$@.so -o $@.so.0.0 $< -lc $(LIB_RP_UNITS) $(LIB_RP_VARIABLE)
    4646                           
    47         /sbin/ldconfig -n $(LIB_DIR)
     47        /sbin/ldconfig -n ./
    4848
    4949#### libRpString ##########################################################
    50 libRpString: $(WORK_DIR)/RpString.o libRpVariable
    51         $(CPP) $(DEGUG) -shared -Wl,-rpath,../lib \
    52                 -Wl,-soname,$@.so -o $(LIB_DIR)/$@.so.0.0 $< -lc $(LIB_RP_VARIABLE)
     50libRpString: RpString.o libRpVariable
     51        $(CPP) $(DEGUG) -shared -Wl,-rpath,./ \
     52                -Wl,-soname,$@.so -o $@.so.0.0 $< -lc $(LIB_RP_VARIABLE)
    5353                           
    54         /sbin/ldconfig -n $(LIB_DIR)
     54        /sbin/ldconfig -n ./
    5555
    5656#### libRpBoolean ##########################################################
    57 libRpBoolean: $(WORK_DIR)/RpBoolean.o libRpVariable
    58         $(CPP) $(DEGUG) -shared -Wl,-rpath,../lib \
    59                 -Wl,-soname,$@.so -o $(LIB_DIR)/$@.so.0.0 $< -lc $(LIB_RP_VARIABLE)
     57libRpBoolean: RpBoolean.o libRpVariable
     58        $(CPP) $(DEGUG) -shared -Wl,-rpath,./ \
     59                -Wl,-soname,$@.so -o $@.so.0.0 $< -lc $(LIB_RP_VARIABLE)
    6060                           
    61         /sbin/ldconfig -n $(LIB_DIR)
     61        /sbin/ldconfig -n ./
    6262
    6363#### libRpChoice ##########################################################
    64 libRpChoice: $(WORK_DIR)/RpChoice.o libRpVariable libRpOption
    65         $(CPP) $(DEGUG) -shared -Wl,-rpath,../lib \
    66                 -Wl,-soname,$@.so -o $(LIB_DIR)/$@.so.0.0 $< -lc $(LIB_RP_VARIABLE) $(LIB_RP_OPTION)
     64libRpChoice: RpChoice.o libRpVariable libRpOption
     65        $(CPP) $(DEGUG) -shared -Wl,-rpath,./ \
     66                -Wl,-soname,$@.so -o $@.so.0.0 $< -lc $(LIB_RP_VARIABLE) $(LIB_RP_OPTION)
    6767                           
    68         /sbin/ldconfig -n $(LIB_DIR)
     68        /sbin/ldconfig -n ./
    6969
    7070#### libRpOption ##########################################################
    71 libRpOption: $(WORK_DIR)/RpOption.o $(WORK_DIR)/RpAbout.o
    72         $(CPP) $(DEGUG) -shared -Wl,-rpath,../lib \
    73                 -Wl,-soname,$@.so -o $(LIB_DIR)/$@.so.0.0 $< -lc $(LIB_RP_ABOUT)
     71libRpOption: RpOption.o RpAbout.o
     72        $(CPP) $(DEGUG) -shared -Wl,-rpath,./ \
     73                -Wl,-soname,$@.so -o $@.so.0.0 $< -lc $(LIB_RP_ABOUT)
    7474                           
    75         /sbin/ldconfig -n $(LIB_DIR)
     75        /sbin/ldconfig -n ./
    7676
  • 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.