SURFEX  V8_0
Surfex V8_0 release
 All Classes Files Functions Variables
pgd_topd.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 ! #############################################################
7  SUBROUTINE pgd_topd (I, UG, U, USS, &
8  hprogram)
9 ! #############################################################
10 !
11 !!**** *PGD_TOPD* - routine to determine the masks that permit to couple ISBA grid with Topmodel one
12 !!
13 !! PURPOSE
14 !! -------
15 !!
16 !!** METHOD
17 !! ------
18 !!
19 !! EXTERNAL
20 !! --------
21 !!
22 !! IMPLICIT ARGUMENTS
23 !! ------------------
24 !!
25 !! REFERENCE
26 !! ---------
27 !! (from initial version of init_coupl_topo.f90 by K. Chancibault, modified by
28 !! M. Lelay and B. Vincendon)
29 !!
30 !! AUTHOR
31 !! ------
32 !! B. Vincendon *Meteo France*
33 !!
34 !! MODIFICATIONS
35 !! -------------
36 !! Original 11/2011
37 !! 03/2014 (E. Artinian) manages the option CGRID='IGN'
38 !-------------------------------------------------------------------------------
39 !
40 !* 0. DECLARATIONS
41 ! ------------
42 !
43 !
44 !
45 USE modd_isba_n, ONLY : isba_t
47 USE modd_surf_atm_n, ONLY : surf_atm_t
49 !
50 USE modd_topd_par, ONLY : nunit
51 USE modd_topodyn, ONLY : ccat, nncat, xrtop_d2, nmesht, xdxt
52 USE modd_coupling_topd, ONLY : lcoupl_topd, nimax, njmax, &
53  xxi, xyi, nmaski, nmaskt, nnpix,&
54  nnbv_in_mesh, xbv_in_mesh, xtotbv_in_mesh
55 USE modd_dummy_exp_profile, ONLY : xf_param_bv, xc_depth_ratio_bv
56 !
57 USE modd_surf_par, ONLY : nundef
58 !
59 !
63 !
64 USE modi_get_luout
65 USE modi_read_nam_pgd_topd
66 USE modi_init_topd
67 USE modi_abor1_sfx
68 USE modi_make_mask_topd_to_isba
69 USE modi_make_mask_isba_to_topd
70 USE modi_write_file_masktopd
71 USE modi_open_file
72 USE modi_close_file
73 !USE MODI_TOPD_TO_ISBA_SLOPE
74 !
75 USE yomhook ,ONLY : lhook, dr_hook
76 USE parkind1 ,ONLY : jprb
77 !
78 IMPLICIT NONE
79 !
80 !* 0.1 Declarations of arguments
81 ! -------------------------
82 !
83 !
84 TYPE(isba_t), INTENT(INOUT) :: i
85 TYPE(surf_atm_grid_t), INTENT(INOUT) :: ug
86 TYPE(surf_atm_t), INTENT(INOUT) :: u
87 TYPE(surf_atm_sso_t), INTENT(INOUT) :: uss
88 !
89  CHARACTER(LEN=*), INTENT(IN) :: hprogram !
90 !
91  CHARACTER(LEN=50),DIMENSION(NNCAT) :: cname
92 INTEGER :: il ! number of points
93 INTEGER :: jj,ji,jk,jwrk ! loop control
94 INTEGER :: jcat,jmesh,jpix ! loop control
95 INTEGER :: iluout ! Logical unit for output filr
96 INTEGER :: imeshl ! number of ISBA grid nodes
97 INTEGER :: ilambert ! Lambert projection type
98 !
99 REAL, DIMENSION(:), ALLOCATABLE :: zxi, zyi ! natural coordinates of ISBA grid (conformal projection or latlon)
100 REAL, DIMENSION(:), ALLOCATABLE :: zdxi, zdyi ! Isba grid resolution in the conformal projection
101 REAL, DIMENSION(:), ALLOCATABLE :: zxn, zyn ! isba nodes coordinates in the Lambert II coordinates
102 REAL, DIMENSION(:), ALLOCATABLE :: zlat,zlon ! Isba nodes geographical coordinates
103 REAL, DIMENSION(:), ALLOCATABLE :: zdtav ! Averaged depth soil on TOP-LAT grid
104 REAL :: zlat0 ! reference latitude
105 REAL :: zlon0 ! reference longitude
106 REAL :: zlonmin,zlonmax ! min and max longitude values (latlon coordinates)
107 REAL :: zlatmin,zlatmax ! min and max latitude values (latlon coordinates)
108 REAL :: zrpk ! projection parameter
109 ! ! K=1 : stereographic north pole
110 ! ! 0<K<1 : Lambert, north hemisphere
111 ! ! K=0 : Mercator
112 ! !-1<K<0 : Lambert, south hemisphere
113 ! ! K=-1: stereographic south pole
114 REAL :: zbeta ! angle between grid and reference longitude
115 REAL :: zlator ! latitude of point of coordinates X=0, Y=0
116 REAL :: zlonor ! longitude of point of coordinates X=0, Y=0!
117 REAL, DIMENSION(:), ALLOCATABLE :: zf_param,zc_depth_ratio !
118 REAL(KIND=JPRB) :: zhook_handle
119 !-------------------------------------------------------------------------------
120 IF (lhook) CALL dr_hook('PGD_TOPD',0,zhook_handle)
121 !
122  CALL get_luout(hprogram,iluout)
123 !
124  CALL read_nam_pgd_topd(hprogram,lcoupl_topd,ccat,xf_param_bv,xc_depth_ratio_bv)
125 !
126 IF (lcoupl_topd .AND. (i%CISBA/='3-L'.AND. i%CISBA/='DIF')) &
127  CALL abor1_sfx("PGD_TOPD: coupling with topmodel only runs with CISBA=3-L or CISBA=DIF ")
128 !
129 ! 1. Reads the namelists
130 ! --------------------
131 IF (lcoupl_topd) THEN
132  !
133  WRITE(iluout,*) 'Debut pgd_topd'
134  !
135  ! 3. Initialises variables specific to Topmodel
136  ! -------------------------------------------
137  WRITE(iluout,*) 'NNCAT',nncat
138  !
139  CALL init_topd_pgd(hprogram)
140  !
141  ! 4. Compute masks to couple ISBA and TOPODYN grids
142  ! -------------------------------------------------------
143  !
144  !* 1. Calcul of the plane coordinates
145  ! -------------------------------
146  !
147  !* 1.1 Gestion des projections conformes
148  ! ---------------------------------
149  !
150  ALLOCATE(nmaskt(nncat,nmesht))
151  nmaskt(:,:)=nundef
152  !
153  IF(ug%CGRID.EQ.'CONF PROJ') THEN
154  !
155  WRITE(iluout,*) 'GRILLE PROJ CONF (application Cevennes)'
156  !
157  !* 1.1.1 lecture des coordonnees X et Y conformes
158  ! -----------------------------------------
159  !
160  ALLOCATE(zxi(u%NDIM_FULL))
161  ALLOCATE(zyi(u%NDIM_FULL))
162  zxi(:)=0.0
163  zyi(:)=0.0
164  !
165  ALLOCATE(zdxi(u%NDIM_FULL))
166  ALLOCATE(zdyi(u%NDIM_FULL))
167  !
168  CALL get_gridtype_conf_proj(ug%XGRID_PAR,plat0=zlat0,plon0=zlon0,prpk=zrpk, &
169  pbeta=zbeta,plator=zlator,plonor=zlonor, &
170  kimax=nimax,kjmax=njmax,px=zxi,py=zyi, &
171  pdx=zdxi,pdy=zdyi)
172  !
173  imeshl = (nimax+1)*(njmax+1)
174  !
175  !* 1.1.2 calcul des coordonnees X et Y conformes des noeuds de la grille ISBA
176  ! --------------------------------------------------------------------
177  ALLOCATE(zxn(imeshl))
178  ALLOCATE(zyn(imeshl))
179  !
180  DO jj=1,nimax
181  zxn(jj) = zxi(jj) - zdxi(jj)/2.
182  ENDDO
183  zxn(nimax+1) = zxi(nimax) + zdxi(nimax)/2.
184  !
185  DO jj=1,njmax
186  jwrk = (jj-1)*(nimax+1)+1 ! indice sur la grille des noeuds
187  ji = (jj-1)*nimax+1 ! indice sur la grille des mailles
188  zyn(jwrk) = zyi(ji) - zdyi(ji)/2.
189  ENDDO
190  !
191  jj = ((njmax+1)-1)*(nimax+1)+1 ! Indice sur la grille des noeuds
192  ji = (njmax-1)*nimax+1
193  zyn(jj) = zyi(ji) + zdyi(ji)/2.
194  !
195  DEALLOCATE(zdxi)
196  DEALLOCATE(zdyi)
197  DEALLOCATE(zxi)
198  DEALLOCATE(zyi)
199  !
200  DO jj=1,nimax+1
201  DO ji=2,njmax+1
202  jk = (ji-1)*(nimax+1)+jj
203  zxn(jk) = zxn(jj)
204  ENDDO
205  ENDDO
206  !
207  DO ji=1,njmax+1
208  DO jj=2,nimax+1
209  jk = (ji-1)*(nimax+1)+jj
210  jwrk = (ji-1)*(nimax+1)+1
211  zyn(jk) = zyn(jwrk)
212  ENDDO
213  ENDDO
214  !
215  !* 1.1.3 calcul des coordonnées géographiques des noeuds de la grille ISBA
216  ! -----------------------------------------------------------------
217  ALLOCATE(zlat(imeshl))
218  ALLOCATE(zlon(imeshl))
219  CALL latlon_conf_proj(zlat0,zlon0,zrpk,zbeta,zlator,zlonor,zxn,zyn,zlat,zlon)
220  DEALLOCATE(zxn)
221  DEALLOCATE(zyn)
222  !
223  !* 1.2 Gestion des coordonnees geographiques
224  ! -------------------------------------
225  !
226  ELSE IF(ug%CGRID.EQ.'LONLAT REG') THEN
227  !
228  WRITE(iluout,*) 'GRILLE LONLAT REG (application AMMA)'
229  !
230  ALLOCATE(zxi(u%NDIM_FULL))
231  ALLOCATE(zyi(u%NDIM_FULL))
232  zxi(:)=0.0
233  zyi(:)=0.0
234  CALL get_gridtype_lonlat_reg(ug%XGRID_PAR,plonmin=zlonmin,plonmax=zlonmax, &
235  platmin=zlatmin,platmax=zlatmax,klon=nimax,klat=njmax, &
236  kl=il,plon=zxi,plat=zyi)
237  !
238  imeshl=(nimax+1)*(njmax+1)
239  !
240  ALLOCATE(zlon(imeshl))
241  ALLOCATE(zlat(imeshl))
242  ALLOCATE(zdxi(u%NDIM_FULL))
243  ALLOCATE(zdyi(u%NDIM_FULL))
244  !
245  zdxi(:)=(zlonmax-zlonmin)/(nimax-1)
246  zdyi(:)=(zlatmax-zlatmin)/(njmax-1)
247  !
248  DO jj=1,nimax
249  zlon(jj) = zxi(jj) - zdxi(jj)/2.
250  ENDDO
251  zlon(nimax+1) = zxi(nimax) + zdxi(nimax)/2.
252  !
253  DO jj=1,njmax
254  jwrk=(jj-1)*(nimax+1)+1 ! indice sur la grille des noeuds
255  ji=(jj-1)*nimax+1 ! indice sur la grille des mailles
256  zlat(jwrk) = zyi(ji) - zdyi(ji)/2.
257  ENDDO
258  !
259  jj=((njmax+1)-1)*(nimax+1)+1 ! Indice sur la grille des noeuds
260  ji=(njmax-1)*nimax+1
261  zlat(jj) = zyi(ji) + zdyi(ji)/2.
262  !
263  DEALLOCATE(zdxi)
264  DEALLOCATE(zdyi)
265  DEALLOCATE(zxi)
266  DEALLOCATE(zyi)
267  !
268  DO jj=1,nimax+1
269  DO ji=2,njmax+1
270  jk = (ji-1)*(nimax+1)+jj
271  zlon(jk) = zlon(jj)
272  ENDDO
273  ENDDO
274  !
275  DO ji=1,njmax+1
276  DO jj=2,nimax+1
277  jk=(ji-1)*(nimax+1)+jj
278  jwrk=(ji-1)*(nimax+1)+1
279  zlat(jk)=zlat(jwrk)
280  ENDDO
281  ENDDO
282  !
283  ! Modification by Eram Artinian to take into account IGN grid 1
284  ELSE IF (ug%CGRID=='IGN') THEN
285  WRITE(iluout,*) 'GRILLE IGN (application Bulgarie)'
286  ALLOCATE(zxn(u%NDIM_FULL))
287  ALLOCATE(zyn(u%NDIM_FULL))
288  CALL get_gridtype_ign(ug%XGRID_PAR,klambert=ilambert,&
289  kl=il,px=zxn,py=zyn,kdimx=nimax)
290  imeshl=il
291  ALLOCATE(zlat(imeshl))
292  ALLOCATE(zlon(imeshl))
293  CALL latlon_ign(ilambert,zxn,zyn,zlat,zlon)
294  !End modification by Eram Artinian to take into account IGN grid
295  ELSE
296  !
297  WRITE(iluout,*) 'ERREUR: TYPE DE GRILLE NON GERE PAR LE CODE'
298  CALL abor1_sfx("PGD_TOPD: TYPE DE GRILLE NON GERE PAR LE CODE")
299  !
300  ENDIF
301  !
302  !* 2.0 calcul des coordonnées lambert II étendu des noeuds de la grille ISBA
303  ! ----------------------------------------------------------------------
304  !
305  ALLOCATE(xxi(imeshl))
306  ALLOCATE(xyi(imeshl))
307  ! Modification by Eram Artinian to take into account IGN grid 2
308  IF (ug%CGRID/='IGN') THEN
309  CALL xy_ign(5,xxi,xyi,zlat,zlon)
310  ELSE
311  xxi=zxn
312  xyi=zyn
313  DEALLOCATE(zxn)
314  DEALLOCATE(zyn)
315  ENDIF
316  !End modification by Eram Artinian to take into account IGN grid 2
317  DEALLOCATE(zlat)
318  DEALLOCATE(zlon)
319  !
320  !* 2.0 mask
321  ! ----
322  !***
323  CALL make_mask_topd_to_isba(ug, &
324  u%NDIM_FULL)
325  !
326  ALLOCATE(nnpix(u%NDIM_FULL))
327  nnpix(:) = nundef
328  DO jj=1,u%NDIM_FULL
329  nnpix(jj) = count(nmaskt(:,:)==jj)
330  ENDDO
331  !
332  CALL make_mask_isba_to_topd(u%NDIM_FULL)
333  !
334  CALL write_file_masktopd(u%NDIM_FULL)
335  !
336  !* 3.0 Compute Mean slope over each ISBA_MESH
337 ! ----------------------------------------------------------------------
338  CALL topd_to_isba_slope(uss, &
339  u%NDIM_FULL)
340 !
341 !* 4.0 Compute F and DC for each ISBA mesh
342  ! ----------------------------------------------------------------------
343  !
344  ALLOCATE(nnbv_in_mesh(u%NDIM_FULL,nncat))
345  ALLOCATE(xbv_in_mesh(u%NDIM_FULL,nncat))
346  ALLOCATE(xtotbv_in_mesh(u%NDIM_FULL))
347  !
348  xtotbv_in_mesh(:) = 0.0
349  !
350  DO jmesh=1,u%NDIM_FULL
351  xbv_in_mesh(jmesh,:)=0.0
352  DO jcat=1,nncat
353  nnbv_in_mesh(jmesh,jcat) = count(nmaski(jmesh,jcat,:)/=nundef)
354  xbv_in_mesh(jmesh,jcat) = REAL(nnbv_in_mesh(jmesh,jcat))*xdxt(jcat)**2
355  xtotbv_in_mesh(jmesh) = xtotbv_in_mesh(jmesh) + xbv_in_mesh(jmesh,jcat)
356  ENDDO
357  ENDDO
358  !
359  ALLOCATE (zf_param(u%NDIM_FULL))
360  ALLOCATE (zc_depth_ratio(u%NDIM_FULL))
361  !
362  zf_param(:) = 0.
363  zc_depth_ratio(:) = 0.
364  DO jcat=1,nncat
365  DO jmesh=1,u%NDIM_FULL
366  IF ( xtotbv_in_mesh(jmesh)/=0. ) THEN
367  zf_param(jmesh) = zf_param(jmesh) + xf_param_bv(jcat)*xbv_in_mesh(jmesh,jcat)/xtotbv_in_mesh(jmesh)
368  zc_depth_ratio(jmesh) = zc_depth_ratio(jmesh) + xc_depth_ratio_bv(jcat)*xbv_in_mesh(jmesh,jcat)/xtotbv_in_mesh(jmesh)
369  ENDIF
370  ENDDO
371  ENDDO
372  !
373  WHERE (zf_param==0.)
374  zf_param=2.5
375  zc_depth_ratio=1.
376  ENDWHERE
377  !
378  !write(*,*) 'f min max isba',MINVAL(ZF_PARAM),MAXVAL(ZF_PARAM)
379  !write(*,*) 'dc min max isba',MINVAL(ZC_DEPTH_RATIO),MAXVAL(ZC_DEPTH_RATIO)
380  !
381  CALL open_file('ASCII ',nunit,'carte_f_dc.txt','FORMATTED',haction='WRITE')
382  DO jmesh=1,u%NDIM_FULL
383  WRITE(nunit,*) zf_param(jmesh),zc_depth_ratio(jmesh)
384  ENDDO
385  CALL close_file('ASCII ',nunit)
386  !
387  DEALLOCATE(zf_param)
388  DEALLOCATE(zc_depth_ratio)
389  !
390  WRITE(iluout,*) 'Couplage avec TOPMODEL active'
391  !
392 ELSE
393  !
394  WRITE(iluout,*) 'Pas de couplage avec TOPMODEL'
395  !
396 ENDIF
397 !
398 IF (lhook) CALL dr_hook('PGD_TOPD',1,zhook_handle)
399 !
400 END SUBROUTINE pgd_topd
subroutine xy_ign(KLAMBERT, PX, PY, PLAT, PLON)
subroutine pgd_topd(I, UG, U, USS, HPROGRAM)
Definition: pgd_topd.F90:7
subroutine topd_to_isba_slope(USS, KI)
subroutine read_nam_pgd_topd(HPROGRAM, OCOUPL_TOPD, HCAT, PF_PARAM_BV, PC_DEPTH_RATIO_BV)
subroutine get_gridtype_ign(PGRID_PAR, KLAMBERT, KL, PX, PY, PDX, PDY, KDIMX, KDIMY, PXALL, PYALL)
subroutine latlon_ign(KLAMBERT, PX, PY, PLAT, PLON)
subroutine abor1_sfx(YTEXT)
Definition: abor1_sfx.F90:6
subroutine latlon_conf_proj(PLAT0, PLON0, PRPK, PBETA, PLATOR, PLONOR, PX, PY, PLAT, PLON)
subroutine make_mask_isba_to_topd(KI)
subroutine init_topd_pgd(HPROGRAM)
subroutine close_file(HPROGRAM, KUNIT)
Definition: close_file.F90:6
subroutine get_luout(HPROGRAM, KLUOUT)
Definition: get_luout.F90:6
subroutine make_mask_topd_to_isba(UG, KI)
subroutine get_gridtype_conf_proj(PGRID_PAR, PLAT0, PLON0, PRPK, PBETA, PLATOR, PLONOR, KIMAX, KJMAX, PX, PY, PDX, PDY, KL)
subroutine write_file_masktopd(KI)
subroutine get_gridtype_lonlat_reg(PGRID_PAR, PLONMIN, PLONMAX, PLATMIN, PLATMAX, KLON, KLAT, KL, PLON, PLAT)
subroutine open_file(HPROGRAM, KUNIT, HFILE, HFORM, HACTION, HACCESS, KRECL)
Definition: open_file.F90:6