[an error occurred while processing this directive]

HP OpenVMS Systems Documentation

Content starts here

HP Fortran for OpenVMS
Language Reference Manual


Previous Contents Index

9.4.98 MERGE (TSOURCE, FSOURCE, MASK)

Description: Selects between two values or between corresponding elements in two arrays, according to the condition specified by a logical mask.
Class: Elemental function; Generic
Arguments: TSOURCE Must be a scalar or array (of any data type).
  FSOURCE Must be a scalar or array of the same type and type parameters as TSOURCE.
  MASK Must be a logical array.
Results: The result type is the same as TSOURCE. The value of MASK determines whether the result value is taken from TSOURCE (if MASK is true) or FSOURCE (if MASK is false).

Examples

For MERGE (1.0, 0.0, R < 0), if R is --3, the merge has the value 1.0, while if R is 7, the merge has the value 0.0.

TSOURCE is the array <left[ symbol><matrix symbol> 1&3&5<cr symbol> 2&4&6<cr symbol> <right] symbol> , FSOURCE is the array <left[ symbol><matrix symbol> 8&9&0<cr symbol> 1&2&3<cr symbol> <right] symbol> , and MASK is the array <left[ symbol><matrix symbol> F&T&T<cr symbol> T&T&F<cr symbol> <right] symbol> .

MERGE (TSOURCE, FSOURCE, MASK) produces the result: <left[ symbol><matrix symbol> 8&3&5<cr symbol> 2&4&3<cr symbol> <right] symbol> .

9.4.99 MIN (A1, A2 [,A3,...])

Description: Returns the minimum 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 MIN0, AMIN1, DMIN1, QMIN1, IMIN0, JMIN0, and KMIN0, the result type is the same as the arguments. For MIN1, IMIN1, JMIN1, and KMIN1, the result is of type integer. For AMIN0, AIMIN0, AJMIN0, and AKMIN0, the result is of type real. The value of the result is that of the smallest argument.
Specific Name1 Argument Type Result Type
  INTEGER(1) INTEGER(1)
  INTEGER(1) REAL(4)
IMIN0 INTEGER(2) INTEGER(2)
AIMIN0 INTEGER(2) REAL(4)
MIN0 2 INTEGER(4) INTEGER(4)
AMIN0 3,4 INTEGER(4) REAL(4)
KMIN0 INTEGER(8) INTEGER(8)
AKMIN0 INTEGER(8) REAL(4)
IMIN1 REAL(4) INTEGER(2)
MIN1 4,5,6 REAL(4) INTEGER(4)
KMIN1 REAL(4) INTEGER(8)
AMIN1 7 REAL(4) REAL(4)
DMIN1 REAL(8) REAL(8)
QMIN1 REAL(16) REAL(16)

1These specific functions cannot be passed as actual arguments.
2Or JMIN0.
3Or AJMIN0. AMIN0 is the same as REAL (MIN).
4In Fortran 95/90, AMIN0 and MIN1 are specific functions with no generic name. For compatibility with older versions of Fortran, these functions can also be specified as generic functions.
5Or JMIN1. MIN1 is the same as INT (MIN).
6The setting of compiler options specifying integer size can affect MIN1.
7The setting of compiler options specifying real size can affect AMIN1.

Examples

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

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

9.4.100 MINEXPONENT (X)

Description: Returns the minimum 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 min , as defined in Section D.2.

Examples

If X is of type REAL(4), MINEXPONENT (X) has the value --125.

9.4.101 MINLOC (ARRAY [,DIM] [,MASK] [,KIND])

Description: Returns the location of the minimum 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 MINLOC (ARRAY) is specified, the elements in the array result form the subscript of the location of the element with the minimum 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 MINLOC (ARRAY, MASK=MASK) is specified, the elements in the array result form the subscript of the location of the element with the minimum 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, MINLOC (ARRAY, DIM [,MASK]) has a value equal to that of MINLOC (ARRAY [,MASK = MASK]). Otherwise, the value of element (s 1, s 2,..., s DIM-1, s DIM+1,..., s n) of MINLOC (ARRAY, DIM [,MASK]) is equal to MINLOC (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 minimum 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 MINLOC ((/3, 1, 4, 1/)) is (2), which is the subscript of the location of the first occurrence of the minimum 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> .

MINLOC (A, MASK=A .GT. --5) has the value (3, 2) because these are the subscripts of the location of the minimum value (--4) that is greater than --5.

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

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

9.4.102 MINVAL (ARRAY [,DIM] [,MASK])

Description: Returns the minimum 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.
  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 MINVAL (ARRAY) is specified, the result has a value equal to the minimum value of all the elements in ARRAY.
  • If MINVAL (ARRAY, MASK=MASK) is specified, the result has a value equal to the minimum 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, MINVAL (ARRAY, DIM [,MASK]) has a value equal to that of MINVAL (ARRAY [,MASK = MASK]). Otherwise, the value of element (s 1, s 2,..., s DIM-1, s DIM+1,..., s n) of MINVAL (ARRAY, DIM, [,MASK]) is equal to MINVAL (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 positive number of the largest magnitude supported by the processor for numbers of the type and kind parameters of ARRAY.

Examples

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

The value of MINVAL (B, MASK=B .GT. 0.0) finds the minimum value of the positive elements of B.

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

MINVAL (C, DIM=1) has the value (2, 3, 4). 2 is the minimum value in column 1; 3 is the minimum value in column 2; and so forth.

MINVAL (C, DIM=2) has the value (2, 5). 2 is the minimum value in row 1 and 5 is the minimum value in row 2.

9.4.103 MOD (A, P)

Description: Returns the remainder when the first argument is divided by the second argument.
Class: Elemental function; Generic
Arguments: A Must be of type integer or real.
  P Must have the same type and kind parameters as A.
Results: The result type is the same as A. If P is not equal to zero, the value of the result is A - INT(A/P) * P . If P is equal to zero, the result is undefined.
Specific Name Argument Type Result Type
  INTEGER(1) INTEGER(1)
IMOD INTEGER(2) INTEGER(2)
MOD 1 INTEGER(4) INTEGER(4)
KMOD INTEGER(8) INTEGER(8)
AMOD 2 REAL(4) REAL(4)
DMOD REAL(8) REAL(8)
QMOD REAL(16) REAL(16)

1Or JMOD.
2The setting of compiler options specifying real size can affect AMOD.

Examples

MOD (7, 3) has the value 1.

MOD (9, --6) has the value 3.

MOD (--9, 6) has the value --3.

9.4.104 MODULO (A, P)

Description: Returns the modulo of the arguments.
Class: Elemental function; Generic
Arguments: A Must be of type integer or real.
  P Must have the same type and kind parameters as A.
Results: The result type is the same as A. The result value depends on the type of A, as follows:
  • If A is of type integer and P is not equal to zero, the value of the result is A - FLOOR(REAL(A) / REAL(P)) * P.
  • If A is of type real and P is not equal to zero, the value of the result is A - FLOOR(A / P) * P.

If P is equal to zero (regardless of the type of A), the result is undefined.

Examples

MODULO (7, 3) has the value 1.

MODULO (9, --6) has the value --3.

MODULO (--9, 6) has the value 3.

9.4.105 MULT_HIGH (I, J)

Description: Multiplies two 64-bit unsigned integers. 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
Arguments: I Must be of type INTEGER(8).
  J Must be of type INTEGER(8).
Results: The result is of type INTEGER(8). The result value is the upper (leftmost) 64 bits of the 128-bit unsigned result.

Examples

Consider the following:


        INTEGER(8) I,J,K
        I=2_8**53
        J=2_8**51
        K = MULT_HIGH (I,J)
        PRINT *,I,J,K
        WRITE (6,1000)I,J,K
1000    FORMAT (' ', 3(Z,1X))
        END

This example prints the following:


      9007199254740992      2251799813685248         1099511627776
          20000000000000           8000000000000             10000000000

9.4.106 MVBITS (FROM, FROMPOS, LEN, TO, TOPOS)

Description: Copies a sequence of bits (a bit field) from one location to another.
Class: Elemental subroutine
Arguments: There are five arguments 1:
FROM Can be of any integer type. It represents the location from which a bit field is transferred.
FROMPOS Can be of any integer type; it must not be negative. It identifies the first bit position in the field transferred from FROM. FROMPOS + LEN must be less than or equal to BIT_SIZE (FROM). 2
LEN Can be of any integer type; it must not be negative. It identifies the length of the field transferred from FROM.
TO Can be of any integer type, but must have the same kind parameter as FROM. It represents the location to which a bit field is transferred. TO is set by copying the sequence of bits of length LEN, starting at position FROMPOS of FROM to position TOPOS of TO. No other bits of TO are altered.

On return, the LEN bits of TO (starting at TOPOS) are equal to the value that LEN bits of FROM (starting at FROMPOS) had on entry. 2

TOPOS Can be of any integer type; it must not be negative. It identifies the starting position (within TO) for the bits being transferred. TOPOS + LEN must be less than or equal to BIT_SIZE (TO).

1FROM, FROMPOS, LEN, and TOPOS are INTENT(IN) arguments; TO is an INTENT(INOUT) argument. For more information on INTENT, see Section 5.10.
2The model for the interpretation of an integer value as a sequence of bits is shown in Section D.3. For more information on bit functions, see Section 9.3.3.

You can also use the following specific subroutines:

IMVBITS All arguments must be INTEGER(2).
JMVBITS Arguments can be INTEGER(2) or INTEGER(4); at least one must be INTEGER(4).
KMVBITS Arguments can be INTEGER(2), INTEGER(4), or INTEGER(8); at least one must be INTEGER(8).

Examples

If TO has the initial value of 6, its value after a call to MVBITS with arguments (7, 2, 2, TO, 0) is 5.


Previous Next Contents Index