Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

BLT and C array linking problem

1 view
Skip to first unread message

Harish Krishnamoorthy

unread,
Jul 1, 2002, 8:24:42 PM7/1/02
to
Thanks a lot to Mr George Howlett for replying to my mail.

I tried the way you had told. The winmain.c file , the one that links
my C program to Tk/GUI is compiling without error. But the Tk
program/GUI when executes gives an error- " cannot load file x".
I dont know why it is considering x as a file instead of vector.What
is the code that I have to write in TK/GUI end?

I am hereby generalising what I want for your perusal:-

xcomp and ycomp are arrays in C which are to be plotted in X axis and
Yaxis resp.I am getting fine values when I print these values in C.
in_menu ()
{
...
...
..
pol_sim()
...
}
pol_sim()
{
...
....
for ( i=1;i<=35;i++)
{
ycomp[i]=z[i];
xcomp[i]=r[i];

//printf("\n check2 = %f ",ycomp[i]);
// printf(" check3 = %f",xcomp[i]);
}
...
}

I just want values of these arrays to be passed to BLT so that I can
plot the graph.

I am stuck up with this problem for more than a week . I would be
highly obliged if you could help me out.

Waiting eagerly for your reply .

Regards
Harish

George A. Howlett

unread,
Jul 2, 2002, 2:03:14 AM7/2/02
to

The easy part is getting the data into the graph. The hard part,
(depending upon how much Windows programming experience you have) is
compiling and linking the code. Where did you get your winmain.c
file? Without seeing the code, I can't tell if you're setting up Tcl
and Tk correctly.

The plan is to create and manage the graph and vectors from Tcl code.
We will create new Tcl commands to call your custom code to put the
data into the vectors.

Create a graph widget and 2 BLT vectors in Tcl code.

blt::vector create x y
blt::graph .g
.g element create "e1" -x X -y Y
pack .g -fill both -expand yes

To get your data into the vectors, you will link in the custom code
below. It creates two new Tcl commands "link_vectors" and
"fill_vectors". The "link_vectors" command tells your C code the
vector to use.

link_vectors X Y

The "fill_vectors" command fills the vectors with the latest data.

fill_vectors

The graph will automatically redraw itself whenever you call
"fill_vectors".

Here's the C code.

#include <tcl.h>
#include <blt.h>
#include <bltVector.h>

static Blt_Vector *xVec, *yVec;

static Tcl_CmdProc FillCmd;
static Tcl_CmdProc LinkCmd;

static double xcomp[35], ycomp[35];

static int
LinkCmd(
ClientData clientData, /* Not used. */
Tcl_Interp *interp, /* Interpreter to report errors back to. */
int argc, /* # of arguments */
char **argv) /* Array of argument strings. */
{
if (argc != 3) {
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" xVecName yVecName", (char *)NULL);
return TCL_ERROR;
}
if ((Blt_GetVector(interp, argv[1], &xVec) != TCL_OK) ||
(Blt_GetVector(interp, argv[2], &yVec) != TCL_OK)) {
return TCL_ERROR;
}
return TCL_OK;
}

static int
FillCmd(
ClientData clientData, /* Not used. */
Tcl_Interp *interp, /* Interpreter to report errors back to. */
int argc, /* Not used. */
char **argv) /* Not used. */
{
if ((xVec == NULL) || (yVec == NULL)) {
Tcl_AppendResult(interp, "no vectors linked", (char *)NULL);
return TCL_ERROR;
}
if ((Blt_ResetVector(xVec, xcomp, 35, 35, TCL_STATIC) != TCL_OK) ||
(Blt_ResetVector(yVec, ycomp, 35, 35, TCL_STATIC) != TCL_OK)) {
return TCL_ERROR; /* Should never fail since memory is
* static. */
}
return TCL_OK;
}

/*
* Call this from your Tcl_AppInit procedure.
*/
int
LinkVectorInit(Tcl_Interp *interp)
{
Tcl_CreateCommand(interp, "fill_vectors", FillCmd, NULL, NULL);
Tcl_CreateCommand(interp, "link_vectors", LinkCmd, NULL, NULL);
return TCL_OK;
}


Note that you can update the vectors (and redraw the graph)
from C code, without going through the FillCmd routine.

/* Fill the xcomp and ycomp arrays with the new values */
for (i = 0; i < 35; i++) {
xcomp[i] = r[i];
ycomp[i] = z[i];
}
/*
* The Blt_ResetVector routine updates the vectors with
* the new information. This causes the graph to be
* redrawn.
*/
Blt_ResetVector(xVec, xcomp, 35, 35, TCL_STATIC);
Blt_ResetVector(yVec, ycomp, 35, 35, TCL_STATIC);


--gah

Harish Krishnamoorthy

unread,
Jul 8, 2002, 5:47:11 PM7/8/02
to
"George A. Howlett" <g...@storm.xmen.net> wrote in message news:<ui2gh2g...@corp.supernews.com>...

Hello Sir,
Thanks a lot for your help.
Actually I have a C code of around 2000 lines. and the following
mentioned is only a part of the C code .
Hence I cannot put my existing C program into the C API code.I have to
keep them separate.

in_menu() is a function which has pol_sim() and which in turn has many
functions.

in_menu ()
> > {
> > ...
> > ...
> > ..

> > pol_sim();
> > function1();
function2();
> > }
> > pol_sim()
> > {
> > function3();
> > function4();


> > for ( i=1;i<=35;i++)
> > {
> > ycomp[i]=z[i];
> > xcomp[i]=r[i];
> >
> > //printf("\n check2 = %f ",ycomp[i]);
> > // printf(" check3 = %f",xcomp[i]);
> > }
> > ...
> > }

I want to link this C code using C API to BLT. I have got to keep the
existing C code separate from the C API program for linking my BLT
with C.

I understood the way to link BLT and C if the C function and C API are
in the same code.But I dont know how it can be done if they are 2
separate codes.I will have to include **.c in the code initially.
After that what else should I do.where should i call the C function ?
for eg "in_menu()" in my C API code.

Regards
Harish

0 new messages