Here is the program that I ran into trouble. The problem occurs when I trying to call subroutine that generates a random matrix.
I just read the later post, and I will try that. Thank you.
program test
integer, parameter :: ikind_real = selected_real_kind(p=8 )
integer, parameter :: NP106 = 70695
real(kind = ikind_real) :: rcoeff_dist(NP106,28 )
call init_random_seed()
n=28
call r8_normal_mn(rcoeff_dist,NP106,n)
end program test
!========================================================================================================================================
!A subroutine to generate random variable from N(0,1)
!========================================================================================================================================
subroutine r8_normal_mn(X,m,n)
implicit none
integer, parameter :: ikind_real= selected_real_kind(p=8 )
integer :: m,n, i,j
real(kind = ikind_real), dimension(m,n) :: r1,r2
real, parameter :: r4_pi = 3.141592653589793E+00
real(kind = ikind_real), dimension(m,n) :: X
call psurand(r1,m,n)
call psurand(r2,m,n)
do i = 1,m
do j = 1,n
X(i,j) = sqrt ( - 2.0E+00 * log ( r1(i,j) ) ) * cos ( 2.0E+00 * r4_pi * r2(i,j) )
end do
end do
return
end subroutine r8_normal_mn
! ========================================================================================================================================
! A subroutine to generate random vector for uniform distribution
! ========================================================================================================================================
subroutine psurand(X,m,n)
implicit none
integer :: m,n
integer, parameter :: ikind_real = selected_real_kind(p=8 )
real(kind = ikind_real), dimension(m,n) :: X
CALL RANDOM_NUMBER(HARVEST = X)
END subroutine psurand
!========================================================================================================================================
! A subroutine to generate seed
!========================================================================================================================================
!We just need to regenerate the seed each time I am starting the program.
subroutine init_random_seed()
INTEGER :: i, n, clock
INTEGER, DIMENSION( : ), ALLOCATABLE :: seed
CALL RANDOM_SEED(size = n)
ALLOCATE(seed(n))
CALL SYSTEM_CLOCK(COUNT=clock)
seed = clock + 37 * (/ (i - 1, i = 1, n) /)
CALL RANDOM_SEED(PUT = seed)
DEALLOCATE(seed)
end