source: trunk/examples/c-example/plotc.c @ 92

Last change on this file since 92 was 92, checked in by cxsong, 17 years ago

fixed a few things so it compiles now.

File size: 2.3 KB
Line 
1#include "RpLibraryCInterface.h"
2
3//#include <stdlib.h>
4#include <time.h>
5#include <string.h>
6#include <stdio.h>
7
8int main(int argc, char * argv[])
9{
10
11    RpLibrary* lib = NULL;
12
13    char* filePath;
14    char* xmltext = NULL;
15    double fmin, fmax;
16    char strFormula[100];
17    int i;
18
19    double fx, fy;
20    int npts = 100;
21    char str[50];
22
23    memset(strFormula, '\0', 100);
24
25    if (argc < 2) {
26        printf("usage: %s driver.xml\n", argv[0]);
27    }
28
29    filePath = argv[1];
30
31    if (DEBUG)
32        printf("filePath: %s:\n", filePath);
33
34    // create a rappture library from the file filePath
35    lib = library(argv[1]);
36
37    if (lib) {
38        if(DEBUG) {
39            printf("created Rappture Library successfully\n");
40        }
41    }
42    else {
43        // cannot open file or out of memory
44        printf("FAILED creating Rappture Library\n");
45        exit(1);
46    }
47
48    // get the xml that is stored in the rappture library lib
49    if( (xmltext = xml(lib)) ) {
50        if(DEBUG) {
51        //printf("XML file content:\n");
52        //printf("%s\n", xmltext);
53    }
54    }
55    else {
56        printf("xml(lib) failed\n");
57        exit(1);
58    }
59
60    // get the min
61    xmltext = getString (lib, "input.number(min).current");
62
63    if (! (xmltext) ) {
64        printf("getString(lib,input.number(xmin).current) returns null\n");
65        exit(1);
66    }
67
68    // if you want to keep the string around, you will need to malloc
69    // space for it and strncpy() it to your own space.
70    // it will live in rappture's memory until the next call to getString()
71
72    if(DEBUG) {
73        printf("xml min: %s: len=%d\n", xmltext, strlen(xmltext));
74    }
75
76    fmin = atof(xmltext);
77    // fmin = getDouble(lib,"input.number(min).current");
78    if(DEBUG) {
79        printf("min: %f\n", fmin);
80    }
81
82    // get the max
83    fmax = getDouble(lib,"input.(max).current");
84    if(DEBUG) {
85        printf("max: %f\n", fmax);
86    }
87
88    // evaluate formula and generate results
89    for (i = 0; i<npts; i++) {
90        fx = i* (fmax - fmin)/npts + fmin;
91        fy = sin(fx);
92        sprintf(str, "%f %f\n", fx, fy);
93        put(lib, "output.curve.component.xy", str, "result", 1);
94    }
95
96
97    // write output to run file and signal
98    result(lib);
99
100    return 0;
101}
Note: See TracBrowser for help on using the repository browser.