1 |
C $Header: /u/gcmpack/MITgcm/pkg/ecco/cost_salt_ini_fin.F,v 1.6 2012/08/10 19:45:26 jmc Exp $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "ECCO_OPTIONS.h" |
5 |
|
6 |
|
7 |
subroutine cost_salt_ini_fin( |
8 |
I myiter, |
9 |
I mytime, |
10 |
I mythid |
11 |
& ) |
12 |
|
13 |
c ================================================================== |
14 |
c SUBROUTINE cost_salt_ini_fin |
15 |
c ================================================================== |
16 |
c |
17 |
c ================================================================== |
18 |
c SUBROUTINE cost_salt_ini_fin |
19 |
c ================================================================== |
20 |
|
21 |
implicit none |
22 |
|
23 |
c == global variables == |
24 |
|
25 |
#ifdef ALLOW_COST_INI_FIN |
26 |
#include "EEPARAMS.h" |
27 |
#include "SIZE.h" |
28 |
#include "GRID.h" |
29 |
#include "DYNVARS.h" |
30 |
|
31 |
#include "ecco_cost.h" |
32 |
#include "CTRL_SIZE.h" |
33 |
#include "ctrl.h" |
34 |
#include "ctrl_dummy.h" |
35 |
#include "optim.h" |
36 |
#endif |
37 |
|
38 |
c == routine arguments == |
39 |
|
40 |
integer myiter |
41 |
_RL mytime |
42 |
integer mythid |
43 |
|
44 |
#ifdef ALLOW_COST_INI_FIN |
45 |
c == local variables == |
46 |
|
47 |
integer bi,bj |
48 |
integer i,j,k |
49 |
integer itlo,ithi |
50 |
integer jtlo,jthi |
51 |
integer jmin,jmax |
52 |
integer imin,imax |
53 |
integer nrec |
54 |
integer irec |
55 |
integer ilfld |
56 |
|
57 |
_RL fctile |
58 |
_RL fcthread |
59 |
_RL tmpx |
60 |
|
61 |
logical doglobalread |
62 |
logical ladinit |
63 |
|
64 |
character*(80) fnamefld |
65 |
|
66 |
character*(MAX_LEN_MBUF) msgbuf |
67 |
|
68 |
c == external functions == |
69 |
|
70 |
integer ilnblnk |
71 |
external ilnblnk |
72 |
|
73 |
c == end of interface == |
74 |
|
75 |
jtlo = mybylo(mythid) |
76 |
jthi = mybyhi(mythid) |
77 |
itlo = mybxlo(mythid) |
78 |
ithi = mybxhi(mythid) |
79 |
jmin = 1 |
80 |
jmax = sny |
81 |
imin = 1 |
82 |
imax = snx |
83 |
|
84 |
c-- Read state record from global file. |
85 |
doglobalread = .false. |
86 |
ladinit = .false. |
87 |
|
88 |
irec = 1 |
89 |
|
90 |
ilfld = ilnblnk( xx_salt_ini_fin_file ) |
91 |
write(fnamefld(1:80),'(2a,i10.10)') |
92 |
& xx_salt_ini_fin_file(1:ilfld),'.',optimcycle |
93 |
|
94 |
fcthread = 0. _d 0 |
95 |
|
96 |
call active_read_xyz( fnamefld, tmpfld3d, irec, doglobalread, |
97 |
& ladinit, optimcycle, mythid, |
98 |
& xx_salt_ini_fin_dummy ) |
99 |
|
100 |
c-- Loop over this thread tiles. |
101 |
do bj = jtlo,jthi |
102 |
do bi = itlo,ithi |
103 |
|
104 |
c-- Determine the weights to be used. |
105 |
|
106 |
fctile = 0. _d 0 |
107 |
do k = 1,nr |
108 |
do j = jmin,jmax |
109 |
do i = imin,imax |
110 |
if (_hFacC(i,j,k,bi,bj) .ne. 0.) then |
111 |
tmpx = tmpfld3d(i,j,k,bi,bj) - salt(i,j,k,bi,bj) |
112 |
fctile = fctile |
113 |
& + wsalt(k,bi,bj)*cosphi(i,j,bi,bj) |
114 |
& *tmpx*tmpx |
115 |
endif |
116 |
enddo |
117 |
enddo |
118 |
enddo |
119 |
|
120 |
objf_salt_ini_fin(bi,bj) = |
121 |
& objf_salt_ini_fin(bi,bj) + fctile |
122 |
fcthread = fcthread + fctile |
123 |
|
124 |
#ifdef ECCO_VERBOSE |
125 |
c-- Print cost function for each tile in each thread. |
126 |
write(msgbuf,'(a)') ' ' |
127 |
call print_message( msgbuf, standardmessageunit, |
128 |
& SQUEEZE_RIGHT , mythid) |
129 |
write(msgbuf,'(a,i8.8,1x,i3.3,1x,i3.3)') |
130 |
& ' cost_salt_ini_fin: irec,bi,bj = ',irec,bi,bj |
131 |
call print_message( msgbuf, standardmessageunit, |
132 |
& SQUEEZE_RIGHT , mythid) |
133 |
write(msgbuf,'(a,d22.15)') |
134 |
& ' cost_salt_ini_fin: irec,bi,bj = ', |
135 |
& fctile |
136 |
call print_message( msgbuf, standardmessageunit, |
137 |
& SQUEEZE_RIGHT , mythid) |
138 |
#endif |
139 |
enddo |
140 |
enddo |
141 |
|
142 |
#ifdef ECCO_VERBOSE |
143 |
c-- Print cost function for all tiles. |
144 |
_GLOBAL_SUM_RL( fcthread , myThid ) |
145 |
write(msgbuf,'(a)') ' ' |
146 |
call print_message( msgbuf, standardmessageunit, |
147 |
& SQUEEZE_RIGHT , mythid) |
148 |
write(msgbuf,'(a,i8.8)') |
149 |
& ' cost_: irec = ',irec |
150 |
call print_message( msgbuf, standardmessageunit, |
151 |
& SQUEEZE_RIGHT , mythid) |
152 |
write(msgbuf,'(a,d22.15)') |
153 |
& ' global cost function value = ', |
154 |
& fcthread |
155 |
call print_message( msgbuf, standardmessageunit, |
156 |
& SQUEEZE_RIGHT , mythid) |
157 |
write(msgbuf,'(a)') ' ' |
158 |
call print_message( msgbuf, standardmessageunit, |
159 |
& SQUEEZE_RIGHT , mythid) |
160 |
#endif |
161 |
|
162 |
#endif |
163 |
|
164 |
return |
165 |
end |
166 |
|
167 |
|