To create a curve in a Rappture C program, we make people do something like this:
... rpPutString ( lib, "output.curve(f12).about.label", "Fermi-Dirac Factor", RPLIB_OVERWRITE ); rpPutString ( lib, "output.curve(f12).xaxis.label", "Fermi-Dirac Factor", RPLIB_OVERWRITE ); rpPutString ( lib, "output.curve(f12).yaxis.label", "Energy", RPLIB_OVERWRITE ); rpPutString ( lib, "output.curve(f12).yaxis.units", "eV", RPLIB_OVERWRITE ); while (E < Emax) { f = 1.0/(1.0 + exp((E - Ef)/kT)); sprintf(line,"%f %f\n",f, E); rpUtilsProgress((int)((E-Emin)/(Emax-Emin)*100),"Iterating"); rpPutString(lib,"output.curve(f12).component.xy", line, RPLIB_APPEND); E = E + dE; } ...
Using RpCurve Object with accessor functions:
... size_t i = 0; size_t cnt = (Emax - E)/dE; double *f = (double*) malloc(cnt*sizeof(double)); double *En = (double*) malloc(cnt*sizeof(double)); RpCurve *c = (RpCurve*) malloc(sizeof(RpCurve)); // assume allocation succeeded // register the object so lib can keep track of it, set a call back/notifier rpLib_register(lib,c); // annotate the curve rpCurve_path(c,"output.curve(f12)"); rpCurve_title(c,"Fermi-Dirac Factor") rpCurve_xlabel(c,"Fermi-Dirac Factor"); rpCurve_ylabel(c,"Energy"); rpCurve_yunits(c,"eV"); while (E < Emax) { f[i] = 1.0/(1.0 + exp((E - Ef)/kT)); En[i] = E; rpUtilsProgress((int)((E-Emin)/(Emax-Emin)*100),"Iterating"); E = E + dE; } // plot the value from the arrays rpCurve_plot(c,f,En); if (c) { free(c); c = NULL; } if (f) { free(f); f = NULL; } if (En) { free(En); En = NULL; } ...
The accessor functions can be replaced with annotate functions:
rpCurve_annotate(c,"path","output.curve(f12)"); rpCurve_annotate(c,"name","f12"); rpCurve_annotate(c,"title","Fermi-Dirac Factor"); rpCurve_annotate(c,"xlabel","Fermi-Dirac Factor"); rpCurve_annotate(c,"ylabel","Energy"); rpCurve_annotate(c,"yunits","eV");
Internally, the RpCurve object should have a hash of curve properties.
Curve Properties:
- path - full xml path of the object.
- name - name or id of the curve. This text is displayed when scrolling over the xy plot, or searching for a specific curve.
- title - title of the plot. Text to be displayed in the Results drop down menu in the gui.
- xlabel - label of the x axis.
- xunits - units of values along the x axis.
- xscale - scale of the x axis. one of linear,log.
- ylabel - label of the y axis.
- yunits - units of values along the y axis.
- yscale - scale of the y axis. one of linear,log.
- color - color of the curve.
- marker - type of marker to use.
- type - type of curve. one of column,bar,area,line(default),xyscatter,xyerror.
- group - grouping curves so they show up on the same graph.
Curve Accessor functions:
- int rpCurve_path(RpCurve *c, const char *val);
- int rpCurve_name(RpCurve *c, const char *val);
- int rpCurve_title(RpCurve *c, const char *val);
- int rpCurve_xlabel(RpCurve *c, const char *val);
- int rpCurve_xunits(RpCurve *c, const char *val);
- int rpCurve_ylabel(RpCurve *c, const char *val);
- int rpCurve_yunits(RpCurve *c, const char *val);
- int rpCurve_annotate(RpCurve *c, const char *prop, const char *val);
- int rpCurve_prop_lookup(RpCurve *c, const char *prop, const char *val);
Last modified 16 years ago
Last modified on Aug 4, 2008 1:05:02 PM