1 | MODULE compute_sections |
---|
2 | !!===================================================================== |
---|
3 | !! *** MODULE diadct *** |
---|
4 | !! Ocean diagnostics: Compute the transport through a section |
---|
5 | !! |
---|
6 | !! History: 2011: Clement Bricaud, Mercator-Ocean |
---|
7 | !! |
---|
8 | !!=============================================================== |
---|
9 | !! * Modules used |
---|
10 | USE declarations |
---|
11 | USE sections_tools |
---|
12 | |
---|
13 | IMPLICIT NONE |
---|
14 | PRIVATE |
---|
15 | |
---|
16 | !! * Routine accessibility |
---|
17 | PUBLIC compsec |
---|
18 | |
---|
19 | !! * Module variables |
---|
20 | |
---|
21 | CONTAINS |
---|
22 | |
---|
23 | SUBROUTINE compsec(jsec,sec,lkdebug) |
---|
24 | !!--------------------------------------------------------------------- |
---|
25 | !! *** ROUTINE compsec *** |
---|
26 | !! |
---|
27 | !! ** Purpose : Compute the series of mesh points that represent the section |
---|
28 | !! defined by its extremities. |
---|
29 | !! |
---|
30 | !! ** Method : |
---|
31 | !! I. Find which cells of the mesh the section is crossing |
---|
32 | !! II. Classification of the intersections mesh/section |
---|
33 | !! -first classification west to east |
---|
34 | !! -second classification south to north |
---|
35 | !! III. Find extremities of section in the mesh |
---|
36 | !! IV. Find the series of mesh points that form the section |
---|
37 | !! ** Input: sec : the section to compute |
---|
38 | !! |
---|
39 | !! ** Output: |
---|
40 | !!--------------------------------------------------------------------- |
---|
41 | !! * Arguments |
---|
42 | INTEGER,INTENT(IN) :: jsec ! number of the section |
---|
43 | TYPE(SECTION), INTENT(INOUT) :: sec ! information about the section |
---|
44 | LOGICAL ,INTENT(IN) :: lkdebug ! debug or not debug this section |
---|
45 | |
---|
46 | !! * Local variables |
---|
47 | INTEGER :: & |
---|
48 | ji,jj , & ! dummy loop argument |
---|
49 | jseg , & ! loop on segments that form the section |
---|
50 | nb_inmesh , & ! number of intersections between the section and the mesh |
---|
51 | nmesh ! number of cells in processor domain |
---|
52 | INTEGER :: itest , jtest ! dummy integer |
---|
53 | REAL(wp),SAVE :: zdistmesh ! Taller cell of the mesh in ocean |
---|
54 | REAL(wp) :: & |
---|
55 | zdistEst , zdistNorth , zdistWest , zdistSouth , &! temporary scalars |
---|
56 | zdistEst2 , zdistNorth2, zdistWest2, zdistSouth2, &! temporary scalars |
---|
57 | zdistEst3 , zdistNorth3, zdistWest3, zdistSouth3, &! temporary scalars |
---|
58 | zdistFirst , zdistLast , zdistref , &! temporary scalars |
---|
59 | zdistante , zdistante2 , zdistnew , zdistnew2 , &! temporary scalars |
---|
60 | zdeltai , zdeltaj ! temporary scalars |
---|
61 | LOGICAL :: & |
---|
62 | ll_overlap_sec_left = .FALSE. , ll_overlap_sec_right = .FALSE. ,&! temporary logical |
---|
63 | ll_date_domain_left = .FALSE. , ll_date_domain_right = .FALSE. ,&! temporary logical |
---|
64 | ll_overlap_sec = .FALSE. , ll_date_domain = .FALSE. ,&! temporary logical |
---|
65 | ll_test = .FALSE. ! temporary logical |
---|
66 | LOGICAL :: lest, lwest, lnorth, lsouth |
---|
67 | LOGICAL :: l_oldmethod |
---|
68 | CHARACTER(len=120) :: cltmp |
---|
69 | TYPE(COORD_SECTION) :: & |
---|
70 | coord_a , coord_b , coord_d , coord_t , &!temporary point (long/lat) |
---|
71 | coordFirst, coordLast, coordTemp ! " |
---|
72 | TYPE(COORD_SECTION), DIMENSION(nb_point_max) :: coordSec !intersections mesh/section |
---|
73 | TYPE(POINT_SECTION) :: & |
---|
74 | endingPoint, prevPoint , nextPoint, &!temporary point (I/J) |
---|
75 | SouthPoint , NorthPoint, EstPoint , WestPoint ! " |
---|
76 | !!--------------------------------------------------------------------- |
---|
77 | IF( jsec==1 )THEN |
---|
78 | PRINT*,' ' |
---|
79 | PRINT*,'COMPUTE SECTIONS' |
---|
80 | PRINT*,'----------------' |
---|
81 | ENDIF |
---|
82 | |
---|
83 | !debug |
---|
84 | CALL write_debug(jsec,'compute section:') |
---|
85 | CALL write_debug(jsec,'================') |
---|
86 | |
---|
87 | |
---|
88 | !==================! |
---|
89 | !0. Initializations! |
---|
90 | !==================! |
---|
91 | |
---|
92 | nmesh = jpi*jpj ! number of cells in processor domain |
---|
93 | nb_inmesh = 0 ! initialize number of intersections between section and the mesh |
---|
94 | zdistEst =0. ; zdistNorth=0. ; zdistWest=0. ; zdistSouth=0. ! temporary scalars |
---|
95 | zdistFirst=0. ; zdistLast =0. ! temporary scalars |
---|
96 | zdistante =0. ; zdistante2=0. ; zdistnew=0. ; zdistnew2=0. ! temporary scalars |
---|
97 | zdeltai=0. ; zdeltaj=0. |
---|
98 | coord_a = COORD_SECTION( 0., 0. ) ; coord_b = COORD_SECTION( 0., 0. ) |
---|
99 | coord_d = COORD_SECTION( 0., 0. ) ; coord_t = COORD_SECTION( 0., 0. ) |
---|
100 | coordFirst = COORD_SECTION( 0., 0. ) ; coordLast = COORD_SECTION( 0., 0. ) |
---|
101 | coordTemp = COORD_SECTION( 0., 0. ) ; coordSec = COORD_SECTION( 0., 0. ) |
---|
102 | endingPoint = POINT_SECTION( -1, -1 ) |
---|
103 | prevPoint = POINT_SECTION( -1, -1 ) ; nextPoint = POINT_SECTION( -1, -1 ) |
---|
104 | SouthPoint = POINT_SECTION( -1, -1 ) ; NorthPoint = POINT_SECTION( -1, -1 ) |
---|
105 | EstPoint = POINT_SECTION( -1, -1 ) ; WestPoint = POINT_SECTION( -1, -1 ) |
---|
106 | |
---|
107 | IF( jsec == 1 )THEN |
---|
108 | !Find the taller cell of the mesh in ocean (used in compsec) |
---|
109 | zdistmesh=0. |
---|
110 | DO jj=2,jpj |
---|
111 | DO ji=2,jpi |
---|
112 | IF( zdistmesh .LT. & |
---|
113 | (e1t(ji,jj)/(cos(gphit(ji,jj))*110000)) ) THEN |
---|
114 | zdistmesh = e1t(ji,jj)/(cos(gphit(ji,jj))*110000) |
---|
115 | ENDIF |
---|
116 | ENDDO |
---|
117 | ENDDO |
---|
118 | |
---|
119 | ENDIF |
---|
120 | |
---|
121 | !debug |
---|
122 | WRITE(cltmp,'(A10,f10.3)')'zdistmesh = ',zdistmesh |
---|
123 | CALL write_debug(jsec,cltmp) |
---|
124 | |
---|
125 | !===========================================================! |
---|
126 | !I. Find which cells of the mesh the section is crossing ! |
---|
127 | !===========================================================! |
---|
128 | |
---|
129 | !loop on the mesh |
---|
130 | DO jj=2,jpj |
---|
131 | DO ji=2,jpi |
---|
132 | !----------------------------------------------------------- |
---|
133 | !For each cell of the mesh, we find the intersection between |
---|
134 | !the section and the cell as described below: |
---|
135 | !The cell is defined by 4 points A B C D |
---|
136 | !and the section by S1 and S2 |
---|
137 | ! |
---|
138 | !Section\ ________ |
---|
139 | ! \ B| | |
---|
140 | ! \ | | |
---|
141 | ! \|one cell| |
---|
142 | ! .....\ | |
---|
143 | ! |\ | |
---|
144 | ! | \ | |
---|
145 | ! A|__\_____|D |
---|
146 | ! ........\ |
---|
147 | !----------------\------------------------------------------- |
---|
148 | |
---|
149 | !definition of points A,B,D (we don't need C) |
---|
150 | coord_a = COORD_SECTION( glamf(ji-1,jj-1) ,gphif(ji-1,jj-1) ) |
---|
151 | coord_b = COORD_SECTION( glamf(ji-1,jj) ,gphif(ji-1,jj) ) |
---|
152 | coord_d = COORD_SECTION( glamf(ji,jj-1) ,gphif(ji,jj-1) ) |
---|
153 | |
---|
154 | !size of the cell |
---|
155 | zdeltai= glamf(ji-1,jj) - glamf(ji-1,jj-1) !zdeltai=[AB] |
---|
156 | zdeltaj= gphif(ji,jj-1) - gphif(ji-1,jj-1) !zdeltaj=[AD] |
---|
157 | |
---|
158 | IF( ABS(zdeltai) .LE. 2.*zdistmesh .OR. & |
---|
159 | ABS(zdeltaj) .LE. 2.*zdistmesh )THEN |
---|
160 | |
---|
161 | !intersection section/[AB]=? |
---|
162 | coordTemp = intersec(sec,coord_a,coord_b) !compute intersection |
---|
163 | coordTemp%lon = coordTemp%lon !* zmask(ji,jj)-9999.*(1-zmask(ji,jj)) |
---|
164 | coordTemp%lat = coordTemp%lat !* zmask(ji,jj)-9999.*(1-zmask(ji,jj)) |
---|
165 | |
---|
166 | IF( coordTemp%lon .NE. -9999 )THEN |
---|
167 | IF( nb_inmesh+1 .GT. nb_point_max )THEN |
---|
168 | PRINT*,"WARNING diadct: nb_point_max needs to be greater than ", nb_inmesh |
---|
169 | ELSE |
---|
170 | nb_inmesh=nb_inmesh+1 |
---|
171 | coordSec(nb_inmesh) = coordTemp !store the intersection's coordinates |
---|
172 | |
---|
173 | !We need to know if the section crosses the overlapping band. |
---|
174 | |
---|
175 | !Fist we look if there is an intersection mesh/section |
---|
176 | !just on the left of the overlapping band: |
---|
177 | IF( coordTemp%lon .GT. glamf(1,1)-5 .AND. coordTemp%lon .LT. glamf(1,1) ) & |
---|
178 | & ll_overlap_sec_left = .TRUE. |
---|
179 | !And we look if there is an intersection mesh/section |
---|
180 | !just on the right of the overlapping band: |
---|
181 | IF( coordTemp%lon .GT. glamf(jpi,1) .AND. coordTemp%lon .LT. glamf(1,1)+5 ) & |
---|
182 | & ll_overlap_sec_right = .TRUE. |
---|
183 | ENDIF |
---|
184 | ENDIF |
---|
185 | |
---|
186 | !intersection section/[AD]=? |
---|
187 | coordTemp=intersec(sec,coord_a,coord_d) !compute intersection |
---|
188 | coordTemp%lon = coordTemp%lon !* zmask(ji,jj)-9999.*(1-zmask(ji,jj)) |
---|
189 | coordTemp%lat = coordTemp%lat !* zmask(ji,jj)-9999.*(1-zmask(ji,jj)) |
---|
190 | |
---|
191 | IF( coordTemp%lon .NE. -9999 )THEN |
---|
192 | IF( nb_inmesh+1 .GT. nb_point_max )THEN |
---|
193 | PRINT*, "WARNING diadct: nb_point_max needs to be greater than ", nb_inmesh |
---|
194 | ELSE |
---|
195 | nb_inmesh=nb_inmesh+1 |
---|
196 | coordSec(nb_inmesh)=coordTemp |
---|
197 | |
---|
198 | !We need to know if the section crosses the overlapping band: |
---|
199 | !same test as above |
---|
200 | IF( coordTemp%lon .GE. glamf(1,1)-3 .AND. coordTemp%lon .LE. glamf(1,1) ) & |
---|
201 | & ll_overlap_sec_left = .TRUE. |
---|
202 | IF( coordTemp%lon .GE. glamf(jpi,1) .AND. coordTemp%lon .LE. glamf(jpi,1)+3) & |
---|
203 | & ll_overlap_sec_right = .TRUE. |
---|
204 | ENDIF |
---|
205 | ENDIF |
---|
206 | |
---|
207 | ENDIF |
---|
208 | |
---|
209 | !We need to know if the domain crosses the date line: |
---|
210 | !Fist, we search a mesh point that is just one the left of date line: |
---|
211 | IF( glamf(ji-1,jj-1) .GT. 175 .AND. glamf(ji-1,jj-1) .LT. 180 ) & |
---|
212 | & ll_date_domain_left = .TRUE. |
---|
213 | !And we search a mesh point that is just one the right of date line: |
---|
214 | IF( glamf(ji-1,jj-1) .GT. -180 .AND. glamf(ji-1,jj-1) .LT. -175 ) & |
---|
215 | & ll_date_domain_right = .TRUE. |
---|
216 | |
---|
217 | ENDDO |
---|
218 | ENDDO !End of the loop on the mesh |
---|
219 | |
---|
220 | |
---|
221 | !Crossing section/overlapping band (we need to know it for later): |
---|
222 | !----------------------------------------------------------------- |
---|
223 | !If there is one intersection mesh/section just on the left of |
---|
224 | !the overlapping band (ll_overlap_sec_left = .TRUE.) |
---|
225 | !AND there is one just the right of the overlapping band |
---|
226 | !(ll_overlap_sec_right = .TRUE.), |
---|
227 | !so the section crosses the overlapping band. |
---|
228 | ll_overlap_sec = ll_overlap_sec_left .AND. ll_overlap_sec_right |
---|
229 | |
---|
230 | !Crossing of the domain and the date line (we need to know it for later): |
---|
231 | !------------------------------------------------------------------------ |
---|
232 | !If there is one point of the domain that is just on the left of the date line |
---|
233 | !(ll_date_domain_left = .TRUE.) AND one point that is just on the right of the |
---|
234 | !date line (ll_date_domain_right = .TRUE. ) |
---|
235 | !So the domain crosses the date line: |
---|
236 | ll_date_domain = ll_date_domain_left .AND. ll_date_domain_right |
---|
237 | |
---|
238 | !=====================================================! |
---|
239 | ! II. Classification of the intersections mesh/section! |
---|
240 | !=====================================================! |
---|
241 | |
---|
242 | ! -first classification west to east |
---|
243 | ! -second classification south to north |
---|
244 | !CAUTION: routine qcksrt doesn't work in the same way if the section |
---|
245 | !and the domain crosse the date line (sec%ll_date_line=T and ll_date_domain=T) |
---|
246 | |
---|
247 | IF( sec%ll_date_line .AND. ll_date_domain )THEN |
---|
248 | |
---|
249 | !we add 360° to negative longitudes to have a good classification |
---|
250 | DO jseg=1,nb_inmesh |
---|
251 | IF( coordSec(jseg)%lon .LT. 0 ) coordSec(jseg)%lon=coordSec(jseg)%lon+360. |
---|
252 | ENDDO |
---|
253 | IF( sec%coordSec(1)%lon .NE. sec%coordSec(2)%lon ) THEN |
---|
254 | CALL qcksrt(coordSec(:)%lon,coordSec(:)%lat,nb_inmesh) |
---|
255 | ELSE |
---|
256 | CALL qcksrt(coordSec(:)%lat,coordSec(:)%lon,nb_inmesh) |
---|
257 | ENDIF |
---|
258 | DO jseg=1,nb_inmesh |
---|
259 | IF( coordSec(jseg)%lon .GT. 180 ) coordSec(jseg)%lon=coordSec(jseg)%lon-360. |
---|
260 | ENDDO |
---|
261 | |
---|
262 | ELSE |
---|
263 | |
---|
264 | IF( sec%coordSec(1)%lon .NE. sec%coordSec(2)%lon )THEN |
---|
265 | CALL qcksrt(coordSec(:)%lon,coordSec(:)%lat,nb_inmesh) |
---|
266 | ELSE |
---|
267 | CALL qcksrt(coordSec(:)%lat,coordSec(:)%lon,nb_inmesh) |
---|
268 | ENDIF |
---|
269 | |
---|
270 | ENDIF |
---|
271 | |
---|
272 | !debug |
---|
273 | WRITE(cltmp,'(A20,i3.3)')'number intersections = ',nb_inmesh ; CALL write_debug(jsec,cltmp) |
---|
274 | CALL write_debug(jsec,'List of intersections between grid and section: ') |
---|
275 | DO jseg=1,nb_inmesh |
---|
276 | WRITE(cltmp,'(i4.4,1X,2(f8.3,1X) )')jseg,coordSec(jseg) ; CALL write_debug(jsec,cltmp) |
---|
277 | ENDDO |
---|
278 | |
---|
279 | !=====================================================! |
---|
280 | ! III. Find extremities of section in the mesh ! |
---|
281 | !=====================================================! |
---|
282 | !we can find section's extremities in the mesh only if |
---|
283 | !there is intersection between section and mesh (nb_inmesh .ne. 0) |
---|
284 | |
---|
285 | IF( nb_inmesh .ne. 0 )THEN |
---|
286 | coordFirst = coordSec(1) |
---|
287 | coordLast = coordSec(nb_inmesh) |
---|
288 | sec%nb_point = nb_inmesh |
---|
289 | sec%listPoint(1) = POINT_SECTION(-1,-1) |
---|
290 | zdistante = 1000. |
---|
291 | zdistante2 = 1000. |
---|
292 | |
---|
293 | !First, we find the point of the mesh that is the closest |
---|
294 | !to the first intersection section/mesh (=coordFirst=coordSec(1)): |
---|
295 | !this point will be called sec%listPoint(1). |
---|
296 | !Then, we find the point of the mesh that is the closest |
---|
297 | !to the last intersection section/mesh (coordLast=coordSec(nb_inmesh)) |
---|
298 | !this point will be called endingPoint. |
---|
299 | |
---|
300 | DO jj=1,jpj |
---|
301 | DO ji=1,jpi |
---|
302 | coord_t=COORD_SECTION(glamf(ji,jj),gphif(ji,jj)) |
---|
303 | zdistFirst = distance2(coord_t,coordFirst) |
---|
304 | zdistLast = distance2(coord_t,coordLast) |
---|
305 | IF( zdistFirst .LT. zdistmesh .AND. zdistFirst .LT. zdistante )THEN |
---|
306 | sec%listPoint(1) = POINT_SECTION(ji,jj) |
---|
307 | zdistante=zdistFirst |
---|
308 | ENDIF |
---|
309 | IF( zdistLast .LT. zdistmesh .AND. zdistLast .LT. zdistante2 )THEN |
---|
310 | endingPoint = POINT_SECTION(ji,jj) |
---|
311 | zdistante2=zdistLast |
---|
312 | ENDIF |
---|
313 | ENDDO |
---|
314 | ENDDO |
---|
315 | |
---|
316 | IF( sec%listPoint(1)%I == endingPoint%I .AND. sec%listPoint(1)%J == endingPoint%J )THEN |
---|
317 | sec%listPoint(1) = POINT_SECTION(-1,-1) |
---|
318 | endingPoint = POINT_SECTION(-1,-1) |
---|
319 | coordFirst = coordSec(1) |
---|
320 | coordLast = coordSec(2) |
---|
321 | sec%nb_point = 0 |
---|
322 | ENDIF |
---|
323 | |
---|
324 | ELSE |
---|
325 | !If there is no intersection section/mesh |
---|
326 | sec%listPoint(1) = POINT_SECTION(-1,-1) |
---|
327 | endingPoint = POINT_SECTION(-1,-1) |
---|
328 | coordFirst = coordSec(1) |
---|
329 | coordLast = coordSec(2) |
---|
330 | sec%nb_point = 0 |
---|
331 | ENDIF |
---|
332 | |
---|
333 | !debug |
---|
334 | CALL write_debug(jsec,"extremities of section in the grid : ") |
---|
335 | ji=sec%listPoint(1)%I ; jj=sec%listPoint(1)%J |
---|
336 | IF( sec%nb_point .ne. 0 )THEN |
---|
337 | ji=sec%listPoint(1)%I ; jj=sec%listPoint(1)%J |
---|
338 | WRITE(cltmp,'(A15,X,i4.4,X,i4.4,X,f8.3,X,f8.3)')'First point: ',sec%listPoint(1),glamf(ji,jj),gphif(ji,jj) |
---|
339 | CALL write_debug(jsec,cltmp) |
---|
340 | ji=endingPoint%I ; jj=endingPoint%J |
---|
341 | WRITE(cltmp,'(A15,X,i4.4,X,i4.4,X,f8.3,X,f8.3)')'Last point: ',endingPoint,glamf(ji,jj),gphif(ji,jj) |
---|
342 | CALL write_debug(jsec,cltmp) |
---|
343 | ! |
---|
344 | coord_a=pointToCoordF(sec%listPoint(1)) ; coord_b=pointToCoordF(endingPoint) |
---|
345 | ll_test = .FALSE. |
---|
346 | IF ( ll_date_domain .AND. ABS( coord_a%lon - coord_b%lon ).GT. 180) ll_test= .TRUE. |
---|
347 | zdistante=distance2(coord_a,coord_b ,ll_test ) |
---|
348 | WRITE(cltmp,'(A20,f10.3)' )'distance between IJ-extremities : ',zdistante |
---|
349 | CALL write_debug(jsec,cltmp) |
---|
350 | ! |
---|
351 | CALL write_debug(jsec,"Initial extremities : ") |
---|
352 | WRITE(cltmp,'( 2(f9.3),A3,2(f9.3) )')coordFirst,'---',coordLast |
---|
353 | CALL write_debug(jsec,cltmp) |
---|
354 | ll_test = .FALSE. |
---|
355 | IF( ll_date_domain .AND. ABS(coordFirst%lon - coordLast%lon).GT. 180)ll_test= .TRUE. |
---|
356 | zdistante=distance2(coordFirst,coordLast,ll_test) |
---|
357 | WRITE(cltmp,'(A30,f10.3)')' distance between initial extremities : ',zdistante |
---|
358 | CALL write_debug(jsec,cltmp) |
---|
359 | CALL write_debug(jsec," ") |
---|
360 | ELSE |
---|
361 | WRITE(cltmp,'(A50)' )"no intersection between section and mesh" |
---|
362 | ENDIF |
---|
363 | |
---|
364 | !==========================================================! |
---|
365 | ! IV. Find the series of mesh points that form the section ! |
---|
366 | !==========================================================! |
---|
367 | CALL write_debug(jsec,"Find the serie of mesh's points that form the section") |
---|
368 | |
---|
369 | IF( sec%nb_point .ne. 0 )THEN |
---|
370 | |
---|
371 | !The series of mesh points that form the section will 'link' |
---|
372 | !sec%listPoint(1) to endingPoint: it will be stored in |
---|
373 | !sec%listPoint(jseg) |
---|
374 | ! |
---|
375 | !We take place on the first point (sec%listPoint(1)) |
---|
376 | ! a. We find the 4 adjacent points (North, South, East, West) |
---|
377 | ! b. Compute distance between current point and endingPoint |
---|
378 | ! c. Compute distance between the 4 adjacent points and endingPoint |
---|
379 | ! d. Select the points which are closer to end-point than current point |
---|
380 | ! e.1 If at least one point is selected, select the point which is closest to original section among selected points |
---|
381 | ! e.2 If no point is selected, select the point which is the closest to end-point |
---|
382 | ! f. save next point and direction of velocity. |
---|
383 | ! g. Save nextPoint and go to nextPoint |
---|
384 | ! |
---|
385 | !We get out of this loop if: |
---|
386 | ! - we are on endingPoint |
---|
387 | ! - the number of points (jseg) that link sec%listPoint(1) to endingPoint is |
---|
388 | ! twice greater than number of section/mesh intersection (nb_inmesh): |
---|
389 | ! it could be possible if thr algorithm can't link endingPoint (bug). |
---|
390 | |
---|
391 | !initialize distnew value (with distance between section's extremities) |
---|
392 | zdistnew = distance2(coordFirst,coordLast,sec%ll_date_line) |
---|
393 | prevPoint = POINT_SECTION(0,0) |
---|
394 | jseg = 1 |
---|
395 | |
---|
396 | DO WHILE ( ( sec%listPoint(jseg)%I .NE. endingPoint%I & |
---|
397 | .OR. sec%listPoint(jseg)%J .NE. endingPoint%J ) & |
---|
398 | .AND. jseg .LT. 500 .AND. sec%listPoint(jseg)%I .GT. 0 ) |
---|
399 | |
---|
400 | ! a. find the 4 adjacent points (North, South, East, West) |
---|
401 | !--------------------------------------------------------- |
---|
402 | SouthPoint = POINT_SECTION(sec%listPoint(jseg)%I,sec%listPoint(jseg)%J-1) |
---|
403 | NorthPoint = POINT_SECTION(sec%listPoint(jseg)%I,sec%listPoint(jseg)%J+1) |
---|
404 | WestPoint = POINT_SECTION(sec%listPoint(jseg)%I-1,sec%listPoint(jseg)%J) |
---|
405 | EstPoint = POINT_SECTION(sec%listPoint(jseg)%I+1,sec%listPoint(jseg)%J) |
---|
406 | |
---|
407 | !debug |
---|
408 | CALL write_debug(jsec,"---------------") |
---|
409 | WRITE(cltmp,100)'Current points: ',sec%listPoint(jseg), & |
---|
410 | glamf(sec%listPoint(jseg)%I,sec%listPoint(jseg)%J), & |
---|
411 | gphif(sec%listPoint(jseg)%I,sec%listPoint(jseg)%J) |
---|
412 | CALL write_debug(jsec,cltmp) |
---|
413 | CALL write_debug(jsec,"E/W/N/S points") |
---|
414 | WRITE(cltmp,102)EstPoint,WestPoint,NorthPoint,SouthPoint |
---|
415 | CALL write_debug(jsec,cltmp) |
---|
416 | itest=MIN(MAX(EstPoint%I,0),jpi+1) ; jtest=MIN(MAX(EstPoint%J,0),jpj+1) |
---|
417 | IF( itest .NE. 0 .AND. itest .NE. jpi+1 .AND. jtest .NE. 0 .AND. jtest .NE. jpj+1 )THEN |
---|
418 | WRITE(cltmp,101)'Est',glamf(itest,jtest),gphif(itest,jtest) |
---|
419 | CALL write_debug(jsec,cltmp) |
---|
420 | ELSE |
---|
421 | CALL write_debug(jsec,"Est point out of domain") |
---|
422 | ENDIF |
---|
423 | ! |
---|
424 | itest=MIN(MAX(WestPoint%I,0),jpi+1) ; jtest=MIN(MAX(WestPoint%J,0),jpj+1) |
---|
425 | IF( itest .NE. 0 .AND. itest .NE. jpi+1 .AND. jtest .NE. 0 .AND. jtest .NE. jpj+1 )THEN |
---|
426 | WRITE(cltmp,101)'West',glamf(itest,jtest),gphif(itest,jtest) |
---|
427 | CALL write_debug(jsec,cltmp) |
---|
428 | ELSE |
---|
429 | CALL write_debug(jsec,"West point out of domain") |
---|
430 | ENDIF |
---|
431 | ! |
---|
432 | itest=MIN(MAX(NorthPoint%I,0),jpi+1) ; jtest=MIN(MAX(NorthPoint%J,0),jpj+1) |
---|
433 | IF( itest .NE. 0 .AND. itest .NE. jpi+1 .AND. jtest .NE. 0 .AND. jtest .NE. jpj+1 )THEN |
---|
434 | WRITE(cltmp,101)'North',glamf(itest,jtest),gphif(itest,jtest) |
---|
435 | CALL write_debug(jsec,cltmp) |
---|
436 | ELSE |
---|
437 | CALL write_debug(jsec,"North point out of domain") |
---|
438 | ENDIF |
---|
439 | ! |
---|
440 | itest=MIN(MAX(SouthPoint%I,0),jpi+1) ; jtest=MIN(MAX(SouthPoint%J,0),jpj+1) |
---|
441 | IF( itest .NE. 0 .AND. itest .NE. jpi+1 .AND. jtest .NE. 0 .AND. jtest .NE. jpj+1 )THEN |
---|
442 | WRITE(cltmp,101)'South',glamf(itest,jtest),gphif(itest,jtest) |
---|
443 | CALL write_debug(jsec,cltmp) |
---|
444 | ELSE |
---|
445 | CALL write_debug(jsec,"South point out of domain") |
---|
446 | ENDIF |
---|
447 | ! |
---|
448 | ! |
---|
449 | 100 FORMAT ( A15,2(i4.4," "),2(f8.3," ") ) |
---|
450 | 101 FORMAT ( A6,2(f7.3," ")) |
---|
451 | 102 FORMAT ( "E ",i4.4,' ',i4.4,"//W ",i4.4,' ',i4.4,"//N ",i4.4,' ',i4.4,"//S ",i4.4,' ',i4.4 ) |
---|
452 | |
---|
453 | |
---|
454 | !Either we are at an end-point |
---|
455 | !-------------------- |
---|
456 | IF( SouthPoint%I==endingPoint%I .AND. SouthPoint%J==endingPoint%J )THEN |
---|
457 | jseg = jseg+1 ; sec%listPoint(jseg) = SouthPoint |
---|
458 | ELSE IF( NorthPoint%I==endingPoint%I .AND. NorthPoint%J==endingPoint%J )THEN |
---|
459 | jseg = jseg+1 ; sec%listPoint(jseg) = NorthPoint |
---|
460 | ELSE IF( WestPoint%I==endingPoint%I .AND. WestPoint%J==endingPoint%J )THEN |
---|
461 | jseg = jseg+1 ; sec%listPoint(jseg) = WestPoint |
---|
462 | ELSE IF( EstPoint%I==endingPoint%I .AND. EstPoint%J==endingPoint%J )THEN |
---|
463 | jseg = jseg+1 ; sec%listPoint(jseg) = EstPoint |
---|
464 | |
---|
465 | ELSE |
---|
466 | !Else we are NOT on end-point |
---|
467 | !------------------------ |
---|
468 | |
---|
469 | ! b. distance between current point and endingPoint |
---|
470 | !-------------------------------------------------- |
---|
471 | zdistante = zdistnew |
---|
472 | |
---|
473 | ! c. compute distance between the 4 adjacent points and endingPoint |
---|
474 | !------------------------------------------------------------------ |
---|
475 | ! BE CAREFUL! When the domain crosses the date line (ll_date_domain): |
---|
476 | ! When we will compute distances between W/E/S/N points and endingPoint, |
---|
477 | ! we have to check if theses 4 lines crosses the date line |
---|
478 | ! (test: ABS(coordTemp%lon - coordLast%lon).GT. 180) |
---|
479 | ! If it's true,we have to add 360° to coordLast%long to compute the |
---|
480 | ! correct distance through the date line and not through the complementary |
---|
481 | ! in the mesh. |
---|
482 | |
---|
483 | ! c.1 compute distWest: distance between west point and endingPoint |
---|
484 | !---------------------- |
---|
485 | zdistWest2 = 99999999.9 ; zdistWest3 = 99999999.9 |
---|
486 | IF( sec%listPoint(jseg)%I .NE. 1 )THEN |
---|
487 | !When we are on the west side of the mesh (i=1),we can't go to the west. |
---|
488 | coordTemp = pointToCoordF(WestPoint) |
---|
489 | ll_test = .FALSE. |
---|
490 | IF( ll_date_domain .AND. ABS(coordTemp%lon - coordLast%lon).GT. 180 )ll_test = .TRUE. |
---|
491 | zdistWest2 = distance2(pointToCoordF(WestPoint) ,coordLast ,ll_test) |
---|
492 | ENDIF |
---|
493 | |
---|
494 | ! c.2 compute distEst: distance between east point and endingPoint |
---|
495 | !--------------------- |
---|
496 | zdistEst2 = 99999999.9 ; zdistEst3 = 99999999.9 |
---|
497 | IF( sec%listPoint(jseg)%I .EQ. jpi )THEN |
---|
498 | !We test if the current point is on the east side of the mesh |
---|
499 | ! The method is done such that we go toward east to link |
---|
500 | ! sec%listPoint(1) to endingPoint. |
---|
501 | ! So, if the section crosses the overlapping band (ll_overlap_sec=T), |
---|
502 | ! we won't have to stop if the current point is on the EAST side of the mesh: |
---|
503 | ! we have to follow the construction of the section on the |
---|
504 | ! WEST side of the mesh |
---|
505 | IF( ll_overlap_sec )THEN |
---|
506 | !section crosses the overlapping band |
---|
507 | !So EastPoint is on the west side of the mesh |
---|
508 | EstPoint = POINT_SECTION(3,sec%listPoint(jseg)%J) |
---|
509 | zdistEst2= distance2(pointToCoordF(EstPoint) ,coordLast ,.FALSE.) |
---|
510 | ENDIF |
---|
511 | ELSE |
---|
512 | coordTemp = pointToCoordF(EstPoint) |
---|
513 | ll_test = .FALSE. |
---|
514 | IF( ll_date_domain .AND. ABS(coordTemp%lon - coordLast%lon).GT. 180 )ll_test= .TRUE. |
---|
515 | zdistEst2 = distance2(pointToCoordF(EstPoint) ,coordLast ,ll_test ) |
---|
516 | ENDIF |
---|
517 | |
---|
518 | ! c.3 compute distSouth: distance between south point and endingPoint |
---|
519 | !----------------------- |
---|
520 | zdistSouth2 = 99999999.9 ; zdistSouth3 = 99999999.9 |
---|
521 | IF( sec%listPoint(jseg)%J .NE. 1 )THEN |
---|
522 | !When we are on the south side of the mesh (j=1),we can't go to the south. |
---|
523 | coordTemp=pointToCoordF(SouthPoint) |
---|
524 | ll_test = .FALSE. |
---|
525 | IF( ll_date_domain .AND. ABS(coordTemp%lon - coordLast%lon).GT. 180 )ll_test= .TRUE. |
---|
526 | zdistSouth2 = distance2(pointToCoordF(SouthPoint),coordlast ,ll_test ) |
---|
527 | ENDIF |
---|
528 | |
---|
529 | ! c.4 compute distNorth: distance between north and endingPoint |
---|
530 | !----------------------- |
---|
531 | zdistNorth2 = 99999999.9 ; zdistNorth3 = 99999999.9 |
---|
532 | IF( sec%listPoint(jseg)%J .NE. jpj )THEN |
---|
533 | !When we are on the north side of the mesh (j=jpj),we can't go to the south. |
---|
534 | coordTemp=pointToCoordF(NorthPoint) |
---|
535 | ll_test = .FALSE. |
---|
536 | IF( ll_date_domain .AND. ABS(coordTemp%lon - coordLast%lon).GT. 180 )ll_test= .TRUE. |
---|
537 | zdistNorth2 = distance2(pointToCoordF(NorthPoint),coordlast ,ll_test ) |
---|
538 | ENDIF |
---|
539 | |
---|
540 | ! d. select the points which are closer to end-point than current point |
---|
541 | !---------------------------------------------------------------------- |
---|
542 | zdistref=distance2(pointToCoordF(sec%listPoint(jseg)),coordlast ,ll_test ) |
---|
543 | WRITE(cltmp,'( A56,f10.3 )' )'distance between actual point and last point: zdistref = ',zdistref |
---|
544 | CALL write_debug(jsec,cltmp) |
---|
545 | lest = .FALSE. ; IF( zdistEst2 .LE. zdistref ) lest = .TRUE. |
---|
546 | lwest = .FALSE. ; IF( zdistwest2 .LE. zdistref ) lwest = .TRUE. |
---|
547 | lnorth = .FALSE. ; IF( zdistnorth2 .LE. zdistref ) lnorth= .TRUE. |
---|
548 | lsouth = .FALSE. ; IF( zdistsouth2 .LE. zdistref ) lsouth= .TRUE. |
---|
549 | |
---|
550 | !debug |
---|
551 | IF( .NOT. lest )CALL write_debug(jsec,'Est point eliminated') |
---|
552 | IF( .NOT. lwest )CALL write_debug(jsec,'West point eliminated') |
---|
553 | IF( .NOT. lnorth )CALL write_debug(jsec,'North point eliminated') |
---|
554 | IF( .NOT. lsouth )CALL write_debug(jsec,'South point eliminated') |
---|
555 | |
---|
556 | l_oldmethod = .FALSE. |
---|
557 | |
---|
558 | IF( ( COUNT((/lest/))+COUNT((/lwest/))+COUNT((/lnorth/))+COUNT((/lsouth/)) ) .NE. 0 )THEN |
---|
559 | |
---|
560 | ! e.1 If at least one point is selected, select the point |
---|
561 | ! which is the closest to original section among selected points |
---|
562 | !------------------------------------------------------------------- |
---|
563 | |
---|
564 | zdistWest3 = 9999999.9 |
---|
565 | IF( lwest )zdistWest3 = & |
---|
566 | distance3(pointToCoordF(sec%listPoint(1)),pointToCoordF(WestPoint) ,pointToCoordF(endingPoint) ,lkdebug ) |
---|
567 | zdistEst3 = 9999999.9 |
---|
568 | IF( lest )zdistEst3 = & |
---|
569 | distance3(pointToCoordF(sec%listPoint(1)),pointToCoordF(EstPoint) ,pointToCoordF(endingPoint) ,lkdebug ) |
---|
570 | zdistSouth3 = 9999999.9 |
---|
571 | IF( lsouth )zdistSouth3 = & |
---|
572 | distance3(pointToCoordF(sec%listPoint(1)),pointToCoordF(SouthPoint),pointToCoordF(endingPoint) ,lkdebug ) |
---|
573 | zdistNorth3 = 9999999.9 |
---|
574 | IF( lnorth )zdistNorth3 = & |
---|
575 | distance3(pointToCoordF(sec%listPoint(1)),pointToCoordF(NorthPoint),pointToCoordF(endingPoint) ,lkdebug ) |
---|
576 | |
---|
577 | zdistEst3 = zdistEst3 + (1-COUNT((/lest/)) )*9999999.9 |
---|
578 | zdistWest3 = zdistWest3 + (1-COUNT((/lwest/)) )*9999999.9 |
---|
579 | zdistNorth3 = zdistNorth3 + (1-COUNT((/lnorth/)))*9999999.9 |
---|
580 | zdistSouth3 = zdistSouth3 + (1-COUNT((/lsouth/)))*9999999.9 |
---|
581 | |
---|
582 | zdistnew = MIN(zdistEst3,zdistWest3,zdistnorth3,zdistSouth3) |
---|
583 | |
---|
584 | ELSE |
---|
585 | |
---|
586 | ! e.2 If no point is selected, select the point which is the closest to end-point |
---|
587 | !-------------------------------------------------------------------------------- |
---|
588 | l_oldmethod = .TRUE. |
---|
589 | |
---|
590 | !debug |
---|
591 | WRITE(cltmp,'(A30,i3.3)' )'SEARCH NEW POINT WITH OLD METHOD: ',jsec |
---|
592 | CALL write_debug(jsec,cltmp) |
---|
593 | |
---|
594 | !be careful! we can't go backward. |
---|
595 | zdistNorth = zdistNorth2 ; zdistSouth = zdistSouth2 |
---|
596 | zdistEst = zdistEst2 ; zdistWest = zdistWest2 |
---|
597 | |
---|
598 | IF( prevPoint%I .EQ. NorthPoint%I .AND. prevPoint%J .EQ. NorthPoint%J) THEN |
---|
599 | zdistnew = MIN(zdistEst,zdistWest,zdistSouth) |
---|
600 | ELSE IF(prevPoint%I .EQ. SouthPoint%I .AND. prevPoint%J .EQ. SouthPoint%J) THEN |
---|
601 | zdistnew = MIN(zdistEst,zdistWest,zdistNorth) |
---|
602 | ELSE IF(prevPoint%I .EQ. WestPoint%I .AND. prevPoint%J .EQ. WestPoint%J ) THEN |
---|
603 | zdistnew = MIN(zdistEst,zdistNorth,zdistSouth) |
---|
604 | ELSE IF(prevPoint%I .EQ. EstPoint%I .AND. prevPoint%J .EQ. EstPoint%J ) THEN |
---|
605 | zdistnew = MIN(zdistWest,zdistNorth,zdistSouth) |
---|
606 | ELSE |
---|
607 | zdistnew = MIN(zdistEst,zdistWest,zdistNorth,zdistSouth) |
---|
608 | ENDIF |
---|
609 | |
---|
610 | ENDIF |
---|
611 | |
---|
612 | !debug |
---|
613 | WRITE(cltmp,'(A11, f8.3)')'zdistref = ',zdistref |
---|
614 | CALL write_debug(jsec,cltmp) |
---|
615 | WRITE(cltmp, 103 )'distance2 :',zdistEst2,zdistWest2,zdistNorth2,zdistSouth2 |
---|
616 | CALL write_debug(jsec,cltmp) |
---|
617 | WRITE(cltmp, 103 )'distance3 :',zdistEst3,zdistWest3,zdistNorth3,zdistSouth3 |
---|
618 | CALL write_debug(jsec,cltmp) |
---|
619 | WRITE(cltmp,'(A11, f8.3)')"zdistnew = ",zdistnew |
---|
620 | CALL write_debug(jsec,cltmp) |
---|
621 | |
---|
622 | 103 FORMAT (A12,"E",f12.3," W",f12.3," N",f12.3," S",f12.3) |
---|
623 | |
---|
624 | !f. save next point and direction of velocity. |
---|
625 | !--------------------------------------------- |
---|
626 | !nextPoint will be the one which is the closest to endingPoint. |
---|
627 | !sec%direction will be direction between current point and nextPoint: |
---|
628 | !It will be used to compute velocity through the segment [CurrentPoint,nextPoint}: |
---|
629 | ! |
---|
630 | !A:Current Point NorthPoint(I,J+1) Nextpoint=NorthPoint(I,J+1) => sec%direction=3 |
---|
631 | ! | Nextpoint=SouthPoint(I,J-1) => sec%direction=2 |
---|
632 | ! | Nextpoint=WestPoint(I-1,J) => sec%direction=0 |
---|
633 | ! |==>V(I,J+1) Nextpoint=EastPoint(I+1,J) => sec%direction=1 |
---|
634 | ! U(I,J) | U(I+1,J) |
---|
635 | ! ^ | ^ |
---|
636 | ! West_____|______A_______|_____EstPoint |
---|
637 | ! Point |(I,J) (I+1,J) |
---|
638 | ! (I-1,J) | |
---|
639 | ! |==>V(I,J) |
---|
640 | ! | |
---|
641 | ! SoutPoint(I,J-1) |
---|
642 | IF( l_oldmethod )THEN |
---|
643 | IF( zdistnew == zdistWest ) THEN |
---|
644 | sec%direction(jseg)=0 ; nextPoint = WestPoint |
---|
645 | ELSE IF( zdistnew == zdistEst ) THEN |
---|
646 | sec%direction(jseg)=1 ; nextPoint = EstPoint |
---|
647 | ELSE IF( zdistnew == zdistSouth )THEN |
---|
648 | sec%direction(jseg)=2 ; nextPoint = SouthPoint |
---|
649 | ELSE IF( zdistnew == zdistNorth )THEN |
---|
650 | sec%direction(jseg)=3 ; nextPoint= NorthPoint |
---|
651 | ENDIF |
---|
652 | ELSE |
---|
653 | IF( zdistnew == zdistWest3 ) THEN |
---|
654 | sec%direction(jseg)=0 ; nextPoint = WestPoint |
---|
655 | ELSE IF( zdistnew == zdistEst3 ) THEN |
---|
656 | sec%direction(jseg)=1 ; nextPoint = EstPoint |
---|
657 | ELSE IF( zdistnew == zdistSouth3 )THEN |
---|
658 | sec%direction(jseg)=2 ; nextPoint = SouthPoint |
---|
659 | ELSE IF( zdistnew == zdistNorth3 )THEN |
---|
660 | sec%direction(jseg)=3 ; nextPoint= NorthPoint |
---|
661 | ENDIF |
---|
662 | ENDIF |
---|
663 | |
---|
664 | WRITE(cltmp,'(A11, 2(i4.4,1X) )')'nextPoint = ', nextPoint |
---|
665 | CALL write_debug(jsec,cltmp) |
---|
666 | |
---|
667 | !f. Save nextPoint and go to nextPoint |
---|
668 | !------------------------------------- |
---|
669 | prevPoint = sec%listPoint(jseg) |
---|
670 | jseg = jseg+1 !increment of number of segments that form the section |
---|
671 | sec%listPoint(jseg) = nextPoint !Save next point |
---|
672 | |
---|
673 | ENDIF ! southP/northP/WestP/EstP == endingpoint ? |
---|
674 | |
---|
675 | ENDDO !End of loop on jseg |
---|
676 | sec%nb_point = jseg !Save the number of segments that form the section |
---|
677 | |
---|
678 | |
---|
679 | ELSE ! isec%nb_point == 0 |
---|
680 | DO jseg=1,nb_point_max |
---|
681 | sec%listPoint(:)=POINT_SECTION(0,0) |
---|
682 | ENDDO |
---|
683 | sec%direction(:)=0. |
---|
684 | sec%nb_point = 0 |
---|
685 | ENDIF |
---|
686 | |
---|
687 | !debug |
---|
688 | IF( sec%nb_point .ne. 0 )THEN |
---|
689 | CALL write_debug(jsec,"-------------------------------------") |
---|
690 | CALL write_debug(jsec,"list of points in the grid : ") |
---|
691 | DO jseg=1,sec%nb_point |
---|
692 | ji=sec%listPoint(jseg)%I ; jj=sec%listPoint(jseg)%J |
---|
693 | WRITE(cltmp, '(i4.4,X,i4.4,X,i4.4,X,f8.3,X,f8.3)' )jseg,ji,jj,glamf(ji,jj),gphif(ji,jj) |
---|
694 | CALL write_debug(jsec,cltmp) |
---|
695 | ENDDO |
---|
696 | |
---|
697 | !test if we are an end-point |
---|
698 | IF( sec%listPoint(sec%nb_point)%I .NE. endingPoint%J .AND. sec%listPoint(sec%nb_point)%J .NE. endingPoint%J )THEN |
---|
699 | PRINT*,TRIM(sec%name)," NOT ARRIVED TO endingPoint FOR jsec = ",jsec |
---|
700 | ENDIF |
---|
701 | ENDIF |
---|
702 | |
---|
703 | !now compute new slopeSection with ij-coordinates of first and last point |
---|
704 | sec%slopeSection = 0 ! default value |
---|
705 | IF( sec%nb_point .ne. 0 )THEN |
---|
706 | IF ( sec%listPoint(sec%nb_point)%I .NE. sec%listPoint(1)%I ) THEN |
---|
707 | sec%slopeSection = ( sec%listPoint(sec%nb_point)%J - sec%listPoint(1)%J ) / & |
---|
708 | ( sec%listPoint(sec%nb_point)%I - sec%listPoint(1)%I ) |
---|
709 | ELSE |
---|
710 | sec%slopeSection = 10000._wp |
---|
711 | ENDIF |
---|
712 | ENDIF |
---|
713 | |
---|
714 | END SUBROUTINE compsec |
---|
715 | |
---|
716 | END MODULE compute_sections |
---|