Advertisement
Guest User

Untitled

a guest
Jun 21st, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. program check_sum
  2.     implicit none
  3.     integer, parameter :: nmol = 2, ndp = 2, npt = 50000
  4.     real, dimension(npt+ndp,nmol) :: rd
  5.     real, dimension(npt) :: y
  6.     real :: c
  7.     integer :: i, j
  8.  
  9.     call init_random_seed()
  10.     call random_number(c)
  11.     call random_number(rd)
  12.  
  13.     do i=1, npt
  14.         y(i) = c*sum(rd(i+ndp,1:nmol))
  15.     end do
  16.  
  17.     print *, y(10:15)
  18.  
  19.     y = 0d0
  20.     do j=1,nmol
  21.         do i=1, npt
  22.             y(i) = y(i) + c*rd(i+ndp,j)
  23.         end do
  24.     end do
  25.  
  26.     print *, y(10:15)
  27. contains
  28.     subroutine init_random_seed()
  29.         integer :: i, n, clock
  30.         integer, dimension(:), allocatable :: seed
  31.  
  32.         call random_seed(size = n)
  33.         allocate(seed(n))
  34.  
  35.         call system_clock(count=clock)
  36.  
  37.         seed = clock + 37 * (/ (i-1, i=1, n) /)
  38.         call random_seed(put = seed)
  39.  
  40.         deallocate(seed)
  41.     end subroutine init_random_seed
  42. end program check_sum
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement