Combine Fortran .for and .f90 include header files

5.9k views Asked by At

I have an old Fortran program that I have to take care of. I have some files with the extention .fd .f90 .for that should work together. I use Visual studio.

I am a total beginner of Fortran so I have the following questions:

Do .f90 and .for - files work together ? Do I have to convert one into anoter? If so, which version would you use?

I have an ABC.f90-file which does some simple calculations. I also have an ABC.fd that seems to be the header-file. In my ABC.f90 I have the following statement :

include 'ABC.fd'    

This won`t work but when I replace that line with the content of my ABC.fd there is no problem with this part of the program.

How do I include a header- file correctly? Is the extension .fd correct for a header-file?

1

There are 1 answers

2
High Performance Mark On

I'm reasonably sure this is a duplicate Q&A, but couldn't find an original. Feel free to dupe-hammer this if you can find one.

The Fortran language standards scarcely recognise the possibility of the existence of source files and don't mandate, even recommend, filename suffixes. Over the years some de facto standards have arisen; it remains possible to persuade your compiler to treat a file differently from the default treatment applied to files with a given suffix on their name. Bear that in mind as you read on.

.f90 usually denotes a free-form source file, that is one which does not obey the pre-Fortran 90 standard for rigid layout of source files with columns 1-6 reserved for line labels, 7 for a line-continuation character, 8-72 for program statements etc.

.for usually denotes a fixed-form source file, one which does adhere to the, now outdated, approach to writing code as if using punched cards.

You can certainly build a program comprising source files of both species. Compilers will generally default to treating the files correctly and may well use the filename suffix to determine what treatment to apply. Compilers also offer options to treat, say, a .f90 file as fixed-form though, since that generally leads to compilation errors it's not clear that you would ever want to. And vice-versa.

Fortran doesn't really do header files, not in the sense that breathtakingly modern languages such as C do them. Many people have used include to include material which in other languages would have been in header files. However, include operates very simply, it effectively tells the compiler to copy the contents of the included file and paste them into the Fortran source file (without modification) over the include line.

.fd is not, that I am aware of, a de facto standard in the world of Fortran and an include line can include any file it wants to, even a .f90 or .txt file. Any file at all. See Steve Lionel's comment below for more on .fd files.

Common reasons why including doesn't work (though you should have reported the error message for a more conclusive diagnosis):

  • the included file isn't where the compiler is looking for it;
  • inclusion results in a file which doesn't obey Fortran's strict statement ordering rules. This seems unlikely in your situation if copy-and-paste works.