1 / 12

Functions & Subroutines

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:

lisabrown
Download Presentation

Functions & Subroutines

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Functions & Subroutines DFMain.chm HTML version

  2. Types of subprograms • Internal • External • Module • Pure • Elemental • Recursive • Optional arguments • Generic • Defined operators • Defined assignment

  3. 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

  4. 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.

  5. Procedure Interfaces

  6. 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)

  7. Explicit Interfaces are required for calling routines with • argument keywords. • generic names. • Defined assignments (subroutine only). • Defined operators ( functions only ). • Pure functions.

  8. 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

  9. 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

  10. Generic routines GenericS.f95GenericS.exe

  11. Defined Operators GenericO.f95GenericO.exe Generic1.f95Generic1.exe

  12. Defined Assignments Pure Procedures Elemental Procedures

More Related