source: trunk/examples/c-example/plot.cc @ 115

Last change on this file since 115 was 115, checked in by mmc, 18 years ago

Updated all copyright notices.

File size: 2.7 KB
Line 
1// ======================================================================
2//  Copyright (c) 2004-2005  Purdue Research Foundation
3//  See the file "license.terms" for information on usage and
4//  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
5// ======================================================================
6
7#include "RpLibrary.h"
8
9#include <stdlib.h>
10#include <math.h>
11
12#include <iostream>
13#include <sstream>
14
15int main(int argc, char * argv[])
16{
17
18    RpLibrary* lib = NULL;
19
20    std::string filePath = "";
21    std::string xmltext = "";
22    double fmin, fmax;
23    std::string strFormula = "";
24    int i;
25
26    if (argc < 2) {
27        std::cout << "usage: " << argv[0] << " driver.xml" << std::endl;
28    }
29
30    filePath = std::string(argv[1]);
31
32    if (DEBUG) {
33        std::cout << "filePath: " << filePath << std::endl;
34    }
35
36    // create a rappture library from the file filePath
37    lib = new RpLibrary(filePath);
38
39    if (lib) {
40        if(DEBUG) {
41            std::cout << "created Rappture Library successfully" << std::endl;
42        }
43    }
44    else {
45        // cannot open file or out of memory
46        std::cout << "FAILED creating Rappture Library" << std::endl;
47        exit(1);
48    }
49
50    // get the xml that is stored in the rappture library lib
51    xmltext = lib->xml();
52
53    if(! (xmltext.empty()) ) {
54        if(DEBUG) {
55        //printf("XML file content:\n");
56        //printf("%s\n", xmltext);
57    }
58    }
59    else {
60        printf("lib->xml() failed\n");
61        exit(1);
62    }
63
64    // get the min
65    xmltext = lib->getString("input.number(min).current");
66
67    if ( xmltext.empty() ) {
68        std::cout << "lib->getString(input.number(xmin).current) returns null" << std::endl;
69        exit(1);
70    }
71
72    if(DEBUG) {
73        std::cout << "xml min :" << xmltext << ": len=" << xmltext.size() << std::endl;
74    }
75
76    // grab a double value from the xml
77    fmin = lib->getDouble("input.number(min).current");
78
79    if(DEBUG) {
80        std::cout << "min: " << fmin << std::endl;
81    }
82
83    // get the max
84    fmax = lib->getDouble("input.(max).current");
85    if(DEBUG) {
86        std::cout << "max: " << fmax << std::endl;
87    }
88
89    // evaluate formula and generate results
90    // science begains here
91    double fx, fy;
92    int npts = 100;
93    std::stringstream myStr;
94
95    for (i = 0; i<npts; i++) {
96        fx = i* (fmax - fmin)/npts + fmin;
97        fy = sin(fx);
98        myStr << fx << " " << fy << std::endl;
99        lib->put("output.curve.component.xy", myStr.str(), "result", 1);
100    }
101
102
103    // write output to run file and signal
104    lib->result();
105
106    return 0;
107}
Note: See TracBrowser for help on using the repository browser.