Question

I have a collection of .F and .H files that makeup a FORTRAN code. I'm running into trouble tyring to compile the .H files. The .H files contain a bunch of common blocks. An example of one of the .H files is:

*AC HEAD      
c                                                                       HEAD 1
      common/blah/ x(25), y, z(25), p(25,mnv),                          HEAD 2
     1                t(25,mx), d(25,mnv)                               HEAD 3
c                                                                       HEAD 4
ETC...

When I search for an answer on google, it is said that .h files are c/c++ files, but they don't look like they are written in c/c++. gfortran seems to also think they are C files.

When I try to compile:

gfortran-4.5 -fdefault-real-8 -fbacktrace -fno-align-commons HEAD.h

I get the errors:

cc1: warning: command line option "-fdefault-real-8" is valid for Fortran but not for C
cc1: warning: command line option "-fbacktrace" is valid for Fortran but not for C
cc1: warning: command line option "-fno-align-commons" is valid for Fortran but not for C
HEAD.h:1:5: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘HEAD’

I tried to comment out the first line '*AC HEAD', but then the error was about looking for an attribute before the *. Do I need something in the last column with the HEAD # values to commment that out, do I need to build the .H files with a C++ compiler or what?

Was it helpful?

Solution

You don't compile those. If you grep the other fortran files, you'll see that they're included using either something like include HEAD.h or '#include "head.h"' (that second is my guess; I'm guessing you're running the C preprocessor on the fortran files). Those include statements basically read in a copy of that .h file wherever the include statement is during the compilation process. So it's a piece of code that's used, but never compiled on its own.

This inclusion of header files in Fortran is not best practice any longer, and all the more so because they're used to widely distribute common blocks through the code. So don't write any new code using this approach. But that's what this particular old code is doing.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top