Re: XForms: Segmentation Fault using xyplot

From: Steve Lamont (spl@blinky.ucsd.edu)
Date: Mon Jun 05 2000 - 12:53:13 EDT

  • Next message: Cihat Ozhasoglu: "XForms: Interix 2.2 (or OpenNT) for Windows 2000 and xforms"

    # To subscribers of the xforms list from Steve Lamont <spl@blinky.ucsd.edu> :

    > Thank you very much for your help, with it i corrected my code. My
    > intention doing the while was try to make xyplot works like a stripchart. I
    > know that i would have to insert others pieces of code but you think it's
    > possible? (I need something like a stripchart with a fixed scale in the
    > both axis) Could i use a fifo to pass data to the xyplot? Thanks in advance,

    It can be done, although it can be a bit tricky, since the XYPlot
    object is pretty thickheaded about how it wants to do scaling, etc.

    You'll have to keep an array of points to which you make your updates
    and then feed them to XYPlot, since there's no way to add a single
    point. For example, the following piece of code plots the most recent
    100 points:

            void add_point( float x, float y, FL_OBJECT *xyplot )

            {

                    static int n = 0;
                    static float X[1000];
                    static float Y[1000];

                    if ( n == 1000 ) {

                            memcpy( &X[0], &X[901], sizeof( float ) * 99 );
                            memcpy( &Y[0], &Y[901], sizeof( float ) * 99 );
                            
                            n = 99;

                    }
                    X[n] = x;
                    Y[n] = y;
                    n++;

                    fl_set_xyplot_data( xyplot,
                                        &X[n - 100],
                                        &Y[n - 100],
                                        100,
                                        ... );

            }

    Note that there is a bug in this code (what happens when n < 100?) and
    it's not intended to be used "straight out of the box." I leave it to
    the user to deal with the startup case.

    As for the mechanism for passing data from your monitoring code to the
    plot code, a FIFO, I suppose, is as good as anything. You may wish to
    refer to the manual's discussion of asynchronous I/O or check the
    archives of this mailing list -- there has been considerable
    discussion of this subject and numerous different solutions to the
    problem, including use of threads.

                                                            spl

    _________________________________________________
    To unsubscribe, send the message "unsubscribe" to
    xforms-request@bob.usuhs.mil or see
    http://bob.usuhs.mil/mailserv/xforms.html
    XForms Home Page: http://world.std.com/~xforms
    List Archive: http://bob.usuhs.mil/mailserv/list-archives/



    This archive was generated by hypermail 2b29 : Mon Jun 05 2000 - 12:57:49 EDT