1 |
|
2 |
#include "CTRL_CPPOPTIONS.h" |
3 |
|
4 |
CBOP |
5 |
C !ROUTINE: ctrl_pack |
6 |
C !INTERFACE: |
7 |
subroutine ctrl_pack( myiter, mytime, mythid ) |
8 |
|
9 |
C !DESCRIPTION: \bv |
10 |
c *================================================================= |
11 |
c | SUBROUTINE ctrl_pack |
12 |
c | Pack the control vector |
13 |
c | * All control variable and adjoint variable fields are |
14 |
c | read from disk. |
15 |
c | * Wet points are extracted, and elements are |
16 |
c | normalized (optional) |
17 |
c | * A single control vector containing only (normalized |
18 |
c | wet points is written to file. |
19 |
c *================================================================= |
20 |
C \ev |
21 |
|
22 |
C !USES: |
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 "ecco.h" |
33 |
#include "ctrl.h" |
34 |
#include "cost.h" |
35 |
|
36 |
#ifdef ALLOW_ECCO_OPTIMIZATION |
37 |
#include "optim.h" |
38 |
#endif |
39 |
|
40 |
c == routine arguments == |
41 |
|
42 |
integer myiter |
43 |
_RL mytime |
44 |
integer mythid |
45 |
|
46 |
c == local variables == |
47 |
|
48 |
#ifndef ALLOW_ECCO_OPTIMIZATION |
49 |
integer optimcycle |
50 |
#endif |
51 |
|
52 |
integer i, j, k |
53 |
integer ii |
54 |
integer il |
55 |
integer irec |
56 |
integer ig,jg |
57 |
integer ivartype |
58 |
integer iobcs |
59 |
|
60 |
logical doglobalread |
61 |
logical ladinit |
62 |
integer cbuffindex |
63 |
|
64 |
integer cunit |
65 |
_RL tmpvar |
66 |
|
67 |
character*(128) cfile |
68 |
character*( 80) weighttype |
69 |
|
70 |
character*( 80) fname_theta |
71 |
character*( 80) fname_salt |
72 |
character*( 80) fname_hflux |
73 |
character*( 80) fname_sflux |
74 |
character*( 80) fname_tauu |
75 |
character*( 80) fname_tauv |
76 |
character*( 80) adfname_theta |
77 |
character*( 80) adfname_salt |
78 |
character*( 80) adfname_hflux |
79 |
character*( 80) adfname_sflux |
80 |
character*( 80) adfname_tauu |
81 |
character*( 80) adfname_tauv |
82 |
character*( 80) fname_atemp |
83 |
character*( 80) adfname_atemp |
84 |
character*( 80) fname_aqh |
85 |
character*( 80) adfname_aqh |
86 |
character*( 80) fname_uwind |
87 |
character*( 80) adfname_uwind |
88 |
character*( 80) fname_vwind |
89 |
character*( 80) adfname_vwind |
90 |
character*( 80) fname_obcsn |
91 |
character*( 80) adfname_obcsn |
92 |
character*( 80) fname_obcss |
93 |
character*( 80) adfname_obcss |
94 |
character*( 80) fname_obcsw |
95 |
character*( 80) adfname_obcsw |
96 |
character*( 80) fname_obcse |
97 |
character*( 80) adfname_obcse |
98 |
character*( 80) fname_diffkr |
99 |
character*( 80) adfname_diffkr |
100 |
character*( 80) fname_kapgm |
101 |
character*( 80) adfname_kapgm |
102 |
character*( 80) fname_tr1 |
103 |
character*( 80) adfname_tr1 |
104 |
character*( 80) fname_sst |
105 |
character*( 80) adfname_sst |
106 |
character*( 80) fname_sss |
107 |
character*( 80) adfname_sss |
108 |
character*( 80) fname_hfacc |
109 |
character*( 80) adfname_hfacc |
110 |
character*( 80) fname_efluxy |
111 |
character*( 80) adfname_efluxy |
112 |
character*( 80) fname_efluxp |
113 |
character*( 80) adfname_efluxp |
114 |
character*( 80) fname_bottomdrag |
115 |
character*( 80) adfname_bottomdrag |
116 |
|
117 |
logical lxxadxx |
118 |
|
119 |
c == external == |
120 |
|
121 |
integer ilnblnk |
122 |
external ilnblnk |
123 |
|
124 |
c == end of interface == |
125 |
|
126 |
#ifndef ALLOW_ECCO_OPTIMIZATION |
127 |
optimcycle = 0 |
128 |
#endif |
129 |
|
130 |
tmpvar = -9999. _d 0 |
131 |
|
132 |
c-- Tiled files are used. |
133 |
doglobalread = .false. |
134 |
|
135 |
c-- Initialise adjoint variables on active files. |
136 |
ladinit = .false. |
137 |
|
138 |
c-- Assign file names. |
139 |
|
140 |
call ctrl_set_fname( |
141 |
I xx_theta_file, fname_theta, adfname_theta, mythid ) |
142 |
call ctrl_set_fname( |
143 |
I xx_salt_file, fname_salt, adfname_salt, mythid ) |
144 |
call ctrl_set_fname( |
145 |
I xx_hflux_file, fname_hflux, adfname_hflux, mythid ) |
146 |
call ctrl_set_fname( |
147 |
I xx_sflux_file, fname_sflux, adfname_sflux, mythid ) |
148 |
call ctrl_set_fname( |
149 |
I xx_tauu_file, fname_tauu, adfname_tauu, mythid ) |
150 |
call ctrl_set_fname( |
151 |
I xx_tauv_file, fname_tauv, adfname_tauv, mythid ) |
152 |
call ctrl_set_fname( |
153 |
I xx_atemp_file, fname_atemp, adfname_atemp, mythid ) |
154 |
call ctrl_set_fname( |
155 |
I xx_aqh_file, fname_aqh, adfname_aqh, mythid ) |
156 |
call ctrl_set_fname( |
157 |
I xx_uwind_file, fname_uwind, adfname_uwind, mythid ) |
158 |
call ctrl_set_fname( |
159 |
I xx_vwind_file, fname_vwind, adfname_vwind, mythid ) |
160 |
call ctrl_set_fname( |
161 |
I xx_obcsn_file, fname_obcsn, adfname_obcsn, mythid ) |
162 |
call ctrl_set_fname( |
163 |
I xx_obcss_file, fname_obcss, adfname_obcss, mythid ) |
164 |
call ctrl_set_fname( |
165 |
I xx_obcsw_file, fname_obcsw, adfname_obcsw, mythid ) |
166 |
call ctrl_set_fname( |
167 |
I xx_obcse_file, fname_obcse, adfname_obcse, mythid ) |
168 |
call ctrl_set_fname( |
169 |
I xx_diffkr_file, fname_diffkr, adfname_diffkr, mythid ) |
170 |
call ctrl_set_fname( |
171 |
I xx_kapgm_file, fname_kapgm, adfname_kapgm, mythid ) |
172 |
call ctrl_set_fname( |
173 |
I xx_tr1_file, fname_tr1, adfname_tr1, mythid ) |
174 |
call ctrl_set_fname( |
175 |
I xx_sst_file, fname_sst, adfname_sst, mythid ) |
176 |
call ctrl_set_fname( |
177 |
I xx_sss_file, fname_sss, adfname_sss, mythid ) |
178 |
call ctrl_set_fname( |
179 |
I xx_hfacc_file, fname_hfacc, adfname_hfacc, mythid ) |
180 |
call ctrl_set_fname( |
181 |
I xx_efluxy_file, fname_efluxy, adfname_efluxy, mythid ) |
182 |
call ctrl_set_fname( |
183 |
I xx_efluxp_file, fname_efluxp, adfname_efluxp, mythid ) |
184 |
call ctrl_set_fname( |
185 |
I xx_bottomdrag_file, fname_bottomdrag, adfname_bottomdrag |
186 |
I , mythid ) |
187 |
|
188 |
c |
189 |
c-- Only the master thread will do I/O. |
190 |
_BEGIN_MASTER( mythid ) |
191 |
|
192 |
c >>> Write control vector <<< |
193 |
|
194 |
cph this part was removed since it's not necessary |
195 |
cph and causes huge amounts of wall clock time on parallel machines |
196 |
|
197 |
|
198 |
|
199 |
c >>> Write gradient vector <<< |
200 |
lxxadxx = .FALSE. |
201 |
|
202 |
call mdsfindunit( cunit, mythid ) |
203 |
write(cfile(1:128),'(4a,i4.4)') |
204 |
& costname(1:9),'_',yctrlid(1:10),'.opt', |
205 |
& optimcycle |
206 |
|
207 |
open( cunit, file = cfile, |
208 |
& status = 'unknown', |
209 |
& form = 'unformatted', |
210 |
& access = 'sequential' ) |
211 |
|
212 |
c-- Header information. |
213 |
write(cunit) nvartype |
214 |
write(cunit) nvarlength |
215 |
write(cunit) yctrlid |
216 |
write(cunit) optimCycle |
217 |
write(cunit) fc |
218 |
write(cunit) 1 |
219 |
write(cunit) 1 |
220 |
write(cunit) 1 |
221 |
write(cunit) 1 |
222 |
write(cunit) (nWetcGlobal(k), k=1,nr) |
223 |
write(cunit) (nWetsGlobal(k), k=1,nr) |
224 |
write(cunit) (nWetwGlobal(k), k=1,nr) |
225 |
#ifdef ALLOW_CTRL_WETV |
226 |
write(cunit) (nWetvGlobal(k), k=1,nr) |
227 |
#endif |
228 |
#ifdef ALLOW_OBCSN_CONTROL |
229 |
write(cunit) ((nWetobcsnGlo(k,iobcs), k=1,nr),iobcs= 1,nobcs) |
230 |
#endif |
231 |
#ifdef ALLOW_OBCSS_CONTROL |
232 |
write(cunit) ((nWetobcssGlo(k,iobcs), k=1,nr),iobcs= 1,nobcs) |
233 |
#endif |
234 |
#ifdef ALLOW_OBCSW_CONTROL |
235 |
write(cunit) ((nWetobcswGlo(k,iobcs), k=1,nr),iobcs= 1,nobcs) |
236 |
#endif |
237 |
#ifdef ALLOW_OBCSE_CONTROL |
238 |
write(cunit) ((nWetobcseGlo(k,iobcs), k=1,nr),iobcs= 1,nobcs) |
239 |
#endif |
240 |
write(cunit) (ncvarindex(i), i=1,maxcvars) |
241 |
write(cunit) (ncvarrecs(i), i=1,maxcvars) |
242 |
write(cunit) (nx, i=1,maxcvars) |
243 |
write(cunit) (ny, i=1,maxcvars) |
244 |
write(cunit) (ncvarnrmax(i), i=1,maxcvars) |
245 |
write(cunit) (ncvargrd(i), i=1,maxcvars) |
246 |
write(cunit) |
247 |
|
248 |
#ifdef ALLOW_THETA0_CONTROL |
249 |
ivartype = 1 |
250 |
call ctrl_set_pack_xyz( |
251 |
& cunit, ivartype, adfname_theta, "hFacC", |
252 |
& wtheta, lxxadxx, mythid) |
253 |
#endif |
254 |
|
255 |
#ifdef ALLOW_SALT0_CONTROL |
256 |
ivartype = 2 |
257 |
call ctrl_set_pack_xyz( |
258 |
& cunit, ivartype, adfname_salt, "hFacC", |
259 |
& wsalt, lxxadxx, mythid) |
260 |
#endif |
261 |
|
262 |
#if (defined (ALLOW_HFLUX_CONTROL) || \ |
263 |
defined (ALLOW_HFLUX0_CONTROL)) |
264 |
ivartype = 3 |
265 |
write(weighttype(1:80),'(80a)') ' ' |
266 |
write(weighttype(1:80),'(a)') "whflux" |
267 |
call ctrl_set_pack_xy( |
268 |
& cunit, ivartype, adfname_hflux, "hFacC", weighttype, |
269 |
& lxxadxx, mythid) |
270 |
#endif |
271 |
|
272 |
#if (defined (ALLOW_SFLUX_CONTROL) || \ |
273 |
defined (ALLOW_SFLUX0_CONTROL)) |
274 |
ivartype = 4 |
275 |
write(weighttype(1:80),'(80a)') ' ' |
276 |
write(weighttype(1:80),'(a)') "wsflux" |
277 |
call ctrl_set_pack_xy( |
278 |
& cunit, ivartype, adfname_sflux, "hFacC", weighttype, |
279 |
& lxxadxx, mythid) |
280 |
#endif |
281 |
|
282 |
#if (defined (ALLOW_USTRESS_CONTROL) || \ |
283 |
defined (ALLOW_TAUU0_CONTROL)) |
284 |
ivartype = 5 |
285 |
write(weighttype(1:80),'(80a)') ' ' |
286 |
write(weighttype(1:80),'(a)') "wtauu" |
287 |
call ctrl_set_pack_xy( |
288 |
& cunit, ivartype, adfname_tauu, "maskW", weighttype, |
289 |
& lxxadxx, mythid) |
290 |
#endif |
291 |
|
292 |
#if (defined (ALLOW_VSTRESS_CONTROL) || \ |
293 |
defined (ALLOW_TAUV0_CONTROL)) |
294 |
ivartype = 6 |
295 |
write(weighttype(1:80),'(80a)') ' ' |
296 |
write(weighttype(1:80),'(a)') "wtauv" |
297 |
call ctrl_set_pack_xy( |
298 |
& cunit, ivartype, adfname_tauv, "maskS", weighttype, |
299 |
& lxxadxx, mythid) |
300 |
#endif |
301 |
|
302 |
#ifdef ALLOW_ATEMP_CONTROL |
303 |
ivartype = 7 |
304 |
write(weighttype(1:80),'(80a)') ' ' |
305 |
write(weighttype(1:80),'(a)') "watemp" |
306 |
call ctrl_set_pack_xy( |
307 |
& cunit, ivartype, adfname_atemp, "hFacC", weighttype, |
308 |
& lxxadxx, mythid) |
309 |
#endif |
310 |
|
311 |
#ifdef ALLOW_AQH_CONTROL |
312 |
ivartype = 8 |
313 |
write(weighttype(1:80),'(80a)') ' ' |
314 |
write(weighttype(1:80),'(a)') "waqh" |
315 |
call ctrl_set_pack_xy( |
316 |
& cunit, ivartype, adfname_aqh, "hFacC", weighttype, |
317 |
& lxxadxx, mythid) |
318 |
#endif |
319 |
|
320 |
#ifdef ALLOW_UWIND_CONTROL |
321 |
ivartype = 9 |
322 |
write(weighttype(1:80),'(80a)') ' ' |
323 |
write(weighttype(1:80),'(a)') "wuwind" |
324 |
call ctrl_set_pack_xy( |
325 |
& cunit, ivartype, adfname_uwind, "maskW", weighttype, |
326 |
& lxxadxx, mythid) |
327 |
#endif |
328 |
|
329 |
#ifdef ALLOW_VWIND_CONTROL |
330 |
ivartype = 10 |
331 |
write(weighttype(1:80),'(80a)') ' ' |
332 |
write(weighttype(1:80),'(a)') "wvwind" |
333 |
call ctrl_set_pack_xy( |
334 |
& cunit, ivartype, adfname_vwind, "maskS", weighttype, |
335 |
& lxxadxx, mythid) |
336 |
#endif |
337 |
|
338 |
#ifdef ALLOW_OBCSN_CONTROL |
339 |
ivartype = 11 |
340 |
call ctrl_set_pack_xz( |
341 |
& cunit, ivartype, adfname_obcsn, "maskobcsn", |
342 |
& wobcsn, lxxadxx, mythid) |
343 |
#endif |
344 |
|
345 |
#ifdef ALLOW_OBCSS_CONTROL |
346 |
ivartype = 12 |
347 |
call ctrl_set_pack_xz( |
348 |
& cunit, ivartype, adfname_obcss, "maskobcss", |
349 |
& wobcss, lxxadxx, mythid) |
350 |
#endif |
351 |
|
352 |
#ifdef ALLOW_OBCSW_CONTROL |
353 |
ivartype = 13 |
354 |
call ctrl_set_pack_yz( |
355 |
& cunit, ivartype, adfname_obcsw, "maskobcsw", |
356 |
& wobcsw, lxxadxx, mythid) |
357 |
#endif |
358 |
|
359 |
#ifdef ALLOW_OBCSE_CONTROL |
360 |
ivartype = 14 |
361 |
call ctrl_set_pack_yz( |
362 |
& cunit, ivartype, adfname_obcse, "maskobcse", |
363 |
& wobcse, lxxadxx, mythid) |
364 |
#endif |
365 |
|
366 |
#ifdef ALLOW_DIFFKR_CONTROL |
367 |
ivartype = 15 |
368 |
call ctrl_set_pack_xyz( |
369 |
& cunit, ivartype, adfname_diffkr, "hFacC", |
370 |
& wunit, lxxadxx, mythid) |
371 |
#endif |
372 |
|
373 |
#ifdef ALLOW_KAPGM_CONTROL |
374 |
ivartype = 16 |
375 |
call ctrl_set_pack_xyz( |
376 |
& cunit, ivartype, adfname_kapgm, "hFacC", |
377 |
& wunit, lxxadxx, mythid) |
378 |
#endif |
379 |
|
380 |
#ifdef ALLOW_TR10_CONTROL |
381 |
ivartype = 17 |
382 |
call ctrl_set_pack_xyz( |
383 |
& cunit, ivartype, adfname_tr1, "hFacC", |
384 |
& wunit, lxxadxx, mythid) |
385 |
#endif |
386 |
|
387 |
#ifdef ALLOW_SST0_CONTROL |
388 |
ivartype = 18 |
389 |
write(weighttype(1:80),'(80a)') ' ' |
390 |
write(weighttype(1:80),'(a)') "wsst0" |
391 |
call ctrl_set_pack_xy( |
392 |
& cunit, ivartype, adfname_sst0, "hFacC", weighttype, |
393 |
& lxxadxx, mythid) |
394 |
#endif |
395 |
|
396 |
#ifdef ALLOW_SSS0_CONTROL |
397 |
ivartype = 19 |
398 |
write(weighttype(1:80),'(80a)') ' ' |
399 |
write(weighttype(1:80),'(a)') "wsss0" |
400 |
call ctrl_set_pack_xy( |
401 |
& cunit, ivartype, adfname_sss0, "hFacC", weighttype, |
402 |
& lxxadxx, mythid) |
403 |
#endif |
404 |
|
405 |
#ifdef ALLOW_HFACC_CONTROL |
406 |
ivartype = 20 |
407 |
#ifdef ALLOW_HFACC3D_CONTROL |
408 |
call ctrl_set_pack_xyz( |
409 |
& cunit, ivartype, adfname_hfacc, "hFacC", |
410 |
& wunit, lxxadxx, mythid) |
411 |
#else |
412 |
write(weighttype(1:80),'(80a)') ' ' |
413 |
write(weighttype(1:80),'(a)') "whfacc" |
414 |
call ctrl_set_pack_xy( |
415 |
& cunit, ivartype, adfname_hfacc, "hFacC", weighttype, |
416 |
& lxxadxx, mythid) |
417 |
#endif |
418 |
#endif |
419 |
|
420 |
#ifdef ALLOW_EFLUXY0_CONTROL |
421 |
ivartype = 21 |
422 |
call ctrl_set_pack_xyz( |
423 |
& cunit, ivartype, adfname_efluxy, "hFacS", |
424 |
& wunit, lxxadxx, mythid) |
425 |
#endif |
426 |
|
427 |
#ifdef ALLOW_EFLUXP0_CONTROL |
428 |
ivartype = 22 |
429 |
call ctrl_set_pack_xyz( |
430 |
& cunit, ivartype, adfname_efluxp, "hFacV", |
431 |
& wunit, lxxadxx, mythid) |
432 |
#endif |
433 |
|
434 |
#ifdef ALLOW_BOTTOMDRAG_CONTROL |
435 |
ivartype = 23 |
436 |
write(weighttype(1:80),'(80a)') ' ' |
437 |
write(weighttype(1:80),'(a)') "wbottomdrag" |
438 |
call ctrl_set_pack_xy( |
439 |
& cunit, ivartype, adfname_bottomdrag, "hFacC", weighttype, |
440 |
& lxxadxx, mythid) |
441 |
#endif |
442 |
|
443 |
close ( cunit ) |
444 |
|
445 |
_END_MASTER( mythid ) |
446 |
|
447 |
return |
448 |
end |
449 |
|