1 |
jmc |
1.7 |
C $Header: $ |
2 |
|
|
C $Name: $ |
3 |
heimbach |
1.2 |
|
4 |
edhill |
1.3 |
#include "AUTODIFF_OPTIONS.h" |
5 |
heimbach |
1.2 |
|
6 |
|
|
c ================================================================== |
7 |
|
|
c |
8 |
|
|
c active_file_control_loc.F: Routines to handle the i/o of active vari- |
9 |
|
|
c ables for the adjoint calculations. All |
10 |
|
|
c files are direct access files. |
11 |
|
|
c |
12 |
|
|
c Routines: |
13 |
|
|
c |
14 |
|
|
c o active_read_rl_loc - Basic routine to handle active read |
15 |
|
|
c operations. |
16 |
|
|
c o active_write_rl_loc - Basic routine to handle active write |
17 |
|
|
c operations. |
18 |
|
|
c |
19 |
|
|
c |
20 |
|
|
c ================================================================== |
21 |
|
|
|
22 |
|
|
CBOP |
23 |
|
|
C !ROUTINE: active_read_rl_loc |
24 |
|
|
C !INTERFACE: |
25 |
|
|
subroutine active_read_rl_loc( |
26 |
|
|
I active_var_file, |
27 |
|
|
O active_var, |
28 |
|
|
I globalfile, |
29 |
|
|
I lAdInit, |
30 |
|
|
I irec, |
31 |
|
|
I mynr, |
32 |
|
|
I theSimulationMode, |
33 |
|
|
I myOptimIter, |
34 |
|
|
I mythid |
35 |
|
|
& ) |
36 |
|
|
|
37 |
|
|
C !DESCRIPTION: \bv |
38 |
|
|
c ================================================================== |
39 |
|
|
c o Read an active _RL variable from file. |
40 |
|
|
c The variable *globalfile* can be used as a switch, which allows |
41 |
|
|
c to read from a global file. The adjoint files are, however, always |
42 |
|
|
c treated as tiled files. |
43 |
|
|
c started: Christian Eckert eckert@mit.edu Jan-1999 |
44 |
|
|
c ================================================================== |
45 |
|
|
C \ev |
46 |
|
|
|
47 |
|
|
C !USES: |
48 |
|
|
implicit none |
49 |
|
|
|
50 |
|
|
c == global variables == |
51 |
|
|
#include "EEPARAMS.h" |
52 |
|
|
#include "SIZE.h" |
53 |
|
|
#include "PARAMS.h" |
54 |
heimbach |
1.5 |
#include "ctrl.h" |
55 |
heimbach |
1.2 |
|
56 |
|
|
C !INPUT/OUTPUT PARAMETERS: |
57 |
|
|
c == routine arguments == |
58 |
|
|
c active_var_file: filename |
59 |
|
|
c active_var: array |
60 |
|
|
c irec: record number |
61 |
|
|
c myOptimIter: number of optimization iteration (default: 0) |
62 |
|
|
c mythid: thread number for this instance |
63 |
|
|
c doglobalread: flag for global or local read/write |
64 |
|
|
c (default: .false.) |
65 |
|
|
c lAdInit: initialisation of corresponding adjoint |
66 |
|
|
c variable and write to active file |
67 |
|
|
c mynr: vertical array dimension |
68 |
|
|
c theSimulationMode: forward mode or reverse mode simulation |
69 |
|
|
character*(*) active_var_file |
70 |
|
|
logical globalfile |
71 |
|
|
logical lAdInit |
72 |
|
|
integer irec |
73 |
|
|
integer mynr |
74 |
|
|
integer theSimulationMode |
75 |
|
|
integer myOptimIter |
76 |
|
|
integer mythid |
77 |
|
|
_RL active_var(1-olx:snx+olx,1-oly:sny+oly,mynr,nsx,nsy) |
78 |
|
|
|
79 |
|
|
C !LOCAL VARIABLES: |
80 |
|
|
c == local variables == |
81 |
|
|
character*(2) adpref |
82 |
|
|
character*(80) adfname |
83 |
|
|
integer bi,bj |
84 |
|
|
integer i,j,k |
85 |
|
|
integer oldprec |
86 |
|
|
integer prec |
87 |
|
|
integer il |
88 |
|
|
integer ilnblnk |
89 |
|
|
logical writeglobalfile |
90 |
heimbach |
1.6 |
_RL active_data_t(1-olx:snx+olx,1-oly:sny+oly,mynr,nsx,nsy) |
91 |
heimbach |
1.2 |
|
92 |
|
|
c == functions == |
93 |
|
|
external ilnblnk |
94 |
|
|
|
95 |
|
|
c == end of interface == |
96 |
|
|
CEOP |
97 |
|
|
|
98 |
|
|
c force 64-bit io |
99 |
|
|
oldPrec = readBinaryPrec |
100 |
heimbach |
1.5 |
readBinaryPrec = ctrlprec |
101 |
|
|
prec = ctrlprec |
102 |
heimbach |
1.2 |
|
103 |
|
|
write(adfname(1:80),'(80a)') ' ' |
104 |
|
|
adpref = 'ad' |
105 |
|
|
il = ilnblnk( active_var_file ) |
106 |
|
|
|
107 |
|
|
write(adfname(1:2),'(a)') adpref |
108 |
|
|
write(adfname(3:il+2),'(a)') active_var_file(1:il) |
109 |
|
|
|
110 |
|
|
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
111 |
|
|
c >>>>>>>>>>>>>>>>>>> FORWARD RUN <<<<<<<<<<<<<<<<<<< |
112 |
|
|
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
113 |
|
|
|
114 |
|
|
if (theSimulationMode .eq. FORWARD_SIMULATION) then |
115 |
|
|
|
116 |
|
|
_BEGIN_MASTER( mythid ) |
117 |
|
|
|
118 |
|
|
c Read the active variable from file. |
119 |
|
|
|
120 |
jmc |
1.7 |
call mdsreadfield_loc( |
121 |
|
|
& active_var_file, |
122 |
|
|
& prec, |
123 |
heimbach |
1.2 |
& 'RL', |
124 |
jmc |
1.7 |
& mynr, |
125 |
heimbach |
1.2 |
& active_var, |
126 |
jmc |
1.7 |
& irec, |
127 |
heimbach |
1.2 |
& mythid ) |
128 |
|
|
|
129 |
|
|
if (lAdInit) then |
130 |
|
|
c Initialise the corresponding adjoint variable on the |
131 |
|
|
c adjoint variable's file. These files are tiled. |
132 |
|
|
|
133 |
|
|
writeglobalfile = .false. |
134 |
|
|
do bj = 1,nsy |
135 |
|
|
do bi = 1,nsx |
136 |
heimbach |
1.6 |
do k = 1, mynr |
137 |
|
|
do j=1,sny |
138 |
|
|
do i=1,snx |
139 |
|
|
active_data_t(i,j,k,bi,bj)= 0. _d 0 |
140 |
|
|
enddo |
141 |
heimbach |
1.2 |
enddo |
142 |
|
|
enddo |
143 |
|
|
enddo |
144 |
|
|
enddo |
145 |
|
|
|
146 |
jmc |
1.7 |
call mdswritefield_loc( |
147 |
|
|
& adfname, |
148 |
|
|
& prec, |
149 |
heimbach |
1.2 |
& globalfile, |
150 |
jmc |
1.7 |
& 'RL', |
151 |
heimbach |
1.6 |
& mynr, |
152 |
heimbach |
1.2 |
& active_data_t, |
153 |
heimbach |
1.6 |
& irec, |
154 |
heimbach |
1.2 |
& myOptimIter, |
155 |
|
|
& mythid ) |
156 |
|
|
endif |
157 |
|
|
|
158 |
|
|
_END_MASTER( mythid ) |
159 |
|
|
|
160 |
|
|
endif |
161 |
|
|
|
162 |
|
|
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
163 |
|
|
c >>>>>>>>>>>>>>>>>>> ADJOINT RUN <<<<<<<<<<<<<<<<<<< |
164 |
|
|
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
165 |
|
|
|
166 |
|
|
if (theSimulationMode .eq. REVERSE_SIMULATION) then |
167 |
|
|
|
168 |
|
|
_BEGIN_MASTER( mythid ) |
169 |
|
|
|
170 |
|
|
writeglobalfile = .false. |
171 |
jmc |
1.7 |
call mdsreadfield_loc( |
172 |
|
|
& active_var_file, |
173 |
|
|
& prec, |
174 |
heimbach |
1.2 |
& 'RL', |
175 |
jmc |
1.7 |
& mynr, |
176 |
|
|
& active_data_t, |
177 |
heimbach |
1.6 |
& irec, |
178 |
heimbach |
1.2 |
& mythid ) |
179 |
|
|
|
180 |
|
|
c Add active_var from appropriate location to data. |
181 |
heimbach |
1.6 |
do bj = 1,nsy |
182 |
|
|
do bi = 1,nsx |
183 |
|
|
do k = 1, mynr |
184 |
heimbach |
1.2 |
do j=1,sny |
185 |
|
|
do i=1,snx |
186 |
jmc |
1.7 |
active_data_t(i,j,k,bi,bj) = |
187 |
heimbach |
1.6 |
& active_data_t(i,j,k,bi,bj) + |
188 |
heimbach |
1.2 |
& active_var(i,j,k,bi,bj) |
189 |
|
|
enddo |
190 |
|
|
enddo |
191 |
|
|
enddo |
192 |
|
|
enddo |
193 |
heimbach |
1.6 |
enddo |
194 |
heimbach |
1.2 |
|
195 |
|
|
c Store the result on disk. |
196 |
jmc |
1.7 |
call mdswritefield_loc( |
197 |
|
|
& active_var_file, |
198 |
heimbach |
1.2 |
& prec, |
199 |
jmc |
1.7 |
& writeglobalfile, |
200 |
heimbach |
1.2 |
& 'RL', |
201 |
jmc |
1.7 |
& mynr, |
202 |
|
|
& active_data_t, |
203 |
|
|
& irec, |
204 |
heimbach |
1.2 |
& myOptimIter, |
205 |
|
|
& mythid ) |
206 |
|
|
|
207 |
|
|
c Set active_var to zero. |
208 |
heimbach |
1.6 |
do bj = 1,nsy |
209 |
|
|
do bi = 1,nsx |
210 |
|
|
do k=1,mynr |
211 |
heimbach |
1.2 |
do j=1,sny |
212 |
|
|
do i=1,snx |
213 |
|
|
active_var(i,j,k,bi,bj) = 0. _d 0 |
214 |
|
|
enddo |
215 |
|
|
enddo |
216 |
|
|
enddo |
217 |
|
|
enddo |
218 |
|
|
enddo |
219 |
|
|
|
220 |
|
|
_END_MASTER( mythid ) |
221 |
|
|
endif |
222 |
|
|
|
223 |
|
|
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
224 |
|
|
c >>>>>>>>>>>>>>>>>>> TANGENT RUN <<<<<<<<<<<<<<<<<<< |
225 |
|
|
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
226 |
|
|
|
227 |
|
|
if (theSimulationMode .eq. TANGENT_SIMULATION) then |
228 |
|
|
|
229 |
|
|
_BEGIN_MASTER( mythid ) |
230 |
|
|
|
231 |
|
|
c Read the active variable from file. |
232 |
|
|
|
233 |
jmc |
1.7 |
call mdsreadfield_loc( |
234 |
|
|
& active_var_file, |
235 |
|
|
& prec, |
236 |
heimbach |
1.2 |
& 'RL', |
237 |
jmc |
1.7 |
& mynr, |
238 |
heimbach |
1.2 |
& active_var, |
239 |
jmc |
1.7 |
& irec, |
240 |
heimbach |
1.2 |
& mythid ) |
241 |
|
|
|
242 |
|
|
_END_MASTER( mythid ) |
243 |
|
|
endif |
244 |
|
|
|
245 |
|
|
c Reset default io precision. |
246 |
|
|
readBinaryPrec = oldPrec |
247 |
|
|
|
248 |
|
|
_BARRIER |
249 |
|
|
|
250 |
|
|
return |
251 |
|
|
end |
252 |
|
|
|
253 |
|
|
|
254 |
|
|
CBOP |
255 |
|
|
C !ROUTINE: active_write_rl_loc |
256 |
|
|
C !INTERFACE: |
257 |
|
|
subroutine active_write_rl_loc( |
258 |
|
|
I active_var_file, |
259 |
|
|
I active_var, |
260 |
|
|
I globalfile, |
261 |
|
|
I irec, |
262 |
|
|
I mynr, |
263 |
|
|
I theSimulationMode, |
264 |
|
|
I myOptimIter, |
265 |
|
|
I mythid |
266 |
|
|
& ) |
267 |
|
|
|
268 |
|
|
C !DESCRIPTION: \bv |
269 |
|
|
c ================================================================== |
270 |
|
|
c o Write an active _RL variable to a file. |
271 |
|
|
c started: Christian Eckert eckert@mit.edu Jan-1999 |
272 |
|
|
c ================================================================== |
273 |
|
|
C \ev |
274 |
|
|
|
275 |
|
|
C !USES: |
276 |
|
|
implicit none |
277 |
|
|
|
278 |
|
|
c == global variables == |
279 |
|
|
#include "EEPARAMS.h" |
280 |
|
|
#include "SIZE.h" |
281 |
|
|
#include "PARAMS.h" |
282 |
heimbach |
1.5 |
#include "ctrl.h" |
283 |
heimbach |
1.2 |
|
284 |
|
|
C !INPUT/OUTPUT PARAMETERS: |
285 |
|
|
c == routine arguments == |
286 |
|
|
c active_var_file: filename |
287 |
|
|
c active_var: array |
288 |
|
|
c irec: record number |
289 |
|
|
c myOptimIter: number of optimization iteration (default: 0) |
290 |
|
|
c mythid: thread number for this instance |
291 |
|
|
c doglobalread: flag for global or local read/write |
292 |
|
|
c (default: .false.) |
293 |
|
|
c lAdInit: initialisation of corresponding adjoint |
294 |
|
|
c variable and write to active file |
295 |
|
|
c mynr: vertical array dimension |
296 |
|
|
c theSimulationMode: forward mode or reverse mode simulation |
297 |
|
|
character*(*) active_var_file |
298 |
|
|
integer mynr |
299 |
|
|
logical globalfile |
300 |
|
|
integer irec |
301 |
|
|
integer theSimulationMode |
302 |
|
|
integer myOptimIter |
303 |
|
|
integer mythid |
304 |
|
|
_RL active_var(1-olx:snx+olx,1-oly:sny+oly,mynr,nsx,nsy) |
305 |
|
|
|
306 |
|
|
C !LOCAL VARIABLES: |
307 |
|
|
c == local variables == |
308 |
|
|
integer i,j,k |
309 |
|
|
integer bi,bj |
310 |
heimbach |
1.6 |
_RL active_data_t(1-olx:snx+olx,1-oly:sny+oly,mynr,nsx,nsy) |
311 |
heimbach |
1.2 |
integer oldprec |
312 |
|
|
integer prec |
313 |
|
|
|
314 |
|
|
c == end of interface == |
315 |
|
|
CEOP |
316 |
|
|
|
317 |
|
|
c force 64-bit io |
318 |
|
|
oldPrec = readBinaryPrec |
319 |
heimbach |
1.5 |
readBinaryPrec = ctrlprec |
320 |
|
|
prec = ctrlprec |
321 |
heimbach |
1.2 |
|
322 |
|
|
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
323 |
|
|
c >>>>>>>>>>>>>>>>>>> FORWARD RUN <<<<<<<<<<<<<<<<<<< |
324 |
|
|
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
325 |
|
|
|
326 |
|
|
if (theSimulationMode .eq. FORWARD_SIMULATION) then |
327 |
|
|
|
328 |
|
|
_BEGIN_MASTER( mythid ) |
329 |
|
|
|
330 |
jmc |
1.7 |
call mdswritefield_loc( |
331 |
|
|
& active_var_file, |
332 |
|
|
& prec, |
333 |
heimbach |
1.2 |
& globalfile, |
334 |
jmc |
1.7 |
& 'RL', |
335 |
|
|
& mynr, |
336 |
|
|
& active_var, |
337 |
|
|
& irec, |
338 |
heimbach |
1.2 |
& myOptimIter, |
339 |
|
|
& mythid ) |
340 |
|
|
|
341 |
|
|
_END_MASTER( mythid ) |
342 |
|
|
|
343 |
|
|
endif |
344 |
|
|
|
345 |
|
|
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
346 |
|
|
c >>>>>>>>>>>>>>>>>>> ADJOINT RUN <<<<<<<<<<<<<<<<<<< |
347 |
|
|
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
348 |
|
|
|
349 |
|
|
if (theSimulationMode .eq. REVERSE_SIMULATION) then |
350 |
|
|
|
351 |
|
|
_BEGIN_MASTER( mythid ) |
352 |
|
|
|
353 |
jmc |
1.7 |
call mdsreadfield_loc( |
354 |
|
|
& active_var_file, |
355 |
|
|
& prec, |
356 |
heimbach |
1.2 |
& 'RL', |
357 |
heimbach |
1.6 |
& mynr, |
358 |
jmc |
1.7 |
& active_data_t, |
359 |
|
|
& irec, |
360 |
heimbach |
1.2 |
& mythid ) |
361 |
|
|
|
362 |
|
|
c Add active_var from appropriate location to data. |
363 |
heimbach |
1.6 |
do bj = 1,nsy |
364 |
|
|
do bi = 1,nsx |
365 |
|
|
do k = 1,mynr |
366 |
|
|
do j=1,sny |
367 |
|
|
do i=1,snx |
368 |
jmc |
1.7 |
active_var(i,j,k,bi,bj) = |
369 |
heimbach |
1.6 |
& active_var(i,j,k,bi,bj) + |
370 |
|
|
& active_data_t(i,j,k,bi,bj) |
371 |
|
|
active_data_t(i,j,k,bi,bj) = 0. _d 0 |
372 |
heimbach |
1.2 |
enddo |
373 |
|
|
enddo |
374 |
|
|
enddo |
375 |
heimbach |
1.6 |
enddo |
376 |
|
|
enddo |
377 |
jmc |
1.7 |
call mdswritefield_loc( |
378 |
|
|
& active_var_file, |
379 |
|
|
& prec, |
380 |
heimbach |
1.2 |
& globalfile, |
381 |
jmc |
1.7 |
& 'RL', |
382 |
|
|
& mynr, |
383 |
|
|
& active_data_t, |
384 |
|
|
& irec, |
385 |
heimbach |
1.2 |
& myOptimIter, |
386 |
|
|
& mythid ) |
387 |
|
|
|
388 |
|
|
_END_MASTER( mythid ) |
389 |
|
|
|
390 |
|
|
endif |
391 |
|
|
|
392 |
|
|
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
393 |
|
|
c >>>>>>>>>>>>>>>>>>> TANGENT RUN <<<<<<<<<<<<<<<<<<< |
394 |
|
|
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
395 |
|
|
|
396 |
|
|
if (theSimulationMode .eq. TANGENT_SIMULATION) then |
397 |
|
|
|
398 |
|
|
_BEGIN_MASTER( mythid ) |
399 |
|
|
|
400 |
jmc |
1.7 |
call mdswritefield_loc( |
401 |
|
|
& active_var_file, |
402 |
|
|
& prec, |
403 |
heimbach |
1.2 |
& globalfile, |
404 |
jmc |
1.7 |
& 'RL', |
405 |
|
|
& mynr, |
406 |
|
|
& active_var, |
407 |
|
|
& irec, |
408 |
heimbach |
1.2 |
& myOptimIter, |
409 |
|
|
& mythid ) |
410 |
|
|
|
411 |
|
|
_END_MASTER( mythid ) |
412 |
|
|
|
413 |
|
|
endif |
414 |
|
|
|
415 |
|
|
c Reset default io precision. |
416 |
|
|
readBinaryPrec = oldPrec |
417 |
|
|
|
418 |
|
|
_BARRIER |
419 |
|
|
|
420 |
|
|
return |
421 |
|
|
end |
422 |
|
|
|