      SUBROUTINE MOVBIT(DATA,POS,NBITS,VAL,IBEG)
C
C ROUTINE TO EXTRACT N BITS FROM ARRAY DATA STARTING AT BIT POSITION IOFF
C AND PLACE THESE BITS INTO WORD VAL STARTING AT BIT POSITION IBEG.
C
      INTEGER*4 VAL
      INTEGER*4 DATA(1),POS
      LOGICAL*4 IVAL
C
      IWORD = INT(POS/32) + 1
      IOFF = MOD(POS,32)
      DO I=0,NBITS-1
C      IVAL = BTEST(DATA(1),POS+I)
       IVAL = BTEST(DATA(IWORD),IOFF+I)
C      TYPE*,I,IVAL
       IF (IVAL) VAL = (IBSET(VAL,IBEG+I))
       IF (.NOT.IVAL) VAL = (IBCLR(VAL,IBEG+I))
      END DO
C
      RETURN
      END
