On Tue, Nov 14, 2006 at 09:28:37AM +0100, [EMAIL PROTECTED] wrote:
> i'm making an apllication using gtk and I need to delete negative points of a
> serie.

How is exactly Gtk+ involved in this task?

> at first i read the first line an identify t,px,py...then i continue until the
> end of the file identifying t[i],px[i],py[i],i=1-NPOINTS
> so i build serie t,serie px,and serie py.
> during the reading...i would like that if any numeber is negative, delete it 
> and
> not appear in the corresponding serie.
> So...at the end i want to obtain:
> (in this case)
> 
> serie t 1,2,3
> serie px 20,4
> serie py 15,30,3
> 
> how can i do it??

Are you *sure* you want the arrays to end up with different
lengths and mutually non-corresponding values?

Anyway, what you wrote above is then quite a good
description of the code: if you get a point you do not want
during the reading, just don't store it.  That's all and
it's elementary C.  To make Gtk+ involved in the whole issue
at least somehow, using GArrays:

    gdouble *t, *px, *py;
    GArray *ta, *pxa, *pya;
    gdouble tp, pxp, pyp;

    ... open the file ...

    ta = g_array_new(FALSE, FALSE, sizeof(gdouble));
    pxa = g_array_new(FALSE, FALSE, sizeof(gdouble));
    pya = g_array_new(FALSE, FALSE, sizeof(gdouble));

    /* Use fscanf() only if the numbers use locale-defined
     * decimal deparator, otherwise you have to use
     * g_ascii_strotod() */
    while (fscanf(filehandle, "%lf %lf %lf", &tp, &pxp, &pyp) == 3) {
        if (tp >= 0.0)
            g_array_append_val(ta, tp);
        if (pxp >= 0.0)
            g_array_append_val(pxa, pxp);
        if (pyp >= 0.0)
            g_array_append_val(pya, pyp);
    }

    /* Now you should also remember the lengths of the
     * arrays because they differ.   Or you can
     * continue using the GArrays (don't free them then)
     * instead of the plain C arrays.
     */

    t = (gdouble*)ta->data;
    px = (gdouble*)pxa->data;
    py = (gdouble*)pya->data;

    g_array_free(ta, FALSE);
    g_array_free(pxa, FALSE);
    g_array_free(pya, FALSE);

Yeti


--
Whatever.
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to