Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using bash and TCL

Status
Not open for further replies.

BabyPinky8888

Programmer
Feb 24, 2009
10
0
0
US
Hi:

I have to generate graphs for a project using a few values. I would like to use bash script in TCL. I have a C++ source code which has the parameters called argc and argv. I have pass those parameters to the TCL and enter my values in command line.. how can i do it without the bash and with the bash ?
 
I'm guessing you're on some kind of Linux platform. If so the answer is two-fold.

1. If your Bash script is executable (and by that I mean both that it has ..x..x..x permissions and that it starts with #! /usr/bin bash or whatever) you should be able to use the Tcl exec statement with just the path to the Bash script as an argument.

2. Alternatively, you can always use the exec statement with the Bash shell and the script name as the argument, as in exec "/usr/bin/bash /yourpath/script.bsh"

That said, if you're already in Tcl, you can do anything you want with Tcl scripting and not use Bash at all.

_________________
Bob Rashkin
 
Hi Bong! Thanks for your reply. Yes I am on linux and I am using TCL already.. but i understand that I need to generate about 9 graphs with X and Y as axes parameters and then w.r.t Z i have to plot a line graph in the same for each corresponding values of X.

i am trying to use the argv and argc but i am not able to figure out how..!
 
Maybe if you posted some of your code I could better understand what you're trying to do. Is it an XY plot? A 3D plot?
Here, for instance, is a proc that graphs a function as y=f(x). I make no claims about whether it's well-written or efficient; it works well enough for me. The arguments, "funcstr" and "w3" are a Tcl-formed mathematical expression and the canvas widget, respectively:
Code:
proc buildG {funcstr w3} {
    global gwth ghght minx maxx numtc gres
    destroy $w3.gcvs1
    canvas $w3.gcvs1 -width $gwth -height $ghght \
            -borderwidth 2 -relief sunken
    pack $w3.gcvs1
    set c0y $ghght
    set c0x 0
    set gres [expr {1.000*$gres}]
    # Assume that input function uses "x" as independant variable
    set funcstr [string map {x \$xi} $funcstr]
    # make sure "exp" function not clobberd
    set funcstr [string map {e\$xip exp} $funcstr]
    #  get all cartesian pairs to plot
    #  break domain into "$resolution" points
    set xinc [expr {($maxx-$minx)/$gres}]
    set xi $minx
    set i 0
    while {$xi <= $maxx} {
        set garr($i,x) $xi
        set garr($i,y) [expr $funcstr]
        set xi [expr {$xi+$xinc}]
        incr i
    }
    #now "i" is the number of array elements since it starts w/ 0 and goes to i-1
    # turn cartesian pairs into canvas coordinates
    # first find ymax and ymin
    set maxy $garr(0,y)
    set miny $garr(0,y)
    for {set p 1} {$p<$i} {incr p} {
        if {$garr($p,y)<$miny} then {set miny $garr($p,y)}
        if {$garr($p,y)>$maxy} then {set maxy $garr($p,y)}
    }
    set deltay [expr {$maxy - $miny}]
    set yscale 20
    if {$deltay!=0} {set yscale [expr {1.00*$ghght/$deltay}]}
    set xscale [expr {1.00*$gwth/($maxx-$minx)}]
    for {set p 0} {$p < $i} {incr p} {
        set cgarr($p,x) [expr {$c0x +($garr($p,x)-$minx)*$xscale}]
        set cgarr($p,y) [expr {$c0y -($garr($p,y)-$miny)*$yscale}]
    }
    
    # create lines in canvas
    set c $w3.gcvs1
    # draw Yaxis
    set xmd [expr {$gwth/2}]
    set tcinc [expr {$ghght/$numtc}]
    $c create line $xmd $c0y $xmd 0 -width 1 -fill white
    for {set p 0} {$p<$numtc} {incr p} {
        set tcy [expr {$ghght - $tcinc*$p}]
        $c create line 0 $tcy $gwth $tcy -width 1 -fill white
        set yval [format "%6.4g" [expr {$miny+$p*$tcinc/$yscale}]]
        $c create text $xmd $tcy -text $yval -fill red -font {courier 8} -anchor w
    }
    for {set p 1} {$p < $i} {incr p} {
        set q [expr {$p -1}]
        $c create line $cgarr($q,x) $cgarr($q,y) $cgarr($p,x) $cgarr($p,y) -width 1
    }
}
where some global variables were set from a configuration file:
Code:
set cmd {source gcfg.txt}
if [catch $cmd] {
    set gwth 420
    set ghght 420
    set minx 0
    set maxx 100
    set numtc 12
    set gres 100.00
}

_________________
Bob Rashkin
 
HI Bong:

I am pretty new to TCL. I am trying to understand the script you sent. I need to compute throughput. I have a hard time understanding from the C++ code as to which variable computes the TCL because I have to associate it with the TCL script that I would write.. i see a variable called maxburst .. any suggestions on how i could find it which variable it is ?

Thanks!
 
oops.. forgot to answer ur qn.. its an XY plot and I have X axis as my max burst size and my Y axis as average throughput.. but I have to have to have a separate line on the graph for each value of BAT (burst assembling time).. but i have to record the average throughput! finally.. which is what is required!
 
There are two processes here:
1. computing the numbers to be plotted
2. plotting.

Being new to Tcl, I suggest you tackle them separately. So for each BAT, compute the numbers (y=f(x)) to be plotted. I would use Tcl's list structure for this. Then make sure you have the numbers correctly computed. As for the average, is that a linear least squares fit or a simple arithmetic average?

Anyway, as far as plotting a sequence of x-y pairs, you need to:
1. instantiate a cavas widget
2. prepare scale factors relating the dimensions of the canvas to the dimensions of the plot data.
3. use the canvas create function to put lines or dots or x's (whatever you want) in the right place on the canvas.

Make sure you have the numbers right and post back. We can go over the steps to plot then.

_________________
Bob Rashkin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top