problem with passing arrays in TF2.Draw()

Petar Maksimovic (petar@heplcdf1.harvard.edu)
Sat, 9 May 1998 22:24:05 -0500


Fellow rooters,

I would appreciate if somebody could spare a minute and look over (and
perhaps try running) the macro given below, in which I attempt to plot
a trivial 2-D function (using TF2.Draw()). I'm using root 2.00/05,
and the problem exists on both IRIX 6.2 and Linux RedHat 5.0.

Thanks a lot!

Petar

// file: test.C
//____________________________________________________________________________
// tfun2() called from tfun1()
//
Double_t tfun2( Double_t *ee)
{
printf("ee[] = %f %f %f\n", ee[0], ee[1], ee[2]);
return ee[0]+ee[1]+ee[2];
}

//____________________________________________________________________________
// tfun1() is used in TF2 constructor and called by TF2.Draw()
//
Double_t tfun1(Double_t *x, Double_t *par)
{
Double_t res; // the result
Double_t xe[3]; // the array we'll try to pass

// put some values in xe[] (they are arbitrary)
xe[0] = x[1] + 0.845;
xe[1] = x[2] * x[1] * 0.246;
xe[2] = 0.941;

printf("xe[] = %f %f %f\n", xe[0], xe[1], xe[2]);

// call tfun2()
res = tfun2(xe);

printf("Result = %f\n", res);
return res;
}

I load and execute the above functions with:

root [0] .L test.C
root [1] TF2 *f2 = new TF2("test",tfun1,0,1,0,1,0);
root [2] f2->Draw()

And get hundreds of the following error messages:

Error: Array index out of range xe+2147351296 valid upto xe[2] FILE:/home/lv48/petar/root/./test.C LINE:10
Error: Array index out of range xe+1072569516 valid upto xe[2] FILE:/home/lv48/petar/root/./test.C LINE:10
Error: Array index out of range xe+57 valid upto xe[2] FILE:/home/lv48/petar/root/./test.C LINE:10
xe[] = 0.941000 0.000000 0.941000

The problem does not appear when I call tfun1() interactively,
e.g. by creating x,par in root shell, and printing its value:

root[77] printf("%f\n", tfun1(x,par));

Am I overlooking something? Thanks for any ideas on where to look...