Changeset 435 for trunk/examples


Ignore:
Timestamp:
May 9, 2006, 5:56:32 PM (19 years ago)
Author:
mmc
Message:

Fixed the <sequence> object so that it can support multiple objects
within each <element>. For example, the zoo/sequence demo now includes
two parameters A and B, and the B parameters are used to generate a
series of <curve> objects within each <element>.

Fixed the <sequence> so it works correctly when an index has units.

Location:
trunk/examples/zoo/sequence
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/examples/zoo/sequence/sequence2.tcl

    r433 r435  
    1616
    1717set func [$driver get input.string(func).current]
    18 set pvals [$driver get input.string(pvals).current]
     18set avals [$driver get input.string(avals).current]
     19set bvals [$driver get input.string(bvals).current]
    1920
    20 # remove any commas in the pvals list
    21 regsub -all {,} $pvals {} pvals
     21# remove any commas in the avals/bvals lists
     22regsub -all {,} $avals {} avals
     23regsub -all {,} $bvals {} bvals
    2224
    2325# change "x" to $x in expression
    2426regsub -all {x} $func {$x} func
    25 regsub -all {P} $func {$P} func
     27regsub -all {A} $func {$A} func
     28regsub -all {B} $func {$B} func
    2629
    2730set xmin -1
    2831set xmax 1
    2932set npts 30
    30 foreach P $pvals {
    31     $driver put output.sequence(outs).element($P).index $P
    32     $driver put output.sequence(outs).element($P).curve.xaxis.label "x"
    33     $driver put output.sequence(outs).element($P).curve.yaxis.label \
    34         "Function y(x)"
     33foreach A $avals {
     34    set elem output.sequence(outs).element($A)
     35    $driver put $elem.index $A
    3536
    36     for {set i 0} {$i < $npts} {incr i} {
    37         set x [expr {$i*($xmax-$xmin)/double($npts) + $xmin}]
    38         set y [expr $func]
    39         $driver put -append yes \
    40           output.sequence(outs).element($P).curve.component.xy "$x $y\n"
     37    if {[llength $bvals] > 0} {
     38        # one or more B values -- put out a separate curve for each B value
     39        foreach B $bvals {
     40            $driver put $elem.curve($B).about.label "B = $B"
     41            $driver put $elem.curve($B).about.group "A = $A"
     42            $driver put $elem.curve($B).xaxis.label "x"
     43            $driver put $elem.curve($B).yaxis.label "Function y(x)"
     44
     45            for {set i 0} {$i < $npts} {incr i} {
     46                set x [expr {$i*($xmax-$xmin)/double($npts) + $xmin}]
     47                set y [expr $func]
     48                $driver put -append yes \
     49                  $elem.curve($B).component.xy "$x $y\n"
     50            }
     51        }
     52    } else {
     53        # no B values -- put out a single curve for each element
     54        $driver put $elem.curve.xaxis.label "x"
     55        $driver put $elem.curve.yaxis.label "Function y(x)"
     56
     57        for {set i 0} {$i < $npts} {incr i} {
     58            set x [expr {$i*($xmax-$xmin)/double($npts) + $xmin}]
     59            set y [expr $func]
     60            $driver put -append yes \
     61              output.sequence(outs).element($A).curve.component.xy "$x $y\n"
     62        }
    4163    }
    4264}
  • trunk/examples/zoo/sequence/tool2.xml

    r433 r435  
    1717    <about>
    1818      <label>Function</label>
    19       <description>Function to plot y=f(x), where x is the range, and P is some other parameter, set below.</description>
     19      <description>Function to plot y=f(x), where x is the range, and A and B are some other parameters, set below.</description>
    2020    </about>
    21     <default>P*x + 2</default>
     21    <default>A*x + 2</default>
    2222  </string>
    23   <string id="pvals">
     23  <string id="avals">
    2424    <about>
    25       <label>P values</label>
    26       <description>List of values for parameter P in the function above.</description>
     25      <label>A values</label>
     26      <description>List of values for parameter A in the function above.</description>
     27      <diffs>ignore</diffs>
    2728    </about>
    2829    <default>0, 1, 2</default>
     30  </string>
     31  <string id="bvals">
     32    <about>
     33      <label>B values</label>
     34      <description>List of values for parameter B in the function above.</description>
     35      <diffs>ignore</diffs>
     36    </about>
     37    <default></default>
    2938  </string>
    3039</input>
     
    3241  <sequence id="outs">
    3342    <about><label>Sequence of Plots</label></about>
    34     <index><label>Parameter P</label></index>
     43    <index><label>Parameter A</label></index>
    3544  </sequence>
    3645</output>
Note: See TracChangeset for help on using the changeset viewer.