[PDF] [PDF] Fortran 90 Subprograms

Fortran 90 has two types of subprograms, functions and subroutines C/C++ Thus, a function returns a computed result via the function name result via the function name



Previous PDF Next PDF





[PDF] Fortran 90 Subprograms

Fortran 90 has two types of subprograms, functions and subroutines C/C++ Thus, a function returns a computed result via the function name result via the function name



[PDF] COURS DE FORTRAN 90 - Institut de Mathématiques de Bordeaux

Le but de ce cours est d'apprendre `a programmer en fortran 90 Il est prévu dans ce cas, pas de type avant le mot clef function – la variable résultat ne doit 



[PDF] L12 – Fortran Programming - Part 4 1 Functions - homechpcutahedu

We have used all kinds of intrinsic functions in Fortran such as ABS, NINT, SIN, etc For example we could create a module file called mod_constants f90 that 



[PDF] Scope in Fortran 90

The external subroutine Sub hosts internal function F3 Objects declared inside a program unit are global; they are visible anywhere in the program unit including



[PDF] Introduction to Fortran 90 - PRACE materials

Third standard in 1991: Fortran 90 supporting Fortran 95 and several features of the 2003 standard We have collected DSP functions in dsp f90 source file 



[PDF] Les Evolutions du Fortran 90/95

Une procédure définit une fonction (FUNCTION) ou un sous-programme ( SUBROUTINE) Elle pourra être: une unité de programmation F90 Il s'agit d'une



[PDF] Fortran 90 Tutorial

and the KIND function operates as expected: KIND( TRUE ) We can specify scalar variables corresponding to the five intrinsic types:



[PDF] Fortran 90

The same syntax applies for other program elements, such as FUNCTION or MODULE 2 3 Specifications Fortran 90 allows an extended form of declaration, in 



[PDF] Fortran 90 Handbook

although a general discussion of the intrinsic functions is included in Chapter 13 • The complete syntax of Fortran 90 may be found in Appendix B The syntax



[PDF] Fortran 90 Features - Geodesy

Fortran 90 Features 14 Coding convention Put all Fortran 90 keywords and intrinsic function names in upper case, everything else in lower case F90 is NOT  

[PDF] fortran 90 handbook pdf

[PDF] fortran 90 pi

[PDF] fortran 90 programming pdf

[PDF] fortran 90 read

[PDF] fortran 90 standard pdf

[PDF] fortran 90 textbook

[PDF] fortran 90 textbook pdf

[PDF] fortran 90 tutorial pdf

[PDF] fortran 90 write format

[PDF] fortran 90/95 pdf

[PDF] fortran 95 compiler

[PDF] fortran 95 continuation line

[PDF] fortran 95 do loop

[PDF] fortran 95 download

[PDF] fortran 95 manual

Fortran 90 SubprogramsFortran

90

Subprograms

If Fortran is the lingua franca, then certainly it must be true that BASIC is the lingua playpen 1

Thomas E. Kurtz

Co-Designer of the BASIC language

Fall 2010

Functions and SubroutinesFunctions

and

Subroutines

Fortran 90 has two types of subprograms,Fortran

90
has two types of subprograms, functions and subroutines.

A Fortran 90 function is a function like those in

A

Fortran

90
function is a function like those in

C/C++. Thus, a functionreturns a computed

result via the function nameresult via the function name

If a function does not have to return a function

l bti va l ue, use s u b rou ti ne. 2

Function Syntax:

1/3

Function

Syntax:

1/3

A Fortran function

or function sub p ro g ram ,pg, has the following syntax: typeFUNCTIONfunction-name(arg1, arg2, ..., argn)

IMPLICIT NONE

[specification part] [execution p art] p [subprogram part]

END FUNCTIONfunction-name

type is a Fortran 90 type ( eg

INTEGER

type is a

Fortran

90
type e g

INTEGER

REAL,LOGICAL, etc) with or without KIND.

function name is a Fortran 90 identifier function name is a

Fortran

90
identifier arg1, ..., argnare formal arguments. 3

Function Syntax:

2/3

Function

Syntax:

2/3

A function is a self-contained unit that receives

some "input" from the outside world via its formal arguments, does some computations, and returns the result with the name of the function. Somewhere in a function there has to be one or more assignment statements like this: function-name= expressionwhere the result of expressionis saved to the name of the function.

Note that function-namecannot appear in

the right-hand side of any expression. 4

Function Syntax:

3/3

Function

Syntax:

3/3

In a t

yp e s p ecification formal ar g uments yp p , g should have a new attribute INTENT(IN).

The meanin

g of INTENT(IN)is that the g function only takes the value from a formal argument and does not change its content.

Any statements that can be used in PROGRAM

can also be used in a FUNCTION. 5

Function ExampleFunction

Example

Note that functions can have no formal argument.Note that functions can have no formal argument.

But, () is still required.

INTEGER FUNCTION Factorial(n)

IMPLICIT NONE

REAL FUNCTION GetNumber()

IMPLICIT NONE

Factorial computation Read and return a positive real number

IMPLICIT NONE INTEGER, INTENT(IN) :: n

INTEGER :: i, Ans

IMPLICIT NONE REAL :: Input_ValueDO

WRITE 'A p ositive number: '

Ans = 1

DO i = 1, n

Ans = Ans * i END DO

(,) p

READ(*,*) Input_Value

IF (Input_Value > 0.0) EXIT

WRITE(*,*) 'ERROR. try again.'

END DO

END DO Factorial = Ans

END FUNCTION Factorial

END DO GetNumber = Input_Value

END FUNCTION GetNumber

6

Common Problems:

1/2

Common

Problems:

1/2 for g et function t yp efor g et INTENT(IN)not an error

FUNCTION DoSomething(a, b)

IMPLICIT NONE

INTEGER, INTENT(IN) :: a, b REAL FUNCTION DoSomething(a, b)

IMPLICIT NONE

INTEGER :: a, b

gyp g

DoSomthing = SQRT(a*a + b*b)

END FUNCTION DoSomething DoSomthing = SQRT(a*a + b*b)

END FUNCTION DoSomething

REAL FUNCTION DoSomething(a, b)

IMPLICIT NONE REAL FUNCTION DoSomething(a, b)

IMPLICIT NONE

change INTENT(IN)argumentforget to return a valueINTEGER, INTENT(IN) :: a, b

IF (a > b) THEN

quotesdbs_dbs2.pdfusesText_3