Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
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 |
Convert an integer to a character
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
character(len=128), | public | :: | buf |
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