- #1
autobot.d
- 68
- 0
Hi all,
So I have a program that calls a module that contains a subroutine so I can make a matrix.
When I write the matrix in the subroutine (commented out part in module) I get the right output, but when the main program tries to output it is some insanely small or large numbers.
I am new to Fortran (not coding) so any help/criticism would be greatly appreciated! Definitely a bit of a learning curve but I am excited to learn fortran.
So I have a program that calls a module that contains a subroutine so I can make a matrix.
When I write the matrix in the subroutine (commented out part in module) I get the right output, but when the main program tries to output it is some insanely small or large numbers.
I am new to Fortran (not coding) so any help/criticism would be greatly appreciated! Definitely a bit of a learning curve but I am excited to learn fortran.
Code:
program test
use test_mod
implicit none
integer :: k
real, allocatable, Dimension(:,:) :: test_mat
write(*,*) 'Dimension for square test matrix: '
read (*,*) k
allocate(test_mat(k,k))
call test_matrix(k)
!This gives bad output, but right dimensions
write(*,*) test_mat
deallocate(test_mat)
end program test
Code:
module test_mod
implicit none
contains
subroutine test_matrix(k)
integer :: k
real, dimension(:,:), allocatable :: test_mat
INTEGER :: i,j,m,nallocate(test_mat(k,k))
do i = 1,k
do j = 1,k
test_mat(i,j) = 1.d0*((i+j-1))
end do
end do
!This loop gives correct output
!do m = 1,k
!write(*,*)(test_mat(m,n), n=1,k)
!end do
deallocate(test_mat)
end subroutine test_matrix
end module test_mod