@@ -17,7 +17,7 @@ module horizontal_interpolate
1717 public :: xy_interp_init, xy_interp
1818
1919contains
20- subroutine xy_interp_init (im1 ,jm1 ,lon0 ,lat0 ,im2 ,jm2 ,weight_x ,weight_y )
20+ subroutine xy_interp_init (im1 ,jm1 ,lon0 ,lat0 ,im2 ,jm2 ,weight_x ,weight_y , use_flight_distance )
2121!- -----------------------------------------------------------------------------------------------------------
2222! This program computes weighting functions to map a variable of (im1,jm1) resolution to (im2,jm2) resolution
2323! weight_x(im2,im1) is the weighting function for zonal interpolation
@@ -28,6 +28,7 @@ subroutine xy_interp_init(im1,jm1,lon0,lat0,im2,jm2,weight_x,weight_y)
2828!- -----------------------------------------------------------------------------------------------------------
2929 implicit none
3030 integer , intent (in ) :: im1, jm1, im2, jm2
31+ logical , intent (in ) :: use_flight_distance ! .true. = flight distance, .false. = all mixing ratios
3132 real (r8 ), intent (in ) :: lon0(im1), lat0(jm1)
3233 real (r8 ), intent (out ) :: weight_x(im2,im1), weight_y(jm2,jm1)
3334
@@ -110,28 +111,40 @@ subroutine xy_interp_init(im1,jm1,lon0,lat0,im2,jm2,weight_x,weight_y)
110111! check if there is any overlap between the source grid and the target grid
111112! if no overlap, then weighting is zero
112113! there are three scenarios overlaps can take place
113- if ( (x1_west.ge. x2_west).and. (x1_east.le. x2_east) ) then
114+ if ( (x1_west>= x2_west).and. (x1_east<= x2_east) ) then
114115! case 1:
115116! x1_west x1_east
116117! |-------------------|
117118! |---------------------------------|
118119! x2_west x2_east
120+ if (use_flight_distance) then
121+ weight_x(i2,i1) = 1.0_r8
122+ else
119123 weight_x(i2,i1) = (x1_east- x1_west)/ (x2_east- x2_west)
120- elseif ( (x1_west.ge. x2_west).and. (x1_west.lt. x2_east) ) then
124+ endif
125+ elseif ( (x1_west>= x2_west).and. (x1_west< x2_east) ) then
121126! case 2:
122127! x1_west x1_east
123128! |--------------------------------|
124129! |---------------------------------|
125130! x2_west x2_east
131+ if (use_flight_distance) then
132+ weight_x(i2,i1) = (x2_east- x1_west)/ (x1_east- x1_west)
133+ else
126134 weight_x(i2,i1) = (x2_east- x1_west)/ (x2_east- x2_west)
127- elseif ( (x1_east> x2_west).and. (x1_east.le. x2_east) ) then
135+ endif
136+ elseif ( (x1_east> x2_west).and. (x1_east<= x2_east) ) then
128137! case 3:
129138! x1_west x1_east
130139! |--------------------------------|
131140! |---------------------------------|
132141! x2_west x2_east
142+ if (use_flight_distance) then
143+ weight_x(i2,i1) = (x1_east- x2_west)/ (x1_east- x1_west)
144+ else
133145 weight_x(i2,i1) = (x1_east- x2_west)/ (x2_east- x2_west)
134- elseif ( (x1_east.gt. x2_east).and. (x1_west.lt. x2_west) ) then
146+ endif
147+ elseif ( (x1_east> x2_east).and. (x1_west< x2_west) ) then
135148! case 4:
136149! x1_west x1_east
137150! |--------------------------------|
@@ -145,22 +158,30 @@ subroutine xy_interp_init(im1,jm1,lon0,lat0,im2,jm2,weight_x,weight_y)
145158
146159
147160! consider end points
148- if (slon1(im1+1 ).gt. slon2(im2+1 )) then
161+ if (slon1(im1+1 )> slon2(im2+1 )) then
149162! case 1:
150163! slon1(im1) slon1(im1+1) <--- end point
151164! |-------------------------|
152165! |----------------|......................|
153166! slon2(im2) slon2(im2+1) slon2(2) (note: slon2(im2+1) = slon2(1))
154- weight_x(1 ,im1)= weight_x(1 ,im1)+ (slon1(im1+1 )- slon2(im2+1 ))/ (slon2(2 )- slon2(1 ))
167+ if (use_flight_distance) then
168+ weight_x(1 ,im1)= weight_x(1 ,im1)+ (slon1(im1+1 )- slon2(im2+1 ))/ (slon1(im1+1 )- slon1(im1))
169+ else
170+ weight_x(1 ,im1)= weight_x(1 ,im1)+ (slon1(im1+1 )- slon2(im2+1 ))/ (slon2(2 )- slon2(1 ))
171+ endif
155172 endif
156173
157- if (slon1(im1+1 ).lt. slon2(im2+1 )) then
174+ if (slon1(im1+1 )< slon2(im2+1 )) then
158175! case 1:
159176! slon1(im1) slon1(im1+1) slon1(2) (note: slon1(im1+1) = slon1(1))
160177! |-------------------------|.............................|
161178! |-------------------------------|
162179! slon2(im2) slon2(im2+1) <--- end point
163- weight_x(im2,1 ) = weight_x(im2,1 )+ (slon2(1 )- slon1(1 ))/ (slon2(2 )- slon2(1 ))
180+ if (use_flight_distance) then
181+ weight_x(im2,1 ) = weight_x(im2,1 )+ (slon2(1 )- slon1(1 ))/ (slon1(2 )- slon1(1 ))
182+ else
183+ weight_x(im2,1 ) = weight_x(im2,1 )+ (slon2(1 )- slon1(1 ))/ (slon2(2 )- slon2(1 ))
184+ endif
164185 endif
165186
166187
@@ -181,34 +202,50 @@ subroutine xy_interp_init(im1,jm1,lon0,lat0,im2,jm2,weight_x,weight_y)
181202! there are three scenarios overlaps can take place
182203! note: there is Guassian weight to consider in the meridional direction!
183204
184- if ( (y1_south.ge. y2_south).and. (y1_north.le. y2_north) ) then
205+ if ( (y1_south>= y2_south).and. (y1_north<= y2_north) ) then
185206! case 1:
186207! y1_south y1_north
187208! |-------------------|
188209! |---------------------------------|
189210! y2_south y2_north
190- weight_y(j2,j1) = gw1(j1)/ gw2(j2)
191- elseif ( (y1_south.ge. y2_south).and. (y1_south.lt. y2_north) ) then
211+ if (use_flight_distance) then
212+ weight_y(j2,j1) = 1.0_r8
213+ else
214+ weight_y(j2,j1) = gw1(j1)/ gw2(j2)
215+ endif
216+ elseif ( (y1_south>= y2_south).and. (y1_south< y2_north) ) then
192217! case 2:
193218! y1_south y1_north
194219! |--------------------------------|
195220! |---------------------------------|
196221! y2_south y2_north
197- weight_y(j2,j1) = (y2_north- y1_south)/ (y1_north- y1_south)* gw1(j1)/ gw2(j2)
198- elseif ( (y1_north.gt. y2_south).and. (y1_north.le. y2_north) ) then
222+ if (use_flight_distance) then
223+ weight_y(j2,j1) = (y2_north- y1_south)/ (y1_north- y1_south)
224+ else
225+ weight_y(j2,j1) = (y2_north- y1_south)/ (y1_north- y1_south)* gw1(j1)/ gw2(j2)
226+ endif
227+ elseif ( (y1_north> y2_south).and. (y1_north<= y2_north) ) then
199228! case 3:
200229! y1_south y1_north
201230! |--------------------------------|
202231! |---------------------------------|
203232! y2_south y2_north
204- weight_y(j2,j1) = (y1_north- y2_south)/ (y1_north- y1_south)* gw1(j1)/ gw2(j2)
205- elseif ( (y1_north.gt. y2_north).and. (y1_south.lt. y2_south) ) then
233+ if (use_flight_distance) then
234+ weight_y(j2,j1) = (y1_north- y2_south)/ (y1_north- y1_south)
235+ else
236+ weight_y(j2,j1) = (y1_north- y2_south)/ (y1_north- y1_south)* gw1(j1)/ gw2(j2)
237+ endif
238+ elseif ( (y1_north> y2_north).and. (y1_south< y2_south) ) then
206239! case 4:
207240! y1_south y1_north
208241! |--------------------------------|
209242! |---------------------|
210243! y2_south y2_north
211- weight_y(j2,j1) = gw1(j1)/ gw2(j2)
244+ if (use_flight_distance) then
245+ weight_y(j2,j1) = 1._r8
246+ else
247+ weight_y(j2,j1) = gw1(j1)/ gw2(j2)
248+ endif
212249 endif
213250
214251 enddo
0 commit comments