1 | SUBROUTINE qgrho (prho, kto, kwg, |
---|
2 | $ px, py, |
---|
3 | $ px1, py1, kmsk1, kngx1, kngy1, |
---|
4 | $ psig, kvma1) |
---|
5 | C**** |
---|
6 | C ***************************** |
---|
7 | C * OASIS ROUTINE - LEVEL 3 * |
---|
8 | C * ------------- ------- * |
---|
9 | C ***************************** |
---|
10 | C |
---|
11 | C**** *qgrho* - Calculate weights and adresses at one location |
---|
12 | C |
---|
13 | C Purpose: |
---|
14 | C ------- |
---|
15 | C At one location xgr gives the kwg closest neighbours |
---|
16 | C adresses kto in grid 1 and their weight, which is function of |
---|
17 | C the distance and may be other grid dependant considerations. |
---|
18 | C |
---|
19 | C** Interface: |
---|
20 | C --------- |
---|
21 | C *CALL* *qgrho(prho, kto, kwg, |
---|
22 | C px, py, |
---|
23 | C px1, py1, kmsk1, kngx1, kngy1, |
---|
24 | C psig, kvma1)* |
---|
25 | C |
---|
26 | C Input: |
---|
27 | C ----- |
---|
28 | C kwg : maximum number of overlapped neighbors |
---|
29 | C px : longitude of the current point on target grid |
---|
30 | C py : latitude of the current point on source grid |
---|
31 | C px1 : longitudes for source grid (real 2D) |
---|
32 | C py1 : latitudes for source grid (real 2D) |
---|
33 | C kmsk1 : the mask for source grid (integer 2D) |
---|
34 | C kngx1 : number of longitudes for source grid |
---|
35 | C kngy1 : number of latitudes for source grid |
---|
36 | C kvma1 : the value of the mask for source grid |
---|
37 | C psig : variance of the gaussian |
---|
38 | C Output: |
---|
39 | C ------ |
---|
40 | C prho : the neighbors weights |
---|
41 | C kto : the neighbors adresses in the source grid |
---|
42 | C |
---|
43 | C Workspace: |
---|
44 | C --------- |
---|
45 | C None |
---|
46 | C |
---|
47 | C External: |
---|
48 | C -------- |
---|
49 | C qlsort, sqdis, qlins, qlgaus |
---|
50 | C |
---|
51 | C References: |
---|
52 | C ---------- |
---|
53 | C O. Thual, Simple ocean-atmosphere interpolation. |
---|
54 | C Part A: The method, EPICOA 0629 (1992) |
---|
55 | C Part B: Software implementation, EPICOA 0630 (1992) |
---|
56 | C See also OASIS manual (1995) |
---|
57 | C |
---|
58 | C History: |
---|
59 | C ------- |
---|
60 | C Version Programmer Date Description |
---|
61 | C ------- ---------- ---- ----------- |
---|
62 | C 1.1 O. Thual 93/04/15 created |
---|
63 | C 2.0 L. Terray 95/10/01 modified: new structure |
---|
64 | C |
---|
65 | C %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
66 | C |
---|
67 | C* ---------------------------- Include files --------------------------- |
---|
68 | C |
---|
69 | USE mod_kinds_oasis |
---|
70 | USE mod_unit |
---|
71 | C |
---|
72 | C* ---------------------------- Argument declarations ------------------- |
---|
73 | C |
---|
74 | REAL (kind=ip_realwp_p) px1(kngx1,kngy1), py1(kngx1,kngy1) |
---|
75 | REAL (kind=ip_realwp_p) prho(kwg) |
---|
76 | INTEGER (kind=ip_intwp_p) kmsk1(kngx1,kngy1) |
---|
77 | INTEGER (kind=ip_intwp_p) kto(kwg) |
---|
78 | C |
---|
79 | C* ---------------------------- Poema verses ---------------------------- |
---|
80 | C |
---|
81 | C %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
82 | C |
---|
83 | C* 1. Various initializations |
---|
84 | C ----------------------- |
---|
85 | C |
---|
86 | C* Value of the mask |
---|
87 | C |
---|
88 | ivma = kvma1 |
---|
89 | ing = kngx1 * kngy1 |
---|
90 | C |
---|
91 | C |
---|
92 | C* 2. Nearest neighbors search |
---|
93 | C ------------------------ |
---|
94 | C |
---|
95 | C* Checks |
---|
96 | C |
---|
97 | IF (kwg .GT. ing) THEN |
---|
98 | WRITE (UNIT = nulou,FMT = *) 'WARNING kwg = ',kwg, |
---|
99 | $ '.GT. kngx1*kngy1 = ',ing |
---|
100 | WRITE (UNIT = nulou,FMT = *) |
---|
101 | $ ' Number of searched neighbors greater ' |
---|
102 | WRITE (UNIT = nulou,FMT = *) |
---|
103 | $ ' than number of grid points ' |
---|
104 | iwg = ing |
---|
105 | WRITE (UNIT = nulou,FMT = *) 'We set iwg = ing = ',iwg |
---|
106 | ELSE |
---|
107 | iwg = kwg |
---|
108 | ENDIF |
---|
109 | C |
---|
110 | C |
---|
111 | C* Put first iwg unmasked points of source grid in kto and prho |
---|
112 | C |
---|
113 | iind = 0 |
---|
114 | DO 210 j2 = 1, kngy1 |
---|
115 | DO 220 j1 = 1, kngx1 |
---|
116 | IF (kmsk1(j1,j2) .NE. ivma) THEN |
---|
117 | iind = iind + 1 |
---|
118 | icum = (j2-1) * kngx1 + j1 |
---|
119 | prho(iind) = sqdis (px, py, px1(j1,j2), py1(j1,j2)) |
---|
120 | kto(iind) = icum |
---|
121 | i1t = j1 |
---|
122 | i2t = j2 |
---|
123 | IF (iind .EQ. iwg) GO TO 225 |
---|
124 | ENDIF |
---|
125 | 220 CONTINUE |
---|
126 | 210 CONTINUE |
---|
127 | 225 CONTINUE |
---|
128 | C |
---|
129 | C* Check |
---|
130 | C |
---|
131 | IF (iind .NE. iwg) THEN |
---|
132 | WRITE(UNIT = nulou,FMT = *) |
---|
133 | $ ' WARNING: iind.ne.iwg ===> ',iind, iwg |
---|
134 | WRITE(UNIT = nulou,FMT = *) |
---|
135 | $ ' ******* ===> Program must stop ' |
---|
136 | CALL HALTE ('STOP in qgrho') |
---|
137 | ENDIF |
---|
138 | C |
---|
139 | C* Sorting of these first iwg points |
---|
140 | C |
---|
141 | CALL qlsort (prho, kto, iwg) |
---|
142 | C |
---|
143 | C* Loop on the remaining points of source grid |
---|
144 | C |
---|
145 | IF (iwg .NE. ing) THEN |
---|
146 | C |
---|
147 | C* Loop over the remaining longitudes for latitude i2t on source grid |
---|
148 | C if necessary |
---|
149 | C |
---|
150 | IF (i1t .LT. kngx1) THEN |
---|
151 | DO 230 j1 = i1t+1, kngx1 |
---|
152 | IF (kmsk1(j1,i2t) .NE. ivma) THEN |
---|
153 | icum = (i2t-1) * kngx1 + j1 |
---|
154 | C |
---|
155 | C* Calculate distance between the current source grid point and |
---|
156 | C the given target grid point |
---|
157 | C |
---|
158 | zrnew = sqdis (px, py, px1(j1,i2t), py1(j1,i2t)) |
---|
159 | C |
---|
160 | C* Insert in list at the correct rank |
---|
161 | C |
---|
162 | CALL qlins (prho, kto, iwg, zrnew, icum) |
---|
163 | ENDIF |
---|
164 | 230 CONTINUE |
---|
165 | ENDIF |
---|
166 | C |
---|
167 | C* Loop over the remaining source grid points |
---|
168 | C |
---|
169 | DO 240 j2 = i2t+1, kngy1 |
---|
170 | DO 250 j1 = 1, kngx1 |
---|
171 | IF (kmsk1(j1,j2) .NE. ivma) THEN |
---|
172 | icum = (j2-1) * kngx1 + j1 |
---|
173 | C |
---|
174 | C* Calculate distance between the current source grid point and |
---|
175 | C the given target grid point |
---|
176 | C |
---|
177 | zrnew = sqdis (px, py, px1(j1,j2), py1(j1,j2)) |
---|
178 | C |
---|
179 | C* Insert in list at the correct rank |
---|
180 | C |
---|
181 | CALL qlins (prho, kto, iwg, zrnew, icum) |
---|
182 | ENDIF |
---|
183 | 250 CONTINUE |
---|
184 | 240 CONTINUE |
---|
185 | ENDIF |
---|
186 | C |
---|
187 | C |
---|
188 | C* 3. Weight function |
---|
189 | C --------------- |
---|
190 | C |
---|
191 | C* Gaussian value for the weight function |
---|
192 | C |
---|
193 | zsum = 0. |
---|
194 | DO 310 jwg = 1, iwg |
---|
195 | zr = qlgaus (prho(jwg), psig) |
---|
196 | zsum = zsum + zr |
---|
197 | prho(jwg) = zr |
---|
198 | 310 CONTINUE |
---|
199 | C |
---|
200 | C* Normalization |
---|
201 | C |
---|
202 | zthres = 1.e-6 |
---|
203 | C |
---|
204 | C* If under threshold |
---|
205 | C |
---|
206 | IF (zsum .LT. zthres) THEN |
---|
207 | WRITE(UNIT=nulou,FMT=*) 'Gaussian sum under threshold value' |
---|
208 | DO 320 jwg = 1, iwg |
---|
209 | prho(jwg) = 1. / float(iwg) |
---|
210 | 320 CONTINUE |
---|
211 | C |
---|
212 | ELSE |
---|
213 | C |
---|
214 | C* If above threshold |
---|
215 | C |
---|
216 | DO 330 jwg = 1, iwg |
---|
217 | prho(jwg) = prho(jwg) / zsum |
---|
218 | 330 CONTINUE |
---|
219 | ENDIF |
---|
220 | C |
---|
221 | C* End of routine |
---|
222 | C |
---|
223 | RETURN |
---|
224 | END |
---|