How can I make an all-inclusive "Include" file?

How can I make an all-inclusive "Include" file?

I want an include file that has ONE LINE:


The purpose is to be able to re-dimension all the routines that use this PARAMETER in my source code,

by changing this one line. How do I make an INCLUDE file that the compiler can accept ?


I tried making it with "open office," but your Fortran compiler generated all kinds of weird errors when I use

that editor to make it.


How can I place this include file so that all my routines can easily access it ?

The routines are in different folders, so I would like to avoid having to give a different syntax in every folder,

if possible.


I was unable to get priority support for this issue.

9 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Just use Notepad. OpenOffice probably created some Office document format.

You can use /Ipath-to-folder (That's a capital I, not lowercase L) to specify where your include file is, and any INCLUDE that just gives the name will find it.

Steve (aka "Doctor Fortran") - Retired from Intel

Where would I put the IPATH? I had trouble finding that one.

Steve gave you the syntax for specifying a non-default include path when running Ifort from the command line. The "/I" identifies the specific option, and what follows is the argument to the option, which is the (absolute or relative) path to the directory containing the files to be included. If, for example, the include file is in .\incl, the command option is /Iincl.

If you are using Visual Studio to build, instead of the command window, there is a corresponding item in the project properties that you can set.

A better route for you to consider is to use a module to contain global parameters or global runtime values that are set at runtime (e.g. from command line options).

! File GlobalParameters.f90
module GlobalParameters
    ! what you want for compile time values
    integer, parameter :: DefaultN = 100
end module GlobalParameters
! End file GlobalParameters.f90

    !---------- next file ---------------

! File GlobalVariables.f90
module GlobalVariables
    use GlobalParameters
    ! what you want for run time values
    integer :: N
    character(256) :: buffer
    subroutine parseCommandLine
        implicit none
        if(COMMAND_ARGUMENT_COUNT() == 0) then
            N = DefaultN
            ! ... your code here to parse arguments
            call GET_COMMAND_ARGUMENT(1, buffer)
            read(buffer,'(I)') N
            ! ... additional arguments
    end subroutine parseCommandLine
end module GlobalVariables
! End file GlobalVariables.f90

    !---------- next file ---------------

! File Globals.f90
module Globals
    use GlobalParameters
    use GlobalVariables
end module Globals
! End file Globals.f90

    !---------- next file ---------------

! GlobalExample.f90
program GlobalExample
    use Globals
    implicit none
    call parseCommandLine
    call FOO
    call FEE
end program GlobalExample

subroutine FOO
    use Globals
    real :: array(N)
    print *, size(array)
    end subroutine FOO

subroutine FEE
    use Globals
    real :: array(DefaultN)
    print *, size(array)
end subroutine FEE

Jim Dempsey

For your simplified

module m_NDA
    integer, parameter :: NDA = 100
end module m_NDA


subroutine foo
   use m_NDA
   implicit none
   real :: array(NDA)

Jim Dempsey

Just create a text file with the extension .fi or .inc

The in your code use an `include` statement similar to the example below.

include ''

But again, I have to agree with the other comments, to make a module with the constant values instead of reading an include file in each source.

this was VERY HELPFUL.

Thanks to all of you ! !


Note that the form of PARAMETER quoted above (no colons or parens) was an extension prior to F90 which was supported by several compilers.  It ought to be rejected if a /stand option is set.  There were some nasty variations possible in data typing which you might have hoped would surface under IMPLICIT NONE (also an extension at the time, but one well enough proven to be adopted as standard).

Leave a Comment

Please sign in to add a comment. Not a member? Join today