Fortran 90 Subprograms
can also be used in a FUNCTION. 5. Page 6. Function Example. ?Note that functions can have
Fortran 90 Basics
?A Fortran 90 program has the following form: ?A Fortran 90 constant may be an integer real
Beginner Fortran 90 tutorial
Beginner Fortran 90 tutorial A very basic program in Fortran contains: ... In the previous example your code probably ran but has nothing to show for.
Fortran 90 Handbook.pdf
For an informal and tutorial approach to learning Fortran 90 the book
Elementary Programming in FORTRAN 90.
Shahrivar 2 1386 AP GNU FORTRAN compiler (fortran77
An introduction to programming in Fortran 90
the context of Fortran 90 and a series of examples and exercises is used to programming and Fortran 90 to write straightforward programs.
Introduction to Fortran 90
A Fortran 90 compiler is required to report any non-conforming code (i.e. the use of referred to as declaring or specifying a variable for example:.
Introduction to using the netCDF data format with Fortran 90 I
Tir 29 1389 AP The examples shown are using the flags available with the g95 compiler. In order to use netCDF with f90 you need to have the f90 netcdf module ...
BLUPF90 - a flexible mixed model program in Fortran 90
BLUPF90 is a mixed model program written in Fortran 90 (Misztal 1999) . Example of single-trait animal model with one fixed effect. DATAFILE.
Fortran 90 Handbook
In Fortran 90 it is possible to treat a whole array as a single object. For example suppose A
Fortran 90 SubprogramsFortran
90Subprograms
If Fortran is the lingua franca, then certainly it must be true that BASIC is the lingua playpen 1Thomas E. Kurtz
Co-Designer of the BASIC language
Fall 2010
Functions and SubroutinesFunctions
andSubroutines
Fortran 90 has two types of subprograms,Fortran
90has two types of subprograms, functions and subroutines.
A Fortran 90 function is a function like those in
AFortran
90function is a function like those in
C/C++. Thus, a functionreturns a computed
result via the function nameresult via the function nameIf a function does not have to return a function
l bti va l ue, use s u b rou ti ne. 2Function Syntax:
1/3Function
Syntax:
1/3A 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 ( egINTEGER
type is aFortran
90type e g
INTEGER
REAL,LOGICAL, etc) with or without KIND.
function name is a Fortran 90 identifier function name is aFortran
90identifier arg1, ..., argnare formal arguments. 3
Function Syntax:
2/3Function
Syntax:
2/3A 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. 4Function Syntax:
3/3Function
Syntax:
3/3In 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. 5Function 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 numberIMPLICIT 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
(,) pREAD(*,*) 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
6Common Problems:
1/2Common
Problems:
1/2 for g et function t yp efor g et INTENT(IN)not an errorFUNCTION DoSomething(a, b)
IMPLICIT NONE
INTEGER, INTENT(IN) :: a, b REAL FUNCTION DoSomething(a, b)IMPLICIT NONE
INTEGER :: a, b
gyp gDoSomthing = 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, bIF (a > b) THEN
a= a - b ELSEINTEGER, INTENT(IN) :: a, b
INTEGER :: c
c = SQRT(a*a + b*b)END FUNCTION DoSomething
ELSE a= a + bEND IF
DoSomthing = SQRT(a*a+b*b)
END FUNCTION DoSomething
7END FUNCTION DoSomething
Common Problems:
2/2Common
Problems:
2/2REAL FUNCTION DoSomething(a, b)
IMPLICIT NONE
REAL FUNCTION DoSomething(a, b)
IMPLICIT NONE
incorrect use of function name only the most recent value is returnedIMPLICIT NONE INTEGER, INTENT(IN) :: a, b
DoSomething = a*a + b*b
DoSomething = SQRT(DoSomething)
IMPLICIT NONE INTEGER, INTENT(IN) :: a, b
DoSomething = a*a + b*b
DoSomething= SQRT(a*a - b*b)
END FUNCTION DoSomething END FUNCTION DoSomething 8Using FunctionsUsing
Functions
The use of a user
defined function is similar to The use of a user defined function is similar to the use of a Fortran 90 intrinsic function.The following uses function
Factorial(n)
to The following uses functionFactorial(n)
to compute the combinatorial coefficient C(m,n), where m and n are actual argument s: where m and n are actual argument s:Cmn = Factorial(m)/(Factorial(n)*Factorial(m-n))
Note that the combinatorial coefficient is
defined as follows, although it is notthe most efficient way: C m n m 9 C m n nmnArgument Association :
1/5Argument
Association
1/5Argument association
is a way of passing valuesArgument
association is a way of passing values from actual arguments to formal arguments.If an actual argument is an
expression it is If an actual argument is an expression it is evaluated and stored in a temporary location from which the value is passed to thefrom which the value is passed to the corresponding formal argument.If t l t i
ibl it l i If an ac t ua l argumen t i s a var i a bl e, it s va l ue i s passed to the corresponding formal argument. Cd h iibl C onstant an d (A), w h ere A i s var i a bl e, are considered expressions. 10Argument Association :
2/5Argument
Association
2/5Actual arguments are variables:Actual
arguments are variables: abcWRITE(*,*) Sum(a,b,c)
x y zINTEGER FUNCTION Sum(x,y,z)
IMPLICIT NONE
INTEGER INTENT(IN)::x y z
x yquotesdbs_dbs17.pdfusesText_23[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