Standard intrinsic functions
-
There are many of them
-
Useful: for concision, clarity, speed
-
Difficulty: to guess there is an intrinsic function for what you want to compute
-
Advice: skim through the list of intrinsic functions. Cf. § 13.5, physical pages 310 to 314, in the Fortran standard. Detailed descriptions are in § 13.7, physical page 316.
Elemental intrinsic functions
-
An elemental function can take either a scalar or an array argument. The function correspondingly returns a scalar or an array with the same shape.
-
If the argument is an array, then the operation is applied to each element of the array.
-
Examples :
sin(x)
,sin([x, 2*x, 3*x])
Intrinsic functions for type conversion
-
int
,floor
,ceiling
,nint
,real
, etc. -
All of them are elemental.
Elemental functions for numeric computation
-
abs
(of an integer or real number) -
mod
,modulo
-
max
,min
. Example:
a = [1, 2, 0, 0]
b = [2, 1, 2, 3]
c = [3, 1, 0, 4]
then max(a, b, c)
equals [3, 2, 2, 4]
-
sign
-
acos
,asin
,atan
,cos
,sin
,tan
-
atan2(x, y)
: returns the argument in ]-π, π] of x+iy -
sqrt
,log
,log10
,exp
,cosh
,sinh
,tanh
Etc.
The elemental intrinsic function merge
-
To merge two arrays.
merge(tsource, fsource, mask)
returnstsource
wheremask
is true andfsource
elsewhere. -
tsource
andfsource
must have the same type and be conformable. -
mask
: logical, conformable withtsource
andfsource
Example use of merge
:
T = merge(land_T, sst, land_mask)
Array reduction intrinsic functions
-
Basic use case: a reduction function applies some operation to a whole array and returns a single scalar (« reduction » : from array to scalar)
-
On a numerical array:
sum
,product
,minval
,maxval
-
On a logical array:
any
(logical or),all
(logical and),count
(number of true values) -
Examples :
any(m==m2)
returns.true.
all(m==m2)
returns.false.
count(m==m2)
returns 3sum(m)
returns 21
Dot product
dot_product(vector_a, vector_b)
- On vectors of the same size
- Equivalent to:
sum(vector_a * vector_b)
- Better to use
dot_product
, clearer and possibly faster
Matrix product and transpose
-
matmul(matrix_a, matrix_b)
-
2 arrays of rank 2 or 1 array of rank 2 and 1 vector
-
The first subscript for a rank 2 array is here assumed to be the row subscript.
-
Constraint on extents so that the matrix product is well defined.
-
-
transpose(matrix)
on a rank-2 array of any type.
Location of an extremum
minloc(array{, mask})
,maxloc(array{, mask})
- Result: vector of subscripts of the first extremum found
- Examples :
minloc(V)
returns[2]
minloc(A, mask=A>-4)
returns[1, 2]