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

First statement in file a continuation character

Daniel_E_1
Beginner
798 Views

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.

0 Kudos
1 Solution
mecej4
Honored Contributor III
798 Views

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)

View solution in original post

0 Kudos
2 Replies
mecej4
Honored Contributor III
799 Views

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)

0 Kudos
Steven_L_Intel1
Employee
798 Views

To add to mecej4's answer, INCLUDE is not a text replacement the way #include is.

0 Kudos
Reply