      SUBROUTINE INSERTNUMsp(crep,nrep0,chars,maxchar)

C     INSERTNUM REPLACES A GIVEN CHARACTER WITH THE
C     CORRESPONDING NUMBER.

C     THIS VERSION ENTERS SPACES INSTEAD OF ZEROS
C     FOR PLACEHOLDERS

c***************************************************
c
c    Passed Variables:
c
c     crep - character to be replaced
c     nrep0 - number to replace character
c     chars - character string in which replacement will occur
c     maxchar - maximum number of characters in chars
c
c****************************************************

      character*1 crep
      character*4 cform
      character*(*) chars

      data cform /'(iX)'/

      inegative=0
      nrep=nrep0

      if ( nrep .lt. 0 ) then
       nrep=-nrep
       inegative=1
      endif

c****************************************************
c
c   Locate first occurance of character to be changed
c
c****************************************************

      do 50 nn=1,maxchar

       if ( chars(nn:nn) .eq. crep ) then

c****************************************************
c
c   Locate last occurance of character to be changed
c
c****************************************************

        do 51 n2=nn+1,maxchar
51       if ( chars(n2:n2) .ne. crep ) goto 52
52      n2=n2-1

        nchar=(n2-nn)+1
        nten=10**(nchar-inegative)

c******************************************************
c
c   Check that there is sufficient room to write given
c   number
c
c******************************************************

        if ( nten+inegative .le. nrep ) then
         write(6,800) 'Given number (',nrep0,
     * ') is larger than space to be',
     * ' written to'
800      format(a14,i3,a28,a11)
         return
        endif

c*****************************************************
c
c   Enter necessary trailing zeros
c
c****************************************************
        nadd=0
        do 60 n3=2,nchar-inegative
         nten=nten/10
         if ( nrep .lt. nten ) then
          chars(nn+nadd:nn+nadd)=' '
          nadd=nadd+1
         endif
60      continue

        if ( inegative .eq. 1 ) then
         chars(nn+nadd:nn+nadd)='-'
         nadd=nadd+1
        endif

c*****************************************************
c
c   Enter number
c
c*****************************************************

        write(cform(3:3),'(i1)') nchar-nadd
        write(chars(nn+nadd:nn+nchar-1),cform) nrep

        return

       endif

50    continue
       
      return
      end 
