       SUBROUTINE SWAPR8(DATA,N)     
       INTEGER N
*v1.0  REAL*8    DATA(N)
       INTEGER*8    DATA(N)
C
C----------------------------------------------------------------------
C
C.IDENTIFICATION: Function   SWAPR8
C.LIBRARY:        GENERAL
C.AUTHOR:         L.Chiappetti - IFCTR Milano
C.VERSIONS:       1.0 -  5 Nov 92 - Original version
C-                2.0 - 01 Mar 10 - support to INTEGER*8
C.PURPOSE:        byte-swap a REAL*8 array or scalar (N=1)           
C-                now support also INTEGER*8
C.METHOD:         use an equivalence with a CHARACTER array
C.SYNTAX:         CALL SWAPR8(DATA,N)                   
C.PARAMETERS:     now INTEGER*8 DATA    the stuff to be swapped (in and out)
C-                INTEGER   N           number of elements in array
C.RESTRICTIONS:   to operate on both REAL and INTEGER the argument and
C-                internal work variable shall be declared INTEGER. This way
C-                they work for both. If declared REAL they fail on bit patterns
C-                corresponding to NaN (bit flip of signalling/quiet)
C.NOTES:          this code should be portable ... though may be slightly
C                 inefficient
C                 it swaps bytes ABCDEFGH --> HGFEDCBA   
C.FILES:          none
C.REFERENCES:     none
C---------------------------------------------------------------------------
C
*v1.0  REAL*8       WORK
       INTEGER*8       WORK
       CHARACTER    C(8),W                   
       EQUIVALENCE  (WORK,C)
       INTEGER      I
C
       IF(N.LE.0)RETURN
       DO 1 I=1,N
       WORK=DATA(I)
       W=C(1)
       C(1)=C(8)
       C(8)=W
       W=C(2)
       C(2)=C(7)
       C(7)=W
       W=C(3)
       C(3)=C(6)
       C(6)=W
       W=C(4)
       C(4)=C(5)
       C(5)=W
       DATA(I)=WORK
 1     CONTINUE
       RETURN
       END
