RWalib C Array Library User Guide > Array Indexing > alibPutSubsetS
  

alibPutSubsetS
Replaces values in a general subarray with a scalar. If the subarray is contiguous then it can be more efficiently replaced with alibPutRangeS. To replace the subarray values with variable values, see alibPutSubset. The PV-WAVE API for this routine is array indexing with at least one index array and at least one scalar or range operator.
Prototypes
void alibPutSubsetSb( wvlong n, wvlong *d, wvlong *b, wvlong **e, UCHAR *p, UCHAR q )
void alibPutSubsetSs( wvlong n, wvlong *d, wvlong *b, wvlong **e, short *p, short q )
void alibPutSubsetSi( wvlong n, wvlong *d, wvlong *b, wvlong **e, int *p, int q )
void alibPutSubsetSl( wvlong n, wvlong *d, wvlong *b, wvlong **e, wvlong *p, wvlong q )
void alibPutSubsetSf( wvlong n, wvlong *d, wvlong *b, wvlong **e, float *p, float q )
void alibPutSubsetSd( wvlong n, wvlong *d, wvlong *b, wvlong **e, double *p, double q )
void alibPutSubsetSc( wvlong n, wvlong *d, wvlong *b, wvlong **e, COMPLEX *p, COMPLEX q )
void alibPutSubsetSz( wvlong n, wvlong *d, wvlong *b, wvlong **e, DCOMPLEX *p, DCOMPLEX q )
Parameters
n — (Input) The number of dimensions in the array containing the subarray to be replaced.
*d — (Input) The n-element array of dimensions for the array containing the subarray to be replaced.
*b — (Input) The n-element array of dimensions for the subarray. Some can be equal to 1, i.e., the subarray can have less than n dimensions.
**e — (Input) The n-element array of pointers to the index arrays defining the subarray to be replaced. Some can be 1-element arrays, i.e., the subarray can have less than n dimensions. Number of elements in array e[i] is b[i].
*p — (Input/Output) The array containing the subarray to be replaced. On output, the subarray has been replaced.
q — (Input) The scalar value which replaces each value in the subarray.
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,4,5};
   /* lengths of index arrays to use for one-dimensional, two-dimensional, three-dimensional, four-dimensional 
      examples */
   wvlong ddst[4] = {2,2,2,3};
   /* index arrays to use for one-dimensional, two-dimensional, three-dimensional, four-dimensional examples */
   wvlong ind0[2] = {0,1};
   wvlong ind1[3] = {0,2,4};
   wvlong *indx[4] = {ind0,ind1,ind1,ind1};
   /* allocate array big enough for one-dimensional, two-dimensional, three-dimensional, and four-dimensional 
      examples */
   UCHAR    *b;
   b = (UCHAR*)malloc(120*sizeof(UCHAR));
   printf( "\n\n initialize and print one-dimensional array b" );
      alibinit( NULL, NULL, NULL, NULL );
      alibRepb( 5, 0, b );
      alibPrintArrayb( 1, 1, 1, 5, b, NULL );
   printf( "\n\n replace even-indexed elements of b with a 1" );
      alibPutSubsetSb( 1, &dims[3], &ddst[3], &indx[3], b, 1 );
      alibPrintArrayb( 1, 1, 1, 5, b, NULL );
   printf( "\n\n initialize and print two-dimensional array b" );
      alibRepb( 20, 0, b );
      alibPrintArrayb( 1, 1, 4, 5, b, NULL );
   printf( "\n\n replace even-indexed elements of b with a 1" );
      alibPutSubsetSb( 2, &dims[2], &ddst[2], &indx[2], b, 1 );
      alibPrintArrayb( 1, 1, 4, 5, b, NULL );
   printf( "\n\n initialize and print three-dimensional array b" );
      alibRepb( 60, 0, b );
      alibPrintArrayb( 1, 3, 4, 5, b, NULL );
   printf( "\n\n replace even-indexed elements of b with a 1" );
      alibPutSubsetSb( 3, &dims[1], &ddst[1], &indx[1], b, 1 );
      alibPrintArrayb( 1, 3, 4, 5, b, NULL );
   printf( "\n\n initialize and print four-dimensional array b" );
      alibRepb( 120, 0, b );
      alibPrintArrayb( 2, 3, 4, 5, b, NULL );
   printf( "\n\n in each slice of the leading dimension of b, \n" );
   printf( " replace the even-indexed elements with a 1" );
      alibPutSubsetSb( 4, dims, ddst, indx, b, 1 );
      alibPrintArrayb( 2, 3, 4, 5, b, NULL );
}
 
Output:
 
 initialize and print one-dimensional array b
 
   0   0   0   0   0
 
 replace even-indexed elements of b with a 1
 
   1   0   1   0   1
 
 initialize and print two-dimensional array b
 
   0   0   0   0   0
   0   0   0   0   0
   0   0   0   0   0
   0   0   0   0   0
 
 replace even-indexed elements of b with a 1
 
   1   0   1   0   1
   0   0   0   0   0
   1   0   1   0   1
   0   0   0   0   0
 
 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   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
 
 replace even-indexed elements of b with a 1
 
   1   0   1   0   1
   0   0   0   0   0
   1   0   1   0   1
   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
 
   1   0   1   0   1
   0   0   0   0   0
   1   0   1   0   1
   0   0   0   0   0
 
 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   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   0   0
   0   0   0   0   0
   0   0   0   0   0
 
 in each slice of the leading dimension of b, 
 replace the even-indexed elements with a 1
 
   1   0   1   0   1
   0   0   0   0   0
   1   0   1   0   1
   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
 
   1   0   1   0   1
   0   0   0   0   0
   1   0   1   0   1
   0   0   0   0   0
 
   1   0   1   0   1
   0   0   0   0   0
   1   0   1   0   1
   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
 
   1   0   1   0   1
   0   0   0   0   0
   1   0   1   0   1
   0   0   0   0   0

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