Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling a function

Status
Not open for further replies.

Zemm

Technical User
Apr 22, 2006
6
US
I am using Salford's Fortran 95 in DOS.

This program is intended to find coordinates on a 15 x 15 grid. Eventually, it will have a subroutine in addition to the function I have written. For now, I am trying to pass two variables to the function. The error from the compiler's error message is "statement not recognized" and is at the line where the function, Jill, is called.

The code:

PROGRAM Grid
!-------------------------------------------------------------------------------------------------
! This program provides a way to move about grid map of !coordinates, and
! assesses the more efficient of two methods.
!--------------------------------------------------------------------------
IMPLICIT NONE
INTEGER :: UL, LL, J
DOUBLE PRECISION :: X, Y
INTEGER :: RandX, RandY
UL = 15
LL = 1

X = 0.0
Y = 0.0
RandX = 0
RandY = 0

DO J = 1, 15
call random_seed
call random_number(X)
call random_number(Y)

Jill(X, Y, RandX, RandY)

WRITE (*,*) "The ", J, "th iteration "

END DO

CONTAINS

FUNCTION Jill(X, Y, RandX, RandY)
IMPLICIT NONE
DOUBLE PRECISION :: Jill

DOUBLE PRECISION, INTENT(IN) :: X, Y
INTEGER, INTENT(OUT) :: RandX, RandY
INTEGER :: LL, UL

Jill = 1.0
LL = 1
UL = 15

WRITE (*, '(1X, A)', ADVANCE = "NO") "X = ", X, " Y = ", Y
RandX = INT(X*(UL-LL+1)) + LL
RandY = INT(Y*(UL-LL+1)) + LL
WRITE (*, '(1X, A)', ADVANCE = "NO") "RandX = ", RandX, " RandY = ", RandY
END FUNCTION
END PROGRAM Grid

Why won't this compile? Thanks!
 
Jill should be a subroutine: not a function.
Call it using the call statement ie. call Jill ...

At a guess you've come from a different language where everything is a function. In Fortran, a void function is a subroutine and it has to be invoked with a call statement. A function needs to return a value by assigning that value to the name of the function.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top