Why Does My Fortran 95 Program Show Random_seed(): PUT Array Too Small?

  • Context: Fortran 
  • Thread starter Thread starter Apollion
  • Start date Start date
  • Tags Tags
    Fortran
Click For Summary

Discussion Overview

The discussion revolves around a Fortran 95 program that generates random numbers using a Gaussian distribution. The main issue raised is an error message stating "Random_seed(): PUT array too small," which occurs during the execution of the program. Participants are exploring the cause of this error and discussing potential issues in the code related to the seed subroutine and the random number generation process.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant describes their code and the error encountered, specifically pointing to the line where the seed is set and the call to random_seed.
  • Another participant questions the logic of adding a scalar to a vector in the seed assignment, suggesting that it may be causing the issue.
  • A different participant points out that "secnds" is not a recognized Fortran function and asks for clarification on its definition.
  • There is a mention of a potential error in the main program regarding a comma in the write statement, which may not affect the execution but could lead to confusion.
  • Some participants assert that adding a scalar to a vector is legal in Fortran, countering the earlier claim about the addition being problematic.

Areas of Agreement / Disagreement

Participants express differing views on the legality of adding a scalar to a vector in Fortran, with some asserting it is valid while others suggest it may not be appropriate in this context. The discussion remains unresolved regarding the exact cause of the "PUT array too small" error, as multiple potential issues are identified without consensus on the primary source.

Contextual Notes

Participants note that the definition of "secnds" is missing, which could lead to compilation issues. Additionally, there are unresolved questions about the proper handling of the seed array and its dimensions in relation to the random_seed function.

Apollion
Messages
1
Reaction score
0
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:
Technology news on Phys.org
Please put [noparse]
Code:
 and
[/noparse] tags around your code. I have done that for you.
Apollion said:
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:
Code:
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 :
Code:
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:

Code:
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! :)

What are you trying to do with this code:
Code:
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.
 
Apollion said:
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
</QUOTE>

Are you sure? There appear to be at least two errors in it.
It is necessary to get a clean compilation before attempting to execute
the program.
1. "secnds" is not a known Fortran name. Nor it it defined. What is it?
2. The statement:
write(299,*),angle
in the main program has a useless comma in it.

To get useful advice, you need to post ALL and EVERY error message(s).

<quote>
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
</quote>
 
Mark44 said:
What are you trying to do with this code:
Code:
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.

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.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 11 ·
Replies
11
Views
2K
  • · Replies 25 ·
Replies
25
Views
9K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 13 ·
Replies
13
Views
4K