1 |
C |
2 |
C $Header: $ |
3 |
C $Name: $ |
4 |
|
5 |
#include "AD_CONFIG.h" |
6 |
#include "CTRL_CPPOPTIONS.h" |
7 |
|
8 |
|
9 |
subroutine ctrl_set_unpack_xy( |
10 |
& cunit, ivartype, fname, masktype, weighttype, |
11 |
& nwetglobal, mythid) |
12 |
|
13 |
c ================================================================== |
14 |
c SUBROUTINE ctrl_set_unpack_xy |
15 |
c ================================================================== |
16 |
c |
17 |
c o Unpack the control vector such that the land points are filled |
18 |
c in. |
19 |
c |
20 |
c changed: heimbach@mit.edu 17-Jun-2003 |
21 |
c merged Armin's changes to replace write of |
22 |
c nr * globfld2d by 1 * globfld3d |
23 |
c (ad hoc fix to speed up global I/O) |
24 |
c |
25 |
c ================================================================== |
26 |
|
27 |
implicit none |
28 |
|
29 |
c == global variables == |
30 |
|
31 |
#include "EEPARAMS.h" |
32 |
#include "SIZE.h" |
33 |
#include "PARAMS.h" |
34 |
#include "GRID.h" |
35 |
|
36 |
#include "ctrl.h" |
37 |
#include "cost.h" |
38 |
|
39 |
#ifdef ALLOW_ECCO_OPTIMIZATION |
40 |
#include "optim.h" |
41 |
#endif |
42 |
|
43 |
c == routine arguments == |
44 |
|
45 |
integer cunit |
46 |
integer ivartype |
47 |
character*( 80) fname |
48 |
character*( 5) masktype |
49 |
character*( 80) weighttype |
50 |
integer nwetglobal(nr) |
51 |
integer mythid |
52 |
|
53 |
c == local variables == |
54 |
|
55 |
#ifndef ALLOW_ECCO_OPTIMIZATION |
56 |
integer optimcycle |
57 |
#endif |
58 |
|
59 |
integer bi,bj |
60 |
integer ip,jp |
61 |
integer i,j,k |
62 |
integer ii |
63 |
integer il |
64 |
integer irec,nrec_nl |
65 |
integer itlo,ithi |
66 |
integer jtlo,jthi |
67 |
integer jmin,jmax |
68 |
integer imin,imax |
69 |
|
70 |
integer cbuffindex |
71 |
|
72 |
_RL cbuff ( snx*nsx*npx*sny*nsy*npy ) |
73 |
_RL globmsk ( snx,nsx,npx,sny,nsy,npy,nr ) |
74 |
_RL globfld3d( snx,nsx,npx,sny,nsy,npy,nr ) |
75 |
_RL globfld2d( snx,nsx,npx,sny,nsy,npy ) |
76 |
|
77 |
character*(128) cfile |
78 |
character*( 80) weightname |
79 |
|
80 |
integer filenvartype |
81 |
integer filenvarlength |
82 |
character*(10) fileExpId |
83 |
integer fileOptimCycle |
84 |
integer filencbuffindex |
85 |
_RL fileDummy |
86 |
integer fileIg |
87 |
integer fileJg |
88 |
integer fileI |
89 |
integer fileJ |
90 |
integer filensx |
91 |
integer filensy |
92 |
integer filek |
93 |
integer filencvarindex(maxcvars) |
94 |
integer filencvarrecs(maxcvars) |
95 |
integer filencvarxmax(maxcvars) |
96 |
integer filencvarymax(maxcvars) |
97 |
integer filencvarnrmax(maxcvars) |
98 |
character*( 1) filencvargrd(maxcvars) |
99 |
|
100 |
c == external == |
101 |
|
102 |
integer ilnblnk |
103 |
external ilnblnk |
104 |
|
105 |
c == end of interface == |
106 |
|
107 |
jtlo = 1 |
108 |
jthi = nsy |
109 |
itlo = 1 |
110 |
ithi = nsx |
111 |
jmin = 1 |
112 |
jmax = sny |
113 |
imin = 1 |
114 |
imax = snx |
115 |
|
116 |
c Initialise temporary file |
117 |
do k = 1,nr |
118 |
do jp = 1,nPy |
119 |
do bj = jtlo,jthi |
120 |
do j = jmin,jmax |
121 |
do ip = 1,nPx |
122 |
do bi = itlo,ithi |
123 |
do i = imin,imax |
124 |
globfld3d(i,bi,ip,j,bj,jp,k) = 0. _d 0 |
125 |
globmsk (i,bi,ip,j,bj,jp,k) = 0. _d 0 |
126 |
enddo |
127 |
enddo |
128 |
enddo |
129 |
enddo |
130 |
enddo |
131 |
enddo |
132 |
enddo |
133 |
|
134 |
#ifndef ALLOW_ECCO_OPTIMIZATION |
135 |
optimcycle = 0 |
136 |
#endif |
137 |
|
138 |
c-- Only the master thread will do I/O. |
139 |
_BEGIN_MASTER( mythid ) |
140 |
|
141 |
#ifdef ALLOW_NONDIMENSIONAL_CONTROL_IO |
142 |
il=ilnblnk( weighttype) |
143 |
write(weightname(1:80),'(80a)') ' ' |
144 |
write(weightname(1:80),'(a)') weighttype(1:il) |
145 |
call MDSREADFIELD_2D_GL( |
146 |
& weightname, ctrlprec, 'RL', |
147 |
& 1, globfld2d, 1, mythid) |
148 |
#endif |
149 |
|
150 |
call MDSREADFIELD_3D_GL( |
151 |
& masktype, ctrlprec, 'RL', |
152 |
& Nr, globmsk, 1, mythid) |
153 |
|
154 |
nrec_nl=int(ncvarrecs(ivartype)/Nr) |
155 |
do irec = 1, nrec_nl |
156 |
do k = 1,Nr |
157 |
read(cunit) filencvarindex(ivartype) |
158 |
if (filencvarindex(ivartype) .NE. ncvarindex(ivartype)) |
159 |
& then |
160 |
print *, 'ctrl_set_unpack_xy:WARNING: wrong ncvarindex ', |
161 |
& filencvarindex(ivartype), ncvarindex(ivartype) |
162 |
STOP 'in S/R ctrl_unpack' |
163 |
endif |
164 |
read(cunit) filej |
165 |
read(cunit) filei |
166 |
cbuffindex = nwetglobal(1) |
167 |
if ( cbuffindex .gt. 0 ) then |
168 |
read(cunit) filencbuffindex |
169 |
if (filencbuffindex .NE. cbuffindex) then |
170 |
print *, 'WARNING: wrong cbuffindex ', |
171 |
& filencbuffindex, cbuffindex |
172 |
STOP 'in S/R ctrl_unpack' |
173 |
endif |
174 |
read(cunit) filek |
175 |
if (filek .NE. 1) then |
176 |
print *, 'WARNING: wrong k ', |
177 |
& filek, 1 |
178 |
STOP 'in S/R ctrl_unpack' |
179 |
endif |
180 |
read(cunit) (cbuff(ii), ii=1,cbuffindex) |
181 |
endif |
182 |
cbuffindex = 0 |
183 |
do jp = 1,nPy |
184 |
do bj = jtlo,jthi |
185 |
do j = jmin,jmax |
186 |
do ip = 1,nPx |
187 |
do bi = itlo,ithi |
188 |
do i = imin,imax |
189 |
if ( globmsk(i,bi,ip,j,bj,jp,1) .ne. 0. ) then |
190 |
cbuffindex = cbuffindex + 1 |
191 |
globfld3d(i,bi,ip,j,bj,jp,k) = cbuff(cbuffindex) |
192 |
#ifdef ALLOW_NONDIMENSIONAL_CONTROL_IO |
193 |
globfld3d(i,bi,ip,j,bj,jp,k) = |
194 |
& globfld3d(i,bi,ip,j,bj,jp,k)/ |
195 |
& sqrt(globfld2d(i,bi,ip,j,bj,jp)) |
196 |
#endif |
197 |
else |
198 |
globfld3d(i,bi,ip,j,bj,jp,k) = 0. _d 0 |
199 |
endif |
200 |
enddo |
201 |
enddo |
202 |
enddo |
203 |
enddo |
204 |
enddo |
205 |
enddo |
206 |
c |
207 |
enddo |
208 |
|
209 |
call MDSWRITEFIELD_3D_GL( fname, ctrlprec, 'RL', |
210 |
& NR, globfld3d, |
211 |
& irec, optimcycle, mythid) |
212 |
|
213 |
enddo |
214 |
|
215 |
do irec = nrec_nl*Nr+1,ncvarrecs(ivartype) |
216 |
read(cunit) filencvarindex(ivartype) |
217 |
if (filencvarindex(ivartype) .NE. ncvarindex(ivartype)) |
218 |
& then |
219 |
print *, 'ctrl_set_unpack_xy:WARNING: wrong ncvarindex ', |
220 |
& filencvarindex(ivartype), ncvarindex(ivartype) |
221 |
STOP 'in S/R ctrl_unpack' |
222 |
endif |
223 |
read(cunit) filej |
224 |
read(cunit) filei |
225 |
do k = 1,1 |
226 |
cbuffindex = nwetglobal(k) |
227 |
if ( cbuffindex .gt. 0 ) then |
228 |
read(cunit) filencbuffindex |
229 |
if (filencbuffindex .NE. cbuffindex) then |
230 |
print *, 'WARNING: wrong cbuffindex ', |
231 |
& filencbuffindex, cbuffindex |
232 |
STOP 'in S/R ctrl_unpack' |
233 |
endif |
234 |
read(cunit) filek |
235 |
if (filek .NE. k) then |
236 |
print *, 'WARNING: wrong k ', |
237 |
& filek, k |
238 |
STOP 'in S/R ctrl_unpack' |
239 |
endif |
240 |
read(cunit) (cbuff(ii), ii=1,cbuffindex) |
241 |
endif |
242 |
cbuffindex = 0 |
243 |
do jp = 1,nPy |
244 |
do bj = jtlo,jthi |
245 |
do j = jmin,jmax |
246 |
do ip = 1,nPx |
247 |
do bi = itlo,ithi |
248 |
do i = imin,imax |
249 |
if ( globmsk(i,bi,ip,j,bj,jp,k) .ne. 0. ) then |
250 |
cbuffindex = cbuffindex + 1 |
251 |
globfld3d(i,bi,ip,j,bj,jp,k) = cbuff(cbuffindex) |
252 |
#ifdef ALLOW_NONDIMENSIONAL_CONTROL_IO |
253 |
globfld3d(i,bi,ip,j,bj,jp,k) = |
254 |
& globfld3d(i,bi,ip,j,bj,jp,k)/ |
255 |
& sqrt(globfld2d(i,bi,ip,j,bj,jp)) |
256 |
#endif |
257 |
else |
258 |
globfld3d(i,bi,ip,j,bj,jp,k) = 0. _d 0 |
259 |
endif |
260 |
enddo |
261 |
enddo |
262 |
enddo |
263 |
enddo |
264 |
enddo |
265 |
enddo |
266 |
c |
267 |
enddo |
268 |
|
269 |
call MDSWRITEFIELD_2D_GL( fname, ctrlprec, 'RL', |
270 |
& 1, globfld3d(1,1,1,1,1,1,1), |
271 |
& irec, optimcycle, mythid) |
272 |
|
273 |
enddo |
274 |
|
275 |
_END_MASTER( mythid ) |
276 |
|
277 |
return |
278 |
end |
279 |
|