1 |
C $Header: /u/gcmpack/MITgcm/pkg/ecco/cost_averagesgeneric.F,v 1.1 2005/09/01 05:32:56 heimbach Exp $ |
2 |
|
3 |
#include "COST_CPPOPTIONS.h" |
4 |
|
5 |
subroutine cost_averagesgeneric( |
6 |
& localbarfile, |
7 |
& localbar, localfld, xx_localbar_mean_dummy, |
8 |
& first, last, startofloc, endofloc, inloc, |
9 |
& sum1loc, locrec, nnz, mythid ) |
10 |
|
11 |
c ================================================================== |
12 |
c SUBROUTINE cost_averagesgeneric |
13 |
c ================================================================== |
14 |
c |
15 |
c o Compute time averages of cost variables |
16 |
c |
17 |
c ================================================================== |
18 |
c SUBROUTINE cost_averagesgeneric |
19 |
c ================================================================== |
20 |
|
21 |
implicit none |
22 |
|
23 |
c == global variables == |
24 |
|
25 |
#include "EEPARAMS.h" |
26 |
#include "SIZE.h" |
27 |
#include "PARAMS.h" |
28 |
|
29 |
#ifdef ALLOW_COST |
30 |
# include "optim.h" |
31 |
# include "ecco_cost.h" |
32 |
# include "ctrl_dummy.h" |
33 |
#endif |
34 |
|
35 |
c == routine arguments == |
36 |
|
37 |
integer mythid |
38 |
integer nnz |
39 |
integer locrec |
40 |
integer sum1loc |
41 |
|
42 |
_RL localbar(1-olx:snx+olx,1-oly:sny+oly,nnz,nsx,nsy) |
43 |
_RL localfld(1-olx:snx+olx,1-oly:sny+oly,nnz,nsx,nsy) |
44 |
_RL xx_localbar_mean_dummy |
45 |
|
46 |
logical first |
47 |
logical last |
48 |
logical startofloc |
49 |
logical endofloc |
50 |
logical inloc |
51 |
|
52 |
character*(128) localbarfile |
53 |
|
54 |
c == local variables == |
55 |
|
56 |
integer bi,bj |
57 |
integer i,j,k |
58 |
integer itlo,ithi |
59 |
integer jtlo,jthi |
60 |
integer jmin,jmax |
61 |
integer imin,imax |
62 |
|
63 |
integer il |
64 |
|
65 |
character*(128) fname |
66 |
|
67 |
c == external functions == |
68 |
|
69 |
integer ilnblnk |
70 |
external ilnblnk |
71 |
|
72 |
c == end of interface == |
73 |
|
74 |
jtlo = mybylo(mythid) |
75 |
jthi = mybyhi(mythid) |
76 |
itlo = mybxlo(mythid) |
77 |
ithi = mybxhi(mythid) |
78 |
jmin = 1 |
79 |
jmax = sny |
80 |
imin = 1 |
81 |
imax = snx |
82 |
|
83 |
c-- First, do the daily averages. |
84 |
if (first .or. startofloc) then |
85 |
c-- Assign the first value to the array holding the average. |
86 |
do bj = jtlo,jthi |
87 |
do bi = itlo,ithi |
88 |
do k = 1,nnz |
89 |
do j = jmin,jmax |
90 |
do i = imin,imax |
91 |
localbar(i,j,k,bi,bj) = localfld(i,j,k,bi,bj) |
92 |
enddo |
93 |
enddo |
94 |
enddo |
95 |
enddo |
96 |
enddo |
97 |
else if (last .or. endofloc) then |
98 |
c-- Add the last value and devide by the number of accumulated records. |
99 |
do bj = jtlo,jthi |
100 |
do bi = itlo,ithi |
101 |
do k = 1,nnz |
102 |
do j = jmin,jmax |
103 |
do i = imin,imax |
104 |
localbar(i,j,k,bi,bj) = |
105 |
& (localbar(i,j,k,bi,bj) |
106 |
& +localfld(i,j,k,bi,bj))/ |
107 |
& float(sum1loc) |
108 |
enddo |
109 |
enddo |
110 |
enddo |
111 |
enddo |
112 |
enddo |
113 |
c-- Save ...bar on file. |
114 |
write(fname(1:128),'(80a)') ' ' |
115 |
il=ilnblnk( localbarfile ) |
116 |
write(fname,'(2a,i10.10)') |
117 |
& localbarfile(1:il), '.', optimcycle |
118 |
if ( nnz .EQ. 1 ) then |
119 |
call active_write_xy( fname, localbar, locrec, optimcycle, |
120 |
& mythid, xx_localbar_mean_dummy ) |
121 |
else |
122 |
call active_write_xyz( fname, localbar, locrec, optimcycle, |
123 |
& mythid, xx_localbar_mean_dummy ) |
124 |
endif |
125 |
else if ( ( inloc ) .and. |
126 |
& .not. (first .or. startofloc) .and. |
127 |
& .not. (last .or. endofloc ) ) then |
128 |
c-- Accumulate the array holding the average. |
129 |
do bj = jtlo,jthi |
130 |
do bi = itlo,ithi |
131 |
do j = jmin,jmax |
132 |
do k = 1,nnz |
133 |
do i = imin,imax |
134 |
localbar(i,j,k,bi,bj) = |
135 |
& localbar(i,j,k,bi,bj) + localfld(i,j,k,bi,bj) |
136 |
enddo |
137 |
enddo |
138 |
enddo |
139 |
enddo |
140 |
enddo |
141 |
else |
142 |
stop 'in cost_averagesgeneric' |
143 |
endif |
144 |
|
145 |
return |
146 |
end |
147 |
|