RWalib C Array Library User Guide > Array Indexing > alibPutTraceS
  

alibPutTraceS
Replaces values in a general subset with a scalar. If the subset is a subarray then it can be more efficiently replaced with alibPutRangeS or alibPutSubsetS. To replace the subset values with variable values, see alibPutTrace. The PV-WAVE API for this routine is Array Subscripting where all subscripts are arrays of the same length.
Prototypes
void alibPutTraceSb( wvlong n, wvlong *d, wvlong b, wvlong **e, UCHAR *p, UCHAR q )
void alibPutTraceSs( wvlong n, wvlong *d, wvlong b, wvlong **e, short *p, short q )
void alibPutTraceSi( wvlong n, wvlong *d, wvlong b, wvlong **e, int *p, int q )
void alibPutTraceSl( wvlong n, wvlong *d, wvlong b, wvlong **e, wvlong *p, wvlong q )
void alibPutTraceSf( wvlong n, wvlong *d, wvlong b, wvlong **e, float *p, float q )
void alibPutTraceSd( wvlong n, wvlong *d, wvlong b, wvlong **e, double *p, double q )
void alibPutTraceSc( wvlong n, wvlong *d, wvlong b, wvlong **e, COMPLEX *p, COMPLEX q )
void alibPutTraceSz( 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, each value in that subset has been replaced with the given scalar.
q — (Input) The scalar value which replaces each value in the subset.
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;
   b = (UCHAR*)malloc(54*sizeof(UCHAR));
   printf( "\n\n initialize and print one-dimensional array b" );
      alibinit( NULL, NULL, NULL, NULL );
      alibRepb( 3, 0, b );
      alibPrintArrayb( 1, 1, 1, 3, b, NULL );
   printf( "\n\n replace even-indexed elements of b with a 1" );
      alibPutTraceSb( 1, &dims[3], 2, &indx[4], b, 1 );
      alibPrintArrayb( 1, 1, 1, 3, b, NULL );
   printf( "\n\n initialize and print two-dimensional array b" );
      alibRepb( 9, 0, b );
      alibPrintArrayb( 1, 1, 3, 3, b, NULL );
   printf( "\n\n replace each value on the main-diagonal of b with a 1" );
      alibPutTraceSb( 2, &dims[2], 3, &indx[2], b, 1 );
      alibPrintArrayb( 1, 1, 3, 3, b, NULL );
   printf( "\n\n initialize and print three-dimensional array b" );
      alibRepb( 27, 0, b );
      alibPrintArrayb( 1, 3, 3, 3, b, NULL );
   printf( "\n\n replace each value on the main-diagonal of b with a 1" );
      alibPutTraceSb( 3, &dims[1], 3, &indx[1], b, 1 );
      alibPrintArrayb( 1, 3, 3, 3, b, NULL );
   printf( "\n\n initialize and print four-dimensional array b" );
      alibRepb( 54, 0, b );
      alibPrintArrayb( 2, 3, 3, 3, b, NULL );
   printf( "\n\n in each 3d slice of the leading dimension of b, \n" );
   printf( " replace each value on the main-diagonal with a 1" );
      alibPutTraceSb( 4, dims, 6, indx, b, 1 );
      alibPrintArrayb( 2, 3, 3, 3, b, NULL );
}
 
Output:
 
 initialize and print one-dimensional array b
 
   0   0   0
 
 replace even-indexed elements of b with a 1
 
   1   0   1
 
 initialize and print two-dimensional array b
 
   0   0   0
   0   0   0
   0   0   0
 
 replace each value on the main-diagonal of b with a 1
 
   1   0   0
   0   1   0
   0   0   1
 
 initialize and print three-dimensional array b
 
 
   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
 
 replace each value on the main-diagonal of b with a 1
 
   1   0   0
   0   0   0
   0   0   0
 
   0   0   0
   0   1   0
   0   0   0
 
   0   0   0
   0   0   0
   0   0   1
 
 initialize and print four-dimensional array b
 
   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
 
 in each 3d slice of the leading dimension of b, 
 replace each value on the main-diagonal with a 1
 
   1   0   0
   0   0   0
   0   0   0
 
   0   0   0
   0   1   0
   0   0   0
 
   0   0   0
   0   0   0
   0   0   1
 
   1   0   0
   0   0   0
   0   0   0
 
   0   0   0
   0   1   0
   0   0   0
 
   0   0   0
   0   0   0
   0   0   1

Version 2017.0
Copyright © 2017, Rogue Wave Software, Inc. All Rights Reserved.