vecrand.f90 889 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. program vecrand
  2. ! vecrand.f90
  3. ! This file creates two random vectors and stores them in the file vecrand.dat
  4. !
  5. !
  6. implicit none
  7. integer n,i,j,a,b,init(4)
  8. real(kind=8),allocatable,dimension(:) ::x,y
  9. integer*4,dimension(3) ::timearray
  10. real ::rand
  11. call itime(timearray) ! Get the current time
  12. i = rand ( timearray(1)+timearray(2)+timearray(3) )
  13. open(unit=20,file='inputfile.dat',status='old')
  14. read(20,*)init
  15. n=init(1)
  16. a=1
  17. b=0
  18. do while(a.ge.b)
  19. print*,'Enter the interval limits : '
  20. read*,a,b
  21. if (a.ge.b) then
  22. print*,'Choose a<b'
  23. endif
  24. end do
  25. allocate(x(n),y(n))
  26. do i=1,n
  27. x(i)=rand(0)*dble(b-a)-dble(b);
  28. y(i)=rand(0)*dble(b-a)-dble(b);
  29. enddo
  30. open(unit=10,file='vecrand.dat',status='unknown')
  31. do i=1,n
  32. write(unit=10,FMT=*) x(i),y(i)
  33. enddo
  34. close(10)
  35. deallocate(x,y)
  36. end program vecrand