1 |
|
2 |
#include "CPP_OPTIONS.h" |
3 |
|
4 |
c ================================================================== |
5 |
c |
6 |
c ad_read_write.F: routines to handle the I/O of the TAMC generated |
7 |
c code. All files are direct access files. |
8 |
c Routines: |
9 |
c |
10 |
c o adread - Read data from file. |
11 |
c o adwrite - Write data to file. |
12 |
c |
13 |
c |
14 |
c The following input veriables are used throughout in the argument |
15 |
c lists: |
16 |
c |
17 |
c name - character |
18 |
c On entry, name is the extended tape name. |
19 |
c len - integer |
20 |
c On entry, len is the number of characters in name. |
21 |
c tid - integer |
22 |
c On entry, tid identifies the tape. |
23 |
c vid - integer |
24 |
c On entry, vid identifies the variable to be stored on |
25 |
c the tape. |
26 |
c var - real array of dimension length |
27 |
c On entry, var contains the values to be stored. |
28 |
c var must not be changed. |
29 |
c size - integer |
30 |
c On entry, size is the size in bytes of the type of |
31 |
c variable var. |
32 |
c length - integer |
33 |
c On entry, length is the dimension of the variable |
34 |
c stored on the tape. |
35 |
c irec - integer |
36 |
c On entry, irec is the record number to be written. |
37 |
c mythid - integer |
38 |
c On entry, mythid is the number of the thread or |
39 |
c instance of the program. |
40 |
c myiter - integer |
41 |
c On entry, myiter is the current iteration step during |
42 |
c the integration. |
43 |
c |
44 |
c For further details on this see the TAMC Users Manual, Appendix B, |
45 |
c User defined Storage Subroutines. |
46 |
c |
47 |
c TAMC does not provide the two leading arguments mythid and myiter |
48 |
c when compiling the MITgcmUV code. Instead the is a sed script avail- |
49 |
c able that does change the TAMC-generated adjoint code. |
50 |
c |
51 |
c Only the master thread is allowed to write data and only gobal |
52 |
c model arrays are allowed to be written be the subsequent routines. |
53 |
c Tiled data are to be stored in common blocks. This implies that at |
54 |
c least a two level checkpointing for the adjoint code has to be |
55 |
c available. |
56 |
c |
57 |
c ================================================================== |
58 |
|
59 |
|
60 |
subroutine adread( |
61 |
I mythid, |
62 |
I name, |
63 |
I len, |
64 |
I tid, |
65 |
I vid, |
66 |
O var, |
67 |
I size, |
68 |
I length, |
69 |
I irec |
70 |
& ) |
71 |
|
72 |
c ================================================================== |
73 |
c SUBROUTINE adread |
74 |
c ================================================================== |
75 |
c |
76 |
c o Read direct access file. |
77 |
c |
78 |
c A call to this routine implies an open-read-close sequence |
79 |
c since it uses the MITgcmUV i/o routine MDSREADVECTOR. Only |
80 |
c the master thread reads the data. Otherwise each thread would |
81 |
c read from file. |
82 |
c |
83 |
c started: Christian Eckert eckert@mit.edu 30-Jun-1999 |
84 |
c |
85 |
c changed: Christian Eckert eckert@mit.edu 15-Feb-2000 |
86 |
c |
87 |
c - Restructured the code in order to create a package |
88 |
c for the MITgcmUV. |
89 |
c |
90 |
c changed: Patrick Heimbach heimbach@mit.edu 27-May-2000 |
91 |
c |
92 |
c - changed subroutine parameter list: skipped myiter |
93 |
c |
94 |
c ================================================================== |
95 |
c SUBROUTINE adread |
96 |
c ================================================================== |
97 |
|
98 |
implicit none |
99 |
|
100 |
c == global variables == |
101 |
|
102 |
#include "EEPARAMS.h" |
103 |
#include "SIZE.h" |
104 |
#include "ctrl.h" |
105 |
#include "optim.h" |
106 |
|
107 |
c == routine arguments == |
108 |
|
109 |
integer mythid |
110 |
character*(*) name |
111 |
integer len |
112 |
integer tid |
113 |
integer vid |
114 |
integer size |
115 |
integer length |
116 |
integer irec |
117 |
_RL var(length) |
118 |
|
119 |
c == local variables == |
120 |
|
121 |
character*(7) itername |
122 |
character*(80) fname |
123 |
integer il |
124 |
integer bx,by |
125 |
|
126 |
c == functions == |
127 |
|
128 |
integer ilnblnk |
129 |
external ilnblnk |
130 |
|
131 |
c == end of interface == |
132 |
|
133 |
write(fname(1:80),'(a)') ' ' |
134 |
write(itername,'(a,i4.4)') '.it',optimcycle |
135 |
|
136 |
il = ilnblnk( name ) |
137 |
|
138 |
write(fname(1:il+7),'(a,a)') name(1:il),itername |
139 |
|
140 |
_BEGIN_MASTER( mythid ) |
141 |
by = myByLo(myThid) |
142 |
bx = myBxLo(myThid) |
143 |
call mdsreadvector( fname, size*8, 'RL', |
144 |
& length, var, bx, by, irec, mythid ) |
145 |
_END_MASTER( mythid ) |
146 |
|
147 |
c Everyone must wait for the read operation to be completed. |
148 |
_BARRIER |
149 |
|
150 |
return |
151 |
end |
152 |
|
153 |
|
154 |
subroutine adwrite( |
155 |
I mythid, |
156 |
I name, |
157 |
I len, |
158 |
I tid, |
159 |
I vid, |
160 |
I var, |
161 |
I size, |
162 |
I length, |
163 |
I irec |
164 |
& ) |
165 |
|
166 |
c ================================================================== |
167 |
c SUBROUTINE adwrite |
168 |
c ================================================================== |
169 |
c |
170 |
c o Write to direct access file. |
171 |
c |
172 |
c A call to this routine implies an open-read-close sequence |
173 |
c since it uses the MITgcmUV i/o routine MDSREADVECTOR. Only |
174 |
c the master thread writes the data. Otherwise each thread would |
175 |
c write to file. This would result in an excessive waste of |
176 |
c disk space. |
177 |
c |
178 |
c started: Christian Eckert eckert@mit.edu 30-Jun-1999 |
179 |
c |
180 |
c changed: Christian Eckert eckert@mit.edu 15-Feb-2000 |
181 |
c |
182 |
c - Restructured the code in order to create a package |
183 |
c for the MITgcmUV. |
184 |
c |
185 |
c changed: Patrick Heimbach heimbach@mit.edu 27-May-2000 |
186 |
c |
187 |
c - changed subroutine parameter list: skipped myiter |
188 |
c |
189 |
c ================================================================== |
190 |
c SUBROUTINE adwrite |
191 |
c ================================================================== |
192 |
|
193 |
implicit none |
194 |
|
195 |
c == global variables == |
196 |
|
197 |
#include "EEPARAMS.h" |
198 |
#include "SIZE.h" |
199 |
#include "ctrl.h" |
200 |
#include "optim.h" |
201 |
|
202 |
c == routine arguments == |
203 |
|
204 |
integer mythid |
205 |
character*(*) name |
206 |
integer len |
207 |
integer tid |
208 |
integer vid |
209 |
integer size |
210 |
integer length |
211 |
integer irec |
212 |
_RL var(length) |
213 |
|
214 |
c == local variables == |
215 |
|
216 |
character*(7) itername |
217 |
character*(80) fname |
218 |
integer il |
219 |
integer bx,by |
220 |
logical globalfile |
221 |
|
222 |
c == functions == |
223 |
|
224 |
integer ilnblnk |
225 |
external ilnblnk |
226 |
|
227 |
c == end of interface == |
228 |
|
229 |
globalfile = .false. |
230 |
il = ilnblnk( name ) |
231 |
write(fname(1:80),'(a)') ' ' |
232 |
|
233 |
write(itername,'(a,i4.4)') '.it',optimcycle |
234 |
|
235 |
write(fname(1:il+7),'(a,a)') name(1:il),itername |
236 |
|
237 |
_BEGIN_MASTER( mythid ) |
238 |
by = myByLo(myThid) |
239 |
bx = myBxLo(myThid) |
240 |
call mdswritevector( fname, size*8, globalfile, 'RL', |
241 |
& length, var, bx, by, irec, 0, mythid ) |
242 |
_END_MASTER( mythid ) |
243 |
|
244 |
c Everyone must wait for the write operation to be completed. |
245 |
_BARRIER |
246 |
|
247 |
return |
248 |
end |