C     @(#)chrxi.f	1.1     02/19/98
C
      subroutine chrxi (number, ch)
c     !-----------------------------

c CHaracters_Right_justified_eX_Integer

c An integer*4 is supplied in NUMBER,  this routine will plant it
c into the CH character string - right justified
c Will put in stars if number is too large

c CHRXI uses blanks to left fill
c CHRXI0 uses zeros to left fill
c CHRXIS uses blanks to left fill and will put in a plus sign

      character*(*) ch, plant*1, sign*1
      character*1 symbol(0:9)/'0','1','2','3','4','5','6','7','8','9'/
      character*4 cols
      character*12 toobig

      integer ismall
      logical first/.true./

      plant = ' '
      go to 6

      entry chrxis (number, ch)
c     -------------------------

      plant = ' '
      sign = '+'
      if (number .eq. 0) sign = ' '
      go to 8

      entry chrxi0 (number, ch)
c     -------------------------

      plant = '0'
6     sign = ' '
8     if (first) then
        ismall = makei4('80000000')
        first = .false.
      end if
      now = len (ch)
      if (number .ge. 0) then
        next = number
      else
        sign = '-'
        if (number .eq. ismall) then
          ch(now:now) = '8'
          now = now - 1
          next = -number / 10
        else
          next = -number
        end if
      end if
2     if (now .eq. 0) goto 7
      numb = next
      next = numb / 10
      ch (now:now) = symbol(numb-10*next)
      now = now - 1
      if (next .ne. 0) go to 2

c     ! Put in sign if required

      if (sign .ne. ' ') then
        if (now .eq. 0) goto 7

c       ! zero fill to column two of field (keep column 1 for sign)

        if (plant .ne. ' ') then
          do while (now .gt. 1)
            ch (now:now) = plant
            now = now - 1
          end do
        end if
        ch (now:now) = sign
        now = now - 1
      end if

c Left fill with zero or blank characters

      do while (now .ne. 0)
        ch (now:now) = plant
        now = now - 1
      end do
      return

c Number overflows space available

7     call cfill (ch, '*')
      write (toobig, '(i12)') number
      write (cols, '(i4)') len(ch)
      call warn (toobig//' is too big for'//cols
     2                 //' columns, filled with *')
      return
      end
