RWalib C Array Library User Guide > Array Indexing > alibGetTrace
  

alibGetTrace
Retrieves a general subset of an array. Unlike alibGetRange and alibGetSubset, the subset need not be a subarray, e.g., the main diagonal of an array. If the subset is a subarray it is more efficiently retrieved with the other routines. The PV-WAVE API for this routine is Array Subscripting where all subscripts are arrays of the same length.
Prototypes
void alibGetTraceb( wvlong n, wvlong *d, wvlong b, wvlong **e, UCHAR *p, UCHAR *q )
void alibGetTraces( wvlong n, wvlong *d, wvlong b, wvlong **e, short *p, short *q )
void alibGetTracei( wvlong n, wvlong *d, wvlong b, wvlong **e, int *p, int *q )
void alibGetTracel( wvlong n, wvlong *d, wvlong b, wvlong **e, wvlong *p, wvlong *q )
void alibGetTracef( wvlong n, wvlong *d, wvlong b, wvlong **e, float *p, float *q )
void alibGetTraced( wvlong n, wvlong *d, wvlong b, wvlong **e, double *p, double *q )
void alibGetTracec( wvlong n, wvlong *d, wvlong b, wvlong **e, COMPLEX *p, COMPLEX *q )
void alibGetTracez( wvlong n, wvlong *d, wvlong b, wvlong **e, DCOMPLEX *p, DCOMPLEX *q )
Parameters
n — (Input) The number of dimensions in the source array.
*d — (Input) The n-element array of dimensions in the source array.
b — (Input) The number of elements in each of n index arrays.
**e — (Input) The n-element array of pointers to b-element index arrays. The n b-element index arrays e define b points in the n-dimensional source array.
*p — (Input) The source array.
*q — (Input/Output) The destination array. On return, array q is a copy of the data at the b points e in array p.
Example
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "alib.h"
void main() {
   /* array of dimensions to use for one-dimensional, */
   /* two-dimensional, three-dimensional, and */
   /* four-dimensional examples */
   wvlong dsrc[4] = {2,3,3,3};
   /* index arrays to use for one-dimensional, */
   /* two-dimensional, three-dimensional, and */
   /* four-dimensional examples */
   wvlong ind0[2] = {0,2};
   wvlong ind1[6] = {0,1,2,0,1,2};
   wvlong ind2[6] = {0,0,0,1,1,1};
   wvlong *indx[5] = {ind2,ind1,ind1,ind1,ind0};
   /* output array big enough for one-dimensional, */
   /* two-dimensional, three-dimensional, and */
   /* four-dimensional examples */
   UCHAR    b[6];
   /* fabricate enough test data for one-dimensional, */
   /* two-dimensional, three-dimensional, and */
   /* four-dimensional examples */
   UCHAR    *b0;
   b0 = (UCHAR*)malloc(54*sizeof(UCHAR));
   alibinit( NULL, NULL, NULL, NULL );
   alibIndexb( 54, 0, 1, b0 );
   printf( "\n\n print 1d-array, retrieve and print its even-indexed data" );
   alibPrintArrayb( 1, 1, 1, 3, b0, NULL );
   alibGetTraceb( 1, &dsrc[3], 2, &indx[4], b0, b );
   alibPrintArrayb( 1, 1, 1, 2, b, NULL );
   printf( "\n\n print 2d-array, retrieve and print its main diagonal" );
   alibPrintArrayb( 1, 1, 3, 3, b0, NULL );
   alibGetTraceb( 2, &dsrc[2], 3, &indx[2], b0, b );
   alibPrintArrayb( 1, 1, 1, 3, b, NULL );
   printf( "\n\n print 3d-array, retrieve and print its main diagonal" );
   alibPrintArrayb( 1, 3, 3, 3, b0, NULL );
   alibGetTraceb( 3, &dsrc[1], 3, &indx[1], b0, b );
   alibPrintArrayb( 1, 1, 1, 3, b, NULL );
   printf( "\n\n print 4d-array with leading dimension of 2, retrieve \n" );
   printf( " and print main diagonal from each three-dimensional slice of that dimension");
   alibPrintArrayb( 2, 3, 3, 3, b0, NULL );
   alibGetTraceb( 4, dsrc, 6, indx, b0, b );
   alibPrintArrayb( 1, 1, 2, 3, b, NULL );
}
 
Output:
 
 print 1d-array, retrieve and print its even-indexed data
 
   0   1   2
 
   0   2
 
 print 2d-array, retrieve and print its main diagonal
 
   0   1   2
   3   4   5
   6   7   8
 
   0   4   8
 
 print 3d-array, retrieve and print its main diagonal
 
   0   1   2
   3   4   5
   6   7   8
 
   9  10  11
  12  13  14
  15  16  17
 
  18  19  20
  21  22  23
  24  25  26
 
   0  13  26
 
 print 4d-array with leading dimension of 2, retrieve 
 and print main diagonal from each three-dimensional slice of that dimension
 
   0   1   2
   3   4   5
   6   7   8
 
   9  10  11
  12  13  14
  15  16  17
 
  18  19  20
  21  22  23
  24  25  26
 
  27  28  29
  30  31  32
  33  34  35
 
  36  37  38
  39  40  41
  42  43  44
 
  45  46  47
  48  49  50
  51  52  53
 
   0  13  26
  27  40  53

Version 2017.1
Copyright © 2019, Rogue Wave Software, Inc. All Rights Reserved.