Create a string from an integer
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | a | Integer value to convert |
||
character(len=*), | intent(in), | optional | :: | f | Format to use |
|
integer, | intent(in), | optional | :: | l | Final length of string |
Nodes of different colours represent the following:
Solid arrows point from a procedure to one which it calls. Dashed arrows point from an interface to procedures which implement that interface. This could include the module procedures in a generic interface or the implementation in a submodule of an interface in a parent module.
elemental function intToChar(a,f,l) result(o)
!! Create a string from an integer
integer,intent(in)::a
!! Integer value to convert
character(*),optional,intent(in)::f
!! Format to use
integer,optional,intent(in)::l
!! Final length of string
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
o = adjustl(o)
else
if(present(f)) then
write(buf,'('//f//')') a
else
write(buf,*) a
end if
o = trim(adjustl(buf))
end if
end function intToChar