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

Last change on this file since 93 was 93, checked in by dkearney, 17 years ago
  1. corrected c interface language binding function names so they are

consistant with previous c interface function names

  1. separated object dictionaries from fortran code, placed them in

the RpBindings.[h,cc] files so matlab bindings can use them too.

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