Convert an integer to a string.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | i |
the integer |
||
logical, | intent(in), | optional | :: | with_sign |
also include the sign (default is False) |
integer converted to a string
function integer_to_string(i, with_sign) result(str) implicit none integer,intent(in) :: i !! the integer logical,intent(in),optional :: with_sign !! also include the sign (default is False) character(len=:),allocatable :: str !! integer converted to a string integer :: istat !! `iostat` code for write statement character(len=100) :: tmp !! logical :: sgn !! local copy of `with_sign` if (present(with_sign)) then sgn = with_sign else sgn = .false. end if if (sgn) then write(tmp,'(SP,I100)',iostat=istat) i else write(tmp,'(I100)',iostat=istat) i end if if (istat == 0) then str = trim(adjustl(tmp)) else str = '****' end if end function integer_to_string