Changeset 90


Ignore:
Timestamp:
Oct 6, 2005 12:49:28 PM (19 years ago)
Author:
dkearney
Message:

adjusted the c-example which include a c example and a c++ example
also changed RpLibrary?.h to look for the scew library in the scew directory.

Location:
trunk
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/examples/c-example/Makefile

    r89 r90  
    11# define rappture src directory
    2 RP_BASE = /opt/rappture
     2RP_BASE         = /opt/rappture
     3
     4PROGS           = plot plotc
    35
    46# define our compiling environment
    57#
    6 CC                      = gcc
    7 CPP                     = g++
    8 DEBUG                   = -g -Wall
    9 DEBUG_PLUS              = -g -DDEBUG
     8CC              = gcc
     9CXX             = g++
     10DEBUG           = -g -Wall
     11DEBUG_PLUS      = -g -DDEBUG
    1012
    1113# define our directories
    1214#
    13 INCLUDES_DIR    = $(RP_BASE)/include
    14 INCL_CEE        = -I $(INCLUDES_DIR)/cee
    15 INCL_CORE       = -I $(INCLUDES_DIR)/core
    16 INCL_PY         = -I $(INCLUDES_DIR)/python2.4
     15INCLUDES_DIR    = $(RP_BASE)/include
     16INCL_CEE        = -I $(INCLUDES_DIR)/cee
     17INCL_CORE       = -I $(INCLUDES_DIR)/core
     18INCL_RP_DEPS    = -I $(RP_BASE)/include
    1719
    18 LIB_DIR         = $(RP_BASE)/lib
    19 LIB_INC_PREFIX  = -Wl,-rpath,$(LIB_DIR) -L$(LIB_DIR)
    20 LIB_RAPPTURE    = -Wl,-rpath,$(LIB_DIR) -L$(LIB_DIR) -lrappture
     20LIB_DIR         = $(RP_BASE)/lib
     21LIB_INC_PREFIX  = -Wl,-rpath,$(LIB_DIR) -L$(LIB_DIR)
     22LIB_RAPPTURE    = -Wl,-rpath,$(LIB_DIR) -L$(LIB_DIR) -lrappture
    2123
    22 plot: plot.cc
    23         $(CPP) $(DEBUG) -DDEBUG $(INCL_CEE) $(INCL_CORE) $(INCL_PY) -o $@ $< $(LIB_RAPPTURE)
     24plot: plot.cc
     25        $(CXX) $(DEBUG) -DDEBUG $(INCL_CEE) $(INCL_CORE) $(INCL_RP_DEPS) -o $@ $< $(LIB_RAPPTURE)
     26
     27plotc: plot.cc
     28        $(CC) $(DEBUG) -DDEBUG $(INCL_CEE) $(INCL_CORE) $(INCL_RP_DEPS) -o $@ $< $(LIB_RAPPTURE)
    2429
    2530#### CLEAN UP ############################################################
    2631clean:
    27         rm -f plot
     32        rm -f $(PROGS) run*.xml
  • trunk/examples/c-example/README

    r61 r90  
     1To build the programs "plot" and "plotc" in this directory, type:
     2        % make
    13To build the progrma "plot" in this directory, type:
    2         % make
     4        % make plot
     5To build the progrma "plot" in this directory, type:
     6        % make plotc
     7
     8To run plot, type:
     9    % driver &
     10To run plotc, type:
     11    % driver -tool tool2.xml &
  • trunk/examples/c-example/plot.cc

    r61 r90  
    1 #include "rappture_interface.h"
     1#include "RpLibrary.h"
     2
    23#include <stdlib.h>
    3 #include <time.h>
     4#include <math.h>
    45
    5 //
    6 // write result xml file out
    7 // put in directive to cause "run" to read and plot using run.xml
    8 //
    9 // return val:    0: error
    10 //              > 0: success
    11 //
    12 //
    13 int myOutputResult(PyObject* lib)
    14 {
    15         char outputFile[50];
    16         char* xtext = NULL;
    17         FILE* fp = NULL;
    18 
    19         xtext = rpXml(lib);
    20         if (!xtext) {
    21                 printf("rpXml error\n");
    22                 return 0;
    23         }
    24 
    25         // create output filename
    26        
    27 
    28         time_t t;
    29 
    30         snprintf(outputFile, 50, "run%d.xml", (int)time(&t));
    31         if(!(fp = fopen(outputFile, "w"))) {
    32                 printf("output file open error (err=%d)\n", errno);
    33                 return 0;
    34         }
    35 
    36         int fsize = fwrite(xtext, strlen(xtext), 1, fp);
    37         if(DEBUG)
    38                 printf("output file size=%d\n", fsize);
    39         fclose(fp);
    40 
    41         printf("=RAPPTURE-RUN=>%s\n", outputFile);
    42 
    43         return 1;
    44 }
     6#include <iostream>
     7#include <sstream>
    458
    469int main(int argc, char * argv[])
    4710{
    4811
    49     PyObject* rpClass = NULL;
    50     PyObject* lib = NULL;
     12    RpLibrary* lib = NULL;
    5113
    52     //char filePath[100];
    53     char *filePath;
    54     char* xmltext = NULL;
     14    std::string filePath = "";
     15    std::string xmltext = "";
    5516    double fmin, fmax;
    56     char strFormula[100];
     17    std::string strFormula = "";
    5718    int i;
    5819
    59     memset(strFormula, '\0', 100);
    60 
    61     filePath = argv[1];
    62 
    63     if (DEBUG)
    64         printf("filePath: %s:\n", filePath);
    65 
    66     // initialize the interpreter
    67     Py_Initialize();
    68     if(DEBUG)
    69         printf("py_init successful\n");
    70 
    71     // import the rappture library
    72     if(!(rpClass = importRappture())) {
    73             printf("importRappture returns NULL\n");
    74             exit(1);
     20    if (argc < 2) {
     21        std::cout << "usage: " << argv[0] << " driver.xml" << std::endl;
    7522    }
    7623
    77     if(!(lib = createRapptureObj(rpClass, filePath))) {
    78             printf("createRapptureObj returns NULL\n");
    79             exit(1);
    80         }
     24    filePath = std::string(argv[1]);
    8125
    82     Py_DECREF(rpClass);
     26    if (DEBUG) {
     27        std::cout << "filePath: " << filePath << std::endl;
     28    }
    8329
    84     if(DEBUG)
    85         printf("createRapptureObj successful\n");
     30    // create a rappture library from the file filePath
     31    lib = new RpLibrary(filePath);
    8632
    87     if((xmltext = (char*)rpXml(lib))) {
     33    if (lib) {
    8834        if(DEBUG) {
    89             //printf("XML file content:\n");
    90             //printf("%s\n", xmltext);
    91         }
     35            std::cout << "created Rappture Library successfully" << std::endl;
     36        }
    9237    }
    9338    else {
    94             printf("rpXml(lib) failed\n");
    95             exit(1);
     39        // cannot open file or out of memory
     40        std::cout << "FAILED creating Rappture Library" << std::endl;
     41        exit(1);
     42    }
     43
     44    // get the xml that is stored in the rappture library lib
     45    xmltext = lib->xml();
     46
     47    if(! (xmltext.empty()) ) {
     48        if(DEBUG) {
     49        //printf("XML file content:\n");
     50        //printf("%s\n", xmltext);
     51    }
     52    }
     53    else {
     54        printf("lib->xml() failed\n");
     55        exit(1);
    9656    }
    9757
    9858    // get the min
    99     if (!(xmltext = (char *) rpGet(lib, "input.number(min).current"))) {
    100             printf("rpGet(input.number(xmin).current) returns null\n");
    101             exit(1);
     59    xmltext = lib->getString("input.number(min).current");
     60
     61    if ( xmltext.empty() ) {
     62        std::cout << "lib->getString(input.number(xmin).current) returns null" << std::endl;
     63        exit(1);
    10264    }
    103     if(DEBUG)
    104         printf("xml min: %s: len=%d\n", xmltext, strlen(xmltext));
    105     fmin = atof((char*)xmltext);
    106     if(DEBUG)
    107         printf("min: %f\n", fmin);
     65
     66    if(DEBUG) {
     67        std::cout << "xml min :" << xmltext << ": len=" << xmltext.size() << std::endl;
     68    }
     69
     70    // grab a double value from the xml
     71    fmin = lib->getDouble("input.number(min).current");
     72
     73    if(DEBUG) {
     74        std::cout << "min: " << fmin << std::endl;
     75    }
    10876
    10977    // get the max
    110     if (!(xmltext = (char *) rpGet(lib, "input.number(max).current"))) {
    111             printf("rpGet(input.number(xmax).current) returns null\n");
    112             exit(1);
     78    fmax = lib->getDouble("input.(max).current");
     79    if(DEBUG) {
     80        std::cout << "max: " << fmax << std::endl;
    11381    }
    114     if(DEBUG)
    115         printf("xml max: %s: len=%d\n", xmltext, strlen(xmltext));
    116     fmax = atof((char*)xmltext);
    117     if(DEBUG)
    118         printf("max: %f\n", fmax);
    11982
    12083    // evaluate formula and generate results
     84    // science begains here
    12185    double fx, fy;
    12286    int npts = 100;
    123     char str[50];
     87    std::stringstream myStr;
     88
    12489    for (i = 0; i<npts; i++) {
    125             fx = i* (fmax - fmin)/npts + fmin;
    126             fy = sin(fx);
    127             sprintf(str, "%f %f\n", fx, fy);
    128             rpPut(lib, "output.curve.component.xy", str, "result", 1);
     90        fx = i* (fmax - fmin)/npts + fmin;
     91        fy = sin(fx);
     92        myStr << fx << " " << fy << std::endl;
     93        lib->put("output.curve.component.xy", myStr.str(), "result", 1);
    12994    }
    130    
    13195
    132     // output
    133     myOutputResult(lib);
    13496
    135     Py_DECREF(lib);
    136    
    137     // shut down the interpreter
    138     Py_Finalize();
     97    // write output to run file and signal
     98    lib->result();
     99
    139100    return 0;
    140101}
  • trunk/examples/c-example/tool.xml

    r61 r90  
    44        <title>SIN(x) Graph</title>
    55        <about>Press Simulate to view results.</about>
    6         <command> @tool/plot @driver</command>
     6        <command> @tool/plotc @driver</command>
    77    </tool>
    88    <input>
  • trunk/include/core/RpLibrary.h

    r83 r90  
    1010 */
    1111
    12 #include "scew.h"
     12#include "scew/scew.h"
    1313#include "scew_extras.h"
    1414#include <iostream>
  • trunk/src/Makefile

    r86 r90  
    44
    55# tell make where to find the expat & libscew sources
    6 EXPAT_HEADERS   = $(RP_INSTALL_BASE)/include
    7 LIB_EXPAT_INCL  = -I $(EXPAT_HEADERS)
    8 SCEW_HEADERS    = $(RP_INSTALL_BASE)/include/scew
    9 LIB_SCEW_INCL   = -I $(SCEW_HEADERS) -I $(EXPAT_HEADERS)
     6INCL_RP_DEPS    = -I $(RP_INSTALL_BASE)/include
     7
     8#EXPAT_HEADERS   = $(RP_INSTALL_BASE)/include
     9#LIB_EXPAT_INCL  = -I $(EXPAT_HEADERS)
     10#SCEW_HEADERS    = $(RP_INSTALL_BASE)/include/scew
     11#LIB_SCEW_INCL   = -I $(SCEW_HEADERS) -I $(EXPAT_HEADERS)
     12
    1013LIB_SCEW_FLAG   = -L$(RP_INSTALL_BASE)/lib -lscew
     14
    1115#LIB_SCEW_FLAG   = /opt/rappture/lib/libscew.a
    1216#LIB_SCEW_FLAG   = -static -L/opt/rappture/lib -lscew
     
    6973                  scew_extras.o
    7074RP_UNITS_DEPS   = RpUnitsStd.o RpUnits.o RpUnitsCInterface.o RpUnitsFInterface.o
    71 RP_OTHER_DEPS   = RpFortranCommon.o
     75RP_OTHER_DEPS   = RpFortranCommon.o # RpBindingsDict.o
    7276RP_OBJS_DEP     = RpVariable.o RpAbout.o RpNumber.o RpString.o RpBoolean.o \
    7377                  RpChoice.o RpOption.o RpUnitsStd.o RpUnits.o
     
    110114
    111115RpLibrary.o: $(CORE_SRC)/RpLibrary.cc
    112         $(CXX) -fPIC $(DEBUG) $(INCL_CORE) $(LIB_SCEW_INCL) -o $@ -c $?
     116        $(CXX) -fPIC $(DEBUG) $(INCL_CORE) $(INCL_RP_DEPS) -o $@ -c $?
    113117
    114118scew_extras.o: $(CORE_SRC)/scew_extras.c
    115         $(CC) -fPIC $(DEBUG) $(INCL_CORE) $(LIB_SCEW_INCL) -o $@ -c $?
     119        $(CC) -fPIC $(DEBUG) $(INCL_CORE) $(INCL_RP_DEPS) -o $@ -c $?
    116120
    117121RpVariable.o: $(CORE_SRC)/RpVariable.cc
     
    142146        $(CXX) -fPIC $(DEBUG) $(INCL_CORE) -o $@ -c $?
    143147
     148RpBindingsDict.o: $(CORE_SRC)/RpBindingsDict.cc
     149        $(CXX) -fPIC $(DEBUG) $(INCL_CORE) -o $@ -c $?
     150
    144151
    145152
     
    154161
    155162RpLibraryCInterface.o: $(CEE_SRC)/RpLibraryCInterface.cc
    156         $(CXX) -fPIC $(DEBUG) $(INCL_CORE) $(INCL_CEE) $(LIB_SCEW_INCL) -o $@ -c $?
     163        $(CXX) -fPIC $(DEBUG) $(INCL_CORE) $(INCL_CEE) $(INCL_RP_DEPS) -o $@ -c $?
    157164
    158165
     
    170177        $(CXX) -fPIC $(DEBUG) $(INCL_FORTRAN) -o $@ -c $<
    171178
    172 RpLibraryFInterface.o: $(FORT_SRC)/RpLibraryFInterface.cc 
    173         $(CXX) -fPIC $(DEBUG) $(INCL_CORE) $(INCL_FORTRAN) $(LIB_SCEW_INCL) -o $@ -c $?
     179RpLibraryFInterface.o: $(FORT_SRC)/RpLibraryFInterface.cc
     180        $(CXX) -fPIC $(DEBUG) $(INCL_CORE) $(INCL_FORTRAN) $(INCL_RP_DEPS) -o $@ -c $?
    174181
    175182
Note: See TracChangeset for help on using the changeset viewer.