Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Fortran 95 random_seed() -help

  1. Nov 11, 2011 #1
    Hello everone!So i am writing this code where I am producoing random numbers from a generator through a subroutine.Then I call the subroutine and pass them through a Gaussian distribution.I have problem with my seed subroutine: my program compiles but when i try to execute it complain that "Random_seed(): PUT array too small" i have no idea what does this means!

    Here is my subroutine:
    subroutine setSEED (seed)
    implicit none

    real*8:: x
    integer, dimension(2), intent(inout):: seed
    if (seed(1) == 0.0) &
    this where
    it complains --> seed = floor(1000*secnds(0.0)) +(/0, 37 /)
    --> call random_seed(put=seed)

    end subroutine setSEED

    and my gaussian distribution :

    Real*8 Function gasdev(idum)
    implicit none
    integer, intent(inout) :: idum
    integer, save::iset
    real*8:: fac,rsq,v1,v2
    real*8, dimension(2) :: x
    real*8, save :: gset
    !data iset/0/
    if (idum.lt.0) iset=0
    if (iset.eq.0) then
    rsq = 0.0
    do while (rsq > 1.0.or.rsq==0)
    call random_number(x)
    v1=2.*x(1)-1
    v2=2.*x(2)-1
    rsq=v1**2+v2**2

    end do

    fac=sqrt(-2.*log(rsq)/rsq)
    gset=v1*fac
    gasdev=v2*fac
    iset=1
    else
    gasdev=gset
    iset=0
    endif

    return

    end Function gasdev

    ....AND MY MAIN PROGRAM:

    program mainprog

    implicit none

    real*8::angle,gasdev,number
    integer::i
    integer, dimension(2) :: seed = 0

    open(299,FILE='gauss.dat',STATUS='REPLACE')

    call setSEED(seed)

    Do i=1,10,1


    angle=gasdev(seed)
    print*,"angle=gasdev =",angle
    write(299,*),angle


    end do

    close(299,STATUS="KEEP")
    end program mainprog


    Do you guys think can help me?its so frustrating!!!thank you all!!! :)
     
    Last edited: Nov 11, 2011
  2. jcsd
  3. Nov 14, 2011 #2

    Mark44

    Staff: Mentor

    Please put [noparse]
    Code (Text):
     and
    [/noparse] tags around your code. I have done that for you.
    What are you trying to do with this code:
    Code (Text):
    seed = floor(1000*secnds(0.0)) +(/0, 37 /)  
    call random_seed(put=seed)
    In the first line, floor returns a single value, so it looks like you are trying to add a scalar to a vector - you can't do that.
     
  4. Mar 15, 2012 #3
     
  5. Mar 15, 2012 #4
    It's perfectly legal to add a scalar to a vector.
    Thus,
    seed = 5 + (/ 0, 37 /)
    is OK too.
    The problem with the line is that "secnds" has not been defined.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Fortran 95 random_seed() -help
  1. Fortran 95 (Replies: 12)

Loading...