      subroutine chvxi (number, ch, nbase)

c CHaracters_Right_justified_eX_Integer  (displayed in nbase)

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 CHVXI uses blanks to left fill
c CHVXI0 uses zeros to left fill
c CHVXIS uses blanks to left fill and will put in a plus sign

      character*(*) ch, plant*1, sign*1
      character*6 chival
      character*1 set(0:35)/'0','1','2','3','4','5','6','7','8','9',
     2                'A','B','C','D','E','F','G','H','I','J',
     2                'K','L','M','N','O','P','Q','R','S','T',
     2                'U','V','W','X','Y','Z'/
      character*80 mesage

      plant = ' '
      sign = ' '
      go to 8

      entry chvxis (number, ch, nbase)

      plant = ' '
      sign = '+'
      go to 8

      entry chvxi0 (number, ch, nbase)

      plant = '0'
      sign = ' '
8     if (nbase .lt. 2 .or. nbase .gt. 36)
     2          call abort ('Number base '//chival(nbase)//' invalid')
      if (number .lt. 0) then
        sign = '-'
      else if (number .eq. 0) then
        sign = ' '
      end if
      numb = iabs (number)
      now = len (ch)
      ch (now:now) = set(mod(numb,nbase))
      do while (numb .ge. nbase)
        if (now .eq. 1) goto 7
        now = now - 1
        numb = numb/nbase
        ch (now:now) = set(mod(numb,nbase))
      end do

c Put in sign if required

      if (sign .ne. ' ') then
        if (now .eq. 1) goto 7

c zero fill to column two of field

        do while (plant .eq. '0' .and. now .gt. 2)
          now = now - 1
          ch (now:now) = '0'
        end do
        now = now - 1
        ch (now:now) = sign
      end if

c Left fill with zero or blank characters

      do while (now .gt. 1)
        now = now - 1
        ch (now:now) = plant
      end do
      return

c Number overflows space available

7     call cfill (ch, '*')
      write (mesage, '(a,i3,a,i14)') 'Space allowed', len(ch),
     2         ' columns cannot accomodate', number
      call logit (mesage)
      return
      end
