2

I have been working with some old legacy code in Fortran used by a colleague. The actual code is proprietary, so the examples I use here are abbreviated compared to the code I'm working with.

Some of the procedures individually defined in *.f files included a file called variables.h:

Example contents of variables.h:

c   VARIABLE DIMENSIONS FOR MODEL
c     height_dim -- number of vertical (z) steps
c     length_dim -- number of horizontal (x) steps
c     width_dim -- number of horizontal (y) steps
      INTEGER height_dim, length_dim, width_dim, nmodes, styleFlag

      PARAMETER (height_dim=80, length_dim=50, width_dim=40)
      PARAMETER (nmodes = 4, 
     $           styleFlag = 3)

I changed that to the following:

!   VARIABLE DIMENSIONS FOR MODEL
!     height_dim -- number of vertical (z) steps
!     length_dim -- number of horizontal (x) steps
!     width_dim -- number of horizontal (y) steps
      INTEGER height_dim, length_dim, width_dim, nmodes, styleFlag

      PARAMETER (height_dim=80, length_dim=50, width_dim=40)
      PARAMETER (nmodes = 4, styleFlag = 3)

An example routine that uses these might be the following, called initial_conditions.f:

c     This sets up the PDE's initial conditions
      subroutine initial_conditions( temperature, density )
      IMPLICIT NONE
      INCLUDE 'variables.h'

      real*8 temperature(height_dim,length_dim,width_dim)
      real*8 density(height_dim)

      temperature = 273.15D0
      density     = 1.0D0

      return
      end

I tried to compile a test routine written in F90 (or newer?) that included dimensions.h, but the compiler didn't like the fixed-form comments being included into the free-form *.f90 source file, so I changed all comments from c to !. Then I was able to compile my test program successfully. Let's call it test.f90:

 program test
   implicit none
   include 'variables.h'

   real*8, dimension(height_dim,length_dim,width_dim) :: vx, vy, vz

   ! <<Initialize data...>>
   ! << Output data...>> 

end program test

Unfortunately, now the original code doesn't compile. It seems that code doesn't like commented lines to begin with ! (based on the fact that that was all I changed), but the actual errors it gives are the following:

variables.h(8): error #5082: Syntax error, found END-OF-STATEMENT when expecting one of: =

     PARAMETER (nmodes = 4, styleFlag = 3)
------------------------------------------^

variables.h(5): error #6219: This variable, used in a specification expression, must be a dummy argument, a COMMON block object, or an object accessible through host or use association.   [NMODES]

  INTEGER height_dim, length_dim, width_dim, nmodes, styleFlag
---------------------------------------------^

What in the world is going on, and how can it be fixed?!

I imagine that comment styles are incompatible (free-form fortran thinks c is a variable, not a comment?), but I have no idea how it would produce these errors.

jvriesem
  • 1,859
  • 3
  • 18
  • 40
  • 1
    For your case, [this answer](https://stackoverflow.com/a/22753383/3157076) may interest you. Otherwise, you could clarify the troublesome aspects of your code (ie., show those parts which have the features) by considering the points of answers to [this question](https://stackoverflow.com/q/25021896/3157076). – francescalus Mar 29 '18 at 06:57
  • 1
    your errors appear to come from exceeding fixed form line length (though they are not too long in the example..?). – agentp Mar 29 '18 at 12:48
  • another route here https://stackoverflow.com/a/22049200/1004168 note even more simply you can break long declaration lines into multiple declarations. – agentp Mar 29 '18 at 12:54
  • Try -132 and -fixed – Holmz Mar 29 '18 at 14:29

0 Answers0