      SUBROUTINE UNPKBMAP(KFILDO,IPACK,ND5,IB,NXY,L3264B,
     1                    LOCN,IPOS,IER,*)
C
C       MARCH   2000   LAWRENCE   GSC/TDL   ORIGINAL CODING
C       JANUARY 2001   GLAHN      COMMENTS
C       MARCH   2001   LAWRENCE   ADDED A LINE OF CODE TO ZERO
C                                 OUT EACH ELEMENT OF IB( )
C                                 BEFORE THE BIT-MAP IS READ INTO
C                                 IT. 
C
C        PURPOSE
C           UNPACKS THE BIT-MAP FROM THE IPACK ARRAY INTO IB(NXY).
C           THIS ROUTINE WAS DEVELOPED TO MAKE THE PROCESS OF UNPACKING
C           A BIT-MAP EFFICIENT BY REDUCING THE NUMBER OF CALLS
C           TO UNPKBG.
C
C        DATA SET USE
C           KFILDO - UNIT NUMBER FOR OUTPUT (PRINT) FILE. (OUTPUT)
C
C        VARIABLES
C              KFILDO = UNIT NUMBER FOR OUTPUT (PRINT) FILE. (INPUT)
C            IPACK(J) = THE ARRAY THAT HOLDS THE ACTUAL PACKED
C                       MESSAGE (J=1,ND5). (INPUT)
C                 ND5 = THE SIZE OF THE ARRAY IPACK( ). (INPUT)
C               IB(J) = THE UNPACKED BIT-MAP GOES IN HERE.
C                       (J=1,NXY). (OUTPUT)
C                 NXY = THE DIMENSIONS OF IB( ). THIS
C                       REFLECTS THE TRUE SIZE OF THE PRODUCT. (INPUT)
C              L3264B = THE INTEGER WORD LENGTH IN BITS OF THE MACHINE
C                       BEING USED. VALUES OF 32 AND 64 ARE
C                       ACCOMMODATED. (INPUT)
C                LOCN = THE WORD POSITION FROM WHICH TO UNPACK THE
C                       NEXT VALUE. (INPUT/OUTPUT)
C                IPOS = THE BIT POSITION IN LOCN FROM WHICH TO START
C                       UNPACKING THE NEXT VALUE.  (INPUT/OUTPUT)
C                 IER = RETURN STATUS CODE. (OUTPUT)
C                         0 = GOOD RETURN.
C                       6-8 = ERROR CODES GENERATED BY UNPKBG. SEE THE
C                             DOCUMENTATION IN THE UNPKBG ROUTINE.
C                   * = ALTERNATIVE ERROR RETURN.
C
C             LOCAL VARIABLES
C               IFILL = CONTAINS THE NUMBER OF BITS ZERO-PADDED 
C                       TO MAKE THE PACKED BIT-MAP OCCUPY A
C                       WHOLE NUMBER OF OCTETS.
C              ITRASH = HOLDS EXTRANEOUS INFORMATION READ IN
C                       FROM IPACK.
C                   J = LOOP INDEX.
C                   N = AN ABBREVIATED FORM OF L3264B. THIS IS 
C                       HELPFUL IN KEEPING THE LINES OF CODE
C                       UNDER 72 COLUMNS.
C
C        NON SYSTEM SUBROUTINES CALLED
C           UNPKBG
C
      DIMENSION IPACK(ND5),IB(NXY)
C
      N=L3264B
C
      DO J=1,NXY
C
         IB(J)=0
         CALL MVBITS(IPACK(LOCN),N-IPOS,1,IB(J),0)
C
         IF(IPOS.EQ.N)THEN
            IPOS=1
            LOCN=LOCN+1
         ELSE
            IPOS=IPOS+1
         ENDIF
      END DO
C
C        DETERMINE IF SOME TRAILING BITS NEED TO BE UNPACKED 
C        BECAUSE THE PACKED BIT-MAP DID NOT OCCUPY A WHOLE
C        NUMBER OF OCTETS. 
      IFILL=MOD(33-IPOS,8)
C
      IF(IFILL.NE.0)THEN
         CALL UNPKBG(KFILDO,IPACK,ND5,LOCN,IPOS,ITRASH,IFILL,N,IER,*900)
      ENDIF
C
C       ERROR RETURN SECTION
C
 900  IF(IER.NE.0)RETURN 1
C
      RETURN
      END
