source: trunk/examples/objects/app-fermi/c/ex3/fermi_io.c @ 1655

Last change on this file since 1655 was 1655, checked in by dkearney, 11 years ago

examples of using a view in tcl and c, update tcl and c view apis

File size: 3.0 KB
Line 
1#include "rappture.h"
2
3void fermi_io() {
4
5    Rp_Table *result = NULL;
6    Rp_TableColumn *x1 = NULL;
7    Rp_TableColumn *y1 = NULL;
8    Rp_TableColumn *x2 = NULL;
9    Rp_TableColumn *y2 = NULL;
10    Rp_View *v1 = NULL;
11    Rp_View *v2 = NULL;
12    Rp_View *v3 = NULL;
13
14    // assume global interface variable.
15    // newly created objects are stored in the
16    // global interface variable. if there is more
17    // than one global interface variable, the
18    // interface that should be used is specified
19    // using the Rp_???InitX version of the funtion
20    // where ??? represents the type of object the
21    // user is trying to create.
22
23    // describe the inputs
24    // declare a number named "temperature",
25    // with units of Kelvin, default value 300,
26    //
27    // the next number is named "Ef", has units of
28    // electron Volts, default value of -5.5
29    //
30    // Rp_Number is assumed to be an input
31    Rp_NumberInit("temperature","K",300);
32    Rp_NumberInit("Ef","eV",-5.5);
33
34    // describe the outputs
35    // declare a table to store the outputs
36    // table is named "factorsTable".
37    // two new columns are added to the
38    // table "factorsTable". the first column is named
39    // "Fermi-Dirac Factor", a description is provided,
40    // and it has no units. the second column is named
41    // "Energy", a description is provided, and has units
42    // of electron Volts
43    results = Rp_TableInit("factorsTable",RP_VAR_OUTPUT);
44
45    x1 = Rp_TableColumnInit(results,"Fermi-Dirac Factor",
46            "Plot of Fermi-Dirac Calculation");
47    y1 = Rp_TableColumnInit(results,"Energy",
48            "Energy cooresponding to each fdf");
49    Rp_TableColumnHint(y1,"units","eV");
50
51    x2 = Rp_TableColumnInit(results,"Fermi-Dirac Factor * 2",
52            "Plot of Fermi-Dirac Calculation multiplied by 2");
53    y2 = Rp_TableColumnInit(results,"Energy * 2",
54            "Energy cooresponding to each fdf multiplied by 2");
55    Rp_TableColumnHint(y2,"units","eV");
56
57    // describe how the outputs should be displayed
58    // initialize a view named "fdfView", with a 1x1 layout.
59    // next, add a plot named "fdfPlot" to the view "fdfView".
60    // populate the plot with data from the table
61    // "factorsTable". Plot the column named
62    // "Fermi-Dirac Factor" vs the column named "Energy".
63    // place the plot, named fdfPlot, at position 1x1 (by default)
64    // within the view's layout.
65    // Rp_View is assumed to be an output
66    v1 = Rp_ViewInit("fdfView");
67    Rp_ViewPlot(v1,"fdfPlot",1,1,x1,y1,"g:o");
68
69    // two stacked plots in the same view
70    v2 = Rp_ViewInit("fdfView2");
71    Rp_ViewPlot(v2,"fdfPlot2",1,1,x1,y1,"g:o");
72    Rp_ViewPlot(v2,"fdfPlot3",2,1,x2,y2,"b-o");
73
74    // two side by side plots in the same view
75    v3 = Rp_ViewInit("fdfView3");
76    Rp_ViewPlot(v3,"fdfPlot4",1,1,x1,y1,"g:o");
77    Rp_ViewPlot(v3,"fdfPlot5",1,2,x2,y2,"b-o");
78
79    // grouped curves in one plot in a view
80    // plots hold same location in the view
81    v4 = Rp_ViewInit("fdfView4");
82    Rp_ViewPlot(v4,"fdfPlot6",1,1,x1,y1,"g:o");
83    Rp_ViewPlot(v4,"fdfPlot7",1,1,x2,y2,"b-o");
84}
Note: See TracBrowser for help on using the repository browser.