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 |
write(cunit) (nWetvGlobal(k), k=1,nr) |
226 |
#ifdef ALLOW_OBCSN_CONTROL |
227 |
write(cunit) ((nWetobcsnGlo(k,iobcs), k=1,nr),iobcs= 1,nobcs) |
228 |
#endif |
229 |
#ifdef ALLOW_OBCSS_CONTROL |
230 |
write(cunit) ((nWetobcssGlo(k,iobcs), k=1,nr),iobcs= 1,nobcs) |
231 |
#endif |
232 |
#ifdef ALLOW_OBCSW_CONTROL |
233 |
write(cunit) ((nWetobcswGlo(k,iobcs), k=1,nr),iobcs= 1,nobcs) |
234 |
#endif |
235 |
#ifdef ALLOW_OBCSE_CONTROL |
236 |
write(cunit) ((nWetobcseGlo(k,iobcs), k=1,nr),iobcs= 1,nobcs) |
237 |
#endif |
238 |
write(cunit) (ncvarindex(i), i=1,maxcvars) |
239 |
write(cunit) (ncvarrecs(i), i=1,maxcvars) |
240 |
write(cunit) (nx, i=1,maxcvars) |
241 |
write(cunit) (ny, i=1,maxcvars) |
242 |
write(cunit) (ncvarnrmax(i), i=1,maxcvars) |
243 |
write(cunit) (ncvargrd(i), i=1,maxcvars) |
244 |
write(cunit) |
245 |
|
246 |
#ifdef ALLOW_THETA0_CONTROL |
247 |
ivartype = 1 |
248 |
call ctrl_set_pack_xyz( |
249 |
& cunit, ivartype, adfname_theta, "hFacC", |
250 |
& wtheta, lxxadxx, mythid) |
251 |
#endif |
252 |
|
253 |
#ifdef ALLOW_SALT0_CONTROL |
254 |
ivartype = 2 |
255 |
call ctrl_set_pack_xyz( |
256 |
& cunit, ivartype, adfname_salt, "hFacC", |
257 |
& wsalt, lxxadxx, mythid) |
258 |
#endif |
259 |
|
260 |
#if (defined (ALLOW_HFLUX_CONTROL) || \ |
261 |
defined (ALLOW_HFLUX0_CONTROL)) |
262 |
ivartype = 3 |
263 |
write(weighttype(1:80),'(80a)') ' ' |
264 |
write(weighttype(1:80),'(a)') "whflux" |
265 |
call ctrl_set_pack_xy( |
266 |
& cunit, ivartype, adfname_hflux, "hFacC", weighttype, |
267 |
& lxxadxx, mythid) |
268 |
#endif |
269 |
|
270 |
#if (defined (ALLOW_SFLUX_CONTROL) || \ |
271 |
defined (ALLOW_SFLUX0_CONTROL)) |
272 |
ivartype = 4 |
273 |
write(weighttype(1:80),'(80a)') ' ' |
274 |
write(weighttype(1:80),'(a)') "wsflux" |
275 |
call ctrl_set_pack_xy( |
276 |
& cunit, ivartype, adfname_sflux, "hFacC", weighttype, |
277 |
& lxxadxx, mythid) |
278 |
#endif |
279 |
|
280 |
#if (defined (ALLOW_USTRESS_CONTROL) || \ |
281 |
defined (ALLOW_TAUU0_CONTROL)) |
282 |
ivartype = 5 |
283 |
write(weighttype(1:80),'(80a)') ' ' |
284 |
write(weighttype(1:80),'(a)') "wtauu" |
285 |
call ctrl_set_pack_xy( |
286 |
& cunit, ivartype, adfname_tauu, "maskW", weighttype, |
287 |
& lxxadxx, mythid) |
288 |
#endif |
289 |
|
290 |
#if (defined (ALLOW_VSTRESS_CONTROL) || \ |
291 |
defined (ALLOW_TAUV0_CONTROL)) |
292 |
ivartype = 6 |
293 |
write(weighttype(1:80),'(80a)') ' ' |
294 |
write(weighttype(1:80),'(a)') "wtauv" |
295 |
call ctrl_set_pack_xy( |
296 |
& cunit, ivartype, adfname_tauv, "maskS", weighttype, |
297 |
& lxxadxx, mythid) |
298 |
#endif |
299 |
|
300 |
#ifdef ALLOW_ATEMP_CONTROL |
301 |
ivartype = 7 |
302 |
write(weighttype(1:80),'(80a)') ' ' |
303 |
write(weighttype(1:80),'(a)') "watemp" |
304 |
call ctrl_set_pack_xy( |
305 |
& cunit, ivartype, adfname_atemp, "hFacC", weighttype, |
306 |
& lxxadxx, mythid) |
307 |
#endif |
308 |
|
309 |
#ifdef ALLOW_AQH_CONTROL |
310 |
ivartype = 8 |
311 |
write(weighttype(1:80),'(80a)') ' ' |
312 |
write(weighttype(1:80),'(a)') "waqh" |
313 |
call ctrl_set_pack_xy( |
314 |
& cunit, ivartype, adfname_aqh, "hFacC", weighttype, |
315 |
& lxxadxx, mythid) |
316 |
#endif |
317 |
|
318 |
#ifdef ALLOW_UWIND_CONTROL |
319 |
ivartype = 9 |
320 |
write(weighttype(1:80),'(80a)') ' ' |
321 |
write(weighttype(1:80),'(a)') "wuwind" |
322 |
call ctrl_set_pack_xy( |
323 |
& cunit, ivartype, adfname_uwind, "maskW", weighttype, |
324 |
& lxxadxx, mythid) |
325 |
#endif |
326 |
|
327 |
#ifdef ALLOW_VWIND_CONTROL |
328 |
ivartype = 10 |
329 |
write(weighttype(1:80),'(80a)') ' ' |
330 |
write(weighttype(1:80),'(a)') "wvwind" |
331 |
call ctrl_set_pack_xy( |
332 |
& cunit, ivartype, adfname_vwind, "maskS", weighttype, |
333 |
& lxxadxx, mythid) |
334 |
#endif |
335 |
|
336 |
#ifdef ALLOW_OBCSN_CONTROL |
337 |
ivartype = 11 |
338 |
call ctrl_set_pack_xz( |
339 |
& cunit, ivartype, adfname_obcsn, "maskobcsn", |
340 |
& wobcsn, lxxadxx, mythid) |
341 |
#endif |
342 |
|
343 |
#ifdef ALLOW_OBCSS_CONTROL |
344 |
ivartype = 12 |
345 |
call ctrl_set_pack_xz( |
346 |
& cunit, ivartype, adfname_obcss, "maskobcss", |
347 |
& wobcss, lxxadxx, mythid) |
348 |
#endif |
349 |
|
350 |
#ifdef ALLOW_OBCSW_CONTROL |
351 |
ivartype = 13 |
352 |
call ctrl_set_pack_yz( |
353 |
& cunit, ivartype, adfname_obcsw, "maskobcsw", |
354 |
& wobcsw, lxxadxx, mythid) |
355 |
#endif |
356 |
|
357 |
#ifdef ALLOW_OBCSE_CONTROL |
358 |
ivartype = 14 |
359 |
call ctrl_set_pack_yz( |
360 |
& cunit, ivartype, adfname_obcse, "maskobcse", |
361 |
& wobcse, lxxadxx, mythid) |
362 |
#endif |
363 |
|
364 |
#ifdef ALLOW_DIFFKR_CONTROL |
365 |
ivartype = 15 |
366 |
call ctrl_set_pack_xyz( |
367 |
& cunit, ivartype, adfname_diffkr, "hFacC", |
368 |
& wunit, lxxadxx, mythid) |
369 |
#endif |
370 |
|
371 |
#ifdef ALLOW_KAPGM_CONTROL |
372 |
ivartype = 16 |
373 |
call ctrl_set_pack_xyz( |
374 |
& cunit, ivartype, adfname_kapgm, "hFacC", |
375 |
& wunit, lxxadxx, mythid) |
376 |
#endif |
377 |
|
378 |
#ifdef ALLOW_TR10_CONTROL |
379 |
ivartype = 17 |
380 |
call ctrl_set_pack_xyz( |
381 |
& cunit, ivartype, adfname_tr1, "hFacC", |
382 |
& wunit, lxxadxx, mythid) |
383 |
#endif |
384 |
|
385 |
#ifdef ALLOW_SST0_CONTROL |
386 |
ivartype = 18 |
387 |
write(weighttype(1:80),'(80a)') ' ' |
388 |
write(weighttype(1:80),'(a)') "wsst0" |
389 |
call ctrl_set_pack_xy( |
390 |
& cunit, ivartype, adfname_sst0, "hFacC", weighttype, |
391 |
& lxxadxx, mythid) |
392 |
#endif |
393 |
|
394 |
#ifdef ALLOW_SSS0_CONTROL |
395 |
ivartype = 19 |
396 |
write(weighttype(1:80),'(80a)') ' ' |
397 |
write(weighttype(1:80),'(a)') "wsss0" |
398 |
call ctrl_set_pack_xy( |
399 |
& cunit, ivartype, adfname_sss0, "hFacC", weighttype, |
400 |
& lxxadxx, mythid) |
401 |
#endif |
402 |
|
403 |
#ifdef ALLOW_HFACC_CONTROL |
404 |
ivartype = 20 |
405 |
#ifdef ALLOW_HFACC3D_CONTROL |
406 |
call ctrl_set_pack_xyz( |
407 |
& cunit, ivartype, adfname_hfacc, "hFacC", |
408 |
& wunit, lxxadxx, mythid) |
409 |
#else |
410 |
write(weighttype(1:80),'(80a)') ' ' |
411 |
write(weighttype(1:80),'(a)') "whfacc" |
412 |
call ctrl_set_pack_xy( |
413 |
& cunit, ivartype, adfname_hfacc, "hFacC", weighttype, |
414 |
& lxxadxx, mythid) |
415 |
#endif |
416 |
#endif |
417 |
|
418 |
#ifdef ALLOW_EFLUXY0_CONTROL |
419 |
ivartype = 21 |
420 |
call ctrl_set_pack_xyz( |
421 |
& cunit, ivartype, adfname_efluxy, "hFacS", |
422 |
& wunit, lxxadxx, mythid) |
423 |
#endif |
424 |
|
425 |
#ifdef ALLOW_EFLUXP0_CONTROL |
426 |
ivartype = 22 |
427 |
call ctrl_set_pack_xyz( |
428 |
& cunit, ivartype, adfname_efluxp, "hFacV", |
429 |
& wunit, lxxadxx, mythid) |
430 |
#endif |
431 |
|
432 |
#ifdef ALLOW_BOTTOMDRAG_CONTROL |
433 |
ivartype = 23 |
434 |
write(weighttype(1:80),'(80a)') ' ' |
435 |
write(weighttype(1:80),'(a)') "wbottomdrag" |
436 |
call ctrl_set_pack_xy( |
437 |
& cunit, ivartype, adfname_bottomdrag, "hFacC", weighttype, |
438 |
& lxxadxx, mythid) |
439 |
#endif |
440 |
|
441 |
close ( cunit ) |
442 |
|
443 |
_END_MASTER( mythid ) |
444 |
|
445 |
return |
446 |
end |
447 |
|