SURFEX  V8_0
Surfex V8_0 release
 All Classes Files Functions Variables
hor_interpol_gauss.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_gauss(KLUOUT,PFIELDIN,PFIELDOUT)
7 ! #################################################################################
8 !
9 !!**** *HOR_INTERPOL_GAUSS* - Interpolation from a gaussian grid
10 !!
11 !! PURPOSE
12 !! -------
13 !
14 !!** METHOD
15 !! ------
16 !!
17 !! REFERENCE
18 !! ---------
19 !!
20 !! AUTHOR
21 !! ------
22 !! V. Masson
23 !!
24 !! MODIFICATIONS
25 !! -------------
26 !! Original 01/2004
27 !! M. Jidane Dec 2013 : initialize NNI if not already done
28 !!------------------------------------------------------------------
29 !
30 USE modd_prep, ONLY : xlat_out, xlon_out, linterp
31 USE modd_grid_gauss, ONLY : xila1, xilo1, xila2, xilo2, ninla, ninlo, nilen, lrotpole, &
32  xlap, xlop, xcoef
33 USE modd_grid_grib, ONLY : nni
34 USE modd_surf_par, ONLY : xundef
35 !
36 USE modi_horibl_surf
37 !
38 !
39 USE yomhook ,ONLY : lhook, dr_hook
40 USE parkind1 ,ONLY : jprb
41 !
42 IMPLICIT NONE
43 !
44 !* 0.1 declarations of arguments
45 !
46 INTEGER, INTENT(IN) :: kluout ! logical unit of output listing
47 REAL, DIMENSION(:,:), INTENT(IN) :: pfieldin ! field to interpolate horizontally
48 REAL, DIMENSION(:,:), INTENT(OUT) :: pfieldout ! interpolated field
49 !
50 !* 0.2 declarations of local variables
51 !
52 REAL, DIMENSION(:), ALLOCATABLE :: zlat ! latitudes
53 REAL, DIMENSION(:), ALLOCATABLE :: zlon ! longitudes
54 INTEGER, DIMENSION(:), ALLOCATABLE :: imaskin ! input mask
55 INTEGER, DIMENSION(:), ALLOCATABLE :: imaskout ! output mask
56 INTEGER :: ino ! output number of points
57 INTEGER :: jl ! loop counter
58 REAL(KIND=JPRB) :: zhook_handle
59 !
60 !-------------------------------------------------------------------------------------
61 !
62 !* 1. Allocations
63 !
64 IF (lhook) CALL dr_hook('HOR_INTERPOL_GAUSS',0,zhook_handle)
65 ino = SIZE(xlat_out)
66 !
67 IF (nni==0) nni=nilen
68 ALLOCATE(imaskin(nni))
69 !
70 ALLOCATE(zlat(ino))
71 ALLOCATE(zlon(ino))
72 ALLOCATE(imaskout(ino))
73 imaskout = 1
74 !
75 !* 2. Is pole rotated?
76 !
77 IF (lrotpole) THEN
78 !* transformation of output latitudes, longitudes into rotated coordinates
79  CALL arpege_stretch_a(ino,xlap,xlop,xcoef,xlat_out,xlon_out,zlat,zlon)
80 ELSE
81  zlat = xlat_out
82  zlon = xlon_out
83 END IF
84 !
85 !* 3. Input mask
86 !
87 DO jl=1,SIZE(pfieldin,2)
88 !
89 imaskin(:) = 1.
90 WHERE(pfieldin(:,jl)==xundef) imaskin = 0.
91 !
92 !
93 !* 4. Interpolation with horibl
94 !
95  CALL horibl_surf(xila1,xilo1,xila2,xilo2,ninla,ninlo,nni,pfieldin(:,jl),ino,zlon,zlat,pfieldout(:,jl), &
96  .false.,kluout,linterp,imaskin,imaskout)
97 END DO
98 !
99 !
100 !* 5. Deallocations
101 !
102 DEALLOCATE(zlat)
103 DEALLOCATE(zlon)
104 DEALLOCATE(imaskin )
105 DEALLOCATE(imaskout)
106 !
107 !-------------------------------------------------------------------------------
108 !-------------------------------------------------------------------------------
109 IF (lhook) CALL dr_hook('HOR_INTERPOL_GAUSS',1,zhook_handle)
110  CONTAINS
111 !
112 ! ##########################################################################
113 SUBROUTINE arpege_stretch_a(KN,PLAP,PLOP,PCOEF,PLAR,PLOR,PLAC,PLOC)
114 ! ##########################################################################
115 !!**** *ARPEGE_STRETCH_A* - Projection to Arpege stretched grid
116 !!
117 !! PURPOSE
118 !! -------
119 !!
120 !! Projection from standard Lat,Lon grid to Arpege stretched grid
121 !!
122 !! METHOD
123 !! ------
124 !!
125 !! The projection is defined in two steps :
126 !! 1. A rotation to place the stretching pole at the north pole
127 !! 2. The stretching
128 !! This routine is a basic implementation of the informations founded in
129 !! 'Note de travail Arpege n#3'
130 !! 'Transformation de coordonnees'
131 !! J.F.Geleyn 1988
132 !! This document describes a slightly different transformation in 3 steps. Only the
133 !! two first steps are to be taken in account (at the time of writing this paper has
134 !! not been updated).
135 !!
136 !! EXTERNAL
137 !! --------
138 !!
139 !!
140 !! IMPLICIT ARGUMENTS
141 !! ------------------
142 !!
143 !! REFERENCE
144 !! ---------
145 !!
146 !! This routine is based on :
147 !! 'Note de travail ARPEGE' number 3
148 !! by J.F. GELEYN (may 1988)
149 !!
150 !! AUTHOR
151 !! ------
152 !!
153 !! V.Bousquet
154 !!
155 !! MODIFICATIONS
156 !! -------------
157 !!
158 !! Original 07/01/1999
159 !! V. Masson 01/2004 Externalization of surface
160 !!
161 !
162 ! 0. DECLARATIONS
163 ! ---------------
164 !
165  USE modd_csts,ONLY : xpi
166 !
167  IMPLICIT NONE
168 !
169 ! 0.1. Declaration of arguments
170 ! -----------------------------
171 
172  INTEGER, INTENT(IN) :: kn ! Number of points to convert
173  REAL, INTENT(IN) :: plap ! Latitude of stretching pole
174  REAL, INTENT(IN) :: plop ! Longitude of stretching pole
175  REAL, INTENT(IN) :: pcoef ! Stretching coefficient
176  REAL, DIMENSION(KN), INTENT(IN) :: plar ! Lat. of points
177  REAL, DIMENSION(KN), INTENT(IN) :: plor ! Lon. of points
178  REAL, DIMENSION(KN), INTENT(OUT) :: plac ! Computed pseudo-lat. of points
179  REAL, DIMENSION(KN), INTENT(OUT) :: ploc ! Computed pseudo-lon. of points
180 !
181  REAL :: zsinstretchla ! Sine of stretching point lat.
182  REAL :: zsinstretchlo ! Sine of stretching point lon.
183  REAL :: zcosstretchla ! Cosine of stretching point lat.
184  REAL :: zcosstretchlo ! Cosine of stretching point lon.
185  REAL :: zsinla ! Sine of computed point latitude
186  REAL :: zsinlo ! Sine of computed point longitude
187  REAL :: zcosla ! Cosine of computed point latitude
188  REAL :: zcoslo ! Cosine of computed point longitude
189  REAL :: zsinlas ! Sine of point's pseudo-latitude
190  REAL :: zsinlos ! Sine of point's pseudo-longitude
191  REAL :: zcoslos ! Cosine of point's pseudo-lon.
192  REAL :: za,zb,zd ! Dummy variables used for
193  REAL :: zx,zy ! computations
194 !
195  INTEGER :: jloop1 ! Dummy loop counter
196  REAL(KIND=JPRB) :: zhook_handle
197 !
198  IF (lhook) CALL dr_hook('ARPEGE_STRETCH_A',0,zhook_handle)
199  zsinstretchla = sin(plap*xpi/180.)
200  zcosstretchla = cos(plap*xpi/180.)
201  zsinstretchlo = sin(plop*xpi/180.)
202  zcosstretchlo = cos(plop*xpi/180.)
203  ! L = longitude (0 = Greenwich, + toward east)
204  ! l = latitude (90 = N.P., -90 = S.P.)
205  ! p stands for stretching pole
206  plac(:) = plar(:) * xpi / 180.
207  ploc(:) = plor(:) * xpi / 180.
208  ! A = 1 + c.c
209  za = 1. + pcoef*pcoef
210  ! B = 1 - c.c
211  zb = 1. - pcoef*pcoef
212  DO jloop1=1, kn
213  zsinla = sin(plac(jloop1))
214  zcosla = cos(plac(jloop1))
215  zsinlo = sin(ploc(jloop1))
216  zcoslo = cos(ploc(jloop1))
217  ! X = cos(Lp-L)
218  zx = zcoslo*zcosstretchlo + zsinlo*zsinstretchlo
219  ! Y = sin(Lp-L)
220  zy = zsinstretchlo*zcoslo - zsinlo*zcosstretchlo
221  ! D = (1+c.c) + (1-c.c)(sin lp.sin l + cos lp.cos l.cos(Lp-L))
222  zd = za + zb*(zsinstretchla*zsinla+zcosstretchla*zcosla*zx)
223  ! (1-c.c)+(1+c.c)((sin lp.sin l + cos lp.cos l.cos(Lp-L))
224  ! sin lr = -------------------------------------------------------
225  ! D
226  zsinlas = (zb + za*(zsinstretchla*zsinla+zcosstretchla*zcosla*zx)) / zd
227  ! D' = D * cos lr
228  zd = zd * (amax1(1e-6,sqrt(1.-zsinlas*zsinlas)))
229  ! 2.c.(cos lp.sin l - sin lp.cos l.cos(Lp-L))
230  ! cos Lr = -------------------------------------------
231  ! D'
232  zcoslos = 2.*pcoef*(zcosstretchla*zsinla-zsinstretchla*zcosla*zx) / zd
233  ! 2.c.cos l.cos(Lp-L)
234  ! sin Lr = -------------------
235  ! D'
236  zsinlos = 2.*pcoef*(zcosla*zy) / zd
237  ! saturations (corrects calculation errors)
238  zsinlas = max(zsinlas,-1.)
239  zsinlas = min(zsinlas, 1.)
240  zcoslos = max(zcoslos,-1.)
241  zcoslos = min(zcoslos, 1.)
242  ! back from sine & cosine
243  plac(jloop1) = asin(zsinlas)
244  IF (zsinlos>0) THEN
245  ploc(jloop1) = acos(zcoslos)
246  ELSE
247  ploc(jloop1) = -acos(zcoslos)
248  ENDIF
249  ENDDO
250  ploc(:) = ploc(:) * 180. / xpi
251  plac(:) = plac(:) * 180. / xpi
252 IF (lhook) CALL dr_hook('ARPEGE_STRETCH_A',1,zhook_handle)
253 END SUBROUTINE arpege_stretch_a
254 !-------------------------------------------------------------------------------
255 END SUBROUTINE hor_interpol_gauss
subroutine horibl_surf(PILA1, PILO1, PILA2, PILO2, KINLA, KINLO, KILEN, PARIN, KOLEN, PXOUT, PYOUT, PAROUT, ODVECT, KLUOUT, OINTERP, KLSMIN, KLSMOUT)
Definition: horibl_surf.F90:6
subroutine hor_interpol_gauss(KLUOUT, PFIELDIN, PFIELDOUT)
subroutine arpege_stretch_a(KN, PLAP, PLOP, PCOEF, PLAR, PLOR, PLAC, PLOC)