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

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

  ViewVC Help
Powered by ViewVC 1.1.22