C-PLOT

Scientific Graphics and Data Analysis

12.21.9. - Referring to data within your subroutines



In the file p_fitsize.h is the definition of the data structure:
struct  f_data {
        unsigned d_flags;   /* Used internally */
        float   d_w2;       /* The square of the weight */
        double  d_y;        /* The dependent variable */
        double  d_ys;       /* Used internally */
        float   d_xx[1];    /* Independent variable(s) */
};
extern  struct  f_data  *f_data, *dp;
#define INC(d)  (d = (struct f_data * ) (((char *) d) + dpsize))
The pointer f_data is the base of an array of these structures. The pointer dp contains the address of the array element associated with the current point when fitting. The macro definition INC(d) illustrates how to increment a pointer to an element in the f_data array by one element. Such machinations are necessary since the size of an array element depends on the number of independent variables configured.


A fragment of code with which you might loop through all the data points follows:
register int  i;
register struct f_data  *d;

for (d = f_data, i = 0; i < npts; i++, INC(d)) {
        if (d->d_flags&D_DONT_FIT)
                continue;
        d-d_xx[0] =
        d-d_xx[1] =
        d-d_xx[2] =
        d-d_y     =
        d-d_w2    =
}
This example assumes three independent variables. Of course, the example still requires the right-hand side of the assignment expressions. The externally defined integer npts contains the current number of data points. The data flags have the D_DONT_FIT bit set if the points are not in the current fit range.