- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I need to have my subroutine INCLUDE several files that build up a statement.
Here's some code:
ASSOCIATE( INCLUDE 'afile' x VAR2 => STRUCT%VAR2)
The included file contains
x VAR1 => STRUCT%VAR1,
If the compiler would just include the file like a text replacement, the statement would compile, but I get the error: "First statement in file must not be continued." That's the lowercase "x."
I really need to structure the subroutine in this way. Is there a compiler switch to help me?
P.S. Before you suggest a free-format file, can I tell the compiler to accept "C" in the first column as a comment line and any character in the sixth column as a continuation? I'm trying to re-use thousands of lines of code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Under 'INCLUDE' in the IFort manual you will find this stipulation:
An included file or text module can contain any source text, but it cannot begin or end with an incomplete Fortran statement.
What you are attempting to do would break this requirement. My view is that you are attempting to use the Fortran INCLUDE directive in the same way as the C preprocessor #include directive.
I think that readability of code is adversely impacted by having inclusions that are part of a block. However, since you insist, you may want to consider using the C preprocessor, using the /fpp compiler option. For example,
subroutine xassoc(struct) implicit none type stype integer :: var1,var2 end type type(stype) :: struct ! associate( #include 'afile' + v2 => struct%var2 + ) write(*,*)v1,v2 end associate return end subroutine
where afile contains
+ v1 => struct%var1, !
(I added the comment line to afile to compensate for the Forum software's propensity to strip leading blanks from source code lines)
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Under 'INCLUDE' in the IFort manual you will find this stipulation:
An included file or text module can contain any source text, but it cannot begin or end with an incomplete Fortran statement.
What you are attempting to do would break this requirement. My view is that you are attempting to use the Fortran INCLUDE directive in the same way as the C preprocessor #include directive.
I think that readability of code is adversely impacted by having inclusions that are part of a block. However, since you insist, you may want to consider using the C preprocessor, using the /fpp compiler option. For example,
subroutine xassoc(struct) implicit none type stype integer :: var1,var2 end type type(stype) :: struct ! associate( #include 'afile' + v2 => struct%var2 + ) write(*,*)v1,v2 end associate return end subroutine
where afile contains
+ v1 => struct%var1, !
(I added the comment line to afile to compensate for the Forum software's propensity to strip leading blanks from source code lines)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
To add to mecej4's answer, INCLUDE is not a text replacement the way #include is.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page