1 |
jmc |
1.19 |
C $Header: $ |
2 |
|
|
C $Name: $ |
3 |
heimbach |
1.2 |
|
4 |
|
|
#include "CTRL_CPPOPTIONS.h" |
5 |
|
|
|
6 |
|
|
subroutine ctrl_set_unpack_xyz( |
7 |
heimbach |
1.9 |
& lxxadxx, cunit, ivartype, fname, masktype, weighttype, |
8 |
heimbach |
1.2 |
& weightfld, nwetglobal, mythid) |
9 |
|
|
|
10 |
|
|
c ================================================================== |
11 |
|
|
c SUBROUTINE ctrl_set_unpack_xyz |
12 |
|
|
c ================================================================== |
13 |
|
|
c |
14 |
heimbach |
1.3 |
c o Unpack the control vector such that land points are filled in. |
15 |
|
|
c |
16 |
|
|
c o Use a more precise nondimensionalization that depends on (x,y) |
17 |
|
|
c Added weighttype to the argument list so that I can geographically |
18 |
|
|
c vary the nondimensionalization. |
19 |
|
|
c gebbie@mit.edu, 18-Mar-2003 |
20 |
heimbach |
1.2 |
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 "optim.h" |
34 |
|
|
|
35 |
|
|
c == routine arguments == |
36 |
|
|
|
37 |
heimbach |
1.9 |
logical lxxadxx |
38 |
heimbach |
1.2 |
integer cunit |
39 |
|
|
integer ivartype |
40 |
|
|
character*( 80) fname |
41 |
heimbach |
1.11 |
character*( 9) masktype |
42 |
heimbach |
1.3 |
character*( 80) weighttype |
43 |
heimbach |
1.2 |
_RL weightfld( nr,nsx,nsy ) |
44 |
|
|
integer nwetglobal(nr) |
45 |
|
|
integer mythid |
46 |
|
|
|
47 |
heimbach |
1.17 |
#ifndef EXCLUDE_CTRL_PACK |
48 |
heimbach |
1.2 |
c == local variables == |
49 |
|
|
|
50 |
|
|
integer bi,bj |
51 |
|
|
integer ip,jp |
52 |
|
|
integer i,j,k |
53 |
|
|
integer ii |
54 |
|
|
integer il |
55 |
|
|
integer irec |
56 |
|
|
integer itlo,ithi |
57 |
|
|
integer jtlo,jthi |
58 |
|
|
integer jmin,jmax |
59 |
|
|
integer imin,imax |
60 |
|
|
|
61 |
|
|
integer cbuffindex |
62 |
|
|
|
63 |
|
|
_RL globmsk ( snx,nsx,npx,sny,nsy,npy,nr ) |
64 |
|
|
_RL globfld3d( snx,nsx,npx,sny,nsy,npy,nr ) |
65 |
heimbach |
1.3 |
#ifdef CTRL_UNPACK_PRECISE |
66 |
|
|
_RL weightfld3d( snx,nsx,npx,sny,nsy,npy,nr ) |
67 |
|
|
#endif |
68 |
heimbach |
1.9 |
real*4 cbuff ( snx*nsx*npx*sny*nsy*npy ) |
69 |
|
|
real*4 globfldtmp2( snx,nsx,npx,sny,nsy,npy ) |
70 |
|
|
real*4 globfldtmp3( snx,nsx,npx,sny,nsy,npy ) |
71 |
heimbach |
1.2 |
|
72 |
|
|
character*(128) cfile |
73 |
heimbach |
1.3 |
character*(80) weightname |
74 |
heimbach |
1.2 |
|
75 |
heimbach |
1.9 |
_RL delZnorm |
76 |
|
|
integer reclen, irectrue |
77 |
|
|
integer cunit2, cunit3 |
78 |
|
|
character*(80) cfile2, cfile3 |
79 |
|
|
|
80 |
heimbach |
1.2 |
c == external == |
81 |
|
|
|
82 |
|
|
integer ilnblnk |
83 |
|
|
external ilnblnk |
84 |
|
|
|
85 |
|
|
cc == end of interface == |
86 |
|
|
|
87 |
|
|
jtlo = 1 |
88 |
|
|
jthi = nsy |
89 |
|
|
itlo = 1 |
90 |
|
|
ithi = nsx |
91 |
|
|
jmin = 1 |
92 |
|
|
jmax = sny |
93 |
|
|
imin = 1 |
94 |
|
|
imax = snx |
95 |
|
|
|
96 |
heimbach |
1.9 |
#ifdef CTRL_DELZNORM |
97 |
|
|
delZnorm = 0. |
98 |
|
|
do k = 1, Nr |
99 |
|
|
delZnorm = delZnorm + delR(k)/FLOAT(Nr) |
100 |
|
|
enddo |
101 |
|
|
#endif |
102 |
|
|
|
103 |
heimbach |
1.2 |
c Initialise temporary file |
104 |
|
|
do k = 1,nr |
105 |
|
|
do jp = 1,nPy |
106 |
|
|
do bj = jtlo,jthi |
107 |
|
|
do j = jmin,jmax |
108 |
|
|
do ip = 1,nPx |
109 |
|
|
do bi = itlo,ithi |
110 |
|
|
do i = imin,imax |
111 |
heimbach |
1.9 |
globfld3d (i,bi,ip,j,bj,jp,k) = 0. _d 0 |
112 |
|
|
globmsk (i,bi,ip,j,bj,jp,k) = 0. _d 0 |
113 |
|
|
globfldtmp2(i,bi,ip,j,bj,jp) = 0. |
114 |
|
|
globfldtmp3(i,bi,ip,j,bj,jp) = 0. |
115 |
heimbach |
1.2 |
enddo |
116 |
|
|
enddo |
117 |
|
|
enddo |
118 |
|
|
enddo |
119 |
|
|
enddo |
120 |
|
|
enddo |
121 |
|
|
enddo |
122 |
|
|
|
123 |
|
|
c-- Only the master thread will do I/O. |
124 |
|
|
_BEGIN_MASTER( mythid ) |
125 |
|
|
|
126 |
heimbach |
1.9 |
#ifdef CTRL_DELZNORM |
127 |
|
|
do k = 1, nr |
128 |
|
|
print *, 'ph-delznorm ', k, delZnorm, delR(k) |
129 |
|
|
print *, 'ph-weight ', weightfld(k,1,1) |
130 |
|
|
enddo |
131 |
|
|
#endif |
132 |
|
|
|
133 |
|
|
if ( doPackDiag ) then |
134 |
|
|
write(cfile2(1:80),'(80a)') ' ' |
135 |
|
|
write(cfile3(1:80),'(80a)') ' ' |
136 |
|
|
if ( lxxadxx ) then |
137 |
|
|
write(cfile2(1:80),'(a,I2.2,a,I4.4,a)') |
138 |
jmc |
1.19 |
& 'diag_unpack_nondim_ctrl_', |
139 |
heimbach |
1.9 |
& ivartype, '_', optimcycle, '.bin' |
140 |
|
|
write(cfile3(1:80),'(a,I2.2,a,I4.4,a)') |
141 |
jmc |
1.19 |
& 'diag_unpack_dimens_ctrl_', |
142 |
heimbach |
1.9 |
& ivartype, '_', optimcycle, '.bin' |
143 |
|
|
else |
144 |
|
|
write(cfile2(1:80),'(a,I2.2,a,I4.4,a)') |
145 |
jmc |
1.19 |
& 'diag_unpack_nondim_grad_', |
146 |
heimbach |
1.9 |
& ivartype, '_', optimcycle, '.bin' |
147 |
|
|
write(cfile3(1:80),'(a,I2.2,a,I4.4,a)') |
148 |
jmc |
1.19 |
& 'diag_unpack_dimens_grad_', |
149 |
heimbach |
1.9 |
& ivartype, '_', optimcycle, '.bin' |
150 |
|
|
endif |
151 |
|
|
|
152 |
|
|
reclen = FLOAT(snx*nsx*npx*sny*nsy*npy*4) |
153 |
|
|
call mdsfindunit( cunit2, mythid ) |
154 |
heimbach |
1.10 |
open( cunit2, file=cfile2, status='unknown', |
155 |
heimbach |
1.9 |
& access='direct', recl=reclen ) |
156 |
|
|
call mdsfindunit( cunit3, mythid ) |
157 |
heimbach |
1.10 |
open( cunit3, file=cfile3, status='unknown', |
158 |
heimbach |
1.9 |
& access='direct', recl=reclen ) |
159 |
|
|
endif |
160 |
|
|
|
161 |
heimbach |
1.3 |
#ifdef CTRL_UNPACK_PRECISE |
162 |
|
|
il=ilnblnk( weighttype) |
163 |
|
|
write(weightname(1:80),'(80a)') ' ' |
164 |
|
|
write(weightname(1:80),'(a)') weighttype(1:il) |
165 |
|
|
|
166 |
|
|
call MDSREADFIELD_3D_GL( |
167 |
|
|
& weightname, ctrlprec, 'RL', |
168 |
|
|
& Nr, weightfld3d, 1, mythid) |
169 |
|
|
#endif |
170 |
|
|
|
171 |
jmc |
1.19 |
call MDSREADFIELD_3D_GL( |
172 |
heimbach |
1.2 |
& masktype, ctrlprec, 'RL', |
173 |
|
|
& Nr, globmsk, 1, mythid) |
174 |
|
|
|
175 |
|
|
do irec = 1, ncvarrecs(ivartype) |
176 |
heimbach |
1.13 |
#ifndef ALLOW_ADMTLM |
177 |
heimbach |
1.2 |
read(cunit) filencvarindex(ivartype) |
178 |
|
|
if (filencvarindex(ivartype) .NE. ncvarindex(ivartype)) |
179 |
|
|
& then |
180 |
|
|
print *, 'ctrl_set_unpack_xyz:WARNING: wrong ncvarindex ', |
181 |
|
|
& filencvarindex(ivartype), ncvarindex(ivartype) |
182 |
|
|
STOP 'in S/R ctrl_unpack' |
183 |
|
|
endif |
184 |
|
|
read(cunit) filej |
185 |
|
|
read(cunit) filei |
186 |
heimbach |
1.13 |
#endif /* ALLOW_ADMTLM */ |
187 |
heimbach |
1.2 |
do k = 1, Nr |
188 |
heimbach |
1.9 |
irectrue = (irec-1)*nr + k |
189 |
heimbach |
1.10 |
if ( doZscaleUnpack ) then |
190 |
heimbach |
1.16 |
delZnorm = (delR(1)/delR(k))**delZexp |
191 |
heimbach |
1.10 |
else |
192 |
|
|
delZnorm = 1. _d 0 |
193 |
|
|
endif |
194 |
heimbach |
1.2 |
cbuffindex = nwetglobal(k) |
195 |
|
|
if ( cbuffindex .gt. 0 ) then |
196 |
heimbach |
1.13 |
#ifndef ALLOW_ADMTLM |
197 |
heimbach |
1.2 |
read(cunit) filencbuffindex |
198 |
|
|
if (filencbuffindex .NE. cbuffindex) then |
199 |
|
|
print *, 'WARNING: wrong cbuffindex ', |
200 |
|
|
& filencbuffindex, cbuffindex |
201 |
|
|
STOP 'in S/R ctrl_unpack' |
202 |
|
|
endif |
203 |
|
|
read(cunit) filek |
204 |
|
|
if (filek .NE. k) then |
205 |
|
|
print *, 'WARNING: wrong k ', |
206 |
|
|
& filek, k |
207 |
|
|
STOP 'in S/R ctrl_unpack' |
208 |
|
|
endif |
209 |
heimbach |
1.15 |
cph#endif /* ALLOW_ADMTLM */ |
210 |
|
|
read(cunit) (cbuff(ii), ii=1,cbuffindex) |
211 |
heimbach |
1.13 |
#endif /* ALLOW_ADMTLM */ |
212 |
heimbach |
1.2 |
endif |
213 |
heimbach |
1.13 |
c |
214 |
heimbach |
1.2 |
cbuffindex = 0 |
215 |
|
|
do jp = 1,nPy |
216 |
|
|
do bj = jtlo,jthi |
217 |
|
|
do j = jmin,jmax |
218 |
|
|
do ip = 1,nPx |
219 |
|
|
do bi = itlo,ithi |
220 |
|
|
do i = imin,imax |
221 |
|
|
if ( globmsk(i,bi,ip,j,bj,jp,k) .ne. 0. ) then |
222 |
|
|
cbuffindex = cbuffindex + 1 |
223 |
|
|
globfld3d(i,bi,ip,j,bj,jp,k) = cbuff(cbuffindex) |
224 |
heimbach |
1.9 |
cph( |
225 |
|
|
globfldtmp2(i,bi,ip,j,bj,jp) = cbuff(cbuffindex) |
226 |
|
|
cph) |
227 |
heimbach |
1.13 |
#ifdef ALLOW_ADMTLM |
228 |
|
|
nveccount = nveccount + 1 |
229 |
jmc |
1.19 |
globfld3d(i,bi,ip,j,bj,jp,k) = |
230 |
heimbach |
1.14 |
& phtmpadmtlm(nveccount) |
231 |
|
|
cph( |
232 |
jmc |
1.19 |
globfldtmp2(i,bi,ip,j,bj,jp) = |
233 |
heimbach |
1.14 |
& phtmpadmtlm(nveccount) |
234 |
|
|
cph) |
235 |
heimbach |
1.13 |
#endif |
236 |
gforget |
1.18 |
#ifndef ALLOW_SMOOTH_CORREL3D |
237 |
heimbach |
1.2 |
#ifdef ALLOW_NONDIMENSIONAL_CONTROL_IO |
238 |
heimbach |
1.9 |
if ( lxxadxx ) then |
239 |
heimbach |
1.10 |
globfld3d(i,bi,ip,j,bj,jp,k) = delZnorm |
240 |
|
|
& * globfld3d(i,bi,ip,j,bj,jp,k) |
241 |
heimbach |
1.9 |
# ifdef CTRL_UNPACK_PRECISE |
242 |
heimbach |
1.10 |
& / sqrt(weightfld3d(i,bi,ip,j,bj,jp,k)) |
243 |
heimbach |
1.9 |
# else |
244 |
heimbach |
1.10 |
& / sqrt(weightfld(k,bi,bj)) |
245 |
heimbach |
1.9 |
# endif |
246 |
|
|
else |
247 |
heimbach |
1.10 |
globfld3d(i,bi,ip,j,bj,jp,k) = delZnorm |
248 |
|
|
& * globfld3d(i,bi,ip,j,bj,jp,k) |
249 |
heimbach |
1.3 |
# ifdef CTRL_UNPACK_PRECISE |
250 |
heimbach |
1.9 |
& * sqrt(weightfld3d(i,bi,ip,j,bj,jp,k)) |
251 |
heimbach |
1.3 |
# else |
252 |
heimbach |
1.9 |
& * sqrt(weightfld(k,bi,bj)) |
253 |
heimbach |
1.3 |
# endif |
254 |
heimbach |
1.9 |
endif |
255 |
heimbach |
1.3 |
#endif /* ALLOW_NONDIMENSIONAL_CONTROL_IO */ |
256 |
gforget |
1.18 |
#endif / * ALLOW_SMOOTH_CORREL3D * / |
257 |
heimbach |
1.2 |
else |
258 |
|
|
globfld3d(i,bi,ip,j,bj,jp,k) = 0. _d 0 |
259 |
|
|
endif |
260 |
heimbach |
1.9 |
cph( |
261 |
|
|
globfldtmp3(i,bi,ip,j,bj,jp) = |
262 |
|
|
& globfld3d(i,bi,ip,j,bj,jp,k) |
263 |
|
|
cph) |
264 |
heimbach |
1.2 |
enddo |
265 |
|
|
enddo |
266 |
|
|
enddo |
267 |
|
|
enddo |
268 |
|
|
enddo |
269 |
|
|
enddo |
270 |
|
|
c |
271 |
heimbach |
1.9 |
if ( doPackDiag ) then |
272 |
|
|
write(cunit2,rec=irectrue) globfldtmp2 |
273 |
|
|
write(cunit3,rec=irectrue) globfldtmp3 |
274 |
|
|
endif |
275 |
|
|
c |
276 |
heimbach |
1.2 |
enddo |
277 |
jmc |
1.19 |
|
278 |
heimbach |
1.2 |
call MDSWRITEFIELD_3D_GL( fname, ctrlprec, 'RL', |
279 |
|
|
& Nr, globfld3d, |
280 |
|
|
& irec, optimcycle, mythid) |
281 |
|
|
|
282 |
|
|
enddo |
283 |
|
|
|
284 |
heimbach |
1.9 |
if ( doPackDiag ) then |
285 |
|
|
close ( cunit2 ) |
286 |
|
|
close ( cunit3 ) |
287 |
|
|
endif |
288 |
|
|
|
289 |
heimbach |
1.2 |
_END_MASTER( mythid ) |
290 |
|
|
|
291 |
heimbach |
1.17 |
#endif |
292 |
|
|
|
293 |
heimbach |
1.2 |
return |
294 |
|
|
end |
295 |
|
|
|