From the course: Introduction to Fortran

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Function and subroutine syntax

Function and subroutine syntax - FORTRAN Tutorial

From the course: Introduction to Fortran

Function and subroutine syntax

- [Instructor] What do you do when there are sections of code you'd like to give a name to, or to be able to reuse? Procedures are how we do that. There are two kinds of procedures in Fortran, functions and subroutines. Let's take a look at how we define them and how we use them. This is the syntax for a function definition. The keyword function, then a name for the function, and then in parenthesis, the arguments that it accepts, and optionally, you can specify the name of the result variable at the end of the line. By default, if you do not have this result variable option used, then the name of the result variable is the same as the name of the function. Then you need to declare the types and intents of the argument and the type of the result variable. These declarations look very similar to regular variable definitions. Then the contents of the function can be any other variable declarations and executable…

Contents