      INTEGER          FUNCTION ISAMAX( N, SX, INCX )
****************************************************************************
*                                                                          *
*   DATA PARALLEL BLAS based on MPL                                        *
*                                                                          *
*   Version 1.1  23/10-92 ,                                                 *
*   For MasPar MP-1 computers                                              *
*                                                                          *
*   para//ab, University of Bergen, NORWAY                                 *
*                                                                          *
*   These programs must be called using F90 style array syntax.            *
*   Note that the F77 style calling sequence has been retained             *
*   in this version for compatibility reasons, be aware that               *
*   parameters related to the array dimensions and shape therefore may     *
*   be redundant and without any influence.                                *
*   The calling sequence may be changed in a future version.               *
*   Please report any BUGs, ideas for improvement or other                 *
*   comments to                                                            *
*                    adm@parallab.uib.no                                   *
*                                                                          *
*   Future versions may then reflect your suggestions.                     *
*   The most current version of this software is available                 *
*   from netlib@nac.no , send the message `send index from maspar'         *
*                                                                          *
*   REVISIONS:                                                             *
*                                                                          *
****************************************************************************
      implicit none
*
*     finds the index of element having max. absolute value.
*     Tor Sorevik, Para//ab, 23. Oct. -92
*
*     .. Scalar Arguments ..
      INTEGER                           INCX, N
*     ..
*     .. Array Arguments ..
      real, array(:) :: SX
*     ..
*     .. Local arrays ..
      integer, array(1:1) :: POSIT
*     ..
*     .. Local scalars ..
      integer  ix, jx
*     ..
*     .. Intrinsic Functions ..
      INTRINSIC                         ABS, MAXLOC
*     ..
*     .. Executable Statements ..
*
      IF( N.LT.1 ) THEN
          ISAMAX = 0
          RETURN
      ENDIF
      IF( N.EQ.1 ) THEN
          ISAMAX = 1
          RETURN
      ENDIF
*
*        code for increment equal to 1
*
      IF( INCX.EQ.1 ) THEN
	 POSIT = MAXLOC(ABS(SX))
	 ISAMAX = POSIT(1)
      ELSE
*
*        code for increment not equal to 1
*
	 IF ( INCX .GT. 0 ) THEN
	     IX = 1
	     JX = 1 + (N-1) * INCX
	 ELSE
             IX = 1 - (N-1) * INCX
             JX = 1
         ENDIF
	 POSIT = MAXLOC(ABS(SX(IX:JX:INCX)))
	 ISAMAX = POSIT(1)
	 IF (INCX .LT. 0) ISAMAX = N - ISAMAX + 1
      ENDIF
*
      RETURN
*
*     End of ISAMAX.
*
      END