Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

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

WSinc
New Contributor I
495 Views

I want an include file that has ONE LINE:

PARAMETER  NDA=100

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.

0 Kudos
8 Replies
Steve_Lionel
Honored Contributor III
495 Views

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.

0 Kudos
WSinc
New Contributor I
495 Views

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

0 Kudos
mecej4
Honored Contributor III
495 Views

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.

0 Kudos
jimdempseyatthecove
Honored Contributor III
495 Views

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
    contains
    subroutine parseCommandLine
        implicit none
        if(COMMAND_ARGUMENT_COUNT() == 0) then
            N = DefaultN
        else
            ! ... your code here to parse arguments
            call GET_COMMAND_ARGUMENT(1, buffer)
            read(buffer,'(I)') N
            ! ... additional arguments
        endif
    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
Output:
         200
         100

Jim Dempsey

0 Kudos
jimdempseyatthecove
Honored Contributor III
495 Views

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

0 Kudos
JAlexiou
New Contributor I
495 Views

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 'constants.inc'

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.

0 Kudos
WSinc
New Contributor I
495 Views

this was VERY HELPFUL.

Thanks to all of you ! !

 

0 Kudos
TimP
Honored Contributor III
495 Views

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).

0 Kudos
Reply