1 |
C $Header: /u/gcmpack/MITgcm/pkg/profiles/active_file_control_profiles.F,v 1.8 2015/07/22 22:46:32 gforget Exp $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "PROFILES_OPTIONS.h" |
5 |
|
6 |
C o==========================================================o |
7 |
C | subroutine active_file_control_profile | |
8 |
C | o handles the i/o of active variables for the adjoint | |
9 |
C | calculations, related to netcdf profiles data files | |
10 |
C | o active_read_profile_rl, active_write_profile_rl | |
11 |
C | started: Gael Forget 15-March-2006 | |
12 |
C o==========================================================o |
13 |
|
14 |
subroutine active_read_profile_rl( |
15 |
I fid, |
16 |
I active_num_file, |
17 |
I nactive_var, |
18 |
O active_var, |
19 |
I active_varnum, |
20 |
I lAdInit, |
21 |
I irec, |
22 |
I irecglob, |
23 |
I theSimulationMode, |
24 |
I myOptimIter, |
25 |
I bi, |
26 |
I bj, |
27 |
I mythid |
28 |
& ) |
29 |
|
30 |
c ================================================================== |
31 |
c |
32 |
c o Read an active 1D record. |
33 |
c |
34 |
c ================================================================== |
35 |
|
36 |
implicit none |
37 |
|
38 |
c == global variables == |
39 |
|
40 |
#include "EEPARAMS.h" |
41 |
#include "SIZE.h" |
42 |
#include "PARAMS.h" |
43 |
#ifdef ALLOW_PROFILES |
44 |
# include "netcdf.inc" |
45 |
# include "PROFILES_SIZE.h" |
46 |
# include "profiles.h" |
47 |
#endif |
48 |
|
49 |
c == routine arguments == |
50 |
|
51 |
integer err, fid, varid1 , vec_start(2), vec_count(2) |
52 |
|
53 |
logical lAdInit |
54 |
integer irec, irecglob,active_varnum |
55 |
integer theSimulationMode |
56 |
integer myOptimIter |
57 |
integer bi,bj,mythid |
58 |
integer nactive_var,active_num_file |
59 |
_RL active_var(nactive_var) |
60 |
_RL active_data_t(nactive_var) |
61 |
integer i,ivar |
62 |
real*8 vec_tmp(nactive_var+1) |
63 |
|
64 |
#ifdef ALLOW_PROFILES |
65 |
|
66 |
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
67 |
c >>>>>>>>>>>>>>>>>>> FORWARD RUN <<<<<<<<<<<<<<<<<<< |
68 |
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
69 |
|
70 |
if (theSimulationMode .eq. FORWARD_SIMULATION) then |
71 |
|
72 |
_BEGIN_MASTER( mythid ) |
73 |
|
74 |
if (profilesDoNcOutput) then |
75 |
vec_start(1)=1 |
76 |
vec_start(2)=irec |
77 |
vec_count(1)=nactive_var |
78 |
vec_count(2)=1 |
79 |
|
80 |
err = NF_INQ_VARID(fid,prof_names(active_num_file,active_varnum), |
81 |
& varid1 ) |
82 |
err = NF_GET_VARA_DOUBLE(fid, varid1 , vec_start, vec_count, |
83 |
& active_var) |
84 |
|
85 |
err = NF_INQ_VARID(fid,prof_namesmask(active_num_file, |
86 |
& active_varnum), varid1) |
87 |
err = NF_GET_VARA_DOUBLE(fid, varid1 , vec_start, vec_count, |
88 |
& prof_mask1D_cur(1,bi,bj)) |
89 |
|
90 |
else |
91 |
|
92 |
read(fid,rec=( (irec-1)*prof_num_var_tot(active_num_file,bi,bj) |
93 |
& +prof_num_var_cur(active_num_file,active_varnum,bi,bj)-1)*2+1 ) |
94 |
& vec_tmp |
95 |
#ifdef _BYTESWAPIO |
96 |
call MDS_BYTESWAPR8(nactive_var+1,vec_tmp) |
97 |
#endif |
98 |
do ivar=1,nactive_var |
99 |
active_var(ivar)=vec_tmp(ivar) |
100 |
enddo |
101 |
read(fid,rec=( (irec-1)*prof_num_var_tot(active_num_file,bi,bj) |
102 |
& +prof_num_var_cur(active_num_file,active_varnum,bi,bj)-1)*2+2 ) |
103 |
& vec_tmp |
104 |
#ifdef _BYTESWAPIO |
105 |
call MDS_BYTESWAPR8(nactive_var+1,vec_tmp) |
106 |
#endif |
107 |
do ivar=1,nactive_var |
108 |
prof_mask1D_cur(ivar,bi,bj)=vec_tmp(ivar) |
109 |
enddo |
110 |
|
111 |
endif |
112 |
|
113 |
_END_MASTER( mythid ) |
114 |
|
115 |
endif |
116 |
|
117 |
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
118 |
c >>>>>>>>>>>>>>>>>>> ADJOINT RUN <<<<<<<<<<<<<<<<<<< |
119 |
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
120 |
|
121 |
if (theSimulationMode .eq. REVERSE_SIMULATION) then |
122 |
|
123 |
_BEGIN_MASTER( mythid ) |
124 |
|
125 |
if (profilesDoNcOutput) then |
126 |
|
127 |
vec_start(1)=1 |
128 |
vec_start(2)=irec |
129 |
vec_count(1)=nactive_var |
130 |
vec_count(2)=1 |
131 |
|
132 |
err = NF_INQ_VARID(fid,prof_names(active_num_file,active_varnum), |
133 |
& varid1 ) |
134 |
err = NF_GET_VARA_DOUBLE(fid, varid1 , vec_start, vec_count, |
135 |
& active_data_t) |
136 |
|
137 |
c Add active_var from appropriate location to data. |
138 |
do i = 1,nactive_var |
139 |
active_data_t(i) = active_data_t(i) + active_var(i) |
140 |
enddo |
141 |
c Store the result on disk. |
142 |
vec_start(1)=1 |
143 |
vec_start(2)=irec |
144 |
vec_count(1)=nactive_var |
145 |
vec_count(2)=1 |
146 |
|
147 |
err = NF_INQ_VARID(fid,prof_names(active_num_file,active_varnum), |
148 |
& varid1 ) |
149 |
err = NF_PUT_VARA_DOUBLE(fid, varid1 , vec_start, vec_count, |
150 |
& active_data_t) |
151 |
|
152 |
c Set active_var to zero. |
153 |
do i = 1,nactive_var |
154 |
active_var(i) = 0. _d 0 |
155 |
enddo |
156 |
|
157 |
else |
158 |
|
159 |
|
160 |
read(fid,rec=( (irec-1)*prof_num_var_tot(active_num_file,bi,bj) |
161 |
& +prof_num_var_cur(active_num_file,active_varnum,bi,bj)-1)*2+1 ) |
162 |
& vec_tmp |
163 |
#ifdef _BYTESWAPIO |
164 |
call MDS_BYTESWAPR8(nactive_var+1,vec_tmp) |
165 |
#endif |
166 |
do ivar=1,nactive_var |
167 |
active_data_t(ivar)=vec_tmp(ivar) |
168 |
enddo |
169 |
|
170 |
c Add active_var from appropriate location to data. |
171 |
do i = 1,nactive_var |
172 |
active_data_t(i) = active_data_t(i) + active_var(i) |
173 |
enddo |
174 |
|
175 |
c Store the result on disk. |
176 |
do ivar=1,nactive_var |
177 |
vec_tmp(ivar)=active_data_t(ivar) |
178 |
enddo |
179 |
#ifdef _BYTESWAPIO |
180 |
call MDS_BYTESWAPR8(nactive_var+1,vec_tmp) |
181 |
#endif |
182 |
write(fid,rec=( (irec-1)*prof_num_var_tot(active_num_file,bi,bj) |
183 |
& +prof_num_var_cur(active_num_file,active_varnum,bi,bj)-1)*2+1 ) |
184 |
& vec_tmp |
185 |
|
186 |
c Set active_var to zero. |
187 |
do i = 1,nactive_var |
188 |
active_var(i) = 0. _d 0 |
189 |
enddo |
190 |
|
191 |
endif |
192 |
|
193 |
_END_MASTER( mythid ) |
194 |
|
195 |
endif |
196 |
|
197 |
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
198 |
c >>>>>>>>>>>>>>>>>>> TANGENT RUN <<<<<<<<<<<<<<<<<<< |
199 |
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
200 |
|
201 |
if (theSimulationMode .eq. TANGENT_SIMULATION) then |
202 |
|
203 |
_BEGIN_MASTER( mythid ) |
204 |
|
205 |
if (profilesDoNcOutput) then |
206 |
|
207 |
vec_start(1)=1 |
208 |
vec_start(2)=irec |
209 |
vec_count(1)=nactive_var |
210 |
vec_count(2)=1 |
211 |
|
212 |
err = NF_INQ_VARID(fid,prof_names(active_num_file,active_varnum), |
213 |
& varid1 ) |
214 |
err = NF_GET_VARA_DOUBLE(fid, varid1 , vec_start, vec_count, |
215 |
& active_var) |
216 |
|
217 |
else |
218 |
|
219 |
read(fid,rec=( (irec-1)*prof_num_var_tot(active_num_file,bi,bj) |
220 |
& +prof_num_var_cur(active_num_file,active_varnum,bi,bj)-1)*2+1 ) |
221 |
& vec_tmp |
222 |
#ifdef _BYTESWAPIO |
223 |
call MDS_BYTESWAPR8(nactive_var+1,vec_tmp) |
224 |
#endif |
225 |
do ivar=1,nactive_var |
226 |
active_var(ivar)=vec_tmp(ivar) |
227 |
enddo |
228 |
|
229 |
endif |
230 |
|
231 |
_END_MASTER( mythid ) |
232 |
|
233 |
endif |
234 |
|
235 |
|
236 |
#endif /* ALLOW_PROFILES */ |
237 |
|
238 |
return |
239 |
end |
240 |
|
241 |
c ================================================================== |
242 |
|
243 |
|
244 |
subroutine active_write_profile_rl( |
245 |
I fid, |
246 |
I active_num_file, |
247 |
I nactive_var, |
248 |
I active_var, |
249 |
I active_varnum, |
250 |
I irec, |
251 |
I irecglob, |
252 |
I theSimulationMode, |
253 |
I myOptimIter, |
254 |
I bi, |
255 |
I bj, |
256 |
I mythid |
257 |
& ) |
258 |
|
259 |
c ================================================================== |
260 |
c |
261 |
c o Write an active 1D record to a file. |
262 |
c |
263 |
c ================================================================== |
264 |
|
265 |
implicit none |
266 |
|
267 |
c == global variables == |
268 |
|
269 |
#include "EEPARAMS.h" |
270 |
#include "SIZE.h" |
271 |
#include "PARAMS.h" |
272 |
#ifdef ALLOW_PROFILES |
273 |
# include "netcdf.inc" |
274 |
# include "PROFILES_SIZE.h" |
275 |
# include "profiles.h" |
276 |
#endif |
277 |
|
278 |
c == routine arguments == |
279 |
|
280 |
integer err, fid, varid1 , vec_start(2), vec_count(2) |
281 |
integer ivar, irec, irecglob,active_varnum |
282 |
integer theSimulationMode |
283 |
integer myOptimIter |
284 |
integer bi,bj,mythid |
285 |
integer nactive_var,active_num_file |
286 |
_RL active_var(nactive_var) |
287 |
real*8 vec_tmp(nactive_var+1) |
288 |
|
289 |
#ifdef ALLOW_PROFILES |
290 |
c == local variables == |
291 |
|
292 |
integer i |
293 |
_RL active_data_t(nactive_var) |
294 |
|
295 |
c == end of interface == |
296 |
|
297 |
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
298 |
c >>>>>>>>>>>>>>>>>>> FORWARD RUN <<<<<<<<<<<<<<<<<<< |
299 |
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
300 |
|
301 |
|
302 |
if (theSimulationMode .eq. FORWARD_SIMULATION) then |
303 |
|
304 |
_BEGIN_MASTER( mythid ) |
305 |
|
306 |
if (profilesDoNcOutput) then |
307 |
|
308 |
vec_start(1)=1 |
309 |
vec_start(2)=irec |
310 |
vec_count(1)=nactive_var |
311 |
vec_count(2)=1 |
312 |
|
313 |
err = NF_INQ_VARID(fid,prof_names(active_num_file,active_varnum), |
314 |
& varid1 ) |
315 |
err = NF_PUT_VARA_DOUBLE(fid, varid1 , vec_start, vec_count, |
316 |
& active_var) |
317 |
|
318 |
err = NF_INQ_VARID(fid,prof_namesmask(active_num_file, |
319 |
& active_varnum), varid1 ) |
320 |
err = NF_PUT_VARA_DOUBLE(fid, varid1 , vec_start, vec_count, |
321 |
& prof_mask1D_cur(1,bi,bj)) |
322 |
|
323 |
err = NF_INQ_VARID(fid,'prof_ind_glob', varid1 ) |
324 |
err = NF_PUT_VAR1_INT(fid, varid1 , vec_start(2), |
325 |
& irecglob) |
326 |
|
327 |
else |
328 |
|
329 |
|
330 |
do ivar=1,nactive_var |
331 |
vec_tmp(ivar)=active_var(ivar) |
332 |
enddo |
333 |
vec_tmp(nactive_var+1)=irecglob |
334 |
#ifdef _BYTESWAPIO |
335 |
call MDS_BYTESWAPR8(nactive_var+1,vec_tmp) |
336 |
#endif |
337 |
write(fid,rec=( (irec-1)*prof_num_var_tot(active_num_file,bi,bj) |
338 |
& +prof_num_var_cur(active_num_file,active_varnum,bi,bj)-1)*2+1 ) |
339 |
& vec_tmp |
340 |
do ivar=1,nactive_var |
341 |
vec_tmp(ivar)=prof_mask1D_cur(ivar,bi,bj) |
342 |
enddo |
343 |
vec_tmp(nactive_var+1)=irecglob |
344 |
#ifdef _BYTESWAPIO |
345 |
call MDS_BYTESWAPR8(nactive_var+1,vec_tmp) |
346 |
#endif |
347 |
write(fid,rec=( (irec-1)*prof_num_var_tot(active_num_file,bi,bj) |
348 |
& +prof_num_var_cur(active_num_file,active_varnum,bi,bj)-1)*2+2 ) |
349 |
& vec_tmp |
350 |
|
351 |
endif |
352 |
|
353 |
|
354 |
_END_MASTER( mythid ) |
355 |
|
356 |
endif |
357 |
|
358 |
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
359 |
c >>>>>>>>>>>>>>>>>>> ADJOINT RUN <<<<<<<<<<<<<<<<<<< |
360 |
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
361 |
|
362 |
if (theSimulationMode .eq. REVERSE_SIMULATION) then |
363 |
|
364 |
_BEGIN_MASTER( mythid ) |
365 |
|
366 |
if (profilesDoNcOutput) then |
367 |
|
368 |
vec_start(1)=1 |
369 |
vec_start(2)=irec |
370 |
vec_count(1)=nactive_var |
371 |
vec_count(2)=1 |
372 |
err = NF_INQ_VARID(fid,prof_names(active_num_file,active_varnum), |
373 |
& varid1 ) |
374 |
err = NF_GET_VARA_DOUBLE(fid, varid1 , vec_start, vec_count, |
375 |
& active_data_t) |
376 |
|
377 |
c Add active_var to data. |
378 |
do i = 1,nactive_var |
379 |
active_var(i) = active_var(i) + active_data_t(i) |
380 |
active_data_t(i) = 0. _d 0 |
381 |
enddo |
382 |
|
383 |
vec_start(1)=1 |
384 |
vec_start(2)=irec |
385 |
vec_count(1)=nactive_var |
386 |
vec_count(2)=1 |
387 |
|
388 |
err = NF_INQ_VARID(fid,prof_names(active_num_file,active_varnum), |
389 |
& varid1 ) |
390 |
err = NF_PUT_VARA_DOUBLE(fid, varid1 , vec_start, vec_count, |
391 |
& active_data_t) |
392 |
|
393 |
else |
394 |
|
395 |
|
396 |
read(fid,rec=( (irec-1)*prof_num_var_tot(active_num_file,bi,bj) |
397 |
& +prof_num_var_cur(active_num_file,active_varnum,bi,bj)-1)*2+1 ) |
398 |
& vec_tmp |
399 |
#ifdef _BYTESWAPIO |
400 |
call MDS_BYTESWAPR8(nactive_var+1,vec_tmp) |
401 |
#endif |
402 |
do ivar=1,nactive_var |
403 |
active_data_t(ivar)=vec_tmp(ivar) |
404 |
enddo |
405 |
|
406 |
c Add active_var from appropriate location to data. |
407 |
do i = 1,nactive_var |
408 |
active_var(i) = active_var(i) + active_data_t(i) |
409 |
active_data_t(i) = 0. _d 0 |
410 |
enddo |
411 |
|
412 |
c Store the result on disk. |
413 |
do ivar=1,nactive_var |
414 |
vec_tmp(ivar)=active_data_t(ivar) |
415 |
enddo |
416 |
#ifdef _BYTESWAPIO |
417 |
call MDS_BYTESWAPR8(nactive_var+1,vec_tmp) |
418 |
#endif |
419 |
write(fid,rec=( (irec-1)*prof_num_var_tot(active_num_file,bi,bj) |
420 |
& +prof_num_var_cur(active_num_file,active_varnum,bi,bj)-1)*2+1 ) |
421 |
& vec_tmp |
422 |
|
423 |
endif |
424 |
|
425 |
|
426 |
_END_MASTER( mythid ) |
427 |
|
428 |
endif |
429 |
|
430 |
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
431 |
c >>>>>>>>>>>>>>>>>>> TANGENT RUN <<<<<<<<<<<<<<<<<<< |
432 |
c >>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<< |
433 |
|
434 |
if (theSimulationMode .eq. TANGENT_SIMULATION) then |
435 |
|
436 |
_BEGIN_MASTER( mythid ) |
437 |
|
438 |
if (profilesDoNcOutput) then |
439 |
|
440 |
vec_start(1)=1 |
441 |
vec_start(2)=irec |
442 |
vec_count(1)=nactive_var |
443 |
vec_count(2)=1 |
444 |
|
445 |
err = NF_INQ_VARID(fid, prof_names(active_num_file,active_varnum), |
446 |
& varid1 ) |
447 |
err = NF_PUT_VARA_DOUBLE(fid, varid1 , vec_start, vec_count, |
448 |
& active_var) |
449 |
|
450 |
else |
451 |
|
452 |
|
453 |
do ivar=1,nactive_var |
454 |
vec_tmp(ivar)=active_var(ivar) |
455 |
enddo |
456 |
vec_tmp(nactive_var+1)=irecglob |
457 |
#ifdef _BYTESWAPIO |
458 |
call MDS_BYTESWAPR8(nactive_var+1,vec_tmp) |
459 |
#endif |
460 |
write(fid,rec=( (irec-1)*prof_num_var_tot(active_num_file,bi,bj) |
461 |
& +prof_num_var_cur(active_num_file,active_varnum,bi,bj)-1)*2+1 ) |
462 |
& vec_tmp |
463 |
|
464 |
endif |
465 |
|
466 |
|
467 |
_END_MASTER( mythid ) |
468 |
|
469 |
endif |
470 |
|
471 |
|
472 |
#endif /* ALLOW_PROFILES */ |
473 |
|
474 |
return |
475 |
end |
476 |
|