Changeset 1615 for trunk/examples


Ignore:
Timestamp:
Nov 16, 2009 3:03:37 PM (15 years ago)
Author:
dkearney
Message:

clean up on example programs for new bindings

Location:
trunk/examples
Files:
3 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/examples/app-fermi/matlab/compiled/fermi_main.m

    r1222 r1615  
    1313    fclose(fid);
    1414    append = 1;
    15     rpLibPutString(lib,'output.log',lastmsg,append)
     15    rpLibPutString(lib,'output.log',lastmsg,append);
    1616    rpLibResult(lib,1);
    1717end
  • trunk/examples/objects/app-fermi/fermi4.c

    r1581 r1615  
    1 
    21// ----------------------------------------------------------------------
    3 //  EXAMPLE: Fermi-Dirac function in Python.
     2//  EXAMPLE: Fermi-Dirac function in C
    43//
    54//  This simple example shows how to use Rappture within a simulator
     
    2221int main(int argc, char * argv[]) {
    2322
    24     Rappture_Library *lib = NULL;
    25     Rappture_Number *T = NULL;
     23    Rp_Library *lib = NULL;
     24    Rp_Number *T = NULL;
    2625
    2726    double Ef         = 0.0;
     
    3635    double fArr[nPts];
    3736
    38     const char *curveLabel = "Fermi-Dirac Curve"
    39     const char *curveDesc = "Plot of Fermi-Dirac Calculation";
    40 
    41     Rappture::Plot *p1 = NULL;
     37    Rp_Plot *p1 = NULL;
    4238
    4339    // create a rappture library from the file filePath
    44     lib = Rappture_Library_init(argv[1]);
     40    lib = Rp_LibraryInit();
     41    Rp_LibraryLoadFile(lib,argv[1]);
    4542
    46     if (Rappture_Library_error(lib) != 0) {
     43    if (Rp_LibraryError(lib) != 0) {
    4744        // cannot open file or out of memory
    48         fprintf(stderr,Rappture_Library_traceback(lib));
    49         return(Rappture_Library_error(lib));
     45        Rp_Outcome *o = Rp_LibraryOutcome(lib);
     46        fprintf(stderr, "%s", Rp_OutcomeContext(o));
     47        fprintf(stderr, "%s", Rp_OutcomeRemark(o));
     48        return(Rp_LibraryError(lib));
    5049    }
    5150
    52     Rappture_connect(lib,"temperature",T);
    53     Rappture_Library_value(lib,"Ef",&Ef,"units=eV");
     51    Rp_Connect(lib,"temperature",T);
     52    Rp_LibraryValue(lib,"Ef",&Ef,1,"units=eV");
    5453
    55     if (Rappture_Library_error(lib) != 0) {
     54    if (Rp_LibraryError(lib) != 0) {
    5655        // there were errors while retrieving input data values
    5756        // dump the tracepack
    58         fprintf(stderr,Rappture_Library_traceback(lib));
    59         return(Rappture_Library_error(lib));
     57        Rp_Outcome *o = Rp_LibraryOutcome(lib);
     58        fprintf(stderr, "%s", Rp_OutcomeContext(o));
     59        fprintf(stderr, "%s", Rp_OutcomeRemark(o));
     60        return(Rp_LibraryError(lib));
    6061    }
    6162
    62     kT = 8.61734e-5 * Rappture_Number_value(T,"K");
     63    kT = 8.61734e-5 * Rp_NumberValue(T,"K");
    6364    Emin = Ef - 10*kT;
    6465    Emax = Ef + 10*kT;
    6566
    66     dE = 0.005*(Emax-Emin);
     67    dE = (1.0/nPts)*(Emax-Emin);
    6768
    6869    E = Emin;
     
    7273        fArr[idx] = f;
    7374        EArr[idx] = E;
    74         Rappture_Utils_Progress((int)((E-Emin)/(Emax-Emin)*100),"Iterating");
     75        Rp_UtilsProgress((int)((E-Emin)/(Emax-Emin)*100),"Iterating");
    7576    }
    7677
     
    7879    // create a plot to add to the library
    7980    // plot is registered with lib upon object creation
    80     // p1->add(nPts,xArr,yArr,format,curveLabel,curveDesc);
     81    // p1->add(nPts,xArr,yArr,format,name);
    8182
    82     p1 = Rappture_Plot_init(lib);
    83     Rappture_Plot_add(p1,nPts,fArr,EArr,"",curveLabel,curveDesc);
    84     Rappture_Plot_propstr(p1,"xlabel","Fermi-Dirac Factor");
    85     Rappture_Plot_propstr(p1,"ylabel","Energy");
    86     Rappture_Plot_propstr(p1,"yunits","eV");
     83    p1 = Rp_PlotInit(lib);
     84    Rp_PlotAdd(p1,nPts,fArr,EArr,"","fdfactor");
     85    Rp_PlotPropstr(p1,"label","Fermi-Dirac Curve");
     86    Rp_PlotPropstr(p1,"desc","Plot of Fermi-Dirac Calculation");
     87    Rp_PlotPropstr(p1,"xlabel","Fermi-Dirac Factor");
     88    Rp_PlotPropstr(p1,"ylabel","Energy");
     89    Rp_PlotPropstr(p1,"yunits","eV");
    8790
    88     Rappture_Library_result(lib);
     91    Rp_LibraryResult(lib);
     92
    8993    return 0;
    9094}
  • trunk/examples/objects/app-fermi/fermi4.cc

    r1581 r1615  
    1414#include "rappture.h"
    1515
    16 #include <stdlib.h>
    17 #include <stdio.h>
     16#include <cstdlib>
     17#include <cstdio>
    1818#include <math.h>
    1919#include <unistd.h>
     
    2222
    2323    // create a rappture library from the file filePath
    24     Rappture::Library lib(argv[1]);
     24    Rappture::Library lib;
    2525    Rappture::Number *T;
    2626
     
    3636    double fArr[nPts];
    3737
     38    lib.loadFile(argv[1]);
    3839    if (lib.error() != 0) {
    3940        // cannot open file or out of memory
     
    4142        fprintf(stderr, "%s",o.context());
    4243        fprintf(stderr, "%s",o.remark());
    43         exit(lib.error());
     44        return (lib.error());
    4445    }
    4546
    46     Rappture::connect(&lib,"temperature",T);
     47    Rappture::Connect(&lib,"temperature",T);
    4748    lib.value("Ef", &Ef, 1, "units=eV");
    4849
     
    5354        fprintf(stderr, "%s",o.context());
    5455        fprintf(stderr, "%s",o.remark());
    55         exit(lib.error());
     56        return(lib.error());
    5657    }
    5758
     
    6869        fArr[idx] = f;
    6970        EArr[idx] = E;
    70         rpUtilsProgress((int)((E-Emin)/(Emax-Emin)*100),"Iterating");
     71        Rappture::Utils::progress((int)((E-Emin)/(Emax-Emin)*100),"Iterating");
    7172    }
    72 
    73     const char *curveLabel = "Fermi-Dirac Curve"
    74     const char *curveDesc = "Plot of Fermi-Dirac Calculation";
    7573
    7674    // do it the easy way,
    7775    // create a plot to add to the library
    7876    // plot is registered with lib upon object creation
    79     // p1.add(nPts,xArr,yArr,format,curveLabel,curveDesc);
     77    // p1.add(nPts,xArr,yArr,format,name);
    8078
    8179    Rappture::Plot p1(lib);
    82     p1.add(nPts,fArr,EArr,"",curveLabel,curveDesc);
     80    p1.add(nPts,fArr,EArr,"","fdfactor");
     81    p1.propstr("label","Fermi-Dirac Curve");
     82    p1.propstr("desc","Plot of Fermi-Dirac Calculation");
    8383    p1.propstr("xlabel","Fermi-Dirac Factor");
    8484    p1.propstr("ylabel","Energy");
  • trunk/examples/objects/app-fermi/fermi4.m

    r1581 r1615  
    2121
    2222% open our xml input file.
    23 lib = Rappture_Library(infile);
     23lib = Rp_LibraryInit();
     24Rp_LibraryLoadFile(lib, infile);
    2425
    2526nPts = 200;
    2627
    27 if (Rappture_Library_error(lib) == 0)) {
     28if (Rp_LibraryError(lib) != 0)) {
    2829    % cannot open file or out of memory
    29     fprintf(stderr, Rappture_Library_traceback(lib));
    30     exit(Rappture_Library_error(lib));
     30    o = Rp_LibraryOutcome(lib);
     31    fprintf(stderr, '%s', Rp_LibraryContext(o));
     32    fprintf(stderr, '%s', Rp_LibraryRemark(o));
     33    return;
    3134}
    3235
    33 T = Rappture_connect(lib,'temperature');
    34 Ef = Rappture_Library_value(lib,'Ef','units=eV');
     36T = Rp_Connect(lib,'temperature');
     37Ef = Rp_LibraryValue(lib,'Ef','units=eV');
    3538
    36 if (Rappture_Library_error(lib) == 0) {
     39if (Rp_LibraryError(lib) != 0) {
    3740    % there were errors while retrieving input data values
    3841    % dump the tracepack
    39     fprintf(stderr,Rappture_Library_traceback(lib));
     42    o = Rp_LibraryOutcome(lib);
     43    fprintf(stderr, '%s', Rp_LibraryContext(o));
     44    fprintf(stderr, '%s', Rp_LibraryRemark(o));
     45    return;
    4046}
    4147
    4248% do fermi calculations (science)...
    43 kT = 8.61734e-5 * Rappture_Number_value(T,'K');
     49kT = 8.61734e-5 * Rp_NumberValue(T,'K');
    4450Emin = Ef - 10*kT;
    4551Emax = Ef + 10*kT;
    4652
    4753EArr = linspace(Emin,Emax,nPts);
    48 fArr = 1.0 ./ (1.0 + exp((E - Ef)/kT));
    49 
    50 
    51 curveLabel = 'Fermi-Dirac Curve';
    52 curveDesc = 'Plot of Fermi-Dirac Calculation';
     54fArr = 1.0 ./ (1.0 + exp((EArr - Ef)/kT));
    5355
    5456% do it the easy way,
    5557% create a plot to add to the library
    5658% plot is registered with lib upon object creation
    57 % p1->add(nPts,xArr,yArr,format,curveLabel,curveDesc);
     59% p1->add(nPts,xArr,yArr,format,name);
    5860
    59 p1 = Rappture_Plot(lib);
    60 Rappture_Plot_add(p1,nPts,fArr,EArr,"",curveLabel,curveDesc);
    61 Rappture_Plot_propstr(p1,"xlabel","Fermi-Dirac Factor");
    62 Rappture_Plot_propstr(p1,"ylabel","Energy");
    63 Rappture_Plot_propstr(p1,"yunits","eV");
     61p1 = Rp_PlotInit(lib);
     62Rp_PlotAdd(p1,nPts,fArr,EArr,'','fdfactor');
     63Rp_PlotPropstr(p1,'label','Fermi-Dirac Curve');
     64Rp_PlotPropstr(p1,'desc','Plot of Fermi-Dirac Calculation');
     65Rp_PlotPropstr(p1,'xlabel','Fermi-Dirac Factor');
     66Rp_PlotPropstr(p1,'ylabel','Energy');
     67Rp_PlotPropstr(p1,'yunits','eV');
    6468
    65 Rappture_Library_result(lib);
     69Rp_LibraryResult(lib);
    6670
    67 quit;
     71return;
  • trunk/examples/objects/app-fermi/fermi4.py

    r1586 r1615  
    5555
    5656    # create a rappture library from the file filePath
    57     lib = Rappture.Library(argv[1])
     57    lib = Rappture.Library()
    5858
    5959    nPts = 200;
    60     EArr = list() # [nPts];
    61     fArr = list() # [nPts];
     60    EArr = list() # [nPts]
     61    fArr = list() # [nPts]
    6262
     63    lib.loadFile(sys.argv[1])
    6364    if (lib.error() != 0) {
    6465        # cannot open file or out of memory
    65         print >>sys.stderr, lib.traceback()
    66         exit(lib.error());
     66        o = lib.outcome()
     67        print >>sys.stderr, "%s", o.context()
     68        print >>sys.stderr, "%s", o.remark()
     69        return (lib.error());
    6770    }
    6871
    69     T = Rappture.connect(lib,"temperature");
    70     Ef = lib.value("Ef","units=eV");
     72    T = Rappture.Connect(lib,"temperature")
     73    Ef = lib.value("Ef","units=eV")
    7174
    7275    if (lib.error() != 0) {
    7376        # there were errors while retrieving input data values
    7477        # dump the tracepack
    75         print >>sys.stderr, lib.traceback()
    76         exit(lib.error());
     78        o = lib.outcome()
     79        print >>sys.stderr, "%s", o.context()
     80        print >>sys.stderr, "%s", o.remark()
     81        return (lib.error())
    7782    }
    7883
    79     kT = 8.61734e-5 * T.value("K");
    80     Emin = Ef - 10*kT;
    81     Emax = Ef + 10*kT;
     84    kT = 8.61734e-5 * T.value("K")
     85    Emin = Ef - 10*kT
     86    Emax = Ef + 10*kT
    8287
    83     dE = (1.0/nPts)*(Emax-Emin);
     88    dE = (1.0/nPts)*(Emax-Emin)
    8489
    8590    E = Emin;
    8691    for (size_t idx = 0; idx < nPts; idx++) {
    87         E = E + dE;
    88         f = 1.0/(1.0 + exp((E - Ef)/kT));
    89         fArr.append(f);
    90         EArr.append(E);
    91         Rappture.Utils.progress((int)((E-Emin)/(Emax-Emin)*100),"Iterating");
     92        E = E + dE
     93        f = 1.0/(1.0 + exp((E - Ef)/kT))
     94        fArr.append(f)
     95        EArr.append(E)
     96        Rappture.Utils.progress((int)((E-Emin)/(Emax-Emin)*100),"Iterating")
    9297    }
    93 
    94     curveLabel = "Fermi-Dirac Curve"
    95     curveDesc = "Plot of Fermi-Dirac Calculation";
    9698
    9799    # do it the easy way,
    98100    # create a plot to add to the library
    99101    # plot is registered with lib upon object creation
    100     # p1->add(nPts,xArr,yArr,format,curveLabel,curveDesc);
     102    # p1->add(nPts,xArr,yArr,format,name);
    101103
    102     p1 = Rappture.Plot(lib);
    103     p1.add(nPts,fArr,EArr,"",curveLabel,curveDesc);
    104     p1.propstr("xlabel","Fermi-Dirac Factor");
    105     p1.propstr("ylabel","Energy");
    106     p1.propstr("yunits","eV");
     104    p1 = Rappture.Plot(lib)
     105    p1.add(nPts,fArr,EArr,"","fdfactor")
     106    p1.propstr("label","Fermi-Dirac Curve")
     107    p1.propstr("desc","Plot of Fermi-Dirac Calculation")
     108    p1.propstr("xlabel","Fermi-Dirac Factor")
     109    p1.propstr("ylabel","Energy")
     110    p1.propstr("yunits","eV")
    107111
    108     lib.result();
     112    lib.result()
    109113
    110     return 0;
     114    return 0
    111115}
    112116
  • trunk/examples/objects/app-fermi/fermi4.tcl

    r1581 r1615  
    1414
    1515# open the XML file containing the run parameters
    16 set lib [Rappture::Library [lindex $argv 0]]
     16set lib [Rappture::Library]
     17
     18$lib loadFile [lindex $argv 0]
    1719
    1820if {[$lib error] != 0} {
    1921    # cannot open file or out of memory
    20     puts stderr [$lib traceback]
     22    set o [$lib outcome]
     23    puts stderr [$o context]
     24    puts stderr [$o remark]
    2125    exit [$lib error]
    2226}
    2327
    24 set T [Rappture::connect $lib "temperature"]
    25 set Ef [$lib value "Ef" "units=eV"]
     28set T [Rappture::Connect $lib "temperature"]
     29set Ef [$lib value "Ef" "units eV"]
    2630
    2731if {[$lib error != 0]} {
    2832    # there were errors while retrieving input data values
    2933    # dump the tracepack
    30     puts stderr [$lib traceback]
     34    set o [$lib outcome]
     35    puts stderr [$o context]
     36    puts stderr [$o remark]
    3137    exit [$lib error]
    3238}
     
    3844set Emax [expr {$Ef + 10*$kT}]
    3945
    40 set dE [expr {0.005*($Emax-$Emin)}]
     46set dE [expr {(1.0/$nPts)*($Emax-$Emin)}]
    4147
    4248set E $Emin
     
    5056}
    5157
    52 set curveLabel "Fermi-Dirac Curve"
    53 set curveDesc "Plot of Fermi-Dirac Calculation"
    54 
    5558# do it the easy way,
    5659# create a plot to add to the library
     
    5962
    6063set p1 [Rappture::Plot $lib]
    61 $p1 add $nPts $fArr $EArr "" $curveLabel $curveDesc
     64$p1 add $fArr $EArr -name "fdfactor"
     65$p1 propstr "label" "Fermi-Dirac Curve"
     66$p1 propstr "desc" "Plot of Fermi-Dirac Calculation"
    6267$p1 propstr "xlabel" "Fermi-Dirac Factor"
    6368$p1 propstr "ylabel" "Energy"
Note: See TracChangeset for help on using the changeset viewer.