ejang
ejang

Reputation: 4062

fortran 'call' vs 'include'

I see that Fortran has 'call' and 'include' statements. what is the difference between the two? Does the .i filetype have some significance?

i.e:

include 'somefile.i'
call 'somesubroutine.f'

Thanks!

Upvotes: 2

Views: 9029

Answers (2)

Rook
Rook

Reputation: 62538

INCLUDE statement lets you include source from some other file, as if it was in the file in which the statement is located. Its usefulness in organizing code is somewhat dubious, but some swear by it. In F77 it was a common extension (from MIL-STD 1971, I believe), in F90 it made it into the Standard. Filetypes have no significance. As the matter of fact, in fortran most filetypes (even the more common ones as f77, f90 and such) have no significance. Most compilers merely use them to automatically "detect" and differentiate free form from fixed form source code, but they also allow for other.

CALL statement is used for calling subroutines. It is of the form CALL subroutine_name(list-of-arguments). Subroutines are one of the more simple ways of structuring and dividing your program into logical sub-units.

But this is all relatively basic, and covered in every Fortran tutorial out there. Some are better, some are worse. A few good starting points for learners would be the Wikipedia page (not perfect, but not that bad either), FortranWiki and two books. One IRO-bot already mentioned, other would be Chapman's Fortran 95/2003 for scientists and engineers. It is generally considered more suitable for beginners, having an easy going approach and a plethora of practical examples, while Metcalf is aiming to be more of a reference book as well.

Upvotes: 6

milancurcic
milancurcic

Reputation: 6241

In general, file extensions don't have special meaning for the compiler. You can include any file, not just .i. Common extension for Fortran source files is .inc though.

include statement literally inserts a specified file into the source code.

call statement is very different, and it is used to call a Fortran subroutine.

These are very basic concepts. Before all, you should look up an introductory Fortran tutorial online (just try googleing it). Or get one of several great books on Fortran programming, e.g. Metcalf and Reid.

Upvotes: 4

Related Questions