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.
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.
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
Type | Intent | Optional | 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. |
String containing the number.
Type | Intent | Optional | 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. |
String containing the number.
Type | Intent | Optional | 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. |
String containing the number.
Type | Intent | Optional | 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. |
String containing the number.