#include "offsets.h" //#define DEBUG_OFFSETS int get_array_offsets(off_t ** offs, size_t * noffs, int dim, const _IPNT gs, const _IPNT gn, const _IPNT ls, const _IPNT ln) { /******************** * declarations * ********************/ int err=0; /* loop counters */ size_t i,j,k; /* dim-1 dim'l loc power sequence excluding axis 0 */ size_t ploc[RARR_MAX_NDIM]; /* dim dim'l glob power sequence */ size_t pglob[RARR_MAX_NDIM]; /* storage for expansion coefficients */ int idx[RARR_MAX_NDIM]; off_t b; /******************** * end declarations * ********************/ #ifdef DEBUG_OFFSETS for (i=0;igs[i]+gn[i]); if (err) { #ifdef DEBUG_OFFSETS fprintf(stderr,"Error: get_array_offsets\n"); fprintf(stderr,"local array is not subarray of global array, i=%d\n",i); #endif return E_OUTOFBOUNDS; } } /* sanity check */ if (dim > RARR_MAX_NDIM) { #ifdef DEBUG_OFFSETS fprintf(stderr,"Error: get_array_offsets\n"); fprintf(stderr,"dim = %d larger than permissible limit %d\n", dim,RARR_MAX_NDIM); #endif return E_OUTOFBOUNDS; } /* work out number of offsets */ *noffs=1; for (i=1; i1) pglob[dim-1]=pglob[dim-2]*gn[dim-2]; #ifdef DEBUG_OFFSETS for (i=0;i0;i--) { idx[i]=k/ploc[i-1]; k=k-ploc[i-1]*idx[i]; #ifdef DEBUG_OFFSETS fprintf(stderr,"j=%jd i=%jd k=%jd idx=%d\n",j,i,k,idx[i]); #endif } idx[0]=k; /* should = 0 , since ploc[0]=1 ex def */ (*offs)[j]=0; for (i=0;i