| 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 |
CBOP |
| 61 |
C !ROUTINE: adread |
| 62 |
C !INTERFACE: |
| 63 |
subroutine adread( |
| 64 |
I mythid, |
| 65 |
I name, |
| 66 |
I len, |
| 67 |
I tid, |
| 68 |
I vid, |
| 69 |
O var, |
| 70 |
I size, |
| 71 |
I length, |
| 72 |
I irec |
| 73 |
& ) |
| 74 |
|
| 75 |
C !DESCRIPTION: \bv |
| 76 |
c ================================================================== |
| 77 |
c SUBROUTINE adread |
| 78 |
c ================================================================== |
| 79 |
c o Read direct access file. |
| 80 |
c A call to this routine implies an open-read-close sequence |
| 81 |
c since it uses the MITgcmUV i/o routine MDSREADVECTOR. Only |
| 82 |
c the master thread reads the data. Otherwise each thread would |
| 83 |
c read from file. |
| 84 |
c started: Christian Eckert eckert@mit.edu 30-Jun-1999 |
| 85 |
c ================================================================== |
| 86 |
c SUBROUTINE adread |
| 87 |
c ================================================================== |
| 88 |
C \ev |
| 89 |
|
| 90 |
C !USES: |
| 91 |
implicit none |
| 92 |
|
| 93 |
c == global variables == |
| 94 |
#include "EEPARAMS.h" |
| 95 |
#include "SIZE.h" |
| 96 |
#include "ctrl.h" |
| 97 |
#include "optim.h" |
| 98 |
|
| 99 |
C !INPUT/OUTPUT PARAMETERS: |
| 100 |
c == routine arguments == |
| 101 |
c name - extended tape name. |
| 102 |
c len - number of characters in name. |
| 103 |
c tid - tape identifier. |
| 104 |
c vid - identifies the variable to be stored on tape. |
| 105 |
c var - values to be stored. |
| 106 |
c size - size in bytes of the type of variable var. |
| 107 |
c length - dimension of the variable stored on the tape. |
| 108 |
c mythid - number of the thread or instance of the program. |
| 109 |
c irec - record number to be written. |
| 110 |
|
| 111 |
integer mythid |
| 112 |
character*(*) name |
| 113 |
integer len |
| 114 |
integer tid |
| 115 |
integer vid |
| 116 |
integer size |
| 117 |
integer length |
| 118 |
integer irec |
| 119 |
_RL var(length) |
| 120 |
|
| 121 |
C !LOCAL VARIABLES: |
| 122 |
c == local variables == |
| 123 |
character*(7) itername |
| 124 |
character*(80) fname |
| 125 |
integer il |
| 126 |
integer bx,by |
| 127 |
|
| 128 |
c == functions == |
| 129 |
integer ilnblnk |
| 130 |
external ilnblnk |
| 131 |
|
| 132 |
c == end of interface == |
| 133 |
CEOP |
| 134 |
|
| 135 |
write(fname(1:80),'(a)') ' ' |
| 136 |
write(itername,'(a,i4.4)') '.it',optimcycle |
| 137 |
|
| 138 |
il = ilnblnk( name ) |
| 139 |
|
| 140 |
write(fname(1:il+7),'(a,a)') name(1:il),itername |
| 141 |
|
| 142 |
_BEGIN_MASTER( mythid ) |
| 143 |
by = myByLo(myThid) |
| 144 |
bx = myBxLo(myThid) |
| 145 |
call mdsreadvector( fname, size*8, 'RL', |
| 146 |
& length, var, bx, by, irec, mythid ) |
| 147 |
_END_MASTER( mythid ) |
| 148 |
|
| 149 |
c Everyone must wait for the read operation to be completed. |
| 150 |
_BARRIER |
| 151 |
|
| 152 |
return |
| 153 |
end |
| 154 |
|
| 155 |
|
| 156 |
CBOP |
| 157 |
C !ROUTINE: adwrite |
| 158 |
C !INTERFACE: |
| 159 |
subroutine adwrite( |
| 160 |
I mythid, |
| 161 |
I name, |
| 162 |
I len, |
| 163 |
I tid, |
| 164 |
I vid, |
| 165 |
I var, |
| 166 |
I size, |
| 167 |
I length, |
| 168 |
I irec |
| 169 |
& ) |
| 170 |
|
| 171 |
C !DESCRIPTION: \bv |
| 172 |
c ================================================================== |
| 173 |
c SUBROUTINE adwrite |
| 174 |
c ================================================================== |
| 175 |
c o Write to direct access file. |
| 176 |
c A call to this routine implies an open-read-close sequence |
| 177 |
c since it uses the MITgcmUV i/o routine MDSREADVECTOR. Only |
| 178 |
c the master thread writes the data. Otherwise each thread would |
| 179 |
c write to file. This would result in an excessive waste of |
| 180 |
c disk space. |
| 181 |
c started: Christian Eckert eckert@mit.edu 30-Jun-1999 |
| 182 |
c ================================================================== |
| 183 |
c SUBROUTINE adwrite |
| 184 |
c ================================================================== |
| 185 |
C \ev |
| 186 |
|
| 187 |
C !USES: |
| 188 |
implicit none |
| 189 |
|
| 190 |
c == global variables == |
| 191 |
#include "EEPARAMS.h" |
| 192 |
#include "SIZE.h" |
| 193 |
#include "ctrl.h" |
| 194 |
#include "optim.h" |
| 195 |
|
| 196 |
C !INPUT/OUTPUT PARAMETERS: |
| 197 |
c == routine arguments == |
| 198 |
c name - extended tape name. |
| 199 |
c len - number of characters in name. |
| 200 |
c tid - tape identifier. |
| 201 |
c vid - identifies the variable to be stored on tape. |
| 202 |
c var - values to be stored. |
| 203 |
c size - size in bytes of the type of variable var. |
| 204 |
c length - dimension of the variable stored on the tape. |
| 205 |
c mythid - number of the thread or instance of the program. |
| 206 |
c irec - record number to be written. |
| 207 |
|
| 208 |
integer mythid |
| 209 |
character*(*) name |
| 210 |
integer len |
| 211 |
integer tid |
| 212 |
integer vid |
| 213 |
integer size |
| 214 |
integer length |
| 215 |
integer irec |
| 216 |
_RL var(length) |
| 217 |
|
| 218 |
C !LOCAL VARIABLES: |
| 219 |
c == local variables == |
| 220 |
character*(7) itername |
| 221 |
character*(80) fname |
| 222 |
integer il |
| 223 |
integer bx,by |
| 224 |
logical globalfile |
| 225 |
|
| 226 |
c == functions == |
| 227 |
integer ilnblnk |
| 228 |
external ilnblnk |
| 229 |
|
| 230 |
c == end of interface == |
| 231 |
CEOP |
| 232 |
|
| 233 |
globalfile = .false. |
| 234 |
il = ilnblnk( name ) |
| 235 |
write(fname(1:80),'(a)') ' ' |
| 236 |
|
| 237 |
write(itername,'(a,i4.4)') '.it',optimcycle |
| 238 |
|
| 239 |
write(fname(1:il+7),'(a,a)') name(1:il),itername |
| 240 |
|
| 241 |
_BEGIN_MASTER( mythid ) |
| 242 |
by = myByLo(myThid) |
| 243 |
bx = myBxLo(myThid) |
| 244 |
call mdswritevector( fname, size*8, globalfile, 'RL', |
| 245 |
& length, var, bx, by, irec, 0, mythid ) |
| 246 |
_END_MASTER( mythid ) |
| 247 |
|
| 248 |
c Everyone must wait for the write operation to be completed. |
| 249 |
_BARRIER |
| 250 |
|
| 251 |
return |
| 252 |
end |