The function str_R4P 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=R4P), | intent(in) | :: | n |
elemental function str_R4P(no_sign,n) result(str)
!---------------------------------------------------------------------------------------------------------------------------------
!!The function str\_R4P 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(R4P), intent(IN):: n ! Real to be converted.
character(DR4P):: str ! Returned string containing input number.
!---------------------------------------------------------------------------------------------------------------------------------
!---------------------------------------------------------------------------------------------------------------------------------
write(str,FR4P) n ! Casting of n to string.
if (n>0._R4P) str(1:1)='+' ! Prefixing plus if n>0.
if (present(no_sign)) str=str(2:) ! Leaving out the sign.
return
!---------------------------------------------------------------------------------------------------------------------------------
endfunction str_R4P