LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Gfortran: attribute that requires explicit interface ??? (https://www.linuxquestions.org/questions/linux-newbie-8/gfortran-attribute-that-requires-explicit-interface-4175531890/)

AlexBB 01-22-2015 07:56 PM

Gfortran: attribute that requires explicit interface ???
 
Hi there,

Trying to compile a few Gfortran lines in Ubuntu 12.04 I get this error:

Quote:

lun = newunit(unit)
1
Error: Dummy argument 'unit' of procedure 'newunit' at (1) has an attribute that requires an explicit interface for this procedure
The number one in fact points to the word "unit" not "lun" in the terminal. It got left-shifted when posted.

The code itself:

Code:

program main
  INTEGER*4 counter,lun,unit
  REAL*8, parameter :: pi = 3.141592653589793
  unit = 10
  lun = newunit(unit)
  ................... 
end program main

What does it all mean and how shall I change the code to compile it without an error?

Thanks, - A.

btmiller 01-22-2015 08:30 PM

What is the definition of the newunit function? Is it even defined anywhere?

AlexBB 01-23-2015 08:37 AM

It is not an intrinsic function but is based on an intrinsic function INQUIRE. So, there is a code in the program for that. I copied it from here.

AlexBB 01-24-2015 10:35 AM

Well, it wanted an interface for this function. In turn an interface needs to be in a module and the module has to be in a separate file too. Otherwise nothing works.

Code:

module sph_persp_mod
  INTERFACE
    integer function newunit(unit1)
      integer, intent(out), optional :: unit1
    end function newunit
  END INTERFACE
end module

The meaning of all this still eludes me. Whatever works!!!

btmiller 01-25-2015 12:50 PM

It's just one of the rules of Fortran syntax ... modules should be in their own files.


All times are GMT -5. The time now is 02:17 AM.