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

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.10

  ViewVC Help
Powered by ViewVC 1.1.22