0

For an academic paper, the authors have provided their code of their results and so I am trying to run their code. When I compile, there is an error which says that a function cannot be used as an argument. Here below I provide the relevant parts of the code that the error seem to point out (In particular the message is: "error 997 - An internal FUNCTION, such as FOC, cannot be used as an actual argument").

.........

 function foc(ain) implicit none real*8:: ain, foc foc = plterm+meru(ain,i)-upap(n,ain,i) end function foc 

...........

 yy1 = zbrent(foc,a(np-1),yexp,errrel) 

where zbrent is a subroutine called by the main program. If necessary I can attach the whole code.

FUNCTION zbrent (func,x1,x2,tol) implicit none real(8), external:: func real(8), intent(in):: x1,x2,tol END FUNCTION zbrent 

I am not familiar with Fortran or any programming and wondering whether someone can advice something.

5
  • What it says exactly? Copy here the important information so we don't have to guess. How is zbrent defined? Commented Jun 2, 2014 at 10:48
  • @VladimirF I have updated the post with the relevant information you asked. The error message says exactly what I have in the post: error 997 - An internal FUNCTION, such as FOC, cannot be used as an actual argument". Hope now is more clear, if not shall I post the whole code ? Commented Jun 2, 2014 at 13:59
  • OK, I missed the error message in your post. Commented Jun 2, 2014 at 14:09
  • I managed to fix bug by writting the module you suggested, however now when i execute the code this error shows up: Commented Jun 3, 2014 at 0:27
  • @VladimirF please see the screen shot in the original Commented Jun 3, 2014 at 0:33

1 Answer 1

2

The key is in the error message:

An internal FUNCTION, such as FOC, cannot be used as an actual argument 

Your function foc is apparently an internal function. It is placed after the word contains in the main program or in another procedure.

Internal procedures are prohibited to be a passed as argument in Fortran 2003 and earlier. Fortran 2008 relaxed this.

Place the function in a module and it will be OK. Also external one will work in this case, but I do not recommend it that much (that means just move foc outside of everything).

Or use a compiler that implements the Fortran 2008 rules for this (recent versions of gfortran should suffice).

Sign up to request clarification or add additional context in comments.

4 Comments

For someone one doesn't know programming, the solution of upgrading the compiler might be easiest.
Apologies for the confusion I commented in a different section. I fixed this particular bug, but now upon execution a new error shows up. I tried to provide a screen shot, but the site here does not allow me as i do not have the necessary reputation points. The error basically says the following :
Salford. Fortran. RuntimeException error 128: file does not exists and the details of this file. My confusion is that what the error says the file does not exists is a particular file that is created withing a subroutine of that the main program calls.
If it compiles now youhave a different error. Start a new question

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.