Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

MINLOC

Mike896
Beginner
678 Views

Hi

following adapted from Help on MINLOC

INTEGER i, minl(1)
INTEGER array(2, 3)
INTEGER, ALLOCATABLE :: AR1(:)
! put values in array
array = RESHAPE((/-7, 1, -2, -9, 5, 0/),(/2, 3/))
! array is -7 -2 5
! 1 -9 0
i = SIZE(SHAPE(array)) ! Get the number of dimensions
! in array
ALLOCATE (AR1 (i) ) ! Allocate AR1 to number
! of dimensions in array
AR1 = MINLOC (array, MASK = array .GT. -5) ! Get the
! location (subscripts) of
! smallest element greater
! than -5 in array

!
! MASK = array .GT. -5 creates a mask array the same
! size and shape as array whose elements are .TRUE. if
! the corresponding element in array is greater than
! -5, and .FALSE. if it is not. This mask causes MINLOC
! to return the index of the element in array with the
! smallest value greater than -5.
!
!array is -7 -2 5 and MASK= array .GT. -5 is F T T
! 1 -9 0 T F T
! and AR1 = MINLOC(array, MASK = array .GT. -5) returns
! (1, 2), the location of the element with value -2

minl = MINLOC((/-7,2,-7,5/)) ! returns 1, first
! occurrence of minimum
print *,min1
END

The result is 0.

Why?

Thank you in advance.

Mike

0 Kudos
2 Replies
TimP
Honored Contributor III
678 Views

You have changed the spelling from minl to min1, and you may have meant to use the form of MINLOC with a 2nd argument MINLOC(array,dim=1). IMPLICIT NONE should have forced the compiler to perform some checking.

0 Kudos
Mike896
Beginner
678 Views
Quoting - tim18

You have changed the spelling from minl to min1, and you may have meant to use the form of MINLOC with a 2nd argument MINLOC(array,dim=1). IMPLICIT NONE should have forced the compiler to perform some checking.

Oh! so embarrassing.

Thank you.

Mike

0 Kudos
Reply