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