int2char Function

public elementalfunction int2char(a, f, l) result(o)

Arguments

Type IntentOptional AttributesName
integer, intent(in) :: a

Integer value to convert

character(len=*), intent(in), optional :: f

Format of result

integer, intent(in), optional :: l

Length of result

Return Value character(len=:), allocatable

Description

Convert an integer to a character


Variables

TypeVisibility AttributesNameInitial
character(len=128), public :: buf

Source Code

	elemental function int2char(a,f,l) result(o)
		!! Convert an integer to a character
		integer,intent(in)::a
			!! Integer value to convert
		character(*),optional,intent(in)::f
			!! Format of result
		integer,optional,intent(in)::l
			!! Length of result
		character(:),allocatable::o
		
		character(128)::buf
		
		if(present(l)) then
			allocate(character(l)::o)
			if(present(f)) then
				write(o,'('//f//')') a
			else
				write(o,*) a
			end if
		else
			if(present(f)) then
				write(buf,'('//f//')') a
			else
				write(buf,*) a
			end if
			o = trim(adjustl(buf))
		end if
	end function int2char