forked from altMITgcm/MITgcm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cost_averagesgeneric.F
218 lines (189 loc) · 6.16 KB
/
cost_averagesgeneric.F
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
C $Header: /u/gcmpack/MITgcm/pkg/ecco/cost_averagesgeneric.F,v 1.10 2015/03/23 21:10:04 gforget Exp $
C $Name: $
#include "ECCO_OPTIONS.h"
subroutine cost_averagesgeneric(
& localbarfile,
& localbar, localfld, xx_localbar_mean_dummy,
& first, last, startofloc, endofloc, inloc,
& sum1loc, locrec, nnz, mythid )
c ==================================================================
c SUBROUTINE cost_averagesgeneric
c ==================================================================
c
c o Compute time averages of cost variables
c
c ==================================================================
c SUBROUTINE cost_averagesgeneric
c ==================================================================
implicit none
c == global variables ==
#include "EEPARAMS.h"
#include "SIZE.h"
#include "PARAMS.h"
#ifdef ALLOW_ECCO
# include "ecco.h"
#endif
c == routine arguments ==
integer mythid
integer nnz
integer locrec
integer sum1loc
_RL localbar(1-olx:snx+olx,1-oly:sny+oly,nnz,nsx,nsy)
_RL localfld(1-olx:snx+olx,1-oly:sny+oly,nnz,nsx,nsy)
_RL xx_localbar_mean_dummy
logical first
logical last
logical startofloc
logical endofloc
logical inloc
character*(MAX_LEN_FNAM) localbarfile
c == local variables ==
integer bi,bj
integer i,j,k
integer itlo,ithi
integer jtlo,jthi
integer jmin,jmax
integer imin,imax
integer il
character*(128) fname
#ifdef ALLOW_ECCO_DEBUG
character*(max_len_mbuf) msgbuf
#endif
c == external functions ==
integer ilnblnk
external ilnblnk
c == end of interface ==
#ifdef ALLOW_ECCO_DEBUG
write(msgbuf,'(a)') '>> entering'
call print_message( msgbuf, standardmessageunit,
& SQUEEZE_RIGHT , mythid)
il=ilnblnk( localbarfile )
write(msgbuf,'(a,a)')
& 'cost_averagesgeneric, file : ',localbarfile(1:il)
call print_message( msgbuf, standardmessageunit,
& SQUEEZE_RIGHT , mythid)
write(msgbuf,'(a,5L5)')
& 'cost_averagesgeneric, logicals : ',
& first, last, startofloc, endofloc, inloc
call print_message( msgbuf, standardmessageunit,
& SQUEEZE_RIGHT , mythid)
write(msgbuf,'(a,3i5)')
& 'cost_averagesgeneric, integers : ',
& sum1loc, locrec, nnz
call print_message( msgbuf, standardmessageunit,
& SQUEEZE_RIGHT , mythid)
write(msgbuf,'(a)') '<< leaving'
call print_message( msgbuf, standardmessageunit,
& SQUEEZE_RIGHT , mythid)
#endif
jtlo = mybylo(mythid)
jthi = mybyhi(mythid)
itlo = mybxlo(mythid)
ithi = mybxhi(mythid)
jmin = 1
jmax = sny
imin = 1
imax = snx
if (startofloc .and. endofloc) then
c-- Save snapshot at every time step
do bj = jtlo,jthi
do bi = itlo,ithi
do k = 1,nnz
do j = jmin,jmax
do i = imin,imax
localbar(i,j,k,bi,bj) = localfld(i,j,k,bi,bj)
enddo
enddo
enddo
enddo
enddo
c-- Save ...bar on file.
write(fname(1:128),'(80a)') ' '
il=ilnblnk( localbarfile )
write(fname,'(2a,i10.10)')
& localbarfile(1:il), '.', eccoiter
#ifdef ALLOW_AUTODIFF
if ( nnz .EQ. 1 ) then
call active_write_xy( fname, localbar, locrec, eccoiter,
& mythid, xx_localbar_mean_dummy )
else
call active_write_xyz( fname, localbar, locrec, eccoiter,
& mythid, xx_localbar_mean_dummy )
endif
#else
if ( nnz .EQ. 1 ) then
CALL WRITE_REC_XY_RL( fname, localbar, locrec, 1, myThid )
else
CALL WRITE_REC_XYZ_RL( fname, localbar, locrec, 1, myThid )
endif
#endif
elseif (first .or. startofloc) then
c-- Assign the first value to the array holding the average.
do bj = jtlo,jthi
do bi = itlo,ithi
do k = 1,nnz
do j = jmin,jmax
do i = imin,imax
localbar(i,j,k,bi,bj) = localfld(i,j,k,bi,bj)
enddo
enddo
enddo
enddo
enddo
else if (last .or. endofloc) then
c-- Add the last value and devide by the number of accumulated records.
do bj = jtlo,jthi
do bi = itlo,ithi
do k = 1,nnz
do j = jmin,jmax
do i = imin,imax
localbar(i,j,k,bi,bj) =
& (localbar(i,j,k,bi,bj)
& +localfld(i,j,k,bi,bj))/
& float(sum1loc)
enddo
enddo
enddo
enddo
enddo
c-- Save ...bar on file.
write(fname(1:128),'(80a)') ' '
il=ilnblnk( localbarfile )
write(fname,'(2a,i10.10)')
& localbarfile(1:il), '.', eccoiter
#ifdef ALLOW_AUTODIFF
if ( nnz .EQ. 1 ) then
call active_write_xy( fname, localbar, locrec, eccoiter,
& mythid, xx_localbar_mean_dummy )
else
call active_write_xyz( fname, localbar, locrec, eccoiter,
& mythid, xx_localbar_mean_dummy )
endif
#else
if ( nnz .EQ. 1 ) then
CALL WRITE_REC_XY_RL( fname, localbar, locrec, 1, myThid )
else
CALL WRITE_REC_XYZ_RL( fname, localbar, locrec, 1, myThid )
endif
#endif
else if ( ( inloc ) .and.
& .not. (first .or. startofloc) .and.
& .not. (last .or. endofloc ) ) then
c-- Accumulate the array holding the average.
do bj = jtlo,jthi
do bi = itlo,ithi
do j = jmin,jmax
do k = 1,nnz
do i = imin,imax
localbar(i,j,k,bi,bj) =
& localbar(i,j,k,bi,bj) + localfld(i,j,k,bi,bj)
enddo
enddo
enddo
enddo
enddo
else
stop 'in cost_averagesgeneric'
endif
return
end