Home > OS >  Fortran OOP no reasons compilation aborted
Fortran OOP no reasons compilation aborted

Time:08-25

So I have a module for an allocatable class array. When I try to access that array from the module where the class is, I get a compilation aborted without reason. I guess its may be related to the module with the array also using the module, so it is in some kind of recursion when I call the module from the module with the class. compilation aborted from VS community 2019

One may ask why I have a dedicated module for the class array, this is actually to prevent recursion with the class. As I have tried having the array in a more general module as global value, but it would lead to a crash related to nested too deep.

The module with the array:

module sys2_moleculesArray
use type3_crossMol_class, only: type3_crossMol
implicit none 
class(type3_crossMol),dimension(:),allocatable :: type3_crossMol_tagArray

end module sys2_moleculesArray

parts of the class array:

module type3_crossMol_class
use sys2_paramData
use sys2_type3ParamData

implicit none
  ...
type :: type3_crossMol 
    integer(kind=4) :: index,x,y,rotType,checkMol_index
    integer,dimension(4,2) :: molBondedTo 
    integer,dimension(20) :: potentialNeighMol
contains
    procedure :: initialise => initialise
    procedure :: addAtom => addAtom
    procedure :: getPotentialNeigh => getPotentialNeigh
    procedure :: test => test
end type type3_crossMol
contains
...
subroutine test(this)
use sys2_type3ParamData, only:cur_type3_mol_number
use sys2_moleculesArray
implicit none
integer :: n
class(type3_crossMol):: this
do n=1,cur_type3_mol_number
        print*, "b4 potential",type3_crossMol_tagArray(n)%index 
    end do
end subroutine test

I guess I can do what I want to do by doing the array manipulation outside the module with the class, but I would like to keep the code sort of organised, with the subroutine inside the class. So any help regarding the issue, at least a more detail reason, would be great!

CodePudding user response:

You apparently have a circular dependency.

  • module sys2_moleculesArray uses type3_crossMol_class
  • module type3_crossMol_class uses sys2_moleculesArray

which one should be compiled first? Weird that VS doesn't have a mechanism to check that, though.

  • Related