str2num Interface

public interface str2num

Converts a string into an integer or real number as specified by the type of variable mold.

Syntax

 t = str2num(str, mold)

Where:

  • str: String to convert to number
  • mold: Real or integer value to identify the type and kind of the output. It is only used to set the type of the return value, so it can be any value.

It returns an integer or real with the number contained in the string.

Example

The following program converts a string to a real number

 PROGRAM str2numExample
    USE FU_Strings, ONLY: str2num
    IMPLICIT NONE
    REAL :: f
    CHARACTER(LEN=:), ALLOCATABLE :: s
    s = '293.75'
    f = str2num(s, f)
    WRITE(*,*) f
 END PROGRAM str2numExample

Contents


Module Procedures

private elemental function str2num_i8(str, mold) result(res)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: str

String to convert to number.

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

Real or integer value to identify the type and kind of the output. It is only used to set the type of the return value, so it can be any value.

Return Value integer(kind=i8)

The number of the input string.

private elemental function str2num_i16(str, mold) result(res)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: str

String to convert to number.

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

Real or integer value to identify the type and kind of the output. It is only used to set the type of the return value, so it can be any value.

Return Value integer(kind=i16)

The number of the input string.

private elemental function str2num_i32(str, mold) result(res)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: str

String to convert to number.

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

Real or integer value to identify the type and kind of the output. It is only used to set the type of the return value, so it can be any value.

Return Value integer(kind=i32)

The number of the input string.

private elemental function str2num_i64(str, mold) result(res)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: str

String to convert to number.

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

Real or integer value to identify the type and kind of the output. It is only used to set the type of the return value, so it can be any value.

Return Value integer(kind=i64)

The number of the input string.

private elemental function str2num_sp(str, mold) result(res)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: str

String to convert to number.

real(kind=sp), intent(in) :: mold

Real or integer value to identify the type and kind of the output. It is only used to set the type of the return value, so it can be any value.

Return Value real(kind=sp)

The number of the input string.

private elemental function str2num_dp(str, mold) result(res)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: str

String to convert to number.

real(kind=dp), intent(in) :: mold

Real or integer value to identify the type and kind of the output. It is only used to set the type of the return value, so it can be any value.

Return Value real(kind=dp)

The number of the input string.

private elemental function str2num_qp(str, mold) result(res)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: str

String to convert to number.

real(kind=qp), intent(in) :: mold

Real or integer value to identify the type and kind of the output. It is only used to set the type of the return value, so it can be any value.

Return Value real(kind=qp)

The number of the input string.