alibPutTrace
Replaces a general subset of an array. Unlike
alibPutRange and
alibPutSubset, the subset need not be a subarray, but if the subset is a subarray then it is more efficiently replaced with those other routines. The PV-WAVE API for this routine is
Array Subscripting where all subscripts are arrays of the same length.
Prototypes
void alibPutTraceb( wvlong n, wvlong *d, wvlong b, wvlong **e, UCHAR *p, UCHAR *q )
void alibPutTraces( wvlong n, wvlong *d, wvlong b, wvlong **e, short *p, short *q )
void alibPutTracei( wvlong n, wvlong *d, wvlong b, wvlong **e, int *p, int *q )
void alibPutTracel( wvlong n, wvlong *d, wvlong b, wvlong **e, wvlong *p, wvlong *q )
void alibPutTracef( wvlong n, wvlong *d, wvlong b, wvlong **e, float *p, float *q )
void alibPutTraced( wvlong n, wvlong *d, wvlong b, wvlong **e, double *p, double *q )
void alibPutTracec( wvlong n, wvlong *d, wvlong b, wvlong **e, COMPLEX *p, COMPLEX *q )
void alibPutTracez( wvlong n, wvlong *d, wvlong b, wvlong **e, DCOMPLEX *p, DCOMPLEX *q )
Parameters
n — (Input) The number of dimensions in the array containing the subset to be replaced.
*d — (Input) The n-element array of dimensions for the array containing the subset to be replaced.
b — (Input) The number of elements to be replaced.
**e — (Input) The n-element array of pointers to b-element index arrays. The n b-element index arrays e define the b elements to be replaced.
*p — (Input/Output) The array containing the subset to be replaced. On output, the values in that subset have been replaced with new data.
*q — (Input) The array containing the replacement data.
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 dims[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};
/* make some arrays big enough for one-dimensional, two-dimensional, three-dimensional, and four-dimensional
examples */
UCHAR b[6];
UCHAR *b0;
b0 = (UCHAR*)malloc(54*sizeof(UCHAR));
/* initialize replacement data for one-dimensional, two-dimensional, three-dimensional, and four-dimensional examples */
alibinit( NULL, NULL, NULL, NULL );
alibIndexb( 6, 10, 1, b );
printf( "\n\n initialize and print one-dimensional array b0" );
alibRepb( 3, 0, b0 );
alibPrintArrayb( 1, 1, 1, 3, b0, NULL );
printf( "\n\n print replacement array b" );
alibPrintArrayb( 1, 1, 1, 2, b, NULL );
printf( "\n\n replace even-indexed elements of b0 with b, print result" );
alibPutTraceb( 1, &dims[3], 2, &indx[4], b0, b );
alibPrintArrayb( 1, 1, 1, 3, b0, NULL );
printf( "\n\n initialize and print two-dimensional array b0" );
alibRepb( 9, 0, b0 );
alibPrintArrayb( 1, 1, 3, 3, b0, NULL );
printf( "\n\n print replacement array b" );
alibPrintArrayb( 1, 1, 1, 3, b, NULL );
printf( "\n\n replace main-diagonal of b0 with b, print result" );
alibPutTraceb( 2, &dims[2], 3, &indx[2], b0, b );
alibPrintArrayb( 1, 1, 3, 3, b0, NULL );
printf( "\n\n initialize and print three-dimensional array b0" );
alibRepb( 27, 0, b0 );
alibPrintArrayb( 1, 3, 3, 3, b0, NULL );
printf( "\n\n print replacement array b" );
alibPrintArrayb( 1, 1, 1, 3, b, NULL );
printf( "\n\n replace main-diagonal of b0 with b, print result" );
alibPutTraceb( 3, &dims[1], 3, &indx[1], b0, b );
alibPrintArrayb( 1, 3, 3, 3, b0, NULL );
printf( "\n\n initialize and print four-dimensional array b0" );
alibRepb( 54, 0, b0 );
alibPrintArrayb( 2, 3, 3, 3, b0, NULL );
printf( "\n\n print replacement array b" );
alibPrintArrayb( 1, 1, 1, 6, b, NULL );
printf( "\n\n replace main-diagonal in both slices of the leading \n" );
printf( " dimension of b0 with b, print result" );
alibPutTraceb( 4, dims, 6, indx, b0, b );
alibPrintArrayb( 2, 3, 3, 3, b0, NULL );
}
Output:
initialize and print one-dimensional array b0
0 0 0
print replacement array b
10 11
replace even-indexed elements of b0 with b, print result
10 0 11
initialize and print two-dimensional array b0
0 0 0
0 0 0
0 0 0
print replacement array b
10 11 12
replace main-diagonal of b0 with b, print result
10 0 0
0 11 0
0 0 12
initialize and print three-dimensional array b0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
print replacement array b
10 11 12
replace main-diagonal of b0 with b, print result
10 0 0
0 0 0
0 0 0
0 0 0
0 11 0
0 0 0
0 0 0
0 0 0
0 0 12
initialize and print four-dimensional array b0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
print replacement array b
10 11 12 13 14 15
replace main-diagonal in both slices of the leading
dimension of b0 with b, print result
10 0 0
0 0 0
0 0 0
0 0 0
0 11 0
0 0 0
0 0 0
0 0 0
0 0 12
13 0 0
0 0 0
0 0 0
0 0 0
0 14 0
0 0 0
0 0 0
0 0 0
0 0 15
Version 2017.0
Copyright © 2017, Rogue Wave Software, Inc. All Rights Reserved.