strz_I2P Function

private elemental function strz_I2P(n, nz_pad) result(str)

Convert integer to string, prefixing with the right number of zeros.

 use penf
 print "(A)", strz(n=1_I2P)
 use penf
 print "(A)", strz(n=1_I2P, nz_pad=3)

Arguments

Type IntentOptional Attributes Name
integer(kind=I2P), intent(in) :: n

Integer to be converted.

integer(kind=I4P), intent(in), optional :: nz_pad

Number of zeros padding.

Return Value character(len=DI2P)

Returned string containing input number plus padding zeros.


Called by

proc~~strz_i2p~~CalledByGraph proc~strz_i2p strz_I2P interface~strz strz interface~strz->proc~strz_i2p program~volatile_doctest~111 volatile_doctest program~volatile_doctest~111->interface~strz program~volatile_doctest~137 volatile_doctest program~volatile_doctest~137->interface~strz program~volatile_doctest~143 volatile_doctest program~volatile_doctest~143->interface~strz program~volatile_doctest~177 volatile_doctest program~volatile_doctest~177->interface~strz program~volatile_doctest~45 volatile_doctest program~volatile_doctest~45->interface~strz program~volatile_doctest~51 volatile_doctest program~volatile_doctest~51->interface~strz program~volatile_doctest~55 volatile_doctest program~volatile_doctest~55->interface~strz program~volatile_doctest~59 volatile_doctest program~volatile_doctest~59->interface~strz

Source Code

   elemental function strz_I2P(n, nz_pad) result(str)
   !< Convert integer to string, prefixing with the right number of zeros.
   !<
   !<```fortran
   !< use penf
   !< print "(A)", strz(n=1_I2P)
   !<```
   !=> 00001 <<<
   !<
   !<```fortran
   !< use penf
   !< print "(A)", strz(n=1_I2P, nz_pad=3)
   !<```
   !=> 001 <<<
   integer(I2P), intent(in)           :: n      !< Integer to be converted.
   integer(I4P), intent(in), optional :: nz_pad !< Number of zeros padding.
   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
   endfunction strz_I2P