      SUBROUTINE RPKPHS3(NF,G,NLEV,IBUF,LON,ILAT,ILEV,LEV,LH,IPKGRD,OK) 

C     * NOV 20/94 - M. LAZARE. ARRAY "G" NOW PROPERLY DEFINED TO HANDLE
C     *                        32-BIT MACHINES AS WELL.
C     * OCT 04/93 - M. LAZARE. DEFINE IPKGRD1 PROPERLY USING "INTSIZE"
C     *                        NOW PASSED IN COMMON BLOCK "MACHTYP".
C     * FEB 20/93 - M. LAZARE. I/O NOW DONE ON COMPLETE GRIDS INSTEAD
C     *                        OF LATITUDE SLICES.
C     * JUL 31/92 - M. LAZARE, E. CHAN, P. MASIER. PREVIOUS VERSION
C     *                        RPKPHS2.
  
C     * READS FROM THE SEQUENTIAL FILE NF THE PACKED ARRAY G WHOSE
C     * EIGHT WORD LABEL IS GIVEN BY IBUF.

C     * THE REPEATING GRENWICH LONGITUDE IS STRIPPED OFF BEFORE
C     * INSERTING INTO ARRAY G.
C     * NOTE THAT THIS CALCULATION, TO AVOID THE OVERHEAD OF GOING
C     * THROUGH THE PACKER, ASSUMES ALL GRID FIELDS ARE UNPACKED
C     * INTERNALLY IN THE GCM (NEW STANDARD).

C     * G CAN BE MULTIDIMENTIONAL, BUT OTHERWISE NLEV HAS TO BE SET 
C     * TO ONE. 
  
C     * THE FIELDS EMD,EMM ARE HANDLED DIFFERENTLY BECAUSE THEY HAVE
C     * "LEV" LEVELS AND ARE ORDERED BOTTOM UP. 
C
C     * 
C     * INPUT: NF    = SEQUENTIAL RESTART FILE. 
C     *        NLEV  = NUMBER OF LEVELS. CAN BE EITHER 1,LEV,ILEV,LEVS. 
C     *        IBUF  = EIGHT WORD LABEL.
C     *         LON  = NUMBER OF DISTINCT EQUALLY-SPACED LONGITUDES.
C     *        ILAT  = NUMBER OF GAUSSIAN LATITUDES.
C     *        ILEV  = NUMBER OF MODEL SIGMA LEVELS.
C     *         LEV  = ILEV+1 
C     *          LH  = VECTOR OF MODEL HALF-LEVEL SIGMA VALUES. 
C     *        IPKGRD= LENGTH OF PACKED GRID. 
C     * 
C     * OUTPUT: G    = PACKED ARRAY PRECEDED BY THE EIGHT WORD
C     *                LABEL IBUF.
C     *         OK   = LOGICAL SWITCH. WHEN THE EXECUTION IS INCORRECT
C     *                OK IS FALSE. 
  
      IMPLICIT REAL (A-H,O-Z),
     +INTEGER (I-N)

      INTEGER IBUF(8), KBUF(8), LH(NLEV)
      INTEGER G(1)
C
      COMMON /RSMXSZ/ MX 
      COMMON /ICOM/ JBUF(8), IDAT(1)
      COMMON /MACHTYP/ MACHINE,INTSIZE
C  
      LOGICAL OK
C-----------------------------------------------------------------------
      OK = .TRUE. 
      JX = 0
      LON1=LON+1
C
C     * DEFINE SIZE OF GRID INCLUDING EXTRA CYCLIC LONGITUDE
C     * (ONE FOR EACH LATITUDE).
C
      IPKGRD1=(IPKGRD+ILAT)*INTSIZE 
C
      DO 30 I=1,8
          KBUF(I)=IBUF(I)
   30 CONTINUE
C
      DO 100 L = 1,NLEV 
          IF( NLEV.EQ.1 )         THEN
              KBUF(4) = 1
          ELSE IF( NLEV.EQ.LEV )  THEN
              IF( L.EQ.LEV ) THEN 
              IF(KBUF(3).NE.NC4TO8(" EMD") .AND. 
     1           KBUF(3).NE.NC4TO8(" EMM")) CALL XIT('RPKPHS3',-1)
                 KBUF(4) = 0
              ELSE
                 KBUF(4) = LH(LEV-L)
              ENDIF 
          ELSE
              KBUF(4) = LH(L)
          ENDIF 
C
          CALL FBUFFIN(NF,JBUF,IPKGRD1+8,K,LEN)
          IF (K.GE.0)                  CALL XIT('RPKPHS3', -2)
          CALL CMPLBL(0,KBUF,0,JBUF,OK) 
          IF((.NOT.OK).OR.( JBUF(3).NE.KBUF(3) )
     1                .OR.( JBUF(4).NE.KBUF(4) ))     GO TO 900 
C
C         * STORE READ DATA INTO REQUIRED ARRAY, SKIPPING CYCLIC
C         * LONGITUDE. NOTE THAT AN INNERMOST LOOP OVER "INTSIZE"
C         * MUST BE ADDED; THIS IS BECAUSE THE DATA READ IN FOR
C         * INTSIZE=2 IS 64-BIT REALS BUT IS PROCESSED HERE IN 
C         * TERMS OF 32-BIT INTEGERS ON A 32-BIT MACHINE.
C
          DO 60 J=1,ILAT
              DO 50 I=1,LON
                  DO 40 INT=1,INTSIZE  
                      JX=JX+1
                      N=8+INTSIZE*((J-1)*LON1+(I-1))+INT 
                      G(JX)=JBUF(N) 
   40             CONTINUE
   50         CONTINUE 
   60     CONTINUE
C
  100 CONTINUE
C
      DO 300 I=1,8
          IBUF(I)=KBUF(I)
  300 CONTINUE
C
      RETURN
C-------------------------------------------------------------------- 
  900 OK = .FALSE.
      WRITE(6,6025) (JBUF(I),I=1,8)
      WRITE(6,6026) (KBUF(I),I=1,8)
 6025 FORMAT('0JBUF: ',A4,I10,A4,5(1X,I5))
 6026 FORMAT('0KBUF: ',A4,I10,A4,5(1X,I5))
C--------------------------------------------------------------
      END
