      SUBROUTINE GSBYTE_MF ( KS, KD, KOFF, KSIZE, KSKBTW, K, KBPW,
     S                    CDADIR, KLENG, KERR, KWORD, LDNEXT )
C
      INTEGER JPSHOR
C
      PARAMETER ( JPSHOR=100 )
C
#include "precision.h"
C
      INTEGER KOFF, KSIZE, KSKBTW, K, KBPW, KLENG, KERR, KWORD
C
      INTEGER (KIND=JPDBLE) KS (*), KD (*)
C
      LOGICAL LDNEXT
C
      CHARACTER*1 CDADIR
C
      INTEGER IWORD, IOFF, IOFF2
      INTEGER (KIND=JPDBLE) IMASKS (128)
C
      SAVE IMASKS
C
      DATA IMASKS(2) / 0 /
C
      KERR=0
C
      IF (K.GT.0) THEN
        IOFF2=KOFF+(KSIZE+KSKBTW)*K
C
        IF (LDNEXT) THEN
C
          IWORD=KWORD+IOFF2/KBPW
          IOFF=MOD (IOFF2,KBPW)
        ELSE
          IWORD=KWORD+(IOFF2-1)/KBPW
          IOFF=1+MOD (IOFF2-1,KBPW)
        ENDIF
        IF (IWORD.GT.KLENG) THEN
          KERR = -2
          IF (CDADIR.EQ.'D') THEN
            WRITE (UNIT=*,FMT=*)
     S'GSBYTE - UNABLE TO PROCEED REQUESTED EXTRACTION FROM BIT STREAM:'
          ELSE
            WRITE (UNIT=*,FMT=*)
     S'GSBYTE - UNABLE TO PROCEED REQUESTED INSERTION INTO BIT STREAM:'
          ENDIF
          IF (LDNEXT) THEN
            WRITE (UNIT=*,FMT='('' GSBYTE - NEXT WORD'',I9,
     S             '' WOULD BE OUTSIDE ARRAY BOUNDS'',I9)') IWORD,KLENG
          ELSE
            WRITE (UNIT=*,FMT='('' GSBYTE - LAST WORD'',I9,
     S             '' WOULD BE OUTSIDE ARRAY BOUNDS'',I9)') IWORD,KLENG
          ENDIF
          RETURN
        ENDIF
      ELSE
        IWORD=KWORD
        IOFF=KOFF
      ENDIF
C     Vector machines use preferably GSBITE_MF :
#if  defined ( NECSX ) || defined ( VPP ) || defined ( CRAY )
      IF (K.GT.JPSHOR.OR.K.LE.0) THEN
        CALL GSBITE_MF (KS,KD,KOFF,KSIZE,KSKBTW,K,KBPW,IMASKS,CDADIR)
      ELSEIF (CDADIR.EQ.'D') THEN
        CALL GBYTES_MF (KS,KD,KOFF,KSIZE,KSKBTW,K)
      ELSE
        CALL SBYTES_MF (KS,KD,KOFF,KSIZE,KSKBTW,K)
      ENDIF
#else
      IF (CDADIR.EQ.'D') THEN
        CALL GBYTES_MF (KS,KD,KOFF,KSIZE,KSKBTW,K)
      ELSE
        CALL SBYTES_MF (KS,KD,KOFF,KSIZE,KSKBTW,K)
      ENDIF
#endif

      KWORD=IWORD
      KOFF=IOFF
      RETURN
      END
