C******************** START FILE GSCMMX.FOR ; GROUP GSCALE ***********
C-----------------------------------------------------------
C  GSCMMX    FIND MIN AND MAX OF DATA FCNS
C
C  MOD DMC 2/86 - X AXIS MONOTONICITY ASSUMPTION REVOKED
C     HOWEVER THERE IS ONLY ONE X AXIS AND ONE N FOR UP TO 2 FCNS HERE!
C
C  MOD DMC 2/86 - CODE REMOVED FROM SUBROUTINE GSCSET
C
      SUBROUTINE GSCMMX(X,NX,Y,Y2,I2,NY,
     >     IX1,INCX,IY1,INCY,N,ZXLIM1,ZXLIM2,IYONLY)
C
C    X(NX) X DATA
C    Y(NY) Y DATA
C    Y2(NY) 2NDRY Y DATA (OPTIONAL - PRESENT IF I2.NE.0 )
C
C    IX1 - ADDR. FIRST X PT
C    INCX - SPACING BTW X PTS
C    IY1 - ADDR. FIRST Y PT(S)
C    INCY - SPACING BTW Y PTS
C    N - NUMBER OF X,Y PAIRS TO EXAMINE
C
C    ZLIMX1,ZLIMX2 - CONSTRAIN MIN/MAX SEARCH TO THIS X RANGE
C    IYONLY=1  ONLY DO Y AXIS SEARCH
C
C  AXES TYPES COMMON --
C
      INCLUDE 'GAXES_BLK'
C
C  SCALE SETTING COMMON BLOCKS --
C
      INCLUDE 'GSCALE_BLK'
C
C  X IN ANY ORDER
C
      DIMENSION X(NX),Y(NY),Y2(NY)
C
      DATA ZINFIN/1.0E37/
      DATA ZSMALL/1.0E-37/
C
      ZMINX=ZXLIM2
      ZMAXX=ZXLIM1
C
C  SAVE PREV. SETTINGS
C
      ZGMINY=GMINY
      ZGMAXY=GMAXY
C
      GMINY=ZINFIN
      GMAXY=-GMINY
C
C  FIND MIN,MAX OF FCN, AND MIN POSITIVE VALUES
C
      ZMINXP=0.0
      GMINYP=0.0
C
      IFND=0
C
      DO 10 I=1,N
C
      IX=IX1+(I-1)*INCX
      IF((X(IX).LT.ZXLIM1).OR.(X(IX).GT.ZXLIM2)) GO TO 10
C
      IFND=I
C
      IY=IY1+(I-1)*INCY
      GMINY=AMIN1(GMINY,Y(IY))
      GMAXY=AMAX1(GMAXY,Y(IY))
      ZMINX=AMIN1(ZMINX,X(IX))
      ZMAXX=AMAX1(ZMAXX,X(IX))
C
      IF(I2.NE.0) GMINY=AMIN1(GMINY,Y2(IY))
      IF(I2.NE.0) GMAXY=AMAX1(GMAXY,Y2(IY))
C
      IF(X(IX).LE.0.0) GO TO 4
C
      IF(ZMINXP.EQ.0.0) ZMINXP=X(IX)
      ZMINXP=AMIN1(ZMINXP,X(IX))
C
 4    CONTINUE
C
      IF(Y(IY).LE.0.0) GO TO 5
      IF(GMINYP.EQ.0.0) GMINYP=Y(IY)
      GMINYP=AMIN1(GMINYP,Y(IY))
C
 5    CONTINUE
C
      IF(I2.EQ.0) GO TO 6
      IF(Y2(IY).LE.0.0) GO TO 6
      IF(GMINYP.EQ.0.0) GMINYP=Y2(IY)
      GMINYP=AMIN1(GMINYP,Y2(IY))
C
 6    CONTINUE
C
 10   CONTINUE
C
C  FOUND ANY DATA?
C
      IF(IFND.NE.0) GO TO 100
C
C  NOTHING IN BOUNDS
C
      ZXMIN=ZXLIM1
      ZXMAX=ZXLIM2
C
      ZXA=0.5*(ZXMAX+ZXMIN)
      ZDIST=ABS(ZXA-X(IX1))
C
      DO 20 I=1,N
        IX=IX1+(I-1)*INCX
        ZD=ABS(ZXA-X(IX))
        IF(ZD.LE.ZDIST) THEN
          ZDIST=ZD
          IDMIN=I
        ENDIF
 20   CONTINUE
C
      IM1=MAX0(1,(IDMIN-1))
      IP1=MIN0(N,(IDMIN+1))
C
      IY=IY1+(IDMIN-1)*INCY
      IYP=IY1+(IP1-1)*INCY
      IYM=IY1+(IM1-1)*INCY
C
      GMINY=AMIN1(Y(IY),Y(IYP),Y(IYM))
      GMAXY=AMAX1(Y(IY),Y(IYP),Y(IYM))
C
 100  CONTINUE
C
C  CHECK ON LIMITS
C
      ZMINXP=AMAX1(ZSMALL,ZMINXP)
      GMINYP=AMAX1(ZSMALL,GMINYP)
C
      IF(IYONLY.NE.1) THEN
        GMINXP=ZMINXP
        GMINX=ZMINX
        GMAXX=ZMAXX
      ENDIF
C
      RETURN
      END
