SURFEX v7.3
General documentation of Surfex
 All Classes Files Functions Variables Typedefs
/home/dasprezs/EXPORT_v7_3/src/SURFEX/get_mesh_index_lonlat_reg.F90
Go to the documentation of this file.
00001 !     ###############################################################
00002       SUBROUTINE GET_MESH_INDEX_LONLAT_REG(KGRID_PAR,KL,PGRID_PAR,PLAT,PLON,KINDEX,KSSO,KISSOX,KISSOY)
00003 !     ###############################################################
00004 !
00005 !!**** *GET_MESH_INDEX_LONLAT_REG* get the grid mesh where point (lat,lon) is located
00006 !!
00007 !!    PURPOSE
00008 !!    -------
00009 !!
00010 !!    AUTHOR
00011 !!    ------
00012 !!
00013 !!    V. Masson         Meteo-France
00014 !!
00015 !!    MODIFICATION
00016 !!    ------------
00017 !!
00018 !!    Original    12/09/95
00019 !!
00020 !----------------------------------------------------------------------------
00021 !
00022 !*    0.     DECLARATION
00023 !            -----------
00024 !
00025 USE MODD_GET_MESH_INDEX_LONLAT_REG, ONLY : XLONLIM, XLATLIM, NLAT, NLON, XLON0
00026 USE MODE_GRIDTYPE_LONLAT_REG
00027 !
00028 !
00029 USE YOMHOOK   ,ONLY : LHOOK,   DR_HOOK
00030 USE PARKIND1  ,ONLY : JPRB
00031 !
00032 IMPLICIT NONE
00033 !
00034 !*    0.1    Declaration of arguments
00035 !            ------------------------
00036 !
00037 INTEGER,                       INTENT(IN)    :: KGRID_PAR ! size of PGRID_PAR
00038 INTEGER,                       INTENT(IN)    :: KL        ! number of points
00039 REAL,    DIMENSION(KGRID_PAR), INTENT(IN)    :: PGRID_PAR ! grid parameters
00040 REAL,    DIMENSION(KL),        INTENT(IN)    :: PLAT      ! latitude of the point
00041 REAL,    DIMENSION(KL),        INTENT(IN)    :: PLON      ! longitude of the point
00042 INTEGER, DIMENSION(KL),        INTENT(OUT)   :: KINDEX    ! index of the grid mesh where the point is
00043 INTEGER,                       INTENT(IN)    :: KSSO      ! number of subgrid mesh in each direction
00044 INTEGER, DIMENSION(KL),        INTENT(OUT)   :: KISSOX    ! X index of the subgrid mesh
00045 INTEGER, DIMENSION(KL),        INTENT(OUT)   :: KISSOY    ! Y index of the subgrid mesh
00046 !
00047 !*    0.2    Declaration of other local variables
00048 !            ------------------------------------
00049 !
00050 INTEGER                           :: JI       ! loop counter in x
00051 INTEGER                           :: JJ       ! loop counter in y
00052 INTEGER                           :: JL       ! loop counter on input points
00053 !
00054 REAL    :: ZLONMIN ! minimum longitude (degrees)
00055 REAL    :: ZLONMAX ! maximum longitude (degrees)
00056 REAL    :: ZLATMIN ! minimum latitude  (degrees)
00057 REAL    :: ZLATMAX ! maximum latitude  (degrees)
00058 REAL    :: ZDLON   ! longitude grid size
00059 REAL    :: ZDLAT   ! latitude  grid size
00060 !
00061 REAL, DIMENSION(SIZE(PLON)) :: ZLON
00062 REAL(KIND=JPRB) :: ZHOOK_HANDLE
00063 !
00064 !----------------------------------------------------------------------------
00065 !
00066 IF (LHOOK) CALL DR_HOOK('GET_MESH_INDEX_LONLAT_REG',0,ZHOOK_HANDLE)
00067 IF (.NOT. ALLOCATED(XLATLIM)) THEN
00068 !
00069 !*    1.     Uncode parameters of the grid
00070 !            -----------------------------
00071 !
00072   CALL GET_GRIDTYPE_LONLAT_REG(PGRID_PAR,ZLONMIN,ZLONMAX, &
00073                                  ZLATMIN,ZLATMAX,NLON,NLAT  )  
00074 !
00075 !----------------------------------------------------------------------------
00076 !
00077 !*    2.     Limits of grid meshes
00078 !            ---------------------
00079 !
00080   ZDLON = (ZLONMAX-ZLONMIN) / FLOAT(NLON)
00081   ZDLAT = (ZLATMAX-ZLATMIN) / FLOAT(NLAT)
00082 !
00083   ALLOCATE(XLONLIM(NLON+1))
00084   DO JI=1,NLON+1
00085     XLONLIM(JI) = ZLONMIN + FLOAT(JI-1)*ZDLON
00086   END DO
00087 
00088   ALLOCATE(XLATLIM(NLAT+1))
00089   DO JI=1,NLAT+1
00090     XLATLIM(JI) = ZLATMIN + FLOAT(JI-1)*ZDLAT
00091   END DO
00092 !
00093   XLON0 = 0.5*(ZLONMIN+ZLONMAX)
00094 !
00095 END IF
00096 !----------------------------------------------------------------------------
00097 !
00098 !*    3.     Reshifts the longitudes with respect to projection reference point
00099 !            ------------------------------------------------------------------
00100 !
00101 !
00102 ZLON(:) = PLON(:)+NINT((XLON0-PLON(:))/360.)*360.
00103 !
00104 !----------------------------------------------------------------------------
00105 !
00106 !*    4.     Localisation of the data points on (x,y) grid
00107 !            ---------------------------------------------
00108 !
00109 IF (KL/=NLON*NLAT) THEN
00110   KINDEX = 0
00111   KISSOX = 0
00112   KISSOY = 0
00113 END IF
00114 !
00115 !
00116 DO JL=1,SIZE(PLAT)
00117   IF (     ZLON(JL)<XLONLIM(1) .OR. ZLON(JL)>=XLONLIM(NLON+1) &
00118         .OR. PLAT(JL)<XLATLIM(1) .OR. PLAT(JL)>=XLATLIM(NLAT+1) ) THEN  
00119     KINDEX(JL) = 0
00120     IF (KSSO/=0) THEN
00121       KISSOX(JL) = 0
00122       KISSOY(JL) = 0
00123     END IF
00124     CYCLE
00125   END IF
00126   JI = COUNT (ZLON(JL)>=XLONLIM(:))
00127   JJ = COUNT (PLAT(JL)>=XLATLIM(:))
00128   KINDEX(JL) = (JJ-1) * NLON + JI
00129 !
00130 !
00131 !*    6.     Localisation of the data points on in the subgrid of this mesh
00132 !            --------------------------------------------------------------
00133 !
00134   IF (KSSO/=0) THEN
00135     KISSOX(JL) = 1 + INT( FLOAT(KSSO) * (ZLON(JL)-XLONLIM(JI))/(XLONLIM(JI+1)-XLONLIM(JI)) )
00136     KISSOY(JL) = 1 + INT( FLOAT(KSSO) * (PLAT(JL)-XLATLIM(JJ))/(XLATLIM(JJ+1)-XLATLIM(JJ)) )
00137   END IF
00138 END DO
00139 IF (LHOOK) CALL DR_HOOK('GET_MESH_INDEX_LONLAT_REG',1,ZHOOK_HANDLE)
00140 !
00141 !-------------------------------------------------------------------------------
00142 !
00143 END SUBROUTINE GET_MESH_INDEX_LONLAT_REG