      subroutine NumberToChar(numitis,numchar,acharitis)
      implicit none
!Convert the number numitis to a character whose units are the digits in numitis 
!and whose length is numchar. if the number of digits in numitis is less than 
!numchar, pad with 0 in the front, e.g. 1 -> 001 and 23 -> 023 if numchar=3
      integer numitis,numchar
      character acharitis*(*)
      character*1 onechar(numchar)
      integer n,i,j,k(numchar)
      n=numitis
      i=0
10    i=i+1
      k(i)=mod(n,10)
      n=(n-k(i))/10
      if(n.ne.0)goto 10
      if(i.lt.numchar)then
        do j=i+1,numchar
          k(j)=0
        enddo
      endif
      do j=1,numchar
        acharitis(numchar-j+1:numchar-j+1)=char(k(j)+48)
      enddo
      n=len(acharitis)
      do j=numchar+1,n
         acharitis(j:j)=''
      enddo
      acharitis=trim(acharitis)
      return
      end subroutine NumberToChar
