The function strz_I1P 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=I1P), | intent(in) | :: | n |
elemental function strz_I1P(nz_pad,n) result(str)
!---------------------------------------------------------------------------------------------------------------------------------
!!The function strz\_I1P 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(I1P), intent(IN):: n ! Integer to be converted.
character(DI1P):: str ! Returned string containing input number plus padding zeros.
!---------------------------------------------------------------------------------------------------------------------------------
!---------------------------------------------------------------------------------------------------------------------------------
write(str,FI1PZP) n ! Casting of n to string.
str=str(2:) ! Leaving out the sign.
if (present(nz_pad)) str=str(DI1P-nz_pad:DI1P-1) ! Leaving out the extra zeros padding
return
!---------------------------------------------------------------------------------------------------------------------------------
endfunction strz_I1P