Changeset 90
- Timestamp:
- Oct 6, 2005 12:49:28 PM (18 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/examples/c-example/Makefile
r89 r90 1 1 # define rappture src directory 2 RP_BASE = /opt/rappture 2 RP_BASE = /opt/rappture 3 4 PROGS = plot plotc 3 5 4 6 # define our compiling environment 5 7 # 6 CC 7 C PP= g++8 DEBUG 9 DEBUG_PLUS 8 CC = gcc 9 CXX = g++ 10 DEBUG = -g -Wall 11 DEBUG_PLUS = -g -DDEBUG 10 12 11 13 # define our directories 12 14 # 13 INCLUDES_DIR 14 INCL_CEE 15 INCL_CORE 16 INCL_ PY = -I $(INCLUDES_DIR)/python2.415 INCLUDES_DIR = $(RP_BASE)/include 16 INCL_CEE = -I $(INCLUDES_DIR)/cee 17 INCL_CORE = -I $(INCLUDES_DIR)/core 18 INCL_RP_DEPS = -I $(RP_BASE)/include 17 19 18 LIB_DIR 19 LIB_INC_PREFIX 20 LIB_RAPPTURE 20 LIB_DIR = $(RP_BASE)/lib 21 LIB_INC_PREFIX = -Wl,-rpath,$(LIB_DIR) -L$(LIB_DIR) 22 LIB_RAPPTURE = -Wl,-rpath,$(LIB_DIR) -L$(LIB_DIR) -lrappture 21 23 22 plot: plot.cc 23 $(CPP) $(DEBUG) -DDEBUG $(INCL_CEE) $(INCL_CORE) $(INCL_PY) -o $@ $< $(LIB_RAPPTURE) 24 plot: plot.cc 25 $(CXX) $(DEBUG) -DDEBUG $(INCL_CEE) $(INCL_CORE) $(INCL_RP_DEPS) -o $@ $< $(LIB_RAPPTURE) 26 27 plotc: plot.cc 28 $(CC) $(DEBUG) -DDEBUG $(INCL_CEE) $(INCL_CORE) $(INCL_RP_DEPS) -o $@ $< $(LIB_RAPPTURE) 24 29 25 30 #### CLEAN UP ############################################################ 26 31 clean: 27 rm -f plot32 rm -f $(PROGS) run*.xml -
trunk/examples/c-example/README
r61 r90 1 To build the programs "plot" and "plotc" in this directory, type: 2 % make 1 3 To build the progrma "plot" in this directory, type: 2 % make 4 % make plot 5 To build the progrma "plot" in this directory, type: 6 % make plotc 7 8 To run plot, type: 9 % driver & 10 To 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 2 3 #include <stdlib.h> 3 #include < time.h>4 #include <math.h> 4 5 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> 45 8 46 9 int main(int argc, char * argv[]) 47 10 { 48 11 49 PyObject* rpClass = NULL; 50 PyObject* lib = NULL; 12 RpLibrary* lib = NULL; 51 13 52 //char filePath[100]; 53 char *filePath; 54 char* xmltext = NULL; 14 std::string filePath = ""; 15 std::string xmltext = ""; 55 16 double fmin, fmax; 56 char strFormula[100];17 std::string strFormula = ""; 57 18 int i; 58 19 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; 75 22 } 76 23 77 if(!(lib = createRapptureObj(rpClass, filePath))) { 78 printf("createRapptureObj returns NULL\n"); 79 exit(1); 80 } 24 filePath = std::string(argv[1]); 81 25 82 Py_DECREF(rpClass); 26 if (DEBUG) { 27 std::cout << "filePath: " << filePath << std::endl; 28 } 83 29 84 if(DEBUG)85 printf("createRapptureObj successful\n");30 // create a rappture library from the file filePath 31 lib = new RpLibrary(filePath); 86 32 87 if ((xmltext = (char*)rpXml(lib))) {33 if (lib) { 88 34 if(DEBUG) { 89 //printf("XML file content:\n"); 90 //printf("%s\n", xmltext); 91 } 35 std::cout << "created Rappture Library successfully" << std::endl; 36 } 92 37 } 93 38 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); 96 56 } 97 57 98 58 // 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); 102 64 } 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 } 108 76 109 77 // 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; 113 81 } 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);119 82 120 83 // evaluate formula and generate results 84 // science begains here 121 85 double fx, fy; 122 86 int npts = 100; 123 char str[50]; 87 std::stringstream myStr; 88 124 89 for (i = 0; i<npts; i++) { 125 126 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); 129 94 } 130 131 95 132 // output133 myOutputResult(lib);134 96 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 139 100 return 0; 140 101 } -
trunk/examples/c-example/tool.xml
r61 r90 4 4 <title>SIN(x) Graph</title> 5 5 <about>Press Simulate to view results.</about> 6 <command> @tool/plot @driver</command>6 <command> @tool/plotc @driver</command> 7 7 </tool> 8 8 <input> -
trunk/include/core/RpLibrary.h
r83 r90 10 10 */ 11 11 12 #include "scew .h"12 #include "scew/scew.h" 13 13 #include "scew_extras.h" 14 14 #include <iostream> -
trunk/src/Makefile
r86 r90 4 4 5 5 # 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) 6 INCL_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 10 13 LIB_SCEW_FLAG = -L$(RP_INSTALL_BASE)/lib -lscew 14 11 15 #LIB_SCEW_FLAG = /opt/rappture/lib/libscew.a 12 16 #LIB_SCEW_FLAG = -static -L/opt/rappture/lib -lscew … … 69 73 scew_extras.o 70 74 RP_UNITS_DEPS = RpUnitsStd.o RpUnits.o RpUnitsCInterface.o RpUnitsFInterface.o 71 RP_OTHER_DEPS = RpFortranCommon.o 75 RP_OTHER_DEPS = RpFortranCommon.o # RpBindingsDict.o 72 76 RP_OBJS_DEP = RpVariable.o RpAbout.o RpNumber.o RpString.o RpBoolean.o \ 73 77 RpChoice.o RpOption.o RpUnitsStd.o RpUnits.o … … 110 114 111 115 RpLibrary.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 $? 113 117 114 118 scew_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 $? 116 120 117 121 RpVariable.o: $(CORE_SRC)/RpVariable.cc … … 142 146 $(CXX) -fPIC $(DEBUG) $(INCL_CORE) -o $@ -c $? 143 147 148 RpBindingsDict.o: $(CORE_SRC)/RpBindingsDict.cc 149 $(CXX) -fPIC $(DEBUG) $(INCL_CORE) -o $@ -c $? 150 144 151 145 152 … … 154 161 155 162 RpLibraryCInterface.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 $? 157 164 158 165 … … 170 177 $(CXX) -fPIC $(DEBUG) $(INCL_FORTRAN) -o $@ -c $< 171 178 172 RpLibraryFInterface.o: $(FORT_SRC)/RpLibraryFInterface.cc 173 $(CXX) -fPIC $(DEBUG) $(INCL_CORE) $(INCL_FORTRAN) $( LIB_SCEW_INCL) -o $@ -c $?179 RpLibraryFInterface.o: $(FORT_SRC)/RpLibraryFInterface.cc 180 $(CXX) -fPIC $(DEBUG) $(INCL_CORE) $(INCL_FORTRAN) $(INCL_RP_DEPS) -o $@ -c $? 174 181 175 182
Note: See TracChangeset
for help on using the changeset viewer.