SURFEX  V8_0
Surfex V8_0 release
 All Classes Files Functions Variables
regular_grid_spawn.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 regular_grid_spawn(KLUOUT, &
7  kl1, kimax1,kjmax1,px1,py1,pdx1,pdy1, &
8  kxor, kyor, kdxratio, kdyratio, &
9  kxsize, kysize, &
10  kl2, kimax2,kjmax2,px2,py2,pdx2,pdy2 )
11 ! ################################################################
12 !
13 !!**** *REGULAR_GRID_SPAWN* - routine to read in namelist the horizontal grid
14 !!
15 !! PURPOSE
16 !! -------
17 !!
18 !!** METHOD
19 !! ------
20 !!
21 !! EXTERNAL
22 !! --------
23 !!
24 !!
25 !! IMPLICIT ARGUMENTS
26 !! ------------------
27 !!
28 !! REFERENCE
29 !! ---------
30 !!
31 !!
32 !! AUTHOR
33 !! ------
34 !! V. Masson *Meteo France*
35 !!
36 !! MODIFICATIONS
37 !! -------------
38 !! Original 01/2004
39 !-------------------------------------------------------------------------------
40 !
41 !* 0. DECLARATIONS
42 ! ------------
43 !
44 USE modd_surf_par, ONLY : nundef
45 !
46 !
47 USE yomhook ,ONLY : lhook, dr_hook
48 USE parkind1 ,ONLY : jprb
49 !
50 USE modi_abor1_sfx
51 !
52 IMPLICIT NONE
53 !
54 !* 0.1 Declarations of arguments
55 ! -------------------------
56 !
57 INTEGER, INTENT(IN) :: kluout ! output listing logical unit
58 INTEGER, INTENT(IN) :: kl1 ! total number of points KIMAX1 * KJMAX1
59 INTEGER, INTENT(IN) :: kimax1 ! number of points in x direction
60 INTEGER, INTENT(IN) :: kjmax1 ! number of points in y direction
61 REAL, DIMENSION(KL1), INTENT(IN) :: px1 ! X coordinate of all points
62 REAL, DIMENSION(KL1), INTENT(IN) :: py1 ! Y coordinate of all points
63 REAL, DIMENSION(KL1), INTENT(IN) :: pdx1 ! X mesh size of all points
64 REAL, DIMENSION(KL1), INTENT(IN) :: pdy1 ! Y mesh size of all points
65 INTEGER, INTENT(IN) :: kxor ! position of modified bottom left point
66 INTEGER, INTENT(IN) :: kyor ! according to initial grid
67 INTEGER, INTENT(IN) :: kxsize ! number of grid meshes in initial grid to be
68 INTEGER, INTENT(IN) :: kysize ! covered by the modified grid
69 INTEGER, INTENT(IN) :: kdxratio ! resolution ratio between modified grid
70 INTEGER, INTENT(IN) :: kdyratio ! and initial grid
71 INTEGER, INTENT(IN) :: kl2 ! total number of points KIMAX2 * KJMAX2
72 INTEGER, INTENT(IN) :: kimax2 ! number of points in x direction
73 INTEGER, INTENT(IN) :: kjmax2 ! number of points in y direction
74 REAL, DIMENSION(KL2), INTENT(OUT) :: px2 ! X coordinate of all points
75 REAL, DIMENSION(KL2), INTENT(OUT) :: py2 ! Y coordinate of all points
76 REAL, DIMENSION(KL2), INTENT(OUT) :: pdx2 ! X mesh size of all points
77 REAL, DIMENSION(KL2), INTENT(OUT) :: pdy2 ! Y mesh size of all points
78 !
79 !* 0.2 Declarations of local variables
80 ! -------------------------------
81 !
82 !* initial grid
83 !
84 REAL, DIMENSION(:), ALLOCATABLE :: zxm1 ! X coordinate of center of mesh (IIMAX1 points)
85 REAL, DIMENSION(:), ALLOCATABLE :: zym1 ! Y coordinate of center of mesh (IJMAX1 points)
86 REAL, DIMENSION(:), ALLOCATABLE :: zxhat1 ! X coordinate of left side (IIMAX1+1 points)
87 REAL, DIMENSION(:), ALLOCATABLE :: zyhat1 ! Y coordinate of bottom side (IJMAX1+1 points)
88 !
89 !* new grid
90 !
91 REAL, DIMENSION(:), ALLOCATABLE :: zxhat2 ! X coordinate of left side (IIMAX2 points)
92 REAL, DIMENSION(:), ALLOCATABLE :: zyhat2 ! Y coordinate of bottom side (IJMAX2 points)
93 !
94 !* other variables
95 !
96 INTEGER :: jl ! loop counter
97 INTEGER :: ji,jj ! loop controls relatively to modified grid
98 INTEGER :: jibox,jjbox ! grid mesh relatively to initial grid
99 REAL :: zcoef ! ponderation coefficient for linear interpolation
100 REAL(KIND=JPRB) :: zhook_handle
101 !
102 !------------------------------------------------------------------------------
103 !
104 !* 1. Coherence tests
105 ! ---------------
106 !
107 !* tests
108 !
109 IF (lhook) CALL dr_hook('REGULAR_GRID_SPAWN',0,zhook_handle)
110 IF ( kxor+kxsize-1 > kimax1 ) THEN
111  WRITE(kluout,*) 'spawned domain is not contained in the input domain'
112  WRITE(kluout,*) 'IXOR = ', kxor, ' IXSIZE = ', kxsize,&
113  ' with NIMAX(file) = ', kimax1
114  CALL abor1_sfx('REGULAR_GRID_SPAWN: (1) SPAWNED DOMAIN NOT CONTAINED IN INPUT DOMAIN')
115 END IF
116 IF ( kyor+kysize-1 > kjmax1 ) THEN
117  WRITE(kluout,*) 'spawned domain is not contained in the input domain'
118  WRITE(kluout,*) 'IYOR = ', kyor, ' IYSIZE = ', kysize,&
119  ' with NJMAX(file) = ', kjmax1
120  CALL abor1_sfx('REGULAR_GRID_SPAWN: (2) SPAWNED DOMAIN NOT CONTAINED IN INPUT DOMAIN')
121 END IF
122 !
123 !------------------------------------------------------------------------------
124 !
125 !* 2. Center of mesh coordinate arrays for each direction separately
126 ! --------------------------------------------------------------
127 !
128 ALLOCATE(zxm1(kimax1))
129 ALLOCATE(zym1(kjmax1))
130 ALLOCATE(zxhat1(kimax1+1))
131 ALLOCATE(zyhat1(kjmax1+1))
132 ALLOCATE(zxhat2(kimax2+1))
133 ALLOCATE(zyhat2(kjmax2+1))
134 !
135 zxm1(:) = px1(1:kimax1)
136 DO jl=1,kl1
137  IF (mod(jl,kimax1)==0) zym1(jl/kimax1) = py1(jl)
138 END DO
139 !
140 !------------------------------------------------------------------------------
141 !
142 !* 3. side of mesh coordinate arrays for each direction separately
143 ! ------------------------------------------------------------
144 !
145 !
146 IF (kimax1==1) THEN
147  zxhat1(1) = zxm1(1) - 0.5 * pdx1(1)
148  zxhat1(2) = zxm1(1) + 0.5 * pdx1(1)
149 ELSE
150  zxhat1(1) = 1.5 * zxm1(1) - 0.5 * zxm1(2)
151  DO ji=2,kimax1
152  zxhat1(ji) = 0.5 * zxm1(ji-1) + 0.5 * zxm1(ji)
153  END DO
154  zxhat1(kimax1+1) = 1.5 * zxm1(kimax1) - 0.5 * zxm1(kimax1-1)
155 END IF
156 !
157 IF (kjmax1==1) THEN
158  zyhat1(1) = zym1(1) - 0.5 * pdy1(1)
159  zyhat1(2) = zym1(1) + 0.5 * pdy1(1)
160 ELSE
161  zyhat1(1) = 1.5 * zym1(1) - 0.5 * zym1(2)
162  DO jj=2,kjmax1
163  zyhat1(jj) = 0.5 * zym1(jj-1) + 0.5 * zym1(jj)
164  END DO
165  zyhat1(kjmax1+1) = 1.5 * zym1(kjmax1) - 0.5 * zym1(kjmax1-1)
166 END IF
167 !
168 !------------------------------------------------------------------------------
169 !
170 !* 5. Interpolation of coordinate arrays for each direction separately
171 ! ----------------------------------------------------------------
172 !
173 !* X coordinate array
174 !
175 DO ji=1,kimax2
176  jibox=(ji-1)/kdxratio + kxor
177  zcoef= float(mod(ji-1,kdxratio))/float(kdxratio)
178  zxhat2(ji)=(1.-zcoef)*zxhat1(jibox)+zcoef*zxhat1(jibox+1)
179 END DO
180 IF (kimax2==1) THEN
181  zxhat2(kimax2+1) = zxhat2(kimax2) + zxhat1(jibox+1) - zxhat1(jibox)
182 ELSE
183  zxhat2(kimax2+1) = 2. * zxhat2(kimax2) - zxhat2(kimax2-1)
184 END IF
185 !
186 !
187 !* Y coordinate array
188 !
189 DO jj=1,kjmax2
190  jjbox=(jj-1)/kdyratio + kyor
191  zcoef= float(mod(jj-1,kdyratio))/float(kdyratio)
192  zyhat2(jj)=(1.-zcoef)*zyhat1(jjbox)+zcoef*zyhat1(jjbox+1)
193 END DO
194 IF (kjmax2==1) THEN
195  zyhat2(kjmax2+1) = zyhat2(kjmax2) + zyhat1(jjbox+1) - zyhat1(jjbox)
196 ELSE
197  zyhat2(kjmax2+1) = 2. * zyhat2(kjmax2) - zyhat2(kjmax2-1)
198 END IF
199 !---------------------------------------------------------------------------
200 DEALLOCATE(zxm1)
201 DEALLOCATE(zym1)
202 DEALLOCATE(zxhat1)
203 DEALLOCATE(zyhat1)
204 !------------------------------------------------------------------------------
205 !
206 !* 5. Coordinate arrays of all points
207 ! -------------------------------
208 !
209 DO jj=1,kjmax2
210  DO ji=1,kimax2
211  jl = (jj-1) * kimax2 + ji
212  px2(jl) = 0.5 * zxhat2(ji) + 0.5 * zxhat2(ji+1)
213  pdx2(jl) = zxhat2(ji+1) - zxhat2(ji)
214  py2(jl) = 0.5 * zyhat2(jj) + 0.5 * zyhat2(jj+1)
215  pdy2(jl) = zyhat2(jj+1) - zyhat2(jj)
216  END DO
217 END DO
218 !
219 !---------------------------------------------------------------------------
220 DEALLOCATE(zxhat2)
221 DEALLOCATE(zyhat2)
222 IF (lhook) CALL dr_hook('REGULAR_GRID_SPAWN',1,zhook_handle)
223 !---------------------------------------------------------------------------
224 !
225 END SUBROUTINE regular_grid_spawn
subroutine regular_grid_spawn(KLUOUT, KL1, KIMAX1, KJMAX1, PX1, PY1, PDX1, PDY1, KXOR, KYOR, KDXRATIO, KDYRATIO, KXSIZE, KYSIZE, KL2, KIMAX2, KJMAX2, PX2, PY2, PDX2, PDY2)
subroutine abor1_sfx(YTEXT)
Definition: abor1_sfx.F90:6