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

  • Home
  • SEARCH
  • 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 8527721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:38:09+00:00 2026-06-11T08:38:09+00:00

I found nothing in Google, so… I try to use all objected-oriented features of

  • 0

I found nothing in Google, so…

I try to use all objected-oriented features of Fortran 90 and create module for some specific work (like class in C++). I have written something like this:

module test

integer, PRIVATE :: dummy
PUBLIC :: sub

contains 

subroutine sub()
dummy = 1
end subroutine sub

end module test

But, I have about 10 such subroutines and it’s very bad idea to place them all into one file. Is it possible to tell compiler, that sub is module subroutine, but place it in another file? Because, it looks like this code will be compiled only if I define body of sub there.

  • 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-11T08:38:10+00:00Added an answer on June 11, 2026 at 8:38 am

    As a direct answer to your question – yes – you can use a INCLUDE line to reference a file that contains the definition of sub from within the file that contains the definition of the rest of the module (the include line for the files with the subroutine code would come after the CONTAINS statement in the module.

    MODULE test
      INTEGER, PRIVATE :: dummy
      PUBLIC :: sub
    CONTAINS
      INCLUDE 'sub.f90'
    END MODULE test
    
    ! sub.f90
    SUBROUTINE sub
      dummy = 1
    END SUBROUTINE sub
    

    However, this is an atypical arrangement. Further, if it is a “very bad idea to place them all into one file”, then is it a good idea (or necessary) to have the presumably disparate subroutines available from the one module?

    The more conventional F90 solution is for the shared data (dummy) to be placed in one “low level” module as public entities, to place the subroutine definitions into a series of “intermediate level” modules that use the low level module as required, and then for a final “high level” module that uses the intermediate modules and provide a collective export to client code. Source code conventions, rather than language rules, are then used to avoid client code from directly using the intermediate and low level modules.

    MODULE low_level_shared
      IMPLICIT NONE
      INTEGER, PUBLIC :: dummy
    END MODULE low_level_shared
    
    MODULE intermediate_sub1
      IMPLICIT NONE
    CONTAINS
       SUBROUTINE sub1
         USE low_level_shared
         dummy = 1
       END SUBROUTINE sub1
    END MODULE intermediate_sub1
    
    MODULE intermediate_sub2
      IMPLICIT NONE
    CONTAINS
       SUBROUTINE sub2
         USE low_level_shared
         ...
       END SUBROUTINE sub2
    END MODULE intermediate_sub2
    
    MODULE high_level
      USE intermediate_sub1
      USE intermediate_sub2
      PRIVATE
      PUBLIC :: sub1, sub2
    END MODULE high_level
    
    PROGRAM client_code
      USE high_level
      ...
      CALL sub1
    END PROGRAM client_code
    

    Fortran 2008 allows additional structures and control through the submodule feature, where module procedures interfaces can be defined in a separate program unit to the module procedure implementation.

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

Sidebar

Related Questions

Hi i have been looking for some solutions but i have found nothing... Is
I've found some similar questions on StackOverflow, but nothing that addresses what I'm looking
I've done a brief Google around and found nothing but I feel I ought
I've been googling for Google App Engine Backends code samples but I found nothing.
Just curious. Tried to google this, but found nothing. I remember earlier there was
I want to use Ninject 2 on Castle Monorail. Searching on google, I found
As per title. I've been google'ing extensively and found nothing. I've tried the RFC
So this is IT more than programming but Google found nothing, and you guys
I have a very simple question (I searched on google but found nothing). How
I really have scoured Google for a similar question and found nothing, which confuses

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.