The following ``ANSI-C'' code calculates and sets the addresses for the start of each of the program arrays. This code may be used and modified as required. This can allow you to work directly with all of FIT2D's main program arrays. The addresses are dependent on the size of the program arrays to create (xmaxdat and ymaxdat), and on whether or not ``memory arrays'' and ``variance arrays'' are to be created. Non-created array addresses are set to NULL.
With care this code could be interfaced to Fortran or other computer languages and allow you work directly with the data arrays used by FIT2D.
/*********1*********2*********3*********4*********5*********6*********7** *** ************************** *** * * *** * f2d_sharedaddressesc.c * *** * * *** ************************** */ #define _POSIX_SOURCE 1 #define TRUE ~0 #include <stdio.h> #include <stdlib.h> /*+ F2D_SHAREDADDRESSESC: Set base addresses of program arrays */ int f2d_sharedaddressesc /* Returns "TRUE" if successful */ (float base_address[], /* Base address of shared memory segment to use */ int xmaxdat, /* Dimension size in X-direction for data arrays */ int ymaxdat, /* Dimension size in Y-direction for data arrays */ int memory_exist, /* "TRUE" if memory array exists */ int variances_exist, /* "TRUE", if a data variance array is created */ float *DATA[], /* Returns base address of array "DATA" */ char *MASK[], /* Returns base address of array "MASK" */ float *XAXIS[], /* Pointer to dynamic array "XAXIS" */ float *YAXIS[], /* Returns base address of array "YAXIS" */ float *VARIANCES[], /* Returns base address of array "VARIANCES" */ float *MDATA[], /* Returns base address of array "MDATA" */ float *MXAXIS[], /* Returns base address of array "MXAXIS" */ float *MYAXIS[], /* Returns base address of array "MYAXIS" */ float *MVARIANCES[]) /* Returns base address of array "MVARIANCES" */ /* Description: * Calculates addresses of different available program arrays given * the base address and the sizes of the arrays. * Status: * Method: * Bugs: * Authors: * A P Hammersley (hammersley@esrf.fr) * History: * 18-Dec-2003: V0.1 Original (Hammersley) * 22-Dec-2003: V0.2 Correct stupid "clever" "C"'s addressing (Hammersley) * 09-Jan-2004: V0.3 Tidy code (Hammersley) * Import: */ /* Status: */ /* Deficiency: /* Extra "C" Variables: */ /*--------1---------2---------3---------4---------5---------6---------7--*/ { /* Local Variables: */ char *address; /* Address pointer, in "char' to stop "C"'s stupid "clever" and confusing address aritmetic logic */ /* Calculate addresses of arrays */ *DATA = base_address; address = (char *) base_address; *MASK = (char *) (address + xmaxdat * ymaxdat * sizeof(float)); address = address + xmaxdat * ymaxdat * (sizeof(float) + sizeof(char)); *XAXIS = (float *) address; address = address + xmaxdat * sizeof(float); *YAXIS = (float *) address; address = address + ymaxdat * sizeof(float); if (memory_exist) { *MDATA = (float *) address; address = address + xmaxdat * ymaxdat * sizeof(float); *MXAXIS = (float *) address; address = address + xmaxdat * sizeof(float); *MYAXIS = (float *) address; address = address + ymaxdat * sizeof(float); } else { *MDATA = NULL; *MXAXIS = NULL; *MYAXIS = NULL; } if (variances_exist) { *VARIANCES = (float *) address; if (memory_exist) { *MVARIANCES = (float *) (address + xmaxdat * ymaxdat * sizeof(float)); } else { *MVARIANCES = NULL; } } else { *VARIANCES = NULL; *MVARIANCES = NULL; } /* Set good return status */ return TRUE; /* End of Function f2d_sharedaddressesc */ }