module M_intcat_jlg ! This file: http://ftp.aset.psu.edu/pub/ger/fortran/hdk/IntCat.f90 ! ! © 2006 James Giles as posted at comp.lang.fortran on 22 February 2006. implicit none public len_int, int_to_string, itoi, itoc, ctoi interface operator(//) module procedure itoi, itoc, ctoi end interface contains elemental function len_int(i) integer, intent(in) :: i integer :: len_int integer :: temp temp = abs(i) len_int = 0 do temp = temp/10 len_int=len_int+1 if(temp == 0) exit ! I'd sure like an UNTIL statement end do if(i < 0) len_int = len_int + 1 return end function len_int pure function itoi(i, j) integer, intent(in) :: i, j character(len_int(i)+len_int(j)) :: itoi itoi = int_to_string(i) // int_to_string(j) return end function itoi pure function ctoi(s, j) integer, intent(in) :: j character(*), intent(in) :: s character(len(s) + len_int(j)) :: ctoi ctoi = s // int_to_string(j) return end function ctoi pure function itoc(i, s) integer, intent(in) :: i character(*), intent(in) :: s character(len_int(i)+len(s)) :: itoc itoc = int_to_string(i) // s return end function itoc pure function int_to_string (i) integer,intent(in) :: i character(len_int(i)) :: int_to_string integer :: temp, d, n n = len(int_to_string) int_to_string = '' temp = abs(i) do d = mod(temp,10) + 1 int_to_string(n:n) = '0123456789'(d:d) temp = temp/10 n=n-1 if(temp == 0) exit ! I'd sure like an UNTIL statement end do if(i < 0) int_to_string(1:1) = '-' return end function int_to_string end module M_intcat_jlg program test_intcat use M_intcat_jlg implicit none integer :: n n=5 print *, "a" // n // 'b' print *, 5 // 6 end program test_intcat