      SUBROUTINE EXTRAC2(GG,ILG1,ILAT,DLAT,GLL,NLG1,NLAT,DEGLAT
     1                  ,SHFTLG,SHIFTIN,SHIFTOUT)
C
C     * FEB 10 /94 - D.RAMSDEN ALLOW FOR SHIFTED GRIDS 
C                    MODIFIED FROM EXTRACT
C     * JULY 11/85 - M.LAZARE. PREVIOUS VERSION EXTRACT.
  
C     * EXTRACTS A GLOBAL GRID GG(ILG1,ILAT) FROM ANOTHER OF DIFFERENT
C     * DIMENSION (NLG1,NLAT), REGARDLESS OF WHETHER THEY ARE GAUSSIAN OR 
C     * LAT-LONG. 
C     * EACH GG POINT TAKES THE VALUE OF THE CLOSEST POINT IN GLL.
  
C     * GG HAS ILG EQUALLY SPACED LONGITUDES (MAY BE SHIFTED). 
C     * DLAT(ILAT) CONTAINS GG LATITUDES IN DEGREES S. TO N.
  
C     * GLL HAS NLG EQUALLY SPACED LONGITUDES (MAY BE SHIFTED).
C     * DEGLAT(NLAT) CONTAINS GLL LATITUDES IN DEGREES S. TO N. 
  
C     * FOR GRIDS WHICH ARE NOT SHIFTED THE LEFT SIDE IS REPEATED. 
  
      IMPLICIT REAL (A-H,O-Z),
     +INTEGER (I-N)
      REAL GG(ILG1,ILAT),GLL(NLG1,NLAT) 
      REAL DLAT(ILAT),DEGLAT(NLAT)
      LOGICAL SHIFTIN,SHIFTOUT
C-----------------------------------------------------------------------
      IF(.NOT.SHIFTOUT)THEN
          ILG=ILG1-1
      ELSE
          ILG=ILG1
      ENDIF
C
      IF(.NOT.SHIFTIN)THEN
          NLG=NLG1-1
      ELSE
          NLG=NLG1
      ENDIF
C
      DEGX=360.E0/REAL(NLG)
  
C     * THE ROWS ARE DONE FROM SOUTH TO NORTH.
  
      DO 400 J=1,ILAT 
         DYOLD=180.E0 
         DO 100 KKK=1,NLAT
            DY=ABS(DLAT(J)-DEGLAT(KKK)) 
            IF(DY.LT.DYOLD) THEN
               DYOLD=DY 
               JJ=KKK 
            ELSE
               GOTO 200 
            ENDIF 
  100    CONTINUE 
  
C     * EXTRACT THE POINTS FROM LEFT TO RIGHT IN EACH ROW.
C     * DLON = DEGREES OF POINT I EASTWARD FROM GREENWICH.
  
  200    DO 300 I=1,ILG 
            DLON=REAL(I-1)/REAL(ILG)*360.E0 
            IF(SHIFTOUT)DLON=DLON+SHFTLG
            IF(SHIFTIN)DLON=DLON-SHFTLG
            X=DLON/DEGX+1.E0
            II=INT(X) 
            DX=X-REAL(II)
C***        II=CVMGT(II,II+1,DX.LE.0.5) 
            IF(DX.GT.0.5E0) II=II+1
            IF(II.EQ.0)II=NLG1
            IF(II.GT.NLG1)II=1  
            GG(I,J)=GLL(II,JJ)
  300    CONTINUE 
  
         IF(.NOT.SHIFTOUT)GG(ILG1,J)=GG(1,J) 
  400 CONTINUE
  
      RETURN
      END 
