SURFEX v7.3
General documentation of Surfex
 All Classes Files Functions Variables Typedefs
/home/dasprezs/EXPORT_v7_3/src/SURFEX/hor_extrapol_surf.F90
Go to the documentation of this file.
00001 !     #########
00002       SUBROUTINE HOR_EXTRAPOL_SURF(KLUOUT,HCOORTYPE,PLAT_IN,PLON_IN,PFIELD_IN, &
00003                                          PLAT,PLON,PFIELD,OINTERP)  
00004 !     ###################################################################
00005 !
00006 !!**** *HOR_EXTRAPOL_SURF* extrapolate a surface field
00007 !!
00008 !!    PURPOSE
00009 !!    -------
00010 !!
00011 !!
00012 !!    METHOD
00013 !!    ------
00014 !!
00015 !!    For each point to interpolate, the nearest valid point value is set.
00016 !!
00017 !!    EXTERNAL
00018 !!    --------
00019 !!
00020 !!    IMPLICIT ARGUMENTS
00021 !!    ------------------
00022 !!
00023 !!    REFERENCE
00024 !!    ---------
00025 !!
00026 !!    AUTHOR
00027 !!    ------
00028 !!
00029 !!    V. Masson          Meteo-France
00030 !!
00031 !!    MODIFICATION
00032 !!    ------------
00033 !!
00034 !!    Original     01/12/98
00035 !!   V. Masson     01/2004 extrapolation in latitude and longitude
00036 !----------------------------------------------------------------------------
00037 !
00038 !*    0.     DECLARATION
00039 !            -----------
00040 !
00041 !
00042 USE MODD_SURF_PAR,   ONLY : XUNDEF
00043 USE MODD_CSTS,       ONLY : XPI
00044 !
00045 !
00046 USE YOMHOOK   ,ONLY : LHOOK,   DR_HOOK
00047 USE PARKIND1  ,ONLY : JPRB
00048 !
00049 IMPLICIT NONE
00050 !
00051 !*    0.1    Declaration of arguments
00052 !            ------------------------
00053 !
00054 INTEGER,               INTENT(IN)     :: KLUOUT   ! output listing logical unit
00055  CHARACTER(LEN=4),      INTENT(IN)     :: HCOORTYPE! type of coordinate
00056 REAL,   DIMENSION(:),  INTENT(IN)     :: PLAT_IN  ! input lat. of each grid mesh.
00057 REAL,   DIMENSION(:),  INTENT(IN)     :: PLON_IN  ! input lon. of each grid mesh.
00058 REAL,   DIMENSION(:),  INTENT(IN)     :: PFIELD_IN! input field on grid mesh
00059 REAL,   DIMENSION(:),  INTENT(IN)     :: PLAT     ! latitude of each grid mesh.
00060 REAL,   DIMENSION(:),  INTENT(IN)     :: PLON     ! longitude of each grid mesh.
00061 REAL,   DIMENSION(:),  INTENT(INOUT)  :: PFIELD   ! field on grid mesh
00062 LOGICAL,DIMENSION(:),  INTENT(IN)     :: OINTERP  ! .true. where physical value is needed
00063 !
00064 !*    0.2    Declaration of local variables
00065 !            ------------------------------
00066 !
00067 INTEGER  :: INO     ! output array size
00068 INTEGER  :: INO_IN  ! input  array size
00069 !
00070 REAL     :: ZLAT  ! latitude of point to define
00071 REAL     :: ZLON  ! longitude of point to define
00072 REAL     :: ZDIST ! current distance to valid point (in lat/lon grid)
00073 REAL     :: ZFIELD! current found field value
00074 REAL     :: ZNDIST! smallest distance to valid point
00075 REAL     :: ZCOSLA! cosine of latitude
00076 !
00077 INTEGER  :: JI    ! loop index on points
00078 INTEGER  :: JISC  ! loop index on valid points
00079 REAL     :: ZLONSC! longitude of valid point
00080 LOGICAL  :: GLALO ! flag true is second coordinate is a longitude or pseudo-lon.
00081 REAL(KIND=JPRB) :: ZHOOK_HANDLE
00082                   !      false if metric coordinates
00083 !-------------------------------------------------------------------------------
00084 !
00085 IF (LHOOK) CALL DR_HOOK('HOR_EXTRAPOL_SURF',0,ZHOOK_HANDLE)
00086 INO = SIZE(PFIELD,1)
00087 !
00088 WHERE (.NOT. OINTERP(:)) PFIELD(:) = XUNDEF
00089 !
00090 !-------------------------------------------------------------------------------
00091 !
00092 INO_IN = SIZE(PFIELD_IN)
00093 !
00094 GLALO = HCOORTYPE=='LALO'
00095 !
00096 !-------------------------------------------------------------------------------
00097 !
00098 !*    3.     No data point
00099 !            -------------
00100 !
00101 IF (COUNT(PFIELD_IN(:)/=XUNDEF)==0 .AND. LHOOK) CALL DR_HOOK('HOR_EXTRAPOL_SURF',1,ZHOOK_HANDLE)
00102 IF (COUNT(PFIELD_IN(:)/=XUNDEF)==0) RETURN
00103 !
00104 !-------------------------------------------------------------------------------
00105 !
00106 !*      4.   Loop on points to define
00107 !            ------------------------
00108 !
00109 !
00110 DO JI=1,INO
00111   IF (PFIELD(JI)/=XUNDEF) CYCLE
00112   IF (.NOT. OINTERP(JI))  CYCLE
00113 !
00114 !*      4.1  initialisation
00115 !            --------------
00116 !
00117   ZNDIST=1.E20
00118   ZLAT=PLAT(JI)
00119   ZLON=PLON(JI)
00120   ZFIELD=PFIELD(JI)
00121   ZCOSLA=COS(ZLAT*XPI/180.)
00122 !
00123 !*      4.2  extrapolation with nearest valid point
00124 !            --------------------------------------
00125 !
00126   DO JISC=1,INO_IN
00127     IF (PFIELD_IN(JISC)/=XUNDEF) THEN
00128       ZLONSC = PLON_IN(JISC)
00129       IF (GLALO) THEN
00130         IF (ZLONSC-ZLON> 180.) ZLONSC = ZLONSC - 360.
00131         IF (ZLONSC-ZLON<-180.) ZLONSC = ZLONSC + 360.
00132         ZDIST= (PLAT_IN(JISC)-ZLAT) ** 2 + ((ZLONSC-ZLON)*ZCOSLA) ** 2
00133       ELSE
00134         ZDIST= (PLAT_IN(JISC)-ZLAT) ** 2 + (ZLONSC-ZLON) ** 2
00135       END IF
00136       IF (ZDIST<=ZNDIST) THEN
00137         ZFIELD=PFIELD_IN(JISC)
00138         ZNDIST=ZDIST
00139       END IF
00140     END IF
00141   END DO
00142   PFIELD(JI) = ZFIELD
00143 
00144 END DO
00145 IF (LHOOK) CALL DR_HOOK('HOR_EXTRAPOL_SURF',1,ZHOOK_HANDLE)
00146 !
00147 !-------------------------------------------------------------------------------
00148 !
00149 END SUBROUTINE HOR_EXTRAPOL_SURF