Changeset 1623


Ignore:
Timestamp:
Dec 7, 2009 9:17:35 AM (14 years ago)
Author:
dkearney
Message:

updating objects tcl bindings example

Location:
trunk/examples/objects/app-fermi/tcl
Files:
1 added
1 edited

Legend:

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

    r1620 r1623  
    1313package require Rappture
    1414
    15 # open the XML file containing the run parameters
    16 set lib [Rappture::Library]
     15# initialize the global interface
     16Rappture::Interface $argv fermi_io
    1717
    18 $lib loadFile [lindex $argv 0]
    19 
    20 if {[$lib error] != 0} {
    21     # cannot open file or out of memory
    22     set o [$lib outcome]
     18# check the global interface for errors
     19if {[Rappture::Interface::error] != 0} {
     20    # there were errors while setting up the inteface
     21    # dump the traceback
     22    set o [Rappture::Interface::outcome]
    2323    puts stderr [$o context]
    2424    puts stderr [$o remark]
    25     exit [$lib error]
     25    exit [Rappture::Interface::error]
    2626}
    2727
    28 set T [Rappture::Connect $lib "temperature"]
    29 set Ef [$lib value "Ef" "units eV"]
     28# connect variables to the interface
     29# look in the global interface for an object named
     30# "temperature, convert its value to Kelvin, and
     31# store the value into the address of T.
     32# look in the global interface for an object named
     33# "Ef", convert its value to electron Volts and store
     34# the value into the address of Ef
     35# look in the global interface for an object named
     36# factorsTable and set the variable result to
     37# point to it.
     38set T [Rappture::Interface::connect "temperature" -hints {"units=K"}]
     39set Ef [Rappture::Interface::connect "Ef" -hints {"units=eV"}]
     40set result [Rappture::Interface::connect "factorsTable"]
    3041
    31 if {[$lib error != 0]} {
     42if {[Rappture::Interface::error] != 0]} {
    3243    # there were errors while retrieving input data values
    3344    # dump the tracepack
    34     set o [$lib outcome]
     45    set o [Rappture::Interface::outcome]
    3546    puts stderr [$o context]
    3647    puts stderr [$o remark]
    37     exit [$lib error]
     48    exit [Rappture::Interface::error]
    3849}
    3950
     51# do science calculations
    4052set nPts 200
    4153
    42 set kT [expr {8.61734e-5 * [$T value "K"]}]
     54set kT [expr {8.61734e-5 * $T}]
    4355set Emin [expr {$Ef - 10*$kT}]
    4456set Emax [expr {$Ef + 10*$kT}]
     
    5668}
    5769
    58 # do it the easy way,
    59 # create a plot to add to the library
    60 # plot is registered with lib upon object creation
    61 # p1->add(nPts,xArr,yArr,format,curveLabel,curveDesc);
     70# store results in the results table
     71# add data to the table pointed to by the variable result.
     72# put the fArr data in the column named "Fermi-Dirac Factor"
     73# put the EArr data in the column named "Energy"
    6274
    63 set p1 [Rappture::Plot $lib]
    64 $p1 add $fArr $EArr -name "fdfactor"
    65 $p1 propstr "label" "Fermi-Dirac Curve"
    66 $p1 propstr "desc" "Plot of Fermi-Dirac Calculation"
    67 $p1 propstr "xlabel" "Fermi-Dirac Factor"
    68 $p1 propstr "ylabel" "Energy"
    69 $p1 propstr "yunits" "eV"
     75$result add data "Fermi-Dirac Factor" $fArr
     76$result add data "Energy" $EArr
    7077
    71 $lib result
     78Rappture::Interface::close
    7279
    7380exit 0
Note: See TracChangeset for help on using the changeset viewer.