      FUNCTION NSCAN(S1,K1,N1,S2,K2,N2)
C     
C     VAX SUBPROGRAM TO EMULATE UWLIB STRING MANIPULATION 
C     PACKAGE NSCAN.
C     USE
C          M1=NSCAN(S1,K1,N1,S2,K2,N2)
C     WHERE
C        S1       IS THE CHARACTER VARIABLE CONTAINING THE 
C                 STRING OF CHARACTERS TO BE SEARCHED.  EACH
C                 CHARACTER IN STRING S1 WILL BE COMPARED WITH
C                 ALL CHARACTERS IN STRING S2.
C
C        K1       IF A LEFT-TO-RIGHT SCAN IS REQUESTED, K1 IS
C                 THE CHARACTER POSITION OF THE LEFTMOST 
C                 CHARACTER IN S1 TO BE COMPARED WITH THE
C                 LEFTMOST CHARACTER IN THE DESIRED STRING.
C                 IF A RIGHT-TO-LEFT SCAN IS REQUESTED, K1 IS
C                 THE CHARACTER POSITION OF THE RIGHTMOST
C                 CHARACTER IN S1 TO BE COMPARED WITH THE 
C                 RIGHTMOST CHARACTER IN THE DESIRED STRING.
C                 TYPE INTEGER.
C
C        N1       IS THE NUMBER OF S1 CHARACTERS TO BE SCANNED.
C                 IF STRING S1 IS TO BE SCANNED RIGHT TO LEFT,
C                 THE VALUE OF N1 MUST BE NEGATIVE.  TYPE 
C                 INTEGER.
C
C        S2       IS A CHARACTER VARIABLE CONTAINING THE POOL
C                 OF CHARACTERS TO BE COMPARED WITH EACH S1
C                 CHARACTER.
C
C        K2       IS THE CHARACTER POSITION OF THE FIRST POOL 
C                 MEMBER, RELATIVE TO TO THE LEFTMOST POSITION
C                 OF ARRAY S2.  TYPE INTEGER.
C
C        N2       IS THE NUMBER OF CHARACTERS IN ARRAY S2 TO BE
C                 USED AS THE POOL.  N2 MUST BE A POSITIVE 
C                 INTEGER.
C        
C        M1       IS RETURNED AS THE LOCATION OF THE FIRST
C                 CHARACTER ENCOUNTERED IN S1 FOR WHICH THERE
C                 WAS NO MATCH IN S2.  IF ALL CHARACTERS IN
C                 S1 CAN BE MATCHED WITH CHARACTERS IN S2, M1
C                 WILL CONTAIN ZERO.  IF THERE IS AN ERROR IN
C                 THE CALLING SEQUENCE, M1 WILL CONTAIN MINUS 
C                 ONE. TYPE INTEGER.
C
      CHARACTER S1*(*),S2*(*)
C
C     INITIALIZE SOME VALUES
C
      NSCAN=0
      IONE=ISIGN(1,N1)
      J1=K1+N1-IONE
      IF(IONE.GT.0)THEN
           J2A=K2
           J2B=N2+K2-1
      ELSE
           J2A=N2+K2-1
           J2B=K2
      ENDIF
C
C     CHECK INPUT VALUES
C
      NCHARS=LEN(S1)
      IF(K1.GT.NCHARS.OR.K1.LT.1)NSCAN=-1
      IF(J1.GT.NCHARS.OR.J1.LT.1)NSCAN=-1
      NCHARS=LEN(S2)
      IF(K2.GT.NCHARS.OR.K2.LT.1)NSCAN=-1
      IF(N2.LT.1.OR.N2+K2-1.GT.NCHARS)NSCAN=-1
      IF(NSCAN.LT.0)RETURN
C
C     CHECK EACH CHARACTER IN S1 UNTIL A NONMATCH IS FOUND OR
C     UNTIL I=J1.
C
      DO 140 I=K1,J1,IONE
C
C          CHECK EACH CHARACTER IN S2 AGAINST THE CURRENT 
C          CHARACTER FROM S1 UNTIL A MATCH IS FOUND. IF NO 
C          MATCH IS FOUND, TERMINATE.
C     
           DO 100 J=J2A,J2B,IONE
                IF(S2(J:J).EQ.S1(I:I))GO TO 140
  100      CONTINUE
C    
C     NON-MATCH FOUND
C
      NSCAN=I
      RETURN
C
C     MATCH FOUND
C
  140 CONTINUE
      RETURN
      END
