/[MITgcm]/MITgcm/pkg/exf/exf_set_uv.F
ViewVC logotype

Contents of /MITgcm/pkg/exf/exf_set_uv.F

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download)
Mon Mar 15 17:15:38 2004 UTC (20 years, 3 months ago) by dimitri
Branch: MAIN
Changes since 1.1: +1 -23 lines
bug fix: removed double exf_inscal factor

1 C $Header: /usr/local/gcmpack/MITgcm/pkg/exf/exf_set_uv.F,v 1.1 2003/12/10 19:37:25 dimitri Exp $
2 C $Name: $
3
4 #include "PACKAGES_CONFIG.h"
5 #include "EXF_OPTIONS.h"
6
7 #ifdef USE_EXF_INTERPOLATION
8
9 subroutine exf_set_uv(
10 & uvecfile, uvecstartdate, uvecperiod,
11 & exf_inscal_uvec, uvec, uvec0, uvec1, uvecmask,
12 & uvec_lon0, uvec_lon_inc, uvec_lat0, uvec_lat_inc,
13 & uvec_nlon, uvec_nlat,
14 & vvecfile, vvecstartdate, vvecperiod,
15 & exf_inscal_vvec, vvec, vvec0, vvec1, vvecmask,
16 & vvec_lon0, vvec_lon_inc, vvec_lat0, vvec_lat_inc,
17 & vvec_nlon, vvec_nlat, output_xC_yC,
18 & mycurrenttime, mycurrentiter, mythid )
19
20 c ==================================================================
21 c SUBROUTINE exf_set_uv
22 c ==================================================================
23 c
24 c o Read-in, interpolate, and rotate wind or wind stress vectors
25 c from a spherical-polar input grid to an arbitrary output grid.
26 c
27 c menemenlis@jpl.nasa.gov, 8-Dec-2003
28 c
29 c ==================================================================
30 c SUBROUTINE exf_set_uv
31 c ==================================================================
32
33 implicit none
34
35 c == global variables ==
36
37 #include "EEPARAMS.h"
38 #include "SIZE.h"
39 #include "PARAMS.h"
40 #include "DYNVARS.h"
41 #include "GRID.h"
42
43 #include "exf_param.h"
44 #include "exf_fields.h"
45 #include "exf_constants.h"
46
47 #ifdef ALLOW_AUTODIFF
48 # include "ctrl.h"
49 # include "ctrl_dummy.h"
50 #endif
51
52 c == routine arguments ==
53
54 c *vec_lon_0, :: longitude and latitude of SouthWest
55 c *vec_lat_0 corner of global input grid for *vec
56 c *vec_nlon, *vec_nlat :: input x-grid and y-grid size for *vec
57 c *vec_lon_inc :: scalar x-grid increment for *vec
58 c *vec_lat_inc :: vector y-grid increments for *vec
59 c output_xC_yC :: when true, output grid is (xC,yC)
60 c otherwise, uvec is at (xG,yC) and
61 c vvec is at (xC,yG).
62
63 character*(128) uvecfile
64 _RL uvecstartdate, uvecperiod
65 _RL exf_inscal_uvec
66 _RL uvec (1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
67 _RL uvec0 (1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
68 _RL uvec1 (1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
69 character*1 uvecmask
70 _RL uvec_lon0, uvec_lon_inc
71 _RL uvec_lat0, uvec_lat_inc(MAX_LAT_INC)
72 INTEGER uvec_nlon, uvec_nlat
73 character*(128) vvecfile
74 _RL vvecstartdate, vvecperiod
75 _RL exf_inscal_vvec
76 _RL vvec (1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
77 _RL vvec0 (1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
78 _RL vvec1 (1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
79 character*1 vvecmask
80 _RL vvec_lon0, vvec_lon_inc
81 _RL vvec_lat0, vvec_lat_inc(MAX_LAT_INC)
82 INTEGER vvec_nlon, vvec_nlat
83 logical output_xC_yC
84 _RL mycurrenttime
85 integer mycurrentiter
86 integer mythid
87
88 c == local variables ==
89
90 logical first, changed
91 _RL fac, x1, x2, x3, x4, y1, y2, y3, y4, dx, dy
92 _RL tmp_u (1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
93 _RL tmp_v (1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
94 integer count0, count1
95 integer i, j, bi, bj
96 integer interp_method
97 parameter(interp_method=2)
98
99 c == end of interface ==
100
101 IF ( useCubedSphereExchange ) THEN
102
103 if ( uvecfile .NE. ' ' .and. vvecfile .NE. ' ' ) then
104
105 c some restrictions that can be relaxed later on
106 if ( uvecstartdate .ne. vvecstartdate .or.
107 & uvecperiod .ne. vvecperiod ) then
108 print*,'For useCubedSphereExchange, S/R exf_set_uv.F'
109 print*,'assumes that the u and v wind or wind stress'
110 print*,'files have the same startdate and period.'
111 stop
112 endif
113 if ( .not. output_xC_yC ) then
114 print*,'For useCubedSphereExchange, S/R exf_set_uv.F'
115 print*,'assumes that the output grid is (xC,yC).'
116 stop
117 endif
118
119 c get record numbers and interpolation factor
120 call exf_GetFFieldRec(
121 I uvecstartdate, uvecperiod
122 O , fac, first, changed
123 O , count0, count1
124 I , mycurrenttime, mycurrentiter, mythid
125 & )
126
127 if ( first ) then
128 c scalar interpolation to (xC,yC) locations
129 call exf_interp( uvecfile, exf_iprec
130 & , tmp_u, count0, xC, yC
131 & , uvec_lon0,uvec_lon_inc
132 & , uvec_lat0,uvec_lat_inc
133 & , uvec_nlon,uvec_nlat,interp_method,mythid
134 & )
135 call exf_interp( vvecfile, exf_iprec
136 & , tmp_v, count0, xC, yC
137 & , vvec_lon0,vvec_lon_inc
138 & , vvec_lat0,vvec_lat_inc
139 & , vvec_nlon,vvec_nlat,interp_method,mythid
140 & )
141 c vector rotation
142 do bj = mybylo(mythid),mybyhi(mythid)
143 do bi = mybxlo(mythid),mybxhi(mythid)
144 do j = 1,sny
145 do i = 1,snx
146 x1=xG(i,j,bi,bj)
147 x2=xG(i+1,j,bi,bj)
148 x3=xG(i,j+1,bi,bj)
149 x4=xG(i+1,j+1,bi,bj)
150 if ((x2-x1).gt.180) x2=x2-360
151 if ((x1-x2).gt.180) x2=x2+360
152 if ((x3-x1).gt.180) x3=x3-360
153 if ((x1-x3).gt.180) x3=x3+360
154 if ((x4-x1).gt.180) x4=x4-360
155 if ((x1-x4).gt.180) x4=x4+360
156 y1=yG(i,j,bi,bj)
157 y2=yG(i+1,j,bi,bj)
158 y3=yG(i,j+1,bi,bj)
159 y4=yG(i+1,j+1,bi,bj)
160 dx=0.5*(x3+x4-x1-x2)
161 dx=dx*cos(deg2rad*yC(i,j,bi,bj))
162 dy=0.5*(y3+y4-y1-y2)
163 vvec1(i,j,bi,bj)=(tmp_u(i,j,bi,bj)*dx+
164 & tmp_v(i,j,bi,bj)*dy)/sqrt(dx*dx+dy*dy)
165 dx=0.5*(x2+x4-x1-x3)
166 dx=dx*cos(deg2rad*yC(i,j,bi,bj))
167 dy=0.5*(y2+y4-y1-y3)
168 uvec1(i,j,bi,bj)=(tmp_u(i,j,bi,bj)*dx+
169 & tmp_v(i,j,bi,bj)*dy)/sqrt(dx*dx+dy*dy)
170 enddo
171 enddo
172 enddo
173 enddo
174 c apply mask
175 if (exf_yftype .eq. 'RL') then
176 call exf_filter_rl( uvec1, uvecmask, mythid )
177 call exf_filter_rl( vvec1, vvecmask, mythid )
178 else
179 call exf_filter_rs( uvec1, uvecmask, mythid )
180 call exf_filter_rs( vvec1, vvecmask, mythid )
181 end if
182 endif
183
184 if (( first ) .or. ( changed )) then
185 call exf_SwapFFields( uvec0, uvec1, mythid )
186 call exf_SwapFFields( vvec0, vvec1, mythid )
187 c scalar interpolation to (xC,yC) locations
188 call exf_interp( uvecfile, exf_iprec
189 & , tmp_u, count1, xC, yC
190 & , uvec_lon0,uvec_lon_inc
191 & , uvec_lat0,uvec_lat_inc
192 & , uvec_nlon,uvec_nlat,interp_method,mythid
193 & )
194 call exf_interp( vvecfile, exf_iprec
195 & , tmp_v, count1, xC, yC
196 & , vvec_lon0,vvec_lon_inc
197 & , vvec_lat0,vvec_lat_inc
198 & , vvec_nlon,vvec_nlat,interp_method,mythid
199 & )
200 c vector rotation
201 do bj = mybylo(mythid),mybyhi(mythid)
202 do bi = mybxlo(mythid),mybxhi(mythid)
203 do j = 1,sny
204 do i = 1,snx
205 x1=xG(i,j,bi,bj)
206 x2=xG(i+1,j,bi,bj)
207 x3=xG(i,j+1,bi,bj)
208 x4=xG(i+1,j+1,bi,bj)
209 if ((x2-x1).gt.180) x2=x2-360
210 if ((x1-x2).gt.180) x2=x2+360
211 if ((x3-x1).gt.180) x3=x3-360
212 if ((x1-x3).gt.180) x3=x3+360
213 if ((x4-x1).gt.180) x4=x4-360
214 if ((x1-x4).gt.180) x4=x4+360
215 y1=yG(i,j,bi,bj)
216 y2=yG(i+1,j,bi,bj)
217 y3=yG(i,j+1,bi,bj)
218 y4=yG(i+1,j+1,bi,bj)
219 dx=0.5*(x3+x4-x1-x2)
220 dx=dx*cos(deg2rad*yC(i,j,bi,bj))
221 dy=0.5*(y3+y4-y1-y2)
222 vvec1(i,j,bi,bj)=(tmp_u(i,j,bi,bj)*dx+
223 & tmp_v(i,j,bi,bj)*dy)/sqrt(dx*dx+dy*dy)
224 dx=0.5*(x2+x4-x1-x3)
225 dx=dx*cos(deg2rad*yC(i,j,bi,bj))
226 dy=0.5*(y2+y4-y1-y3)
227 uvec1(i,j,bi,bj)=(tmp_u(i,j,bi,bj)*dx+
228 & tmp_v(i,j,bi,bj)*dy)/sqrt(dx*dx+dy*dy)
229 enddo
230 enddo
231 enddo
232 enddo
233 c apply mask
234 if (exf_yftype .eq. 'RL') then
235 call exf_filter_rl( uvec1, uvecmask, mythid )
236 call exf_filter_rl( vvec1, vvecmask, mythid )
237 else
238 call exf_filter_rs( uvec1, uvecmask, mythid )
239 call exf_filter_rs( vvec1, vvecmask, mythid )
240 end if
241 endif
242
243 c Interpolate linearly onto the current time.
244 do bj = mybylo(mythid),mybyhi(mythid)
245 do bi = mybxlo(mythid),mybxhi(mythid)
246 do j = 1,sny
247 do i = 1,snx
248 uvec(i,j,bi,bj) = exf_inscal_uvec * (
249 & fac * uvec0(i,j,bi,bj) +
250 & (exf_one - fac) * uvec1(i,j,bi,bj) )
251 vvec(i,j,bi,bj) = exf_inscal_vvec * (
252 & fac * vvec0(i,j,bi,bj) +
253 & (exf_one - fac) * vvec1(i,j,bi,bj) )
254 enddo
255 enddo
256 enddo
257 enddo
258
259 endif
260
261 ELSE
262 c IF ( .NOT. useCubedSphereExchange )
263
264 IF ( output_xC_yC ) THEN
265 call exf_set_gen(
266 & uvecfile, uvecstartdate, uvecperiod,
267 & exf_inscal_uvec,
268 & uvec, uvec0, uvec1, uvecmask,
269 & uvec_lon0, uvec_lon_inc, uvec_lat0, uvec_lat_inc,
270 & uvec_nlon, uvec_nlat, xC, yC,
271 & mycurrenttime, mycurrentiter, mythid )
272 call exf_set_gen(
273 & vvecfile, vvecstartdate, vvecperiod,
274 & exf_inscal_vvec,
275 & vvec, vvec0, vvec1, vvecmask,
276 & vvec_lon0, vvec_lon_inc, vvec_lat0, vvec_lat_inc,
277 & vvec_nlon, vvec_nlat, xC, yC,
278 & mycurrenttime, mycurrentiter, mythid )
279 ELSE
280 call exf_set_gen(
281 & uvecfile, uvecstartdate, uvecperiod,
282 & exf_inscal_uvec,
283 & uvec, uvec0, uvec1, uvecmask,
284 & uvec_lon0, uvec_lon_inc, uvec_lat0, uvec_lat_inc,
285 & uvec_nlon, uvec_nlat, xG, yC,
286 & mycurrenttime, mycurrentiter, mythid )
287 call exf_set_gen(
288 & vvecfile, vvecstartdate, vvecperiod,
289 & exf_inscal_vvec,
290 & vvec, vvec0, vvec1, vvecmask,
291 & vvec_lon0, vvec_lon_inc, vvec_lat0, vvec_lat_inc,
292 & vvec_nlon, vvec_nlat, xC, yG,
293 & mycurrenttime, mycurrentiter, mythid )
294 ENDIF
295
296 ENDIF
297
298 return
299 end
300
301 #endif /* USE_EXF_INTERPOLATION */

  ViewVC Help
Powered by ViewVC 1.1.22