subroutine int_to_char(n,g) c Routine for converting the integer "n" to a character c string "g" of length "ilength," which is useful for c writing file numbers in time dependent computations, etc.. c You can change the length of the string simply by changing c the value of ilength to the desired length as well as c changing the length of the character string in the declaration c to the same size. integer n,lev,i,ich,npart,int,ilength real*8 x c Change the "5" in the following two lines to whatever length to c use longer character strings (i.e. higher numbers). character*5 g ilength=5 x=log10(1.0*n) if(x.ge.ilength) then print*,'Integer size too large in int_to_char:' print*,'Modify character length in subroutine' stop endif npart=0 do i=ilength,1,-1 j=ilength-i+1 lev=10**(i-1) int=0 ich=n-npart if(ich.ge.0.and.ich.lt.1*lev) then g(j:j)='0' int=0 elseif(ich.ge.1*lev.and.ich.lt.2*lev) then g(j:j)='1' int=1*lev elseif(ich.ge.2*lev.and.ich.lt.3*lev) then g(j:j)='2' int=2*lev elseif(ich.ge.3*lev.and.ich.lt.4*lev) then g(j:j)='3' int=3*lev elseif(ich.ge.4*lev.and.ich.lt.5*lev) then g(j:j)='4' int=4*lev elseif(ich.ge.5*lev.and.ich.lt.6*lev) then g(j:j)='5' int=5*lev elseif(ich.ge.6*lev.and.ich.lt.7*lev) then g(j:j)='6' int=6*lev elseif(ich.ge.7*lev.and.ich.lt.8*lev) then g(j:j)='7' int=7*lev elseif(ich.ge.8*lev.and.ich.lt.9*lev) then g(j:j)='8' int=8*lev elseif(ich.ge.9*lev.and.ich.lt.10*lev) then g(j:j)='9' int=9*lev else print*,'problem in int_to_char i=',i stop endif npart=npart+int enddo return end