/[MITgcm]/MITgcm/pkg/mnc/mnc_cw_readwrite.template
ViewVC logotype

Annotation of /MITgcm/pkg/mnc/mnc_cw_readwrite.template

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


Revision 1.37 - (hide annotations) (download)
Fri Mar 10 16:09:31 2006 UTC (18 years, 3 months ago) by edhill
Branch: MAIN
CVS Tags: checkpoint58l_post, checkpoint58e_post, checkpoint58h_post, checkpoint58j_post, checkpoint58f_post, checkpoint58d_post, checkpoint58c_post, checkpoint58i_post, checkpoint58g_post, checkpoint58k_post, checkpoint58b_post, checkpoint58m_post
Changes since 1.36: +4 -3 lines
fix a bunch of formatted internal writes that need explicit string lengths
  for certain compilers (eg. PGI)

1 edhill 1.37 C $Header: /u/gcmpack/MITgcm/pkg/mnc/mnc_cw_readwrite.template,v 1.36 2006/03/10 05:50:23 edhill Exp $
2 edhill 1.1 C $Name: $
3    
4     #include "MNC_OPTIONS.h"
5    
6     C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
7 edhill 1.17 CBOP 0
8 edhill 1.19 C !ROUTINE: MNC_CW_RX_W_S
9    
10     C !INTERFACE:
11     SUBROUTINE MNC_CW_RX_W_S(
12     I stype,
13     I fbname, bi,bj,
14     I vtype,
15     I var,
16     I myThid )
17    
18     C !DESCRIPTION:
19     C A scalar version of MNC_CW_RX_W() for compilers that cannot
20     C gracefully handle the conversion on their own.
21    
22     C !USES:
23     implicit none
24    
25     C !INPUT PARAMETERS:
26 edhill 1.20 integer myThid, bi,bj
27 edhill 1.19 character*(*) stype, fbname, vtype
28     __V var
29     __V var_arr(1)
30     CEOP
31    
32     var_arr(1) = var
33     CALL MNC_CW_RX_W(stype,fbname,bi,bj,vtype, var_arr, myThid)
34    
35     RETURN
36     END
37    
38     C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
39     CBOP 0
40 edhill 1.15 C !ROUTINE: MNC_CW_RX_W
41 edhill 1.1
42 edhill 1.15 C !INTERFACE:
43 edhill 1.14 SUBROUTINE MNC_CW_RX_W(
44     I stype,
45 edhill 1.1 I fbname, bi,bj,
46     I vtype,
47 edhill 1.9 I var,
48     I myThid )
49 edhill 1.1
50 edhill 1.15 C !DESCRIPTION:
51 edhill 1.20 C A scalar version of MNC_CW_RX_W() for compilers that cannot
52     C gracefully handle the conversion on their own.
53    
54     C !USES:
55     implicit none
56    
57     C !INPUT PARAMETERS:
58     integer myThid, bi,bj
59     character*(*) stype, fbname, vtype
60 jmc 1.21 __V var(*)
61 edhill 1.20 INTEGER offsets(9)
62     CEOP
63     INTEGER i
64    
65     DO i = 1,9
66     offsets(i) = 0
67     ENDDO
68 jmc 1.21 CALL MNC_CW_RX_W_OFFSET(stype,fbname,bi,bj,vtype, var,
69 edhill 1.20 & offsets, myThid)
70    
71     RETURN
72     END
73    
74     C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
75     CBOP 0
76     C !ROUTINE: MNC_CW_RX_W_OFFSET
77    
78     C !INTERFACE:
79     SUBROUTINE MNC_CW_RX_W_OFFSET(
80     I stype,
81     I fbname, bi,bj,
82     I vtype,
83     I var,
84     I offsets,
85     I myThid )
86    
87     C !DESCRIPTION:
88 edhill 1.15 C This subroutine writes one variable to a file or a file group,
89     C depending upon the tile indicies.
90    
91     C !USES:
92 edhill 1.1 implicit none
93     #include "netcdf.inc"
94     #include "mnc_common.h"
95 edhill 1.12 #include "SIZE.h"
96 edhill 1.32 #include "MNC_BUFF.h"
97 edhill 1.1 #include "EEPARAMS.h"
98 edhill 1.12 #include "PARAMS.h"
99 edhill 1.18 #include "MNC_PARAMS.h"
100 edhill 1.2
101 edhill 1.15 C !INPUT PARAMETERS:
102 edhill 1.20 integer myThid, bi,bj
103 edhill 1.14 character*(*) stype, fbname, vtype
104 edhill 1.6 __V var(*)
105 edhill 1.20 INTEGER offsets(*)
106 edhill 1.17 CEOP
107 edhill 1.1
108 edhill 1.15 C !LOCAL VARIABLES:
109 edhill 1.20 integer i,j,k, indv,nvf,nvl, n1,n2, igrid, ntot, indu
110 edhill 1.32 integer bis,bie, bjs,bje, uniq_tnum, uniq_fnum, nfname, iseq
111 edhill 1.37 integer fid, idv, indvids, ndim, indf, err, nf
112 edhill 1.15 integer lbi,lbj, bidim,bjdim, unlim_sz, kr
113     integer p(9),s(9),e(9), dimnc(9)
114     integer vstart(9),vcount(9), udo(9)
115 edhill 1.3 integer j1,j2,j3,j4,j5,j6,j7, k1,k2,k3,k4,k5,k6,k7
116 edhill 1.11 integer indfg, fg1,fg2, npath
117 edhill 1.1 character*(MAX_LEN_MBUF) msgbuf
118 edhill 1.36 character*(MNC_MAX_PATH) fname
119     character*(MNC_MAX_PATH) path_fname
120     character*(MNC_MAX_PATH) tmpnm
121     character*(MNC_MAX_PATH) bpath
122 edhill 1.35 REAL*8 dval, dvm(2)
123     REAL*4 rval, rvm(2)
124     INTEGER ival, ivm(2), irv
125 edhill 1.24 REAL*8 resh_d( MNC_MAX_BUFF )
126     REAL*4 resh_r( MNC_MAX_BUFF )
127     INTEGER resh_i( MNC_MAX_BUFF )
128 edhill 1.35 LOGICAL write_attributes, use_missing
129 edhill 1.23 #ifdef HAVE_STAT
130     integer ntotenc, ncenc, nbytes, fs_isdone
131     character*(200) cenc
132     integer ienc(200)
133     REAL*8 fsnu
134     #endif
135 edhill 1.17
136 edhill 1.15 C Functions
137     integer IFNBLNK, ILNBLNK
138 edhill 1.1
139     C Only do I/O if I am the master thread
140     _BEGIN_MASTER( myThid )
141    
142 edhill 1.36 DO i = 1,MNC_MAX_PATH
143     bpath(i:i) = ' '
144     ENDDO
145    
146 edhill 1.10 C Get the current index for the unlimited dimension from the file
147     C group (or base) name
148     fg1 = IFNBLNK(fbname)
149     fg2 = ILNBLNK(fbname)
150     CALL MNC_GET_IND(MNC_MAX_ID, fbname, mnc_cw_fgnm, indfg, myThid)
151     IF (indfg .LT. 1) THEN
152     write(msgbuf,'(3a)')
153 edhill 1.14 & 'MNC_CW_RX_W ERROR: file group name ''',
154 edhill 1.10 & fbname(fg1:fg2), ''' is not defined'
155     CALL print_error(msgbuf, mythid)
156 edhill 1.14 STOP 'ABNORMAL END: S/R MNC_CW_RX_W'
157 edhill 1.10 ENDIF
158     indu = mnc_cw_fgud(indfg)
159 edhill 1.22 iseq = mnc_cw_fgis(indfg)
160 edhill 1.23 C write(*,*) 'indu,iseq = ', indu, iseq
161 edhill 1.10
162 edhill 1.1 C Check that the Variable Type exists
163     nvf = IFNBLNK(vtype)
164     nvl = ILNBLNK(vtype)
165 edhill 1.9 CALL MNC_GET_IND(MNC_MAX_ID, vtype, mnc_cw_vname, indv, myThid)
166 edhill 1.2 IF (indv .LT. 1) THEN
167 edhill 1.14 write(msgbuf,'(3a)') 'MNC_CW_RX_W ERROR: vtype ''',
168 edhill 1.2 & vtype(nvf:nvl), ''' is not defined'
169 edhill 1.1 CALL print_error(msgbuf, mythid)
170 edhill 1.14 STOP 'ABNORMAL END: S/R MNC_CW_RX_W'
171 edhill 1.1 ENDIF
172 edhill 1.2 igrid = mnc_cw_vgind(indv)
173 edhill 1.1
174 edhill 1.5 C Set the bi,bj indicies
175 edhill 1.2 bis = bi
176     bie = bi
177 edhill 1.1 IF (bi .LT. 1) THEN
178     bis = 1
179     bie = nSx
180     ENDIF
181 edhill 1.2 bjs = bj
182     bje = bj
183 edhill 1.1 IF (bj .LT. 1) THEN
184     bjs = 1
185     bje = nSy
186     ENDIF
187    
188 edhill 1.2 DO lbj = bjs,bje
189     DO lbi = bis,bie
190 edhill 1.1
191 edhill 1.23 #ifdef HAVE_STAT
192     fs_isdone = 0
193     #endif
194     10 CONTINUE
195    
196 edhill 1.1 C Create the file name
197 edhill 1.9 CALL MNC_CW_GET_TILE_NUM(lbi,lbj, uniq_tnum, myThid)
198 edhill 1.36 fname(1:MNC_MAX_PATH) = bpath(1:MNC_MAX_PATH)
199 edhill 1.1 n1 = IFNBLNK(fbname)
200     n2 = ILNBLNK(fbname)
201 edhill 1.32
202     #ifdef MNC_WRITE_OLDNAMES
203    
204 edhill 1.1 ntot = n2 - n1 + 1
205     fname(1:ntot) = fbname(n1:n2)
206     ntot = ntot + 1
207     fname(ntot:ntot) = '.'
208 edhill 1.31 IF ( mnc_use_name_ni0 ) THEN
209     write(fname((ntot+1):(ntot+17)),'(i10.10,a1,i6.6)')
210     & nIter0,'.',uniq_tnum
211     write(fname((ntot+18):(ntot+25)),'(a1,i4.4,a3)')
212     & '.', iseq, '.nc'
213     nfname = ntot + 25
214     ELSE
215     write(fname((ntot+1):(ntot+14)),'(i4.4,a1,i6.6,a3)')
216     & iseq,'.',uniq_tnum, '.nc'
217     nfname = ntot + 14
218     ENDIF
219 edhill 1.2
220 edhill 1.32 #else
221    
222     CALL MNC_PSNCM(tmpnm, uniq_tnum, MNC_DEF_TMNC)
223     k = ILNBLNK(tmpnm)
224     IF ( mnc_cw_cit(1,mnc_cw_fgci(indfg)) .GT. -1 ) THEN
225 edhill 1.34 j = mnc_cw_cit(2,mnc_cw_fgci(indfg))
226     IF ( mnc_cw_fgis(indfg) .GT. j )
227     & j = mnc_cw_fgis(indfg)
228 edhill 1.32 write(fname,'(a,a1,i10.10,a2,a,a3)') fbname(n1:n2),
229 edhill 1.34 & '.', j, '.t', tmpnm(1:k), '.nc'
230 edhill 1.32 ELSEIF ( mnc_cw_cit(1,mnc_cw_fgci(indfg)) .EQ. -1 ) THEN
231     C Leave off the myIter value entirely
232     write(fname,'(a,a2,a,a3)') fbname(n1:n2), '.t',
233     & tmpnm(1:k),'.nc'
234     ELSE
235     C We have an error--bad flag value
236     write(msgbuf,'(4a)')
237     & 'MNC_CW_RX_W ERROR: bad mnc_cw_cit(1,...) ',
238     & 'flag value for base name ''', fbname(fg1:fg2),
239     & ''''
240     CALL print_error(msgbuf, mythid)
241     STOP 'ABNORMAL END: S/R MNC_CW_RX_W'
242     ENDIF
243     nfname = ILNBLNK(fname)
244    
245     #endif
246    
247 edhill 1.11 C Add the path to the file name
248 edhill 1.12 IF (mnc_use_outdir) THEN
249 edhill 1.36 path_fname(1:MNC_MAX_PATH) = bpath(1:MNC_MAX_PATH)
250 edhill 1.12 npath = ILNBLNK(mnc_out_path)
251     path_fname(1:npath) = mnc_out_path(1:npath)
252 edhill 1.13 path_fname((npath+1):(npath+nfname)) = fname(1:nfname)
253 edhill 1.36 fname(1:MNC_MAX_PATH) = path_fname(1:MNC_MAX_PATH)
254 edhill 1.13 nfname = npath + nfname
255 edhill 1.12 ENDIF
256 edhill 1.11
257 edhill 1.2 C Append to an existing or create a new file
258 edhill 1.26 CALL MNC_CW_FILE_AORC(fname,indf, lbi,lbj,uniq_tnum, myThid)
259 edhill 1.2 fid = mnc_f_info(indf,2)
260    
261 edhill 1.23 #ifdef HAVE_STAT
262     IF ((mnc_cw_fgig(indfg) .EQ. 1)
263     & .AND. (fs_isdone .EQ. 0)) THEN
264 edhill 1.26 C Decide whether to append to the existing or create a new
265     C file based on the byte count per unlimited dimension
266 edhill 1.23 ncenc = 70
267     cenc(1:26) = 'abcdefghijklmnopqrstuvwxyz'
268     cenc(27:52) = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
269     cenc(53:70) = '0123456789_.,+-=/~'
270     k = nfname
271     IF (k .GT. 200) k = 200
272     ntotenc = 0
273     DO i = 1,k
274     DO j = 1,ncenc
275     IF (fname(i:i) .EQ. cenc(j:j)) THEN
276     ntotenc = ntotenc + 1
277     ienc(ntotenc) = j
278     GOTO 20
279     ENDIF
280     ENDDO
281     20 CONTINUE
282     ENDDO
283     CALL mncfsize(ntotenc, ienc, nbytes)
284     IF (nbytes .GT. 0) THEN
285     CALL MNC_DIM_UNLIM_SIZE(fname, unlim_sz, myThid)
286     fsnu = (1.0 _d 0 + 1.0 _d 0 / DBLE(unlim_sz))
287     & * DBLE(nbytes)
288     IF (fsnu .GT. mnc_max_fsize) THEN
289 edhill 1.25 C Delete the now-full fname from the lookup tables since
290     C we are all done writing to it.
291     CALL MNC_FILE_CLOSE(fname, myThid)
292 edhill 1.23 indu = 1
293     mnc_cw_fgud(indfg) = 1
294 edhill 1.32
295     #ifdef MNC_WRITE_OLDNAMES
296     iseq = iseq + 1
297 edhill 1.23 mnc_cw_fgis(indfg) = iseq
298 edhill 1.32 #else
299     IF (mnc_cw_cit(1,mnc_cw_fgci(indfg)) .LT. 0) THEN
300     write(msgbuf,'(5a)')
301     & 'MNC_CW_RX_W ERROR: output file for base name ''',
302     & fbname(fg1:fg2), ''' is about to exceed the max ',
303     & 'file size and is NOT ALLOWED an iteration value ',
304     & 'within its file name'
305     CALL print_error(msgbuf, mythid)
306     STOP 'ABNORMAL END: S/R MNC_CW_RX_W'
307     ELSEIF (mnc_cw_cit(3,mnc_cw_fgci(indfg)) .LT. 0) THEN
308     write(msgbuf,'(5a)')
309     & 'MNC_CW_RX_W ERROR: output file for base name ''',
310     & fbname(fg1:fg2), ''' is about to exceed the max ',
311     & 'file size and no next-iter has been specified--',
312     & 'please see the MNC CITER functions'
313     CALL print_error(msgbuf, mythid)
314     STOP 'ABNORMAL END: S/R MNC_CW_RX_W'
315     ENDIF
316 edhill 1.34 mnc_cw_fgis(indfg) = mnc_cw_cit(3,mnc_cw_fgci(indfg))
317     C DO NOT BUMP THE CURRENT ITER FOR ALL FILES IN THIS CITER
318     C GROUP SINCE THIS IS ONLY GROWTH TO AVOID FILE SIZE
319     C LIMITS FOR THIS ONE BASENAME GROUP, NOT GROWTH OF THE
320     C ENTIRE CITER GROUP !!!
321     C mnc_cw_cit(2,mnc_cw_fgci(indfg))
322     C & = mnc_cw_cit(3,mnc_cw_fgci(indfg))
323     C mnc_cw_cit(3,mnc_cw_fgci(indfg)) = -1
324 edhill 1.32 #endif
325 edhill 1.23 fs_isdone = 1
326     GOTO 10
327 edhill 1.32
328 edhill 1.23 ENDIF
329     ENDIF
330     ENDIF
331     #endif /* HAVE_STAT */
332    
333 edhill 1.3 C Ensure that all the NetCDF dimensions are defined and create a
334     C local copy of them
335 edhill 1.2 DO i = 1,9
336     dimnc(i) = 1
337     ENDDO
338     DO i = 1,mnc_cw_ndim(igrid)
339 edhill 1.3 IF (mnc_cw_dims(i,igrid) .EQ. -1) THEN
340     dimnc(i) = -1
341     ELSE
342     dimnc(i) = mnc_cw_ie(i,igrid) - mnc_cw_is(i,igrid) + 1
343     ENDIF
344 edhill 1.26
345     C Add the coordinate variables
346 edhill 1.27 CALL MNC_DIM_INIT_ALL_CV(fname,
347     & mnc_cw_dn(i,igrid), dimnc(i), 'Y', lbi,lbj, myThid)
348 edhill 1.26
349 edhill 1.2 ENDDO
350    
351     C Ensure that the "grid" is defined
352 edhill 1.9 CALL MNC_GRID_INIT(fname, mnc_cw_gname(igrid),
353     & mnc_cw_ndim(igrid), mnc_cw_dn(1,igrid), myThid)
354 edhill 1.2
355     C Ensure that the variable is defined
356 edhill 1.35 irv = 0
357 edhill 1.14 IF (stype(1:1) .EQ. 'D')
358     & CALL MNC_VAR_INIT_DBL(
359 edhill 1.35 & fname, mnc_cw_gname(igrid), vtype, irv, myThid)
360 edhill 1.14 IF (stype(1:1) .EQ. 'R')
361     & CALL MNC_VAR_INIT_REAL(
362 edhill 1.35 & fname, mnc_cw_gname(igrid), vtype, irv, myThid)
363 edhill 1.14 IF (stype(1:1) .EQ. 'I')
364     & CALL MNC_VAR_INIT_INT(
365 edhill 1.35 & fname, mnc_cw_gname(igrid), vtype, irv, myThid)
366    
367     IF (irv .GT. 0) THEN
368     C Return value indicates that the variable did not previously
369     C exist in this file, so we need to write all the attributes
370     write_attributes = .TRUE.
371     ELSE
372     write_attributes = .FALSE.
373     ENDIF
374 edhill 1.14
375 edhill 1.2 DO i = 1,mnc_fv_ids(indf,1)
376     j = 2 + 3*(i - 1)
377     IF (mnc_v_names(mnc_fv_ids(indf,j)) .EQ. vtype) THEN
378     idv = mnc_fv_ids(indf,j+1)
379     indvids = mnc_fd_ind(indf, mnc_f_info(indf,
380     & (mnc_fv_ids(indf,j+2) + 1)) )
381 edhill 1.23 GOTO 30
382 edhill 1.2 ENDIF
383     ENDDO
384 edhill 1.14 write(msgbuf,'(4a)') 'MNC_MNC_CW_RX_W ERROR: ',
385 edhill 1.2 & 'cannot reference variable ''', vtype, ''''
386     CALL print_error(msgbuf, mythid)
387 edhill 1.5 STOP 'ABNORMAL END: package MNC'
388 edhill 1.23 30 CONTINUE
389 edhill 1.2
390 edhill 1.3 C Check for bi,bj indicies
391     bidim = mnc_cw_vbij(1,indv)
392     bjdim = mnc_cw_vbij(2,indv)
393 edhill 1.4 CEH3 write(*,*) 'bidim,bjdim = ', bidim,bjdim
394 edhill 1.3
395 edhill 1.2 C Set the dimensions for the in-memory array
396     ndim = mnc_cw_ndim(igrid)
397 edhill 1.3 k = mnc_cw_dims(1,igrid)
398     IF (k .GT. 0) THEN
399     p(1) = k
400     ELSE
401     p(1) = 1
402     ENDIF
403 edhill 1.2 DO i = 2,9
404 edhill 1.3 k = mnc_cw_dims(i,igrid)
405     IF (k .LT. 1) THEN
406     k = 1
407     ENDIF
408     IF ((bidim .GT. 0) .AND. (i .EQ. bidim)) THEN
409     p(i) = nSx * p(i-1)
410     ELSEIF ((bjdim .GT. 0) .AND. (i .EQ. bjdim)) THEN
411     p(i) = nSy * p(i-1)
412     ELSE
413     p(i) = k * p(i-1)
414     ENDIF
415 edhill 1.20 IF (offsets(i) .GT. 0) THEN
416     k = 1
417     p(i) = k * p(i-1)
418     ENDIF
419 edhill 1.2 ENDDO
420    
421 edhill 1.3 C Set starting and ending indicies for the in-memory array and
422     C the unlimited dimension offset for the NetCDF array
423 edhill 1.2 DO i = 1,9
424 edhill 1.3 udo(i) = 0
425     s(i) = 1
426     e(i) = 1
427     IF (i .LE. ndim) THEN
428     s(i) = mnc_cw_is(i,igrid)
429     e(i) = mnc_cw_ie(i,igrid)
430     ENDIF
431     C Check for the unlimited dimension
432     IF ((i .EQ. ndim)
433     & .AND. (mnc_cw_dims(i,igrid) .EQ. -1)) THEN
434     IF (indu .GT. 0) THEN
435     C Use the indu value
436     udo(i) = indu - 1
437     ELSEIF (indu .EQ. -1) THEN
438     C Append one to the current unlimited dim size
439 edhill 1.9 CALL MNC_DIM_UNLIM_SIZE( fname, unlim_sz, myThid)
440 edhill 1.3 udo(i) = unlim_sz
441 edhill 1.2 ELSE
442 edhill 1.3 C Use the current unlimited dim size
443 edhill 1.9 CALL MNC_DIM_UNLIM_SIZE( fname, unlim_sz, myThid)
444 edhill 1.3 udo(i) = unlim_sz - 1
445 edhill 1.2 ENDIF
446     ENDIF
447     ENDDO
448 edhill 1.3 IF (bidim .GT. 0) THEN
449     s(bidim) = lbi
450     e(bidim) = lbi
451     ENDIF
452     IF (bjdim .GT. 0) THEN
453     s(bjdim) = lbj
454     e(bjdim) = lbj
455     ENDIF
456 edhill 1.20
457     C Check the offsets
458     DO i = 1,9
459     IF (offsets(i) .GT. 0) THEN
460     udo(i) = udo(i) + offsets(i) - 1
461     s(i) = 1
462     e(i) = 1
463     ENDIF
464     ENDDO
465 edhill 1.3
466 edhill 1.35 IF (write_attributes) THEN
467     C Add the per-variable attributes
468     DO i = 1,mnc_cw_vnat(1,indv)
469     CALL MNC_VAR_ADD_ATTR_STR( fname, vtype,
470     & mnc_cw_vtnm(i,indv), mnc_cw_vtat(i,indv), myThid)
471     ENDDO
472     DO i = 1,mnc_cw_vnat(2,indv)
473     CALL MNC_VAR_ADD_ATTR_INT( fname, vtype,
474     & mnc_cw_vinm(i,indv), 1, mnc_cw_viat(i,indv), myThid)
475     ENDDO
476     DO i = 1,mnc_cw_vnat(3,indv)
477     CALL MNC_VAR_ADD_ATTR_DBL( fname, vtype,
478     & mnc_cw_vdnm(i,indv), 1, mnc_cw_vdat(i,indv), myThid)
479     ENDDO
480     ENDIF
481    
482     C Handle missing values
483     use_missing = .FALSE.
484     IF (mnc_cw_vfmv(indv) .EQ. 0) THEN
485     use_missing = .FALSE.
486     ELSE
487     IF (mnc_cw_vfmv(indv) .EQ. 1) THEN
488     use_missing = .TRUE.
489     dvm(1) = mnc_def_dmv(1)
490     dvm(2) = mnc_def_dmv(2)
491     rvm(1) = mnc_def_rmv(1)
492     rvm(2) = mnc_def_rmv(2)
493     ivm(1) = mnc_def_imv(1)
494     ivm(2) = mnc_def_imv(2)
495     ELSEIF (mnc_cw_vfmv(indv) .EQ. 2) THEN
496     use_missing = .TRUE.
497     dvm(1) = mnc_cw_vmvd(1,indv)
498     dvm(2) = mnc_cw_vmvd(2,indv)
499     rvm(1) = mnc_cw_vmvr(1,indv)
500     rvm(2) = mnc_cw_vmvr(2,indv)
501     ivm(1) = mnc_cw_vmvi(1,indv)
502     ivm(2) = mnc_cw_vmvi(2,indv)
503     ENDIF
504     ENDIF
505     IF (write_attributes .AND. use_missing) THEN
506     write(msgbuf,'(4a)') 'writing attribute ''missing_value''',
507     & ' within file ''', fname(1:nfname), ''''
508     IF (stype(1:1) .EQ. 'D') THEN
509     err = NF_PUT_ATT_DOUBLE(fid, idv, 'missing_value',
510     & NF_DOUBLE, 1, dvm(2))
511     ELSEIF (stype(1:1) .EQ. 'R') THEN
512     err = NF_PUT_ATT_REAL(fid, idv, 'missing_value',
513     & NF_FLOAT, 1, dvm(2))
514     ELSEIF (stype(1:1) .EQ. 'I') THEN
515     err = NF_PUT_ATT_INT(fid, idv, 'missing_value',
516     & NF_INT, 1, ivm(2))
517     ENDIF
518     CALL MNC_HANDLE_ERR(err, msgbuf, myThid)
519     ENDIF
520 edhill 1.2
521 edhill 1.9 CALL MNC_FILE_ENDDEF(fname, myThid)
522 edhill 1.2
523 edhill 1.8 write(msgbuf,'(5a)') 'writing variable type ''',
524     & vtype(nvf:nvl), ''' within file ''',
525     & fname(1:nfname), ''''
526    
527 edhill 1.20 C DO i = 1,9
528     C write(*,*) 'i,p(i),s(i),e(i),udo(i),offsets(i) = ',
529     C & i,p(i),s(i),e(i),udo(i),offsets(i)
530     C ENDDO
531    
532 edhill 1.2 C Write the variable one vector at a time
533 edhill 1.3 DO j7 = s(7),e(7)
534 edhill 1.4 k7 = (j7 - 1)*p(6)
535 edhill 1.3 vstart(7) = udo(7) + j7 - s(7) + 1
536     vcount(7) = 1
537     DO j6 = s(6),e(6)
538 edhill 1.4 k6 = (j6 - 1)*p(5) + k7
539 edhill 1.3 vstart(6) = udo(6) + j6 - s(6) + 1
540     vcount(6) = 1
541     DO j5 = s(5),e(5)
542 edhill 1.4 k5 = (j5 - 1)*p(4) + k6
543 edhill 1.3 vstart(5) = udo(5) + j5 - s(5) + 1
544     vcount(5) = 1
545     DO j4 = s(4),e(4)
546 edhill 1.4 k4 = (j4 - 1)*p(3) + k5
547 edhill 1.3 vstart(4) = udo(4) + j4 - s(4) + 1
548     vcount(4) = 1
549     DO j3 = s(3),e(3)
550 edhill 1.4 k3 = (j3 - 1)*p(2) + k4
551 edhill 1.3 vstart(3) = udo(3) + j3 - s(3) + 1
552     vcount(3) = 1
553     DO j2 = s(2),e(2)
554 edhill 1.4 k2 = (j2 - 1)*p(1) + k3
555 edhill 1.3 vstart(2) = udo(2) + j2 - s(2) + 1
556     vcount(2) = 1
557 edhill 1.1
558 edhill 1.3 kr = 0
559     vstart(1) = udo(1) + 1
560     vcount(1) = e(1) - s(1) + 1
561 edhill 1.2
562 edhill 1.24 IF (vcount(1) .GT. MNC_MAX_BUFF) THEN
563     write(msgbuf,'(2a,I7,a)') 'MNC_MAX_BUFF is too small',
564     & '--please increase to at least ',
565 edhill 1.32 & vcount(1), ' in ''MNC_BUFF.h'''
566 edhill 1.24 CALL PRINT_ERROR(msgBuf , 1)
567     STOP 'ABNORMAL END: S/R MNC_CW_RX_W_OFFSET'
568     ENDIF
569    
570 edhill 1.35 IF (use_missing) THEN
571    
572     IF (stype(1:1) .EQ. 'D') THEN
573     DO j1 = s(1),e(1)
574     k1 = k2 + j1
575     kr = kr + 1
576     dval = var(k1)
577     IF (dval .EQ. dvm(1)) THEN
578     resh_d(kr) = dvm(2)
579     ELSE
580     resh_d(kr) = dval
581     ENDIF
582     ENDDO
583     err = NF_PUT_VARA_DOUBLE(fid, idv, vstart, vcount, resh_d)
584     ELSEIF (stype(1:1) .EQ. 'R') THEN
585     DO j1 = s(1),e(1)
586     k1 = k2 + j1
587     kr = kr + 1
588     rval = var(k1)
589     IF (rval .EQ. rvm(1)) THEN
590     resh_r(kr) = rvm(2)
591     ELSE
592     resh_r(kr) = rval
593     ENDIF
594     ENDDO
595     err = NF_PUT_VARA_REAL(fid, idv, vstart, vcount, resh_r)
596     ELSEIF (stype(1:1) .EQ. 'I') THEN
597     DO j1 = s(1),e(1)
598     k1 = k2 + j1
599     kr = kr + 1
600     ival = MNC2I( var(k1) )
601     IF (ival .EQ. ivm(1)) THEN
602     resh_i(kr) = ivm(2)
603     ELSE
604     resh_i(kr) = ival
605     ENDIF
606     ENDDO
607     err = NF_PUT_VARA_INT(fid, idv, vstart, vcount, resh_i)
608     ENDIF
609    
610     ELSE
611    
612     IF (stype(1:1) .EQ. 'D') THEN
613     DO j1 = s(1),e(1)
614     k1 = k2 + j1
615     kr = kr + 1
616     resh_d(kr) = var(k1)
617     ENDDO
618     err = NF_PUT_VARA_DOUBLE(fid, idv, vstart, vcount, resh_d)
619     ELSEIF (stype(1:1) .EQ. 'R') THEN
620     DO j1 = s(1),e(1)
621     k1 = k2 + j1
622     kr = kr + 1
623     resh_r(kr) = var(k1)
624     ENDDO
625     err = NF_PUT_VARA_REAL(fid, idv, vstart, vcount, resh_r)
626     ELSEIF (stype(1:1) .EQ. 'I') THEN
627     DO j1 = s(1),e(1)
628     k1 = k2 + j1
629     kr = kr + 1
630     resh_i(kr) = MNC2I( var(k1) )
631     ENDDO
632     err = NF_PUT_VARA_INT(fid, idv, vstart, vcount, resh_i)
633     ENDIF
634    
635 edhill 1.14 ENDIF
636 edhill 1.9 CALL MNC_HANDLE_ERR(err, msgbuf, myThid)
637 edhill 1.8
638 edhill 1.3 ENDDO
639     ENDDO
640 edhill 1.2 ENDDO
641     ENDDO
642     ENDDO
643     ENDDO
644    
645     C Sync the file
646     err = NF_SYNC(fid)
647 edhill 1.37 nf = ILNBLNK( fname )
648     write(msgbuf,'(3a)') 'sync for file ''', fname(1:nf),
649 edhill 1.14 & ''' in S/R MNC_CW_RX_W'
650 edhill 1.9 CALL MNC_HANDLE_ERR(err, msgbuf, myThid)
651 edhill 1.5
652     ENDDO
653     ENDDO
654    
655     _END_MASTER( myThid )
656    
657     RETURN
658     END
659    
660    
661     C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
662 edhill 1.17 CBOP 0
663 edhill 1.19 C !ROUTINE: MNC_CW_RX_R_S
664    
665     C !INTERFACE:
666     SUBROUTINE MNC_CW_RX_R_S(
667     I stype,
668     I fbname, bi,bj,
669     I vtype,
670     I var,
671     I myThid )
672    
673     C !DESCRIPTION:
674     C A scalar version of MNC_CW_RX_R() for compilers that cannot
675     C gracefully handle the conversion on their own.
676    
677     C !USES:
678     implicit none
679    
680     C !INPUT PARAMETERS:
681 edhill 1.20 integer myThid, bi,bj
682 edhill 1.19 character*(*) stype, fbname, vtype
683     __V var
684     __V var_arr(1)
685     CEOP
686     var_arr(1) = var
687    
688     CALL MNC_CW_RX_R(stype,fbname,bi,bj,vtype, var_arr, myThid)
689    
690     RETURN
691     END
692    
693    
694     C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
695     CBOP 0
696 edhill 1.15 C !ROUTINE: MNC_CW_RX_R
697 edhill 1.5
698 edhill 1.15 C !INTERFACE:
699 edhill 1.14 SUBROUTINE MNC_CW_RX_R(
700     I stype,
701 edhill 1.5 I fbname, bi,bj,
702     I vtype,
703 edhill 1.9 I var,
704     I myThid )
705 edhill 1.5
706 edhill 1.15 C !DESCRIPTION:
707     C This subroutine reads one variable from a file or a file group,
708     C depending upon the tile indicies.
709    
710     C !USES:
711 edhill 1.17 implicit none
712 edhill 1.5 #include "netcdf.inc"
713     #include "mnc_common.h"
714 edhill 1.13 #include "SIZE.h"
715 edhill 1.32 #include "MNC_BUFF.h"
716 edhill 1.5 #include "EEPARAMS.h"
717 edhill 1.13 #include "PARAMS.h"
718 edhill 1.18 #include "MNC_PARAMS.h"
719 edhill 1.5
720 edhill 1.15 C !INPUT PARAMETERS:
721 edhill 1.20 integer myThid, bi,bj
722 edhill 1.14 character*(*) stype, fbname, vtype
723 edhill 1.6 __V var(*)
724 edhill 1.17 CEOP
725 edhill 1.5
726 edhill 1.15 C !LOCAL VARIABLES:
727 edhill 1.20 integer i,k, nvf,nvl, n1,n2, igrid, ntot, indu
728 edhill 1.32 integer bis,bie, bjs,bje, uniq_tnum,uniq_fnum, nfname, fid, idv
729 edhill 1.28 integer ndim, err, lbi,lbj, bidim,bjdim, unlim_sz, kr
730 edhill 1.32 integer ind_vt, npath, unlid, f_or_t, ixoff,iyoff
731 edhill 1.28 C integer f_sNx,f_sNy, alen, atype, ind_fv_ids, ierr, indf
732 edhill 1.6 integer p(9),s(9),e(9), vstart(9),vcount(9), udo(9)
733     integer j1,j2,j3,j4,j5,j6,j7, k1,k2,k3,k4,k5,k6,k7
734 edhill 1.5 character*(MAX_LEN_MBUF) msgbuf
735 edhill 1.36 character*(MNC_MAX_PATH) fname
736     character*(MNC_MAX_PATH) fname_zs
737     character*(MNC_MAX_PATH) tmpnm
738     character*(MNC_MAX_PATH) path_fname
739     character*(MNC_MAX_PATH) bpath
740 edhill 1.10 integer indfg, fg1,fg2
741 edhill 1.24 REAL*8 resh_d( MNC_MAX_BUFF )
742     REAL*4 resh_r( MNC_MAX_BUFF )
743     INTEGER resh_i( MNC_MAX_BUFF )
744 edhill 1.17
745 edhill 1.15 C Functions
746     integer IFNBLNK, ILNBLNK
747 edhill 1.5
748     C Only do I/O if I am the master thread
749     _BEGIN_MASTER( myThid )
750 edhill 1.10
751 edhill 1.36 DO i = 1,MNC_MAX_PATH
752     bpath(i:i) = ' '
753     ENDDO
754    
755 edhill 1.10 C Get the current index for the unlimited dimension from the file
756     C group (or base) name
757     fg1 = IFNBLNK(fbname)
758     fg2 = ILNBLNK(fbname)
759     CALL MNC_GET_IND(MNC_MAX_ID, fbname, mnc_cw_fgnm, indfg, myThid)
760     IF (indfg .LT. 1) THEN
761     write(msgbuf,'(3a)')
762 edhill 1.14 & 'MNC_CW_RX_W ERROR: file group name ''',
763 edhill 1.10 & fbname(fg1:fg2), ''' is not defined'
764     CALL print_error(msgbuf, mythid)
765 edhill 1.14 STOP 'ABNORMAL END: S/R MNC_CW_RX_W'
766 edhill 1.10 ENDIF
767     indu = mnc_cw_fgud(indfg)
768 edhill 1.5
769     C Check that the Variable Type exists
770     nvf = IFNBLNK(vtype)
771     nvl = ILNBLNK(vtype)
772 edhill 1.9 CALL MNC_GET_IND( MNC_MAX_ID, vtype, mnc_cw_vname, ind_vt, myThid)
773 edhill 1.7 IF (ind_vt .LT. 1) THEN
774 edhill 1.14 write(msgbuf,'(3a)') 'MNC_CW_RX_R ERROR: vtype ''',
775 edhill 1.5 & vtype(nvf:nvl), ''' is not defined'
776     CALL print_error(msgbuf, mythid)
777 edhill 1.14 STOP 'ABNORMAL END: S/R MNC_CW_RX_R'
778 edhill 1.5 ENDIF
779     igrid = mnc_cw_vgind(ind_vt)
780    
781     C Check for bi,bj indicies
782 edhill 1.6 bidim = mnc_cw_vbij(1,ind_vt)
783     bjdim = mnc_cw_vbij(2,ind_vt)
784 edhill 1.5
785     C Set the bi,bj indicies
786     bis = bi
787     bie = bi
788     IF (bi .LT. 1) THEN
789     bis = 1
790     bie = nSx
791     ENDIF
792     bjs = bj
793     bje = bj
794     IF (bj .LT. 1) THEN
795     bjs = 1
796     bje = nSy
797     ENDIF
798    
799     DO lbj = bjs,bje
800     DO lbi = bis,bie
801    
802     C Create the file name
803 edhill 1.9 CALL MNC_CW_GET_TILE_NUM( lbi,lbj, uniq_tnum, myThid)
804 edhill 1.36 fname(1:MNC_MAX_PATH) = bpath(1:MNC_MAX_PATH)
805 edhill 1.32
806     #ifdef MNC_READ_OLDNAMES
807    
808 edhill 1.5 n1 = IFNBLNK(fbname)
809     n2 = ILNBLNK(fbname)
810     ntot = n2 - n1 + 1
811     fname(1:ntot) = fbname(n1:n2)
812     ntot = ntot + 1
813     fname(ntot:ntot) = '.'
814     write(fname((ntot+1):(ntot+9)),'(i6.6,a3)') uniq_tnum, '.nc'
815     nfname = ntot+9
816 edhill 1.13
817     C Add the path to the file name
818     IF (mnc_use_indir) THEN
819 edhill 1.36 path_fname(1:MNC_MAX_PATH) = bpath(1:MNC_MAX_PATH)
820 edhill 1.13 npath = ILNBLNK(mnc_indir_str)
821     path_fname(1:npath) = mnc_indir_str(1:npath)
822     path_fname((npath+1):(npath+nfname)) = fname(1:nfname)
823 edhill 1.36 fname(1:MNC_MAX_PATH) = path_fname(1:MNC_MAX_PATH)
824 edhill 1.13 nfname = npath + nfname
825     ENDIF
826 edhill 1.5
827 edhill 1.30 WRITE(fname_zs,'(2a,i4.4,a1,i6.6,a3)')
828     & mnc_indir_str(1:npath), fbname(n1:n2),
829     & 0, '.', uniq_tnum, '.nc'
830    
831     C The steps are:
832     C (1) open the file in a READ-ONLY mode,
833     C (2) get the var id for the current variable,
834     C (3) read the data, and then
835     C (4) close the file--theres no need to keep it open!
836 edhill 1.5
837 edhill 1.28 write(msgbuf,'(4a)') 'MNC_CW_RX_R: cannot open',
838     & ' file ''', fname(1:nfname), ''' in read-only mode'
839     err = NF_OPEN(fname, NF_NOWRITE, fid)
840 edhill 1.30 IF ( err .NE. NF_NOERR ) THEN
841     C If the initial open fails, try again using a name with a
842     C zero sequence number inserted
843     err = NF_OPEN(fname_zs, NF_NOWRITE, fid)
844     ENDIF
845 edhill 1.28 CALL MNC_HANDLE_ERR(err, msgbuf, myThid)
846    
847 edhill 1.32 write(msgbuf,'(5a)')
848 edhill 1.28 & 'MNC_CW_RX_R: cannot get id for variable ''',
849     & vtype(nvf:nvl), '''in file ''', fname(1:nfname), ''''
850     err = NF_INQ_VARID(fid, vtype, idv)
851     CALL MNC_HANDLE_ERR(err, msgbuf, myThid)
852 edhill 1.32 f_or_t = 0
853    
854     #else
855    
856     C The sequence for PER-FACE and PER-TILE is:
857     C (1) check whether a PER-FACE file exists
858     C . (a) if only one face is used for the entire domain,
859     C . then omit the face index from the file name
860     C . (b) if the PER-FACE file exists and is somehow faulty,
861     C . then we die with an error message
862     C (2) if no PER-FACE file exists, then use a PER-TILE file
863    
864     C Create the PER-FACE file name
865     n1 = IFNBLNK(fbname)
866     n2 = ILNBLNK(fbname)
867     C Add an iteraton count to the file name if its requested
868     IF (mnc_cw_cit(1,mnc_cw_fgci(indfg)) .LT. 0) THEN
869     WRITE(fname,'(a,a1)') fbname(n1:n2), '.'
870     ELSE
871     WRITE(fname,'(a,a1,i10.10,a1)') fbname(n1:n2), '.',
872     & mnc_cw_cit(2,mnc_cw_fgci(indfg)), '.'
873     ENDIF
874     ntot = ILNBLNK(fname)
875 edhill 1.36 path_fname(1:MNC_MAX_PATH) = bpath(1:MNC_MAX_PATH)
876 edhill 1.32 npath = ILNBLNK(mnc_indir_str)
877     C Add the face index
878     CALL MNC_CW_GET_FACE_NUM( lbi,lbj, uniq_fnum, myThid)
879     IF ( uniq_fnum .EQ. -1 ) THEN
880     C There is only one face
881     WRITE(path_fname,'(2a,a2)')
882     & mnc_indir_str(1:npath), fname(1:ntot), 'nc'
883     ELSE
884     CALL MNC_PSNCM(tmpnm, uniq_fnum, MNC_DEF_FMNC)
885     k = ILNBLNK(tmpnm)
886     WRITE(path_fname,'(2a,a1,a,a3)')
887     & mnc_indir_str(1:npath), fname(1:ntot), 'f',
888     & tmpnm(1:k), '.nc'
889     ENDIF
890    
891     C Try to open the PER-FACE file
892 edhill 1.33 C WRITE(*,*) 'trying: "', path_fname, '"'
893 edhill 1.32 err = NF_OPEN(path_fname, NF_NOWRITE, fid)
894     IF ( err .EQ. NF_NOERR ) THEN
895 edhill 1.33 f_or_t = 1
896 edhill 1.32 ELSE
897    
898     C Create the PER-TILE file name
899     CALL MNC_PSNCM(tmpnm, uniq_tnum, MNC_DEF_TMNC)
900     k = ILNBLNK(tmpnm)
901 edhill 1.36 path_fname(1:MNC_MAX_PATH) = bpath(1:MNC_MAX_PATH)
902 edhill 1.32 WRITE(path_fname,'(2a,a1,a,a3)')
903     & mnc_indir_str(1:npath), fname(1:ntot), 't',
904     & tmpnm(1:k), '.nc'
905 edhill 1.33 C WRITE(*,*) 'trying: "', path_fname, '"'
906 edhill 1.32 err = NF_OPEN(path_fname, NF_NOWRITE, fid)
907     IF ( err .EQ. NF_NOERR ) THEN
908 edhill 1.33 f_or_t = 0
909 edhill 1.32 ELSE
910     k = ILNBLNK(path_fname)
911     write(msgbuf,'(4a)')
912     & 'MNC_CW_RX_R: cannot open either a per-face or a ',
913     & 'per-tile file: last try was ''', path_fname(1:k),
914     & ''''
915     CALL print_error(msgbuf, mythid)
916     STOP 'ABNORMAL END: S/R MNC_CW_RX_W'
917     ENDIF
918    
919     ENDIF
920    
921     ntot = ILNBLNK(path_fname)
922     write(msgbuf,'(5a)')
923     & 'MNC_CW_RX_R: cannot get netCDF id for variable ''',
924     & vtype(nvf:nvl), ''' in file ''', path_fname(1:ntot),
925     & ''''
926     err = NF_INQ_VARID(fid, vtype, idv)
927     CALL MNC_HANDLE_ERR(err, msgbuf, myThid)
928    
929 edhill 1.33 k = ILNBLNK(path_fname)
930     fname(1:k) = path_fname(1:k)
931     nfname = k
932    
933 edhill 1.32 #endif
934    
935     IF ( f_or_t .EQ. 1 ) THEN
936    
937 edhill 1.33 C write(msgbuf,'(2a)')
938     C & 'MNC_CW_RX_R: per-face reads are not yet ',
939     C & 'implemented -- so pester Ed to finish them'
940     C CALL print_error(msgbuf, mythid)
941     C STOP 'ABNORMAL END: S/R MNC_CW_RX_W'
942    
943 edhill 1.32 C Get the X,Y PER-FACE offsets
944     CALL MNC_CW_GET_XYFO(lbi,lbj, ixoff,iyoff, myThid)
945    
946     ENDIF
947 edhill 1.6
948 edhill 1.33 C WRITE(*,*) 'f_or_t = ',f_or_t
949    
950 edhill 1.6 C Check that the current sNy,sNy values and the in-file values
951     C are compatible and WARN (only warn) if not
952 edhill 1.28 C f_sNx = -1
953     C f_sNy = -1
954     C err = NF_INQ_ATT(fid,NF_GLOBAL, 'sNx',atype,alen)
955     C IF ((err .EQ. NF_NOERR) .AND. (alen .EQ. 1)) THEN
956     C err = NF_GET_ATT_INT(fid, NF_GLOBAL, 'sNx', f_sNx)
957     C CALL MNC_HANDLE_ERR(err,
958     C & 'reading attribute ''sNx'' in S/R MNC_CW_RX_R',
959     C & myThid)
960     C ENDIF
961     C err = NF_INQ_ATT(fid,NF_GLOBAL, 'sNy',atype,alen)
962     C IF ((err .EQ. NF_NOERR) .AND. (alen .EQ. 1)) THEN
963     C err = NF_GET_ATT_INT(fid, NF_GLOBAL, 'sNy', f_sNy)
964     C CALL MNC_HANDLE_ERR(err,
965     C & 'reading attribute ''sNy'' in S/R MNC_CW_RX_R',
966     C & myThid)
967     C ENDIF
968     C IF ((f_sNx .NE. sNx) .OR. (f_sNy .NE. sNy)) THEN
969     C write(msgbuf,'(5a)') 'MNC_CW_RX_R WARNING: the ',
970     C & 'attributes ''sNx'' and ''sNy'' within the file ''',
971     C & fname(1:nfname), ''' do not exist or do not match ',
972     C & 'the current sizes within the model'
973     C CALL print_error(msgbuf, mythid)
974     C ENDIF
975 edhill 1.5
976 edhill 1.6 C Check that the in-memory variable and the in-file variables
977     C are of compatible sizes
978 edhill 1.8 C ires = 1
979 edhill 1.9 C CALL MNC_CHK_VTYP_R_NCVAR( ind_vt,
980 edhill 1.8 C & indf, ind_fv_ids, indu, ires)
981     C IF (ires .LT. 0) THEN
982 edhill 1.14 C write(msgbuf,'(7a)') 'MNC_CW_RX_R WARNING: the sizes ',
983 edhill 1.8 C & 'of the in-program variable ''', vtype(nvf:nvl),
984     C & ''' and the corresponding variable within file ''',
985     C & fname(1:nfname), ''' are not compatible -- please ',
986     C & 'check the sizes'
987     C CALL print_error(msgbuf, mythid)
988 edhill 1.14 C STOP 'ABNORMAL END: S/R MNC_CW_RX_R'
989 edhill 1.8 C ENDIF
990 edhill 1.5
991 edhill 1.6 C Check for bi,bj indicies
992     bidim = mnc_cw_vbij(1,ind_vt)
993     bjdim = mnc_cw_vbij(2,ind_vt)
994    
995     C Set the dimensions for the in-memory array
996     ndim = mnc_cw_ndim(igrid)
997     k = mnc_cw_dims(1,igrid)
998     IF (k .GT. 0) THEN
999     p(1) = k
1000     ELSE
1001     p(1) = 1
1002     ENDIF
1003     DO i = 2,9
1004     k = mnc_cw_dims(i,igrid)
1005     IF (k .LT. 1) THEN
1006     k = 1
1007     ENDIF
1008     IF ((bidim .GT. 0) .AND. (i .EQ. bidim)) THEN
1009     p(i) = nSx * p(i-1)
1010     ELSEIF ((bjdim .GT. 0) .AND. (i .EQ. bjdim)) THEN
1011     p(i) = nSy * p(i-1)
1012     ELSE
1013     p(i) = k * p(i-1)
1014     ENDIF
1015     ENDDO
1016    
1017     C Set starting and ending indicies for the in-memory array and
1018     C the unlimited dimension offset for the NetCDF array
1019     DO i = 1,9
1020     udo(i) = 0
1021     s(i) = 1
1022     e(i) = 1
1023     IF (i .LE. ndim) THEN
1024     s(i) = mnc_cw_is(i,igrid)
1025     e(i) = mnc_cw_ie(i,igrid)
1026 edhill 1.32
1027     IF ( f_or_t .EQ. 1 ) THEN
1028     C Add the per-face X,Y offsets to the udo offset vector
1029     C since they accomplish the same thing
1030     IF ( mnc_cw_dn(i,igrid)(1:1) .EQ. 'X' ) THEN
1031     udo(i) = ixoff - 1
1032     ELSEIF ( mnc_cw_dn(i,igrid)(1:1) .EQ. 'Y' ) THEN
1033     udo(i) = iyoff - 1
1034     ENDIF
1035     ENDIF
1036    
1037 edhill 1.6 ENDIF
1038     C Check for the unlimited dimension
1039     IF ((i .EQ. ndim)
1040     & .AND. (mnc_cw_dims(i,igrid) .EQ. -1)) THEN
1041     IF (indu .GT. 0) THEN
1042     C Use the indu value
1043     udo(i) = indu - 1
1044 edhill 1.28 ELSE
1045     C We need the current unlim dim size
1046     write(msgbuf,'(5a)') 'MNC_CW_RX_R: getting the ',
1047     & 'unlim dim id within file ''',
1048     & fname(1:nfname), ''''
1049     err = NF_INQ_UNLIMDIM(fid, unlid)
1050     CALL MNC_HANDLE_ERR(err, msgbuf, myThid)
1051     write(msgbuf,'(5a)') 'MNC_CW_RX_R: getting the ',
1052     & 'unlim dim size within file ''',
1053     & fname(1:nfname), ''''
1054     err = NF_INQ_DIMLEN(fid, unlid, unlim_sz)
1055     CALL MNC_HANDLE_ERR(err, msgbuf, myThid)
1056 edhill 1.6 udo(i) = unlim_sz
1057     ENDIF
1058     ENDIF
1059     ENDDO
1060     IF (bidim .GT. 0) THEN
1061     s(bidim) = lbi
1062     e(bidim) = lbi
1063     ENDIF
1064     IF (bjdim .GT. 0) THEN
1065     s(bjdim) = lbj
1066     e(bjdim) = lbj
1067     ENDIF
1068    
1069 edhill 1.8 C DO i = 9,1,-1
1070     C write(*,*) 'i,p(i),s(i),e(i) = ', i,': ',p(i),s(i),e(i)
1071     C ENDDO
1072 edhill 1.6
1073     write(msgbuf,'(5a)') 'reading variable type ''',
1074     & vtype(nvf:nvl), ''' within file ''',
1075     & fname(1:nfname), ''''
1076    
1077     C Read the variable one vector at a time
1078     DO j7 = s(7),e(7)
1079     k7 = (j7 - 1)*p(6)
1080     vstart(7) = udo(7) + j7 - s(7) + 1
1081     vcount(7) = 1
1082     DO j6 = s(6),e(6)
1083     k6 = (j6 - 1)*p(5) + k7
1084     vstart(6) = udo(6) + j6 - s(6) + 1
1085     vcount(6) = 1
1086     DO j5 = s(5),e(5)
1087     k5 = (j5 - 1)*p(4) + k6
1088     vstart(5) = udo(5) + j5 - s(5) + 1
1089     vcount(5) = 1
1090     DO j4 = s(4),e(4)
1091     k4 = (j4 - 1)*p(3) + k5
1092     vstart(4) = udo(4) + j4 - s(4) + 1
1093     vcount(4) = 1
1094     DO j3 = s(3),e(3)
1095     k3 = (j3 - 1)*p(2) + k4
1096     vstart(3) = udo(3) + j3 - s(3) + 1
1097     vcount(3) = 1
1098     DO j2 = s(2),e(2)
1099     k2 = (j2 - 1)*p(1) + k3
1100     vstart(2) = udo(2) + j2 - s(2) + 1
1101     vcount(2) = 1
1102    
1103 edhill 1.14 kr = 0
1104 edhill 1.6 vstart(1) = udo(1) + 1
1105     vcount(1) = e(1) - s(1) + 1
1106 edhill 1.24
1107     IF (vcount(1) .GT. MNC_MAX_BUFF) THEN
1108     write(msgbuf,'(2a,I7,a)') 'MNC_MAX_BUFF is too small',
1109     & '--please increase to at least ',
1110 edhill 1.32 & vcount(1), ' in ''MNC_BUFF.h'''
1111 edhill 1.24 CALL PRINT_ERROR(msgBuf , 1)
1112     STOP 'ABNORMAL END: S/R MNC_CW_RX_R_OFFSET'
1113     ENDIF
1114    
1115 edhill 1.14 IF (stype(1:1) .EQ. 'D') THEN
1116     err = NF_GET_VARA_DOUBLE(fid, idv, vstart, vcount, resh_d)
1117     CALL MNC_HANDLE_ERR(err, msgbuf, myThid)
1118     DO j1 = s(1),e(1)
1119     k1 = k2 + j1
1120     kr = kr + 1
1121 edhill 1.29 var(k1) = MNCI2( resh_d(kr) )
1122 edhill 1.14 ENDDO
1123     ENDIF
1124     IF (stype(1:1) .EQ. 'R') THEN
1125     err = NF_GET_VARA_REAL(fid, idv, vstart, vcount, resh_r)
1126     CALL MNC_HANDLE_ERR(err, msgbuf, myThid)
1127     DO j1 = s(1),e(1)
1128     k1 = k2 + j1
1129     kr = kr + 1
1130 edhill 1.29 var(k1) = MNCI2( resh_r(kr) )
1131 edhill 1.14 ENDDO
1132     ENDIF
1133     IF (stype(1:1) .EQ. 'I') THEN
1134     err = NF_GET_VARA_INT(fid, idv, vstart, vcount, resh_i)
1135     CALL MNC_HANDLE_ERR(err, msgbuf, myThid)
1136     DO j1 = s(1),e(1)
1137     k1 = k2 + j1
1138     kr = kr + 1
1139     var(k1) = resh_i(kr)
1140     ENDDO
1141     ENDIF
1142 edhill 1.6
1143    
1144     ENDDO
1145     ENDDO
1146     ENDDO
1147     ENDDO
1148     ENDDO
1149     ENDDO
1150 edhill 1.8
1151     C Close the file
1152 edhill 1.28 C CALL MNC_FILE_CLOSE(fname, myThid)
1153     err = NF_CLOSE(fid)
1154     write(msgbuf,'(3a)') 'MNC_CW_RX_R: cannot close file ''',
1155     & fname(1:nfname), ''''
1156     CALL MNC_HANDLE_ERR(err, msgbuf, myThid)
1157    
1158 edhill 1.1
1159 edhill 1.6 C End the lbj,lbi loops
1160 edhill 1.1 ENDDO
1161     ENDDO
1162    
1163     _END_MASTER( myThid )
1164    
1165     RETURN
1166     END
1167    
1168     C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
1169    
1170     CEH3 ;;; Local Variables: ***
1171     CEH3 ;;; mode:fortran ***
1172     CEH3 ;;; End: ***

  ViewVC Help
Powered by ViewVC 1.1.22