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: Michael McLennan, Purdue University |
---|
9 | % AUTHOR: Derrick Kearney, Purdue University |
---|
10 | % Copyright (c) 2004-2005 Purdue Research Foundation |
---|
11 | % |
---|
12 | % See the file "license.terms" for information on usage and |
---|
13 | % redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
14 | % ====================================================================== |
---|
15 | |
---|
16 | % get input file from the command line |
---|
17 | % open our xml input file. |
---|
18 | infile = sprintf("%s",argv(1,:)); |
---|
19 | lib = rpLib(infile); |
---|
20 | |
---|
21 | % retrieve user specified data out of the input file |
---|
22 | % convert values to correct units. |
---|
23 | Ef = rpLibGetString(lib,"input.number(Ef).current"); |
---|
24 | [Ef,err] = rpUnitsConvertDbl(Ef,"eV"); |
---|
25 | T = rpLibGetString(lib,"input.number(temperature).current"); |
---|
26 | [T,err] = rpUnitsConvertDbl(T,"K"); |
---|
27 | |
---|
28 | % do fermi calculations (science)... |
---|
29 | kT = 8.61734e-5 * T; |
---|
30 | Emin = Ef - 10*kT; |
---|
31 | Emax = Ef + 10*kT; |
---|
32 | |
---|
33 | E = linspace(Emin,Emax,200); |
---|
34 | f = 1.0 ./ (1.0 + exp((E - Ef)/kT)); |
---|
35 | |
---|
36 | % prepare out output section |
---|
37 | % label graphs |
---|
38 | rpLibPutString(lib,"output.curve(f12).about.label","Fermi-Dirac Factor",0); |
---|
39 | rpLibPutString(lib,"output.curve(f12).xaxis.label","Fermi-Dirac Factor",0); |
---|
40 | rpLibPutString(lib,"output.curve(f12).yaxis.label","Energy",0); |
---|
41 | rpLibPutString(lib,"output.curve(f12).yaxis.units","eV",0); |
---|
42 | |
---|
43 | % this is a slow and inefficient method of putting |
---|
44 | % large amounts of data back in to the rappture library object |
---|
45 | %for j=1:200 |
---|
46 | % rpUtilsProgress((j/200*100),'Iterating'); |
---|
47 | % putStr = sprintf('%12g %12g\n', f(j), E(j)); |
---|
48 | % % put the data into the xml file |
---|
49 | % rpLibPutString(lib,"output.curve(f12).component.xy",putStr,1); |
---|
50 | %end |
---|
51 | |
---|
52 | % a better way is to take advantage of octave's vector operations. |
---|
53 | outData = [f;E]; |
---|
54 | putStr = sprintf('%12g %12g\n', outData); |
---|
55 | rpLibPutString(lib,'output.curve(f12).component.xy',putStr,0); |
---|
56 | |
---|
57 | % signal the end of processing |
---|
58 | rpLibResult(lib); |
---|