#3 problems with plplot in c++

closed
nobody
None
5
2007-02-02
2002-10-01
Anonymous
No

I am trying to use PLplot within a c++ program. I use
the following code to initialize plstream:

plstream pls;
pls.col(Red);

pls.env(minX, maxX, minY, maxY, 0, 1);

pls.poin(NumData, (PLFLT *)&x, (PLFLT *)&y, -1);

To fill my x and y arrays i used the following source:

double *x;
x = new double[10];
double *y;
y = new double[10];
for (int i=1; i<=10; i++)
{
x[i] = i;
y[i] = i;
}

If I run the program with this source I just get
segmentation fault, and no chance to select plotting
options.

If I change the for loop to:

for (int i=1; i<=10; i++)
{
x[i] = i;
y[i] = i;
std::cout << i << std::endl;
}

The program prints out numbers 1-10, and then gives me
a choice of plotting options. I choose xwin and a
blank 10 x 10 box and labeled axes in red appears. I am
compiling with the following code:

g++ -o TestGrp TestGrp.cc GrpDisp.cc
-L /usr/local/Tools/plplot/lib -I
/usr/local/Tools/plplot/include -I /usr/X11R6/include
-L /usr/X11R6/lib
-lm -lX11 -lplcxx -lplplot

Any help on how to get a graph on the screen would be
much appreciated.

Discussion

  • Werner Smekal

    Werner Smekal - 2007-02-02

    Logged In: YES
    user_id=899567
    Originator: NO

    In C/C++ the array index goes from 0 to size-1. So this >>for (int i=1; i<=10; i++)<< is wrong and should be >>for (int i=0; i<10; i++)<<. You have solved this problem I'm sure, it's just for the records.

     
  • Werner Smekal

    Werner Smekal - 2007-02-02
    • status: open --> closed
     

Log in to post a comment.