SURFEX  V8_0
Surfex V8_0 release
 All Classes Files Functions Variables
hor_interpol_rotlatlon.F90
Go to the documentation of this file.
1 !SFX_LIC Copyright 1994-2014 CNRS, Meteo-France and Universite Paul Sabatier
2 !SFX_LIC This is part of the SURFEX software governed by the CeCILL-C licence
3 !SFX_LIC version 1. See LICENSE, CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt
4 !SFX_LIC for details. version 1.
5 ! #########
6 SUBROUTINE hor_interpol_rotlatlon(KLUOUT,PFIELDIN,PFIELDOUT)
7 ! #################################################################################
8 !
9 !!**** *HOR_INTERPOL_ROTLATLON * - Interpolation from a rotated lat/lon grid
10 !!
11 !! PURPOSE
12 !! -------
13 !!
14 !!** METHOD
15 !! ------
16 !!
17 !! REFERENCE
18 !! ---------
19 !!
20 !!
21 !! AUTHOR
22 !! ------
23 !! U. Andrae
24 !!
25 !! MODIFICATIONS
26 !! -------------
27 !! Original 10/2007
28 !! P. Samuelsson 10/2014 Moved subroutine REGROT to separate routine
29 !!------------------------------------------------------------------
30 !
31 !
32 !
33 USE modd_prep, ONLY : xlat_out, xlon_out
35 USE modd_surf_par, ONLY : xundef
36 USE modd_grid_grib, ONLY : nni
37 !
38 !RJ: missing modi
39 USE modi_regrot_lonlat_rot
40 !
41 !
42 USE yomhook ,ONLY : lhook, dr_hook
43 USE parkind1 ,ONLY : jprb
44 !
45 IMPLICIT NONE
46 !
47 !* 0.1 declarations of arguments
48 !
49 INTEGER, INTENT(IN) :: kluout ! logical unit of output listing
50 REAL, DIMENSION(:,:), INTENT(IN) :: pfieldin ! field to interpolate horizontally
51 REAL, DIMENSION(:,:), INTENT(OUT) :: pfieldout ! interpolated field
52 !
53 !* 0.2 declarations of local variables
54 !
55 
56  INTEGER, ALLOCATABLE :: ii(:),jj(:)
57 
58  REAL, ALLOCATABLE :: xlat_ind(:),xlon_ind(:), &
59  xrat_out(:),xron_out(:), &
60  w00(:),w01(:), &
61  w10(:),w11(:)
62 
63  LOGICAL, ALLOCATABLE :: lmask(:)
64 
65 INTEGER :: i,j,k,l,ij,ij00,ij01,ij10,ij11,ino,jl
66 REAL :: wx,wy,wsum
67 REAL(KIND=JPRB) :: zhook_handle
68 !
69 !-------------------------------------------------------------------------------------
70 IF (lhook) CALL dr_hook('HOR_INTERPOL_ROTLATLON',0,zhook_handle)
71 WRITE(kluout,'(A)')' | Running rotated latlon interpolation'
72 
73 ino = SIZE(xlat_out)
74 
75 !
76 !* 1. Allocations
77 !
78 ALLOCATE(xrat_out(ino), &
79  xron_out(ino), &
80  xlat_ind(ino), &
81  xlon_ind(ino), &
82  ii(ino), &
83  jj(ino), &
84  w00(ino), &
85  w01(ino), &
86  w10(ino), &
87  w11(ino))
88 
89 ALLOCATE(lmask(nni))
90 !
91 !* Transformation of latitudes/longitudes into rotated coordinates
92 
93  WRITE(kluout,*)'XLAT_OUT',xlat_out(10:10)
94  WRITE(kluout,*)'XLON_OUT',xlon_out(10:10)
95 
96  CALL regrot_lonlat_rot(xlon_out,xlat_out, &
97  xron_out,xrat_out, &
98  ino,1,ino,1, &
99  xrlop,xrlap,1 )
100 
101  WRITE(kluout,*)'XRAT_OUT',xrat_out(10:10)
102  WRITE(kluout,*)'XRON_OUT',xron_out(10:10)
103 
104  DO ij=1,ino
105  xlat_ind(ij) = ( xrat_out(ij) - xrila1) / xrdy + 1.
106  xlon_ind(ij) = ( xron_out(ij) - xrilo1) / xrdx + 1.
107  ENDDO
108 
109  pfieldout(:,:) = xundef
110 
111  DO jl=1,SIZE(pfieldin,2)
112 
113  lmask= .true.
114  WHERE ( abs(pfieldin(:,jl)-xundef) < 1.e-6 ) lmask = .false.
115 
116  DO ij=1,ino
117 
118  ii(ij) = int(xlon_ind(ij))
119  jj(ij) = int(xlat_ind(ij))
120 
121  wx = xlon_ind(ij) - float(ii(ij))
122  wy = xlat_ind(ij) - float(jj(ij))
123 
124  w00(ij) = (1.-wx)*(1.-wy)
125  w01(ij) = (1.-wx)* wy
126  w10(ij) = wx *(1.-wy)
127  w11(ij) = wx * wy
128 
129  k = ii(ij)
130  l = jj(ij)
131  ij00 = k + nrx*(l -1)
132  ij01 = k + nrx*(l+1 -1)
133  ij10 = k+1 + nrx*(l -1)
134  ij11 = k+1 + nrx*(l+1 -1)
135 
136  IF (.NOT. lmask(ij00)) w00(ij) = 0.
137  IF (.NOT. lmask(ij01)) w01(ij) = 0.
138  IF (.NOT. lmask(ij10)) w10(ij) = 0.
139  IF (.NOT. lmask(ij11)) w11(ij) = 0.
140 
141  wsum = w00(ij) + w01(ij) + &
142  w10(ij) + w11(ij)
143 
144  IF ( abs(wsum) < 1.e-6 ) cycle
145 
146  w00(ij) = w00(ij) / wsum
147  w01(ij) = w01(ij) / wsum
148  w10(ij) = w10(ij) / wsum
149  w11(ij) = w11(ij) / wsum
150 
151  ENDDO
152 
153  !
154  ! Bi linear
155  !
156 
157  WRITE(kluout,*)'NRX,NRY',nrx,nry
158 
159  DO ij=1,ino
160 
161  k = ii(ij)
162  l = jj(ij)
163  ij00 = k + nrx*(l -1)
164  ij01 = k + nrx*(l+1 -1)
165  ij10 = k+1 + nrx*(l -1)
166  ij11 = k+1 + nrx*(l+1 -1)
167 
168  WRITE(kluout,*)pfieldin(ij00,jl)
169 
170  pfieldout(ij,jl) = w00(ij)*pfieldin(ij00,jl) + &
171  w01(ij)*pfieldin(ij01,jl) + &
172  w10(ij)*pfieldin(ij10,jl) + &
173  w11(ij)*pfieldin(ij11,jl)
174 
175  ENDDO
176  ENDDO
177 
178 
179 !
180 !* 5. Deallocations
181 !
182 DEALLOCATE(xrat_out,xron_out, &
183  xlat_ind,xlon_ind, &
184  ii,jj, &
185  w00,w01,w10,w11, &
186  lmask)
187 !
188 IF (lhook) CALL dr_hook('HOR_INTERPOL_ROTLATLON',1,zhook_handle)
189 !-------------------------------------------------------------------------------------
190 END SUBROUTINE hor_interpol_rotlatlon
subroutine regrot_lonlat_rot(PXREG, PYREG, PXROT, PYROT, KXDIM, KYDIM, KX, KY, PXCEN, PYCEN, KCALL)
subroutine hor_interpol_rotlatlon(KLUOUT, PFIELDIN, PFIELDOUT)