mardi 29 décembre 2015

Reading and Printing random number in FORTRAN

**Dear All, I have a following program and below the program there is input data file, which is contain 10 lines of different data. I want to read these data randomly not sequentially, for example, it will may read number 3 line then may be number 5 line not like number 1 2 3 4...Then these numbers I want to print randomly...Kindly help me

Thank You **

 program rand
  implicit none
  integer::i, ok
  real(kind=8) , allocatable , dimension(:):: s
  integer, parameter:: nstep = 1, natom = 10
  integer:: seed, rand


  open(unit=2,file="fort.2",status="old",action="read")


  allocate(s(natom),stat=ok)
  if(ok/=0)then
  print*,"problem allocating position array"
  end if

  do i=1,natom
  read(2,*)s(i)
  print*,i=(rand(seed))
  end do
  end program rand



Input file 
   1.004624
   1.008447
   1.028897
   1.001287
  0.9994195
   1.036111
  0.9829285
   1.029622
   1.005867
  0.9372157




Aucun commentaire:

Enregistrer un commentaire