The function strz_I2P converts integer to string, prefixing with the right number of zeros. This function achieves casting of integer to string.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=I4P), | intent(in), | optional | :: | nz_pad | ||
integer(kind=I2P), | intent(in) | :: | n |
elemental function strz_I2P(nz_pad,n) result(str)
!---------------------------------------------------------------------------------------------------------------------------------
!!The function strz\_I2P converts integer to string, prefixing with the right number of zeros. This function achieves casting of
!!integer to string.
!---------------------------------------------------------------------------------------------------------------------------------
!---------------------------------------------------------------------------------------------------------------------------------
implicit none
integer(I4P), intent(IN), optional:: nz_pad ! Number of zeros padding.
integer(I2P), intent(IN):: n ! Integer to be converted.
character(DI2P):: str ! Returned string containing input number plus padding zeros.
!---------------------------------------------------------------------------------------------------------------------------------
!---------------------------------------------------------------------------------------------------------------------------------
write(str,FI2PZP) n ! Casting of n to string.
str=str(2:) ! Leaving out the sign.
if (present(nz_pad)) str=str(DI2P-nz_pad:DI2P-1) ! Leaving out the extra zeros padding
return
!---------------------------------------------------------------------------------------------------------------------------------
endfunction strz_I2P