      program main
      implicit none
      real*8, allocatable :: r(:), theta(:), phi(:), x(:), y(:), z(:)
      real*8 time
      integer*8 time0, time1, dtime
      integer i, j, n, m
c
      n = 10000
      m = 1000

c Initialization
      allocate(r(n), theta(n), phi(n), x(n), y(n), z(n))
      do i=1,n
        r(i) = rand()
        theta(i) = rand()
        phi(i) = rand()
      end do

c Start time
      call system_clock(time0)

c Main calculation
      do j=1,m
        do i=1,n
c
          x(i) = r(i) * cos(theta(i)) * cos(phi(i))
          y(i) = r(i) * cos(theta(i)) * sin(phi(i))
          z(i) = r(i) * sin(theta(i))
        end do
      end do

c Finish time
      call system_clock(time1, dtime)

c Output time
      time = 1d0*(time1-time0)/dtime
      write(*,"(a7,f16.7)")"Time = ",time

      deallocate(r, theta, phi, x, y, z)
      end program
