-
Notifications
You must be signed in to change notification settings - Fork 237
/
ctrl_set_pack_xz.F
330 lines (301 loc) · 9.78 KB
/
ctrl_set_pack_xz.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
#include "CTRL_OPTIONS.h"
subroutine ctrl_set_pack_xz(
& cunit, ivar, fname, masktype,weighttype,
& weightfld, lxxadxx, mythid)
c ==================================================================
c SUBROUTINE ctrl_set_pack_xz
c ==================================================================
c
c o Compress the control vector such that only ocean points are
c written to file.
c
c o Open boundary packing finalized :
c gebbie@mit.edu, 18-Mar-2003
c
c changed: heimbach@mit.edu 17-Jun-2003
c merged changes from Armin to replace write of
c nr * globfld2d by 1 * globfld3d
c (ad hoc fix to speed up global I/O)
c
c ==================================================================
implicit none
c == global variables ==
#include "EEPARAMS.h"
#include "SIZE.h"
#include "PARAMS.h"
#include "GRID.h"
#include "CTRL_SIZE.h"
#include "CTRL.h"
#include "CTRL_OBCS.h"
#include "OPTIMCYCLE.h"
c == routine arguments ==
integer cunit
integer ivar
character*(MAX_LEN_FNAM) fname
character*( 9) masktype
character*( *) weighttype
_RL weightfld( Nr,nobcs )
logical lxxadxx
integer mythid
#ifndef EXCLUDE_CTRL_PACK
c == local variables ==
integer bi,bj
integer ip,jp
integer i,j,k
integer ii,jj,kk
integer irec,iobcs,nrec_nl
integer itlo,ithi
integer jtlo,jthi
integer jmin,jmax
integer imin,imax
integer cbuffindex
integer reclen, irectrue
integer cunit2, cunit3
character*(MAX_LEN_FNAM) cfile2, cfile3
real*4 cbuff ( sNx*nSx*nPx*nSy*nPy )
real*4 globfldtmp2( sNx,nSx,nPx,nSy,nPy )
real*4 globfldtmp3( sNx,nSx,nPx,nSy,nPy )
_RL globfldxz ( sNx,nSx,nPx,nSy,nPy,Nr )
_RL globfld3d ( sNx,nSx,nPx,sNy,nSy,nPy,Nr )
_RL globmskxz ( sNx,nSx,nPx,nSy,nPy,Nr,nobcs )
#ifdef CTRL_PACK_PRECISE
integer il
character*(MAX_LEN_FNAM) weightname
_RL weightfldxz( sNx,nSx,nPx,nSy,nPy,Nr,nobcs )
c == external ==
integer ilnblnk
external ilnblnk
#endif
c == end of interface ==
jtlo = 1
jthi = nSy
itlo = 1
ithi = nSx
jmin = 1
jmax = sNy
imin = 1
imax = sNx
c Initialise temporary file
do k = 1,Nr
do jp = 1,nPy
do bj = jtlo,jthi
do ip = 1,nPx
do bi = itlo,ithi
do i = imin,imax
globfldxz (i,bi,ip,bj,jp,k) = 0. _d 0
globfldtmp2(i,bi,ip,bj,jp) = 0.
globfldtmp3(i,bi,ip,bj,jp) = 0.
do iobcs=1,nobcs
globmskxz(i,bi,ip,bj,jp,k,iobcs) = 0. _d 0
enddo
enddo
enddo
enddo
enddo
enddo
enddo
c Initialise temporary file
do k = 1,Nr
do jp = 1,nPy
do bj = jtlo,jthi
do j = jmin,jmax
do ip = 1,nPx
do bi = itlo,ithi
do i = imin,imax
globfld3d(i,bi,ip,j,bj,jp,k) = 0. _d 0
enddo
enddo
enddo
enddo
enddo
enddo
enddo
c-- Only the master thread will do I/O.
_BEGIN_MASTER( mythid )
if ( doPackDiag ) then
if ( lxxadxx ) then
write(cfile2,'(a,I2.2,a,I4.4,a)')
& 'diag_pack_nonout_ctrl_',
& ivar, '_', optimcycle, '.bin'
write(cfile3,'(a,I2.2,a,I4.4,a)')
& 'diag_pack_dimout_ctrl_',
& ivar, '_', optimcycle, '.bin'
else
write(cfile2,'(a,I2.2,a,I4.4,a)')
& 'diag_pack_nonout_grad_',
& ivar, '_', optimcycle, '.bin'
write(cfile3,'(a,I2.2,a,I4.4,a)')
& 'diag_pack_dimout_grad_',
& ivar, '_', optimcycle, '.bin'
endif
reclen = sNx*nSx*nPx*nSy*nPy*4
call mdsfindunit( cunit2, mythid )
open( cunit2, file=cfile2, status='unknown',
& access='direct', recl=reclen )
call mdsfindunit( cunit3, mythid )
open( cunit3, file=cfile3, status='unknown',
& access='direct', recl=reclen )
endif
do iobcs = 1, nobcs
call MDSREADFIELD_XZ_GL(
& masktype, ctrlprec, 'RL',
& Nr, globmskxz(1,1,1,1,1,1,iobcs), iobcs, mythid)
#ifdef CTRL_PACK_PRECISE
il=ilnblnk( weighttype)
write(weightname,'(a)') weighttype(1:il)
call MDSREADFIELD_XZ_GL(
& weightname, ctrlprec, 'RL',
& Nr, weightfldxz(1,1,1,1,1,1,iobcs), iobcs, mythid)
#endif
enddo
if ( useSingleCPUio ) then
C MDSREADFIELD_XZ_GL does not know about useSingleCPUio, so the faster
C method that works for .not.useSingleCPUio cannot be used
nrec_nl = 0
else
nrec_nl = int(ncvarrecs(ivar)/Ny)
endif
do irec = 1, nrec_nl
call MDSREADFIELD_3D_GL( fname, ctrlprec, 'RL',
& Nr, globfld3d, irec, mythid)
do j=1,sNy
iobcs= mod((irec-1)*sNy+j-1,nobcs)+1
write(cunit) ncvarindex(ivar)
write(cunit) 1
write(cunit) 1
do k = 1,Nr
irectrue = (irec-1)*nobcs*Nr + (iobcs-1)*Nr + k
cbuffindex = 0
do jp = 1,nPy
do bj = jtlo,jthi
do ip = 1,nPx
do bi = itlo,ithi
do i = imin,imax
jj=mod((j-1)*Nr+k-1,sNy)+1
kk=int((j-1)*Nr+K-1)/sNy+1
if (globmskxz(i,bi,ip,bj,jp,k,iobcs) .ne. 0. ) then
cbuffindex = cbuffindex + 1
cph(
globfldtmp3(i,bi,ip,bj,jp) =
& globfld3d(i,bi,ip,jj,bj,jp,kk)
cph)
#ifdef ALLOW_NONDIMENSIONAL_CONTROL_IO
if (lxxadxx) then
cbuff(cbuffindex) =
& globfld3d(i,bi,ip,jj,bj,jp,kk) *
# ifdef CTRL_PACK_PRECISE
& sqrt(weightfldxz(i,bi,ip,bj,jp,k,iobcs))
# else
& sqrt(weightfld(k,iobcs))
# endif
else
cbuff(cbuffindex) =
& globfld3d(i,bi,ip,jj,bj,jp,kk) /
# ifdef CTRL_PACK_PRECISE
& sqrt(weightfldxz(i,bi,ip,bj,jp,k,iobcs))
# else
& sqrt(weightfld(k,iobcs))
# endif
endif
cph(
globfldtmp2(i,bi,ip,bj,jp) = cbuff(cbuffindex)
cph)
#else /* ALLOW_NONDIMENSIONAL_CONTROL_IO undef */
cbuff(cbuffindex) = globfld3d(i,bi,ip,jj,bj,jp,kk)
#endif /* ALLOW_NONDIMENSIONAL_CONTROL_IO */
endif
enddo
enddo
enddo
enddo
enddo
c --> check cbuffindex.
if ( cbuffindex .gt. 0) then
write(cunit) cbuffindex
write(cunit) k
write(cunit) (cbuff(ii), ii=1,cbuffindex)
endif
c
if ( doPackDiag ) then
write(cunit2,rec=irectrue) globfldtmp2
write(cunit3,rec=irectrue) globfldtmp3
endif
c
c -- end of k loop --
enddo
c -- end of j loop --
enddo
c -- end of irec loop --
enddo
do irec = nrec_nl*ny+1, ncvarrecs(ivar)
c Need to solve for what iobcs would have been.
iobcs= mod(irec-1,nobcs)+1
call MDSREADFIELD_XZ_GL( fname, ctrlprec, 'RL',
& Nr, globfldxz, irec, mythid)
write(cunit) ncvarindex(ivar)
write(cunit) 1
write(cunit) 1
do k = 1,Nr
irectrue = (irec-1)*nobcs*Nr + (iobcs-1)*Nr + k
cbuffindex = 0
do jp = 1,nPy
do bj = jtlo,jthi
do ip = 1,nPx
do bi = itlo,ithi
do i = imin,imax
if (globmskxz(i,bi,ip,bj,jp,k,iobcs) .ne. 0. ) then
cbuffindex = cbuffindex + 1
cph(
globfldtmp3(i,bi,ip,bj,jp) =
& globfldxz(i,bi,ip,bj,jp,k)
cph)
#ifdef ALLOW_NONDIMENSIONAL_CONTROL_IO
if (lxxadxx) then
cbuff(cbuffindex) =
& globfldxz(i,bi,ip,bj,jp,k) *
# ifdef CTRL_PACK_PRECISE
& sqrt(weightfldxz(i,bi,ip,bj,jp,k,iobcs))
# else
& sqrt(weightfld(k,iobcs))
# endif
else
cbuff(cbuffindex) =
& globfldxz(i,bi,ip,bj,jp,k) /
# ifdef CTRL_PACK_PRECISE
& sqrt(weightfldxz(i,bi,ip,bj,jp,k,iobcs))
# else
& sqrt(weightfld(k,iobcs))
# endif
endif
cph(
globfldtmp2(i,bi,ip,bj,jp) = cbuff(cbuffindex)
cph)
#else /* ALLOW_NONDIMENSIONAL_CONTROL_IO undef */
cbuff(cbuffindex) = globfldxz(i,bi,ip,bj,jp,k)
#endif /* ALLOW_NONDIMENSIONAL_CONTROL_IO */
endif
enddo
enddo
enddo
enddo
enddo
c --> check cbuffindex.
if ( cbuffindex .gt. 0) then
write(cunit) cbuffindex
write(cunit) k
write(cunit) (cbuff(ii), ii=1,cbuffindex)
endif
c
if ( doPackDiag ) then
write(cunit2,rec=irectrue) globfldtmp2
write(cunit3,rec=irectrue) globfldtmp3
endif
c
c -- end of k loop --
enddo
c -- end of irec loop --
enddo
_END_MASTER( mythid )
#endif
return
end