3 ims, ime, jms, jme, icmask , &
4 its, ite, jts, jte, nf, xstag, ystag )
6 INTEGER ims, ime, jms, jme, &
9 LOGICAL icmask( ims:ime, jms:jme )
14 PARAMETER(one12=1./12.,one24=1./24.)
17 REAL XF(ims:ime,jms:jme,NF)
19 REAL Y(ims:ime,jms:jme,-IOR:IOR), &
20 Z(ims:ime,jms:jme,-IOR:IOR), &
21 F(ims:ime,jms:jme,0:1)
24 INTEGER N2STAR, N2END, N1STAR, N1END
28 REAL W(ims:ime,jms:jme),OV(ims:ime,jms:jme),UN(ims:ime,jms:jme)
29 REAL MXM(ims:ime,jms:jme),MN(ims:ime,jms:jme)
30 REAL FL(ims:ime,jms:jme,0:1)
31 REAL XIG(NF*NF), XJG(NF*NF) ! NF is parent to child grid refinement ratio
37 DONOR(Y1,Y2,A)=(Y1*AMAX1(0.,SIGN(1.,A))-Y2*AMIN1(0.,SIGN(1.,A)))*A
38 REAL tr4, ym1, y0, yp1, yp2
39 TR4(YM1,Y0,YP1,YP2,A)=A*ONE12*(7.*(YP1+Y0)-(YP2+YM1)) &
40 -A*A*ONE24*(15.*(YP1-Y0)-(YP2-YM1))-A*A*A*ONE12*((YP1+Y0) &
41 -(YP2+YM1))+A*A*A*A*ONE24*(3.*(YP1-Y0)-(YP2-YM1))
46 rr = nint(sqrt(float(nf)))
47 !! write(6,*) ' nf, rr are ',nf,rr
51 if(xstag .and. (mod(rr,2) .eq. 0)) rioff = 1.
52 if(ystag .and. (mod(rr,2) .eq. 0)) rjoff = 1.
56 XIG(J+(I-1)*rr)=(float(rr)-1.-rioff)/float(2*rr)-FLOAT(J-1)*1./float(rr)
57 XJG(J+(I-1)*rr)=(float(rr)-1.-rjoff)/float(2*rr)-FLOAT(I-1)*1./float(rr)
68 ! HERE STARTS RESIDUAL ADVECTION
70 DO 9000 JJ=N2STAR,N2END
74 DO 511 II=N1STAR,N1END
75 IF ( icmask(II,JJ) ) Y(II,JJ,I)=XF(II+I,JJ+J,IIM)
79 DO 811 II=N1STAR,N1END
80 IF ( icmask(II,JJ) ) THEN
81 FL(II,JJ,0)=DONOR(Y(II,JJ,-1),Y(II,JJ,0),XIG(IIM))
82 FL(II,JJ,1)=DONOR(Y(II,JJ,0),Y(II,JJ,1),XIG(IIM))
85 DO 812 II=N1STAR,N1END
86 IF ( icmask(II,JJ) ) W(II,JJ)=Y(II,JJ,0)-(FL(II,JJ,1)-FL(II,JJ,0))
88 DO 813 II=N1STAR,N1END
89 IF ( icmask(II,JJ) ) THEN
91 AMAX1(Y(II,JJ,-1),Y(II,JJ,0),Y(II,JJ,1), &
93 MN(II,JJ)=AMIN1(Y(II,JJ,-1),Y(II,JJ,0),Y(II,JJ,1),W(II,JJ))
96 DO 312 II=N1STAR,N1END
97 IF ( icmask(II,JJ) ) THEN
99 TR4(Y(II,JJ,-2),Y(II,JJ,-1),Y(II,JJ,0), &
102 TR4(Y(II,JJ,-1),Y(II,JJ,0),Y(II,JJ,1),Y(II,JJ,2),&
106 DO 822 II=N1STAR,N1END
107 IF ( icmask(II,JJ) ) THEN
108 F(II,JJ,0)=F(II,JJ,0)-FL(II,JJ,0)
109 F(II,JJ,1)=F(II,JJ,1)-FL(II,JJ,1)
112 DO 823 II=N1STAR,N1END
113 IF ( icmask(II,JJ) ) THEN
114 OV(II,JJ)=(MXM(II,JJ)-W(II,JJ))/(-PN(F(II,JJ,1))+ &
116 UN(II,JJ)=(W(II,JJ)-MN(II,JJ))/(PP(F(II,JJ,1))- &
120 DO 824 II=N1STAR,N1END
121 IF ( icmask(II,JJ) ) THEN
122 F(II,JJ,0)=PP(F(II,JJ,0))*AMIN1(1.,OV(II,JJ))+ &
123 PN(F(II,JJ,0))*AMIN1(1.,UN(II,JJ))
124 F(II,JJ,1)=PP(F(II,JJ,1))*AMIN1(1.,UN(II,JJ))+ &
125 PN(F(II,JJ,1))*AMIN1(1.,OV(II,JJ))
128 DO 825 II=N1STAR,N1END
129 IF ( icmask(II,JJ) ) THEN
130 Y(II,JJ,0)=W(II,JJ)-(F(II,JJ,1)-F(II,JJ,0))
133 DO 361 II=N1STAR,N1END
134 IF ( icmask(II,JJ) ) Z(II,JJ,J)=Y(II,JJ,0)
137 ! END IF FIRST J LOOP
142 DO 911 II=N1STAR,N1END
143 IF ( icmask(II,JJ) ) THEN
144 FL(II,JJ,0)=DONOR(Z(II,JJ,-1),Z(II,JJ,0),XJG(IIM))
145 FL(II,JJ,1)=DONOR(Z(II,JJ,0),Z(II,JJ,1),XJG(IIM))
148 DO 912 II=N1STAR,N1END
149 IF ( icmask(II,JJ) ) W(II,JJ)=Z(II,JJ,0)-(FL(II,JJ,1)-FL(II,JJ,0))
151 DO 913 II=N1STAR,N1END
152 IF ( icmask(II,JJ) ) THEN
153 MXM(II,JJ)=AMAX1(Z(II,JJ,-1),Z(II,JJ,0),Z(II,JJ,1),W(II,JJ))
154 MN(II,JJ)=AMIN1(Z(II,JJ,-1),Z(II,JJ,0),Z(II,JJ,1),W(II,JJ))
157 DO 412 II=N1STAR,N1END
158 IF ( icmask(II,JJ) ) THEN
160 TR4(Z(II,JJ,-2),Z(II,JJ,-1),Z(II,JJ,0),Z(II,JJ,1)&
163 TR4(Z(II,JJ,-1),Z(II,JJ,0),Z(II,JJ,1),Z(II,JJ,2), &
167 DO 922 II=N1STAR,N1END
168 IF ( icmask(II,JJ) ) THEN
169 F(II,JJ,0)=F(II,JJ,0)-FL(II,JJ,0)
170 F(II,JJ,1)=F(II,JJ,1)-FL(II,JJ,1)
173 DO 923 II=N1STAR,N1END
174 IF ( icmask(II,JJ) ) THEN
175 OV(II,JJ)=(MXM(II,JJ)-W(II,JJ))/(-PN(F(II,JJ,1))+ &
177 UN(II,JJ)=(W(II,JJ)-MN(II,JJ))/(PP(F(II,JJ,1))-PN(F(II,JJ,0))+ &
181 DO 924 II=N1STAR,N1END
182 IF ( icmask(II,JJ) ) THEN
183 F(II,JJ,0)=PP(F(II,JJ,0))*AMIN1(1.,OV(II,JJ))+PN(F(II,JJ,0)) &
185 F(II,JJ,1)=PP(F(II,JJ,1))*AMIN1(1.,UN(II,JJ))+PN(F(II,JJ,1)) &
190 DO 925 JJ=N2STAR,N2END
191 DO 925 II=N1STAR,N1END
192 IF ( icmask(II,JJ) ) XF(II,JJ,IIM)=W(II,JJ)-(F(II,JJ,1)-F(II,JJ,0))
200 ! Version of sint that replaces mask with detailed ranges for avoiding boundaries
201 ! may help performance by getting the conditionals out of innner loops
203 SUBROUTINE SINTB(XF1, XF , &
204 ims, ime, jms, jme, icmask , &
205 its, ite, jts, jte, nf, xstag, ystag )
207 INTEGER ims, ime, jms, jme, &
210 LOGICAL icmask( ims:ime, jms:jme )
214 REAL one12, one24, ep
215 PARAMETER(one12=1./12.,one24=1./24.)
218 REAL XF(ims:ime,jms:jme,NF)
219 REAL XF1(ims:ime,jms:jme,NF)
222 Z(ims:ime,-IOR:IOR), &
225 INTEGER I,J,II,JJ,IIM
226 INTEGER N2STAR, N2END, N1STAR, N1END
231 ! PARAMETER(N1OS=N1*NONOS+1-NONOS,N2OS=N2*NONOS+1-NONOS)
236 REAL XIG(NF*NF), XJG(NF*NF) ! NF is the parent to child grid refinement ratio
241 REAL donor, y1, y2, a
242 DONOR(Y1,Y2,A)=(Y1*AMAX1(0.,SIGN(1.,A))-Y2*AMIN1(0.,SIGN(1.,A)))*A
243 REAL tr4, ym1, y0, yp1, yp2
244 TR4(YM1,Y0,YP1,YP2,A)=A*ONE12*(7.*(YP1+Y0)-(YP2+YM1)) &
245 -A*A*ONE24*(15.*(YP1-Y0)-(YP2-YM1))-A*A*A*ONE12*((YP1+Y0) &
246 -(YP2+YM1))+A*A*A*A*ONE24*(3.*(YP1-Y0)-(YP2-YM1))
251 rr = nint(sqrt(float(nf)))
255 if(xstag .and. (mod(rr,2) .eq. 0)) rioff = 1.
256 if(ystag .and. (mod(rr,2) .eq. 0)) rjoff = 1.
260 XIG(J+(I-1)*rr)=(float(rr)-1.-rioff)/float(2*rr)-FLOAT(J-1)*1./float(rr)
261 XJG(J+(I-1)*rr)=(float(rr)-1.-rjoff)/float(2*rr)-FLOAT(I-1)*1./float(rr)
272 ! HERE STARTS RESIDUAL ADVECTION
274 DO 9000 JJ=N2STAR,N2END
279 DO 511 II=N1STAR,N1END
280 Y(-2)=XF1(II-2,JJ+J,IIM)
281 Y(-1)=XF1(II-1,JJ+J,IIM)
282 Y(0)=XF1(II,JJ+J,IIM)
283 Y(1)=XF1(II+1,JJ+J,IIM)
284 Y(2)=XF1(II+2,JJ+J,IIM)
286 FL(0)=DONOR(Y(-1),Y(0),XIG(IIM))
287 FL(1)=DONOR(Y(0),Y(1),XIG(IIM))
290 AMAX1(Y(-1),Y(0),Y(1), &
292 MN=AMIN1(Y(-1),Y(0),Y(1),W)
294 TR4(Y(-2),Y(-1),Y(0), &
297 TR4(Y(-1),Y(0),Y(1),Y(2),&
301 OV=(MXM-W)/(-PN(F(1))+ &
303 UN=(W-MN)/(PP(F(1))- &
305 F(0)=PP(F(0))*AMIN1(1.,OV)+ &
306 PN(F(0))*AMIN1(1.,UN)
307 F(1)=PP(F(1))*AMIN1(1.,UN)+ &
308 PN(F(1))*AMIN1(1.,OV)
313 ! END IF FIRST J LOOP
318 DO 911 II=N1STAR,N1END
319 FL(0)=DONOR(Z(II,-1),Z(II,0),XJG(IIM))
320 FL(1)=DONOR(Z(II,0),Z(II,1),XJG(IIM))
321 W=Z(II,0)-(FL(1)-FL(0))
322 MXM=AMAX1(Z(II,-1),Z(II,0),Z(II,1),W)
323 MN=AMIN1(Z(II,-1),Z(II,0),Z(II,1),W)
325 TR4(Z(II,-2),Z(II,-1),Z(II,0),Z(II,1)&
328 TR4(Z(II,-1),Z(II,0),Z(II,1),Z(II,2), &
332 OV=(MXM-W)/(-PN(F(1))+ &
334 UN=(W-MN)/(PP(F(1))-PN(F(0))+ &
336 F(0)=PP(F(0))*AMIN1(1.,OV)+PN(F(0)) &
338 F(1)=PP(F(1))*AMIN1(1.,UN)+PN(F(1)) &
340 XF(II,JJ,IIM)=W-(F(1)-F(0))