MINVAL(3) - [ARRAY:REDUCTION] Minimum value of all the elements of ARRAY along dimension DIM corresponding to true elements of MASK.
forms
result = minval(array, [mask])or
result = minval(array [,dim] [,mask])type(TYPE(kind=**)) function minval(array, dim, mask)
NUMERIC,intent(in) :: array(..) integer(kind=**),intent(in),optional :: dim logical(kind=**),intent(in),optional :: mask(..)
o TYPE may be real, integer, or character. o a kind designated as ** may be any supported kind for the type o DIM is an integer scalar indicating a dimension of the array. It may not be an optional dummy argument. o MASK is an array of type logical, and conformable with ARRAY. o the result is of the same type and kind as ARRAY.
MINVAL(3) determines the minimum value of the elements in an array or, if the DIM argument is supplied, determines the minimum value in the subarrays indicated by stepping along the DIMth dimension.
Note that the result of
MINVAL(ARRAY, MASK = MASK)has a value equal to that of
MINVAL (PACK (ARRAY, MASK)).and The result of
MINVAL (ARRAY, DIM = DIM [, MASK = MASK])has a value equal to that of
MINVAL (ARRAY [, MASK = MASK])if ARRAY has rank one. Otherwise, the value of element (s1 , s2 , . . . , sDIM-1 , sDIM+1 , . . . , sn ) of the result is equal to
MINVAL (ARRAY (s1 , s2 , . . . , sDIM-1 , :, sDIM+1 , . . . , sn ) [, MASK= MASK (s1 , s2 , . . . , sDIM-1 , :, sDIM+1 , . . . , sn ) ] ).
o ARRAY : array to search for minimum values. If the array has zero size, or all of the elements of MASK are .false., then the result is HUGE(ARRAY) if ARRAY is numeric, or an array of strings of CHAR(LEN=LEN(ARRAY)) characters, with each character equal to CHAR (n - 1, KIND (ARRAY)), where n is the number of characters in the collating sequence for characters with the kind type parameter of ARRAY. If ARRAY is of type character, the result is the value that would be selected by application of intrinsic relational operators; that is, the collating sequence for characters with the kind type parameter of the arguments is applied.
o DIM : Indicates which dimension to split the array into subarrays along. It has a value between one and the rank of ARRAY, inclusive. o MASK ; If MASK is present, only the elements for which MASK is [char46]true. are considered when searching for the minimal value.
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.
sample program:
program demo_minval implicit none integer :: i character(len=:),allocatable :: strs(:) character(len=*),parameter :: g=(3x,*(g0,1x))Result: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])
integer,save :: box(3,5,2)
box(:,:,1)=ints box(:,:,2)=-ints
write(*,*)Given the array write(*,(1x,*(g4.4,1x))) & & (ints(i,:),new_line(a),i=1,size(ints,dim=1))
write(*,*)What is the smallest element in the array? write(*,g) minval(ints),at <,minloc(ints),>
write(*,*)What is the smallest element in each column? write(*,g) minval(ints,dim=1)
write(*,*)What is the smallest element in each row? write(*,g) minval(ints,dim=2)
! notice the shape of the output has less columns ! than the input in this case write(*,*)What is the smallest element in each column, write(*,*)considering only those elements that are write(*,*)greater than zero? write(*,g) minval(ints, dim=1, mask = ints > 0)
write(*,*)& & if everything is false a zero-sized array is NOT returned write(*,*) minval(ints, dim=1, mask = .false.) write(*,*)even for a zero-sized input write(*,g) minval([integer ::], dim=1, mask = .false.)
write(*,*)a scalar answer for everything false is huge() write(*,g) minval(ints, mask = .false.) write(*,g) minval([integer ::], mask = .false.)
print *, if zero-size character array all dels if ASCII strs=[character(len=5)::] strs=minval(strs) print g, ichar([(strs(i),i=1,len(strs))])
write(*,*)some calls with three dimensions write(*,g) minval(box, mask = .true. ) write(*,g) minval(box, dim=1, mask = .true. )
write(*,g) minval(box, dim=2, mask = .true. ) write(*,g) shape of answer is , & & shape(minval(box, dim=2, mask = .true. ))
end program demo_minval
> Given the array > 1 -2 3 4 5 > 10 20 -30 40 50 > 11 22 33 -44 55 > > What is the smallest element in the array? > -44 at < 3 4 > > What is the smallest element in each column? > 1 -2 -30 -44 5 > What is the smallest element in each row? > -2 -30 -44 > What is the smallest element in each column, > considering only those elements that are > greater than zero? > 1 20 3 4 5 > if everything is false a zero-sized array is NOT returned > 2147483647 2147483647 2147483647 2147483647 2147483647 > even for a zero-sized input > 2147483647 > a scalar answer for everything false is huge() > 2147483647 > 2147483647 > if zero-size character array all dels if ASCII > > some calls with three dimensions > -55 > 1 -2 -30 -44 5 -11 -22 -33 -40 -55 > -2 -30 -44 -5 -50 -55 > shape of answer is 3 2
Fortran 95
MIN(3), MINLOC(3) MAXLOC(3), MAXVAL(3), MIN(3)
Fortran intrinsic descriptions (license: MIT) @urbanjost
Nemo Release 3.1 | minval (3fortran) | November 02, 2024 |