!-------------------------------------- LICENCE BEGIN ------------------------------------
!Environment Canada - Atmospheric Science and Technology License/Disclaimer,
!                     version 3; Last Modified: May 7, 2008.
!This is free but copyrighted software; you can use/redistribute/modify it under the terms
!of the Environment Canada - Atmospheric Science and Technology License/Disclaimer
!version 3 or (at your option) any later version that should be found at:
!http://collaboration.cmc.ec.gc.ca/science/rpn.comm/license.html
!
!This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
!without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
!See the above mentioned License/Disclaimer for more details.
!You should have received a copy of the License/Disclaimer along with this software;
!if not, you can write to: EC-RPN COMM Group, 2121 TransCanada, suite 500, Dorval (Quebec),
!CANADA, H9P 1J3; or send e-mail to service.rpn@ec.gc.ca
!-------------------------------------- LICENCE END --------------------------------------
!

      SUBROUTINE SRCHLON (KILOC,PLONRAD,PLONDEG) 4
*
*
#if defined (DOC)
*
***s/r SRCHLON  - Calculate the longitude in radians and the index
*                 of the grid point nearest to PLONDEG
*
*
*
*Author: Luc Fillion  RPN/AES  Nov 98
*Revision:
*        C.Charette   ARMA     Jan 1999
*                  - Corrected bug in determintion of the nearest grid point
*
*     -------------------
**    Purpose: Used in the oneobs experiments
*     .
*
*Arguments
*     KILOC   OUT : INDEX OF THE GRID POINT
*     PLONRAD OUT : LONGITUDE OF GRID POINT (RADIANS;0<= LON < 2.*RPI)
*     PLONDEG IN  : LONGITUDE TO BE READ(DEGREES;0<= LON < 360)
#endif
*
      IMPLICIT NONE
*implicits
#include "comdim.cdk"
#include "comcst.cdk"
*
C
      REAL*8    PLONDEG,PLONRAD
      INTEGER   KILOC
C
      INTEGER   INDEX, JI
      REAL*8    ZOBSRAD, ZDEL, ZLONRAD(1000)
C
      ZOBSRAD = (2.*RPI/360.)*PLONDEG
      ZDEL    = 2.*RPI/NI
      DO JI = 1,NI+1
         ZLONRAD(JI) = (JI-1)*ZDEL
      ENDDO
C
      DO JI = 1,NI
         IF(ZLONRAD(JI) .LE. ZOBSRAD) INDEX = JI
      ENDDO
C
      IF(ABS(ZOBSRAD-ZLONRAD(INDEX)).LT.
     &                    ABS(ZOBSRAD-ZLONRAD(INDEX+1)))THEN
         KILOC = INDEX
      ELSE
         KILOC = INDEX + 1
      ENDIF
      IF(KILOC .EQ. NI+1) KILOC = 1
      PLONRAD = ZLONRAD(KILOC)
C
      RETURN
      END