MAX Subroutine

public subroutine MAX(X, N, Iwrite, Xmax)

NAME

max(3f) - [M_datapac:VECTOR_OPERATION] MAX compute the maximum of a
data vector

SYNOPSIS

   SUBROUTINE MAX(X,N,Iwrite,Xmax)

    REAL(kind=wp) :: X(:) , Xmax
    INTEGER :: Iwrite , N

DESCRIPTION

MAX(3f) computes the sample maximum of the data in the input vector x.

INPUT ARGUMENTS

 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.

OUTPUT ARGUMENTS

  XMAX    The value of the computed sample maximum.

EXAMPLES

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

AUTHOR

The original DATAPAC library was written by James Filliben of the
Statistical Engineering Division, National Institute of Standards
and Technology.

MAINTAINER

John Urban, 2022.05.31

LICENSE

CC0-1.0

REFERENCES

  • David, Order Statistics, 1970, page 7.

Arguments

Type IntentOptional Attributes Name
real(kind=wp) :: X(:)
integer :: N
integer :: Iwrite
real(kind=wp) :: Xmax

Source Code

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