     SUBROUTINE SSTG2EGRD(GLAT,GLON,INCR_LAT,INCR_LON,NX,AR1,AR2,AR3,AR4,LON1INDX,LON2INDX,        &
                       & LAT1INDX,LAT2INDX)
    USE PARMETA
    USE CONSTANTS
    USE DIAGNOSTIC
!
    IMPLICIT NONE
!
!
    REAL   (KIND=R4KIND)                          , INTENT(IN)              :: INCR_LAT
    REAL   (KIND=R4KIND)                          , INTENT(IN)              :: INCR_LON
    INTEGER(KIND=R4KIND)                          , INTENT(IN)              :: NX
    REAL   (KIND=R4KIND)   , DIMENSION(IM  ,JM)   , INTENT(IN)              :: GLAT
    REAL   (KIND=R4KIND)   , DIMENSION(IM  ,JM)   , INTENT(IN)              :: GLON  
    INTEGER(KIND=R4KIND)   , DIMENSION(IM  ,JM)   , INTENT(INOUT)           :: LON1INDX
    INTEGER(KIND=R4KIND)   , DIMENSION(IM  ,JM)   , INTENT(INOUT)           :: LON2INDX
    INTEGER(KIND=R4KIND)   , DIMENSION(IM  ,JM)   , INTENT(INOUT)           :: LAT1INDX
    INTEGER(KIND=R4KIND)   , DIMENSION(IM  ,JM)   , INTENT(INOUT)           :: LAT2INDX
    REAL   (KIND=R4KIND)   , DIMENSION(IM  ,JM)   , INTENT(INOUT)           :: AR1
    REAL   (KIND=R4KIND)   , DIMENSION(IM  ,JM)   , INTENT(INOUT)           :: AR2
    REAL   (KIND=R4KIND)   , DIMENSION(IM  ,JM)   , INTENT(INOUT)           :: AR3
    REAL   (KIND=R4KIND)   , DIMENSION(IM  ,JM)   , INTENT(INOUT)           :: AR4 
!
    INTEGER(KIND=R4KIND)                                                    :: I
    INTEGER(KIND=R4KIND)                                                    :: J
    INTEGER(KIND=R4KIND)                                                    :: GNAV_LAT
    INTEGER(KIND=R4KIND)                                                    :: GNAV_LON
    REAL   (KIND=R4KIND)                                                    :: DIST_X1
    REAL   (KIND=R4KIND)                                                    :: DIST_X2
    REAL   (KIND=R4KIND)                                                    :: DIST_Y1
    REAL   (KIND=R4KIND)                                                    :: DIST_Y2
    REAL   (KIND=R4KIND)                                                    :: DIST_P1
    REAL   (KIND=R4KIND)                                                    :: DIST_P2
    REAL   (KIND=R4KIND)                                                    :: DIST_P3
    REAL   (KIND=R4KIND)                                                    :: DIST_P4
    REAL   (KIND=R4KIND)                                                    :: SUM_DIST_P
    REAL   (KIND=R4KIND)                                                    :: ELAT
    REAL   (KIND=R4KIND)                                                    :: ELON
    REAL   (KIND=R4KIND)                                                    :: LAT1
    REAL   (KIND=R4KIND)                                                    :: LON1
    REAL   (KIND=R4KIND)                                                    :: LAT2
    REAL   (KIND=R4KIND)                                                    :: LON2
    REAL   (KIND=R4KIND)                                                    :: DIF
    REAL   (KIND=R4KIND)                                                    :: W1
    REAL   (KIND=R4KIND)                                                    :: W2
 

!----  INTERPOLATE 0.25-DEG GLOBAL SST TO ETA GRID  -------
!
!-CP NOTE:  THIS SUBROUTINE AND INTERPOLATION ALGORITHM ASSUME
!-CP A 0.25-DEG GLOBAL SST FIELD IN THE FOLLOWING FORMAT:  
!
!	I=1 at 0.125 E, I=1440 at 359.875E, I=1441 at 0.125 E
!	J=1 at 89.875 S, J=720 at 89.875 N 
!
!	Old 1 degree data
!	I=1 AT 0.5 E,  I=2 AT 1.5 E, ... , I=360 at 0.5W
!	J=1 AT 89.5S, J=2 AT 88.5 S, ..., J=180 at 89.5N
!
!	Old 0.5 degree data
!	I=1 at 0.25 E, I=720 at 359.75E, I=721 at 0.25 E
!	J=1 at 89.75 S, J=360 at 89.75 N 
!
!-CP  
!-CP In the interpolation algorithm below, glon is positive westward,
!-CP from 0 to 360, with 0 at the greenwich meridian.  Elon is positive 
!-CP eastward, thus the need to subtract glon from 360 to get the index
!-CP of the correct oisst point.  If your input 1 deg SST field is in
!-CP a different indexing scheme, you will need to change the algorithm
!-CP below - see "grdeta.oldoi"

      DO J=1,JM
        DO I=1,IM
	
          ELAT=H90+GLAT(I,J)/DTR
          ELON=H360-GLON(I,J)/DTR
          IF(ELON.GT.H360)ELON=ELON-H360
          GNAV_LON=INT(ELON/INCR_LON)
 	  DIF=ELON/INCR_LON-INT(ELON/INCR_LON)

!CCC    0.0833333358/2 = 0.0416666679
!CCC    0.0833333358*1.5=0.12500000370
          IF (DIF .GT. 0.5) THEN
            LON1INDX(I,J)=GNAV_LON+1
            IF(GNAV_LON+1.GT.NX)LON1INDX(I,J)=1 
            LON2INDX(I,J)=GNAV_LON
          ELSE
            LON1INDX(I,J)=GNAV_LON
            LON2INDX(I,J)=GNAV_LON+1
            IF(GNAV_LON+1.GT.NX)LON2INDX(I,J)=1 
          END IF 
 
!-MP    New approach sets ILAT1, ILON1 to point on SST grid that is
!-MP    SW of the Eta Grid point.
          
          GNAV_LAT=INT(ELAT/INCR_LAT)
 	  DIF=ELAT/INCR_LAT-INT(ELAT/INCR_LAT)
       !CCC    write(6,*) 'DIF_LAT: ',DIF
!CCC    0.0833719298/2=0.0416859649
!CCC    0.0833719298*1.5=0.12505789470
          IF (DIF .GT. 0.5) THEN
            LAT1INDX(I,J)=GNAV_LAT+1
            LAT2INDX(I,J)=GNAV_LAT
          ELSE
            LAT1INDX(I,J)=GNAV_LAT
            LAT2INDX(I,J)=GNAV_LAT+1
          END IF 

          LON1=LON1INDX(I,J)*INCR_LON
          LON2=LON2INDX(I,J)*INCR_LON
          LAT1=LAT1INDX(I,J)*INCR_LAT
          LAT2=LAT2INDX(I,J)*INCR_LAT
 
          DIST_Y1=ABS(ELAT-LAT1)/INCR_LAT
          DIST_Y2=ABS(ELAT-LAT2)/INCR_LAT
          DIST_X1=ABS(ELON-LON1)/INCR_LON
          DIST_X2=ABS(ELON-LON2)/INCR_LON

          DIST_P1=(DIST_Y1**2+DIST_X1**2)**0.5
          DIST_P2=(DIST_Y2**2+DIST_X1**2)**0.5
          DIST_P3=(DIST_Y2**2+DIST_X2**2)**0.5
          DIST_P4=(DIST_Y1**2+DIST_X2**2)**0.5
 
          SUM_DIST_P=DIST_P1+DIST_P2+DIST_P3+DIST_P4

          AR1(I,J)=DIST_P1/SUM_DIST_P
          AR2(I,J)=DIST_P2/SUM_DIST_P
          AR3(I,J)=DIST_P3/SUM_DIST_P
          AR4(I,J)=DIST_P4/SUM_DIST_P
         
          IF (DIAG) THEN
	    if ( (mod(I,(IM/2)) .eq. 0) .and. (mod(J,(JM/2)) .eq. 0) ) then
	      write(6,*) 'I, J: ',I, J
	      write(6,*) 'weights: ',AR1(I,J),AR2(I,J),AR3(I,J),AR4(I,J)
	      write(6,*) 'LAT1,LON1,ELAT,ELON: ', LAT1,LON1,LAT2,LON2,ELAT,ELON
	      write(6,*) '------------------------------------------'
	      write(6,*) 'corresponding indices: ',                               &
              &LAT1INDX(I,J),LON1INDX(I,J),LAT2INDX(I,J),LON2INDX(I,J)
	     endif
          ENDIF
        WRITE(1000,*)I,J,ELAT,ELON
        WRITE(1000,*)LAT1,LON1,LAT2,LON2
        WRITE(1000,*)LAT1INDX(I,J),LON1INDX(I,J),LAT2INDX(I,J),LON2INDX(I,J)
        WRITE(1000,*)AR1(I,J),AR2(I,J),AR3(I,J),AR4(I,J)
        END DO
      END DO
!
      END SUBROUTINE SSTG2EGRD





