/[MITgcm]/MITgcm/pkg/autodiff/active_file_loc_control.F
ViewVC logotype

Contents of /MITgcm/pkg/autodiff/active_file_loc_control.F

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.6 - (show annotations) (download)
Tue Jul 26 13:10:46 2005 UTC (18 years, 9 months ago) by heimbach
Branch: MAIN
CVS Tags: checkpoint57t_post, checkpoint58l_post, checkpoint57o_post, checkpoint57m_post, checkpoint58e_post, checkpoint57v_post, checkpoint57s_post, checkpoint58u_post, checkpoint58r_post, checkpoint57y_post, checkpoint58g_post, checkpoint57x_post, checkpoint58n_post, checkpoint58x_post, checkpoint58t_post, checkpoint58h_post, checkpoint58w_post, checkpoint58j_post, checkpoint57y_pre, checkpoint58q_post, checkpoint59e, checkpoint59d, checkpoint59g, checkpoint59f, checkpoint59a, checkpoint59c, checkpoint59b, checkpoint59h, checkpoint57r_post, checkpoint59, checkpoint58, checkpoint58f_post, checkpoint57n_post, checkpoint58d_post, checkpoint58c_post, checkpoint57w_post, checkpoint57p_post, checkpint57u_post, checkpoint58a_post, checkpoint58i_post, checkpoint57q_post, checkpoint58o_post, checkpoint57z_post, checkpoint58y_post, checkpoint58k_post, checkpoint58v_post, checkpoint58s_post, checkpoint58p_post, checkpoint58b_post, checkpoint58m_post
Changes since 1.5: +42 -44 lines
Re-structured unnecessary k-loop bracketing mdsio routines.

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

  ViewVC Help
Powered by ViewVC 1.1.22