* Last processed by NICE on 12-Jun-2000 15:54:00
* Customized for :  IEEE, LINUX, UNIX, MOTIF, F77
* maxmin_image.f
*
*
      SUBROUTINE MAXMIN_IMAGE (INPUT,NX,NY,NZ,MAXMIN)
*
      INCLUDE 'parameter.inc'
*
      INTEGER NX, NY, NZ, I, J, K, II
      REAL    INPUT(1)
      REAL    VAL, MAXMIN(8)
*
      MAXMIN(1) =  1.D31                 ! MAXMIN(1) = minimum
      MAXMIN(2) = -1.D31                 ! MAXMIN(2) = maximum
      DO K=1,NZ
         DO J=1,NY
            DO I=1,NX
               II = I + (J-1)*NX + (K-1)*NX*NY
               VAL = INPUT(II)
               IF (ABS(VAL-BLANKING).GT.0.5)
     $         MAXMIN(1) = MIN (MAXMIN(1),VAL)
               IF (MAXMIN(1).EQ.VAL) THEN
                  MAXMIN(3) = I
                  MAXMIN(4) = J
                  MAXMIN(5) = K
               ENDIF
               MAXMIN(2) = MAX (MAXMIN(2),VAL)
               IF (MAXMIN(2).EQ.VAL) THEN
                  MAXMIN(6) = I
                  MAXMIN(7) = J
                  MAXMIN(8) = K
               ENDIF
            ENDDO
         ENDDO
      ENDDO
      RETURN
      END
*
*----------------------------------------------------------------
*
*     MAXMIN_COORD()
*
*----------------------------------------------------------------
*
      SUBROUTINE  MAXMIN_COORD(X,NP,XMIN,XMAX,SIG)
*
      INCLUDE 'parameter.inc'
      REAL      X(1),SIG(1),XMIN,XMAX
      INTEGER   NP,I
*
      XMIN =  1.D32
      XMAX = -1.D32
      DO I=1,NP
         IF (ABS(SIG(I)-BLANKING).GE.0.5) THEN
            IF (X(I).LT.XMIN) XMIN = X(I)
            IF (X(I).GT.XMAX) XMAX = X(I)
         ENDIF
      ENDDO
      XMIN = XMIN/10.                    ! xmin in arcseconds
      XMAX = XMAX/10.                    ! xmax in arcseconds
      RETURN
      END
*
*----------------------------------------------------------------------
*
*    WMAX ()
*
c   this subroutine computes the max and min of a nod2 array, amap,   *
c   containing real*4 numbers in its data section.                    *
*----------------------------------------------------------------------
*
      SUBROUTINE WMAX(MAPD,MAPW,AMAX,AMIN,BLANKING,NPOINT)
*
      REAL*4  MAPD(1),MAPW(1)
      REAL*4  BLANKING
      REAL*8  AMAX,AMIN
      INTEGER NPOINT
      INTEGER I
*
      AMAX = -1.D35
      AMIN =  1.D35
      DO I = 1,NPOINT
         IF(ABS(MAPD(I) - BLANKING).GE. 0.5) THEN
            IF(MAPW(I).GT.AMAX) AMAX = MAPW(I)
            IF(MAPW(I).LT.AMIN) AMIN = MAPW(I)
         ENDIF
      ENDDO
      RETURN
      END
