1 |
C $Header: /u/gcmpack/MITgcm/pkg/autodiff/active_file.F,v 1.9 2012/08/02 22:10:31 jmc Exp $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "AUTODIFF_OPTIONS.h" |
5 |
|
6 |
C ================================================================== |
7 |
C active_file_gen.F: Routines to handle the I/O of the active file |
8 |
C for the adjoint calculations. |
9 |
C Routines |
10 |
C o ACTIVE_READ_GEN_RL - Read an active RL variable from file. |
11 |
C o ACTIVE_READ_GEN_RS - Read an active RS variable from file. |
12 |
C |
13 |
C o ACTIVE_WRITE_GEN_RL - Write an active RL variable to a file. |
14 |
C o ACTIVE_WRITE_GEN_RS - Write an active RS variable to a file. |
15 |
C |
16 |
C Generic version for each array type (_RL or _RS). |
17 |
C Note: the _RL version can replace the 4 x 2 shape-specific |
18 |
C (_xy,_xyz,_xz,_yz) and standard or "_loc' routines. |
19 |
C ================================================================== |
20 |
|
21 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
22 |
CBOP |
23 |
C !ROUTINE: ACTIVE_READ_GEN_RL |
24 |
C !INTERFACE: |
25 |
SUBROUTINE ACTIVE_READ_GEN_RL( |
26 |
I activeVar_file, |
27 |
O active_var, |
28 |
I arrShape, myNr, |
29 |
I iRec, |
30 |
I globalFile, |
31 |
I useCurrentDir, |
32 |
I lAdInit, |
33 |
I myOptimIter, |
34 |
I myThid, |
35 |
I dummy ) |
36 |
|
37 |
C !DESCRIPTION: \bv |
38 |
C ================================================================== |
39 |
C SUBROUTINE ACTIVE_READ_GEN_RL |
40 |
C ================================================================== |
41 |
C o Read an active (_RL) variable from file (generic version). |
42 |
C Accept active variable of various (XY,XZ,YZ) shape and level |
43 |
C number, according to arguments arrShape and myNr. |
44 |
C ================================================================== |
45 |
C \ev |
46 |
|
47 |
C !USES: |
48 |
IMPLICIT NONE |
49 |
|
50 |
C == global variables == |
51 |
#include "EEPARAMS.h" |
52 |
|
53 |
C !INPUT/OUTPUT PARAMETERS: |
54 |
C activeVar_file :: filename |
55 |
C active_var :: active variable array |
56 |
C arrShape :: shape of active-var array ('XY','XZ' or 'YZ') |
57 |
C myNr :: number of vertical-levels in active-var array |
58 |
C iRec :: record number in file |
59 |
C globalFile :: used for writing global (if =T) or tiled files |
60 |
C useCurrentDir :: always read from the current directory |
61 |
C (even if "mdsioLocalDir" is set) |
62 |
C lAdInit :: initialisation of corresponding adjoint variable |
63 |
C and write to active file |
64 |
C myOptimIter :: number of optimization iteration (default: 0) |
65 |
C myThid :: my Thread Id number |
66 |
C dummy :: (needed for 2nd derivative code) |
67 |
CHARACTER*(*) activeVar_file |
68 |
_RL active_var(*) |
69 |
CHARACTER*(2) arrShape |
70 |
INTEGER myNr |
71 |
INTEGER iRec |
72 |
LOGICAL globalFile |
73 |
LOGICAL useCurrentDir |
74 |
LOGICAL lAdInit |
75 |
INTEGER myOptimIter |
76 |
INTEGER myThid |
77 |
_RL dummy |
78 |
|
79 |
C !LOCAL VARIABLES: |
80 |
CEOP |
81 |
|
82 |
IF ( arrShape.EQ.'XY' ) THEN |
83 |
|
84 |
CALL ACTIVE_READ_3D_RL( |
85 |
& activeVar_file, active_var, globalFile, |
86 |
& useCurrentDir, lAdInit, iRec, myNr, |
87 |
& FORWARD_SIMULATION, myOptimIter, myThid ) |
88 |
|
89 |
ELSEIF ( arrShape.EQ.'XZ' ) THEN |
90 |
|
91 |
CALL ACTIVE_READ_XZ_RL( |
92 |
& activeVar_file, active_var, globalFile, |
93 |
& useCurrentDir, lAdInit, iRec, myNr, |
94 |
& FORWARD_SIMULATION, myOptimIter, myThid ) |
95 |
|
96 |
ELSEIF ( arrShape.EQ.'YZ' ) THEN |
97 |
|
98 |
CALL ACTIVE_READ_YZ_RL( |
99 |
& activeVar_file, active_var, globalFile, |
100 |
& useCurrentDir, lAdInit, iRec, myNr, |
101 |
& FORWARD_SIMULATION, myOptimIter, myThid ) |
102 |
|
103 |
ELSE |
104 |
STOP |
105 |
& 'ABNORMAL END: S/R ACTIVE_READ_GEN_RL: invalid arrShape' |
106 |
ENDIF |
107 |
|
108 |
RETURN |
109 |
END |
110 |
|
111 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
112 |
CBOP |
113 |
C !ROUTINE: ACTIVE_READ_GEN_RS |
114 |
C !INTERFACE: |
115 |
SUBROUTINE ACTIVE_READ_GEN_RS( |
116 |
I activeVar_file, |
117 |
O active_var, |
118 |
I arrShape, myNr, |
119 |
I iRec, |
120 |
I globalFile, |
121 |
I useCurrentDir, |
122 |
I lAdInit, |
123 |
I myOptimIter, |
124 |
I myThid, |
125 |
I dummy ) |
126 |
|
127 |
C !DESCRIPTION: \bv |
128 |
C ================================================================== |
129 |
C SUBROUTINE ACTIVE_READ_GEN_RS |
130 |
C ================================================================== |
131 |
C o Read an active (_RS) variable from file (generic version). |
132 |
C Accept active variable of various (XY,XZ,YZ) shape and level |
133 |
C number, according to arguments arrShape and myNr. |
134 |
C ================================================================== |
135 |
C \ev |
136 |
|
137 |
C !USES: |
138 |
IMPLICIT NONE |
139 |
|
140 |
C == global variables == |
141 |
#include "EEPARAMS.h" |
142 |
|
143 |
C !INPUT/OUTPUT PARAMETERS: |
144 |
C activeVar_file :: filename |
145 |
C active_var :: active variable array |
146 |
C arrShape :: shape of active-var array ('XY','XZ' or 'YZ') |
147 |
C myNr :: number of vertical-levels in active-var array |
148 |
C iRec :: record number in file |
149 |
C globalFile :: used for writing global (if =T) or tiled files |
150 |
C useCurrentDir :: always read from the current directory |
151 |
C (even if "mdsioLocalDir" is set) |
152 |
C lAdInit :: initialisation of corresponding adjoint variable |
153 |
C and write to active file |
154 |
C myOptimIter :: number of optimization iteration (default: 0) |
155 |
C myThid :: my Thread Id number |
156 |
C dummy :: (needed for 2nd derivative code) |
157 |
CHARACTER*(*) activeVar_file |
158 |
_RS active_var(*) |
159 |
CHARACTER*(2) arrShape |
160 |
INTEGER myNr |
161 |
INTEGER iRec |
162 |
LOGICAL globalFile |
163 |
LOGICAL useCurrentDir |
164 |
LOGICAL lAdInit |
165 |
INTEGER myOptimIter |
166 |
INTEGER myThid |
167 |
_RS dummy |
168 |
|
169 |
C !LOCAL VARIABLES: |
170 |
CEOP |
171 |
|
172 |
IF ( arrShape.EQ.'XY' ) THEN |
173 |
|
174 |
CALL ACTIVE_READ_3D_RS( |
175 |
& activeVar_file, active_var, globalFile, |
176 |
& useCurrentDir, lAdInit, iRec, myNr, |
177 |
& FORWARD_SIMULATION, myOptimIter, myThid ) |
178 |
|
179 |
ELSEIF ( arrShape.EQ.'XZ' ) THEN |
180 |
|
181 |
CALL ACTIVE_READ_XZ_RS( |
182 |
& activeVar_file, active_var, globalFile, |
183 |
& useCurrentDir, lAdInit, iRec, myNr, |
184 |
& FORWARD_SIMULATION, myOptimIter, myThid ) |
185 |
|
186 |
ELSEIF ( arrShape.EQ.'YZ' ) THEN |
187 |
|
188 |
CALL ACTIVE_READ_YZ_RS( |
189 |
& activeVar_file, active_var, globalFile, |
190 |
& useCurrentDir, lAdInit, iRec, myNr, |
191 |
& FORWARD_SIMULATION, myOptimIter, myThid ) |
192 |
|
193 |
ELSE |
194 |
STOP |
195 |
& 'ABNORMAL END: S/R ACTIVE_READ_GEN_RS: invalid arrShape' |
196 |
ENDIF |
197 |
|
198 |
RETURN |
199 |
END |
200 |
|
201 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
202 |
CBOP |
203 |
C !ROUTINE: ACTIVE_WRITE_GEN_RL |
204 |
C !INTERFACE: |
205 |
SUBROUTINE ACTIVE_WRITE_GEN_RL( |
206 |
I activeVar_file, |
207 |
I active_var, |
208 |
I arrShape, myNr, |
209 |
I iRec, |
210 |
I useCurrentDir, |
211 |
I myOptimIter, |
212 |
I myThid, |
213 |
I dummy ) |
214 |
|
215 |
C !DESCRIPTION: \bv |
216 |
C ================================================================== |
217 |
C SUBROUTINE ACTIVE_WRITE_GEN_RL |
218 |
C ================================================================== |
219 |
C o Write an active (_RL) variable from file (generic version). |
220 |
C Accept active variable of various (XY,XZ,YZ) shape and level |
221 |
C number, according to arguments arrShape and myNr. |
222 |
C ================================================================== |
223 |
C \ev |
224 |
|
225 |
C !USES: |
226 |
IMPLICIT NONE |
227 |
|
228 |
C == global variables == |
229 |
#include "EEPARAMS.h" |
230 |
|
231 |
C !INPUT/OUTPUT PARAMETERS: |
232 |
C activeVar_file :: filename |
233 |
C active_var :: active variable array |
234 |
C arrShape :: shape of active-var array ('XY','XZ' or 'YZ') |
235 |
C myNr :: number of vertical-levels in active-var array |
236 |
C iRec :: record number in file |
237 |
C useCurrentDir :: always write to the current directory |
238 |
C (even if "mdsioLocalDir" is set) |
239 |
C myOptimIter :: number of optimization iteration (default: 0) |
240 |
C myThid :: my Thread Id number |
241 |
C dummy :: (needed for 2nd derivative code) |
242 |
CHARACTER*(*) activeVar_file |
243 |
_RL active_var(*) |
244 |
CHARACTER*(2) arrShape |
245 |
INTEGER myNr |
246 |
INTEGER iRec |
247 |
LOGICAL useCurrentDir |
248 |
INTEGER myOptimIter |
249 |
INTEGER myThid |
250 |
_RL dummy |
251 |
|
252 |
C !LOCAL VARIABLES: |
253 |
C globalFile :: used for writing global (if =T) or tiled files |
254 |
LOGICAL globalFile |
255 |
CEOP |
256 |
|
257 |
globalFile = .FALSE. |
258 |
IF ( arrShape.EQ.'XY' ) THEN |
259 |
|
260 |
CALL ACTIVE_WRITE_3D_RL( |
261 |
& activeVar_file, active_var, globalFile, |
262 |
& useCurrentDir, iRec, myNr, |
263 |
& FORWARD_SIMULATION, myOptimIter, myThid ) |
264 |
|
265 |
ELSEIF ( arrShape.EQ.'XZ' ) THEN |
266 |
|
267 |
CALL ACTIVE_WRITE_XZ_RL( |
268 |
& activeVar_file, active_var, globalFile, |
269 |
& useCurrentDir, iRec, myNr, |
270 |
& FORWARD_SIMULATION, myOptimIter, myThid ) |
271 |
|
272 |
ELSEIF ( arrShape.EQ.'YZ' ) THEN |
273 |
|
274 |
CALL ACTIVE_WRITE_YZ_RL( |
275 |
& activeVar_file, active_var, globalFile, |
276 |
& useCurrentDir, iRec, myNr, |
277 |
& FORWARD_SIMULATION, myOptimIter, myThid ) |
278 |
|
279 |
ELSE |
280 |
STOP |
281 |
& 'ABNORMAL END: S/R ACTIVE_WRITE_GEN_RL: invalid arrShape' |
282 |
ENDIF |
283 |
|
284 |
RETURN |
285 |
END |
286 |
|
287 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
288 |
CBOP |
289 |
C !ROUTINE: ACTIVE_WRITE_GEN_RS |
290 |
C !INTERFACE: |
291 |
SUBROUTINE ACTIVE_WRITE_GEN_RS( |
292 |
I activeVar_file, |
293 |
I active_var, |
294 |
I arrShape, myNr, |
295 |
I iRec, |
296 |
I useCurrentDir, |
297 |
I myOptimIter, |
298 |
I myThid, |
299 |
I dummy ) |
300 |
|
301 |
C !DESCRIPTION: \bv |
302 |
C ================================================================== |
303 |
C SUBROUTINE ACTIVE_WRITE_GEN_RS |
304 |
C ================================================================== |
305 |
C o Write an active (_RS) variable from file (generic version). |
306 |
C Accept active variable of various (XY,XZ,YZ) shape and level |
307 |
C number, according to arguments arrShape and myNr. |
308 |
C ================================================================== |
309 |
C \ev |
310 |
|
311 |
C !USES: |
312 |
IMPLICIT NONE |
313 |
|
314 |
C == global variables == |
315 |
#include "EEPARAMS.h" |
316 |
|
317 |
C !INPUT/OUTPUT PARAMETERS: |
318 |
C activeVar_file :: filename |
319 |
C active_var :: active variable array |
320 |
C arrShape :: shape of active-var array ('XY','XZ' or 'YZ') |
321 |
C myNr :: number of vertical-levels in active-var array |
322 |
C iRec :: record number in file |
323 |
C useCurrentDir :: always write to the current directory |
324 |
C (even if "mdsioLocalDir" is set) |
325 |
C myOptimIter :: number of optimization iteration (default: 0) |
326 |
C myThid :: my Thread Id number |
327 |
C dummy :: (needed for 2nd derivative code) |
328 |
CHARACTER*(*) activeVar_file |
329 |
_RS active_var(*) |
330 |
CHARACTER*(2) arrShape |
331 |
INTEGER myNr |
332 |
INTEGER iRec |
333 |
LOGICAL useCurrentDir |
334 |
INTEGER myOptimIter |
335 |
INTEGER myThid |
336 |
_RS dummy |
337 |
|
338 |
C !LOCAL VARIABLES: |
339 |
C globalFile :: used for writing global (if =T) or tiled files |
340 |
LOGICAL globalFile |
341 |
CEOP |
342 |
|
343 |
globalFile = .FALSE. |
344 |
IF ( arrShape.EQ.'XY' ) THEN |
345 |
|
346 |
CALL ACTIVE_WRITE_3D_RS( |
347 |
& activeVar_file, active_var, globalFile, |
348 |
& useCurrentDir, iRec, myNr, |
349 |
& FORWARD_SIMULATION, myOptimIter, myThid ) |
350 |
|
351 |
ELSEIF ( arrShape.EQ.'XZ' ) THEN |
352 |
|
353 |
CALL ACTIVE_WRITE_XZ_RS( |
354 |
& activeVar_file, active_var, globalFile, |
355 |
& useCurrentDir, iRec, myNr, |
356 |
& FORWARD_SIMULATION, myOptimIter, myThid ) |
357 |
|
358 |
ELSEIF ( arrShape.EQ.'YZ' ) THEN |
359 |
|
360 |
CALL ACTIVE_WRITE_YZ_RS( |
361 |
& activeVar_file, active_var, globalFile, |
362 |
& useCurrentDir, iRec, myNr, |
363 |
& FORWARD_SIMULATION, myOptimIter, myThid ) |
364 |
|
365 |
ELSE |
366 |
STOP |
367 |
& 'ABNORMAL END: S/R ACTIVE_WRITE_GEN_RS: invalid arrShape' |
368 |
ENDIF |
369 |
|
370 |
RETURN |
371 |
END |