- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Where would I put the IPATH? I had trouble finding that one.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
this was VERY HELPFUL.
Thanks to all of you ! !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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).

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page