      SUBROUTINE UNPK_SECT1(KFILDO,IPACK,ND5,IS1,NS1,L3264B,
     1                      LOCN,IPOS,IER,ISEVERE,*)
C
C        MARCH    2000   LAWRENCE  GSC/TDL   ORIGINAL CODING
C        JANUARY  2001   GLAHN     COMMENTS; ELIMINATED EXISTS;
C                                  SET IER = 100 WHEN IS1(5) DOES
C                                  NOT INDICATE SECTION 1
C        FEBRUARY 2001   GLAHN     CHECKED SIZE OF NS1
C        NOVEMBER 2001   GLAHN     MOVED ISEVERE=2 UP TO BEGINNING
C
C        PURPOSE
C            UNPACKS SECTION 1, THE IDENTIFICATION SECTION, OF A GRIB2
C            MESSAGE.
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 MESSAGE
C                       (J=1,ND5). (INPUT/OUTPUT)
C                 ND5 = THE SIZE OF THE ARRAY IPACK( ). (INPUT)
C              IS1(J) = THE IDENTIFICATION DATA THAT IS UNPACKED FROM
C                       IPACK( ) IS WRITTEN TO THIS ARRAY (J=1,NS1).
C                       (OUTPUT)
C                 NS1 = SIZE OF IS1( ). (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                        100 = NO SECTION 1 ON A NEW PRODUCT.
C                        102 = IS1( ) HAS NOT BEEN DIMENSIONED LARGE
C                              ENOUGH TO CONTAIN THE ENTIRE TEMPLATE. 
C                        199 = UNEXPECTED END OF MESSAGE.
C             ISEVERE = THE SEVERITY LEVEL OF THE ERROR.  THE ONLY
C                       VALUE RETUNED IS:
C                       2 = A FATAL ERROR  (OUTPUT)
C                   * = ALTERNATE RETURN WHEN IER NE 0.
C
C             LOCAL VARIABLES
C             LOCN1_1 = SAVES THE WORD POSITION LOCN IN IPACK
C                       UPON ENTRY TO STORE BACK TO LOCN IN CASE
C                       THERE IS A FATAL ERROR.
C             IPOS1_1 = SAVES THE BIT POSITION IPOS IN LOCN
C                       UPON ENTRY TO STORE BACK TO IPOS IN CASE
C                       THERE IS A FATAL ERROR.
C               LSECT = CONTAINS THE LENGTH OF SECTION 1
C                       AS UNPACKED FROM THE FIRST FOUR
C                       BYTES IN THE SECTION.
C               NSECT = SECTION NUMBER.
C                   K = A LOOPING INDEX VARIABLE.
C                   N = L3264B = THE INTEGER WORD LENGTH IN BITS OF
C                       THE MACHINE BEING USED. VALUES OF 32 AND
C                       64 ARE ACCOMMODATED.
C
C        NON SYSTEM SUBROUTINES CALLED
C           ENDOMESS, UNPKBG
C
      DIMENSION IPACK(ND5),IS1(NS1)
C
      LOGICAL ENDOMESS
C
      N=L3264B
      IER=0
C
C        ANY ERRORS GENERATED FROM WITHIN THIS ROUTINE WILL BE FATAL.
      ISEVERE=2
C
C        CHECK SIZE OF IS1( ).
C
      IF(NS1.LT.21)THEN
         IER=102
         GO TO 900
      ENDIF
C
      LOCN1_1=LOCN
      IPOS1_1=IPOS
C
C        UNPACK SECTION LENGTH, LSECT.
      CALL UNPKBG(KFILDO,IPACK,ND5,LOCN,IPOS,LSECT,32,N,IER,*900)
C
C        CHECK FOR AN UNEXPECTED END OF MESSAGE.
      IF(ENDOMESS(LSECT,N))THEN
         IER=199
         GO TO 900
      ENDIF
C
C        UNPACK THE SECTION NUMBER. CHECK TO SEE IF THIS
C        IS SECTION 1.
      CALL UNPKBG(KFILDO,IPACK,ND5,LOCN,IPOS,NSECT,8,N,IER,*900)
C
      IF(NSECT.NE.1)THEN
         IER=100
C           A SECTION 1 MUST BE PRESENT WHEN UNPK_SECT1 IS CALLED
C           OR IT IS A FATAL ERROR.
         LOCN=LOCN1_1
         IPOS=IPOS1_1 
         GO TO 900 
      ENDIF
C
      DO K=1,NS1
         IS1(K)=0
      ENDDO
C
      IS1(1)=LSECT
      IS1(5)=NSECT
C
C        UNPACK OCTETS 6 THRU 13.
      CALL UNPKBG(KFILDO,IPACK,ND5,LOCN,IPOS,IS1(6),16,N,IER,*900)
      CALL UNPKBG(KFILDO,IPACK,ND5,LOCN,IPOS,IS1(8),16,N,IER,*900)  
      CALL UNPKBG(KFILDO,IPACK,ND5,LOCN,IPOS,IS1(10),8,N,IER,*900)  
      CALL UNPKBG(KFILDO,IPACK,ND5,LOCN,IPOS,IS1(11),8,N,IER,*900)  
      CALL UNPKBG(KFILDO,IPACK,ND5,LOCN,IPOS,IS1(12),8,N,IER,*900)
      CALL UNPKBG(KFILDO,IPACK,ND5,LOCN,IPOS,IS1(13),16,N,IER,*900)
C
C         UNPACK OCTETS 15 THRU 21.      
C
      DO 160 K=15,21
         CALL UNPKBG(KFILDO,IPACK,ND5,LOCN,IPOS,IS1(K),8,N,IER,*900)  
 160  CONTINUE
C
C       ERROR RETURN SECTION
 900  IF(IER.NE.0)RETURN 1
C
      RETURN
      END
