Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9110195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:12:54+00:00 2026-06-17T03:12:54+00:00

I feel like this has to be a duplicate, but I can’t seem to

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T03:12:55+00:00Added an answer on June 17, 2026 at 3:12 am

    You need renaming:

    [luser@cromer stackoverflow]$ cat ren.f90
    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, local_name => x, namespacefoo => foo  
      real x
      call foo() !should print "foo is the new bar"
      call namespacefoo() !somehow call module namespace's version of foo
    end program main
    [luser@cromer stackoverflow]$ nagfor ren.f90
    NAG Fortran Compiler Release 5.3.1 pre-release(904)
    Warning: ren.f90, line 17: X explicitly imported into MAIN (as LOCAL_NAME) but not used
    Warning: ren.f90, line 17: Unused local variable X
    [NAG Fortran Compiler normal termination, 2 warnings]
    [luser@cromer stackoverflow]$ ./a.out
     foo is the new bar :)
     foo!
    

    Though of course it’s better to keep things private to the module if at all possible to avoid precisely this kind of thing

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(I feel like this must be a duplicate, but I can't find it). Consider:
somehow couldn't find this with a google search, but I feel like it has
I feel like this should be trivial, but I've struggled to find anything useful
I feel like this has a very simple solution, but I am trying to
I feel like this is a common problem but nothing I've researched has worked
I feel like this is a stupid question, but I can't think of a
I must apologize if this is a duplicate question, but I can't seem to
I feel like this question has been answered but no implementation I've found from
I feel like this question has to have been asked but for the life
I feel like this has already been answered and implemented, but I cannot figure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.