Today I had learnt about the procedures and intrinsic procedures in Fortran. Basically, a procedure can be of two types
- function
- subroutine
Functions
The functions are procedures which return a value which can either be
- Given the same name as function name in which case the syntax will be.
|
|
In this case, the return type is given before function keyword. Also, note that in fortran, values are passed by reference by default. Hence, if the input is only an input, intent(in)
needs to be mentioned. Other intents are out, inout
.
- Give a separate variable name for return value
|
|
Hence, the result
keyword is used to specify the return value. There is a return
keyword in Fortran but it only returns the control back to the caller. Hence, the result need to be assigned properly.
Also, fortran can take optional arguments. Inside the function body, these need to be declared with optional
keyword.
|
|
Subroutines
Subroutines do not have a return value. They are preferably used when the input values are to be modified though the same can be done in functions. The subroutines are called through
|
|
declaring a subroutine is straight forward.
|
|
Intrinsic Procedures
There are quite a few intrinsic procedures that are available in Fortran. Many of them are scientific, but few string manipulation procedures are also available.
The list of intrinsic procedures in gcc
I tried to implement the fibonacci optimization method but the current knowledge is not sufficient. Will try again once I learn more about Fortran.