      SUBROUTINE LL2ETA(GLATD,GLOND,IM,JM,TPH0D,TLM0DX,DPHD,DLMD,
     1                  II,JI,i,j)
      include "mpif.h"
      INCLUDE "MPI_PARM.comm"
      PARAMETER (D2R=1.74532925E-2,R2D=1./D2R)
C-----------------------------------------------------------------
Cmp
        real(8) DLM1,DLM2,TLAT1,TLON1,TLAT2,TLON2,D1,D2
	real(8) GLAT,GLON,TPH0,TLM0,DPH,DLM,TLAT,TLON,X,Y,Z
Cmp
      TLM0D=-TLM0DX
      IMT=2*IM-1
      JMT=JM/2+1
C***  
C***  CONVERT FROM GEODETIC TO TRANSFORMED COORDINATES (DEGREES)
C***
      GLAT=GLATD*D2R
      GLON=GLOND*D2R
      DPH=DPHD*D2R
      DLM=DLMD*D2R
      TPH0=TPH0D*D2R
      TLM0=TLM0D*D2R
C
C      X=COS(TPH0)*COS(GLAT)*COS(GLON-TLM0)+SIN(TPH0)*SIN(GLAT)
C      Y=-COS(GLAT)*SIN(GLON-TLM0)
C      Z=COS(TPH0)*SIN(GLAT)-SIN(TPH0)*COS(GLAT)*COS(GLON-TLM0)
      X=DCOS(TPH0)*DCOS(GLAT)*DCOS(GLON-TLM0)+DSIN(TPH0)*DSIN(GLAT)
      Y=-DCOS(GLAT)*DSIN(GLON-TLM0)
      Z=DCOS(TPH0)*DSIN(GLAT)-DSIN(TPH0)*DCOS(GLAT)*DCOS(GLON-TLM0)
      TLAT=R2D*DATAN(Z/SQRT(X*X+Y*Y))
      TLON=R2D*DATAN(Y/X)
C
C***
C***  FIND THE I,J INDEX (E.G. NCOL, NROW) OF THE NEAREST H POINT
C***
      ROW=TLAT/DPHD+JMT
      COL=TLON/DLMD+IM
      NROW=INT(ROW)
      NCOL=INT(COL)
      TLAT=TLAT*D2R
      TLON=TLON*D2R
C***
C***  FIRST CONSIDER THE SITUATION WHERE THE POINT X IS AT
C***
C***              V      H
C***
C***
C***                 X
C***              H      V
C***
      IF(MOD(NROW,2).EQ.1.AND.MOD(NCOL,2).EQ.1.OR.
     1   MOD(NROW,2).EQ.0.AND.MOD(NCOL,2).EQ.0)THEN
        TLAT1=(NROW-JMT)*DPH
        TLAT2=TLAT1+DPH
        TLON1=(NCOL-IM)*DLM
        TLON2=TLON1+DLM
        DLM1=TLON-TLON1
        DLM2=TLON-TLON2
Cmp        D1=ACOS(COS(TLAT)*COS(TLAT1)*COS(DLM1)+SIN(TLAT)*SIN(TLAT1))
Cmp        D2=ACOS(COS(TLAT)*COS(TLAT2)*COS(DLM2)+SIN(TLAT)*SIN(TLAT2))
      D1=DACOS(DCOS(TLAT)*DCOS(TLAT1)*DCOS(DLM1)+DSIN(TLAT)*DSIN(TLAT1))
      D2=DACOS(DCOS(TLAT)*DCOS(TLAT2)*DCOS(DLM2)+DSIN(TLAT)*DSIN(TLAT2))
        IF(D1.GT.D2)THEN
          NROW=NROW+1
          NCOL=NCOL+1
        ENDIF
C***
C***  NOW CONSIDER THE SITUATION WHERE THE POINT X IS AT
C***
C***              H      V
C***
C***
C***                 X
C***              V      H
C***
      ELSE
        TLAT1=(NROW+1-JMT)*DPH
        TLAT2=TLAT1-DPH
        TLON1=(NCOL-IM)*DLM
        TLON2=TLON1+DLM
        DLM1=TLON-TLON1
        DLM2=TLON-TLON2
Cmp        D1=ACOS(COS(TLAT)*COS(TLAT1)*COS(DLM1)+SIN(TLAT)*SIN(TLAT1))
Cmp        D2=ACOS(COS(TLAT)*COS(TLAT2)*COS(DLM2)+SIN(TLAT)*SIN(TLAT2))
      D1=DACOS(DCOS(TLAT)*DCOS(TLAT1)*DCOS(DLM1)+DSIN(TLAT)*DSIN(TLAT1))
      D2=DACOS(DCOS(TLAT)*DCOS(TLAT2)*DCOS(DLM2)+DSIN(TLAT)*DSIN(TLAT2))
        IF(D1.LT.D2)THEN
          NROW=NROW+1
        ELSE
          NCOL=NCOL+1
        ENDIF
      ENDIF
      
      JI=NROW
      IF (MOD(NROW,2) .EQ. 1) THEN
        II=(NCOL+1)/2
c        II=NCOL/2+1
      ELSE
        II=NCOL/2
      ENDIF

C***
C***  NOW WE CAN FIND THE K VALUE
C***
c      KROWS=((NROW-1)/2)*IMT
c      IF(MOD(NROW,2).EQ.1)THEN
c        K=KROWS+(NCOL+1)/2
c      ELSE
c        K=KROWS+IM+NCOL/2
c      ENDIF
C
      RETURN
      END
      
