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

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

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


Revision 1.11 - (show annotations) (download)
Tue Nov 8 15:53:41 2005 UTC (18 years, 7 months ago) by cnh
Branch: MAIN
CVS Tags: checkpoint57y_post, checkpoint57y_pre, checkpoint58, checkpoint57x_post, checkpoint57z_post
Changes since 1.10: +3 -2 lines
Changes toward getting exf working multi-threaded.
  o added some opitonal consistency check in barrier for
    trapping barrier calls in singel threaded region
  o removed a single thread block in ini_depths - singleCpuIO
    still broken.
  o modified parts of exf_ that were setting local stack variables
    in single threaded section and then referencing them from all
    threads.
  o commented out strange stop in mdsio for multithreading which
    seems uneeded.
  o fixed ptracers initialization and changed ptracers monitor
    to avoid race condition in which several threads set a shared
    logical flag at arbitrary moments with respect to each other

1 #include "EXF_OPTIONS.h"
2 CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
3 C Flux Coupler using C
4 C Bilinear interpolation of forcing fields C
5 C C
6 C B. Cheng (12/2002) C
7 C C
8 C added Bicubic (bnc 1/2003) C
9 C C
10 CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
11
12 real*8 function lagran(i,x,a,sp)
13
14 INTEGER i,k,sp
15 _RS x
16 real*8 a(4)
17 real*8 numer,denom
18
19 numer = 1.D0
20 denom = 1.D0
21
22 do k=1,sp
23 if ( k .ne. i) then
24 denom = denom*(a(i) - a(k))
25 numer = numer*(x - a(k))
26 endif
27 enddo
28
29 lagran = numer/denom
30
31 return
32 end
33
34
35 SUBROUTINE exf_interp(
36 I infile,
37 I filePrec,
38 O arrayout,
39 I irecord, xG, yG,
40 I lon_0, lon_inc,
41 I lat_0, lat_inc,
42 I nx_in, ny_in, method, mythid)
43
44 implicit none
45
46 C infile = name of the input file (direct access binary)
47 C filePrec = file precicision (currently not used, assumes real*4)
48 C arrout = output arrays (different for each processor)
49 C irecord = record number in global file
50 C xG,yG = coordinates for output grid
51 C lon_0, lat_0 = lon and lat of sw corner of global input grid
52 C lon_inc = scalar x-grid increment
53 C lat_inc = vector y-grid increments
54 C nx_in, ny_in = input x-grid and y-grid size
55 C method = 1 for bilinear 2 for bicubic
56 C mythid = thread id
57 C
58
59 #include "SIZE.h"
60 #include "EEPARAMS.h"
61 #include "PARAMS.h"
62
63 C subroutine variables
64 character*(*) infile
65 integer filePrec, irecord, nx_in, ny_in
66 _RL arrayout(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
67 _RS xG (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
68 _RS yG (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
69 _RL lon_0, lon_inc
70 _RL lat_0, lat_inc(ny_in-1)
71 integer method, mythid
72
73 C local variables
74 real*8 ne_fac,nw_fac,se_fac,sw_fac
75 integer e_ind(snx,sny),w_ind(snx,sny)
76 integer n_ind(snx,sny),s_ind(snx,sny)
77 real*8 px_ind(4), py_ind(4), ew_val(4)
78 external lagran
79 real*8 lagran
80 real*4 arrayin(-1:nx_in+2 , -1:ny_in+2)
81 real*8 x_in (-1:nx_in+2), y_in(-1:ny_in+2)
82 integer i, j, k, l, js, bi, bj, sp, interp_unit
83
84 call exf_interp_read(
85 I infile,
86 I filePrec,
87 O arrayin,
88 I irecord, xG, yG,
89 I lon_0, lon_inc,
90 I lat_0, lat_inc,
91 I nx_in, ny_in, method, mythid)
92 _BARRIER
93
94 C _BEGIN_MASTER( myThid )
95
96 C setup input grid
97 do i=-1,nx_in+2
98 x_in(i) = lon_0 + (i-1.)*lon_inc
99 enddo
100 y_in(0) = lat_0 - lat_inc(1)
101 y_in(-1)= lat_0 - 2.*lat_inc(1)
102 y_in(1) = lat_0
103 do j=2,ny_in
104 y_in(j) = y_in(j-1) + lat_inc(j-1)
105 enddo
106 y_in(ny_in+1) = y_in(ny_in) + lat_inc(ny_in-1)
107 y_in(ny_in+2) = y_in(ny_in) + 2.*lat_inc(ny_in-1)
108
109 C enlarge boundary
110 do j=1,ny_in
111 arrayin(0,j) = arrayin(nx_in,j)
112 arrayin(-1,j) = arrayin(nx_in-1,j)
113 arrayin(nx_in+1,j) = arrayin(1,j)
114 arrayin(nx_in+2,j) = arrayin(2,j)
115 enddo
116 do i=-1,nx_in+2
117 arrayin(i,0) = arrayin(i,1)
118 arrayin(i,-1) = arrayin(i,1)
119 arrayin(i,ny_in+1) = arrayin(i,ny_in)
120 arrayin(i,ny_in+2) = arrayin(i,ny_in)
121 enddo
122
123 C _END_MASTER( myThid )
124
125 do bj = mybylo(mythid), mybyhi(mythid)
126 do bi = mybxlo(mythid), mybxhi(mythid)
127
128 C check validity of input/output coordinates
129 #ifdef ALLOW_DEBUG
130 if ( debugLevel .ge. debLevB ) then
131 do i=1,snx
132 do j=1,sny
133 if ( xG(i,j,bi,bj) .lt. x_in(0) .or.
134 & xG(i,j,bi,bj) .ge. x_in(nx_in+1) .or.
135 & yG(i,j,bi,bj) .lt. y_in(0) .or.
136 & yG(i,j,bi,bj) .ge. y_in(ny_in+1) ) then
137 print*,'ERROR in S/R EXF_INTERP:'
138 print*,' input grid must encompass output grid.'
139 print*,'i,j,bi,bj' ,i,j,bi,bj
140 print*,'xG,yG' ,xG(i,j,bi,bj),yG(i,j,bi,bj)
141 print*,'nx_in,ny_in' ,nx_in ,ny_in
142 print*,'x_in(0,nx_in+1)',x_in(0) ,x_in(nx_in+1)
143 print*,'y_in(0,ny_in+1)',y_in(0) ,y_in(ny_in+1)
144 STOP ' ABNORMAL END: S/R EXF_INTERP'
145 endif
146 enddo
147 enddo
148 endif
149 #endif /* ALLOW_DEBUG */
150
151 C compute interpolation indices
152 do i=1,snx
153 do j=1,sny
154 if (xG(i,j,bi,bj)-x_in(1) .ge. 0.) then
155 w_ind(i,j) = int((xG(i,j,bi,bj)-x_in(1))/lon_inc) + 1
156 else
157 w_ind(i,j) = int((xG(i,j,bi,bj)-x_in(1))/lon_inc)
158 endif
159 e_ind(i,j) = w_ind(i,j) + 1
160 js = ny_in*.5
161 do while (yG(i,j,bi,bj) .lt. y_in(js))
162 js = (js - 1)*.5
163 enddo
164 do while (yG(i,j,bi,bj) .ge. y_in(js+1))
165 js = js + 1
166 enddo
167 s_ind(i,j) = js
168 n_ind(i,j) = js + 1
169 enddo
170 enddo
171
172 if (method .eq. 1) then
173
174 C bilinear interpolation
175 sp = 2
176 do j=1,sny
177 do i=1,snx
178 arrayout(i,j,bi,bj) = 0.
179 do l=0,1
180 px_ind(l+1) = x_in(w_ind(i,j)+l)
181 py_ind(l+1) = y_in(s_ind(i,j)+l)
182 enddo
183 do k=1,2
184 ew_val(k) = arrayin(w_ind(i,j),s_ind(i,j)+k-1)
185 & *lagran(1,xG(i,j,bi,bj),px_ind,sp)
186 & +arrayin(e_ind(i,j),s_ind(i,j)+k-1)
187 & *lagran(2,xG(i,j,bi,bj),px_ind,sp)
188 arrayout(i,j,bi,bj)=arrayout(i,j,bi,bj)
189 & +ew_val(k)*lagran(k,yG(i,j,bi,bj),py_ind,sp)
190 enddo
191 enddo
192 enddo
193 elseif (method .eq. 2) then
194
195 C bicubic interpolation
196 sp = 4
197 do j=1,sny
198 do i=1,snx
199 arrayout(i,j,bi,bj) = 0.
200 do l=-1,2
201 px_ind(l+2) = x_in(w_ind(i,j)+l)
202 py_ind(l+2) = y_in(s_ind(i,j)+l)
203 enddo
204 do k=1,4
205 ew_val(k) =
206 & arrayin(w_ind(i,j)-1,s_ind(i,j)+k-2)
207 & *lagran(1,xG(i,j,bi,bj),px_ind,sp)
208 & +arrayin(w_ind(i,j) ,s_ind(i,j)+k-2)
209 & *lagran(2,xG(i,j,bi,bj),px_ind,sp)
210 & +arrayin(e_ind(i,j) ,s_ind(i,j)+k-2)
211 & *lagran(3,xG(i,j,bi,bj),px_ind,sp)
212 & +arrayin(e_ind(i,j)+1,s_ind(i,j)+k-2)
213 & *lagran(4,xG(i,j,bi,bj),px_ind,sp)
214 arrayout(i,j,bi,bj)=arrayout(i,j,bi,bj)
215 & +ew_val(k)*lagran(k,yG(i,j,bi,bj),py_ind,sp)
216 enddo
217 enddo
218 enddo
219 else
220 stop 'stop in exf_interp.F: interpolation method not supported'
221 endif
222 enddo
223 enddo
224
225 END

  ViewVC Help
Powered by ViewVC 1.1.22