HP Fortran for OpenVMS
Language Reference Manual


Previous Contents Index

9.4.88 LOC (X)

Description: Returns the internal address of a storage item. 1
Class: Inquiry function; Generic
Arguments: X is a variable, an array or record field reference, a procedure, or a constant; it can be of any data type. It must not be the name of an internal procedure or statement function. If it is a pointer, it must be defined and associated with a target.
Results: The result is of type INTEGER(8). The value of the result represents the address of the data object or, in the case of pointers, the address of its associated target. If the argument is not valid, the result is undefined.
  In the case of global symbolic constants, LOC returns the value of the constant rather than an address.
  This function serves the same purpose as the %LOC built-in function.

1This specific function cannot be passed as an actual argument.

9.4.89 LOG (X)

Description: Returns the natural logarithm of the argument.
Class: Elemental function; Generic
Arguments: X must be of type real or complex. If X is real, its value must be greater than zero. If X is complex, its value must not be zero.
Results: The result type is the same as X. The result value is approximately equal to log eX.
  If the arguments are complex, the result is the principal value of imaginary part <omega symbol> in the range --Pi sign < <omega symbol> <= Pi sign. The imaginary part of the result is Pi sign if the real part of the argument is less than zero and the imaginary part of the argument is zero.
Specific Name Argument Type Result Type
ALOG 1 REAL(4) REAL(4)
DLOG REAL(8) REAL(8)
QLOG REAL(16) REAL(16)
CLOG 1 COMPLEX(4) COMPLEX(4)
CDLOG 2 COMPLEX(8) COMPLEX(8)
CQLOG COMPLEX(16) COMPLEX(16)

1The setting of compiler options specifying real size can affect ALOG and CLOG.
2This function can also be specified as ZLOG.

Examples

LOG (8.0) has the value 2.079442.

LOG (25.0) has the value 3.218876.

9.4.90 LOG10 (X)

Description: Returns the common logarithm of the argument.
Class: Elemental function; Generic
Arguments: X must be of type real. The value of X must be greater than zero.
Results: The result type is the same as X. The result has a value equal to log 10X.
Specific Name Argument Type Result Type
ALOG10 1 REAL(4) REAL(4)
DLOG10 REAL(8) REAL(8)
QLOG10 REAL(16) REAL(16)

1The setting of compiler options specifying real size can affect ALOG10.

Examples

LOG10 (8.0) has the value 0.9030900.

LOG10 (15.0) has the value 1.176091.

9.4.91 LOGICAL (L [,KIND])

Description: Converts the logical value of the argument to a logical value with different kind parameters.
Class: Elemental function; Generic
Arguments: L Must be of type logical.
  KIND (opt) Must be a scalar integer initialization expression.
Results: The result is of type logical. If KIND is present, the kind parameter is that specified by KIND; otherwise, the kind parameter is that of default logical. The result value is that of L.

The setting of compiler options specifying integer size can affect this function.

Examples

LOGICAL (L .OR. .NOT. L) has the value true and is of type default logical regardless of the kind parameter of logical variable L.

LOGICAL (.FALSE., 2) has the value false, with the kind parameter of INTEGER(KIND=2).

9.4.92 MALLOC (I)

Description: Allocates a block of memory. This is a specific function that has no generic function associated with it. It must not be passed as an actual argument.
Class: Elemental function; Specific
Arguments: I must be of type integer. This value is the size (in bytes) of memory to be allocated.
Results: The result is of type INTEGER(8).

If the argument is INTEGER(8), a 64-bit (P3) space is allocated.

The result is the starting address of the allocated memory. The memory allocated can be freed by using the FREE intrinsic function (see Section 9.4.55).

Examples

Consider the following:


INTEGER(4) ADDR, SIZE 
SIZE = 1024                 ! Size in bytes 
ADDR = MALLOC(SIZE)         ! Allocate the memory 
CALL FREE(ADDR)             ! Free it 
END 

9.4.93 MATMUL (MATRIX_A, MATRIX_B)

Description: Performs matrix multiplication of numeric or logical matrices.
Class: Transformational function; Generic
Arguments: MATRIX_A Must be an array of rank one or two. It must be of numeric (integer, real, or complex) or logical type.
  MATRIX_B Must be an array of rank one or two. It must be of numeric type if MATRIX_A is of numeric type or logical type if MATRIX_A is logical type.

At least one argument must be of rank two. The size of the first (or only) dimension of MATRIX_B must equal the size of the last (or only) dimension of MATRIX_A.

Results: The result is an array whose type depends on the data type of the arguments, according to the rules shown in Table 4-2. The rank and shape of the result depends on the rank and shapes of the arguments, as follows:
  • If MATRIX_A has shape (n, m) and MATRIX_B has shape (m, k), the result is a rank-two array with shape (n, k).
  • If MATRIX_A has shape (m) and MATRIX_B has shape (m, k), the result is a rank-one array with shape (k).
  • If MATRIX_A has shape (n, m) and MATRIX_B has shape (m), the result is a rank-one array with shape (n).

If the arguments are of numeric type, element (i, j) of the result has the value SUM ((row i of MATRIX_A) * (column j of MATRIX_B)). If the arguments are of logical type, element (i, j) of the result has the value ANY ((row i of MATRIX_A) .AND. (column j of MATRIX_B)).

Examples

A is matrix <left[ symbol><matrix symbol> 2&3&4<cr symbol> 3&4&5<cr symbol> <right] symbol> , B is matrix <left[ symbol><matrix symbol> 2&3<cr symbol> 3&4<cr symbol> 4&5<cr symbol> <right] symbol> , X is vector (1, 2), and Y is vector (1, 2, 3).

The result of MATMUL (A, B) is the matrix-matrix product AB with the value <left[ symbol><matrix symbol> 29&38<cr symbol> 38&50<cr symbol> <right] symbol> .

The result of MATMUL (X, A) is the vector-matrix product XA with the value (8, 11, 14).

The result of MATMUL (A, Y) is the matrix-vector product AY with the value (20, 26).

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

Description: Returns the maximum value of the arguments.
Class: Elemental function; Generic
Arguments: A1, A2, and A3 (opt) must all have the same type (integer or real) and kind parameters.
Results: For MAX0, AMAX1, DMAX1, QMAX1, IMAX0, JMAX0, and KMAX0, the result type is the same as the arguments. For MAX1, IMAX1, JMAX1, and KMAX1, the result is of type integer. For AMAX0, AIMAX0, AJMAX0, and AKMAX0, the result is of type real. The value of the result is that of the largest argument.
Specific Name1 Argument Type Result Type
  INTEGER(1) INTEGER(1)
  INTEGER(1) REAL(4)
IMAX0 INTEGER(2) INTEGER(2)
AIMAX0 INTEGER(2) REAL(4)
MAX0 2 INTEGER(4) INTEGER(4)
AMAX0 3,4 INTEGER(4) REAL(4)
KMAX0 INTEGER(8) INTEGER(8)
AKMAX0 INTEGER(8) REAL(4)
IMAX1 REAL(4) INTEGER(2)
MAX1 4,5,6 REAL(4) INTEGER(4)
KMAX1 REAL(4) INTEGER(8)
AMAX1 7 REAL(4) REAL(4)
DMAX1 REAL(8) REAL(8)
QMAX1 REAL(16) REAL(16)

1These specific functions cannot be passed as actual arguments.
2Or JMAX0.
3Or AJMAX0. AMAX0 is the same as REAL (MAX).
4In Fortran 95/90, AMAX0 and MAX1 are specific functions with no generic name. For compatibility with older versions of Fortran, these functions can also be specified as generic functions.
5Or JMAX1. MAX1 is the same as INT (MAX).
6The setting of compiler options specifying integer size can affect MAX1.
7The setting of compiler options specifying real size can affect AMAX1.

Examples

MAX (2.0, --8.0, 6.0) has the value 6.0.

MAX (14, 32, --50) has the value 32.

9.4.95 MAXEXPONENT (X)

Description: Returns the maximum exponent in the model representing the same type and kind parameters as the argument.
Class: Inquiry function; Generic
Arguments: X must be of type real; it can be scalar or array valued.
Results: The result is a scalar of type default integer. The result has the value e max , as defined in Section D.2.

Examples

If X is of type REAL(4), MAXEXPONENT (X) has the value 128.

9.4.96 MAXLOC (ARRAY [,DIM] [,MASK] [,KIND])

Description: Returns the location of the maximum value of all elements in an array, a set of elements in an array, or elements in a specified dimension of an array.
Class: Transformational function; Generic
Arguments: ARRAY Must be an array of type integer or real.
  DIM (opt) Must be a scalar integer with a value in the range 1 to n, where n is the rank of ARRAY. This argument is a Fortran 95 feature.
  MASK (opt) Must be a logical array that is conformable with ARRAY.
  KIND (opt) Must be a scalar integer initialization expression.
Results: The result is an array of type integer. If KIND is present, the kind parameter of the result is that specified by KIND; otherwise, the kind parameter of the result is that of default integer. If the processor cannot represent the result value in the kind of the result, the result is undefined.

The following rules apply if DIM is omitted:

  • The array result has rank one and a size equal to the rank of ARRAY.
  • If MAXLOC (ARRAY) is specified, the elements in the array result form the subscript of the location of the element with the maximum value in ARRAY. The ith subscript returned is in the range 1 to e i, where e i is the extent of the ith dimension of ARRAY.
  • If MAXLOC (ARRAY, MASK=MASK) is specified, the elements in the array result form the subscript of the location of the element with the maximum value corresponding to the condition specified by MASK.

The following rules apply if DIM is specified:

  • The array result has a rank that is one less than ARRAY, and shape (d 1, d 2,...,d DIM-1, d DIM+1,..., d n), where (d 1, d 2,..., d n) is the shape of ARRAY.
  • If ARRAY has rank one, MAXLOC (ARRAY, DIM [,MASK]) has a value equal to that of MAXLOC (ARRAY [,MASK = MASK]). Otherwise, the value of element (s 1, s 2,..., s DIM-1, s DIM+1,..., s n) of MAXLOC (ARRAY, DIM [,MASK]) is equal to MAXLOC (ARRAY (s 1, s 2,..., s DIM-1, :, s DIM+1,..., s n) [,MASK = MASK (s 1, s 2,..., s DIM-1, :, s DIM+1,..., s n)]).

If more than one element has maximum value, the element whose subscripts are returned is the first such element, taken in array element order. If ARRAY has size zero, or every element of MASK has the value .FALSE., the value of the result is undefined.

Examples

The value of MAXLOC ((/3, 7, 4, 7/)) is (2), which is the subscript of the location of the first occurrence of the maximum value in the rank-one array.

A is the array <left[ symbol><matrix symbol> 4& 0&-3& 2<cr symbol> 3& 1&-2& 6<cr symbol> -1&-4& 5&-5<cr symbol> <right] symbol> .

MAXLOC (A, MASK=A .LT. 5) has the value (1, 1) because these are the subscripts of the location of the maximum value (4) that is less than 5.

MAXLOC (A, DIM=1) has the value (1, 2, 3, 2). 1 is the subscript of the location of the maximum value (4) in column 1; 2 is the subscript of the location of the maximum value (1) in column 2; and so forth.

MAXLOC (A, DIM=2) has the value (1, 4, 3). 1 is the subscript of the location of the maximum value in row 1; 4 is the subscript of the location of the maximum value in row 2; and so forth.

9.4.97 MAXVAL (ARRAY [,DIM] [,MASK])

Description: Returns the maximum value of all elements in an array, a set of elements in an array, or elements in a specified dimension of an array.
Class: Transformational function; Generic
Arguments: ARRAY Must be an array of type integer or real.
  DIM (opt) Must be a scalar integer expression with a value in the range 1 to n, where n is the rank of ARRAY.
  MASK (opt) Must be a logical array that is conformable with ARRAY.
Results: The result is an array or a scalar of the same data type as ARRAY.

The result is a scalar if DIM is omitted or ARRAY has rank one.

The following rules apply if DIM is omitted:

  • If MAXVAL (ARRAY) is specified, the result has a value equal to the maximum value of all the elements in ARRAY.
  • If MAXVAL (ARRAY, MASK=MASK) is specified, the result has a value equal to the maximum value of the elements in ARRAY corresponding to the condition specified by MASK.

The following rules apply if DIM is specified:

  • An array result has a rank that is one less than ARRAY, and shape (d 1, d 2,...,d DIM-1, d DIM+1,..., d n), where (d 1, d 2,..., d n) is the shape of ARRAY.
  • If ARRAY has rank one, MAXVAL (ARRAY, DIM [,MASK]) has a value equal to that of MAXVAL (ARRAY [,MASK = MASK]). Otherwise, the value of element (s 1, s 2,..., s DIM-1, s DIM+1,..., s n) of MAXVAL (ARRAY, DIM, [,MASK]) is equal to MAXVAL (ARRAY (s 1, s 2,..., s DIM-1, :, s DIM+1,..., s n) [,MASK = MASK (s 1, s 2,..., s DIM-1, :, s DIM+1,..., s n)]).

If ARRAY has size zero or if there are no true elements in MASK, the result (if DIM is omitted), or each element in the result array (if DIM is specified), has the value of the negative number of the largest magnitude supported by the processor for numbers of the type and kind parameters of ARRAY.

Examples

The value of MAXVAL ((/2, 3, 4/)) is 4 because that is the maximum value in the rank-one array.

MAXVAL (B, MASK=B .LT. 0.0) finds the maximum value of the negative elements of B.

C is the array <left[ symbol><matrix symbol> 2&3&4<cr symbol> 5&6&7<cr symbol> <right] symbol> .

MAXVAL (C, DIM=1) has the value (5, 6, 7). 5 is the maximum value in column 1; 6 is the maximum value in column 2; and so forth.

MAXVAL (C, DIM=2) has the value (4, 7). 4 is the maximum value in row 1 and 7 is the maximum value in row 2.


Previous Next Contents Index