      integer function uni2ieee_int (iarray,iwrd)

C Function converts Univac 36-bit integer to IEEE 32-bit integer
C  Not well tested for negative numbers

      integer*4     iarray(1)    !array of Univac numbers
      integer*4     iwrd         !word number of first half of Univac number
                                 ! where words are counted 0,1,2,... and a
                                 ! word is 36 bits (DP = 72 bits = 2 words)

      integer*4     jwrd         !32-bit word pointer in iarray (1,2,3,...)
      integer*4     jbit         !bit position in iarray (31,30,...0)

      integer*4     jsign        !sign bit for the number
      integer*4     jman0        !more significant 17 bits
      integer*4     jman1        !less significant 18 bits

      integer*4     kman0        !temporary jman0 for 2's complement
      integer*4     kman1        !temporary jman1 for 2's complement

      integer*4     zero         !constant

      integer*4     get_bits     !integer function


C Initializations

      jsign = 0
      jman0 = 0
      jman1 = 0
      zero  = 0


C Translate 36-bit pointer to 32-bit pointers

      jwrd = iwrd*36/32 + 1
      jbit = 31 - (iwrd*36 - 32*(jwrd-1))


C Extract components of Univac number
C  Sign bit goes into  jsign
C  Most significant 15 bits go into  man0
C  Least significant 20 bits go into  man1

c      write(*,'("init:  ",3i5,3z11.8)') iwrd,jwrd,jbit,
c     *       iarray(jwrd),iarray(jwrd+1),iarray(jwrd+2)

      jsign = get_bits(iarray,jwrd,jbit,1)
      jman0 = get_bits(iarray,jwrd,jbit,15)
      jman1 = get_bits(iarray,jwrd,jbit,20)

c      write(*,'("jman0: ",3i5,2z11.8)')
c      *       iwrd,jwrd,jbit,jsign,jman0

c      write(*,'("jman0: ",3i5,3z11.8)') iwrd,jwrd,jbit,
c     *                                jsign,jman0,jman1



C Do two's complement for negative numbers

      if (jsign .eq. 1) then

        kman0 = not(jman0)                   !One's complement
        call mvbits(zero,15,17,kman0,15)
        kman1 = not(jman1)
        call mvbits(zero,20,12,kman1,20)

        kman1 = kman1 + 1                    !Two's complement
        if (kman1 .eq. 2**20) then
          kman1 = 0
          kman0 = kman0 + 1
        end if

        jman0 = kman0
        jman1 = kman1

      end if


C Reconstruct double precision number in local binary

      uni2ieee_int = (2**20)*jman0 + jman1


C Put on the correct sign

      if (jsign .eq. 1) uni2ieee_int = - uni2ieee_int

      return
      end
