1 |
|
|
2 |
#include "CPP_OPTIONS.h" |
#include "AUTODIFF_OPTIONS.h" |
3 |
|
|
4 |
c ================================================================== |
c ================================================================== |
5 |
c |
c |
6 |
c active_file_control.F: Routines to handle the i/o of active vari- |
c active_file_control.F: Routines to handle the i/o of active vari- |
7 |
c ables for the adjoint calculations. All |
c ables for the adjoint calculations. All |
8 |
c files are direct access files. |
c files are direct access files. |
9 |
c |
c |
10 |
c Routines: |
c Routines: |
11 |
c |
c |
12 |
c o active_read_xz_rl - Basic routine to handle active read |
c o active_read_xz_rl - Basic routine to handle active read |
13 |
c operations. |
c operations. |
14 |
c o active_write_xz_rl - Basic routine to handle active write |
c o active_write_xz_rl - Basic routine to handle active write |
15 |
c operations. |
c operations. |
16 |
c o active_read_yz_rl - Basic routine to handle active read |
c o active_read_yz_rl - Basic routine to handle active read |
17 |
c operations. |
c operations. |
18 |
c o active_write_yz_rl - Basic routine to handle active write |
c o active_write_yz_rl - Basic routine to handle active write |
19 |
c operations. |
c operations. |
20 |
c |
c |
21 |
c ================================================================== |
c ================================================================== |
22 |
|
|
23 |
|
|
24 |
subroutine active_read_xz_rl( |
subroutine active_read_xz_rl( |
25 |
I active_var_file, |
I active_var_file, |
26 |
O active_var, |
O active_var, |
27 |
I globalfile, |
I globalfile, |
28 |
I lAdInit, |
I lAdInit, |
29 |
I irec, |
I irec, |
30 |
I mynr, |
I mynr, |
31 |
I theSimulationMode, |
I theSimulationMode, |
32 |
I myOptimIter, |
I myOptimIter, |
33 |
I mythid |
I mythid |
34 |
& ) |
& ) |
35 |
|
|
36 |
c ================================================================== |
c ================================================================== |
37 |
c SUBROUTINE active_read_xz_rl |
c SUBROUTINE active_read_xz_rl |
38 |
c ================================================================== |
c ================================================================== |
39 |
c |
c |
40 |
c o Read an active variable from file. |
c o Read an active variable from file. |
41 |
c |
c |
42 |
c The variable *globalfile* can be used as a switch, which allows |
c The variable *globalfile* can be used as a switch, which allows |
43 |
c to read from a global file. The adjoint files are, however, always |
c to read from a global file. The adjoint files are, however, always |
44 |
c treated as tiled files. |
c treated as tiled files. |
45 |
c |
c |
46 |
c started: heimbach@mit.edu 05-Mar-2001 |
c started: heimbach@mit.edu 05-Mar-2001 |
47 |
c |
c |
48 |
c ================================================================== |
c ================================================================== |
49 |
c SUBROUTINE active_read_xz_rl |
c SUBROUTINE active_read_xz_rl |
50 |
c ================================================================== |
c ================================================================== |
51 |
|
|
52 |
implicit none |
implicit none |
53 |
|
|
54 |
c == global variables == |
c == global variables == |
55 |
|
|
56 |
#include "EEPARAMS.h" |
#include "EEPARAMS.h" |
57 |
#include "SIZE.h" |
#include "SIZE.h" |
58 |
#include "PARAMS.h" |
#include "PARAMS.h" |
59 |
|
#include "ctrl.h" |
60 |
c == routine arguments == |
|
61 |
|
c == routine arguments == |
62 |
character*(*) active_var_file |
|
63 |
|
character*(*) active_var_file |
64 |
logical globalfile |
|
65 |
logical lAdInit |
logical globalfile |
66 |
integer irec |
logical lAdInit |
67 |
integer mynr |
integer irec |
68 |
integer theSimulationMode |
integer mynr |
69 |
integer myOptimIter |
integer theSimulationMode |
70 |
integer mythid |
integer myOptimIter |
71 |
_RL active_var(1-olx:snx+olx,mynr,nsx,nsy) |
integer mythid |
72 |
|
_RL active_var(1-olx:snx+olx,mynr,nsx,nsy) |
73 |
c == local variables == |
|
74 |
|
c == local variables == |
75 |
character*(2) adpref |
|
76 |
character*(80) adfname |
character*(2) adpref |
77 |
|
character*(80) adfname |
78 |
integer bi,bj |
|
79 |
integer i,j,k |
integer bi,bj |
80 |
integer oldprec |
integer i,j,k |
81 |
integer prec |
integer oldprec |
82 |
integer il |
integer prec |
83 |
integer ilnblnk |
integer il |
84 |
|
integer ilnblnk |
85 |
logical writeglobalfile |
|
86 |
|
logical writeglobalfile |
87 |
_RL active_data_t(1-olx:snx+olx,nsx,nsy) |
|
88 |
|
_RL active_data_t(1-olx:snx+olx,nsx,nsy) |
89 |
c == functions == |
|
90 |
|
c == functions == |
91 |
external ilnblnk |
|
92 |
|
external ilnblnk |
93 |
c == end of interface == |
|
94 |
|
c == end of interface == |
95 |
c force 64-bit io |
|
96 |
oldPrec = readBinaryPrec |
c force 64-bit io |
97 |
readBinaryPrec = precFloat64 |
oldPrec = readBinaryPrec |
98 |
prec = precFloat64 |
readBinaryPrec = ctrlprec |
99 |
|
prec = ctrlprec |
100 |
write(adfname(1:80),'(80a)') ' ' |
|
101 |
adpref = 'ad' |
write(adfname(1:80),'(80a)') ' ' |
102 |
il = ilnblnk( active_var_file ) |
adpref = 'ad' |
103 |
|
il = ilnblnk( active_var_file ) |
104 |
write(adfname(1:2),'(a)') adpref |
|
105 |
write(adfname(3:il+2),'(a)') active_var_file(1:il) |
write(adfname(1:2),'(a)') adpref |
106 |
|
write(adfname(3:il+2),'(a)') active_var_file(1:il) |
107 |
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
|
108 |
c >>>>>>>>>>>>>>>>>>> FORWARD RUN <<<<<<<<<<<<<<<<<<< |
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
109 |
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
c >>>>>>>>>>>>>>>>>>> FORWARD RUN <<<<<<<<<<<<<<<<<<< |
110 |
|
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
111 |
if (theSimulationMode .eq. FORWARD_SIMULATION) then |
|
112 |
|
if (theSimulationMode .eq. FORWARD_SIMULATION) then |
113 |
_BEGIN_MASTER( mythid ) |
|
114 |
|
_BEGIN_MASTER( mythid ) |
115 |
c Read the active variable from file. |
|
116 |
|
c Read the active variable from file. |
117 |
call mdsreadfieldxz( |
|
118 |
& active_var_file, |
call mdsreadfieldxz( |
119 |
& prec, |
& active_var_file, |
120 |
& 'RL', |
& prec, |
121 |
& mynr, |
& 'RL', |
122 |
& active_var, |
& mynr, |
123 |
& irec, |
& active_var, |
124 |
& mythid ) |
& irec, |
125 |
|
& mythid ) |
126 |
if (lAdInit) then |
|
127 |
c Initialise the corresponding adjoint variable on the |
if (lAdInit) then |
128 |
c adjoint variable's file. These files are tiled. |
c Initialise the corresponding adjoint variable on the |
129 |
|
c adjoint variable's file. These files are tiled. |
130 |
writeglobalfile = .false. |
|
131 |
do bj = 1,nsy |
writeglobalfile = .false. |
132 |
do bi = 1,nsx |
do bj = 1,nsy |
133 |
do i = 1,snx |
do bi = 1,nsx |
134 |
active_data_t(i,bi,bj)= 0. _d 0 |
do i = 1,snx |
135 |
enddo |
active_data_t(i,bi,bj)= 0. _d 0 |
136 |
enddo |
enddo |
137 |
enddo |
enddo |
138 |
|
enddo |
139 |
do k = 1,mynr |
|
140 |
call mdswritefieldxz( |
do k = 1,mynr |
141 |
& adfname, |
call mdswritefieldxz( |
142 |
& prec, |
& adfname, |
143 |
& globalfile, |
& prec, |
144 |
& 'RL', |
& globalfile, |
145 |
& 1, |
& 'RL', |
146 |
& active_data_t, |
& 1, |
147 |
& (irec-1)*mynr+k, |
& active_data_t, |
148 |
& myOptimIter, |
& (irec-1)*mynr+k, |
149 |
& mythid ) |
& myOptimIter, |
150 |
enddo |
& mythid ) |
151 |
endif |
enddo |
152 |
|
endif |
153 |
_END_MASTER( mythid ) |
|
154 |
|
_END_MASTER( mythid ) |
155 |
endif |
|
156 |
|
endif |
157 |
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
|
158 |
c >>>>>>>>>>>>>>>>>>> ADJOINT RUN <<<<<<<<<<<<<<<<<<< |
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
159 |
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
c >>>>>>>>>>>>>>>>>>> ADJOINT RUN <<<<<<<<<<<<<<<<<<< |
160 |
|
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
161 |
if (theSimulationMode .eq. REVERSE_SIMULATION) then |
|
162 |
|
if (theSimulationMode .eq. REVERSE_SIMULATION) then |
163 |
_BEGIN_MASTER( mythid ) |
|
164 |
|
_BEGIN_MASTER( mythid ) |
165 |
writeglobalfile = .false. |
|
166 |
do k=1,mynr |
writeglobalfile = .false. |
167 |
c Read data from file layer by layer. |
do k=1,mynr |
168 |
call mdsreadfieldxz( |
c Read data from file layer by layer. |
169 |
& active_var_file, |
call mdsreadfieldxz( |
170 |
& prec, |
& active_var_file, |
171 |
& 'RL', |
& prec, |
172 |
& 1, |
& 'RL', |
173 |
& active_data_t, |
& 1, |
174 |
& (irec-1)*mynr+k, |
& active_data_t, |
175 |
& mythid ) |
& (irec-1)*mynr+k, |
176 |
|
& mythid ) |
177 |
c Add active_var from appropriate location to data. |
|
178 |
do bj = 1,nsy |
c Add active_var from appropriate location to data. |
179 |
do bi = 1,nsx |
do bj = 1,nsy |
180 |
do i = 1,snx |
do bi = 1,nsx |
181 |
active_data_t(i,bi,bj) = active_data_t(i,bi,bj) + |
do i = 1,snx |
182 |
& active_var(i,k,bi,bj) |
active_data_t(i,bi,bj) = active_data_t(i,bi,bj) + |
183 |
enddo |
& active_var(i,k,bi,bj) |
184 |
enddo |
enddo |
185 |
enddo |
enddo |
186 |
|
enddo |
187 |
c Store the result on disk. |
|
188 |
call mdswritefieldxz( |
c Store the result on disk. |
189 |
& active_var_file, |
call mdswritefieldxz( |
190 |
& prec, |
& active_var_file, |
191 |
& writeglobalfile, |
& prec, |
192 |
& 'RL', |
& writeglobalfile, |
193 |
& 1, |
& 'RL', |
194 |
& active_data_t, |
& 1, |
195 |
& (irec-1)*mynr+k, |
& active_data_t, |
196 |
& myOptimIter, |
& (irec-1)*mynr+k, |
197 |
& mythid ) |
& myOptimIter, |
198 |
enddo |
& mythid ) |
199 |
|
enddo |
200 |
|
|
201 |
c Set active_var to zero. |
|
202 |
do k=1,mynr |
c Set active_var to zero. |
203 |
do bj = 1,nsy |
do k=1,mynr |
204 |
do bi = 1,nsx |
do bj = 1,nsy |
205 |
do i = 1,snx |
do bi = 1,nsx |
206 |
active_var(i,k,bi,bj) = 0. _d 0 |
do i = 1,snx |
207 |
enddo |
active_var(i,k,bi,bj) = 0. _d 0 |
208 |
enddo |
enddo |
209 |
enddo |
enddo |
210 |
enddo |
enddo |
211 |
|
enddo |
212 |
_END_MASTER( mythid ) |
|
213 |
endif |
_END_MASTER( mythid ) |
214 |
|
endif |
215 |
c Reset default io precision. |
|
216 |
readBinaryPrec = oldPrec |
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
217 |
|
c >>>>>>>>>>>>>>>>>>> TANGENT RUN <<<<<<<<<<<<<<<<<<< |
218 |
_BARRIER |
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
219 |
|
|
220 |
return |
if (theSimulationMode .eq. TANGENT_SIMULATION) then |
221 |
end |
|
222 |
|
_BEGIN_MASTER( mythid ) |
223 |
c ================================================================== |
|
224 |
|
c Read the active variable from file. |
225 |
subroutine active_write_xz_rl( |
|
226 |
I active_var_file, |
call mdsreadfieldxz( |
227 |
I active_var, |
& active_var_file, |
228 |
I globalfile, |
& prec, |
229 |
I irec, |
& 'RL', |
230 |
I mynr, |
& mynr, |
231 |
I theSimulationMode, |
& active_var, |
232 |
I myOptimIter, |
& irec, |
233 |
I mythid |
& mythid ) |
234 |
& ) |
|
235 |
|
_END_MASTER( mythid ) |
236 |
c ================================================================== |
|
237 |
c SUBROUTINE active_write_xz_rl |
endif |
238 |
c ================================================================== |
|
239 |
c |
c Reset default io precision. |
240 |
c o Write an active variable to a file. |
readBinaryPrec = oldPrec |
241 |
c |
|
242 |
c started: heimbach@mit.edu 05-Mar-2001 |
_BARRIER |
243 |
c |
|
244 |
c ================================================================== |
return |
245 |
c SUBROUTINE active_write_xz_rl |
end |
246 |
c ================================================================== |
|
247 |
|
c ================================================================== |
248 |
implicit none |
|
249 |
|
subroutine active_write_xz_rl( |
250 |
c == global variables == |
I active_var_file, |
251 |
|
I active_var, |
252 |
#include "EEPARAMS.h" |
I globalfile, |
253 |
#include "SIZE.h" |
I irec, |
254 |
#include "PARAMS.h" |
I mynr, |
255 |
|
I theSimulationMode, |
256 |
c == routine arguments == |
I myOptimIter, |
257 |
|
I mythid |
258 |
character*(*) active_var_file |
& ) |
259 |
|
|
260 |
integer mynr |
c ================================================================== |
261 |
logical globalfile |
c SUBROUTINE active_write_xz_rl |
262 |
integer irec |
c ================================================================== |
263 |
integer theSimulationMode |
c |
264 |
integer myOptimIter |
c o Write an active variable to a file. |
265 |
integer mythid |
c |
266 |
_RL active_var(1-olx:snx+olx,mynr,nsx,nsy) |
c started: heimbach@mit.edu 05-Mar-2001 |
267 |
|
c |
268 |
c == local variables == |
c ================================================================== |
269 |
|
c SUBROUTINE active_write_xz_rl |
270 |
integer i,j,k |
c ================================================================== |
271 |
integer bi,bj |
|
272 |
_RL active_data_t(1-olx:snx+olx,nsx,nsy) |
implicit none |
273 |
integer oldprec |
|
274 |
integer prec |
c == global variables == |
275 |
|
|
276 |
c == end of interface == |
#include "EEPARAMS.h" |
277 |
|
#include "SIZE.h" |
278 |
c force 64-bit io |
#include "PARAMS.h" |
279 |
oldPrec = readBinaryPrec |
#include "ctrl.h" |
280 |
readBinaryPrec = precFloat64 |
|
281 |
prec = precFloat64 |
c == routine arguments == |
282 |
|
|
283 |
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
character*(*) active_var_file |
284 |
c >>>>>>>>>>>>>>>>>>> FORWARD RUN <<<<<<<<<<<<<<<<<<< |
|
285 |
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
integer mynr |
286 |
|
logical globalfile |
287 |
if (theSimulationMode .eq. FORWARD_SIMULATION) then |
integer irec |
288 |
|
integer theSimulationMode |
289 |
_BEGIN_MASTER( mythid ) |
integer myOptimIter |
290 |
|
integer mythid |
291 |
call mdswritefieldxz( |
_RL active_var(1-olx:snx+olx,mynr,nsx,nsy) |
292 |
& active_var_file, |
|
293 |
& prec, |
c == local variables == |
294 |
& globalfile, |
|
295 |
& 'RL', |
integer i,j,k |
296 |
& mynr, |
integer bi,bj |
297 |
& active_var, |
_RL active_data_t(1-olx:snx+olx,nsx,nsy) |
298 |
& irec, |
integer oldprec |
299 |
& myOptimIter, |
integer prec |
300 |
& mythid ) |
|
301 |
|
c == end of interface == |
302 |
_END_MASTER( mythid ) |
|
303 |
|
c force 64-bit io |
304 |
endif |
oldPrec = readBinaryPrec |
305 |
|
readBinaryPrec = ctrlprec |
306 |
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
prec = ctrlprec |
307 |
c >>>>>>>>>>>>>>>>>>> ADJOINT RUN <<<<<<<<<<<<<<<<<<< |
|
308 |
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
309 |
|
c >>>>>>>>>>>>>>>>>>> FORWARD RUN <<<<<<<<<<<<<<<<<<< |
310 |
if (theSimulationMode .eq. REVERSE_SIMULATION) then |
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
311 |
|
|
312 |
_BEGIN_MASTER( mythid ) |
if (theSimulationMode .eq. FORWARD_SIMULATION) then |
313 |
|
|
314 |
do k=1,mynr |
_BEGIN_MASTER( mythid ) |
315 |
c Read data from file layer by layer. |
|
316 |
call mdsreadfieldxz( |
call mdswritefieldxz( |
317 |
& active_var_file, |
& active_var_file, |
318 |
& prec, |
& prec, |
319 |
& 'RL', |
& globalfile, |
320 |
& 1, |
& 'RL', |
321 |
& active_data_t, |
& mynr, |
322 |
& (irec-1)*mynr+k, |
& active_var, |
323 |
& mythid ) |
& irec, |
324 |
|
& myOptimIter, |
325 |
c Add active_var from appropriate location to data. |
& mythid ) |
326 |
do bj = 1,nsy |
|
327 |
do bi = 1,nsx |
_END_MASTER( mythid ) |
328 |
do i = 1,snx |
|
329 |
active_var(i,k,bi,bj) = |
endif |
330 |
& active_var(i,k,bi,bj) + |
|
331 |
& active_data_t(i,bi,bj) |
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
332 |
active_data_t(i,bi,bj) = 0. _d 0 |
c >>>>>>>>>>>>>>>>>>> ADJOINT RUN <<<<<<<<<<<<<<<<<<< |
333 |
enddo |
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
334 |
enddo |
|
335 |
enddo |
if (theSimulationMode .eq. REVERSE_SIMULATION) then |
336 |
call mdswritefieldxz( |
|
337 |
& active_var_file, |
_BEGIN_MASTER( mythid ) |
338 |
& prec, |
|
339 |
& globalfile, |
do k=1,mynr |
340 |
& 'RL', |
c Read data from file layer by layer. |
341 |
& 1, |
call mdsreadfieldxz( |
342 |
& active_data_t, |
& active_var_file, |
343 |
& (irec-1)*mynr+k, |
& prec, |
344 |
& myOptimIter, |
& 'RL', |
345 |
& mythid ) |
& 1, |
346 |
enddo |
& active_data_t, |
347 |
|
& (irec-1)*mynr+k, |
348 |
_END_MASTER( mythid ) |
& mythid ) |
349 |
|
|
350 |
endif |
c Add active_var from appropriate location to data. |
351 |
|
do bj = 1,nsy |
352 |
c Reset default io precision. |
do bi = 1,nsx |
353 |
readBinaryPrec = oldPrec |
do i = 1,snx |
354 |
|
active_var(i,k,bi,bj) = |
355 |
_BARRIER |
& active_var(i,k,bi,bj) + |
356 |
|
& active_data_t(i,bi,bj) |
357 |
return |
active_data_t(i,bi,bj) = 0. _d 0 |
358 |
end |
enddo |
359 |
|
enddo |
360 |
c ================================================================== |
enddo |
361 |
|
call mdswritefieldxz( |
362 |
subroutine active_read_yz_rl( |
& active_var_file, |
363 |
I active_var_file, |
& prec, |
364 |
O active_var, |
& globalfile, |
365 |
I globalfile, |
& 'RL', |
366 |
I lAdInit, |
& 1, |
367 |
I irec, |
& active_data_t, |
368 |
I mynr, |
& (irec-1)*mynr+k, |
369 |
I theSimulationMode, |
& myOptimIter, |
370 |
I myOptimIter, |
& mythid ) |
371 |
I mythid |
enddo |
372 |
& ) |
|
373 |
|
_END_MASTER( mythid ) |
374 |
c ================================================================== |
|
375 |
c SUBROUTINE active_read_yz_rl |
endif |
376 |
c ================================================================== |
|
377 |
c |
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
378 |
c o Read an active variable from file. |
c >>>>>>>>>>>>>>>>>>> TANGENT RUN <<<<<<<<<<<<<<<<<<< |
379 |
c |
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
380 |
c The variable *globalfile* can be used as a switch, which allows |
|
381 |
c to read from a global file. The adjoint files are, however, always |
if (theSimulationMode .eq. TANGENT_SIMULATION) then |
382 |
c treated as tiled files. |
|
383 |
c |
_BEGIN_MASTER( mythid ) |
384 |
c started: heimbach@mit.edu 05-Mar-2001 |
|
385 |
c |
call mdswritefieldxz( |
386 |
c ================================================================== |
& active_var_file, |
387 |
c SUBROUTINE active_read_yz_rl |
& prec, |
388 |
c ================================================================== |
& globalfile, |
389 |
|
& 'RL', |
390 |
implicit none |
& mynr, |
391 |
|
& active_var, |
392 |
c == global variables == |
& irec, |
393 |
|
& myOptimIter, |
394 |
#include "EEPARAMS.h" |
& mythid ) |
395 |
#include "SIZE.h" |
|
396 |
#include "PARAMS.h" |
_END_MASTER( mythid ) |
397 |
|
|
398 |
c == routine arguments == |
endif |
399 |
|
|
400 |
character*(*) active_var_file |
c Reset default io precision. |
401 |
|
readBinaryPrec = oldPrec |
402 |
logical globalfile |
|
403 |
logical lAdInit |
_BARRIER |
404 |
integer irec |
|
405 |
integer mynr |
return |
406 |
integer theSimulationMode |
end |
407 |
integer myOptimIter |
|
408 |
integer mythid |
c ================================================================== |
409 |
_RL active_var(1-oly:sny+oly,mynr,nsx,nsy) |
|
410 |
|
subroutine active_read_yz_rl( |
411 |
c == local variables == |
I active_var_file, |
412 |
|
O active_var, |
413 |
character*(2) adpref |
I globalfile, |
414 |
character*(80) adfname |
I lAdInit, |
415 |
|
I irec, |
416 |
integer bi,bj |
I mynr, |
417 |
integer i,j,k |
I theSimulationMode, |
418 |
integer oldprec |
I myOptimIter, |
419 |
integer prec |
I mythid |
420 |
integer il |
& ) |
421 |
integer ilnblnk |
|
422 |
|
c ================================================================== |
423 |
logical writeglobalfile |
c SUBROUTINE active_read_yz_rl |
424 |
|
c ================================================================== |
425 |
_RL active_data_t(1-oly:sny+oly,nsx,nsy) |
c |
426 |
|
c o Read an active variable from file. |
427 |
c == functions == |
c |
428 |
|
c The variable *globalfile* can be used as a switch, which allows |
429 |
external ilnblnk |
c to read from a global file. The adjoint files are, however, always |
430 |
|
c treated as tiled files. |
431 |
c == end of interface == |
c |
432 |
|
c started: heimbach@mit.edu 05-Mar-2001 |
433 |
c force 64-bit io |
c |
434 |
oldPrec = readBinaryPrec |
c ================================================================== |
435 |
readBinaryPrec = precFloat64 |
c SUBROUTINE active_read_yz_rl |
436 |
prec = precFloat64 |
c ================================================================== |
437 |
|
|
438 |
write(adfname(1:80),'(80a)') ' ' |
implicit none |
439 |
adpref = 'ad' |
|
440 |
il = ilnblnk( active_var_file ) |
c == global variables == |
441 |
|
|
442 |
write(adfname(1:2),'(a)') adpref |
#include "EEPARAMS.h" |
443 |
write(adfname(3:il+2),'(a)') active_var_file(1:il) |
#include "SIZE.h" |
444 |
|
#include "PARAMS.h" |
445 |
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
#include "ctrl.h" |
446 |
c >>>>>>>>>>>>>>>>>>> FORWARD RUN <<<<<<<<<<<<<<<<<<< |
|
447 |
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
c == routine arguments == |
448 |
|
|
449 |
if (theSimulationMode .eq. FORWARD_SIMULATION) then |
character*(*) active_var_file |
450 |
|
|
451 |
_BEGIN_MASTER( mythid ) |
logical globalfile |
452 |
|
logical lAdInit |
453 |
c Read the active variable from file. |
integer irec |
454 |
|
integer mynr |
455 |
call mdsreadfieldyz( |
integer theSimulationMode |
456 |
& active_var_file, |
integer myOptimIter |
457 |
& prec, |
integer mythid |
458 |
& 'RL', |
_RL active_var(1-oly:sny+oly,mynr,nsx,nsy) |
459 |
& mynr, |
|
460 |
& active_var, |
c == local variables == |
461 |
& irec, |
|
462 |
& mythid ) |
character*(2) adpref |
463 |
|
character*(80) adfname |
464 |
if (lAdInit) then |
|
465 |
c Initialise the corresponding adjoint variable on the |
integer bi,bj |
466 |
c adjoint variable's file. These files are tiled. |
integer i,j,k |
467 |
|
integer oldprec |
468 |
writeglobalfile = .false. |
integer prec |
469 |
do bj = 1,nsy |
integer il |
470 |
do bi = 1,nsx |
integer ilnblnk |
471 |
do j = 1,sny |
|
472 |
active_data_t(j,bi,bj)= 0. _d 0 |
logical writeglobalfile |
473 |
enddo |
|
474 |
enddo |
_RL active_data_t(1-oly:sny+oly,nsx,nsy) |
475 |
enddo |
|
476 |
|
c == functions == |
477 |
do k = 1,mynr |
|
478 |
call mdswritefieldyz( |
external ilnblnk |
479 |
& adfname, |
|
480 |
& prec, |
c == end of interface == |
481 |
& globalfile, |
|
482 |
& 'RL', |
c force 64-bit io |
483 |
& 1, |
oldPrec = readBinaryPrec |
484 |
& active_data_t, |
readBinaryPrec = ctrlprec |
485 |
& (irec-1)*mynr+k, |
prec = ctrlprec |
486 |
& myOptimIter, |
|
487 |
& mythid ) |
write(adfname(1:80),'(80a)') ' ' |
488 |
enddo |
adpref = 'ad' |
489 |
endif |
il = ilnblnk( active_var_file ) |
490 |
|
|
491 |
_END_MASTER( mythid ) |
write(adfname(1:2),'(a)') adpref |
492 |
|
write(adfname(3:il+2),'(a)') active_var_file(1:il) |
493 |
endif |
|
494 |
|
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
495 |
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
c >>>>>>>>>>>>>>>>>>> FORWARD RUN <<<<<<<<<<<<<<<<<<< |
496 |
c >>>>>>>>>>>>>>>>>>> ADJOINT RUN <<<<<<<<<<<<<<<<<<< |
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
497 |
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
|
498 |
|
if (theSimulationMode .eq. FORWARD_SIMULATION) then |
499 |
if (theSimulationMode .eq. REVERSE_SIMULATION) then |
|
500 |
|
_BEGIN_MASTER( mythid ) |
501 |
_BEGIN_MASTER( mythid ) |
|
502 |
|
c Read the active variable from file. |
503 |
writeglobalfile = .false. |
|
504 |
do k=1,mynr |
call mdsreadfieldyz( |
505 |
c Read data from file layer by layer. |
& active_var_file, |
506 |
call mdsreadfieldyz( |
& prec, |
507 |
& active_var_file, |
& 'RL', |
508 |
& prec, |
& mynr, |
509 |
& 'RL', |
& active_var, |
510 |
& 1, |
& irec, |
511 |
& active_data_t, |
& mythid ) |
512 |
& (irec-1)*mynr+k, |
|
513 |
& mythid ) |
if (lAdInit) then |
514 |
|
c Initialise the corresponding adjoint variable on the |
515 |
c Add active_var from appropriate location to data. |
c adjoint variable's file. These files are tiled. |
516 |
do bj = 1,nsy |
|
517 |
do bi = 1,nsx |
writeglobalfile = .false. |
518 |
do j = 1,sny |
do bj = 1,nsy |
519 |
active_data_t(j,bi,bj) = active_data_t(j,bi,bj) + |
do bi = 1,nsx |
520 |
& active_var(j,k,bi,bj) |
do j = 1,sny |
521 |
enddo |
active_data_t(j,bi,bj)= 0. _d 0 |
522 |
enddo |
enddo |
523 |
enddo |
enddo |
524 |
|
enddo |
525 |
c Store the result on disk. |
|
526 |
call mdswritefieldyz( |
do k = 1,mynr |
527 |
& active_var_file, |
call mdswritefieldyz( |
528 |
& prec, |
& adfname, |
529 |
& writeglobalfile, |
& prec, |
530 |
& 'RL', |
& globalfile, |
531 |
& 1, |
& 'RL', |
532 |
& active_data_t, |
& 1, |
533 |
& (irec-1)*mynr+k, |
& active_data_t, |
534 |
& myOptimIter, |
& (irec-1)*mynr+k, |
535 |
& mythid ) |
& myOptimIter, |
536 |
enddo |
& mythid ) |
537 |
|
enddo |
538 |
|
endif |
539 |
c Set active_var to zero. |
|
540 |
do k=1,mynr |
_END_MASTER( mythid ) |
541 |
do bj = 1,nsy |
|
542 |
do bi = 1,nsx |
endif |
543 |
do j = 1,sny |
|
544 |
active_var(j,k,bi,bj) = 0. _d 0 |
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
545 |
enddo |
c >>>>>>>>>>>>>>>>>>> ADJOINT RUN <<<<<<<<<<<<<<<<<<< |
546 |
enddo |
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
547 |
enddo |
|
548 |
enddo |
if (theSimulationMode .eq. REVERSE_SIMULATION) then |
549 |
|
|
550 |
_END_MASTER( mythid ) |
_BEGIN_MASTER( mythid ) |
551 |
endif |
|
552 |
|
writeglobalfile = .false. |
553 |
c Reset default io precision. |
do k=1,mynr |
554 |
readBinaryPrec = oldPrec |
c Read data from file layer by layer. |
555 |
|
call mdsreadfieldyz( |
556 |
_BARRIER |
& active_var_file, |
557 |
|
& prec, |
558 |
return |
& 'RL', |
559 |
end |
& 1, |
560 |
|
& active_data_t, |
561 |
c ================================================================== |
& (irec-1)*mynr+k, |
562 |
|
& mythid ) |
563 |
subroutine active_write_yz_rl( |
|
564 |
I active_var_file, |
c Add active_var from appropriate location to data. |
565 |
I active_var, |
do bj = 1,nsy |
566 |
I globalfile, |
do bi = 1,nsx |
567 |
I irec, |
do j = 1,sny |
568 |
I mynr, |
active_data_t(j,bi,bj) = active_data_t(j,bi,bj) + |
569 |
I theSimulationMode, |
& active_var(j,k,bi,bj) |
570 |
I myOptimIter, |
enddo |
571 |
I mythid |
enddo |
572 |
& ) |
enddo |
573 |
|
|
574 |
c ================================================================== |
c Store the result on disk. |
575 |
c SUBROUTINE active_write_yz_rl |
call mdswritefieldyz( |
576 |
c ================================================================== |
& active_var_file, |
577 |
c |
& prec, |
578 |
c o Write an active variable to a file. |
& writeglobalfile, |
579 |
c |
& 'RL', |
580 |
c started: heimbach@mit.edu 05-Mar-2001 |
& 1, |
581 |
c |
& active_data_t, |
582 |
c ================================================================== |
& (irec-1)*mynr+k, |
583 |
c SUBROUTINE active_write_yz_rl |
& myOptimIter, |
584 |
c ================================================================== |
& mythid ) |
585 |
|
enddo |
586 |
implicit none |
|
587 |
|
|
588 |
c == global variables == |
c Set active_var to zero. |
589 |
|
do k=1,mynr |
590 |
#include "EEPARAMS.h" |
do bj = 1,nsy |
591 |
#include "SIZE.h" |
do bi = 1,nsx |
592 |
#include "PARAMS.h" |
do j = 1,sny |
593 |
|
active_var(j,k,bi,bj) = 0. _d 0 |
594 |
c == routine arguments == |
enddo |
595 |
|
enddo |
596 |
character*(*) active_var_file |
enddo |
597 |
|
enddo |
598 |
integer mynr |
|
599 |
logical globalfile |
_END_MASTER( mythid ) |
600 |
integer irec |
endif |
601 |
integer theSimulationMode |
|
602 |
integer myOptimIter |
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
603 |
integer mythid |
c >>>>>>>>>>>>>>>>>>> TANGENT RUN <<<<<<<<<<<<<<<<<<< |
604 |
_RL active_var(1-oly:sny+oly,mynr,nsx,nsy) |
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
605 |
|
|
606 |
c == local variables == |
if (theSimulationMode .eq. TANGENT_SIMULATION) then |
607 |
|
|
608 |
integer i,j,k |
_BEGIN_MASTER( mythid ) |
609 |
integer bi,bj |
|
610 |
_RL active_data_t(1-oly:sny+oly,nsx,nsy) |
c Read the active variable from file. |
611 |
integer oldprec |
|
612 |
integer prec |
call mdsreadfieldyz( |
613 |
|
& active_var_file, |
614 |
c == end of interface == |
& prec, |
615 |
|
& 'RL', |
616 |
c force 64-bit io |
& mynr, |
617 |
oldPrec = readBinaryPrec |
& active_var, |
618 |
readBinaryPrec = precFloat64 |
& irec, |
619 |
prec = precFloat64 |
& mythid ) |
620 |
|
|
621 |
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
_END_MASTER( mythid ) |
622 |
c >>>>>>>>>>>>>>>>>>> FORWARD RUN <<<<<<<<<<<<<<<<<<< |
|
623 |
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
endif |
624 |
|
|
625 |
if (theSimulationMode .eq. FORWARD_SIMULATION) then |
c Reset default io precision. |
626 |
|
readBinaryPrec = oldPrec |
627 |
_BEGIN_MASTER( mythid ) |
|
628 |
|
_BARRIER |
629 |
call mdswritefieldyz( |
|
630 |
& active_var_file, |
return |
631 |
& prec, |
end |
632 |
& globalfile, |
|
633 |
& 'RL', |
c ================================================================== |
634 |
& mynr, |
|
635 |
& active_var, |
subroutine active_write_yz_rl( |
636 |
& irec, |
I active_var_file, |
637 |
& myOptimIter, |
I active_var, |
638 |
& mythid ) |
I globalfile, |
639 |
|
I irec, |
640 |
_END_MASTER( mythid ) |
I mynr, |
641 |
|
I theSimulationMode, |
642 |
endif |
I myOptimIter, |
643 |
|
I mythid |
644 |
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
& ) |
645 |
c >>>>>>>>>>>>>>>>>>> ADJOINT RUN <<<<<<<<<<<<<<<<<<< |
|
646 |
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
c ================================================================== |
647 |
|
c SUBROUTINE active_write_yz_rl |
648 |
if (theSimulationMode .eq. REVERSE_SIMULATION) then |
c ================================================================== |
649 |
|
c |
650 |
_BEGIN_MASTER( mythid ) |
c o Write an active variable to a file. |
651 |
|
c |
652 |
do k=1,mynr |
c started: heimbach@mit.edu 05-Mar-2001 |
653 |
c Read data from file layer by layer. |
c |
654 |
call mdsreadfieldyz( |
c ================================================================== |
655 |
& active_var_file, |
c SUBROUTINE active_write_yz_rl |
656 |
& prec, |
c ================================================================== |
657 |
& 'RL', |
|
658 |
& 1, |
implicit none |
659 |
& active_data_t, |
|
660 |
& (irec-1)*mynr+k, |
c == global variables == |
661 |
& mythid ) |
|
662 |
|
#include "EEPARAMS.h" |
663 |
c Add active_var from appropriate location to data. |
#include "SIZE.h" |
664 |
do bj = 1,nsy |
#include "PARAMS.h" |
665 |
do bi = 1,nsx |
#include "ctrl.h" |
666 |
do j = 1,sny |
|
667 |
active_var(j,k,bi,bj) = |
c == routine arguments == |
668 |
& active_var(j,k,bi,bj) + |
|
669 |
& active_data_t(j,bi,bj) |
character*(*) active_var_file |
670 |
active_data_t(j,bi,bj) = 0. _d 0 |
|
671 |
enddo |
integer mynr |
672 |
enddo |
logical globalfile |
673 |
enddo |
integer irec |
674 |
call mdswritefieldyz( |
integer theSimulationMode |
675 |
& active_var_file, |
integer myOptimIter |
676 |
& prec, |
integer mythid |
677 |
& globalfile, |
_RL active_var(1-oly:sny+oly,mynr,nsx,nsy) |
678 |
& 'RL', |
|
679 |
& 1, |
c == local variables == |
680 |
& active_data_t, |
|
681 |
& (irec-1)*mynr+k, |
integer i,j,k |
682 |
& myOptimIter, |
integer bi,bj |
683 |
& mythid ) |
_RL active_data_t(1-oly:sny+oly,nsx,nsy) |
684 |
enddo |
integer oldprec |
685 |
|
integer prec |
686 |
_END_MASTER( mythid ) |
|
687 |
|
c == end of interface == |
688 |
endif |
|
689 |
|
c force 64-bit io |
690 |
c Reset default io precision. |
oldPrec = readBinaryPrec |
691 |
readBinaryPrec = oldPrec |
readBinaryPrec = ctrlprec |
692 |
|
prec = ctrlprec |
693 |
_BARRIER |
|
694 |
|
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
695 |
return |
c >>>>>>>>>>>>>>>>>>> FORWARD RUN <<<<<<<<<<<<<<<<<<< |
696 |
end |
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
697 |
|
|
698 |
|
if (theSimulationMode .eq. FORWARD_SIMULATION) then |
699 |
|
|
700 |
|
_BEGIN_MASTER( mythid ) |
701 |
|
|
702 |
|
call mdswritefieldyz( |
703 |
|
& active_var_file, |
704 |
|
& prec, |
705 |
|
& globalfile, |
706 |
|
& 'RL', |
707 |
|
& mynr, |
708 |
|
& active_var, |
709 |
|
& irec, |
710 |
|
& myOptimIter, |
711 |
|
& mythid ) |
712 |
|
|
713 |
|
_END_MASTER( mythid ) |
714 |
|
|
715 |
|
endif |
716 |
|
|
717 |
|
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
718 |
|
c >>>>>>>>>>>>>>>>>>> ADJOINT RUN <<<<<<<<<<<<<<<<<<< |
719 |
|
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
720 |
|
|
721 |
|
if (theSimulationMode .eq. REVERSE_SIMULATION) then |
722 |
|
|
723 |
|
_BEGIN_MASTER( mythid ) |
724 |
|
|
725 |
|
do k=1,mynr |
726 |
|
c Read data from file layer by layer. |
727 |
|
call mdsreadfieldyz( |
728 |
|
& active_var_file, |
729 |
|
& prec, |
730 |
|
& 'RL', |
731 |
|
& 1, |
732 |
|
& active_data_t, |
733 |
|
& (irec-1)*mynr+k, |
734 |
|
& mythid ) |
735 |
|
|
736 |
|
c Add active_var from appropriate location to data. |
737 |
|
do bj = 1,nsy |
738 |
|
do bi = 1,nsx |
739 |
|
do j = 1,sny |
740 |
|
active_var(j,k,bi,bj) = |
741 |
|
& active_var(j,k,bi,bj) + |
742 |
|
& active_data_t(j,bi,bj) |
743 |
|
active_data_t(j,bi,bj) = 0. _d 0 |
744 |
|
enddo |
745 |
|
enddo |
746 |
|
enddo |
747 |
|
call mdswritefieldyz( |
748 |
|
& active_var_file, |
749 |
|
& prec, |
750 |
|
& globalfile, |
751 |
|
& 'RL', |
752 |
|
& 1, |
753 |
|
& active_data_t, |
754 |
|
& (irec-1)*mynr+k, |
755 |
|
& myOptimIter, |
756 |
|
& mythid ) |
757 |
|
enddo |
758 |
|
|
759 |
|
_END_MASTER( mythid ) |
760 |
|
|
761 |
|
endif |
762 |
|
|
763 |
|
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
764 |
|
c >>>>>>>>>>>>>>>>>>> TANGENTY RUN <<<<<<<<<<<<<<<<<<< |
765 |
|
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
766 |
|
|
767 |
|
if (theSimulationMode .eq. TANGENT_SIMULATION) then |
768 |
|
|
769 |
|
_BEGIN_MASTER( mythid ) |
770 |
|
|
771 |
|
call mdswritefieldyz( |
772 |
|
& active_var_file, |
773 |
|
& prec, |
774 |
|
& globalfile, |
775 |
|
& 'RL', |
776 |
|
& mynr, |
777 |
|
& active_var, |
778 |
|
& irec, |
779 |
|
& myOptimIter, |
780 |
|
& mythid ) |
781 |
|
|
782 |
|
_END_MASTER( mythid ) |
783 |
|
|
784 |
|
endif |
785 |
|
|
786 |
|
c Reset default io precision. |
787 |
|
readBinaryPrec = oldPrec |
788 |
|
|
789 |
|
_BARRIER |
790 |
|
|
791 |
|
return |
792 |
|
end |
793 |
|
|