      subroutine etaPr(spl,eta,pt,ldt1,ldm,lm)
!----------------------------------------------------------------------!
!                                                                      !
!     find the nearest pressure level to each eta                      !
!                                                                      !    
!----------------------------------------------------------------------! 
      implicit none

      INTEGER :: ldm,lm
      real::pt
      REAL ::  spl(ldm),peta(lm+1),dpu,dpd
      INTEGER:: ldt1(lm),i,l
      real,dimension(lm+1)::eta
      real,parameter::prf0=101325.

      do l=1,lm
         i=1
         peta(l)=(prf0-pt)*eta(l)+pt
	 print *,l,peta(l) !JBF

!!!!         print *,l,peta(l) !JBF

         do while (peta(l) .ge. spl(i) .and. i .lt. ldm)
!!!!??missing this line?  TEST
         peta(l)=(prf0-pt)*eta(l)+pt
	    i=i+1
         enddo
!	 print *,l,i,spl(i),peta(l)

         if (i .le. 2) then
            ldt1(l)=1
         elseif (i .eq. ldm) then
            ldt1(l)=ldm-2
         else
            dpu=abs(spl(i-2)-peta(l))
            dpd=abs(spl(i+1)-peta(l))
            if (dpu .gt. dpd) then
               ldt1(l)=i-1
            else
               ldt1(l)=i-2
            endif
         endif

!	 print *,l,ldt1(l)
      enddo
      return 
      END SUBROUTINE etaPr

