num2str Interface

public interface num2str

Converts an integer or real variable into a string variable. Useful to open files named sequentially.

Syntax

 t = num2str(num, format)

Where:

  • num: Real or Integer to convert to a string.
  • format: Format to use in the string variable. Only for real numbers.

It returns a string containing the number.

Example

The following program a converts an integer and a real to a string, using them to create a filename:

 PROGRAM num2strExample
    USE FU_Strings, ONLY: num2str
    IMPLICIT NONE
    REAL :: temperature
    INTEGER :: case_number
    CHARACTER(LEN=:), ALLOCATABLE :: filename
    temperature = 293.75
    case_number = 17
    filename = 'Case_'//num2str(case_number)// &
       '_Temp_'//num2str(temperature, "F4.0")//'txt'
    WRITE(*,*) filename
 END PROGRAM num2strExample

Contents


Module Procedures

private pure function num2str_i8(num) result(str)

Arguments

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

Number to convert to string.

Return Value character(len=:), ALLOCATABLE

String containing the number

private pure function num2str_i16(num) result(str)

Arguments

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

Number to convert to string.

Return Value character(len=:), ALLOCATABLE

String containing the number

private pure function num2str_i32(num) result(str)

Arguments

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

Number to convert to string.

Return Value character(len=:), ALLOCATABLE

String containing the number

private pure function num2str_i64(num) result(str)

Arguments

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

Number to convert to string.

Return Value character(len=:), ALLOCATABLE

String containing the number

private pure function num2str_sp(num, formato) result(str)

Arguments

Type IntentOptional Attributes Name
real(kind=sp), intent(in) :: num

Number to convert to string.

character(len=*), intent(in) :: formato

Format to use in the string variable. Only for real numbers.

Return Value character(len=:), ALLOCATABLE

String containing the number

private pure function num2str_dp(num, formato) result(str)

Arguments

Type IntentOptional Attributes Name
real(kind=dp), intent(in) :: num

Number to convert to string.

character(len=*), intent(in) :: formato

Format to use in the string variable. Only for real numbers.

Return Value character(len=:), ALLOCATABLE

String containing the number

private pure function num2str_qp(num, formato) result(str)

Arguments

Type IntentOptional Attributes Name
real(kind=qp), intent(in) :: num

Number to convert to string.

character(len=*), intent(in) :: formato

Format to use in the string variable. Only for real numbers.

Return Value character(len=:), ALLOCATABLE

String containing the number