The arguments in the CALL and
SUBROUTINE statements must be consistent with respect to :

- The number of arguments
- Type of arguments
- Order of arguments

**DUMMY ARGUMENTS**

This term is used to describe
the arguments in the SUBROUTINE. Let say we have the arrays UNITS
and SALES. They really only exist in the main program, where they
are allocated and take up main memory space. They do not exist
in the SUBROUTINE. The subroutine is passed the* address or
starting point of the array*. The data is read into the arrays
in the main program and the subroutine refers to and uses this
data without having to make a copy of it into the subroutine memory
area.

Moreover, you can use a variable
name in the SUBROUTINE that you already use in the main program
because those variables do not exist in main memory. Thus, they
won't change the value of the variable of the main program even
if they have the same variable name.

For example, see program P67.F90

YOU CAN **CHANGE CONSTANTS**

PROGRAM CHANGE ! INTERFACE SUBROUTINE DECREM(N) IMPLICIT NONE INTEGER, INTENT(IN OUT) :: N END SUBROUTINE DECREM END INTERFACE ! PRINT 5,1 5 FORMAT (' THE VALUE OF 1 IS ',I2) CALL DECREM(1) PRINT 5,1 END PROGRAM CHANGE ! SUBROUTINE DECREM(N) IMPLICIT NONE INTEGER, INTENT(IN OUT) :: N N = N-1 RETURN END SUBROUTINE DECREM

__OUTPUT :
__

THE VALUE OF 1 IS 1 THE VALUE OF 1 IS 0

**FUNCTION STATEMENT
**

Another type of subprogram is
a FUNCTION which returns a single value, and rather than using
a CALL statement, it is used in an assignment statement like the
SIN or SQRT built-in functions.

For example, see program P68.F90

__Conversion from real to integer ( truncation )__INT(X) : Sign of X times the largest integer |X|

This converts the expression to integer form.

INT(3.2) = 3

INT(-3.2) = -3

AINT(X) : Sign of times the largest integer |X|

Same as INT, but returns a real number.

AINT(3.2) = 3.0

AINT(-3.2) = -3.0

__Conversion from integer to real__FLOAT(N) : The real (floating point) form of the integer N.

FLOAT(2) = 2.0

__Absolute value__IABS(N) : Absolute value of N. (N is Integer)

IABS(N) = { N, if N 0 and -N, if N < 0. }

IABS(-3) = 3

ABS(X) : Absolute value of X. (X is Real)

ABS(X) = { X, if X 0 and -X, if X < 0. }

ABS(-3.2) = 3.2

__Remaindering__MOD(N,K) : The remainder when N is divided by K (i.e., N

modulo K).

The function is defined as N - INT(N/K) * K. (for integer

numbers)

MOD(17,5) = 2

MOD(8,2) = 0

MOD(-5,3) = -2

AMOD(X,A) : The remainder when X is divided by A.

Similar to MOD, but for real numbers.

The function is defined as X - AINT(X/A) * A.

MOD(3.123,1.0) = 0.123

MOD(8.0,2.0) = 0.0

MOD(-7.25,2.0) = -1.25

__Maximum and minimum__MAX0(N1,N2,N3,…) : Maximum of two or more integer

arguments.

MAX1(X1,X2,X3,…) : Maximum of two or more real arguments.

Result is converted to integer (truncated).

AMAX0(N1,N2,N3,…) : Maximum of two or more integer

arguments. Result is converted to real.

AMAX1(X1,X2,X3,…) : Maximum of two or more real arguments.

MIN0(N1,N2,N3,…) : Minimum of two or more integer

arguments.

MIN1(X1,X2,X3,…) : Minimum of two or more real arguments.

Result is converted to integer (truncated).

AMIN0(N1,N2,N3,…) : Minimum of two or more integer

arguments. Result is converted to real.

AMIN1(X1,X2,X3,…) : Minimum of two or more real arguments.

__Square root__SQRT(X) : The square root of X, where X > 0.

__Exponential and logarithmic__EXP(X) : The exponential function.

ALOG(X) : The natural logarithm, where X > 0.

ALOG10(X) : The common logarithm, where X > 0.0

__Trigonometric__SIN(X) , COS(X) ,TAN(X) where X is in radians

To change from degrees to radians, divide by 180 and multiply by

For example: Change 30

^{o}into radiansrad = 30/180* rad = --- 6

__Inverse trigonometric__ASIN(X) , ACOS(X), ATAN(X) , ATAN2(Y,X)

__Hyperbolic__SINH(X) , COSH(X), TANH(X)

On to the next lecture

Go back to lecture menu