Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29285 Discussions

error:the call statement is making a function subprogram as a subroutine

andibrains
Beginner
1,360 Views
im new to fortran and im trying to write a test driver program which uses a sub routine norm_rand_number(X) which will return a variable X. The subroutine performs a polar transform using two uniform random numbers U1 AND U2. The code is included, everytime i try to compile i get this subprogram error msg

PROGRAM TEST_normrand
!
!PURPOSE
!PROGRAM TO TEST SUBROUTINE normrand
!
IMPLICIT NONE

!DECLARE LOCAL VARIABLES
REAL::norm_rand_number
REAL::X


!CALL norm_rand
CALL norm_rand_number(X)

!WRITE RANDOM NUMBERS
WRITE(*,100) 'norm_rand=',X
100 FORMAT (1X,A,F8.5)

END PROGRAM



SUBROUTINE norm_rand_number(X)

!PURPOSE:
!TO PRODUCE A NORMALLY DISTRIBUTED RANDOM NUMBER WITH A MEAN OF ZERO AND VARIANCE OF ONE

IMPLICIT NONE
REAL, INTENT(OUT) ::X

REAL::U1,U2,V1,V2,S,Y
!PERFORM POLAR TRANSFORM
DO
CALL SEED(1984)
CALL RANDOM_NUMBER(U1)
CALL SEED(1789)
CALL RANDOM_NUMBER(U2)

V1=(2.0*U1)-1.0
V2=(2.0*U2)-1.0
S=V1**2+V2**2
IF(S>0.0.AND.S<1.0)EXIT
END DO

X=SQRT(-2.0*LOG(S)/S)
Y=SQRT(-2.0*LOG(S)/S)
X=V1*X
Y=V2*X

END SUBROUTINE
0 Kudos
2 Replies
Steven_L_Intel1
Employee
1,360 Views
Remove this line:

REAL::norm_rand_number

It effectively declares norm_rand_number as a function, but it's not allowed to call a function as if it were a subroutine.

I also question the code in norm_rand_number. You are calling the Fortran intrinsic RANDOM_NUMBER which is fine, but then calling some routine SEED which is not specified. What does SEED do? If you were intending to call the intrinsic RANDOM_SEED, the call is wrong. (It also looks as if you might be trying to force the same random numbers for each call???)

If you wish to "randomize" the start of the random number sequence, simply call RANDOM_SEED with no arguments at the start of the program.
0 Kudos
andibrains
Beginner
1,360 Views
Remove this line:

REAL::norm_rand_number

It effectively declares norm_rand_number as a function, but it's not allowed to call a function as if it were a subroutine.

I also question the code in norm_rand_number. You are calling the Fortran intrinsic RANDOM_NUMBER which is fine, but then calling some routine SEED which is not specified. What does SEED do? If you were intending to call the intrinsic RANDOM_SEED, the call is wrong. (It also looks as if you might be trying to force the same random numbers for each call???)

If you wish to "randomize" the start of the random number sequence, simply call RANDOM_SEED with no arguments at the start of the program.

man one line? i spent two hours trying to figure this out!! it works fine now and i modified the seed value as suggested thanks!
0 Kudos
Reply