The function str_R8P converts real to string. This function achieves casting of real to string.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
logical, | intent(in), | optional | :: | no_sign | ||
real(kind=R8P), | intent(in) | :: | n |
elemental function str_R8P(no_sign,n) result(str)
!---------------------------------------------------------------------------------------------------------------------------------
!!The function str\_R8P converts real to string. This function achieves casting of real to string.
!---------------------------------------------------------------------------------------------------------------------------------
!---------------------------------------------------------------------------------------------------------------------------------
implicit none
logical, intent(IN), optional:: no_sign ! Flag for leaving out the sign.
real(R8P), intent(IN):: n ! Real to be converted.
character(DR8P):: str ! Returned string containing input number.
!---------------------------------------------------------------------------------------------------------------------------------
!---------------------------------------------------------------------------------------------------------------------------------
write(str,FR8P) n ! Casting of n to string.
if (n>0._R8P) str(1:1)='+' ! Prefixing plus if n>0.
if (present(no_sign)) str=str(2:) ! Leaving out the sign.
return
!---------------------------------------------------------------------------------------------------------------------------------
endfunction str_R8P