1 | % ---------------------------------------------------------------------- |
---|
2 | % EXAMPLE: Fermi-Dirac function in Octave. |
---|
3 | % |
---|
4 | % This script represents a newly written application with rappture |
---|
5 | % bindings and interface. |
---|
6 | % |
---|
7 | % ====================================================================== |
---|
8 | % AUTHOR: Derrick Kearney, Purdue University |
---|
9 | % Copyright (c) 2005-2009 Purdue Research Foundation |
---|
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 | |
---|
15 | function fermi4(argv) |
---|
16 | |
---|
17 | % declare variables to interact with Rappture |
---|
18 | T = 0.0; |
---|
19 | Ef = 0.0; |
---|
20 | result = 0; |
---|
21 | |
---|
22 | % declare program variables |
---|
23 | E = 0.0; |
---|
24 | dE = 0.0; |
---|
25 | kT = 0.0; |
---|
26 | Emin = 0.0; |
---|
27 | Emax = 0.0; |
---|
28 | f = 0.0; |
---|
29 | nPts = 200; |
---|
30 | |
---|
31 | % initialize the global interface |
---|
32 | Rp_InterfaceInit(argv,@fermi_io); |
---|
33 | |
---|
34 | % check that global interface for errors |
---|
35 | if (Rp_InterfaceError() != 0)) { |
---|
36 | % there were errors while setting up the interface |
---|
37 | % dump the traceback |
---|
38 | o = Rp_InterfaceOutcome(); |
---|
39 | fprintf(2, '%s', Rp_OutcomeContext(o)); |
---|
40 | fprintf(2, '%s', Rp_OutcomeRemark(o)); |
---|
41 | return(Rp_InterfaceError()); |
---|
42 | } |
---|
43 | |
---|
44 | % connect variables to the interface |
---|
45 | % look in the global interface for an object named |
---|
46 | % 'temperature', convert its value to Kelvin, and |
---|
47 | % store the value into the variable T. |
---|
48 | % look in the global interface for an object named |
---|
49 | % 'Ef', convert its value to electron Volts and store |
---|
50 | % the value into the variable Ef. |
---|
51 | % look in the global interface for the columns to |
---|
52 | % store data. retrieve them for later use. |
---|
53 | T = Rp_InterfaceConnect('temperature','units=K'); |
---|
54 | Ef = Rp_InterfaceConnect('Ef','units=eV'); |
---|
55 | |
---|
56 | x1 = Rp_InterfaceConnect('Fermi-Dirac Factor'); |
---|
57 | y1 = Rp_InterfaceConnect('Energy'); |
---|
58 | x2 = Rp_InterfaceConnect('Fermi-Dirac Factor * 2'); |
---|
59 | y2 = Rp_InterfaceConnect('Energy * 2'); |
---|
60 | |
---|
61 | % check the global interface for errors |
---|
62 | if (Rp_InterfaceError() != 0) { |
---|
63 | % there were errors while retrieving input data values |
---|
64 | % dump the tracepack |
---|
65 | o = Rp_InterfaceOutcome(); |
---|
66 | fprintf(stderr, '%s', Rp_OutcomeContext(o)); |
---|
67 | fprintf(stderr, '%s', Rp_OutcomeRemark(o)); |
---|
68 | return(Rp_InterfaceError()); |
---|
69 | } |
---|
70 | |
---|
71 | % do fermi calculations (science)... |
---|
72 | kT = 8.61734e-5 * T; |
---|
73 | Emin = Ef - (10*kT); |
---|
74 | Emax = Ef + (10*kT); |
---|
75 | |
---|
76 | % store results in the results table |
---|
77 | % add data to the table pointed to by the variable result. |
---|
78 | % put the fArr data in the column named "Fermi-Dirac Factor" |
---|
79 | % put the EArr data in the column named "Energy" |
---|
80 | |
---|
81 | Rp_TableColumnStore(x1,fArr); |
---|
82 | Rp_TableColumnStore(y1,EArr); |
---|
83 | Rp_TableColumnStore(x2,fArr2); |
---|
84 | Rp_TableColumnStore(y2,EArr2); |
---|
85 | |
---|
86 | % close the global interface |
---|
87 | % signal to the graphical user interface that science |
---|
88 | % calculations are complete and to display the data |
---|
89 | % as described in the views |
---|
90 | |
---|
91 | Rp_InterfaceClose(); |
---|
92 | |
---|
93 | return 0; |
---|