Changeset 3177 for trunk/examples/objects/app-fermi/c/ex2/fermi.c
- Timestamp:
- Sep 21, 2012, 10:01:16 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/examples/objects/app-fermi/c/ex2/fermi.c
r1655 r3177 1 // ---------------------------------------------------------------------- 2 // EXAMPLE: Fermi-Dirac function in C 3 // 4 // This simple example shows how to use Rappture within a simulator 5 // written in C. 6 // ====================================================================== 7 // AUTHOR: Derrick Kearney, Purdue University 8 // Copyright (c) 2005-2009 Purdue Research Foundation 9 // 10 // See the file "license.terms" for information on usage and 11 // redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. 12 // ====================================================================== 13 1 /* 2 * ---------------------------------------------------------------------- 3 * EXAMPLE: Fermi-Dirac function in C 4 * 5 * This simple example shows how to use Rappture within a simulator 6 * written in C. 7 * ====================================================================== 8 * AUTHOR: Derrick Kearney, Purdue University 9 * Copyright (c) 2004-2012 HUBzero Foundation, LLC 10 * 11 * See the file "license.terms" for information on usage and 12 * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. 13 * ====================================================================== 14 */ 14 15 #include "rappture.h" 15 16 … … 23 24 int main(int argc, char * argv[]) { 24 25 25 / / declare variables to interact with Rappture26 /* declare variables to interact with Rappture */ 26 27 double T = 0.0; 27 28 double Ef = 0.0; … … 30 31 31 32 32 / / declare program variables33 /* declare program variables */ 33 34 double E = 0.0; 34 35 double dE = 0.0; … … 42 43 double fArr[nPts]; 43 44 44 / / initialize the global interface45 /* initialize the global interface */ 45 46 Rp_InterfaceInit(argc,argv,&fermi_io); 46 47 47 / / check the global interface for errors48 /* check the global interface for errors */ 48 49 if (Rp_InterfaceError() != 0) { 49 / / there were errors while setting up the interface50 / / dump the traceback50 /* there were errors while setting up the interface */ 51 /* dump the traceback */ 51 52 Rp_Outcome *o = Rp_InterfaceOutcome(); 52 53 fprintf(stderr, "%s", Rp_OutcomeContext(o)); … … 55 56 } 56 57 57 // connect variables to the interface 58 // look in the global interface for an object named 59 // "temperature", convert its value to Kelvin, and 60 // store the value into the address of T. 61 // look in the global interface for an object named 62 // "Ef", convert its value to electron Volts and store 63 // the value into the address of Ef. 64 // look in the global interface for an object named 65 // factorsTable and set the variable result to 66 // point to it. 58 /* 59 * connect variables to the interface 60 * look in the global interface for an object named 61 * "temperature", convert its value to Kelvin, and 62 * store the value into the address of T. 63 * look in the global interface for an object named 64 * "Ef", convert its value to electron Volts and store 65 * the value into the address of Ef. 66 * look in the global interface for an object named 67 * factorsTable and set the variable result to 68 * point to it. 69 */ 67 70 Rp_InterfaceConnect("temperature",&T,"units=K",NULL); 68 71 Rp_InterfaceConnect("Ef",&Ef,"units=eV",NULL); … … 70 73 Rp_InterfaceConnect("fdfPlot2",p2,NULL); 71 74 72 / / check the global interface for errors75 /* check the global interface for errors */ 73 76 if (Rp_InterfaceError() != 0) { 74 / / there were errors while retrieving input data values75 / / dump the traceback77 /* there were errors while retrieving input data values */ 78 /* dump the traceback */ 76 79 Rp_Outcome *o = Rp_InterfaceOutcome(); 77 80 fprintf(stderr, "%s", Rp_OutcomeContext(o)); … … 80 83 } 81 84 82 / / do science calculations85 /* do science calculations */ 83 86 kT = 8.61734e-5 * T; 84 87 Emin = Ef - (10*kT); … … 96 99 } 97 100 98 // set up the curves for the plot by using the add command 99 // Rp_PlotAdd(plot,name,nPts,xdata,ydata,fmt); 100 // 101 // to group curves on the same plot, just keep adding curves 102 // to save space, X array values are compared between curves. 103 // the the X arrays contain the same values, we only store 104 // one version in the internal data table, otherwise a new 105 // column is created for the array. for big arrays this may take 106 // some time, we should benchmark to see if this can be done 107 // efficiently. 108 101 /* 102 * set up the curves for the plot by using the add command 103 * Rp_PlotAdd(plot,name,nPts,xdata,ydata,fmt); 104 * 105 * to group curves on the same plot, just keep adding curves 106 * to save space, X array values are compared between curves. 107 * the the X arrays contain the same values, we only store 108 * one version in the internal data table, otherwise a new 109 * column is created for the array. for big arrays this may take 110 * some time, we should benchmark to see if this can be done 111 * efficiently. 112 */ 109 113 Rp_PlotAdd(p1,"fdfCurve1",nPts,fArr,EArr,"g:o"); 110 114 … … 112 116 Rp_PlotAdd(p2,"fdfCurve3",nPts,fArr,EArr,"p--"); 113 117 114 // close the global interface 115 // signal to the graphical user interface that science 116 // calculations are complete and to display the data 117 // as described in the views 118 /* 119 * close the global interface 120 * signal to the graphical user interface that science 121 * calculations are complete and to display the data 122 * as described in the views 123 */ 118 124 Rp_InterfaceClose(); 119 125
Note: See TracChangeset
for help on using the changeset viewer.