RWalib C Array Library User Guide > Array Initialization > alibFlipDim
  

alibFlipDim
Reverses the order of elements along one dimension of an array. The PV-WAVE API for this routine is the REVERSE Function.
Prototypes
void alibFlipDimb( wvlong d, wvlong m, wvlong n, UCHAR *p, UCHAR *q )
void alibFlipDims( wvlong d, wvlong m, wvlong n, short *p, short *q )
void alibFlipDimi( wvlong d, wvlong m, wvlong n, int *p, int *q )
void alibFlipDiml( wvlong d, wvlong m, wvlong n, wvlong *p, wvlong *q )
void alibFlipDimf( wvlong d, wvlong m, wvlong n, float *p, float *q )
void alibFlipDimd( wvlong d, wvlong m, wvlong n, double *p, double *q )
void alibFlipDimc( wvlong d, wvlong m, wvlong n, COMPLEX *p, COMPLEX *q )
void alibFlipDimz( wvlong d, wvlong m, wvlong n, DCOMPLEX *p, DCOMPLEX *q )
Parameters
d — (Input) If d=0 then the order of elements along the first dimension is reversed. Otherwise, the order along the last dimension is reversed.
m — (Input) If d=0, m is the number of elements in the first dimension. Otherwise, m is the number of elements in a slice of the last dimension, i.e., equals the product of all dimensions except the last one.
n — (Input) The number of elements in the array, divided by m.
*p — (Input) The m*n-element source array.
*q — (Input/Output) The m*n-element destination array. On return, q is the array obtained from p by reversing the order of its elements along the dimension specified by d.
Example
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "alib.h"
void main() {
    UCHAR    b0[24] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,
                       20,21,22,23};
    UCHAR    *b;
    b = (UCHAR*)malloc(24*sizeof(UCHAR));
    alibinit( NULL, NULL, NULL, NULL );
    printf( "\n\n first treat b0 as a (6,4) array" );
    alibPrintArrayb( 1, 1, 6, 4, b0, NULL );
    printf( "\n\n reverse order along columns (first dimension)" );
    alibFlipDimb( 0, 6, 4, b0, b );
    alibPrintArrayb( 1, 1, 6, 4, b, NULL );
    printf( "\n\n reverse order along rows (last dimension)" );
    alibFlipDimb( 1, 6, 4, b0, b );
    alibPrintArrayb( 1, 1, 6, 4, b, NULL );
    printf( "\n\n now treat b0 as a (2,3,4) array" );
    alibPrintArrayb( 1, 2, 3, 4, b0, NULL );
    printf( "\n\n reverse order along first dimension" );
    alibFlipDimb( 0, 2, 3*4, b0, b );
    alibPrintArrayb( 1, 2, 3, 4, b, NULL );
    printf( "\n\n reverse order along last dimension" );
    alibFlipDimb( 1, 2*3, 4, b0, b );
    alibPrintArrayb( 1, 2, 3, 4, b, NULL );
}
 
Output:
 
 first treat b0 as a (6,4) array
 
   0   1   2   3
   4   5   6   7
   8   9  10  11
  12  13  14  15
  16  17  18  19
  20  21  22  23
 
reverse order along columns (first dimension)
 
  20  21  22  23
  16  17  18  19
  12  13  14  15
   8   9  10  11
   4   5   6   7
   0   1   2   3
 
reverse order along rows (last dimension)
 
  3   2   1   0
   7   6   5   4
  11  10   9   8
  15  14  13  12
  19  18  17  16
  23  22  21  20
 
now treat b0 as a (2,3,4) array
 
   0   1   2   3
   4   5   6   7
   8   9  10  11
 
  12  13  14  15
  16  17  18  19
  20  21  22  23
 
 
 reverse order along first dimension
 
  12  13  14  15
  16  17  18  19
  20  21  22  23
 
   0   1   2   3
   4   5   6   7
   8   9  10  11
 
reverse order along last dimension
 
   3   2   1   0
   7   6   5   4
  11  10   9   8
 
  15  14  13  12
  19  18  17  16
  23  22  21  20
 

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