Manual Reference Pages  - maxval (3fortran)

NAME

MAXVAL(3) - [ARRAY:REDUCTION] Determines the maximum value in an array or row

SYNOPSIS

result = maxval(array [,mask]) | maxval(array [,dim] [,mask])

         NUMERIC function maxval(array ,dim, mask)

NUMERIC,intent(in) :: array(..) integer(kind=**),intent(in),optional :: dim logical(kind=**),intent(in),optional :: mask(..)

CHARACTERISTICS

o a kind designated as ** may be any supported kind for the type
o NUMERIC designates any numeric type and kind.

DESCRIPTION

MAXVAL(3) determines the maximum value of the elements in an array value, or, if the DIM argument is supplied, determines the maximum value along each row of the array in the DIM direction. If MASK is present, only the elements for which MASK is .true. are considered.

OPTIONS

o ARRAY : Shall be an array of type integer, real, or character.
o DIM : (Optional) Shall be a scalar of type integer, with a value between one and the rank of ARRAY, inclusive. It may not be an optional dummy argument.
o MASK : (Optional) Shall be an array of type logical, and conformable with ARRAY.

RESULT

If DIM is absent, or if ARRAY has a rank of one, the result is a scalar. If DIM is present, the result is an array with a rank one less than the rank of ARRAY, and a size corresponding to the size of ARRAY with the DIM dimension removed. In all cases, the result is of the same type and kind as ARRAY.

If the considered array has zero size then the result is the most negative number of the type and kind of ARRAY if ARRAY is numeric, or a string of nulls if ARRAY is of ASCII character type. or equal to CHAR(0, KIND(ARRAY)) otherwise.

EXAMPLES

sample program:

    program demo_maxval
    implicit none
    integer,save :: ints(3,5)= reshape([&
       1,  2,  3,  4,  5, &
      10, 20, 30, 40, 50, &
      11, 22, 33, 44, 55  &
    ],shape(ints),order=[2,1])
    character(len=:),allocatable :: strs(:)
    integer :: i
    character(len=*),parameter :: gen=’(*(g0,1x))’
    character(len=*),parameter :: ind=’(3x,*(g0,1x))’

print gen,’Given the array’ write(*,’(1x,*(g4.4,1x))’) & & (ints(i,:),new_line(’a’),i=1,size(ints,dim=1)) print gen,’Basics:’ print ind, ’biggest value in array’ print ind, maxval(ints) print ind, ’biggest value in each column’ print ind, maxval(ints,dim=1) print ind, ’biggest value in each row’ print ind, maxval(ints,dim=2)

print gen,’With a mask:’ print ind, ’ find biggest number less than 30 with mask’ print ind, maxval(ints,mask=ints.lt.30)

print gen,’If zero size considered:’ print ind, ’if zero size numeric array’ print ind, maxval([integer :: ]),’and -huge(0) is’,-huge(0),& & ’(often not the same!)’ print ind, ’if zero-size character array all nulls’ strs=[character(len=5)::] strs=maxval(strs) print ind, ichar([(strs(i),i=1,len(strs))]) print ind, ’if everything is false,’ print ind, ’same as zero-size array for each subarray’ print ind, maxval(ints,mask=.false.) print ind, maxval(ints,mask=.false.,dim=1) end program demo_maxval

Results:

     > Given the array:
     >    1,  2,  3,  4,  5, &
     >   10, 20, 30, 40, 50, &
     >   11, 22, 33, 44, 55  &
     > biggest value in array
     > 55
     > biggest value in each column
     > 11 22 33 44 55
     > biggest value in each row
     > 5 50 55
     > find biggest number less than 30 with mask
     > 22
     > if zero size numeric array
     > -2147483648 and -huge(0) is -2147483647 (often not the same!)
     > if zero-size character array all nulls
     > 0 0 0 0 0
     > if everything is false, same as zero-size array
     > -2147483648
     > -2147483648 -2147483648 -2147483648 -2147483648 -2147483648

STANDARD

Fortran 95

SEE ALSO

MINVAL(3), MINLOC(3), MAXLOC(3), MIN(3) MAX(3),

Fortran intrinsic descriptions (license: MIT) @urbanjost


Nemo Release 3.1 maxval (3fortran) November 02, 2024
Generated by manServer 1.08 from 28d12859-e8a6-4c55-88cc-b84f085c0621 using man macros.