Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Fortran modules

franzw82
Beginner
817 Views
I wrote the following piece of code.

[bash]module module_1
   implicit none

   type :: mod_1_type
      integer(4) :: a = 10
   end type mod_1_type
   
   contains
      
   subroutine sub_mod1 (t1, t2)
     use module_2

     type (mod_1_type), intent(inout) :: t1
     type (mod_2_type), intent(inout) :: t2

     call sub_mod2 (t1, t2)        
    
   end subroutine sub_mod1

end module module_1

module module_2
   implicit none
  
   type :: mod_2_type
      integer(4) :: a = 20
   end type mod_2_type
  
   contains
   
   subroutine sub_mod2 (t1, t2)
      use module_1

      type (mod_1_type), intent(inout) :: t1
      type (mod_2_type), intent(inout) :: t2
     
   end subroutine sub_mod2
  
end module module_2

program prog
   use module_1
   use module_2
  
   type (mod_1_type) :: t1
   type (mod_2_type) :: t2
  
   call sub_mod1 (t1, t2)
    
end program prog

[/bash]

I can't get the code to compile (Intel Visual Fortran Compiler XE 12.0.5.221). Any helpful comments would be appreciated.
0 Kudos
1 Reply
GVautier
New Contributor III
817 Views
hello

Your modules are nested. Module_1 refers to Module_2 and needs it to be compiled and Module_2 refers to Module_1 and also needs it to be compiled. So it cannot be compiled.

You can define your 2 types mod_1_type and mod_2_type in a new "module_type" for example and refer to it in module1 and module_2.

0 Kudos
Reply