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

Diff of /MITgcm/pkg/autodiff/active_file_control_slice.F

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

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

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

  ViewVC Help
Powered by ViewVC 1.1.22