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

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

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

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

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.35

  ViewVC Help
Powered by ViewVC 1.1.22