source: trunk/examples/app-fermi/cee/fermi.c @ 124

Last change on this file since 124 was 124, checked in by dkearney, 19 years ago

added c example for app-fermi
not sure if it compiles on mac

File size: 2.1 KB
Line 
1// ----------------------------------------------------------------------
2//  EXAMPLE: Fermi-Dirac function in Python.
3//
4//  This simple example shows how to use Rappture within a simulator
5//  written in Python.
6// ======================================================================
7//  AUTHOR:  Michael McLennan, Purdue University
8//  Copyright (c) 2004-2005  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
14#include "RpLibraryCInterface.h"
15#include "RpUnitsCInterface.h"
16
17#include <stdlib.h>
18#include <stdio.h>
19#include <math.h>
20
21int main(int argc, char * argv[]) {
22
23    RpLibrary* lib    = NULL;
24
25    const char* data  = NULL;
26    char line[100];
27
28    double T          = 0.0;
29    double Ef         = 0.0;
30    double E          = 0.0;
31    double dE         = 0.0;
32    double kT         = 0.0;
33    double Emin       = 0.0;
34    double Emax       = 0.0;
35    double f          = 0.0;
36
37    int err           = 0;
38
39    // create a rappture library from the file filePath
40    lib = rpLibrary(argv[1]);
41
42    if (lib == NULL) {
43        // cannot open file or out of memory
44        printf("FAILED creating Rappture Library\n");
45        return(1);
46    }
47
48
49    data = rpGetString(lib,"input.(temperature).current");
50    T = rpConvertDbl(data, "K", &err);
51    if (err) {
52        printf ("Error while retrieving input.(temperature).current\n");
53        return(1);
54    }
55
56
57    data = rpGetString(lib,"input.(Ef).current");
58    Ef = rpConvertDbl(data, "eV", &err);
59    if (err) {
60        printf ("Error while retrieving input.(Ef).current\n");
61        return(1);
62    }
63
64    kT = 8.61734e-5 * T;
65    Emin = Ef - 10*kT;
66    Emax = Ef + 10*kT;
67
68    E = Emin;
69    dE = 0.005*(Emax-Emin);
70
71    while (E < Emax) {
72        f = 1.0/(1.0 + exp((E - Ef)/kT));
73        sprintf(line,"%f %f\n",f, E);
74        rpPutString(lib,"output.curve(f12).component.xy", line, 1);
75        E = E + dE;
76    }
77
78    rpResult(lib);
79    return 0;
80}
Note: See TracBrowser for help on using the repository browser.