int2str0 Interface

public interface int2str0

Converts an integer variable into a string variable, filling with leading zeros up to the limit imposed by the user. Useful to open files named sequentially with leading zeros in the name.

Syntax

 t = int2str0(integ, total_length)

Where:

  • integ: Integer number to convert. This number MUST be positive.
  • format: Number of digits to use, including leading zeros. This number MUST be positive.

It returns a string containing the number.

Example

The following program a converts an integer to a number with leading zeros to create sequential filenames

 PROGRAM int2str0Example
    USE FU_Strings, ONLY: int2str0
    IMPLICIT NONE
    INTEGER :: i
    INTEGER :: total_length
    CHARACTER(LEN=:), ALLOCATABLE :: filename
    total_length = 5
    DO i = 1, 25
       filename = int2str0(i, total_length)//'.dat'
       WRITE(*,*) filename
    END DO
 END PROGRAM int2str0Example

Contents


Module Procedures

private pure function int2str0_i8(integ, total_length) result(str)

Arguments

Type IntentOptional Attributes Name
integer(kind=i8), intent(in) :: integ

Integer number to convert. This number MUST be positive.

integer(kind=i8), intent(in) :: total_length

Number of digits to use, including leading zeros. This number MUST be positive.

Return Value character(len=:), ALLOCATABLE

String containing the number.

private pure function int2str0_i16(integ, total_length) result(str)

Arguments

Type IntentOptional Attributes Name
integer(kind=i16), intent(in) :: integ

Integer number to convert. This number MUST be positive.

integer(kind=i16), intent(in) :: total_length

Number of digits to use, including leading zeros. This number MUST be positive.

Return Value character(len=:), ALLOCATABLE

String containing the number.

private pure function int2str0_i32(integ, total_length) result(str)

Arguments

Type IntentOptional Attributes Name
integer(kind=i32), intent(in) :: integ

Integer number to convert. This number MUST be positive.

integer(kind=i32), intent(in) :: total_length

Number of digits to use, including leading zeros. This number MUST be positive.

Return Value character(len=:), ALLOCATABLE

String containing the number.

private pure function int2str0_i64(integ, total_length) result(str)

Arguments

Type IntentOptional Attributes Name
integer(kind=i64), intent(in) :: integ

Integer number to convert. This number MUST be positive.

integer(kind=i64), intent(in) :: total_length

Number of digits to use, including leading zeros. This number MUST be positive.

Return Value character(len=:), ALLOCATABLE

String containing the number.