SURFEX v8.1
General documentation of Surfex
read_nam_grid_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 read_nam_grid_gauss(PGRID_FULL_PAR,KDIM_FULL,HPROGRAM,KGRID_PAR,KL,PGRID_PAR,HDIR)
7 !################################################################
8 !
9 !!**** *READ_NAM_GRID_GAUSS* - routine to read in namelist the horizontal grid
10 !!
11 !! PURPOSE
12 !! -------
13 !!
14 !!** METHOD
15 !! ------
16 !!
17 !! EXTERNAL
18 !! --------
19 !!
20 !!
21 !! IMPLICIT ARGUMENTS
22 !! ------------------
23 !!
24 !! REFERENCE
25 !! ---------
26 !!
27 !!
28 !! AUTHOR
29 !! ------
30 !! V. Masson *Meteo France*
31 !!
32 !! MODIFICATIONS
33 !! -------------
34 !! Original 01/2004
35 !! B. Decharme 2008 Comput and save the Mesh size
36 !! 2013 Bug lat and lon for non rotat-strech grid
37 !! Grid corner (used with oasis)
38 !-------------------------------------------------------------------------------
39 !
40 !* 0. DECLARATIONS
41 ! ------------
42 !
43 USE modd_surfex_mpi, ONLY : nrank, nsize_task
44 !
45 USE modd_csts, ONLY : xpi
46 USE modd_surf_par, ONLY : xundef
47 !
48 USE mode_pos_surf
49 !
50 USE modi_open_namelist
51 USE modi_close_namelist
52 USE modi_get_luout
53 !
55 !
56 USE eggangles , ONLY : p_asin
57 !
59 !
60 USE yomhook ,ONLY : lhook, dr_hook
61 USE parkind1 ,ONLY : jprb
62 !
63 USE modi_abor1_sfx
64 !
65 IMPLICIT NONE
66 !
67 !* 0.1 Declarations of arguments
68 ! -------------------------
69 !
70 REAL, DIMENSION(:), POINTER :: PGRID_FULL_PAR
71 INTEGER, INTENT(IN) :: KDIM_FULL
72 !
73  CHARACTER(LEN=6), INTENT(IN) :: HPROGRAM ! calling program
74 INTEGER, INTENT(INOUT) :: KGRID_PAR ! size of PGRID_PAR
75 INTEGER, INTENT(OUT) :: KL ! number of points
76 REAL, DIMENSION(KGRID_PAR), INTENT(OUT) :: PGRID_PAR ! parameters defining this grid
77  CHARACTER(LEN=1), INTENT(IN) :: HDIR
78 !
79 !* 0.2 Declarations of local variables
80 ! -------------------------------
81 !
82 INTEGER :: ILUOUT ! output listing logical unit
83 INTEGER :: ILUNAM ! namelist file logical unit
84 REAL, DIMENSION(:), ALLOCATABLE :: ZLAT_XY, ZLAT_XY0 ! pseudo-latitudes
85 REAL, DIMENSION(:), ALLOCATABLE :: ZLON_XY, ZLON_XY0 ! pseudo-longitudes
86 REAL, DIMENSION(:), ALLOCATABLE :: ZLAT, ZLAT0 ! latitudes
87 REAL, DIMENSION(:), ALLOCATABLE :: ZLON, ZLON0 ! longitudes
88 REAL, DIMENSION(:), ALLOCATABLE :: ZMESH_SIZE, ZMESH_SIZE0 ! Mesh size
89 ! _____ Sup
90 REAL, DIMENSION(:), ALLOCATABLE :: ZLATSUP, ZLATSUP0 ! Grid corner Latitude | |
91 REAL, DIMENSION(:), ALLOCATABLE :: ZLONSUP, ZLONSUP0 ! Grid corner Longitude | |
92 REAL, DIMENSION(:), ALLOCATABLE :: ZLATINF, ZLATINF0 ! Grid corner Latitude |_____|
93 REAL, DIMENSION(:), ALLOCATABLE :: ZLONINF, ZLONINF0 ! Grid corner Longitude Inf
94 !
95 REAL, DIMENSION(:), ALLOCATABLE :: ZXINF ! pseudo-longitude western limit of grid mesh
96 REAL, DIMENSION(:), ALLOCATABLE :: ZXSUP ! pseudo-longitude eastern limit of grid mesh
97 REAL, DIMENSION(:), ALLOCATABLE :: ZYINF ! pseudo-latitude southern limit of grid mesh
98 REAL, DIMENSION(:), ALLOCATABLE :: ZYSUP ! pseudo-latitude northern limit of grid mesh
99 !
100 !* 0.3 Declarations of namelist
101 ! ------------------------
102 !
103 INTEGER :: NDGLG ! number of pseudo-latitudes
104 REAL :: RMUCEN ! sine of the latitude of the rotated pole
105 REAL :: RLOCEN ! longitude of the rotated pole (radian)
106 REAL :: RSTRET ! stretching factor (must be greater than or equal to 1)
107 INTEGER, DIMENSION(1000) :: NRGRI ! number of pseudo-longitudes on each
108  ! pseudo-latitude circle on pseau
109  ! northern hemisphere (starting from
110  ! the rotated pole)
111 !
112 REAL :: ZLAPO ! latitude of the rotated pole (deg)
113 REAL :: ZLOPO ! longitude of the rotated pole (deg)
114 REAL :: ZCODIL ! stretching factor (must be greater than or equal to 1)
115 INTEGER :: ITYP ! type of transform (0 --> no rotation, 1 otherwise)
116 INTEGER :: INLATI ! number of latitudes
117 INTEGER, DIMENSION(:), ALLOCATABLE :: INLOPA ! number of pseudo-longitudes on each
118  ! pseudo-latitude circle
119 
120 INTEGER :: JSTGLO
121 
122 !
123 REAL, DIMENSION(:), POINTER :: ZGRID_PAR
124 !
125 LOGICAL :: GFOUND
126 REAL(KIND=JPRB) :: ZHOOK_HANDLE
127 !
128 NAMELIST/namdim/ndglg
129 NAMELIST/namgem/rmucen, rlocen, rstret
130 NAMELIST/namrgri/nrgri
131 !
132 !------------------------------------------------------------------------------
133 !
134 !* 1. Default values
135 !
136 IF (lhook) CALL dr_hook('READ_NAM_GRID_GAUSS',0,zhook_handle)
137 ndglg = 0
138 rmucen = 1.
139 rlocen = xpi
140 rstret = 1.
141 !
142 nrgri(:) = 0
143 !------------------------------------------------------------------------------
144 !
145 !* 2. opening of namelist
146 !
147  CALL get_luout(hprogram,iluout)
148 !
149 IF (hdir/='H') THEN
150  !
151  CALL open_namelist(hprogram,ilunam)
152  !
153  !---------------------------------------------------------------------------
154  !
155  !* 3. Reading of projection parameters
156  ! --------------------------------
157  !
158  CALL posnam(ilunam,'NAMGEM',gfound,iluout)
159  IF (gfound) READ(unit=ilunam,nml=namgem)
160  !
161  IF (rstret<1.) THEN
162  WRITE(iluout,*) '****************************************************'
163  WRITE(iluout,*) 'stretching factor RSTRET for the Gaussian grid'
164  WRITE(iluout,*) 'definition must be greater than or equal to 1'
165  WRITE(iluout,*) 'You have set RSTRET=', rstret
166  WRITE(iluout,*) 'Please modify the value of RSTRET in namelist NAMGEM'
167  WRITE(iluout,*) '****************************************************'
168  CALL abor1_sfx('READ_NAM_GRID_GAUSS: STRETCHING FACTOR MUST BE >= 1.')
169  END IF
170  !
171  zlapo = 180. / xpi * p_asin(rmucen)
172  zlopo = 180. / xpi * rlocen
173  !
174  zcodil = rstret
175  !
176  !---------------------------------------------------------------------------
177  !
178  !* 4. Reading parameters of the grid
179  ! ------------------------------
180  !
181  CALL posnam(ilunam,'NAMDIM',gfound,iluout)
182  IF (gfound) READ(unit=ilunam,nml=namdim)
183  CALL posnam(ilunam,'NAMRGRI',gfound,iluout)
184  IF (gfound) READ(unit=ilunam,nml=namrgri)
185  !
186  inlati = ndglg
187  ALLOCATE(inlopa(inlati))
188  inlopa(1:inlati/2) = nrgri(1:inlati/2)
189  inlopa(inlati/2+1:inlati) = nrgri(inlati/2:1:-1)
190  !
191  !---------------------------------------------------------------------------
192  CALL close_namelist(hprogram,ilunam)
193  !---------------------------------------------------------------------------
194  !
195  !* 5. Computes pseudo-latitudes and pseudo-longitudes of all points
196  ! -------------------------------------------------------------
197  !
198  !* number of points
199  kl = sum(inlopa)
200  !
201  !
202  !* type of transform
203  IF (zlapo>89.99 .AND. abs(zlopo)<0.00001) THEN
204  ityp=0
205  ELSE
206  ityp=1
207  ENDIF
208  !
209  ALLOCATE(zlat_xy(kl))
210  ALLOCATE(zlon_xy(kl))
211  zlat_xy(:) = xundef
212  zlon_xy(:) = xundef
213  !
214  CALL comp_gridtype_gauss(inlati,inlopa,kl,ityp,zlat_xy,zlon_xy)
215  !
216  !---------------------------------------------------------------------------
217  !
218  !* 6. Computes latitudes and longitudes
219  ! ---------------------------------
220  !
221  !* all points are used
222  ALLOCATE(zlat(kl))
223  ALLOCATE(zlon(kl))
224  !
225  zlat(:) = xundef
226  zlon(:) = xundef
227  !
228  IF(zcodil==1.0.AND.ityp==0)THEN
229  zlon(:)=zlon_xy(:)
230  zlat(:)=zlat_xy(:)
231  ELSE
232  CALL latlon_gauss(zlon_xy,zlat_xy,kl,zlopo,zlapo,zcodil,zlon,zlat)
233  ENDIF
234  !
235  !---------------------------------------------------------------------------
236  !
237  !* 7. Computes grid corner latitudes and longitudes
238  ! ---------------------------------------------
239  !
240  ALLOCATE(zxinf(kl))
241  ALLOCATE(zyinf(kl))
242  ALLOCATE(zxsup(kl))
243  ALLOCATE(zysup(kl))
244  !
245  ALLOCATE(zloninf(kl))
246  ALLOCATE(zlatinf(kl))
247  ALLOCATE(zlonsup(kl))
248  ALLOCATE(zlatsup(kl))
249  !
250  zxinf(:) = xundef
251  zyinf(:) = xundef
252  zxsup(:) = xundef
253  zysup(:) = xundef
254  zloninf(:) = xundef
255  zlatinf(:) = xundef
256  zlonsup(:) = xundef
257  zlatsup(:) = xundef
258  !
259  CALL gauss_grid_limits(inlati,inlopa,zxinf,zxsup,zyinf,zysup)
260  !
261  IF(zcodil==1.0.AND.ityp==0)THEN
262  zloninf(:) = zxinf(:)
263  zlatinf(:) = zyinf(:)
264  zlonsup(:) = zxsup(:)
265  zlatsup(:) = zysup(:)
266  ELSE
267  CALL latlon_gauss(zxinf,zyinf,kl,zlopo,zlapo,zcodil,zloninf,zlatinf)
268  CALL latlon_gauss(zxsup,zysup,kl,zlopo,zlapo,zcodil,zlonsup,zlatsup)
269  ENDIF
270  !
271  DEALLOCATE(zxinf)
272  DEALLOCATE(zyinf)
273  DEALLOCATE(zxsup)
274  DEALLOCATE(zysup)
275  !
276  !---------------------------------------------------------------------------
277  !
278  !* 8. Computes mesh size
279  ! ---------------------------------
280  !
281  ALLOCATE(zmesh_size(kl))
282  zmesh_size(:) = xundef
283  !
284  CALL mesh_size_gauss(kl,inlati,inlopa,zlapo,zlopo,zcodil,&
285  zlat_xy,zlon,zlat,zmesh_size)
286 !
287 ELSE
288  !
289  ALLOCATE(zlon0(kdim_full),zlat0(kdim_full),zlon_xy0(kdim_full),zlat_xy0(kdim_full),&
290  zmesh_size0(kdim_full),zloninf0(kdim_full),zlatinf0(kdim_full),&
291  zlonsup0(kdim_full),zlatsup0(kdim_full))
292  !
293  CALL get_gridtype_gauss(pgrid_full_par,inlati)
294  !
295  ALLOCATE(inlopa(inlati))
296  !
297  CALL get_gridtype_gauss(pgrid_full_par,knlati=inlati,plapo=zlapo,&
298  plopo=zlopo,pcodil=zcodil,knlopa=inlopa, &
299  plat=zlat0,plon=zlon0,plat_xy=zlat_xy0,&
300  plon_xy=zlon_xy0,pmesh_size=zmesh_size0,&
301  ploninf=zloninf0,platinf=zlatinf0,&
302  plonsup=zlonsup0,platsup=zlatsup0)
303  !
304  kl = nsize_task(nrank)
305  ALLOCATE(zlat(kl),zlon(kl),zlat_xy(kl),zlon_xy(kl),zmesh_size(kl))
306  ALLOCATE(zloninf(kl))
307  ALLOCATE(zlatinf(kl))
308  ALLOCATE(zlonsup(kl))
309  ALLOCATE(zlatsup(kl))
310  !
311  CALL read_and_send_mpi(zlon0,zlon)
312  CALL read_and_send_mpi(zlat0,zlat)
313  CALL read_and_send_mpi(zlon_xy0,zlon_xy)
314  CALL read_and_send_mpi(zlat_xy0,zlat_xy)
315  CALL read_and_send_mpi(zmesh_size0,zmesh_size)
316  CALL read_and_send_mpi(zloninf0,zloninf)
317  CALL read_and_send_mpi(zlatinf0,zlatinf)
318  CALL read_and_send_mpi(zlonsup0,zlonsup)
319  CALL read_and_send_mpi(zlatsup0,zlatsup)
320  !
321  DEALLOCATE(zlon0,zlat0,zlon_xy0,zlat_xy0,zmesh_size0,zloninf0,zlatinf0,&
322  zlonsup0,zlatsup0)
323  !
324 ENDIF
325 !---------------------------------------------------------------------------
326 !
327 !* 9. All this information stored into pointer PGRID_PAR
328 ! --------------------------------------------------
329 !
330  CALL put_gridtype_gauss(zgrid_par,inlati,zlapo,zlopo,zcodil,inlopa, &
331  kl,zlat,zlon,zlat_xy,zlon_xy,zmesh_size, &
332  zloninf,zlatinf,zlonsup,zlatsup )
333 !
334 !---------------------------------------------------------------------------
335 !
336 !* 9. All this information stored into pointer PGRID_PAR
337 ! --------------------------------------------------
338 !
339 DEALLOCATE(zlat)
340 DEALLOCATE(zlon)
341 DEALLOCATE(zlat_xy)
342 DEALLOCATE(zlon_xy)
343 DEALLOCATE(inlopa)
344 DEALLOCATE(zmesh_size)
345 DEALLOCATE(zlatinf)
346 DEALLOCATE(zloninf)
347 DEALLOCATE(zlatsup)
348 DEALLOCATE(zlonsup)
349 !
350 !---------------------------------------------------------------------------
351 !
352 !* 1st call : initializes dimension
353 !
354 IF (kgrid_par==0) THEN
355  kgrid_par = SIZE(zgrid_par)
356 !
357 ELSE
358 !
359 !* 2nd call : initializes grid array
360 !
361  pgrid_par(:) = 0.
362  pgrid_par(:) = zgrid_par
363 END IF
364 !
365 DEALLOCATE(zgrid_par)
366 IF (lhook) CALL dr_hook('READ_NAM_GRID_GAUSS',1,zhook_handle)
367 
368 !
369 !---------------------------------------------------------------------------
370 !
371 END SUBROUTINE read_nam_grid_gauss
subroutine read_nam_grid_gauss(PGRID_FULL_PAR, KDIM_FULL, HPROGRAM, KGRID_PAR, KL, PGRID_PAR, HDIR)
subroutine gauss_grid_limits(KNLATI, KNLOPA, PXINF, PXSUP, PYINF, PYSUP)
subroutine latlon_gauss(PLON_XY, PLAT_XY, KL, PLOPO, PLAPO, PCODIL, PLON, PLAT)
subroutine mesh_size_gauss(KL, KNLATI, KNLOPA, PLAPO, PLOPO, PCODIL, PLAT_XY, PLAT, PLON, PMESH_SIZE)
real, save xpi
Definition: modd_csts.F90:43
subroutine posnam(KULNAM, HDNAML, OFOUND, KLUOUT)
subroutine abor1_sfx(YTEXT)
Definition: abor1_sfx.F90:7
real, parameter xundef
integer, parameter jprb
Definition: parkind1.F90:32
subroutine close_namelist(HPROGRAM, KLUNAM)
subroutine get_luout(HPROGRAM, KLUOUT)
Definition: get_luout.F90:7
intent(out) overrides sub arrays one Sort by the least significant key first sum(iindex(1:n))
integer, dimension(:), allocatable nsize_task
logical lhook
Definition: yomhook.F90:15
subroutine comp_gridtype_gauss(KNLATI, KNLOPA, KL, KTYP, PLAT_XY, PLON_XY)
subroutine get_gridtype_gauss(PGRID_PAR, KNLATI, PLAPO, PLOPO, PCODIL, KNLOPA, KL, PLAT, PLON, PLAT_XY, PLON_XY, PMESH_SIZE, PLONINF, PLATINF, PLONSUP, PLATSUP)
subroutine put_gridtype_gauss(PGRID_PAR, KNLATI, PLAPO, PLOPO, PCODIL, KNLOPA, KL, PLAT, PLON, PLAT_XY, PLON_XY, PMESH_SIZE, PLONINF, PLATINF, PLONSUP, PLATSUP)
subroutine open_namelist(HPROGRAM, KLUNAM, HFILE)