max(3f) - [M_datapac:VECTOR_OPERATION] MAX compute the maximum of a
data vector
SUBROUTINE MAX(X,N,Iwrite,Xmax)
REAL(kind=wp) :: X(:) , Xmax
INTEGER :: Iwrite , N
MAX(3f) computes the sample maximum of the data in the input vector x.
X The vector of (unsorted or sorted) observations.
N The integer number of observations in the vector X.
IWRITE An integer flag code which (if set to 0) will suppress
the printing of the sample maximum as it is computed;
or (if set to some integer value not equal to 0),
like, say, 1) will cause the printing of the
sample maximum at the time it is computed.
XMAX The value of the computed sample maximum.
Sample program:
program demo_max
!use M_datapac, only : max, label
use M_datapac, only : intel_max=>max, label ! ifort (IFORT) 2021.3.0 20210609 bug
implicit none
real :: xmax
call label('max')
call intel_max([-100.0, 200.0, 0.0, 400.0, -200.0],5,1,xmax)
!call max([-100.0, 200.0, 0.0, 400.0, -200.0],5,1,xmax)
write(*,*)xmax
end program demo_max
Results:
THE MAXIMUM OF THE SET OF 5 OBSERVATIONS IS 0.40000000E+03
400.000000
The original DATAPAC library was written by James Filliben of the
Statistical Engineering Division, National Institute of Standards
and Technology.
John Urban, 2022.05.31
CC0-1.0
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=wp) | :: | X(:) | ||||
integer | :: | N | ||||
integer | :: | Iwrite | ||||
real(kind=wp) | :: | Xmax |
SUBROUTINE MAX(X,N,Iwrite,Xmax) REAL(kind=wp) :: hold , X(:) , Xmax INTEGER i , Iwrite , N !--------------------------------------------------------------------- ! ! CHECK THE INPUT ARGUMENTS FOR ERRORS ! IF ( N<1 ) THEN WRITE (G_IO,99001) 99001 FORMAT (' ***** FATAL ERROR--The second input argument to MAX(3f) is non-positive *****') WRITE (G_IO,99002) N 99002 FORMAT (' ','***** The value of the argument is ',I0,' *****') RETURN ELSE IF ( N==1 ) THEN WRITE (G_IO,99003) 99003 FORMAT (' ***** NON-FATAL DIAGNOSTIC--The second input argument to MAX(3f) has the value 1 *****') Xmax = X(1) ELSE hold = X(1) DO i = 2 , N IF ( X(i)/=hold ) GOTO 50 ENDDO WRITE (G_IO,99004) hold 99004 FORMAT (' ***** NON-FATAL DIAGNOSTIC--the first input argument (a vector) to MAX(3f) has all elements = ',g0,' *****') Xmax = X(1) ENDIF GOTO 100 50 continue Xmax = X(1) DO i = 2 , N IF ( X(i)>Xmax ) Xmax = X(i) ENDDO ENDIF 100 continue IF ( Iwrite==0 ) RETURN WRITE (G_IO,99005) 99005 FORMAT (' ') WRITE (G_IO,99006) N , Xmax 99006 FORMAT (' ','The maximum of the set of ',I0,' observations is ', e15.8) end subroutine max