C******************** START FILE G3INX1.FOR ; GROUP G3MSEL ******************
C-------------------------------------------------------------
C  G3INX1
C
C  INSERT PROFILE
C  GIVEN INDEPENDANT VARIABLE VALUE ZVAL FIND NEAREST INDEX
C  LOCATION AND CORRESPONDING INDEXED IND. VAR. VALUE.  CHECK
C  AGAINST DUPLICATION AND INSERT IN LIST
C
      SUBROUTINE G3INX1(ZVAL,ISELX,X,NX,Y,NY,ISELF,ZSELF,NDIM,NSEL)
C
      REAL X(NX),Y(NY),ZSELF(NDIM)
      INTEGER ISELF(NDIM)
C
      IF(NSEL.LT.NDIM) GO TO 10
      CALL UERMSG('? EXCEEDED MAX NUMBER OF SLICES',' ',2)
      RETURN
C
 10   CONTINUE
C  LOCATE NEAREST PT.
      IF(ISELX.EQ.2) GO TO 20
        ZDMIN=AMAX1(ABS(ZVAL-Y(1)),ABS(ZVAL-Y(NY)))
        INUM=NY
        GO TO 50
C
 20   CONTINUE
        ZDMIN=AMAX1(ABS(ZVAL-X(1)),ABS(ZVAL-X(NX)))
        INUM=NX
C
 50   CONTINUE
      DO 60 I=1,INUM
      IF(ISELX.EQ.1) ZD=ABS(ZVAL-Y(I))
      IF(ISELX.EQ.2) ZD=ABS(ZVAL-X(I))
      IF(ZD.GT.ZDMIN) GO TO 60
      IMIN=I
      ZDMIN=ZD
 60   CONTINUE
C
C  CHECK FOR DUPLICATION
C
      IF(NSEL.EQ.0) GO TO 100
      DO 70 J=1,NSEL
      IF(IMIN.EQ.ISELF(J)) GO TO 90
 70   CONTINUE
      GO TO 100
C  DUPLICATE
 90   CONTINUE
      RETURN
C
 100  CONTINUE
      NSEL=NSEL+1
      ISELF(NSEL)=IMIN
      IF(ISELX.EQ.1) ZSELF(NSEL)=Y(IMIN)
      IF(ISELX.EQ.2) ZSELF(NSEL)=X(IMIN)
      RETURN
      END
C******************** END FILE G3INX1.FOR ; GROUP G3MSEL ******************
