C+ C NAME: C CvSwap C PURPOSE: C Swapping bytes C CATEGORY: C gen/for/lib C CALLING SEQUENCE: subroutine CvSwap(IB,NB,NN,X) C INPUTS: C IB integer # bytes treated as single unit (1,2 or 4) C NB integer # bytes in one element of X (1,2,4 or 8) C (1 for byte, 2 for integer*2, 4 for integer*4 and real*4, C 8 for real*8) C NN integer # elements in X C X(NB,NN)integer*1 declared as integer*1 array, but can be anything C OUTPUTS: C X(NB,NN)integer*1 input array with bytes swapped C CALLS: C (none) C EXAMPLE: C For integer*4 array I(10) C call CvSwap(1,4,10,I) C will reverse the order of bytes in each element of I (bytes 1,2,3,4 -> 4,3,2,1) C call CvSwap(2,4,10,I) C will reverse the order of words in each element of I (bytes 1,2,3,4 -> 3,4,1,2) C PROCEDURE: C MODIFICATION HISTORY: C SEP-1998, Paul Hick (UCSD/CASS; pphick@ucsd.edu) C- integer IB integer NB integer NN integer*1 X(NB,NN) integer*1 B NU = NB/IB ! # I-byte units IU = (NU/2-1)*IB KU = (NU-1)*IB do I=0,IU,IB ! Loop over half # units K = KU-I do J=1,IB ! Loop over # bytes in unit IJ = I+J KJ = K+J do N=1,NN B = X(IJ,N) X(IJ,N) = X(KJ,N) X(KJ,N) = B end do end do end do return end