Converts an integer or real variable into a string variable. Useful to open files named sequentially.
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.
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
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=i8), | intent(in) | :: | num |
Number to convert to string. |
String containing the number
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=i16), | intent(in) | :: | num |
Number to convert to string. |
String containing the number
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=i32), | intent(in) | :: | num |
Number to convert to string. |
String containing the number
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=i64), | intent(in) | :: | num |
Number to convert to string. |
String containing the number
Type | Intent | Optional | 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. |
String containing the number
Type | Intent | Optional | 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. |
String containing the number
Type | Intent | Optional | 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. |
String containing the number