1 |
C |
2 |
C $Header: /u/gcmpack/MITgcm/pkg/ctrl/ctrl_set_pack_xy.F,v 1.4 2003/10/23 04:41:40 edhill Exp $ |
3 |
C $Name: $ |
4 |
|
5 |
#include "CTRL_CPPOPTIONS.h" |
6 |
|
7 |
|
8 |
subroutine ctrl_set_pack_xy( |
9 |
& cunit, ivartype, fname, masktype, weighttype, |
10 |
& lxxadxx, mythid) |
11 |
|
12 |
c ================================================================== |
13 |
c SUBROUTINE ctrl_set_pack_xy |
14 |
c ================================================================== |
15 |
c |
16 |
c o Compress the control vector such that only ocean points are |
17 |
c written to file. |
18 |
c |
19 |
c changed: heimbach@mit.edu 17-Jun-2003 |
20 |
c merged Armin's changes to replace write of |
21 |
c nr * globfld2d by 1 * globfld3d |
22 |
c (ad hoc fix to speed up global I/O) |
23 |
c |
24 |
c ================================================================== |
25 |
|
26 |
implicit none |
27 |
|
28 |
c == global variables == |
29 |
|
30 |
#include "EEPARAMS.h" |
31 |
#include "SIZE.h" |
32 |
#include "PARAMS.h" |
33 |
#include "GRID.h" |
34 |
|
35 |
#include "ctrl.h" |
36 |
#include "cost.h" |
37 |
|
38 |
#ifdef ALLOW_ECCO_OPTIMIZATION |
39 |
#include "optim.h" |
40 |
#endif |
41 |
|
42 |
c == routine arguments == |
43 |
|
44 |
integer cunit |
45 |
integer ivartype |
46 |
character*( 80) fname |
47 |
character*( 5) masktype |
48 |
character*( 80) weighttype |
49 |
logical lxxadxx |
50 |
integer mythid |
51 |
|
52 |
c == local variables == |
53 |
|
54 |
#ifndef ALLOW_ECCO_OPTIMIZATION |
55 |
integer optimcycle |
56 |
#endif |
57 |
|
58 |
integer bi,bj |
59 |
integer ip,jp |
60 |
integer i,j,k |
61 |
integer ii |
62 |
integer il |
63 |
integer irec,nrec_nl |
64 |
integer itlo,ithi |
65 |
integer jtlo,jthi |
66 |
integer jmin,jmax |
67 |
integer imin,imax |
68 |
|
69 |
integer cbuffindex |
70 |
|
71 |
_RL cbuff ( snx*nsx*npx*sny*nsy*npy ) |
72 |
_RL globmsk ( snx,nsx,npx,sny,nsy,npy,nr ) |
73 |
_RL globfld3d( snx,nsx,npx,sny,nsy,npy,nr ) |
74 |
_RL globfld2d( snx,nsx,npx,sny,nsy,npy ) |
75 |
|
76 |
character*( 80) weightname |
77 |
|
78 |
c == external == |
79 |
|
80 |
integer ilnblnk |
81 |
external ilnblnk |
82 |
|
83 |
c == end of interface == |
84 |
|
85 |
#ifndef ALLOW_ECCO_OPTIMIZATION |
86 |
optimcycle = 0 |
87 |
#endif |
88 |
|
89 |
jtlo = 1 |
90 |
jthi = nsy |
91 |
itlo = 1 |
92 |
ithi = nsx |
93 |
jmin = 1 |
94 |
jmax = sny |
95 |
imin = 1 |
96 |
imax = snx |
97 |
|
98 |
c Initialise temporary file |
99 |
do k = 1,nr |
100 |
do jp = 1,nPy |
101 |
do bj = jtlo,jthi |
102 |
do j = jmin,jmax |
103 |
do ip = 1,nPx |
104 |
do bi = itlo,ithi |
105 |
do i = imin,imax |
106 |
globfld3d(i,bi,ip,j,bj,jp,k) = 0. _d 0 |
107 |
globmsk (i,bi,ip,j,bj,jp,k) = 0. _d 0 |
108 |
enddo |
109 |
enddo |
110 |
enddo |
111 |
enddo |
112 |
enddo |
113 |
enddo |
114 |
enddo |
115 |
|
116 |
c-- Only the master thread will do I/O. |
117 |
_BEGIN_MASTER( mythid ) |
118 |
|
119 |
#ifdef ALLOW_NONDIMENSIONAL_CONTROL_IO |
120 |
il=ilnblnk( weighttype) |
121 |
write(weightname(1:80),'(80a)') ' ' |
122 |
write(weightname(1:80),'(a)') weighttype(1:il) |
123 |
call MDSREADFIELD_2D_GL( |
124 |
& weightname, ctrlprec, 'RL', |
125 |
& 1, globfld2d, 1, mythid) |
126 |
#endif |
127 |
|
128 |
call MDSREADFIELD_3D_GL( |
129 |
& masktype, ctrlprec, 'RL', |
130 |
& Nr, globmsk, 1, mythid) |
131 |
|
132 |
nrec_nl=int(ncvarrecs(ivartype)/Nr) |
133 |
do irec = 1, nrec_nl |
134 |
|
135 |
call MDSREADFIELD_3D_GL( fname, ctrlprec, 'RL', |
136 |
& Nr, globfld3d, irec, mythid) |
137 |
do k = 1, Nr |
138 |
write(cunit) ncvarindex(ivartype) |
139 |
write(cunit) 1 |
140 |
write(cunit) 1 |
141 |
cbuffindex = 0 |
142 |
do jp = 1,nPy |
143 |
do bj = jtlo,jthi |
144 |
do j = jmin,jmax |
145 |
do ip = 1,nPx |
146 |
do bi = itlo,ithi |
147 |
do i = imin,imax |
148 |
if (globmsk(i,bi,ip,j,bj,jp,1) .ne. 0. ) then |
149 |
cbuffindex = cbuffindex + 1 |
150 |
#ifdef ALLOW_NONDIMENSIONAL_CONTROL_IO |
151 |
if (lxxadxx) then |
152 |
cbuff(cbuffindex) = |
153 |
& globfld3d(i,bi,ip,j,bj,jp,k) * |
154 |
& sqrt(globfld2d(i,bi,ip,j,bj,jp)) |
155 |
else |
156 |
cbuff(cbuffindex) = |
157 |
& globfld3d(i,bi,ip,j,bj,jp,k) / |
158 |
& sqrt(globfld2d(i,bi,ip,j,bj,jp)) |
159 |
endif |
160 |
#else |
161 |
cbuff(cbuffindex) = globfld3d(i,bi,ip,j,bj,jp,k) |
162 |
#endif |
163 |
endif |
164 |
enddo |
165 |
enddo |
166 |
enddo |
167 |
enddo |
168 |
enddo |
169 |
enddo |
170 |
c --> check cbuffindex. |
171 |
if ( cbuffindex .gt. 0) then |
172 |
write(cunit) cbuffindex |
173 |
write(cunit) 1 |
174 |
write(cunit) (cbuff(ii), ii=1,cbuffindex) |
175 |
endif |
176 |
enddo |
177 |
c |
178 |
c -- end of irec loop -- |
179 |
enddo |
180 |
|
181 |
do irec = nrec_nl*Nr+1, ncvarrecs(ivartype) |
182 |
|
183 |
call MDSREADFIELD_2D_GL( fname, ctrlprec, 'RL', |
184 |
& 1, globfld3d(1,1,1,1,1,1,1), irec, mythid) |
185 |
|
186 |
write(cunit) ncvarindex(ivartype) |
187 |
write(cunit) 1 |
188 |
write(cunit) 1 |
189 |
do k = 1, 1 |
190 |
cbuffindex = 0 |
191 |
do jp = 1,nPy |
192 |
do bj = jtlo,jthi |
193 |
do j = jmin,jmax |
194 |
do ip = 1,nPx |
195 |
do bi = itlo,ithi |
196 |
do i = imin,imax |
197 |
if (globmsk(i,bi,ip,j,bj,jp,k) .ne. 0. ) then |
198 |
cbuffindex = cbuffindex + 1 |
199 |
#ifdef ALLOW_NONDIMENSIONAL_CONTROL_IO |
200 |
if (lxxadxx) then |
201 |
cbuff(cbuffindex) = |
202 |
& globfld3d(i,bi,ip,j,bj,jp,k) * |
203 |
& sqrt(globfld2d(i,bi,ip,j,bj,jp)) |
204 |
else |
205 |
cbuff(cbuffindex) = |
206 |
& globfld3d(i,bi,ip,j,bj,jp,k) / |
207 |
& sqrt(globfld2d(i,bi,ip,j,bj,jp)) |
208 |
endif |
209 |
#else |
210 |
cbuff(cbuffindex) = globfld3d(i,bi,ip,j,bj,jp,k) |
211 |
#endif |
212 |
endif |
213 |
enddo |
214 |
enddo |
215 |
enddo |
216 |
enddo |
217 |
enddo |
218 |
enddo |
219 |
c --> check cbuffindex. |
220 |
if ( cbuffindex .gt. 0) then |
221 |
write(cunit) cbuffindex |
222 |
write(cunit) k |
223 |
write(cunit) (cbuff(ii), ii=1,cbuffindex) |
224 |
endif |
225 |
enddo |
226 |
c |
227 |
c -- end of irec loop -- |
228 |
enddo |
229 |
|
230 |
_END_MASTER( mythid ) |
231 |
|
232 |
return |
233 |
end |
234 |
|