I know that circular dependence of modules in FORTRAN is forbidden. But I am wondering how strong that proscription is. Let's say I have:
module mod1
integer, public :: i,j,k
use mod2, only: m
end module mod1
and
module mod2
integer, public :: l,m,n
use mod1, only: j
end module mod2
It seems to me that this evades circularity in a logical sense, but that doesn't mean the standard allows it. Should it work?
If so, I am having trouble compiling because, of course, mod1 wants to see mod2 and vice versa. Is there a way around this?
No, it shouldn't work. The standard says that a module must be "available" when a USE is seen. If mod2 hasn't been compiled by the time the "use mod2" is seen, the build will fail. (Some compilers might allow you to use a module defined later in the same source, some do not.) You might be able to use submodules (see https://stevelionel.com/drfortran/2015/07/07/doctor-fortran-in-we-all-live-in-a-yellow-submodule/) to accomplish what you want - I don't know because clearly what you posted is not representative of your real application, but Mark's suggestion of a separate module is easier to understand.