/[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.21 by jmc, Mon Oct 11 18:25:50 2004 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 "EEPARAMS.h"
97    #include "PARAMS.h"
98    #include "MNC_PARAMS.h"
99    
100  #define mnc_rtype_YY  C     !INPUT PARAMETERS:
101          integer myThid, bi,bj
102  C     Arguments        character*(*) stype, fbname, vtype
       integer myThid, bi,bj, indu  
       character*(*) fbname, vtype  
103        __V var(*)        __V var(*)
104          INTEGER offsets(*)
105    CEOP
106    
107  C     Functions  C     !LOCAL VARIABLES:
108        integer IFNBLNK, ILNBLNK        integer i,j,k, indv,nvf,nvl, n1,n2, igrid, ntot, indu
109          integer bis,bie, bjs,bje, uniq_tnum, nfname
110  C     Local Variables        integer fid, idv, indvids, ndim, indf, err
111        integer i,j,k, indv,nvf,nvl, n1,n2, igrid, ntot        integer lbi,lbj, bidim,bjdim, unlim_sz, kr
112        integer bis,bie, bjs,bje, uniq_tnum, nfname, fid, idv, indvids        integer p(9),s(9),e(9), dimnc(9)
113        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)  
114        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
115          integer indfg, fg1,fg2, npath
116        character*(MAX_LEN_MBUF) msgbuf        character*(MAX_LEN_MBUF) msgbuf
117        character*(MNC_MAX_CHAR) fname        character*(MNC_MAX_CHAR) fname
118          character*(MNC_MAX_CHAR) path_fname
119          REAL*8  resh_d( sNx + 2*OLx + sNy + 2*OLy )
120          REAL*4  resh_r( sNx + 2*OLx + sNy + 2*OLy )
121          INTEGER resh_i( sNx + 2*OLx + sNy + 2*OLy )
122    
123  C     Temporary storage for the simultaneous type conversion and  C     Functions
124  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  
125    
126  C     Only do I/O if I am the master thread  C     Only do I/O if I am the master thread
127        _BEGIN_MASTER( myThid )        _BEGIN_MASTER( myThid )
128    
129    C     Get the current index for the unlimited dimension from the file
130    C     group (or base) name
131          fg1 = IFNBLNK(fbname)
132          fg2 = ILNBLNK(fbname)
133          CALL MNC_GET_IND(MNC_MAX_ID, fbname, mnc_cw_fgnm, indfg, myThid)
134          IF (indfg .LT. 1) THEN
135            write(msgbuf,'(3a)')
136         &       'MNC_CW_RX_W ERROR: file group name ''',
137         &       fbname(fg1:fg2), ''' is not defined'
138            CALL print_error(msgbuf, mythid)
139            STOP 'ABNORMAL END: S/R MNC_CW_RX_W'
140          ENDIF
141          indu = mnc_cw_fgud(indfg)
142    
143  C     Check that the Variable Type exists  C     Check that the Variable Type exists
144        nvf = IFNBLNK(vtype)        nvf = IFNBLNK(vtype)
145        nvl = ILNBLNK(vtype)        nvl = ILNBLNK(vtype)
146        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)
147        IF (indv .LT. 1) THEN        IF (indv .LT. 1) THEN
148          write(msgbuf,'(3a)') 'MNC_CW_RX_W_YY ERROR: vtype ''',          write(msgbuf,'(3a)') 'MNC_CW_RX_W ERROR: vtype ''',
149       &       vtype(nvf:nvl), ''' is not defined'       &       vtype(nvf:nvl), ''' is not defined'
150          CALL print_error(msgbuf, mythid)          CALL print_error(msgbuf, mythid)
151          STOP 'ABNORMAL END: S/R MNC_CW_RX_W_YY'          STOP 'ABNORMAL END: S/R MNC_CW_RX_W'
152        ENDIF        ENDIF
153        igrid = mnc_cw_vgind(indv)        igrid = mnc_cw_vgind(indv)
154    
# Line 83  C     Set the bi,bj indicies Line 170  C     Set the bi,bj indicies
170          DO lbi = bis,bie          DO lbi = bis,bie
171    
172  C         Create the file name  C         Create the file name
173            CALL MNC_CW_GET_TILE_NUM(myThid, lbi,lbj, uniq_tnum)            CALL MNC_CW_GET_TILE_NUM(lbi,lbj, uniq_tnum, myThid)
174            fname(1:MNC_MAX_CHAR) = mnc_blank_name(1:MNC_MAX_CHAR)            fname(1:MNC_MAX_CHAR) = mnc_blank_name(1:MNC_MAX_CHAR)
175            n1 = IFNBLNK(fbname)            n1 = IFNBLNK(fbname)
176            n2 = ILNBLNK(fbname)            n2 = ILNBLNK(fbname)
# Line 94  C         Create the file name Line 181  C         Create the file name
181            write(fname((ntot+1):(ntot+9)),'(i6.6,a3)') uniq_tnum, '.nc'            write(fname((ntot+1):(ntot+9)),'(i6.6,a3)') uniq_tnum, '.nc'
182            nfname = ntot+9            nfname = ntot+9
183    
184    C         Add the path to the file name
185              IF (mnc_use_outdir) THEN
186                path_fname(1:MNC_MAX_CHAR) = mnc_blank_name(1:MNC_MAX_CHAR)
187                npath = ILNBLNK(mnc_out_path)
188                path_fname(1:npath) = mnc_out_path(1:npath)
189                path_fname((npath+1):(npath+nfname)) = fname(1:nfname)
190                fname(1:MNC_MAX_CHAR) = path_fname(1:MNC_MAX_CHAR)
191                nfname = npath + nfname
192              ENDIF
193    
194  C         Append to an existing or create a new file  C         Append to an existing or create a new file
195            CALL MNC_CW_FILE_AORC(myThid, fname, indf)            CALL MNC_CW_FILE_AORC(fname, indf, myThid)
196            fid = mnc_f_info(indf,2)            fid = mnc_f_info(indf,2)
197    
198  C         Ensure that all the NetCDF dimensions are defined and create a  C         Ensure that all the NetCDF dimensions are defined and create a
# Line 109  C         local copy of them Line 206  C         local copy of them
206              ELSE              ELSE
207                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
208              ENDIF              ENDIF
209              CALL MNC_DIM_INIT(myThid,fname,              CALL MNC_DIM_INIT(fname,
210       &           mnc_cw_dn(i,igrid), dimnc(i) )       &           mnc_cw_dn(i,igrid), dimnc(i), myThid)
211            ENDDO            ENDDO
212    
213  C         Ensure that the "grid" is defined  C         Ensure that the "grid" is defined
214            CALL MNC_GRID_INIT(myThid,fname, mnc_cw_gname(igrid),            CALL MNC_GRID_INIT(fname, mnc_cw_gname(igrid),
215       &        mnc_cw_ndim(igrid), mnc_cw_dn(1,igrid))       &        mnc_cw_ndim(igrid), mnc_cw_dn(1,igrid), myThid)
216    
217  C         Ensure that the variable is defined  C         Ensure that the variable is defined
218  #ifdef  mnc_rtype_D            IF (stype(1:1) .EQ. 'D')
219        CALL MNC_VAR_INIT_DBL(myThid,fname,mnc_cw_gname(igrid),vtype)       &         CALL MNC_VAR_INIT_DBL(
220  #endif       &         fname, mnc_cw_gname(igrid), vtype, myThid)
221  #ifdef  mnc_rtype_R            IF (stype(1:1) .EQ. 'R')
222        CALL MNC_VAR_INIT_REAL(myThid,fname,mnc_cw_gname(igrid),vtype)       &         CALL MNC_VAR_INIT_REAL(
223  #endif       &         fname, mnc_cw_gname(igrid), vtype, myThid)
224  #ifdef  mnc_rtype_I            IF (stype(1:1) .EQ. 'I')
225        CALL MNC_VAR_INIT_INT(myThid,fname,mnc_cw_gname(igrid),vtype)       &         CALL MNC_VAR_INIT_INT(
226  #endif       &         fname, mnc_cw_gname(igrid), vtype, myThid)
227    
228            DO i = 1,mnc_fv_ids(indf,1)            DO i = 1,mnc_fv_ids(indf,1)
229              j = 2 + 3*(i - 1)              j = 2 + 3*(i - 1)
230              IF (mnc_v_names(mnc_fv_ids(indf,j)) .EQ. vtype) THEN              IF (mnc_v_names(mnc_fv_ids(indf,j)) .EQ. vtype) THEN
# Line 136  C         Ensure that the variable is de Line 234  C         Ensure that the variable is de
234                GOTO 10                GOTO 10
235              ENDIF              ENDIF
236            ENDDO            ENDDO
237            write(msgbuf,'(4a)') 'MNC_MNC_CW_RX_W_YY ERROR: ',            write(msgbuf,'(4a)') 'MNC_MNC_CW_RX_W ERROR: ',
238       &         'cannot reference variable ''', vtype, ''''       &         'cannot reference variable ''', vtype, ''''
239            CALL print_error(msgbuf, mythid)            CALL print_error(msgbuf, mythid)
240            STOP 'ABNORMAL END: package MNC'            STOP 'ABNORMAL END: package MNC'
# Line 167  C         Set the dimensions for the in- Line 265  C         Set the dimensions for the in-
265              ELSE              ELSE
266                p(i) = k * p(i-1)                p(i) = k * p(i-1)
267              ENDIF              ENDIF
268                IF (offsets(i) .GT. 0) THEN
269                  k = 1
270                  p(i) = k * p(i-1)
271                ENDIF
272            ENDDO            ENDDO
273    
274  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 289  C               Use the indu value
289                  udo(i) = indu - 1                  udo(i) = indu - 1
290                ELSEIF (indu .EQ. -1) THEN                ELSEIF (indu .EQ. -1) THEN
291  C               Append one to the current unlimited dim size  C               Append one to the current unlimited dim size
292                  CALL MNC_DIM_UNLIM_SIZE(myThid, fname, unlim_sz)                  CALL MNC_DIM_UNLIM_SIZE( fname, unlim_sz, myThid)
293                  udo(i) = unlim_sz                  udo(i) = unlim_sz
294                ELSE                ELSE
295  C               Use the current unlimited dim size  C               Use the current unlimited dim size
296                  CALL MNC_DIM_UNLIM_SIZE(myThid, fname, unlim_sz)                  CALL MNC_DIM_UNLIM_SIZE( fname, unlim_sz, myThid)
297                  udo(i) = unlim_sz - 1                  udo(i) = unlim_sz - 1
298                ENDIF                ENDIF
299              ENDIF              ENDIF
# Line 204  C               Use the current unlimite Line 306  C               Use the current unlimite
306              s(bjdim) = lbj              s(bjdim) = lbj
307              e(bjdim) = lbj              e(bjdim) = lbj
308            ENDIF            ENDIF
309  CEH3      DO i = 1,9            
310  CEH3        write(*,*) 'i,p(i),s(i),e(i) = ', i,p(i),s(i),e(i)  C         Check the offsets
311  CEH3      ENDDO            DO i = 1,9
312                IF (offsets(i) .GT. 0) THEN
313                  udo(i) = udo(i) + offsets(i) - 1
314                  s(i) = 1
315                  e(i) = 1
316                ENDIF
317              ENDDO
318    
319  C         Add the global attributes  C         Add the global attributes
320            CALL MNC_CW_SET_GATTR(myThid, fname, lbi,lbj, uniq_tnum)            CALL MNC_CW_SET_GATTR( fname, lbi,lbj, uniq_tnum, myThid)
321    
322  C         Add the per-variable attributes  C         Add the per-variable attributes
323            DO i = 1,mnc_cw_vnat(1,indv)            DO i = 1,mnc_cw_vnat(1,indv)
324              CALL MNC_VAR_ADD_ATTR_STR(myThid, fname, vtype,              CALL MNC_VAR_ADD_ATTR_STR( fname, vtype,
325       &           mnc_cw_vtnm(i,indv), mnc_cw_vtat(i,indv))       &           mnc_cw_vtnm(i,indv), mnc_cw_vtat(i,indv), myThid)
326            ENDDO            ENDDO
327            DO i = 1,mnc_cw_vnat(2,indv)            DO i = 1,mnc_cw_vnat(2,indv)
328              CALL MNC_VAR_ADD_ATTR_INT(myThid, fname, vtype,              CALL MNC_VAR_ADD_ATTR_INT( fname, vtype,
329       &           mnc_cw_vinm(i,indv), 1, mnc_cw_viat(i,indv))       &           mnc_cw_vinm(i,indv), 1, mnc_cw_viat(i,indv), myThid)
330            ENDDO            ENDDO
331            DO i = 1,mnc_cw_vnat(3,indv)            DO i = 1,mnc_cw_vnat(3,indv)
332              CALL MNC_VAR_ADD_ATTR_DBL(myThid, fname, vtype,              CALL MNC_VAR_ADD_ATTR_DBL( fname, vtype,
333       &           mnc_cw_vdnm(i,indv), 1, mnc_cw_vdat(i,indv))       &           mnc_cw_vdnm(i,indv), 1, mnc_cw_vdat(i,indv), myThid)
334            ENDDO            ENDDO
335    
336            CALL MNC_FILE_ENDDEF(myThid,fname)            CALL MNC_FILE_ENDDEF(fname, myThid)
337    
338            write(msgbuf,'(5a)') 'writing variable type ''',            write(msgbuf,'(5a)') 'writing variable type ''',
339       &         vtype(nvf:nvl), ''' within file ''',       &         vtype(nvf:nvl), ''' within file ''',
340       &         fname(1:nfname), ''''       &         fname(1:nfname), ''''
341    
342    C         DO i = 1,9
343    C         write(*,*) 'i,p(i),s(i),e(i),udo(i),offsets(i) = ',
344    C         &        i,p(i),s(i),e(i),udo(i),offsets(i)
345    C         ENDDO
346    
347  C         Write the variable one vector at a time  C         Write the variable one vector at a time
348            DO j7 = s(7),e(7)            DO j7 = s(7),e(7)
349              k7 = (j7 - 1)*p(6)              k7 = (j7 - 1)*p(6)
# Line 258  C         Write the variable one vector Line 371  C         Write the variable one vector
371                        vcount(2) = 1                        vcount(2) = 1
372    
373        kr = 0        kr = 0
       DO j1 = s(1),e(1)  
         k1 = k2 + j1  
         kr = kr + 1  
         resh(kr) = var(k1)  
       ENDDO  
         
374        vstart(1) = udo(1) + 1        vstart(1) = udo(1) + 1
375        vcount(1) = e(1) - s(1) + 1        vcount(1) = e(1) - s(1) + 1
376    
377  #ifdef  mnc_rtype_D        IF (stype(1:1) .EQ. 'D') THEN
378        err = NF_PUT_VARA_DOUBLE(fid, idv, vstart, vcount, resh)          DO j1 = s(1),e(1)
379  #endif            k1 = k2 + j1
380  #ifdef  mnc_rtype_R            kr = kr + 1
381        err = NF_PUT_VARA_REAL(fid, idv, vstart, vcount, resh)            resh_d(kr) = var(k1)
382  #endif          ENDDO
383  #ifdef  mnc_rtype_I          err = NF_PUT_VARA_DOUBLE(fid, idv, vstart, vcount, resh_d)
384        err = NF_PUT_VARA_INT(fid, idv, vstart, vcount, resh)        ENDIF
385  #endif        IF (stype(1:1) .EQ. 'R') THEN
386            DO j1 = s(1),e(1)
387              k1 = k2 + j1
388              kr = kr + 1
389              resh_r(kr) = var(k1)
390            ENDDO
391            err = NF_PUT_VARA_REAL(fid, idv, vstart, vcount, resh_r)
392          ENDIF
393          IF (stype(1:1) .EQ. 'I') THEN
394            DO j1 = s(1),e(1)
395              k1 = k2 + j1
396              kr = kr + 1
397              resh_i(kr) = var(k1)
398            ENDDO
399            err = NF_PUT_VARA_INT(fid, idv, vstart, vcount, resh_i)
400          ENDIF
401    
402        CALL MNC_HANDLE_ERR(myThid, err, msgbuf)        CALL MNC_HANDLE_ERR(err, msgbuf, myThid)
403    
404                      ENDDO                      ENDDO
405                    ENDDO                    ENDDO
# Line 289  C         Write the variable one vector Line 411  C         Write the variable one vector
411  C         Sync the file  C         Sync the file
412            err = NF_SYNC(fid)            err = NF_SYNC(fid)
413            write(msgbuf,'(3a)') 'sync for file ''', fname,            write(msgbuf,'(3a)') 'sync for file ''', fname,
414       &         ''' in S/R MNC_CW_RX_W_YY'       &         ''' in S/R MNC_CW_RX_W'
415            CALL MNC_HANDLE_ERR(myThid, err, msgbuf)            CALL MNC_HANDLE_ERR(err, msgbuf, myThid)
416    
417          ENDDO          ENDDO
418        ENDDO        ENDDO
# Line 302  C         Sync the file Line 424  C         Sync the file
424                
425    
426  C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|  C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
427    CBOP 0
428    C !ROUTINE: MNC_CW_RX_R_S
429    
430    C !INTERFACE:
431        SUBROUTINE MNC_CW_RX_R_YY(        SUBROUTINE MNC_CW_RX_R_S(
432       I     myThid,       I     stype,
433       I     fbname, bi,bj,       I     fbname, bi,bj,
434       I     vtype,       I     vtype,
435       I     indu,       I     var,
436       I     var )       I     myThid )
437    
438    C     !DESCRIPTION:
439    C     A scalar version of MNC_CW_RX_R() for compilers that cannot
440    C     gracefully handle the conversion on their own.
441          
442    C     !USES:
443        implicit none        implicit none
444    
445    C     !INPUT PARAMETERS:
446          integer myThid, bi,bj
447          character*(*) stype, fbname, vtype
448          __V var
449          __V var_arr(1)
450    CEOP
451          var_arr(1) = var
452    
453          CALL MNC_CW_RX_R(stype,fbname,bi,bj,vtype, var_arr, myThid)
454    
455          RETURN
456          END
457    
458    
459    C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
460    CBOP 0
461    C !ROUTINE: MNC_CW_RX_R
462    
463    C !INTERFACE:
464          SUBROUTINE MNC_CW_RX_R(
465         I     stype,
466         I     fbname, bi,bj,
467         I     vtype,
468         I     var,
469         I     myThid )
470    
471    C     !DESCRIPTION:
472    C     This subroutine reads one variable from a file or a file group,
473    C     depending upon the tile indicies.
474          
475    C     !USES:
476          implicit none
477  #include "netcdf.inc"  #include "netcdf.inc"
478  #include "mnc_common.h"  #include "mnc_common.h"
 #include "EEPARAMS.h"  
479  #include "SIZE.h"  #include "SIZE.h"
480    #include "EEPARAMS.h"
481    #include "PARAMS.h"
482    #include "MNC_PARAMS.h"
483    
484  #define mnc_rtype_YY  C     !INPUT PARAMETERS:
485          integer myThid, bi,bj
486  C     Arguments        character*(*) stype, fbname, vtype
       integer myThid, bi,bj, indu  
       character*(*) fbname, vtype  
487        __V var(*)        __V var(*)
488    CEOP
489    
490  C     Functions  C     !LOCAL VARIABLES:
491        integer IFNBLNK, ILNBLNK        integer i,k, nvf,nvl, n1,n2, igrid, ntot, indu
   
 C     Local Variables  
       integer i,k, nvf,nvl, n1,n2, igrid, ntot  
492        integer bis,bie, bjs,bje, uniq_tnum, nfname, fid, idv        integer bis,bie, bjs,bje, uniq_tnum, nfname, fid, idv
493        integer ndim, indf, err, lbi,lbj, bidim,bjdim, unlim_sz, kr        integer ndim, indf, err, lbi,lbj, bidim,bjdim, unlim_sz, kr
494        integer ind_fv_ids, ind_vt, ierr, atype, alen        integer ind_fv_ids, ind_vt, ierr, atype, alen
495        integer f_sNx,f_sNy, ires        integer f_sNx,f_sNy, npath
496        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)
497        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
498        character*(MAX_LEN_MBUF) msgbuf        character*(MAX_LEN_MBUF) msgbuf
499        character*(MNC_MAX_CHAR) fname        character*(MNC_MAX_CHAR) fname
500          character*(MNC_MAX_CHAR) path_fname
501          integer indfg, fg1,fg2
502          REAL*8  resh_d( sNx + 2*OLx + sNy + 2*OLy )
503          REAL*4  resh_r( sNx + 2*OLx + sNy + 2*OLy )
504          INTEGER resh_i( sNx + 2*OLx + sNy + 2*OLy )
505    
506  C     Temporary storage for the simultaneous type conversion and  C     Functions
507  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  
508    
509  C     Only do I/O if I am the master thread  C     Only do I/O if I am the master thread
510        _BEGIN_MASTER( myThid )        _BEGIN_MASTER( myThid )
511    
512    C     Get the current index for the unlimited dimension from the file
513    C     group (or base) name
514          fg1 = IFNBLNK(fbname)
515          fg2 = ILNBLNK(fbname)
516          CALL MNC_GET_IND(MNC_MAX_ID, fbname, mnc_cw_fgnm, indfg, myThid)
517          IF (indfg .LT. 1) THEN
518            write(msgbuf,'(3a)')
519         &       'MNC_CW_RX_W ERROR: file group name ''',
520         &       fbname(fg1:fg2), ''' is not defined'
521            CALL print_error(msgbuf, mythid)
522            STOP 'ABNORMAL END: S/R MNC_CW_RX_W'
523          ENDIF
524          indu = mnc_cw_fgud(indfg)
525    
526  C     Check that the Variable Type exists  C     Check that the Variable Type exists
527        nvf = IFNBLNK(vtype)        nvf = IFNBLNK(vtype)
528        nvl = ILNBLNK(vtype)        nvl = ILNBLNK(vtype)
529        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)
530        IF (ind_vt .LT. 1) THEN        IF (ind_vt .LT. 1) THEN
531          write(msgbuf,'(3a)') 'MNC_CW_RX_R_YY ERROR: vtype ''',          write(msgbuf,'(3a)') 'MNC_CW_RX_R ERROR: vtype ''',
532       &       vtype(nvf:nvl), ''' is not defined'       &       vtype(nvf:nvl), ''' is not defined'
533          CALL print_error(msgbuf, mythid)          CALL print_error(msgbuf, mythid)
534          STOP 'ABNORMAL END: S/R MNC_CW_RX_R_YY'          STOP 'ABNORMAL END: S/R MNC_CW_RX_R'
535        ENDIF        ENDIF
536        igrid = mnc_cw_vgind(ind_vt)        igrid = mnc_cw_vgind(ind_vt)
537    
# Line 388  C     Set the bi,bj indicies Line 557  C     Set the bi,bj indicies
557          DO lbi = bis,bie          DO lbi = bis,bie
558    
559  C         Create the file name  C         Create the file name
560            CALL MNC_CW_GET_TILE_NUM(myThid, lbi,lbj, uniq_tnum)            CALL MNC_CW_GET_TILE_NUM( lbi,lbj, uniq_tnum, myThid)
561            fname(1:MNC_MAX_CHAR) = mnc_blank_name(1:MNC_MAX_CHAR)            fname(1:MNC_MAX_CHAR) = mnc_blank_name(1:MNC_MAX_CHAR)
562            n1 = IFNBLNK(fbname)            n1 = IFNBLNK(fbname)
563            n2 = ILNBLNK(fbname)            n2 = ILNBLNK(fbname)
# Line 399  C         Create the file name Line 568  C         Create the file name
568            write(fname((ntot+1):(ntot+9)),'(i6.6,a3)') uniq_tnum, '.nc'            write(fname((ntot+1):(ntot+9)),'(i6.6,a3)') uniq_tnum, '.nc'
569            nfname = ntot+9            nfname = ntot+9
570    
571    C         Add the path to the file name
572              IF (mnc_use_indir) THEN
573                path_fname(1:MNC_MAX_CHAR) = mnc_blank_name(1:MNC_MAX_CHAR)
574                npath = ILNBLNK(mnc_indir_str)
575                path_fname(1:npath) = mnc_indir_str(1:npath)
576                path_fname((npath+1):(npath+nfname)) = fname(1:nfname)
577                fname(1:MNC_MAX_CHAR) = path_fname(1:MNC_MAX_CHAR)
578                nfname = npath + nfname
579              ENDIF
580    
581  C         Open the existing file  C         Open the existing file
582            CALL MNC_FILE_TRY_READ(myThid, fname, ierr, indf)            CALL MNC_FILE_TRY_READ( fname, ierr, indf, myThid)
583    
584  C         Check that the variable (VType) is defined within the file  C         Check that the variable (VType) is defined within the file
585            CALL MNC_GET_FVINDS(myThid, fname, vtype, indf, ind_fv_ids)            CALL MNC_GET_FVINDS( fname, vtype, indf, ind_fv_ids, myThid)
586            IF ((indf .LT. 1) .OR. (ind_fv_ids .LT. 1)) THEN            IF ((indf .LT. 1) .OR. (ind_fv_ids .LT. 1)) THEN
587              write(msgbuf,'(4a)') 'MNC_CW_RX_R_YY ERROR: vtype ''',              write(msgbuf,'(4a)') 'MNC_CW_RX_R ERROR: vtype ''',
588       &           vtype(nvf:nvl), ''' is not defined within file ''',       &           vtype(nvf:nvl), ''' is not defined within file ''',
589       &           fname(1:nfname)       &           fname(1:nfname)
590              CALL print_error(msgbuf, mythid)              CALL print_error(msgbuf, mythid)
591              STOP 'ABNORMAL END: S/R MNC_CW_RX_R_YY'              STOP 'ABNORMAL END: S/R MNC_CW_RX_R'
592            ENDIF            ENDIF
593            fid = mnc_f_info(indf,2)            fid = mnc_f_info(indf,2)
594            idv = mnc_fv_ids(indf,ind_fv_ids+1)            idv = mnc_fv_ids(indf,ind_fv_ids+1)
# Line 421  C         are compatible and WARN (only Line 600  C         are compatible and WARN (only
600            err = NF_INQ_ATT(fid,NF_GLOBAL, 'sNx',atype,alen)            err = NF_INQ_ATT(fid,NF_GLOBAL, 'sNx',atype,alen)
601            IF ((err .EQ. NF_NOERR) .AND. (alen .EQ. 1)) THEN            IF ((err .EQ. NF_NOERR) .AND. (alen .EQ. 1)) THEN
602              err = NF_GET_ATT_INT(fid, NF_GLOBAL, 'sNx', f_sNx)              err = NF_GET_ATT_INT(fid, NF_GLOBAL, 'sNx', f_sNx)
603              CALL MNC_HANDLE_ERR(myThid, err,              CALL MNC_HANDLE_ERR(err,
604       &           'reading attribute ''sNx'' in S/R MNC_CW_RX_R_YY')       &           'reading attribute ''sNx'' in S/R MNC_CW_RX_R',
605         &           myThid)
606            ENDIF            ENDIF
607            err = NF_INQ_ATT(fid,NF_GLOBAL, 'sNy',atype,alen)            err = NF_INQ_ATT(fid,NF_GLOBAL, 'sNy',atype,alen)
608            IF ((err .EQ. NF_NOERR) .AND. (alen .EQ. 1)) THEN            IF ((err .EQ. NF_NOERR) .AND. (alen .EQ. 1)) THEN
609              err = NF_GET_ATT_INT(fid, NF_GLOBAL, 'sNy', f_sNy)              err = NF_GET_ATT_INT(fid, NF_GLOBAL, 'sNy', f_sNy)
610              CALL MNC_HANDLE_ERR(myThid, err,              CALL MNC_HANDLE_ERR(err,
611       &           'reading attribute ''sNy'' in S/R MNC_CW_RX_R_YY')       &           'reading attribute ''sNy'' in S/R MNC_CW_RX_R',
612         &           myThid)
613            ENDIF            ENDIF
614            IF ((f_sNx .NE. sNx) .OR. (f_sNy .NE. sNy)) THEN            IF ((f_sNx .NE. sNx) .OR. (f_sNy .NE. sNy)) THEN
615              write(msgbuf,'(5a)') 'MNC_CW_RX_R_YY WARNING: the ',              write(msgbuf,'(5a)') 'MNC_CW_RX_R WARNING: the ',
616       &           'attributes ''sNx'' and ''sNy'' within the file ''',       &           'attributes ''sNx'' and ''sNy'' within the file ''',
617       &           fname(1:nfname), ''' do not exist or do not match ',       &           fname(1:nfname), ''' do not exist or do not match ',
618       &           'the current sizes within the model'       &           'the current sizes within the model'
# Line 441  C         are compatible and WARN (only Line 622  C         are compatible and WARN (only
622  C         Check that the in-memory variable and the in-file variables  C         Check that the in-memory variable and the in-file variables
623  C         are of compatible sizes  C         are of compatible sizes
624  C           ires = 1  C           ires = 1
625  C           CALL MNC_CHK_VTYP_R_NCVAR(myThid, ind_vt,  C           CALL MNC_CHK_VTYP_R_NCVAR( ind_vt,
626  C      &         indf, ind_fv_ids, indu, ires)  C      &         indf, ind_fv_ids, indu, ires)
627  C           IF (ires .LT. 0) THEN  C           IF (ires .LT. 0) THEN
628  C             write(msgbuf,'(7a)') 'MNC_CW_RX_R_YY WARNING: the sizes ',  C             write(msgbuf,'(7a)') 'MNC_CW_RX_R WARNING: the sizes ',
629  C      &           'of the in-program variable ''', vtype(nvf:nvl),  C      &           'of the in-program variable ''', vtype(nvf:nvl),
630  C      &           ''' and the corresponding variable within file ''',  C      &           ''' and the corresponding variable within file ''',
631  C      &           fname(1:nfname), ''' are not compatible -- please ',  C      &           fname(1:nfname), ''' are not compatible -- please ',
632  C      &           'check the sizes'  C      &           'check the sizes'
633  C             CALL print_error(msgbuf, mythid)  C             CALL print_error(msgbuf, mythid)
634  C             STOP 'ABNORMAL END: S/R MNC_CW_RX_R_YY'  C             STOP 'ABNORMAL END: S/R MNC_CW_RX_R'
635  C           ENDIF  C           ENDIF
636    
637  C         Check for bi,bj indicies  C         Check for bi,bj indicies
# Line 497  C               Use the indu value Line 678  C               Use the indu value
678                  udo(i) = indu - 1                  udo(i) = indu - 1
679                ELSEIF (indu .EQ. -1) THEN                ELSEIF (indu .EQ. -1) THEN
680  C               Append one to the current unlimited dim size  C               Append one to the current unlimited dim size
681                  CALL MNC_DIM_UNLIM_SIZE(myThid, fname, unlim_sz)                  CALL MNC_DIM_UNLIM_SIZE( fname, unlim_sz, myThid)
682                  udo(i) = unlim_sz                  udo(i) = unlim_sz
683                ELSE                ELSE
684  C               Use the current unlimited dim size  C               Use the current unlimited dim size
685                  CALL MNC_DIM_UNLIM_SIZE(myThid, fname, unlim_sz)                  CALL MNC_DIM_UNLIM_SIZE( fname, unlim_sz, myThid)
686                  udo(i) = unlim_sz - 1                  udo(i) = unlim_sz - 1
687                ENDIF                ENDIF
688              ENDIF              ENDIF
# Line 519  C     DO i = 9,1,-1 Line 700  C     DO i = 9,1,-1
700  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)
701  C     ENDDO  C     ENDDO
702                        
703            CALL MNC_FILE_ENDDEF(myThid,fname)            CALL MNC_FILE_ENDDEF(fname, myThid)
704    
705            write(msgbuf,'(5a)') 'reading variable type ''',            write(msgbuf,'(5a)') 'reading variable type ''',
706       &         vtype(nvf:nvl), ''' within file ''',       &         vtype(nvf:nvl), ''' within file ''',
# Line 551  C         Read the variable one vector a Line 732  C         Read the variable one vector a
732                        vstart(2) = udo(2) + j2 - s(2) + 1                        vstart(2) = udo(2) + j2 - s(2) + 1
733                        vcount(2) = 1                        vcount(2) = 1
734    
735          kr = 0
736        vstart(1) = udo(1) + 1        vstart(1) = udo(1) + 1
737        vcount(1) = e(1) - s(1) + 1        vcount(1) = e(1) - s(1) + 1
738                
739  #ifdef  mnc_rtype_D        IF (stype(1:1) .EQ. 'D') THEN
740        err = NF_GET_VARA_DOUBLE(fid, idv, vstart, vcount, resh)          err = NF_GET_VARA_DOUBLE(fid, idv, vstart, vcount, resh_d)
741  #endif          CALL MNC_HANDLE_ERR(err, msgbuf, myThid)
742  #ifdef  mnc_rtype_R          DO j1 = s(1),e(1)
743        err = NF_GET_VARA_REAL(fid, idv, vstart, vcount, resh)            k1 = k2 + j1
744  #endif            kr = kr + 1
745  #ifdef  mnc_rtype_I            var(k1) = resh_d(kr)
746        err = NF_GET_VARA_INT(fid, idv, vstart, vcount, resh)          ENDDO
747  #endif        ENDIF
748          IF (stype(1:1) .EQ. 'R') THEN
749        CALL MNC_HANDLE_ERR(myThid, err, msgbuf)          err = NF_GET_VARA_REAL(fid, idv, vstart, vcount, resh_r)
750            CALL MNC_HANDLE_ERR(err, msgbuf, myThid)
751            DO j1 = s(1),e(1)
752              k1 = k2 + j1
753              kr = kr + 1
754              var(k1) = resh_r(kr)
755            ENDDO
756          ENDIF
757          IF (stype(1:1) .EQ. 'I') THEN
758            err = NF_GET_VARA_INT(fid, idv, vstart, vcount, resh_i)
759            CALL MNC_HANDLE_ERR(err, msgbuf, myThid)
760            DO j1 = s(1),e(1)
761              k1 = k2 + j1
762              kr = kr + 1
763              var(k1) = resh_i(kr)
764            ENDDO
765          ENDIF
766    
       kr = 0  
       DO j1 = s(1),e(1)  
         k1 = k2 + j1  
         kr = kr + 1  
         var(k1) = resh(kr)  
       ENDDO  
767                
768    
769                      ENDDO                      ENDDO
# Line 582  C         Read the variable one vector a Line 774  C         Read the variable one vector a
774            ENDDO            ENDDO
775    
776  C         Close the file  C         Close the file
777            CALL MNC_FILE_CLOSE(myThid, fname)            CALL MNC_FILE_CLOSE(fname, myThid)
778    
779  C         End the lbj,lbi loops  C         End the lbj,lbi loops
780          ENDDO          ENDDO

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

  ViewVC Help
Powered by ViewVC 1.1.22