RWalib C Array Library User Guide > Array Indexing > alibPutRange
  

alibPutRange
Replaces a contiguous subarray with an array. This routine can be used to replace a stack of slices in an array or more generally to replace any m-dimensional box in any n-dimensional array (m <= n). The PV-WAVE API for this routine is array indexing that uses any combination of scalars and range operators.
Prototypes
void alibPutRangeb( wvlong n, wvlong *d, wvlong *b, wvlong *e, UCHAR *p, UCHAR *q )
void alibPutRanges( wvlong n, wvlong *d, wvlong *b, wvlong *e, short *p, short *q )
void alibPutRangei( wvlong n, wvlong *d, wvlong *b, wvlong *e, int *p, int *q )
void alibPutRangel( wvlong n, wvlong *d, wvlong *b, wvlong *e, wvlong *p, wvlong *q )
void alibPutRangef( wvlong n, wvlong *d, wvlong *b, wvlong *e, float *p, float *q )
void alibPutRanged( wvlong n, wvlong *d, wvlong *b, wvlong *e, double *p, double *q )
void alibPutRangec( wvlong n, wvlong *d, wvlong *b, wvlong *e, COMPLEX *p, COMPLEX *q )
void alibPutRangez( 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 beginning subscripts defining the "lower-left" corner of the subarray to be replaced.
*e — (Input) The n-element array of ending subscripts defining the "upper-right" corner of the subarray to be replaced. Note that subarrays of dimensionality less than n are prescribed if b[i] = e[i] for some i.
*p — (Input/Output) The array containing the subarray to be replaced. On output, the subarray defined by corners b and e has been replaced.
*q — (Input) The array which replaces the subarray in array p. Dimensionality of array q is automatically determined from corners b and e.
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};
   /* array of beginning subscripts to use for one-dimensional, two-dimensional, three-dimensional, 4-   d examples */
   wvlong begs[4] = {0,1,1,1};
   /* array of ending subscripts to use for one-dimensional, two-dimensional, three-dimensional, four-dimensional    examples */
   wvlong ends[4] = {1,2,2,3};
   /* allocate arrays big enough for one-dimensional, two-dimensional, three-dimensional, and four-dimensional 
   examples */
   UCHAR    *b, *b0;
   b0 = (UCHAR*)malloc(120*sizeof(UCHAR));
   b  = (UCHAR*)malloc(24*sizeof(UCHAR));
   /* initialize replacement data to use for one-dimensional, two-dimensional, three-dimensional, four-dimensional    examples */
   alibinit( NULL, NULL, NULL, NULL );
   alibIndexb( 24, 120, 1, b );
   printf( "\n\n initialize and print one-dimensional array b0" );
   alibIndexb( 5, 0, 1, b0 );
   alibPrintArrayb( 1, 1, 1, 5, b0, NULL );
   printf( "\n\n print one-dimensional array b" );
   alibPrintArrayb( 1, 1, 1, 3, b, NULL );
   printf( "\n\n replace b0's interior with array b, and print the result" );
   alibPutRangeb( 1, &dims[3], &begs[3], &ends[3], b0, b );
   alibPrintArrayb( 1, 1, 1, 5, b0, NULL );
   printf( "\n\n initalize and print two-dimensional array b0" );
   alibIndexb( 20, 0, 1, b0 );
   alibPrintArrayb( 1, 1, 4, 5, b0, NULL );
   printf( "\n\n print two-dimensional array b" );
   alibPrintArrayb( 1, 1, 2, 3, b, NULL );
   printf( "\n\n replace b0's interior with array b, and print the result" );
   alibPutRangeb( 2, &dims[2], &begs[2], &ends[2], b0, b );
   alibPrintArrayb( 1, 1, 4, 5, b0, NULL );
   printf( "\n\n initialize and print three-dimensional array b0" );
   alibIndexb( 60, 0, 1, b0 );
   alibPrintArrayb( 1, 3, 4, 5, b0, NULL );
   printf( "\n\n print three-dimensional array b" );
   alibPrintArrayb( 1, 2, 2, 3, b, NULL );
   printf( "\n\n use array b to replace the interior of each of the last\n");
   printf( " two two-dimensional slices through b0's leading dimension;  print result" );
   alibPutRangeb( 3, &dims[1], &begs[1], &ends[1], b0, b );
   alibPrintArrayb( 1, 3, 4, 5, b0, NULL );
   printf( "\n\n initialize and print four-dimensional array b0" );
   alibIndexb( 120, 0, 1, b0 );
   alibPrintArrayb( 2, 3, 4, 5, b0, NULL );
   printf( "\n\n print four-dimensional array b" );
   alibPrintArrayb( 2, 2, 2, 3, b, NULL );
   printf( "\n\n use array b to repeat the three-dimensional example on each \n" );
   printf( " three-dimensional slice of b0's leading dimension;  print result" );
   alibPutRangeb( 4, dims, begs, ends, b0, b );
   alibPrintArrayb( 2, 3, 4, 5, b0, NULL );
}
 
Output:
 
 initialize and print one-dimensional array b0
 
   0   1   2   3   4
 
 print one-dimensional array b
 
 120 121 122
 
 replace b0's interior with array b, and print the result
 
   0 120 121 122   4
 
 initalize and print two-dimensional array b0
 
   0   1   2   3   4
   5   6   7   8   9
  10  11  12  13  14
  15  16  17  18  19
 
 print two-dimensional array b
 
 120 121 122
 123 124 125
 
 replace b0's interior with array b, and print the result
 
   0   1   2   3   4
   5 120 121 122   9
  10 123 124 125  14
  15  16  17  18  19
 
 initialize and print three-dimensional array b0
 
   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  54
  55  56  57  58  59
 
 print three-dimensional array b
 
 120 121 122
 123 124 125
 
 126 127 128
 129 130 131
 
 use array b to replace the interior of each of the last
 two two-dimensional slices through b0's leading dimension;  print result
 
   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 120 121 122  29
  30 123 124 125  34
  35  36  37  38  39
 
  40  41  42  43  44
  45 126 127 128  49
  50 129 130 131  54
  55  56  57  58  59
 
 initialize and print four-dimensional array b0
 
   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  54
  55  56  57  58  59
 
  60  61  62  63  64
  65  66  67  68  69
  70  71  72  73  74
  75  76  77  78  79
 
  80  81  82  83  84
  85  86  87  88  89
  90  91  92  93  94
  95  96  97  98  99
 
 100 101 102 103 104
 105 106 107 108 109
 110 111 112 113 114
 115 116 117 118 119
 
 print four-dimensional array b
 
 120 121 122
 123 124 125
 
 126 127 128
 129 130 131
 
 132 133 134
 135 136 137
 
 138 139 140
 141 142 143
 
 use array b to repeat the three-dimensional example on each 
 three-dimensional slice of b0's leading dimension;  print result
 
   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 120 121 122  29
  30 123 124 125  34
  35  36  37  38  39
 
  40  41  42  43  44
  45 126 127 128  49
  50 129 130 131  54
  55  56  57  58  59
 
  60  61  62  63  64
  65  66  67  68  69
  70  71  72  73  74
  75  76  77  78  79
 
  80  81  82  83  84
  85 132 133 134  89
  90 135 136 137  94
  95  96  97  98  99
 
 100 101 102 103 104
 105 138 139 140 109
 110 141 142 143 114
 115 116 117 118 119

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