Search code examples
fortranphysicsfortran77fortran95

Meaning of this statement in Fortran


I was looking at some code in the tinker molecular dynamics package from ponder lab: http://dasher.wustl.edu/tinker/.

And I saw this statement in one of the files alchemy.f:

    program alchemy
     ...
     ...
     some statements here and there
     ...
     ...
     integer ixyz
     integer freeunit
     ...

then later on there is this puzzling statement

    ixyz = freeunit ()

   ...

Since both variables are scallars of the type integer I'm not sure what the parenthesis means.

Thanks,


Solution

  • The statement

    integer freeunit
    

    may, especially in old code, not declare a scalar integer variable but a function that returns an integer. Typically then the function would be defined in another compilation unit and its declaration in the program provides enough for the linker to do its work.

    If this is the case then

    ixyz = freeunit ()
    

    would be construed as a call to that function with no arguments.

    Scour your source files for a line containing

    integer function freeunit 
    

    Note that I'm making educated guesses here, I never follow links away from the safety of SO. I'll go further and hazard a guess that the function freeunit returns an i/o unit number which is not already in use.