/[MITgcm]/MITgcm/pkg/ctrl/ctrl_set_unpack_xy.F
ViewVC logotype

Annotation of /MITgcm/pkg/ctrl/ctrl_set_unpack_xy.F

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.11 - (hide annotations) (download)
Tue Jan 4 22:02:31 2005 UTC (19 years, 5 months ago) by heimbach
Branch: MAIN
Changes since 1.10: +87 -8 lines
o Add ctrlvec diagnostics in pack/unpack for nondimensional I/O
o May be enabled via doPackDiag

1 heimbach 1.2
2     #include "CTRL_CPPOPTIONS.h"
3    
4     subroutine ctrl_set_unpack_xy(
5 heimbach 1.11 & lxxadxx, cunit, ivartype, fname, masktype, weighttype,
6 heimbach 1.2 & nwetglobal, mythid)
7    
8     c ==================================================================
9     c SUBROUTINE ctrl_set_unpack_xy
10     c ==================================================================
11     c
12     c o Unpack the control vector such that the land points are filled
13     c in.
14     c
15 heimbach 1.3 c changed: heimbach@mit.edu 17-Jun-2003
16     c merged Armin's changes to replace write of
17     c nr * globfld2d by 1 * globfld3d
18     c (ad hoc fix to speed up global I/O)
19     c
20 heimbach 1.2 c ==================================================================
21    
22     implicit none
23    
24     c == global variables ==
25    
26     #include "EEPARAMS.h"
27     #include "SIZE.h"
28     #include "PARAMS.h"
29     #include "GRID.h"
30    
31     #include "ctrl.h"
32     #include "optim.h"
33    
34     c == routine arguments ==
35    
36 heimbach 1.11 logical lxxadxx
37 heimbach 1.2 integer cunit
38     integer ivartype
39 heimbach 1.9 character*( 80) fname, fnameGlobal
40 heimbach 1.2 character*( 5) masktype
41     character*( 80) weighttype
42     integer nwetglobal(nr)
43     integer mythid
44    
45     c == local variables ==
46    
47     integer bi,bj
48     integer ip,jp
49     integer i,j,k
50     integer ii
51     integer il
52 heimbach 1.3 integer irec,nrec_nl
53 heimbach 1.2 integer itlo,ithi
54     integer jtlo,jthi
55     integer jmin,jmax
56     integer imin,imax
57    
58     integer cbuffindex
59    
60     _RL globmsk ( snx,nsx,npx,sny,nsy,npy,nr )
61     _RL globfld3d( snx,nsx,npx,sny,nsy,npy,nr )
62     _RL globfld2d( snx,nsx,npx,sny,nsy,npy )
63 heimbach 1.11 real*4 cbuff ( snx*nsx*npx*sny*nsy*npy )
64 heimbach 1.2
65     character*(128) cfile
66     character*( 80) weightname
67    
68 heimbach 1.11 integer reclen,irectrue
69     integer cunit2, cunit3
70     character*(80) cfile2, cfile3
71     real*4 cbufftmp( snx*nsx*npx*sny*nsy*npy )
72    
73 heimbach 1.2 c == external ==
74    
75     integer ilnblnk
76     external ilnblnk
77    
78     c == end of interface ==
79    
80     jtlo = 1
81     jthi = nsy
82     itlo = 1
83     ithi = nsx
84     jmin = 1
85     jmax = sny
86     imin = 1
87     imax = snx
88    
89 heimbach 1.9 nbuffGlobal = nbuffGlobal + 1
90    
91 heimbach 1.2 c Initialise temporary file
92     do k = 1,nr
93     do jp = 1,nPy
94     do bj = jtlo,jthi
95     do j = jmin,jmax
96     do ip = 1,nPx
97     do bi = itlo,ithi
98     do i = imin,imax
99     globfld3d(i,bi,ip,j,bj,jp,k) = 0. _d 0
100     globmsk (i,bi,ip,j,bj,jp,k) = 0. _d 0
101     enddo
102     enddo
103     enddo
104     enddo
105     enddo
106     enddo
107     enddo
108    
109     c-- Only the master thread will do I/O.
110     _BEGIN_MASTER( mythid )
111    
112 heimbach 1.11 if ( doPackDiag ) then
113     write(cfile2(1:80),'(80a)') ' '
114     write(cfile3(1:80),'(80a)') ' '
115     if ( lxxadxx ) then
116     write(cfile2(1:80),'(a,I2.2,a,I4.4,a)')
117     & 'diag_unpack_nondim_ctrl_',
118     & ivartype, '_', optimcycle, '.bin'
119     write(cfile3(1:80),'(a,I2.2,a,I4.4,a)')
120     & 'diag_unpack_dimens_ctrl_',
121     & ivartype, '_', optimcycle, '.bin'
122     else
123     write(cfile2(1:80),'(a,I2.2,a,I4.4,a)')
124     & 'diag_unpack_nondim_grad_',
125     & ivartype, '_', optimcycle, '.bin'
126     write(cfile3(1:80),'(a,I2.2,a,I4.4,a)')
127     & 'diag_unpack_dimens_grad_',
128     & ivartype, '_', optimcycle, '.bin'
129     endif
130    
131     reclen = nWetGlobal(1)*4.
132     call mdsfindunit( cunit2, mythid )
133     open( cunit2, file=cfile2, status='new',
134     & access='direct', recl=reclen )
135     call mdsfindunit( cunit3, mythid )
136     open( cunit3, file=cfile3, status='new',
137     & access='direct', recl=reclen )
138     endif
139    
140 heimbach 1.2 #ifdef ALLOW_NONDIMENSIONAL_CONTROL_IO
141     il=ilnblnk( weighttype)
142     write(weightname(1:80),'(80a)') ' '
143     write(weightname(1:80),'(a)') weighttype(1:il)
144     call MDSREADFIELD_2D_GL(
145     & weightname, ctrlprec, 'RL',
146     & 1, globfld2d, 1, mythid)
147     #endif
148    
149     call MDSREADFIELD_3D_GL(
150     & masktype, ctrlprec, 'RL',
151     & Nr, globmsk, 1, mythid)
152    
153 heimbach 1.3 nrec_nl=int(ncvarrecs(ivartype)/Nr)
154     do irec = 1, nrec_nl
155 heimbach 1.7 print *, 'ph-pack nrec_nl = ', irec, nrec_nl, ivartype,
156     & ncvarrecs(ivartype)
157 heimbach 1.3 do k = 1,Nr
158 heimbach 1.11 irectrue = (irec-1)*nr + k
159 heimbach 1.3 read(cunit) filencvarindex(ivartype)
160     if (filencvarindex(ivartype) .NE. ncvarindex(ivartype))
161     & then
162     print *, 'ctrl_set_unpack_xy:WARNING: wrong ncvarindex ',
163     & filencvarindex(ivartype), ncvarindex(ivartype)
164     STOP 'in S/R ctrl_unpack'
165     endif
166     read(cunit) filej
167     read(cunit) filei
168     cbuffindex = nwetglobal(1)
169     if ( cbuffindex .gt. 0 ) then
170     read(cunit) filencbuffindex
171     if (filencbuffindex .NE. cbuffindex) then
172     print *, 'WARNING: wrong cbuffindex ',
173     & filencbuffindex, cbuffindex
174     STOP 'in S/R ctrl_unpack'
175     endif
176     read(cunit) filek
177     if (filek .NE. 1) then
178     print *, 'WARNING: wrong k ',
179     & filek, 1
180     STOP 'in S/R ctrl_unpack'
181     endif
182     read(cunit) (cbuff(ii), ii=1,cbuffindex)
183 heimbach 1.11 c
184     if ( doPackDiag )
185     & write(cunit2,rec=irectrue)
186     & (cbuff(ii), ii=1,cbuffindex)
187     c
188 heimbach 1.3 endif
189     cbuffindex = 0
190     do jp = 1,nPy
191     do bj = jtlo,jthi
192     do j = jmin,jmax
193     do ip = 1,nPx
194     do bi = itlo,ithi
195     do i = imin,imax
196     if ( globmsk(i,bi,ip,j,bj,jp,1) .ne. 0. ) then
197     cbuffindex = cbuffindex + 1
198     globfld3d(i,bi,ip,j,bj,jp,k) = cbuff(cbuffindex)
199     #ifdef ALLOW_NONDIMENSIONAL_CONTROL_IO
200 heimbach 1.11 if ( lxxadxx ) then
201     globfld3d(i,bi,ip,j,bj,jp,k) =
202     & globfld3d(i,bi,ip,j,bj,jp,k)/
203     & sqrt(globfld2d(i,bi,ip,j,bj,jp))
204     else
205     globfld3d(i,bi,ip,j,bj,jp,k) =
206     & globfld3d(i,bi,ip,j,bj,jp,k)*
207     & sqrt(globfld2d(i,bi,ip,j,bj,jp))
208     endif
209     cph(
210     cbufftmp(cbuffindex) =
211     & globfld3d(i,bi,ip,j,bj,jp,k)
212     cph)
213 heimbach 1.3 #endif
214     else
215     globfld3d(i,bi,ip,j,bj,jp,k) = 0. _d 0
216     endif
217     enddo
218     enddo
219     enddo
220     enddo
221     enddo
222     enddo
223     c
224 heimbach 1.11 if ( doPackDiag )
225     & write(cunit3,rec=irectrue)
226     & (cbufftmp(ii),ii=1,nwetglobal(1))
227     c
228 heimbach 1.3 enddo
229    
230     call MDSWRITEFIELD_3D_GL( fname, ctrlprec, 'RL',
231     & NR, globfld3d,
232     & irec, optimcycle, mythid)
233    
234     enddo
235    
236     do irec = nrec_nl*Nr+1,ncvarrecs(ivartype)
237 heimbach 1.7 print *, 'ph-pack nrec_nl+irec ', irec, nrec_nl, ivartype,
238     & ncvarrecs(ivartype)
239 heimbach 1.10 #ifndef ALLOW_ADMTLM
240 heimbach 1.2 read(cunit) filencvarindex(ivartype)
241     if (filencvarindex(ivartype) .NE. ncvarindex(ivartype))
242     & then
243     print *, 'ctrl_set_unpack_xy:WARNING: wrong ncvarindex ',
244     & filencvarindex(ivartype), ncvarindex(ivartype)
245     STOP 'in S/R ctrl_unpack'
246     endif
247     read(cunit) filej
248     read(cunit) filei
249 heimbach 1.10 #endif /* ndef ALLOW_ADMTLM */
250 heimbach 1.2 do k = 1,1
251 heimbach 1.11 irectrue = irec
252 heimbach 1.2 cbuffindex = nwetglobal(k)
253 heimbach 1.10 #ifndef ALLOW_ADMTLM
254 heimbach 1.2 if ( cbuffindex .gt. 0 ) then
255     read(cunit) filencbuffindex
256     if (filencbuffindex .NE. cbuffindex) then
257     print *, 'WARNING: wrong cbuffindex ',
258     & filencbuffindex, cbuffindex
259     STOP 'in S/R ctrl_unpack'
260     endif
261     read(cunit) filek
262     if (filek .NE. k) then
263     print *, 'WARNING: wrong k ',
264     & filek, k
265     STOP 'in S/R ctrl_unpack'
266     endif
267     read(cunit) (cbuff(ii), ii=1,cbuffindex)
268 heimbach 1.11 c
269     if ( doPackDiag )
270     & write(cunit2,rec=irectrue)
271     & (cbuff(ii), ii=1,cbuffindex)
272     c
273 heimbach 1.2 endif
274 heimbach 1.10 #else ALLOW_ADMTLM
275 heimbach 1.9 write(fnameGlobal(1:80),'(a)') ' '
276     write(fnameGlobal,'(a,i4.4)')
277     & 'admtlm_vector.it', optimcycle
278     call mdsreadvector( fnameGlobal, 64, 'RL',
279 heimbach 1.10 & admtlmrec, cbuffGlobal, 1, 1, nbuffGlobal, mythid )
280     do ii = 1, cbuffindex
281     cbuff(ii) = cbuffGlobal(ii)
282     enddo
283 heimbach 1.9 #endif
284 heimbach 1.2 cbuffindex = 0
285     do jp = 1,nPy
286     do bj = jtlo,jthi
287     do j = jmin,jmax
288     do ip = 1,nPx
289     do bi = itlo,ithi
290     do i = imin,imax
291     if ( globmsk(i,bi,ip,j,bj,jp,k) .ne. 0. ) then
292     cbuffindex = cbuffindex + 1
293     globfld3d(i,bi,ip,j,bj,jp,k) = cbuff(cbuffindex)
294     #ifdef ALLOW_NONDIMENSIONAL_CONTROL_IO
295 heimbach 1.11 if ( lxxadxx ) then
296     globfld3d(i,bi,ip,j,bj,jp,k) =
297     & globfld3d(i,bi,ip,j,bj,jp,k)/
298     & sqrt(globfld2d(i,bi,ip,j,bj,jp))
299     else
300     globfld3d(i,bi,ip,j,bj,jp,k) =
301     & globfld3d(i,bi,ip,j,bj,jp,k)*
302     & sqrt(globfld2d(i,bi,ip,j,bj,jp))
303     endif
304     cph(
305     cbufftmp(cbuffindex) =
306     & globfld3d(i,bi,ip,j,bj,jp,k)
307     cph)
308 heimbach 1.2 #endif
309     else
310     globfld3d(i,bi,ip,j,bj,jp,k) = 0. _d 0
311     endif
312     enddo
313     enddo
314     enddo
315     enddo
316     enddo
317     enddo
318     c
319 heimbach 1.11 if ( doPackDiag )
320     & write(cunit3,rec=irectrue)
321     & (cbufftmp(ii), ii=1,nwetglobal(1))
322     c
323 heimbach 1.2 enddo
324    
325     call MDSWRITEFIELD_2D_GL( fname, ctrlprec, 'RL',
326     & 1, globfld3d(1,1,1,1,1,1,1),
327     & irec, optimcycle, mythid)
328    
329     enddo
330    
331 heimbach 1.11 if ( doPackDiag ) then
332     close ( cunit2 )
333     close ( cunit3 )
334     endif
335    
336 heimbach 1.2 _END_MASTER( mythid )
337    
338     return
339     end
340    

  ViewVC Help
Powered by ViewVC 1.1.22