forked from altMITgcm/MITgcm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
admtlm_model2dsvd.F
547 lines (474 loc) · 17.5 KB
/
admtlm_model2dsvd.F
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
C $Header: /u/gcmpack/MITgcm/pkg/admtlm/admtlm_model2dsvd.F,v 1.9 2012/08/12 18:29:25 jmc Exp $
C $Name: $
#include "ADMTLM_OPTIONS.h"
#ifdef ALLOW_CTRL
# include "CTRL_OPTIONS.h"
#endif
subroutine admtlm_model2dsvd(
& first, preprocev, mythid )
c ==================================================================
c SUBROUTINE ctrl_pack
c ==================================================================
c
c o Compress the control vector such that only ocean points are
c written to file.
c
c started: Christian Eckert eckert@mit.edu 10-Mar=2000
c
c changed: Patrick Heimbach heimbach@mit.edu 06-Jun-2000
c - Transferred some filename declarations
c from here to namelist in ctrl_init
c
c Patrick Heimbach heimbach@mit.edu 16-Jun-2000
c - single file name convention with or without
c ALLOW_ECCO_OPTIMIZATION
c
c G. Gebbie, added open boundary control packing,
c gebbie@mit.edu 18 -Mar- 2003
c
c heimbach@mit.edu totally restructured 28-Oct-2003
c
c ==================================================================
c SUBROUTINE ctrl_pack
c ==================================================================
implicit none
c == global variables ==
#include "EEPARAMS.h"
#include "SIZE.h"
#include "PARAMS.h"
#include "GRID.h"
#include "ctrl.h"
#include "optim.h"
#ifdef ALLOW_COST
# include "cost.h"
#endif
#ifdef ALLOW_ECCO
# include "ecco_cost.h"
#else
# include "ctrl_weights.h"
#endif
c == routine arguments ==
logical first
logical preprocev
integer mythid
#ifndef EXCLUDE_CTRL_PACK
c == local variables ==
_RL fcloc
integer i, j, k
integer ii
integer il
integer irec
integer ig,jg
integer ivartype
integer iobcs
logical doglobalread
logical ladinit
integer cbuffindex
logical lxxadxx
integer cunit
integer ictrlgrad
character*(128) cfile
character*( 80) weighttype
c == external ==
integer ilnblnk
external ilnblnk
c == end of interface ==
#ifndef ALLOW_ECCO_OPTIMIZATION
fmin = 0. _d 0
#endif
c-- Tiled files are used.
doglobalread = .false.
c-- Initialise adjoint variables on active files.
ladinit = .false.
c-- Initialise global buffer index
nbuffglobal = 0
cph-new(
if ( preprocev ) then
yadprefix = 'ev'
else
yadprefix = 'ad'
endif
nveccount = 0
cph-new)
c-- Assign file names.
call ctrl_set_fname(xx_theta_file, fname_theta, mythid)
call ctrl_set_fname(xx_salt_file, fname_salt, mythid)
call ctrl_set_fname(xx_hflux_file, fname_hflux, mythid)
call ctrl_set_fname(xx_sflux_file, fname_sflux, mythid)
call ctrl_set_fname(xx_tauu_file, fname_tauu, mythid)
call ctrl_set_fname(xx_tauv_file, fname_tauv, mythid)
call ctrl_set_fname(xx_atemp_file, fname_atemp, mythid)
call ctrl_set_fname(xx_aqh_file, fname_aqh, mythid)
call ctrl_set_fname(xx_precip_file, fname_precip, mythid)
call ctrl_set_fname(xx_swflux_file, fname_swflux, mythid)
call ctrl_set_fname(xx_swdown_file, fname_swdown, mythid)
call ctrl_set_fname(xx_uwind_file, fname_uwind, mythid)
call ctrl_set_fname(xx_vwind_file, fname_vwind, mythid)
call ctrl_set_fname(xx_obcsn_file, fname_obcsn, mythid)
call ctrl_set_fname(xx_obcss_file, fname_obcss, mythid)
call ctrl_set_fname(xx_obcsw_file, fname_obcsw, mythid)
call ctrl_set_fname(xx_obcse_file, fname_obcse, mythid)
call ctrl_set_fname(xx_diffkr_file, fname_diffkr, mythid)
call ctrl_set_fname(xx_kapgm_file, fname_kapgm, mythid)
call ctrl_set_fname(xx_tr1_file, fname_tr1, mythid)
call ctrl_set_fname(xx_sst_file, fname_sst, mythid)
call ctrl_set_fname(xx_sss_file, fname_sss, mythid)
call ctrl_set_fname(xx_depth_file, fname_depth, mythid)
call ctrl_set_fname(xx_efluxy_file, fname_efluxy, mythid)
call ctrl_set_fname(xx_efluxp_file, fname_efluxp, mythid)
call ctrl_set_fname(xx_bottomdrag_file, fname_bottomdrag, mythid)
call ctrl_set_fname(xx_edtaux_file, fname_edtaux, mythid)
call ctrl_set_fname(xx_edtauy_file, fname_edtauy, mythid)
call ctrl_set_fname(xx_uvel_file, fname_uvel, mythid)
call ctrl_set_fname(xx_vvel_file, fname_vvel, mythid)
call ctrl_set_fname(xx_etan_file, fname_etan, mythid)
call ctrl_set_fname(xx_relaxsst_file, fname_relaxsst, mythid)
call ctrl_set_fname(xx_relaxsss_file, fname_relaxsss, mythid)
c-- Only the master thread will do I/O.
_BEGIN_MASTER( mythid )
if ( first ) then
c >>> Initialise control vector for optimcycle=0 <<<
lxxadxx = .TRUE.
ictrlgrad = 1
fcloc = fmin
write(cfile(1:128),'(4a,i4.4)')
& ctrlname(1:9),'_',yctrlid(1:10),
& yctrlpospack, optimcycle
print *, 'ph-pack: packing ', ctrlname(1:9)
else
c >>> Write gradient vector <<<
lxxadxx = .FALSE.
ictrlgrad = 2
fcloc = fc
write(cfile(1:128),'(4a,i4.4)')
& costname(1:9),'_',yctrlid(1:10),
& yctrlpospack, optimcycle
print *, 'ph-pack: packing ', costname(1:9)
endif
call mdsfindunit( cunit, mythid )
#ifdef ALLOW_ADMTLM
if ( preprocev ) then
cph do a dummy write of initial EV fields
write(cfile(1:128),'(a)') ' '
write(cfile,'(a,i4.4)')
& 'admtlm_eigen', optimcycle
else
write(cfile(1:128),'(a)') ' '
write(cfile,'(a,i4.4)')
& 'admtlm_vector.it', optimcycle + 1
endif
print *, 'ph-pack: unpacking ', cfile
cph open( cunit, file = cfile,
cph & status = 'unknown',
cph & form = 'unformatted',
cph & access = 'sequential' )
#else /* ndef ALLOW_ADMTLM */
open( cunit, file = cfile,
& status = 'unknown',
& form = 'unformatted',
& access = 'sequential' )
c-- Header information.
write(cunit) nvartype
write(cunit) nvarlength
write(cunit) yctrlid
write(cunit) optimCycle
write(cunit) fc
C place holder of obsolete variable iG
write(cunit) 1
C place holder of obsolete variable jG
write(cunit) 1
write(cunit) nsx
write(cunit) nsy
write(cunit) (nWetcGlobal(k), k=1,nr)
write(cunit) (nWetsGlobal(k), k=1,nr)
write(cunit) (nWetwGlobal(k), k=1,nr)
#ifdef ALLOW_CTRL_WETV
write(cunit) (nWetvGlobal(k), k=1,nr)
#endif
#ifdef ALLOW_OBCSN_CONTROL
write(cunit) ((nWetobcsnGlo(k,iobcs), k=1,nr),iobcs= 1,nobcs)
#endif
#ifdef ALLOW_OBCSS_CONTROL
write(cunit) ((nWetobcssGlo(k,iobcs), k=1,nr),iobcs= 1,nobcs)
#endif
#ifdef ALLOW_OBCSW_CONTROL
write(cunit) ((nWetobcswGlo(k,iobcs), k=1,nr),iobcs= 1,nobcs)
#endif
#ifdef ALLOW_OBCSE_CONTROL
write(cunit) ((nWetobcseGlo(k,iobcs), k=1,nr),iobcs= 1,nobcs)
#endif
write(cunit) (ncvarindex(i), i=1,maxcvars)
write(cunit) (ncvarrecs(i), i=1,maxcvars)
write(cunit) (ncvarxmax(i), i=1,maxcvars)
write(cunit) (ncvarymax(i), i=1,maxcvars)
write(cunit) (ncvarnrmax(i), i=1,maxcvars)
write(cunit) (ncvargrd(i), i=1,maxcvars)
write(cunit)
#endif /* ALLOW_ADMTLM */
#ifdef ALLOW_THETA0_CONTROL
ivartype = 1
write(weighttype(1:80),'(80a)') ' '
write(weighttype(1:80),'(a)') "wtheta"
call ctrl_set_pack_xyz(
& cunit, ivartype, fname_theta(ictrlgrad), "maskCtrlC",
& weighttype, wtheta, lxxadxx, mythid)
#endif
#ifdef ALLOW_SALT0_CONTROL
ivartype = 2
write(weighttype(1:80),'(80a)') ' '
write(weighttype(1:80),'(a)') "wsalt"
call ctrl_set_pack_xyz(
& cunit, ivartype, fname_salt(ictrlgrad), "maskCtrlC",
& weighttype, wsalt, lxxadxx, mythid)
#endif
#if (defined (ALLOW_HFLUX_CONTROL) || defined (ALLOW_HFLUX0_CONTROL))
ivartype = 3
write(weighttype(1:80),'(80a)') ' '
write(weighttype(1:80),'(a)') "whflux"
call ctrl_set_pack_xy(
& cunit, ivartype, fname_hflux(ictrlgrad), "maskCtrlC",
& weighttype, lxxadxx, mythid)
#endif
#if (defined (ALLOW_SFLUX_CONTROL) || defined (ALLOW_SFLUX0_CONTROL))
ivartype = 4
write(weighttype(1:80),'(80a)') ' '
write(weighttype(1:80),'(a)') "wsflux"
call ctrl_set_pack_xy(
& cunit, ivartype, fname_sflux(ictrlgrad), "maskCtrlC",
& weighttype, lxxadxx, mythid)
#endif
#if (defined (ALLOW_USTRESS_CONTROL) || defined (ALLOW_TAUU0_CONTROL))
ivartype = 5
write(weighttype(1:80),'(80a)') ' '
write(weighttype(1:80),'(a)') "wtauu"
call ctrl_set_pack_xy(
& cunit, ivartype, fname_tauu(ictrlgrad), "maskCtrlW",
& weighttype, lxxadxx, mythid)
#endif
#if (defined (ALLOW_VSTRESS_CONTROL) || defined (ALLOW_TAUV0_CONTROL))
ivartype = 6
write(weighttype(1:80),'(80a)') ' '
write(weighttype(1:80),'(a)') "wtauv"
call ctrl_set_pack_xy(
& cunit, ivartype, fname_tauv(ictrlgrad), "maskCtrlS",
& weighttype, lxxadxx, mythid)
#endif
#ifdef ALLOW_ATEMP_CONTROL
ivartype = 7
write(weighttype(1:80),'(80a)') ' '
write(weighttype(1:80),'(a)') "watemp"
call ctrl_set_pack_xy(
& cunit, ivartype, fname_atemp(ictrlgrad), "maskCtrlC",
& weighttype, lxxadxx, mythid)
#endif
#ifdef ALLOW_AQH_CONTROL
ivartype = 8
write(weighttype(1:80),'(80a)') ' '
write(weighttype(1:80),'(a)') "waqh"
call ctrl_set_pack_xy(
& cunit, ivartype, fname_aqh(ictrlgrad), "maskCtrlC",
& weighttype, lxxadxx, mythid)
#endif
#ifdef ALLOW_UWIND_CONTROL
ivartype = 9
write(weighttype(1:80),'(80a)') ' '
write(weighttype(1:80),'(a)') "wuwind"
call ctrl_set_pack_xy(
& cunit, ivartype, fname_uwind(ictrlgrad), "maskCtrlC",
& weighttype, lxxadxx, mythid)
#endif
#ifdef ALLOW_VWIND_CONTROL
ivartype = 10
write(weighttype(1:80),'(80a)') ' '
write(weighttype(1:80),'(a)') "wvwind"
call ctrl_set_pack_xy(
& cunit, ivartype, fname_vwind(ictrlgrad), "maskCtrlC",
& weighttype, lxxadxx, mythid)
#endif
#ifdef ALLOW_OBCSN_CONTROL
ivartype = 11
write(weighttype(1:80),'(80a)') ' '
write(weighttype(1:80),'(a)') "wobcsn"
call ctrl_set_pack_xz(
& cunit, ivartype, fname_obcsn(ictrlgrad), "maskobcsn",
& weighttype, wobcsn, lxxadxx, mythid)
#endif
#ifdef ALLOW_OBCSS_CONTROL
ivartype = 12
write(weighttype(1:80),'(80a)') ' '
write(weighttype(1:80),'(a)') "wobcss"
call ctrl_set_pack_xz(
& cunit, ivartype, fname_obcss(ictrlgrad), "maskobcss",
& weighttype, wobcss, lxxadxx, mythid)
#endif
#ifdef ALLOW_OBCSW_CONTROL
ivartype = 13
write(weighttype(1:80),'(80a)') ' '
write(weighttype(1:80),'(a)') "wobcsw"
call ctrl_set_pack_yz(
& cunit, ivartype, fname_obcsw(ictrlgrad), "maskobcsw",
& weighttype, wobcsw, lxxadxx, mythid)
#endif
#ifdef ALLOW_OBCSE_CONTROL
ivartype = 14
write(weighttype(1:80),'(80a)') ' '
write(weighttype(1:80),'(a)') "wobcse"
call ctrl_set_pack_yz(
& cunit, ivartype, fname_obcse(ictrlgrad), "maskobcse",
& weighttype, wobcse, lxxadxx, mythid)
#endif
#ifdef ALLOW_DIFFKR_CONTROL
ivartype = 15
write(weighttype(1:80),'(80a)') ' '
write(weighttype(1:80),'(a)') "wdiffkr"
call ctrl_set_pack_xyz(
& cunit, ivartype, fname_diffkr(ictrlgrad), "maskCtrlC",
& weighttype, wunit, lxxadxx, mythid)
#endif
#ifdef ALLOW_KAPGM_CONTROL
ivartype = 16
write(weighttype(1:80),'(80a)') ' '
write(weighttype(1:80),'(a)') "wkapgm"
call ctrl_set_pack_xyz(
& cunit, ivartype, fname_kapgm(ictrlgrad), "maskCtrlC",
& weighttype, wunit, lxxadxx, mythid)
#endif
#ifdef ALLOW_TR10_CONTROL
ivartype = 17
write(weighttype(1:80),'(80a)') ' '
write(weighttype(1:80),'(a)') "wtr1"
call ctrl_set_pack_xyz(
& cunit, ivartype, fname_tr1(ictrlgrad), "maskCtrlC",
& weighttype, wunit, lxxadxx, mythid)
#endif
#if (defined (ALLOW_SST_CONTROL) || defined (ALLOW_SST0_CONTROL))
ivartype = 18
write(weighttype(1:80),'(80a)') ' '
write(weighttype(1:80),'(a)') "wsst"
call ctrl_set_pack_xy(
& cunit, ivartype, fname_sst(ictrlgrad), "maskCtrlC",
& weighttype, lxxadxx, mythid)
#endif
#if (defined (ALLOW_SSS_CONTROL) || defined (ALLOW_SSS0_CONTROL))
ivartype = 19
write(weighttype(1:80),'(80a)') ' '
write(weighttype(1:80),'(a)') "wsss"
call ctrl_set_pack_xy(
& cunit, ivartype, fname_sss(ictrlgrad), "maskCtrlC",
& weighttype, lxxadxx, mythid)
#endif
#ifdef ALLOW_DEPTH_CONTROL
ivartype = 20
write(weighttype(1:80),'(80a)') ' '
write(weighttype(1:80),'(a)') "wdepth"
call ctrl_set_pack_xy(
& cunit, ivartype, fname_depth(ictrlgrad), "maskCtrlC",
& weighttype, lxxadxx, mythid)
#endif
#ifdef ALLOW_EFLUXY0_CONTROL
ivartype = 21
write(weighttype(1:80),'(80a)') ' '
write(weighttype(1:80),'(a)') "wefluxy0"
call ctrl_set_pack_xyz(
& cunit, ivartype, fname_efluxy(ictrlgrad), "maskCtrlS",
& weighttype, wunit, lxxadxx, mythid)
#endif
#ifdef ALLOW_EFLUXP0_CONTROL
ivartype = 22
write(weighttype(1:80),'(80a)') ' '
write(weighttype(1:80),'(a)') "wefluxp0"
call ctrl_set_pack_xyz(
& cunit, ivartype, fname_efluxp(ictrlgrad), "maskhFacV",
& weighttype, wunit, lxxadxx, mythid)
#endif
#ifdef ALLOW_BOTTOMDRAG_CONTROL
ivartype = 23
write(weighttype(1:80),'(80a)') ' '
write(weighttype(1:80),'(a)') "wbottomdrag"
call ctrl_set_pack_xy(
& cunit, ivartype, fname_bottomdrag(ictrlgrad), "maskCtrlC",
& weighttype, lxxadxx, mythid)
#endif
#ifdef ALLOW_EDDYPSI_CONTROL
ivartype = 25
write(weighttype(1:80),'(80a)') ' '
write(weighttype(1:80),'(a)') "wedtaux"
call ctrl_set_pack_xyz(
& cunit, ivartype, fname_edtaux(ictrlgrad), "maskCtrlW",
& weighttype, wunit, lxxadxx, mythid)
ivartype = 26
write(weighttype(1:80),'(80a)') ' '
write(weighttype(1:80),'(a)') "wedtauy"
call ctrl_set_pack_xyz(
& cunit, ivartype, fname_edtauy(ictrlgrad), "maskCtrlS",
& weighttype, wunit, lxxadxx, mythid)
#endif
#ifdef ALLOW_UVEL0_CONTROL
ivartype = 27
write(weighttype(1:80),'(80a)') ' '
write(weighttype(1:80),'(a)') "wuvvel"
call ctrl_set_pack_xyz(
& cunit, ivartype, fname_uvel(ictrlgrad), "maskCtrlW",
& weighttype, wuvvel, lxxadxx, mythid)
#endif
#ifdef ALLOW_VVEL0_CONTROL
ivartype = 28
write(weighttype(1:80),'(80a)') ' '
write(weighttype(1:80),'(a)') "wuvvel"
call ctrl_set_pack_xyz(
& cunit, ivartype, fname_vvel(ictrlgrad), "maskCtrlS",
& weighttype, wuvvel, lxxadxx, mythid)
#endif
#ifdef ALLOW_ETAN0_CONTROL
ivartype = 29
write(weighttype(1:80),'(80a)') ' '
write(weighttype(1:80),'(a)') "wetan"
call ctrl_set_pack_xy(
& cunit, ivartype, fname_etan(ictrlgrad), "maskCtrlC",
& weighttype, lxxadxx, mythid)
#endif
#ifdef ALLOW_RELAXSST_CONTROL
ivartype = 30
write(weighttype(1:80),'(80a)') ' '
write(weighttype(1:80),'(a)') "wrelaxsst"
call ctrl_set_pack_xy(
& cunit, ivartype, fname_relaxsst(ictrlgrad), "maskCtrlC",
& weighttype, lxxadxx, mythid)
#endif
#ifdef ALLOW_RELAXSSS_CONTROL
ivartype = 31
write(weighttype(1:80),'(80a)') ' '
write(weighttype(1:80),'(a)') "wrelaxsss"
call ctrl_set_pack_xy(
& cunit, ivartype, fname_relaxsss(ictrlgrad), "maskCtrlC",
& weighttype, lxxadxx, mythid)
#endif
#ifdef ALLOW_PRECIP_CONTROL
ivartype = 32
write(weighttype(1:80),'(80a)') ' '
write(weighttype(1:80),'(a)') "wprecip"
call ctrl_set_pack_xy(
& cunit, ivartype, fname_precip(ictrlgrad), "maskCtrlC",
& weighttype, lxxadxx, mythid)
#endif
#ifdef ALLOW_SWFLUX_CONTROL
ivartype = 33
write(weighttype(1:80),'(80a)') ' '
write(weighttype(1:80),'(a)') "wswflux"
call ctrl_set_pack_xy(
& cunit, ivartype, fname_swflux(ictrlgrad), "maskCtrlC",
& weighttype, lxxadxx, mythid)
#endif
#ifdef ALLOW_SWDOWN_CONTROL
ivartype = 34
write(weighttype(1:80),'(80a)') ' '
write(weighttype(1:80),'(a)') "wswdown"
call ctrl_set_pack_xy(
& cunit, ivartype, fname_swdown(ictrlgrad), "maskCtrlC",
& weighttype, lxxadxx, mythid)
#endif
close ( cunit )
_END_MASTER( mythid )
#endif /* EXCLUDE_CTRL_PACK */
return
end