[PDF] Fortran 90 Subprograms Note that functions can have





Previous PDF Next PDF



Fortran 90 Subprograms

Note that functions can have no formal argument. ?But () is still required. INTEGER FUNCTION Factorial(n). IMPLICIT NONE. REAL FUNCTION GetNumber().



Fortran 90 Basics

?A Fortran 90 program has the following form: Fortran Intrinsic Functions: 2/4. ?Some mathematical functions: Function. Meaning. Arg. Type Return Type.



Contouring and Analysis

– Not necessary in Fortran 90 but is probably something you will run into. Page 6. Example: Temperature conversion. • Write a function to convert a temperature.



1 Fortran 90 Modules

21-Mar-2006 A module can contain functions and subroutines just like a main program unit by placing them between a 'CONTAINS' statement and the 'END MODULE' ...



FORTRAN 90

write a fortran 90 program to calculate the modulus and argument of z=5-4i by function subprograms. program complex_ma implicit none complex:: z real:: modulus 



appendix a - fortran 90 standard statement keywords

Fortran 90 standard relaxes the FORTRAN 77 requirement that all DATA. PROGRAM SUBROUTINE



Fortran 90/95 Programming Manual

The function cmplx is one of the intrinsic functions (see below). Arrays. A series of variables of the same type can be collected in an array. Arrays can be one 



Appendix A - A Fortran 90/95 primer

Subprograms (subroutines and functions) can be included in modules. The form of a module subroutine



Expanded Description of Fortran 90/95 Intrinsic Procedures

A transformational function is a function that has one or more array-valued arguments or an array-valued result. Unlike elemental functions which operate on an 



Scope in Fortran 90

Scope in Fortran 90 subroutine Sub hosts internal function F3. ... example variable X and function F3 are not visible to the module program unit Mod.

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
[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