Question about use and host association

From: Paul Van Delst (paul.vandelst_at_noaa.gov)
Date: 06/24/04


Date: Thu, 24 Jun 2004 13:43:44 -0400

Hello,

Let's say I have a module that defines a data structure:

MODULE mytype_define
   IMPLICIT NONE
   PRIVATE
   TYPE, PUBLIC :: mytype
     INTEGER :: i
     REAL :: x
     ...various other stuff...
   END TYPE mytype
END MODULE mytype_define

I then have another module that does I/O for the structure:

MODULE mytype_io
   USE mytype_define
   IMPLICIT NONE
   PRIVATE
   PUBLIC :: mytype_Write
   PUBLIC :: mytype_Read
CONTAINS
   SUBROUTINE mytype_Write(myStructure,Filename)
     TYPE(mytype),INTENT(IN) :: myStructure
     CHARACTER(*),INTENT(IN) :: Filename
     ....
   END SUBROUTINE mytype_Write
   SUBROUTINE mytype_Read(Filename,myStructure)
     CHARACTER(*),INTENT(IN) :: Filename
     TYPE(mytype),INTENT(OUT) :: myStructure
    ....
   END SUBROUTINE mytype_Read
END MODULE mytype_io

Nothing very complicated. But, do notice my use of the PRIVATE and PUBLIC statements in
the two modules above. I always use PRIVATE with an empty entity list and then make each
module entity I want to be public by using the PUBLIC statement for that entity.

I then have a program that uses both these modules,

PROGRAM mytype_create
   USE mytype_define
   USE mytype_io
   IMPLICIT NONE
   TYPE(mytype) :: myStructure

   ! -- Fill the structure with data
   myStructure%i = 1
   myStructure%x = -99.0
   ... etc...

   ! -- Write the structure
   CALL mytype_Write(myStructure,'mytype.bin')

END PROGRAM mytype_create

For SGI, Sun, and Linux (using the Absoft compiler) systems I always get the following
"caution" message when the *program source file* is being compiled:

   USE mytype_io
       ^
"mytype_create.f90", Line = 3, Column = 7: CAUTION: A module named "MYTYPE_DEFINE" has
already been directly or indirectly use associated into this scope.

Now, everything in mytype_io is PRIVATE except for the contained subprograms. Nothing from
the mytype_define USEd in mytype_io should be visible to the code that USEs the mytype_io
module, right?

Is this compiler message bogus, or am I misunderstanding something about use and/or host
association, or am I using the PRIVATE and PUBLIC statements incorrectly? Compilation on
IBM AIX and Linux (using either the PGI or Intel compiler) systems produces no such
message (with all the warning stuff turned on). The message doesn't prevent compilation on
any of the systems, and the code has always worked fine - but I wonder if there is some
latent bomb waiting to go off?

Thanx and cheers,

paulv

p.s. I wonder if the three compilers where I see this (SGI, Sun, and Absoft) have some
common heritage since the CAUTION message has almost exactly the same wording for all
three. I seem to recall a link between the SGI and Absoft compilers, but not between them
and the Sun compiler.



Relevant Pages

  • Advice on polymorphic arguments
    ... implicit none ... subroutine print_data_i ...
    (comp.lang.fortran)
  • Re: Passing module procedures to external procedures -- type issues
    ... subroutine internal_sub ... if you use the right compiler option. ... but is instead a module procedure in the same module. ... default accessibility private. ...
    (comp.lang.fortran)
  • Re: Why does compiler only look at public methods of superclasses of...?
    ... Compiler enumerates all methods in class A and all public methods ... in the superclasses of A to find methods named x ... if method is declared final, static or private then compiler knows ... override a protected method. ...
    (comp.lang.java.programmer)
  • random number code
    ... Will it really compile exactly the same as mingw compiler used ... // initialization of static private members ... MSBs of the seed affect only MSBs of the array ... // constructor with 32 bit int as seed ...
    (comp.lang.cpp)
  • Re: setting of private variables
    ... If I comment the line " public:: init, area, ... Aren't they private? ... subroutine init ... But why doesn't compiler pick up the errors of private variables used ...
    (comp.lang.fortran)