FUNCTION CH_IGETMODLEV(rpress, rppobs, topbtm, ntotlev) 4
*
************************************************************************
*
*      PURPOSE: Get the vertical level index for the pressure in rppobs
*               within obs layer and nearest specified obs layer boundary.
*
*      ARGUMENTS:
*
*              rpress : pressure value in Pascal
*              rppobs : prefile of pressure at obs. location
*              topbtm : indicating whether we are looking for top or bottom
*                       presure
*              ntotlev: total levels of rppobs
*
*       AUTHOR: Y. Yang    May 2004
*
*       Revisions:
*                 Y.J. Rochon, ARQX/MSC May 2005
*                      - Indentation alignment
*                 Y.J. Rochon, ARQX/EC May 2007
*                      - Clarification of function purpose 
*
************************************************************************
*
      IMPLICIT NONE
#
      INTEGER CH_IGETMODLEV
      real*8 rpress, rppobs(ntotlev)
      INTEGER ilev1, ilev2, ntotlev
      INTEGER  jk
      character*3 topbtm
C
C     Find the model levels adjacent to pressure level rpress
C
C     Default values
C
      if (rpress .lt. 0.) then
        if((topbtm .eq. 'btm') .or. (topbtm .eq. 'BTM')) then
             CH_IGETMODLEV = ntotlev
        endif
        if((topbtm .eq. 'top') .or. (topbtm .eq. 'TOP')) then
             CH_IGETMODLEV = 1
        endif
C
         RETURN
      endif
C
      ilev1=0
      ilev2=1
      do jk=1,NTOTLEV
         if(rpress.gt.RPPOBS(jk)) then
           ilev1=jk
           ilev2=jk+1
         else
           exit
         endif
      enddo
C
C     Find the model level index
C
C     If we are looking for top level, the index is the level immediately 
C     below. if looking for bottom level, the index is the one immediately 
C     above.
C
      if((topbtm .eq. 'btm') .or. (topbtm .eq. 'BTM')) then
           CH_IGETMODLEV=ilev1
      elseif ((topbtm .eq. 'top') .or. (topbtm .eq. 'TOP')) then
           CH_IGETMODLEV=ilev2
      endif
C
      if (CH_IGETMODLEV .lt. 1) CH_IGETMODLEV=1
      if (CH_IGETMODLEV .gt. ntotlev) CH_IGETMODLEV=ntotlev
C
      RETURN
      END