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