c     Byte swapping helper functions in Fortran, used in conversion2
c     to get unswapped SDD classes and data into Unipops internal 
c     format.  The bootstrap and index are handled when the SDD file
c     is read, in the C-language SDD disk functions.  We can't do that
c     for the scans, since the SDD scan is blindly dumped out as a slew of 
c     doubles -- the actual processing of that mess into the various
c     datatypes happens in CONLINE (F77).   So we need these helpers too.
c     Bugger.                                     -CAK 12 Sept 2004
c
      subroutine swapINT2(k)
c     does a byteswap on integer*2 number
      integer*1 ii(2), jj(2)
      integer*2 i, j, k
      equivalence (i,ii)
      equivalence (j,jj)
c
      i = k
      jj(1) = ii(2)
      jj(2) = ii(1)
      k = j
      end
c
      subroutine swapINT4(k)
c     does a byteswap on integer*4 number
      integer*1 ii(4), jj(4)
      integer*4 i, j, k
      equivalence (i,ii)
      equivalence (j,jj)
c
      i = k
      jj(1) = ii(4)
      jj(2) = ii(3)
      jj(3) = ii(2)
      jj(4) = ii(1)
      k = j
      end
c
c
      subroutine swapR4(r)
c     does a byteswap on real*4 number
      integer*1 ii(4), jj(4)
      real*4 r, s, t
      equivalence (s,ii)
      equivalence (t,jj)
c
      s = r
      jj(1) = ii(4)
      jj(2) = ii(3)
      jj(3) = ii(2)
      jj(4) = ii(1)
      r = t
      end
c
c
      subroutine swapR8(r)
c     does a byteswap on real*8 number
      integer*1 ii(8), jj(8)
      real*8 r, s, t
      equivalence (s,ii)
      equivalence (t,jj)
c
      s = r
      jj(1) = ii(8)
      jj(2) = ii(7)
      jj(3) = ii(6)
      jj(4) = ii(5)
      jj(5) = ii(4)
      jj(6) = ii(3)
      jj(7) = ii(2)
      jj(8) = ii(1)
      r = t
      end
c
c
      subroutine swapR4inR8(r)
c     does a byteswap on two R*4 numbers inside a R*8
      integer*1 ii(8), jj(8)
      real*8 r, s, t
      equivalence (s,ii)
      equivalence (t,jj)
c
      s = r
      jj(1) = ii(4)
      jj(2) = ii(3)
      jj(3) = ii(2)
      jj(4) = ii(1)
      jj(5) = ii(8)
      jj(6) = ii(7)
      jj(7) = ii(6)
      jj(8) = ii(5)
      r = t
      end
c
