Intrinsic functions

Fortran provides many built-in functions, called intrinsic functions. To use one of these functions, you need to know:




Function

Argument

Result

Explanation





ABS(X)

integer, real or complex

Integer real complex

The absolute value





ACHAR(I)

integer

character

Integer to ASCII character





ACOS(X)

real

real

Arc cosine





ADJUSTL(STR)

character

character

Left adjustment (remove blanks)





ADJUSTR(STR)

character

character

Right adjustment





AIMAG(Z)

complex

real

Imaginary part





AINT(X)

real

real

Truncate to a whole number





ALL(MASK [, DIM])

MASK is a logical and not scalar, DIM is an integer

logical

True if all elements == mask





ALLOCATED(X)

array of any type

logical

True if allocated in memory





ANINT(X)

real

real

Round to nearest integer





ANY(MASK [, DIM])

MASK is a logical and not scalar, DIM is an integer

logical

True if all elemnts == mask





ASIN(X)

real

real

Arc sine





ASSOCIATED(PTR [, TGT])

PTR is a pointer, TGT is a pointer or target

logical

determines the status of the pointer PTR or if PTR is associated with the target TGT.





ATAN(X)

real

real

Arc tangent





ATAN2(Y,X)

X+iY with X and Y reals

real

Arc tangent





BIT_SIZE(I)

integer

integer

Number of bits in argument





BTEST(I,POS)

I is an integer, POS is an integer

logical

Test a bit of an integer





CEILING(X)

real

real

Least integer <= argument





CHAR(I [, KIND])

integer

character

Integer to ASCCI character





CMPLX(X,Y)

reals

complex

Convert to complex number





CONJG(Z)

complex

complex

Conjugate the imaginary part





COS(X)

real

real

Cosine





COSH(X)

real

real

Hyperbolic cosine





COUNT(mask [,DIM])

mask is logical and non scalar, dim is integer

integer

Count of true entries in mask





CPU_TIME(X)

real

real

Returns the elapsed CPU time in seconds.





CSHIFT(A, shift [,DIM])

A is an array of any type, shift and dim are integers

array

Circular shift of elements





DATE_AND_TIME([DATE, TIME, ZONE, VALUES])

DATE is CHARACTER(LEN=8), TIME is CHARACTER(LEN=10), ZONE is CHARACTER(LEN=5)

VALUES is INTEGER(8)

Realtime clock





DBLE(X)

integer, real or complex

double precision

Convert to double precision





DIGITS(X)

integer or real

integer

Number of bits in argument





DIM(X,Y)

integers or reals

same type as inputs

returns the di erence if the result is positive; otherwise returns zero.





DOT_PRODUCT(VECTOR_A,  VECTOR_B)

1D array

If the arguments are numeric, the return value is a scalar of numeric type, INTEGER, REAL, or COMPLEX. If the arguments are LOGICAL, the return value is .TRUE. or .FALSE.

Dot product





DPROD(X,Y)

real

double precision

Double precision dot prod.





EOSHIFT(ARRAY, SHIFT [, BOUNDARY, DIM])

ARRAY is an array of any type, not scalar. SHIFT is integer, BOUNDARY is like ARRAY, DIM is INTEGER

same type and rank as the ARRAY argument

Array element shift





EPSILON(X)

real

real

Smallest positive number





EXP(X)

real, complex

same type and kind as X

Exponential





EXPONENT(X)

real

integer

Model exponenet of argument





FLOOR(X)

real

integer

Integer <= argument





FRACTION(X)

real

real

Fractional pert of argument





HUGE(X)

real or integer

same type and kind as X

Largest number





IACHAR(C [, KIND])

C is a scalar CHARACTER, KIND is integer

INTEGER and of kind KIND. If KIND is absent, the return value is of default integer kind.

Integer value of argument





IAND(I, J)

integer

integer

Bitwise logical and





IBCLR(I, POS)

integer

integer

Setting a bit to 0 in position pos





IBITS(I, POS, LEN)

integer

integer

Extract len bits from pos





IBSET(I, POS)

integer

integer

Set pos bit to one





ICHAR(C [, KIND])

C is a scalar CHARACTER, KIND is integer

integer of type KIND or default integer if KIND is missing

ASCII number of argument





IEOR(I,J)

integer

integer

Bitwise logical XOR





INDEX(STRING,  SUBSTRING [, BACK [, KIND]])

STRING and SUBSTRING are scalar characters, BACK is a scalar logical and KIND is integer

integer of type KIND or default integer if KIND is missing

Position of substring





INT(X [, KIND))

X is integer, real or complex and kind is integer

integer

Convert to integer type





IOR(I, J)

integer

integer

bitwise Boolean inclusive-OR of I and J





ISHFT(I, SHIFT)

integer

integer

Shift bits by shift





ISHFTC(I, SHIFT)

integer

integer

Shift circular bits in argument





KIND(X)

LOGICAL, INTEGER, REAL, COMPLEX or CHARACTER

integer

the kind value of the entity X





LBOUND (ARRAY [, DIM [, KIND]])

ARRAY is an array of any type, DIM and KIN are integers

integer of kind KIND (default integer if KIND is missing)

Lower dimension bounds of an array





LEN(STRING [, KIND])

STRING is a scalar or array of type CHARACTER, KIND is integer

integer

Length of a character entity





LEN_TRIM (STRING [, KIND])

STRING is a scalar or array of type CHARACTER, KIND is integer

integer

Length of a character entity without trailing blank characters





LGE (STRING_A, STRING_B)

characters

logical

Lexical greater than or equal





LGT (STRING_A, STRING_B)

characters

logical

Lexical greater than





LLE (STRING_A, STRING_B)

characters

logical

Lexical less than or equal





LLT (STRING_A, STRING_B)

characters

logical

Lexical less than





LOG(X)

REAL or COMPLEX

REAL or COMPLEX

Natural logarithm function





LOG10(X)

REAL or COMPLEX

REAL or COMPLEX

Base 10 logarithm function





LOGICAL (L [, KIND])

L is logical, KIND is integer

logical

Converts one kind of LOGICAL variable to another





MATMUL (MATRIX_A,  MATRIX_B)

arrays of INTEGER, REAL, COMPLEX, or LOGICAL type, with a rank of one or two

array

Performs a matrix multiplication on numeric or logical arguments.





MAX (A1, A2  [, A3 [, ...]])

integers or reals

same type as the rst argument

Returns the argument with the largest (most positive) value.





MAXEXPONENT(X)

REAL

integer

Maximum exponent of a real kind





MAXLOC (ARRAY [, DIM , MASK])

ARRAY is an array of type INTEGER or REAL, DIM is integer and MASK an array of type LOGICAL, and conformable with ARRAY

integer (array or scalar depending on the call)

Location of the maximum value within an array





MAXVAL (ARRAY [, DIM , MASK])

ARRAY is an array of type INTEGER or REAL, DIM is integer and MASK an array of type LOGICAL, and conformable with ARRAY

integer (array or scalar)

Maximum value of an array





MERGE (TSOURCE,  FSOURCE, MASK)

TSOURCE is of any type, FSOURCE is like TSOURCE, MASK is of type LOGICAL

The result is of the same type and type parameters as TSOURCE

Select values from two arrays according to a logical mask. The result is equal to TSOURCE if MASK is .TRUE., or equal to FSOURCE if it is .FALSE..





REAL(A [, KIND])

A is INTEGER, REAL, or COMPLEX. KIND is integer

real

Convert to real type





REPEAT (STRING, NCOPIES)

STRING is a scalar of type CHARACTER. NCOPIES is integer

characters

Repeated string concatenation





RESHAPE (SOURCE, SHAPE  [, PAD, ORDER])

SOURCE is an array of any type, SHAPE is of type INTEGER and an array of rank one.PAD is an array of the same type as SOURCE. ORDER is of type INTEGER and an array of the same shape as SHAPE.

array of shape SHAPE with the same type as SOURCE.

Function to reshape an array





RRSPACING(X)

real

real

Reciprocal of the relative spacing





SCALE(X,I)

X is real, I is integer

real

Scale a real value i.e. returns X * RADIX(X)**I





SCAN (STRING, SET [, BACK [, KIND]])

STRING is a string of characters, SET is character, BACK is logical, KIND is integer

integer

Scan a string for the presence of a set of characters





SELECTED_INT_KIND(R)

integer

integer

the kind value of the smallest integer type that can represent all values ranging from -10^R (exclusive) to 10^R (exclusive).





SELECTED_REAL_KIND (P,R, RADIX)

integers

integer

the kind value of a real data type with decimal precision of at least P digits, exponent range of at least R, and with a radix of RADIX.





SET_EXPONENT (X, I)

X is real, I is integer

real

returns the real number whose fractional part is that that of X and whose exponent part is I.





SHAPE (SOURCE [, KIND])

SOURCE is an array or scalar of any type.i KIND is integer

integer (scalar or array)

Determines the shape of an array.





SIGN(A, B)

integer or real

integer or real

the value of A with the sign of B.





SIN(X)

real or complex

real or complex

Sine function





SINH

real or complex

real or complex

Hyperbolic sine function





SIZE (ARRAY[, DIM  [, KIND]])

ARRAY is an array of any type, DIM and KIND are integers

integer

Determine the size of an array





SPREAD (SOURCE, DIM, NCOPIES)

SOURCE is a scalar or an array of any type. DIM and NCOPIES are integers

an array of the same type as SOURCE and has rank n+1 where n equals the rank of SOURCE.

Add a dimension to an array





SQRT(X)

real or complex

real or complex

Square-root function





SUM (ARRAY, DIM[, MASK])

ARRAY is an array of INTEGER, REAL or COMPLEX, DIM is integer, MASK is LOGICAL and either be a scalar or an array of the same shape as ARRAY.

The result is of the same type as ARRAY.

Sum of array elements





SYSTEM_CLOCK ([COUNT, COUNT_RATE, COUNT_MAX])

COUNT and COUNT_MAX are integers. COUNT_RATE is integer or REAL

NONE as it is a subroutine and not a function...

Time function





TAN(X)

real or complex

real or complex

Tangent function





TANH(X)

real or complex

real or complex

Hyperbolic tangent function





TINY(X)

real

real

Smallest positive number of a real kind





UNPACK (VECTOR, MASK, FIELD)

VECTOR is an array of any type and rank one. MASK is an array of type LOGICAL. FIELD is of the same type as VECTOR and have the same shape as MASK.

same type as VECTOR

The resulting array corresponds to FIELD with TRUE elements of MASK replaced by values from VECTOR in array element order.





VERIFY (STRING, SET [, BACK [, KIND]])

STRING and SET are of type CHARACTER, BACK is logical, KIND is integer

The return value is of type INTEGER and of kind KIND.

Scan a string for characters not a given set