120 likes | 123 Views
Functions & Subroutines. DFMain.chm. HTML version. Types of subprograms. Internal External Module Pure Elemental. Recursive Optional arguments Generic Defined operators Defined assignment. INTENT. Type Declaration Statement:
E N D
Functions & Subroutines DFMain.chm HTML version
Types of subprograms • Internal • External • Module • Pure • Elemental • Recursive • Optional arguments • Generic • Defined operators • Defined assignment
INTENT Type Declaration Statement: type, [att-ls,] INTENT (intent-spec) [, att-ls] :: d-arg [, d-arg] ... Statement: INTENT (intent-spec) [::] d-arg [, d-arg] ... intent-spec IN, OUT, or INOUT Intent.f95Intent.exe
CONTAINS Separates the body of a main program, module, or external subprogram from any internal or module procedures it may contain. It is not executable. Thus, procedures following the CONTAINS statement are local ( internal ) procedures of the host program.
Explicit Interfaces are requiredfor routines with • optional dummy arguments. • dummy arguments that are assumed-shape arrays, pointers, or targets. • result that is array-valued or a pointer (functions only). • result whose length is neither assumed nor a constant (character functions only)
Explicit Interfaces are required for calling routines with • argument keywords. • generic names. • Defined assignments (subroutine only). • Defined operators ( functions only ). • Pure functions.
Recursive Procedures If a function is directly recursive and array valued, the keywords RECURSIVE and RESULT must both be specified in the FUNCTION statement. Recursive.f95Recursive.exe Fibonacci.f95Fibonacci.exe
Optional Arguments • Optional arguments are specified by the OPTIONAL attribute. • Use the intrinsic function PRESENT to determine whether an actual argument is present. • Explicit procedure interfaces must be used. Optional.f95Optional.exe
Generic routines GenericS.f95GenericS.exe
Defined Operators GenericO.f95GenericO.exe Generic1.f95Generic1.exe
Defined Assignments Pure Procedures Elemental Procedures