source: branches/1.7/examples/app-fermi/octave/octave4/fermi.m @ 6688

Last change on this file since 6688 was 6688, checked in by clarksm, 4 years ago

Add support for octave series 4

File size: 2.0 KB
Line 
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-2012  HUBzero Foundation, LLC
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.
18lib = rpLib(infile);
19
20% retrieve user specified data out of the input file
21% convert values to correct units.
22Ef = rpLibGetString(lib,"input.number(Ef).current");
23[Ef,err] = rpUnitsConvertDbl(Ef,"eV");
24T = rpLibGetString(lib,"input.number(temperature).current");
25[T,err] = rpUnitsConvertDbl(T,"K");
26
27% do fermi calculations (science)...
28kT = 8.61734e-5 * T;
29Emin = Ef - 10*kT;
30Emax = Ef + 10*kT;
31
32E = linspace(Emin,Emax,200);
33f = 1.0 ./ (1.0 + exp((E - Ef)/kT));
34
35% prepare out output section
36% label graphs
37rpLibPutString(lib,"output.curve(f12).about.label","Fermi-Dirac Factor",0);
38rpLibPutString(lib,"output.curve(f12).xaxis.label","Fermi-Dirac Factor",0);
39rpLibPutString(lib,"output.curve(f12).yaxis.label","Energy",0);
40rpLibPutString(lib,"output.curve(f12).yaxis.units","eV",0);
41
42% this is a slow and inefficient method of putting
43% large amounts of data back in to the rappture library object
44%for j=1:200
45%  rpUtilsProgress((j/200*100),'Iterating');
46%  putStr = sprintf('%12g  %12g\n', f(j), E(j));
47%  % put the data into the xml file
48%  rpLibPutString(lib,"output.curve(f12).component.xy",putStr,1);
49%end
50
51% a better way is to take advantage of octave's vector operations.
52outData = [f;E];
53putStr = sprintf('%12g  %12g\n', outData);
54rpLibPutString(lib,'output.curve(f12).component.xy',putStr,0);
55
56% signal the end of processing
57rpLibResult(lib);
58quit;
Note: See TracBrowser for help on using the repository browser.