C-PLOT

Scientific Graphics and Data Analysis

E.1.12. - Getting and setting auxiliary data arrays



The user function overhead modules also provide you with a method of storing auxiliary data arrays that have the same number of elements as there are data points. This auxiliary data is also kept in a temporary file if there is not enough room in program memory.

The following functions handle the file control.

 Name   What it Does 
 fpt_init(ptr, size  ptr points to static storage of size bytes 
 fpt_get(i  Fetch the ith element 
 fpt_set(i  Set the ith element 
 fpt_fini()   Bring the temporary file up to date 

The function fpt_init() is used to initialize the auxiliary storage routine. You supply it with a pointer to the data structure you are using and tell it how big that structure is. The fpt_get() and fpt_set() routines then use that storage you have allocated to transfer the data in and out.

For example,
{
        Point   pt;
        static  struct  aux {
                float   a_1;
                float   a_2;
                float   a_3;
        } aux;
        static  once;
        ...
        if (!once) {
                /* Initialize storage just once */
                fpt_init(&aux, sizeof(aux));
                once++;
        }
        for (i = 0; i  get_npts(); i++) {
                pt_get(&pt, i);
                aux.a_1 = get_x(&pt);
                aux.a_2 = get_x(&pt) * 2;
                aux.a_3 = get_x(&pt) * 3;
                fpt_set(i);
        }
        fpt_fini();
        ...
}
fpt_init() can be called more than once to reinitialize the storage, perhaps using a different data structure. Every time it is called, though, the previously stored numbers are wiped out. Call it just once and the values stored will be retained over successive invocations of the user function when it is reinvoked with the fn . syntax.