- Intrinsic functions in Fortran 90 are shown in this page.
- Functions introduced in this page are chosen based on webmaster's liking.
- Classification of function is carried out following this page.
- Explanation of functions are made following gfortran manual.
- A few convenient subroutine by GNU extension are added in this page's item, such as 'getarg' and 'system'
- Classification of functions in this page is shown below:
Outline of this page
1. Numerical functions
ABS : Absolute value
Description:
ABS(A) computes the absolute value of A.
Class:
Elemental function
Syntax:
RESULT = ABS(A) |
Arguments:
A : The type of the argument shall be an INTEGER, REAL, or COMPLEX.
Return value:
The return value is of the same type and kind as the argument except the return value is REAL for a COMPLEX argument.
Example:
program test_abs integer :: i = -1 real :: x = -1.e0 complex :: z = (-1.e0,0.e0) i = abs(i) x = abs(x) x = abs(z) end program test_abs |
AIMAG : Imaginary part of complex number
Description:
AIMAG(Z) yields the imaginary part of complex argument Z.
Class:
Elemental function
Syntax:
RESULT = AIMAG(Z) |
Arguments:
Z : The type of the argument shall be COMPLEX.
Return value:
The return value is of type REAL with the kind type parameter of the argument.
Example:
program test_aimag complex(4) z4 complex(8) z8 z4 = cmplx(1.e0_4, 0.e0_4) z8 = cmplx(0.e0_8, 1.e0_8) print *, aimag(z4), dimag(z8) end program test_aimag |
AINT : Truncate to a whole number
Description:
AINT(A [, KIND]) truncates its argument to a whole number.
Class:
Elemental function
Syntax:
RESULT = AINT(A [, KIND]) |
Arguments:
- A : The type of the argument shall be REAL.
- KIND : (Optional) An INTEGER initialization expression indicating the kind parameter of the result.
Return value:
- The return value is of type REAL with the kind type parameter of the argument if the optional KIND is absent; otherwise, the kind type parameter will be given by KIND.
- If the magnitude of X is less than one, AINT(X) returns zero.
- If the magnitude is equal to or greater than one then it returns the largest whole number that does not exceed its magnitude.
- The sign is the same as the sign of X.
Example:
program test_aint real(4) x4 real(8) x8 x4 = 1.234E0_4 x8 = 4.321_8 print *, aint(x4), dint(x8) x8 = aint(x4,8) end program test_aint |
ANINT : Nearest whole number
Description:
ANINT(A [, KIND]) rounds its argument to the nearest whole number.
Class:
Elemental function
Syntax:
RESULT = ANINT(A [, KIND]) |
Arguments:
- A : The type of the argument shall be REAL.
- KIND : (Optional) An INTEGER initialization expression indicating the kind parameter of the result.
Return value:
- The return value is of type real with the kind type parameter of the argument if the optional KIND is absent; otherwise, the kind type parameter will be given by KIND.
- If A is greater than zero, ANINT(A) returns AINT(X+0.5).
- If A is less than or equal to zero then it returns AINT(X-0.5).
Example:
program test_anint real(4) x4 real(8) x8 x4 = 1.234E0_4 x8 = 4.321_8 Chapter 8: Intrinsic Procedures 73 print *, anint(x4), dnint(x8) x8 = anint(x4,8) end program test_anint |
CEILING : Integer ceiling function
Description:
CEILING(A) returns the least integer greater than or equal to A.
Class:
Elemental function
Syntax:
RESULT = CEILING(A [, KIND]) |
Arguments:
- A : The type shall be REAL.
- KIND : (Optional) An INTEGER initialization expression indicating the kind parameter of the result.
Return value:
The return value is of type INTEGER(KIND) if KIND is present and a defaultkind INTEGER otherwise.
Example:
program test_ceiling real :: x = 63.29 real :: y = -63.59 print *, ceiling(x) ! returns 64 print *, ceiling(y) ! returns -63 end program test_ceiling |
CMPLX : Complex conversion function
Description:
- CMPLX(X [, Y [, KIND]]) returns a complex number where X is converted to the real component.
- If Y is present it is converted to the imaginary component.
- If Y is not present then the imaginary component is set to 0.0.
- If X is complex then Y must not be present.
Class:
Elemental function
Syntax:
RESULT = CMPLX(X [, Y [, KIND]]) |
Arguments:
- X : The type may be INTEGER, REAL, or COMPLEX.
- Y : (Optional; only allowed if X is not COMPLEX.) May be INTEGER or REAL.
- KIND : (Optional) An INTEGER initialization expression indicating the kind parameter of the result.
Return value:
- The return value is of COMPLEX type, with a kind equal to KIND if it is specified.
- If KIND is not specified, the result is of the default COMPLEX kind, regardless of the kinds of X and Y.
Example:
program test_cmplx integer :: i = 42 real :: x = 3.14 complex :: z z = cmplx(i, x) print *, z, cmplx(x) end program test_cmplx |
CONJG : Complex conjugate function
Description:
- CONJG(Z) returns the conjugate of Z.
- If Z is (x, y) then the result is (x, -y)
Class:
Elemental function
Syntax:
Z = CONJG(Z) |
Arguments:
Z : The type shall be COMPLEX.
Return value:
The return value is of type COMPLEX.
Example:
program test_conjg complex :: z = (2.0, 3.0) complex(8) :: dz = (2.71_8, -3.14_8) z= conjg(z) print *, z dz = dconjg(dz) print *, dz end program test_conjg |
DBLE : Double conversion function
Description:
DBLE(A) Converts A to double precision real type.
Class:
Elemental function
Syntax:
RESULT = DBLE(A) |
Arguments:
A : The type shall be INTEGER, REAL, or COMPLEX.
Return value:
The return value is of type double precision real.
Example:
program test_dble real :: x = 2.18 integer :: i = 5 complex :: z = (2.3,1.14) print *, dble(x), dble(i), dble(z) end program test_dble |
DIM : Positive difference
Description:
DIM(X,Y) returns the difference X-Y if the result is positive; otherwise returns zero.
Class:
Elemental function
Syntax:
RESULT = DIM(X, Y) |
Arguments:
- X : The type shall be INTEGER or REAL
- Y : The type shall be the same type and kind as X.
Return value:
The return value is of type INTEGER or REAL.
Example:
program test_dim integer :: i real(8) :: x i = dim(4, 15) x = dim(4.345_8, 2.111_8) print *, i print *, x end program test_dim |
DPROD : Double product function
Description:
DPROD(X,Y) returns the product X*Y.
Class:
Elemental function
Syntax:
RESULT = DPROD(X, Y) |
Arguments:
- X : The type shall be REAL.
- Y : The type shall be REAL.
Return value:
The return value is of type REAL(8).
Example:
program test_dprod real :: x = 5.2 real :: y = 2.3 real(8) :: d d = dprod(x,y) print *, d end program test_dprod |
FLOOR : Integer floor function
Description:
FLOOR(A) returns the greatest integer less than or equal to X.
Class:
Elemental function
Syntax:
RESULT = FLOOR(A [, KIND]) |
Arguments:
- A : The type shall be REAL.
- KIND : (Optional) An INTEGER initialization expression indicating the kind parameter of the result.
Return value:
The return value is of type INTEGER(KIND) if KIND is present and of defaultkind INTEGER otherwise.
Example:
program test_floor real :: x = 63.29 real :: y = -63.59 print *, floor(x) ! returns 63 print *, floor(y) ! returns -64 end program test_floor |
INT : Convert to integer type
Description:
Convert to integer type
Class:
Elemental function
Syntax:
RESULT = INT(A [, KIND)) |
Arguments:
- A : Shall be of type INTEGER, REAL, or COMPLEX.
- KIND : (Optional) An INTEGER initialization expression indicating the kind parameter of the result.
Return value:
These functions return a INTEGER variable or array under the following rules:
- (A) If A is of type INTEGER, INT(A) = A
- (B) If A is of type REAL and |A| < 1, INT(A) equals 0. If |A| >= 1, then INT(A) equals the largest integer that does not exceed the range of A and whose sign is the same as the sign of A.
- (C) If A is of type COMPLEX, rule B is applied to the real part of A.
Example:
program test_int integer :: i = 42 complex :: z = (-3.7, 1.0) print *, int(i) print *, int(z), int(z,8) end program |
MAX : Maximum value of an argument list
Description:
Returns the argument with the largest (most positive) value.
Class:
Elemental function
Syntax:
RESULT = MAX(A1, A2 [, A3 [, ...]]) |
Arguments:
- A1 : The type shall be INTEGER or REAL.
- A2, A3, ... : An expression of the same type and kind as A1. (As a GNU extension, arguments of different kinds are permitted.)
Return value:
The return value corresponds to the maximum value among the arguments, and has the same type and kind as the first argument.
MIN : Minimum value of an argument list
Description:
Returns the argument with the smallest (most negative) value.
Class:
Elemental function
Syntax:
RESULT = MIN(A1, A2 [, A3, ...]) |
Arguments:
- A1 : The type shall be INTEGER or REAL.
- A2, A3, ... : An expression of the same type and kind as A1. (As a GNU extension, arguments of different kinds are permitted.)
Return value:
The return value corresponds to the maximum value among the arguments, and has the same type and kind as the first argument.
MOD : Remainder function
Description:
- MOD(A,P) computes the remainder of the division of A by P.
- It is calculated as A - (INT(A/P) * P).
Class:
Elemental function
Syntax:
RESULT = MOD(A, P) |
Arguments:
- A : Shall be a scalar of type INTEGER or REAL
- P : Shall be a scalar of the same type as A and not equal to zero
Return value:
The kind of the return value is the result of cross-promoting the kinds of the arguments.
Example:
program test_mod print *, mod(17,3) print *, mod(17.5,5.5) print *, mod(17.5d0,5.5) print *, mod(17.5,5.5d0) print *, mod(-17,3) print *, mod(-17.5,5.5) print *, mod(-17.5d0,5.5) print *, mod(-17.5,5.5d0) print *, mod(17,-3) print *, mod(17.5,-5.5) print *, mod(17.5d0,-5.5) print *, mod(17.5,-5.5d0) end program test_mod |
NINT : Nearest whole number
Description:
NINT(A) rounds its argument to the nearest whole number.
Class:
Elemental function
Syntax:
RESULT = NINT(A [, KIND]) |
Arguments:
- A : The type of the argument shall be REAL.
- KIND : (Optional) An INTEGER initialization expression indicating the kind parameter of the result.
Return value:
Returns A with the fractional portion of its magnitude eliminated by rounding to the nearest whole number and with its sign preserved, converted to an INTEGER of the default kind.
Example:
program test_nint real(4) x4 real(8) x8 x4 = 1.234E0_4 x8 = 4.321_8 print *, nint(x4), idnint(x8) end program test_nint |
REAL : Convert to real type
Description:
REAL(A [, KIND]) converts its argument A to a real type.
Class:
Elemental function
Syntax:
RESULT = REAL(A [, KIND]) RESULT = REALPART(Z) |
Arguments:
- A : Shall be INTEGER, REAL, or COMPLEX.
- KIND : (Optional) An INTEGER initialization expression indicating the kind parameter of the result.
Return value:
These functions return a REAL variable or array under the following rules:
- (A) REAL(A) is converted to a default real type if A is an integer or real variable.
- (B) REAL(A) is converted to a real type with the kind type parameter of A if A is a complex variable.
- (C) REAL(A, KIND) is converted to a real type with kind type parameter KIND if A is a complex, integer, or real variable.
Example:
program test_real complex :: x = (1.0, 2.0) print *, real(x), real(x,8), realpart(x) end program test_real |
SIGN : Sign copying function
Description:
SIGN(A,B) returns the value of A with the sign of B.
Class:
Elemental function
Syntax:
RESULT = SIGN(A, B) |
Arguments:
- A : Shall be of type INTEGER or REAL
- B : Shall be of the same type and kind as A
Return value:
- The kind of the return value is that of A and B.
- If B >= 0 then the result is ABS(A), else it is -ABS(A).
Example:
program test_sign print *, sign(-12,1) print *, sign(-12,0) print *, sign(-12,-1) print *, sign(-12.,1.) print *, sign(-12.,0.) print *, sign(-12.,-1.) end program test_sign |
2. Mathematical functions
ACOS : Arccosine function
Description:
ACOS(X) computes the arccosine of X (inverse of COS(X)).
Class:
Elemental function
Syntax:
RESULT = ACOS(X) |
Arguments:
X : The type shall either be REAL with a magnitude that is less than or equal to one - or the type shall be COMPLEX.
Return value:
- The return value is of the same type and kind as X.
- The real part of the result is in radians and lies in the range 0 <= Re(acos(x)) <= pi.
Example:
program test_acos real(8) :: x = 0.866_8 x = acos(x) end program test_acos |
ASIN : Arcsine function
Description:
ASIN(X) computes the arcsine of its X (inverse of SIN(X)).
Class:
Elemental function
Syntax:
RESULT = ASIN(X) |
Arguments:
X : The type shall be either REAL and a magnitude that is less than or equal to one - or be COMPLEX.
Return value:
- The return value is of the same type and kind as X.
- The real part of the result is in radians and lies in the range -pi/2<=Re(asin(x))<=pi/2.
Example:
program test_asin real(8) :: x = 0.866_8 x = asin(x) end program test_asin |
ATAN : Arctangent function
Description:
ATAN(X) computes the arctangent of X.
Class:
Elemental function
Syntax:
RESULT = ATAN(X) RESULT = ATAN(Y, X) |
Arguments:
- X : The type shall be REAL or COMPLEX; if Y is present, X shall be REAL.
- Y : Shall be of the same type and kind as X.
Return value:
- The return value is of the same type and kind as X.
- If Y is present, the result is identical to ATAN2(Y,X).
- Otherwise, it the arcus tangent of X, where the real part of the result is in radians and lies in the range -pi/2<Re(atan(x))<=pi/2.
Example:
program test_atan real(8) :: x = 2.866_8 x = atan(x) end program test_atan |
ATAN2 : Arctangent function
Description:
- ATAN2(Y, X) computes the principal value of the argument function of the complex number X+iY .
- This function can be used to transform from Cartesian into polar coordinates and allows to determine the angle in the correct quadrant.
Class:
Elemental function
Syntax:
RESULT = ATAN2(Y, X) |
Arguments:
- Y : The type shall be REAL.
- X : The type and kind type parameter shall be the same as Y. If Y is zero, then X must be nonzero.
Return value:
- The return value has the same type and kind type parameter as Y.
- It is the principal value of the complex number X + iY .
- If X is nonzero, then it lies in the range -pi <= atan(x) <= pi.
- The sign is positive if Y is positive.
- If Y is zero, then the return value is zero if X is strictly positive, pi if X is negative and Y is positive zero (or the processor does not handle signed zeros), and -pi if X is negative and Y is negative zero.
- Finally, if X is zero, then the magnitude of the result is pi/2.
Example:
program test_atan2 real(4) :: x = 1.e0_4, y = 0.5e0_4 x = atan2(y,x) end program test_atan2 |
COS : Cosine function
Description:
COS(X) computes the cosine of X.
Class:
Elemental function
Syntax:
RESULT = COS(X) |
Arguments:
X : The type shall be REAL or COMPLEX.
Return value:
- The return value is of the same type and kind as X.
- The real part of the result is in radians.
- If X is of the type REAL, the return value lies in the range -1<= cos(x) <= 1.
Example:
program test_cos real :: x = 0.0 x = cos(x) end program test_cos |
COSH : Hyperbolic cosine function
Description:
COSH(X) computes the hyperbolic cosine of X.
Class:
Elemental functionSyntax:
X = COSH(X) |
Arguments:
X : The type shall be REAL or COMPLEX.
Return value:
- The return value has same type and kind as X.
- If X is complex, the imaginary part of the result is in radians.
- If X is REAL, the return value has a lower bound of one, cosh(x) >= 1.
Example:
program test_cosh real(8) :: x = 1.0_8 x = cosh(x) end program test_cosh |
EXP : Exponential function
Description:
EXP(X) computes the base e exponential of X.
Class:
Elemental function
Syntax:
RESULT = EXP(X) |
Arguments:
X : The type shall be REAL or COMPLEX.
Return value:
The return value has same type and kind as X.
Example:
program test_exp real :: x = 1.0 x = exp(x) end program test_exp |
LOG : Natural logarithm function
Description:
LOG(X) computes the natural logarithm of X, i.e. the logarithm to the base e.
Class:
Elemental function
Syntax:
RESULT = LOG(X) |
Arguments:
X : The type shall be REAL or COMPLEX.
Return value:
- The return value is of type REAL or COMPLEX.
- The kind type parameter is the same as X.
- If X is COMPLEX, the imaginary part omega is in the range -pi<= omega <=pi.
Example:
program test_log real(8) :: x = 2.7182818284590451_8 complex :: z = (1.0, 2.0) x = log(x) ! will yield (approximately) 1 z = log(z) end program test_log |
LOG10 : Base 10 logarithm function
Description:
LOG10(X) computes the base 10 logarithm of X.
Class:
Elemental function
Syntax:
RESULT = LOG10(X) |
Arguments:
X : The type shall be REAL.
Return value:
- The return value is of type REAL or COMPLEX.
- The kind type parameter is the same as X.
Example:
program test_log10 real(8) :: x = 10.0_8 x = log10(x) end program test_log10 |
SIN : Sine function
Description:
SIN(X) computes the sine of X.
Class:
Elemental function
Syntax:
RESULT = SIN(X) |
Arguments:
X : The type shall be REAL or COMPLEX.
Return value:
The return value has same type and kind as X.
Example:
program test_sin real :: x = 0.0 x = sin(x) end program test_sin |
SINH : Hyperbolic sine function
Description:
SINH(X) computes the hyperbolic sine of X.
Class:
Elemental function
Syntax:
RESULT = SINH(X) |
Arguments:
X : The type shall be REAL or COMPLEX.
Return value:
The return value has same type and kind as X.
Example:
program test_sinh real(8) :: x = - 1.0_8 x = sinh(x) end program test_sinh |
SQRT : Square-root function
Description:
SQRT(X) computes the square root of X.
Class:
Elemental function
Syntax:
RESULT = SQRT(X) |
Arguments:
X : The type shall be REAL or COMPLEX.
Return value:
- The return value is of type REAL or COMPLEX.
- The kind type parameter is the same as X.
Example:
program test_sqrt real(8) :: x = 2.0_8 complex :: z = (1.0, 2.0) x = sqrt(x) z = sqrt(z) end program test_sqrt |
TAN : Tangent function
Description:
TAN(X) computes the tangent of X.
Class:
Elemental function
Syntax:
RESULT = TAN(X) |
Arguments:
X : The type shall be REAL or COMPLEX.
Return value:
The return value has same type and kind as X.
Example:
program test_tan real(8) :: x = 0.165_8 x = tan(x) end program test_tan |
TANH : Hyperbolic tangent function
Description:
TANH(X) computes the hyperbolic tangent of X.
Class:
Elemental function
Syntax:
X = TANH(X) |
Arguments:
X : The type shall be REAL or COMPLEX.
Return value:
- The return value has same type and kind as X.
- If X is complex, the imaginary part of the result is in radians.
- If X is REAL, the return value lies in the range -1<= tanh(x) <= 1.
Example:
program test_tanh real(8) :: x = 2.1_8 x = tanh(x) end program test_tanh |
3. Character string functions
ACHAR : Character in ASCII collating sequence
Description:
ACHAR(I) returns the character located at position I in the ASCII collating sequence.
Class:
Elemental function
Syntax:
RESULT = ACHAR(I [, KIND]) |
Arguments:
- I : The type shall be INTEGER.
- KIND : (Optional) An INTEGER initialization expression indicating the kind parameter of the result.
Return value:
- The return value is of type CHARACTER with a length of one.
- If the KIND argument is present, the return value is of the specified kind and of the default kind otherwise.
Example:
program test_achar character c c = achar(32) end program test_achar |
ADJUSTL : Left adjust a string
Description:
- ADJUSTL(STRING) will left adjust a string by removing leading spaces.
- Spaces are inserted at the end of the string as needed.
Class:
Elemental function
Syntax:
RESULT = ADJUSTL(STRING) |
Arguments:
STRING : The type shall be CHARACTER.
Return value:
The return value is of type CHARACTER and of the same kind as STRING where leading spaces are removed and the same number of spaces are inserted on the end of STRING.
Example:
program test_adjustl character(len=20) :: str = ' gfortran' str = adjustl(str) print *, str end program test_adjustl |
ADJUSTR : Right adjust a string
Description:
- ADJUSTR(STRING) will right adjust a string by removing trailing spaces.
- Spaces are inserted at the start of the string as needed.
Class:
Elemental function
Syntax:
RESULT = ADJUSTR(STRING) |
Arguments:
STRING : The type shall be CHARACTER.
Return value:
The return value is of type CHARACTER and of the same kind as STRING where trailing spaces are removed and the same number of spaces are inserted at the start of STRING.
Example:
program test_adjustr character(len=20) :: str = 'gfortran' str = adjustr(str) print *, str end program test_adjustr |
IACHAR : Code in ASCII collating sequence
Description:
IACHAR(C) returns the code for the ASCII character in the first character position of C.
Class:
Elemental function
Syntax:
RESULT = IACHAR(C [, KIND]) |
Arguments:
- C : Shall be a scalar CHARACTER, with INTENT(IN)
- KIND : (Optional) An INTEGER initialization expression indicating the kind parameter of the result.
Return value:
- The return value is of type INTEGER and of kind KIND.
- If KIND is absent, the return value is of default integer kind.
Example:
program test_iachar integer i i = iachar(' ') end program test_iachar |
ICHAR : Character-to-integer conversion function
Description:
- ICHAR(C) returns the code for the character in the first character position of C in the system's native character set.
- The correspondence between characters and their codes is not necessarily the same across different GNU Fortran implementations.
Class:
Elemental function
Syntax:
RESULT = ICHAR(C [, KIND]) |
Arguments:
- C : Shall be a scalar CHARACTER, with INTENT(IN)
- KIND : (Optional) An INTEGER initialization expression indicating the kind parameter of the result.
Return value:
- The return value is of type INTEGER and of kind KIND.
- If KIND is absent, the return value is of default integer kind.
Example:
program test_ichar integer i i = ichar(' ') end program test_ichar |
Note: No intrinsic exists to convert between a numeric value and a formatted character string representation -- for instance, given the CHARACTER value '154', obtaining an INTEGER or REAL value with the value 154, or vice versa. Instead, this functionality is provided by internal-file I/O, as in the following Example:
program read_val integer value character(len=10) string, string2 string = '154' Chapter 8: Intrinsic Procedures 137 ! Convert a string to a numeric value read (string,'(I10)') value print *, value ! Convert a value to a formatted string write (string2,'(I10)') value print *, string2 end program read_val |
CHAR : Character conversion function
Description:
CHAR(I [, KIND]) returns the character represented by the integer I.
Class:
Elemental function
Syntax:
RESULT = CHAR(I [, KIND]) |
Arguments:
- I : The type shall be INTEGER.
- KIND : (Optional) An INTEGER initialization expression indicating the kind parameter of the result.
Return value:
The return value is of type CHARACTER(1)
Example:
program test_char integer :: i = 74 character(1) :: c c = char(i) print *, i, c ! returns 'J' end program test_char |
INDEX : Position of a substring within a string
Description:
- Returns the position of the start of the first occurrence of string SUBSTRING as a substring in STRING, counting from one.
- If SUBSTRING is not present in STRING, zero is returned.
- If the BACK argument is present and true, the return value is the start of the last occurrence rather than the first.
Class:
Elemental function
Syntax:
RESULT = INDEX(STRING, SUBSTRING [, BACK [, KIND]]) |
Arguments:
- STRING : Shall be a scalar CHARACTER, with INTENT(IN)
- SUBSTRING : Shall be a scalar CHARACTER, with INTENT(IN)
- BACK : (Optional) Shall be a scalar LOGICAL, with INTENT(IN)
- KIND : (Optional) An INTEGER initialization expression indicating the kind parameter of the result.
Return value:
- The return value is of type INTEGER and of kind KIND.
- If KIND is absent, the return value is of default integer kind.
LEN : Length of a character entity
Description:
- Returns the length of a character string.
- If STRING is an array, the length of an element of STRING is returned.
- Note that STRING need not be defined when this intrinsic is invoked, since only the length, not the content, of STRING is needed.
Class:
Inquiry function
Syntax:
L = LEN(STRING [, KIND]) |
Arguments:
- STRING : Shall be a scalar or array of type CHARACTER, with INTENT(IN)
- KIND : (Optional) An INTEGER initialization expression indicating the kind parameter of the result.
Return value:
- The return value is of type INTEGER and of kind KIND.
- If KIND is absent, the return value is of default integer kind.
LEN_TRIM : Length of a character entity without trailing blank characters
Description:
Returns the length of a character string, ignoring any trailing blanks.
Class:
Elemental function
Syntax:
RESULT = LEN_TRIM(STRING [, KIND]) |
Arguments:
- STRING : Shall be a scalar of type CHARACTER, with INTENT(IN)
- KIND : (Optional) An INTEGER initialization expression indicating the kind parameter of the result.
Return value:
- The return value is of type INTEGER and of kind KIND.
- If KIND is absent, the return value is of default integer kind.
REPEAT : Repeated string concatenation
Description:
Concatenates NCOPIES copies of a string.
Class:
Transformational function
Syntax:
RESULT = REPEAT(STRING, NCOPIES) |
Arguments:
- STRING : Shall be scalar and of type CHARACTER.
- NCOPIES : Shall be scalar and of type INTEGER.
Return value:
A new scalar of type CHARACTER built up from NCOPIES copies of STRING.
Example:
program test_repeat write(*,*) repeat("x", 5) ! "xxxxx" end program |
SCAN : Scan a string for the presence of a set of characters
Description:
- Scans a STRING for any of the characters in a SET of characters.
- If BACK is either absent or equals FALSE, this function returns the position of the leftmost character of STRING that is in SET.
- If BACK equals TRUE, the rightmost position is returned.
- If no character of SET is found in STRING, the result is zero.
Class:
Elemental function
Syntax:
RESULT = SCAN(STRING, SET[, BACK [, KIND]]) |
Arguments:
- STRING : Shall be of type CHARACTER.
- SET : Shall be of type CHARACTER.
- BACK : (Optional) shall be of type LOGICAL.
- KIND : (Optional) An INTEGER initialization expression indicating the kind parameter of the result.
Return value:
- The return value is of type INTEGER and of kind KIND.
- If KIND is absent, the return value is of default integer kind.
Example:
PROGRAM test_scan WRITE(*,*) SCAN("FORTRAN", "AO") ! 2, found 'O' WRITE(*,*) SCAN("FORTRAN", "AO", .TRUE.) ! 6, found 'A' WRITE(*,*) SCAN("FORTRAN", "C++") ! 0, found none END PROGRAM |
TRIM : Remove trailing blank characters of a string
Description:
Removes trailing blank characters of a string.
Class:
Transformational function
Syntax:
RESULT = TRIM(STRING) |
Arguments:
STRING : Shall be a scalar of type CHARACTER.
Return value:
A scalar of type CHARACTER which length is that of STRING less the number of trailing blanks.
Example:
PROGRAM test_trim CHARACTER(len=10), PARAMETER :: s = "GFORTRAN " WRITE(*,*) LEN(s), LEN(TRIM(s)) ! "10 8", with/without trailing blanks END PROGRAM |
VERIFY : Scan a string for characters not a given set
Description:
- Verifies that all the characters in STRING belong to the set of characters in SET.
- If BACK is either absent or equals FALSE, this function returns the position of the leftmost character of STRING that is not in SET.
- If BACK equals TRUE, the rightmost position is returned.
- If all characters of STRING are found in SET, the result is zero.
Class:
Elemental function
Syntax:
RESULT = VERIFY(STRING, SET[, BACK [, KIND]]) |
Arguments:
- STRING : Shall be of type CHARACTER.
- SET : Shall be of type CHARACTER.
- BACK : (Optional) shall be of type LOGICAL.
- KIND : (Optional) An INTEGER initialization expression indicating the kind parameter of the result.
Return value:
- The return value is of type INTEGER and of kind KIND.
- If KIND is absent, the return value is of default integer kind.
Example:
PROGRAM test_verify WRITE(*,*) VERIFY("FORTRAN", "AO") ! 1, found 'F' WRITE(*,*) VERIFY("FORTRAN", "FOO") ! 3, found 'R' WRITE(*,*) VERIFY("FORTRAN", "C++") ! 1, found 'F' WRITE(*,*) VERIFY("FORTRAN", "C++", .TRUE.) ! 7, found 'N' WRITE(*,*) VERIFY("FORTRAN", "FORTRAN") ! 0' found none END PROGRAM |
4. Intrinsic subroutines
DATE_AND_TIME : Date and time subroutine
Description:
- DATE_AND_TIME(DATE, TIME, ZONE, VALUES) gets the corresponding date and time information from the real-time system clock.
- DATE is INTENT(OUT) and has form ccyymmdd.
- TIME is INTENT(OUT) and has form hhmmss.sss.
- ZONE is INTENT(OUT) and has form (+-)hhmm, representing the difference with respect to Coordinated Universal Time (UTC).
- Unavailable time and date parameters return blanks.
- VALUES is INTENT(OUT) and provides the following:
- VALUE(1): The year
- VALUE(2): The month
- VALUE(3): The day of the month
- VALUE(4): Time difference with UTC in minutes
- VALUE(5): The hour of the day
- VALUE(6): The minutes of the hour
- VALUE(7): The seconds of the minute
- VALUE(8): The milliseconds of the second
Class:
Subroutine
Syntax:
CALL DATE_AND_TIME([DATE, TIME, ZONE, VALUES]) |
Arguments:
- DATE : (Optional) The type shall be CHARACTER(LEN=8) or larger, and of default kind.
- TIME : (Optional) The type shall be CHARACTER(LEN=10) or larger, and of default kind.
- ZONE : (Optional) The type shall be CHARACTER(LEN=5) or larger, and of default kind.
- VALUES : (Optional) The type shall be INTEGER(8).
Return value:
None
Example:
program test_time_and_date character(8) :: date character(10) :: time character(5) :: zone integer,dimension(8) :: values ! using keyword arguments call date_and_time(date,time,zone,values) call date_and_time(DATE=date,ZONE=zone) call date_and_time(TIME=time) call date_and_time(VALUES=values) print '(a,2x,a,2x,a)', date, time, zone print '(8i5))', values end program test_time_and_date |
SYSTEM_CLOCK : Time function
Description:
- Determines the COUNT of a processor clock since an unspecified time in the past modulo COUNT MAX, COUNT RATE determines the number of clock ticks per second.
- If the platform supports a high resolution monotonic clock, that clock is used and can provide up to nanosecond resolution.
- If a high resolution monotonic clock is not available, the implementation falls back to a potentially lower resolution realtime clock.
- COUNT RATE and COUNT MAX vary depending on the kind of the arguments.
- For kind=8 arguments, COUNT represents nanoseconds, and for kind=4 arguments, COUNT represents milliseconds.
- Other than the kind dependency, COUNT RATE and COUNT MAX are constant, however the particular values are specific to gfortran.
- If there is no clock, COUNT is set to -HUGE(COUNT), and COUNT RATE and COUNT MAX are set to zero.
- When running on a platform using the GNU C library (glibc), or a derivative thereof, the high resolution monotonic clock is available only when linking with the rt library.
- This can be done explicitly by adding the -lrt flag when linking the application, but is also done implicitly when using OpenMP.
Class:
Subroutine
Syntax:
CALL SYSTEM_CLOCK([COUNT, COUNT_RATE, COUNT_MAX]) |
Arguments:
- COUNT (Optional) shall be a scalar of type INTEGER with INTENT(OUT).
- COUNT RATE (Optional) shall be a scalar of type INTEGER with INTENT(OUT).
- COUNT MAX (Optional) shall be a scalar of type INTEGER with INTENT(OUT).
Example:
PROGRAM test_system_clock INTEGER :: count, count_rate, count_max CALL SYSTEM_CLOCK(count, count_rate, count_max) WRITE(*,*) count, count_rate, count_max END PROGRAM |
RANDOM_NUMBER : Pseudo-random number
Description:
- Returns a single pseudorandom number or an array of pseudorandom numbers from the uniform distribution over the range 0 <= x < 1.
- The runtime-library implements George Marsaglia's KISS (Keep It Simple Stupid) random number generator (RNG).
- This RNG combines:
- 1. The congruential generator x(n) = 69069*x(n - 1) + 1327217885 with a period of 232,
- 2. A 3-shift shift-register generator with a period of 232 - 1,
- 3. Two 16-bit multiply-with-carry generators with a period of 597273182964842497 > 259.
- The overall period exceeds 2123.
- Please note, this RNG is thread safe if used within OpenMP directives, i.e., its state will be consistent while called from multiple threads.
- However, the KISS generator does not create random numbers in parallel from multiple sources, but in sequence from a single source.
- If an OpenMP-enabled application heavily relies on random numbers, one should consider employing a dedicated parallel random number generator instead.
Class:
Subroutine
Syntax:
RANDOM_NUMBER(HARVEST) |
Arguments:
HARVEST : Shall be a scalar or an array of type REAL.
Example:
program test_random_number REAL :: r(5,5) CALL init_random_seed() ! see example of RANDOM_SEED CALL RANDOM_NUMBER(r) end program |
RANDOM_SEED : Initialize a pseudo-random number sequence
Description:
- Restarts or queries the state of the pseudorandom number generator used by RANDOM_NUMBER.
- If RANDOM_SEED is called without arguments, it is initialized to a default state.
- The example below shows how to initialize the random seed based on the system's time.
Class:
Subroutine
Syntax:
CALL RANDOM_SEED([SIZE, PUT, GET]) |
Arguments:
- SIZE : (Optional) Shall be a scalar and of type default INTEGER, with INTENT(OUT). It specifies the minimum size of the arrays used with the PUT and GET arguments.
- PUT : (Optional) Shall be an array of type default INTEGER and rank one. It is INTENT(IN) and the size of the array must be larger than or equal to the number returned by the SIZE argument.
- GET : (Optional) Shall be an array of type default INTEGER and rank one. It is INTENT(OUT) and the size of the array must be larger than or equal to the number returned by the SIZE argument.
Example:
SUBROUTINE init_random_seed() INTEGER :: i, n, clock INTEGER, DIMENSION(:), ALLOCATABLE :: seed CALL RANDOM_SEED(size = n) ALLOCATE(seed(n)) CALL SYSTEM_CLOCK(COUNT=clock) seed = clock + 37 * (/ (i - 1, i = 1, n) /) CALL RANDOM_SEED(PUT = seed) DEALLOCATE(seed) END SUBROUTINE |
5. Function and subroutines by GNU extension
IARGC : Get the number of command line arguments
Description:
- IARGC returns the number of arguments passed on the command line when the containing program was invoked.
- In new code, programmers should consider the use of [COMMAND ARGUMENT COUNT], intrinsic defined by the Fortran 2003 standard.
Class:
Function
Syntax:
RESULT = IARGC() |
Arguments:
None.
Return value:
The number of command line arguments, type INTEGER(4).
GETARG : Get command line arguments
Description:
- Retrieve the POS-th argument that was passed on the command line when the containing program was invoked.
- In new code, programmers should consider the use of [GET COMMAND ARGUMENT], intrinsic defined by the Fortran 2003 standard.
Class:
Subroutine
Syntax:
CALL GETARG(POS, VALUE) |
Arguments:
- POS : Shall be of type INTEGER and not wider than the default integer kind; POS >= 0
- VALUE : Shall be of type CHARACTER and of default kind.
- VALUE : Shall be of type CHARACTER.
Return value:
- After GETARG returns, the VALUE argument holds the POSth command line argument.
- If VALUE can not hold the argument, it is truncated to fit the length of VALUE.
- If there are less than POS arguments specified at the command line, VALUE will be filled with blanks.
- If POS = 0, VALUE is set to the name of the program (on systems that support this feature).
Example:
PROGRAM test_getarg INTEGER :: i CHARACTER(len=32) :: arg DO i = 1, iargc() CALL getarg(i, arg) WRITE (*,*) arg END DO END PROGRAM |
SYSTEM : Execute a shell command
Description:
- Passes the command COMMAND to a shell.
- If argument STATUS is present, it contains the value returned by system(3), which is presumably 0 if the shell command succeeded.
- Note that which shell is used to invoke the command is system-dependent and environment-dependent.
- This intrinsic is provided in both subroutine and function forms; however, only one form can be used in any given program unit.
- Note that the system function need not be thread-safe.
- It is the responsibility of the user to ensure that system is not called concurrently.
Class:
Subroutine, function
Syntax:
CALL SYSTEM(COMMAND [, STATUS]) STATUS = SYSTEM(COMMAND) |
Arguments:
- COMMAND : Shall be of default CHARACTER type.
- STATUS : (Optional) Shall be of default INTEGER type.