fortran int to string

To convert an integer to a string in Fortran, you can use the intrinsic function itoa or the write statement. Here are examples of both methods:

Using itoa function:

program int_to_string
   implicit none
   integer :: num
   character(10) :: str

   num = 12345
   str = itoa(num)
   print *, str

end program int_to_string

Using write statement:

program int_to_string
   implicit none
   integer :: num
   character(10) :: str

   num = 12345
   write(str, '(I10)') num
   print *, str

end program int_to_string

In both cases, the integer value 12345 is converted to a string and stored in the variable str. The resulting string is then printed to the console. You can adjust the format specifier (I10) in the write statement to control the width and formatting of the resulting string.

These methods allow you to convert an integer to a string in Fortran without using any external libraries or functions.