Ignore:
Timestamp:
Dec 3, 2009 10:01:34 AM (11 years ago)
Author:
dkearney
Message:

rewriting some language bindings examples to incorporate feedback from meetings

Location:
trunk/examples/objects/app-fermi
Files:
15 added
5 moved

Legend:

Unmodified
Added
Removed
  • trunk/examples/objects/app-fermi/c/fermi4.c

    r1615 r1620  
    1919#include <unistd.h>
    2020
     21#include "fermi_io.c"
     22
    2123int main(int argc, char * argv[]) {
    2224
    23     Rp_Library *lib = NULL;
    24     Rp_Number *T = NULL;
     25    // declare variables to interact with Rappture
     26    double T          = 0.0;
     27    double Ef         = 0.0;
     28    Rp_Table *result = NULL;
    2529
    26     double Ef         = 0.0;
     30
     31    // declare program variables
    2732    double E          = 0.0;
    2833    double dE         = 0.0;
     
    3540    double fArr[nPts];
    3641
    37     Rp_Plot *p1 = NULL;
     42    // initialize the global interface
     43    Rp_InterfaceInit(argc,argv,&fermi_io);
    3844
    39     // create a rappture library from the file filePath
    40     lib = Rp_LibraryInit();
    41     Rp_LibraryLoadFile(lib,argv[1]);
    42 
    43     if (Rp_LibraryError(lib) != 0) {
    44         // cannot open file or out of memory
    45         Rp_Outcome *o = Rp_LibraryOutcome(lib);
     45    // check the global interface for errors
     46    if (Rp_InterfaceError() != 0) {
     47        // there were errors while setting up the interface
     48        // dump the traceback
     49        Rp_Outcome *o = Rp_InterfaceOutcome();
    4650        fprintf(stderr, "%s", Rp_OutcomeContext(o));
    4751        fprintf(stderr, "%s", Rp_OutcomeRemark(o));
    48         return(Rp_LibraryError(lib));
     52        return(Rp_InterfaceError());
    4953    }
    5054
    51     Rp_Connect(lib,"temperature",T);
    52     Rp_LibraryValue(lib,"Ef",&Ef,1,"units=eV");
     55    // connect variables to the interface
     56    // look in the global interface for an object named
     57    // "temperature", convert its value to Kelvin, and
     58    // store the value into the address of T.
     59    // look in the global interface for an object named
     60    // "Ef", convert its value to electron Volts and store
     61    // the value into the address of Ef.
     62    // look in the global interface for an object named
     63    // factorsTable and set the variable result to
     64    // point to it.
     65    Rp_InterfaceConnect("temperature",&T,"units=K",NULL);
     66    Rp_InterfaceConnect("Ef",&Ef,"units=eV",NULL);
     67    Rp_InterfaceConnect("factorsTable",result,NULL);
    5368
    54     if (Rp_LibraryError(lib) != 0) {
     69    // check the global interface for errors
     70    if (Rp_InterfaceError() != 0) {
    5571        // there were errors while retrieving input data values
    56         // dump the tracepack
    57         Rp_Outcome *o = Rp_LibraryOutcome(lib);
     72        // dump the traceback
     73        Rp_Outcome *o = Rp_InterfaceOutcome();
    5874        fprintf(stderr, "%s", Rp_OutcomeContext(o));
    5975        fprintf(stderr, "%s", Rp_OutcomeRemark(o));
    60         return(Rp_LibraryError(lib));
     76        return(Rp_InterfaceError());
    6177    }
    6278
    63     kT = 8.61734e-5 * Rp_NumberValue(T,"K");
    64     Emin = Ef - 10*kT;
    65     Emax = Ef + 10*kT;
     79    // do science calculations
     80    kT = 8.61734e-5 * T;
     81    Emin = Ef - (10*kT);
     82    Emax = Ef + (10*kT);
    6683
    6784    dE = (1.0/nPts)*(Emax-Emin);
     
    7693    }
    7794
    78     // do it the easy way,
    79     // create a plot to add to the library
    80     // plot is registered with lib upon object creation
    81     // p1->add(nPts,xArr,yArr,format,name);
     95    // store results in the results table
     96    // add data to the table pointed to by the variable result.
     97    // put the fArr data in the column named "Fermi-Dirac Factor"
     98    // put the EArr data in the column named "Energy"
     99    //
     100    Rp_TableAddData(result,"Fermi-Dirac Factor",nPts,fArr);
     101    Rp_TableAddData(result,"Energy",nPts,EArr);
    82102
    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");
    90 
    91     Rp_LibraryResult(lib);
     103    // close the global interface
     104    // signal to the graphical user interface that science
     105    // calculations are complete and to display the data
     106    // as described in the views
     107    Rp_InterfaceClose();
    92108
    93109    return 0;
  • trunk/examples/objects/app-fermi/cpp/fermi4.cc

    r1615 r1620  
    1919#include <unistd.h>
    2020
     21#include "fermi_io.c"
     22
    2123int main(int argc, char * argv[]) {
    2224
    23     // create a rappture library from the file filePath
    24     Rappture::Library lib;
    25     Rappture::Number *T;
     25    // declare variables to interact with Rappture
     26    double T            = 0.0;
     27    double Ef           = 0.0;
     28    Rappture::Table *result = NULL;
    2629
    27     double Ef           = 0.0;
     30    // declare program variables
    2831    double E            = 0.0;
    2932    double dE           = 0.0;
     
    3639    double fArr[nPts];
    3740
    38     lib.loadFile(argv[1]);
    39     if (lib.error() != 0) {
    40         // cannot open file or out of memory
    41         Rappture::Outcome o = lib.outcome();
     41    // initialize the global interface
     42    Rappture::Interface(argc,argv,&fermi_io);
     43
     44    //check the global interface for errors
     45    if (Rappture::Interface::error() != 0) {
     46        // there were errors while setting up the interface
     47        // dump the traceback
     48        Rappture::Outcome o = Rappture::Interface::outcome();
    4249        fprintf(stderr, "%s",o.context());
    4350        fprintf(stderr, "%s",o.remark());
    44         return (lib.error());
     51        return (Rappture::Interface::error());
    4552    }
    4653
    47     Rappture::Connect(&lib,"temperature",T);
    48     lib.value("Ef", &Ef, 1, "units=eV");
     54    // connect variables to the interface
     55    // look in the global interface for an object named
     56    // "temperature", convert its value to Kelvin, and
     57    // store the value into the address of T.
     58    // look in the global interface for an object named
     59    // "Ef", convert its value to electron Volts and store
     60    // the value into the address of Ef
     61    // look in the global interface for an object named
     62    // factorsTable and set the variable result to
     63    // point to it.
     64    Rappture::Interface::connect("temperature",&T,"units=K",NULL);
     65    Rappture::Interface::connect("Ef",&Ef,"units=eV",NULL);
     66    Rappture::Interface::connect("factorsTable",result,NULL);
    4967
    50     if (lib.error() != 0) {
     68    // check the global interface for errors
     69    if (Rappture::Interface::error() != 0) {
    5170        // there were errors while retrieving input data values
    5271        // dump the tracepack
    53         Rappture::Outcome o = lib.outcome();
     72        Rappture::Outcome o = Rappture::Interface::outcome();
    5473        fprintf(stderr, "%s",o.context());
    5574        fprintf(stderr, "%s",o.remark());
    56         return(lib.error());
     75        return(Rappture::Interface::error());
    5776    }
    5877
    59     kT = 8.61734e-5 * T->value("K");
     78    // do science calculations
     79    kT = 8.61734e-5 * T;
    6080    Emin = Ef - 10*kT;
    6181    Emax = Ef + 10*kT;
     
    7292    }
    7393
    74     // do it the easy way,
    75     // create a plot to add to the library
    76     // plot is registered with lib upon object creation
    77     // p1.add(nPts,xArr,yArr,format,name);
     94    // store results in the results table
     95    // add data to the table pointed to by the variable result.
     96    // put the fArr data in the column named "Fermi-Dirac Factor"
     97    // put the EArr data in the column named "Energy"
    7898
    79     Rappture::Plot p1(lib);
    80     p1.add(nPts,fArr,EArr,"","fdfactor");
    81     p1.propstr("label","Fermi-Dirac Curve");
    82     p1.propstr("desc","Plot of Fermi-Dirac Calculation");
    83     p1.propstr("xlabel","Fermi-Dirac Factor");
    84     p1.propstr("ylabel","Energy");
    85     p1.propstr("yunits","eV");
     99    result->addData("Fermi-Dirac Factor",nPts,fArr);
     100    result->addData("Energy",nPts,EArr);
    86101
    87     lib.result();
     102    // close the global interface
     103    // signal to the graphical user interface that science
     104    // calculations are complete and to display the data
     105    // as described in the views
     106    Rappture::Interface::close();
    88107
    89108    return 0;
  • trunk/examples/objects/app-fermi/matlab/fermi4.m

    r1615 r1620  
    1313% ======================================================================
    1414
    15 % get out input file from the command line
    16 % invoke this script with the following command:
    17 % matlab -nodisplay -r infile=\'driver1234.xml\',fermi
    18 % the above command sets variable infile to the name 'driver1234.xml'
     15function fermi4(argv)
    1916
    20 % infile = 'driver31619.xml'
     17% declare variables to interact with Rappture
     18T       = 0.0;
     19Ef      = 0.0;
     20result  = 0;
    2121
    22 % open our xml input file.
    23 lib = Rp_LibraryInit();
    24 Rp_LibraryLoadFile(lib, infile);
     22% declare program variables
     23E       = 0.0;
     24dE      = 0.0;
     25kT      = 0.0;
     26Emin    = 0.0;
     27Emax    = 0.0;
     28f       = 0.0;
     29nPts    = 200;
    2530
    26 nPts = 200;
     31% initialize the global interface
     32Rp_InterfaceInit(argv,@fermi_io);
    2733
    28 if (Rp_LibraryError(lib) != 0)) {
    29     % cannot open file or out of memory
    30     o = Rp_LibraryOutcome(lib);
    31     fprintf(stderr, '%s', Rp_LibraryContext(o));
    32     fprintf(stderr, '%s', Rp_LibraryRemark(o));
    33     return;
     34% check that global interface for errors
     35if (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());
    3442}
    3543
    36 T = Rp_Connect(lib,'temperature');
    37 Ef = Rp_LibraryValue(lib,'Ef','units=eV');
     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 an object named
     52% factorsTable and store a handle to it in the
     53% variable result.
    3854
    39 if (Rp_LibraryError(lib) != 0) {
     55T = Rp_InterfaceConnect('temperature','units=K')
     56Ef = Rp_InterfaceConnect('Ef','units=eV')
     57result = Rp_InterfaceConnect('factorsTable')
     58
     59% check the global interface for errors
     60if (Rp_InterfaceError() != 0) {
    4061    % there were errors while retrieving input data values
    4162    % dump the tracepack
    42     o = Rp_LibraryOutcome(lib);
    43     fprintf(stderr, '%s', Rp_LibraryContext(o));
    44     fprintf(stderr, '%s', Rp_LibraryRemark(o));
    45     return;
     63    o = Rp_InterfaceOutcome();
     64    fprintf(stderr, '%s', Rp_OutcomeContext(o));
     65    fprintf(stderr, '%s', Rp_OutcomeRemark(o));
     66    return(Rp_InterfaceError());
    4667}
    4768
    4869% do fermi calculations (science)...
    49 kT = 8.61734e-5 * Rp_NumberValue(T,'K');
    50 Emin = Ef - 10*kT;
    51 Emax = Ef + 10*kT;
     70kT = 8.61734e-5 * T;
     71Emin = Ef - (10*kT);
     72Emax = Ef + (10*kT);
    5273
    5374EArr = linspace(Emin,Emax,nPts);
    5475fArr = 1.0 ./ (1.0 + exp((EArr - Ef)/kT));
    5576
    56 % do it the easy way,
    57 % create a plot to add to the library
    58 % plot is registered with lib upon object creation
    59 % p1->add(nPts,xArr,yArr,format,name);
     77% store results in the results table
     78% add data to the table pointed to by the variable result
     79% put the fArr data in the column named 'Fermi-Dirac Factor'
     80% put the EArr data in the column named 'Energy'
    6081
    61 p1 = Rp_PlotInit(lib);
    62 Rp_PlotAdd(p1,nPts,fArr,EArr,'','fdfactor');
    63 Rp_PlotPropstr(p1,'label','Fermi-Dirac Curve');
    64 Rp_PlotPropstr(p1,'desc','Plot of Fermi-Dirac Calculation');
    65 Rp_PlotPropstr(p1,'xlabel','Fermi-Dirac Factor');
    66 Rp_PlotPropstr(p1,'ylabel','Energy');
    67 Rp_PlotPropstr(p1,'yunits','eV');
     82Rp_TableAddData(result,'Fermi-Dirac Factor',fArr);
     83Rp_TableAddData(result,'Energy',EArr);
    6884
    69 Rp_LibraryResult(lib);
     85% close the global interface
     86% signal to the graphical user interface that science
     87% calculations are complete and to display the data
     88% as described in the views
    7089
    71 return;
     90Rp_InterfaceClose();
     91
     92return 0;
  • trunk/examples/objects/app-fermi/python/fermi4.py

    r1615 r1620  
    2121from math import *
    2222
     23from fermi_io import fermi_io
    2324
    2425def help(argv=sys.argv):
     
    3435def main(argv=None):
    3536
    36     if argv is None:
    37         argv = sys.argv
     37    # declare variables to interact with Rappture
     38    T = 0.0
     39    Ef = 0.0
    3840
    39     if len(argv) < 1:
    40         msg = "%(prog)s requires at least 0 argument" % {'prog':argv[0]}
    41         print >>sys.stderr, msg
    42         print >>sys.stderr, help()
    43         return 2
    44 
    45     longOpts = ["help"]
    46     shortOpts = "h"
    47     try:
    48         opts,args = getopt.getopt(argv[1:],shortOpts,longOpts)
    49     except getopt.GetOptError, msg:
    50         print >>sys.stderr, msg
    51         print >>sys.stderr, help()
    52         return 2
    53 
    54 
    55 
    56     # create a rappture library from the file filePath
    57     lib = Rappture.Library()
    58 
     41    # declare program variables
    5942    nPts = 200;
    6043    EArr = list() # [nPts]
    6144    fArr = list() # [nPts]
    6245
    63     lib.loadFile(sys.argv[1])
    64     if (lib.error() != 0) {
    65         # cannot open file or out of memory
    66         o = lib.outcome()
     46    # initialize the global interface
     47    Rappture.Interface(sys.argv,fermi_io)
     48
     49    # check the global interface for errors
     50    if (Rappture.Interface.error() != 0) {
     51        # there were errors while setting up the interface
     52        # dump the traceback
     53        o = Rappture.Interface.outcome()
    6754        print >>sys.stderr, "%s", o.context()
    6855        print >>sys.stderr, "%s", o.remark()
    69         return (lib.error());
     56        return (Rappture.Interface.error())
    7057    }
    7158
    72     T = Rappture.Connect(lib,"temperature")
    73     Ef = lib.value("Ef","units=eV")
     59    # connect variables to the interface
     60    # look in the global interface for an object named
     61    # "temperature", convert its value to Kelvin, and
     62    # store the value into the address of T.
     63    # look in the global interface for an object named
     64    # "Ef", convert its value to electron Volts and store
     65    # the value into the address of Ef
     66    # look in the global interface for an object named
     67    # factorsTable and set the variable result to
     68    # point to it.
    7469
    75     if (lib.error() != 0) {
     70    T = Rappture.Interface.connect(name="temperature",
     71                                   hints=["units=K"])
     72    Ef = Rappture.Interface.connect(name="Ef",
     73                                    hints=["units=eV"]);
     74    result = Rappture.Interface.connect(name="factorsTable");
     75
     76    # check the global interface for errors
     77    if (Rappture.Interface.error() != 0) {
    7678        # there were errors while retrieving input data values
    7779        # dump the tracepack
    78         o = lib.outcome()
     80        o = Rappture.Interface.outcome()
    7981        print >>sys.stderr, "%s", o.context()
    8082        print >>sys.stderr, "%s", o.remark()
    81         return (lib.error())
     83        return (Rappture.Interface.error())
    8284    }
    8385
    84     kT = 8.61734e-5 * T.value("K")
    85     Emin = Ef - 10*kT
    86     Emax = Ef + 10*kT
     86    # do science calculations
     87    kT = 8.61734e-5 * T
     88    Emin = Ef - (10*kT)
     89    Emax = Ef + (10*kT)
    8790
    8891    dE = (1.0/nPts)*(Emax-Emin)
     
    97100    }
    98101
    99     # do it the easy way,
    100     # create a plot to add to the library
    101     # plot is registered with lib upon object creation
    102     # p1->add(nPts,xArr,yArr,format,name);
     102    # store results in the results table
     103    # add data to the table pointed to by the variable result.
     104    # put the fArr data in the column named "Fermi-Dirac Factor"
     105    # put the EArr data in the column named "Energy"
    103106
    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")
     107    result.addData(name="Fermi-Dirac Factor",data=fArr)
     108    result.addData(name="Energy",data=EArr)
    111109
    112     lib.result()
     110    # close the global interface
     111    # signal to the graphical user interface that science
     112    # calculations are complete and to display the data
     113    # as described in the views
     114    Rappture.Interface.close()
    113115
    114116    return 0
    115 }
    116 
    117117
    118118if __name__ == '__main__':
Note: See TracChangeset for help on using the changeset viewer.