I feel like this has to be a duplicate, but I can’t seem to find it anywhere and I didn’t get anything with a very quick google search.
Is there a way to change the name of stuff in a module so that it doesn’t conflict with the name of something local (or global)? Consider the example:
module namespace
real x !some data
contains
subroutine foo()
write(0,*) "foo!"
end subroutine foo
end module
subroutine foo()
write(0,*) "foo is the new bar :)"
end subroutine
program main
use namespace
real x
call foo() !should print "foo is the new bar"
call namespacefoo() !somehow call module namespace's version of foo
end program main
The above code doesn’t compile because x isn’t defined. Of course if I don’t want a local variable named x, then I could use namespace, only: foo, but it seems a little cumbersome to have to mangle my local variable names. (as a side note, I’m pretty sure that I’ve seen this before with some magic in the only part of the statement …)
For the benefit of those who also know python, I’m looking for something similar to python’s:
import namespace as other_namespace
Or I guess since Fortran doesn’t quite have that level of namespace control:
from namespace import somefunc as otherfunc
from namespace import somedata as otherdata
You need renaming:
Though of course it’s better to keep things private to the module if at all possible to avoid precisely this kind of thing