Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Thank you all for your help. Here's the code I wrote which should work similar to <code>num2str()</code> in MATLAB. It has additional functionality to show arrays and matrices as well.</p> <pre><code>module module_common_functions !GLOBAL FUNCTIONS public :: num2str interface num2str module procedure num2str_int module procedure num2str_real module procedure num2str_array module procedure num2str_matrix end interface contains function num2str_int(number) implicit none integer,intent(in)::number character(len=10)::num2str_int character(len=10):: tmp write(tmp,'(I6)')number num2str_int=trim(adjustl(tmp)) return end function function num2str_real(number) implicit none real,intent(in)::number character(len=32):: tmp ! Deferred length allocatable character result. character(len=:), allocatable ::num2str_real ! Format specifier changed to use full length. write(tmp,'(F32.4)')number ! Reallocation on assignment means length of result will ! be set to match length of right hand side expression. ! Note ordering of trim and adjustl. num2str_real=trim(adjustl(tmp)) end function function num2str_array(number,col) implicit none integer::i,col real, dimension(col)::number character(len=32):: tmp character(len=33*col)::num2str_array num2str_array ='' do i=1,col write(tmp,'(F12.4)') number(i) num2str_array = trim(num2str_array)//adjustl(trim(tmp))//',' end do return end function function num2str_matrix(number,row,col) implicit none integer::i,j,row,col real,dimension(row,col)::number character(len=32):: tmp character(len=33*row*col)::num2str_matrix num2str_matrix='' do i=1,row do j=1,col write(tmp,'(F12.4)') number(i,j) num2str_matrix= trim(num2str_matrix)//adjustl(trim(tmp))//',' end do end do return end function end module </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload