/[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.25 by edhill, Sun Nov 14 03:34:35 2004 UTC revision 1.30 by edhill, Fri Jun 24 19:43:52 2005 UTC
# Line 207  C         Add the path to the file name Line 207  C         Add the path to the file name
207            ENDIF            ENDIF
208    
209  C         Append to an existing or create a new file  C         Append to an existing or create a new file
210            CALL MNC_CW_FILE_AORC(fname, indf, myThid)            CALL MNC_CW_FILE_AORC(fname,indf, lbi,lbj,uniq_tnum, myThid)
211            fid = mnc_f_info(indf,2)            fid = mnc_f_info(indf,2)
212    
213  #ifdef HAVE_STAT  #ifdef HAVE_STAT
214            IF ((mnc_cw_fgig(indfg) .EQ. 1)            IF ((mnc_cw_fgig(indfg) .EQ. 1)
215       &         .AND. (fs_isdone .EQ. 0)) THEN       &         .AND. (fs_isdone .EQ. 0)) THEN
216  C           Decide whether to append to the existing or create a new file  C           Decide whether to append to the existing or create a new
217  C           based on the byte count per unlimited dimension  C           file based on the byte count per unlimited dimension
218              ncenc = 70              ncenc = 70
219              cenc(1:26)  = 'abcdefghijklmnopqrstuvwxyz'              cenc(1:26)  = 'abcdefghijklmnopqrstuvwxyz'
220              cenc(27:52) = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'              cenc(27:52) = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
# Line 263  C         local copy of them Line 263  C         local copy of them
263              ELSE              ELSE
264                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
265              ENDIF              ENDIF
266              CALL MNC_DIM_INIT(fname,  
267       &           mnc_cw_dn(i,igrid), dimnc(i), myThid)  C           Add the coordinate variables
268                CALL MNC_DIM_INIT_ALL_CV(fname,
269         &           mnc_cw_dn(i,igrid), dimnc(i), 'Y', lbi,lbj, myThid)
270    
271            ENDDO            ENDDO
272    
273  C         Ensure that the "grid" is defined  C         Ensure that the "grid" is defined
# Line 373  C         Check the offsets Line 376  C         Check the offsets
376              ENDIF              ENDIF
377            ENDDO            ENDDO
378    
 C         Add the global attributes  
           CALL MNC_CW_SET_GATTR( fname, lbi,lbj, uniq_tnum, myThid)  
   
379  C         Add the per-variable attributes  C         Add the per-variable attributes
380            DO i = 1,mnc_cw_vnat(1,indv)            DO i = 1,mnc_cw_vnat(1,indv)
381              CALL MNC_VAR_ADD_ATTR_STR( fname, vtype,              CALL MNC_VAR_ADD_ATTR_STR( fname, vtype,
# Line 459  C         Write the variable one vector Line 459  C         Write the variable one vector
459          DO j1 = s(1),e(1)          DO j1 = s(1),e(1)
460            k1 = k2 + j1            k1 = k2 + j1
461            kr = kr + 1            kr = kr + 1
462            resh_i(kr) = var(k1)            resh_i(kr) = MNC2I( var(k1) )
463          ENDDO          ENDDO
464          err = NF_PUT_VARA_INT(fid, idv, vstart, vcount, resh_i)          err = NF_PUT_VARA_INT(fid, idv, vstart, vcount, resh_i)
465        ENDIF        ENDIF
# Line 556  CEOP Line 556  CEOP
556  C     !LOCAL VARIABLES:  C     !LOCAL VARIABLES:
557        integer i,k, nvf,nvl, n1,n2, igrid, ntot, indu        integer i,k, nvf,nvl, n1,n2, igrid, ntot, indu
558        integer bis,bie, bjs,bje, uniq_tnum, nfname, fid, idv        integer bis,bie, bjs,bje, uniq_tnum, nfname, fid, idv
559        integer ndim, indf, err, lbi,lbj, bidim,bjdim, unlim_sz, kr        integer ndim, err, lbi,lbj, bidim,bjdim, unlim_sz, kr
560        integer ind_fv_ids, ind_vt, ierr, atype, alen        integer ind_vt, npath, unlid
561        integer f_sNx,f_sNy, npath  C     integer f_sNx,f_sNy, alen, atype, ind_fv_ids, ierr, indf
562        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)
563        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
564        character*(MAX_LEN_MBUF) msgbuf        character*(MAX_LEN_MBUF) msgbuf
565        character*(MNC_MAX_CHAR) fname        character*(MNC_MAX_CHAR) fname
566          character*(MNC_MAX_CHAR) fname_zs
567        character*(MNC_MAX_CHAR) path_fname        character*(MNC_MAX_CHAR) path_fname
568        integer indfg, fg1,fg2        integer indfg, fg1,fg2
569        REAL*8  resh_d( MNC_MAX_BUFF )        REAL*8  resh_d( MNC_MAX_BUFF )
# Line 644  C         Add the path to the file name Line 645  C         Add the path to the file name
645              nfname = npath + nfname              nfname = npath + nfname
646            ENDIF            ENDIF
647    
648  C         Open the existing file            WRITE(fname_zs,'(2a,i4.4,a1,i6.6,a3)')
649            CALL MNC_FILE_TRY_READ( fname, ierr, indf, myThid)       &         mnc_indir_str(1:npath), fbname(n1:n2),
650         &         0, '.', uniq_tnum, '.nc'
651  C         Check that the variable (VType) is defined within the file  
652            CALL MNC_GET_FVINDS( fname, vtype, indf, ind_fv_ids, myThid)  C         The steps are:
653            IF ((indf .LT. 1) .OR. (ind_fv_ids .LT. 1)) THEN  C         (1) open the file in a READ-ONLY mode,
654              write(msgbuf,'(4a)') 'MNC_CW_RX_R ERROR: vtype ''',  C         (2) get the var id for the current variable,
655       &           vtype(nvf:nvl), ''' is not defined within file ''',  C         (3) read the data, and then
656       &           fname(1:nfname)  C         (4) close the file--theres no need to keep it open!
657              CALL print_error(msgbuf, mythid)  
658              STOP 'ABNORMAL END: S/R MNC_CW_RX_R'            write(msgbuf,'(4a)') 'MNC_CW_RX_R: cannot open',
659         &         ' file ''', fname(1:nfname), ''' in read-only mode'
660              err = NF_OPEN(fname, NF_NOWRITE, fid)
661              IF ( err .NE. NF_NOERR ) THEN
662    C           If the initial open fails, try again using a name with a
663    C           zero sequence number inserted
664                err = NF_OPEN(fname_zs, NF_NOWRITE, fid)
665            ENDIF            ENDIF
666            fid = mnc_f_info(indf,2)            CALL MNC_HANDLE_ERR(err, msgbuf, myThid)
667            idv = mnc_fv_ids(indf,ind_fv_ids+1)  
668              write(msgbuf,'(6a)')
669         &         'MNC_CW_RX_R: cannot get id for variable ''',
670         &         vtype(nvf:nvl), '''in file ''', fname(1:nfname), ''''
671              err = NF_INQ_VARID(fid, vtype, idv)
672              CALL MNC_HANDLE_ERR(err, msgbuf, myThid)
673    
674  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
675  C         are compatible and WARN (only warn) if not  C         are compatible and WARN (only warn) if not
676            f_sNx = -1  C           f_sNx = -1
677            f_sNy = -1  C           f_sNy = -1
678            err = NF_INQ_ATT(fid,NF_GLOBAL, 'sNx',atype,alen)  C           err = NF_INQ_ATT(fid,NF_GLOBAL, 'sNx',atype,alen)
679            IF ((err .EQ. NF_NOERR) .AND. (alen .EQ. 1)) THEN  C           IF ((err .EQ. NF_NOERR) .AND. (alen .EQ. 1)) THEN
680              err = NF_GET_ATT_INT(fid, NF_GLOBAL, 'sNx', f_sNx)  C             err = NF_GET_ATT_INT(fid, NF_GLOBAL, 'sNx', f_sNx)
681              CALL MNC_HANDLE_ERR(err,  C             CALL MNC_HANDLE_ERR(err,
682       &           'reading attribute ''sNx'' in S/R MNC_CW_RX_R',  C      &           'reading attribute ''sNx'' in S/R MNC_CW_RX_R',
683       &           myThid)  C      &           myThid)
684            ENDIF  C           ENDIF
685            err = NF_INQ_ATT(fid,NF_GLOBAL, 'sNy',atype,alen)  C           err = NF_INQ_ATT(fid,NF_GLOBAL, 'sNy',atype,alen)
686            IF ((err .EQ. NF_NOERR) .AND. (alen .EQ. 1)) THEN  C           IF ((err .EQ. NF_NOERR) .AND. (alen .EQ. 1)) THEN
687              err = NF_GET_ATT_INT(fid, NF_GLOBAL, 'sNy', f_sNy)  C             err = NF_GET_ATT_INT(fid, NF_GLOBAL, 'sNy', f_sNy)
688              CALL MNC_HANDLE_ERR(err,  C             CALL MNC_HANDLE_ERR(err,
689       &           'reading attribute ''sNy'' in S/R MNC_CW_RX_R',  C      &           'reading attribute ''sNy'' in S/R MNC_CW_RX_R',
690       &           myThid)  C      &           myThid)
691            ENDIF  C           ENDIF
692            IF ((f_sNx .NE. sNx) .OR. (f_sNy .NE. sNy)) THEN  C           IF ((f_sNx .NE. sNx) .OR. (f_sNy .NE. sNy)) THEN
693              write(msgbuf,'(5a)') 'MNC_CW_RX_R WARNING: the ',  C             write(msgbuf,'(5a)') 'MNC_CW_RX_R WARNING: the ',
694       &           'attributes ''sNx'' and ''sNy'' within the file ''',  C      &           'attributes ''sNx'' and ''sNy'' within the file ''',
695       &           fname(1:nfname), ''' do not exist or do not match ',  C      &           fname(1:nfname), ''' do not exist or do not match ',
696       &           'the current sizes within the model'  C      &           'the current sizes within the model'
697              CALL print_error(msgbuf, mythid)  C             CALL print_error(msgbuf, mythid)
698            ENDIF  C           ENDIF
699    
700  C         Check that the in-memory variable and the in-file variables  C         Check that the in-memory variable and the in-file variables
701  C         are of compatible sizes  C         are of compatible sizes
# Line 742  C           Check for the unlimited dime Line 754  C           Check for the unlimited dime
754                IF (indu .GT. 0) THEN                IF (indu .GT. 0) THEN
755  C               Use the indu value  C               Use the indu value
756                  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( fname, unlim_sz, myThid)  
                 udo(i) = unlim_sz  
757                ELSE                ELSE
758  C               Use the current unlimited dim size  C               We need the current unlim dim size
759                  CALL MNC_DIM_UNLIM_SIZE( fname, unlim_sz, myThid)                  write(msgbuf,'(5a)') 'MNC_CW_RX_R: getting the ',
760                  udo(i) = unlim_sz - 1       &               'unlim dim id within file ''',
761         &               fname(1:nfname), ''''
762                    err = NF_INQ_UNLIMDIM(fid, unlid)
763                    CALL MNC_HANDLE_ERR(err, msgbuf, myThid)
764                    write(msgbuf,'(5a)') 'MNC_CW_RX_R: getting the ',
765         &               'unlim dim size within file ''',
766         &               fname(1:nfname), ''''
767                    err = NF_INQ_DIMLEN(fid, unlid, unlim_sz)
768                    CALL MNC_HANDLE_ERR(err, msgbuf, myThid)
769                    udo(i) = unlim_sz
770                ENDIF                ENDIF
771              ENDIF              ENDIF
772            ENDDO            ENDDO
# Line 766  C     DO i = 9,1,-1 Line 783  C     DO i = 9,1,-1
783  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)
784  C     ENDDO  C     ENDDO
785                        
           CALL MNC_FILE_ENDDEF(fname, myThid)  
   
786            write(msgbuf,'(5a)') 'reading variable type ''',            write(msgbuf,'(5a)') 'reading variable type ''',
787       &         vtype(nvf:nvl), ''' within file ''',       &         vtype(nvf:nvl), ''' within file ''',
788       &         fname(1:nfname), ''''       &         fname(1:nfname), ''''
# Line 816  C         Read the variable one vector a Line 831  C         Read the variable one vector a
831          DO j1 = s(1),e(1)          DO j1 = s(1),e(1)
832            k1 = k2 + j1            k1 = k2 + j1
833            kr = kr + 1            kr = kr + 1
834            var(k1) = resh_d(kr)            var(k1) = MNCI2( resh_d(kr) )
835          ENDDO          ENDDO
836        ENDIF        ENDIF
837        IF (stype(1:1) .EQ. 'R') THEN        IF (stype(1:1) .EQ. 'R') THEN
# Line 825  C         Read the variable one vector a Line 840  C         Read the variable one vector a
840          DO j1 = s(1),e(1)          DO j1 = s(1),e(1)
841            k1 = k2 + j1            k1 = k2 + j1
842            kr = kr + 1            kr = kr + 1
843            var(k1) = resh_r(kr)            var(k1) = MNCI2( resh_r(kr) )
844          ENDDO          ENDDO
845        ENDIF        ENDIF
846        IF (stype(1:1) .EQ. 'I') THEN        IF (stype(1:1) .EQ. 'I') THEN
# Line 838  C         Read the variable one vector a Line 853  C         Read the variable one vector a
853          ENDDO          ENDDO
854        ENDIF        ENDIF
855    
         
856    
857                      ENDDO                      ENDDO
858                    ENDDO                    ENDDO
# Line 848  C         Read the variable one vector a Line 862  C         Read the variable one vector a
862            ENDDO            ENDDO
863    
864  C         Close the file  C         Close the file
865            CALL MNC_FILE_CLOSE(fname, myThid)  C         CALL MNC_FILE_CLOSE(fname, myThid)
866              err = NF_CLOSE(fid)
867              write(msgbuf,'(3a)') 'MNC_CW_RX_R:  cannot close file ''',
868         &         fname(1:nfname), ''''
869              CALL MNC_HANDLE_ERR(err, msgbuf, myThid)
870    
871    
872  C         End the lbj,lbi loops  C         End the lbj,lbi loops
873          ENDDO          ENDDO

Legend:
Removed from v.1.25  
changed lines
  Added in v.1.30

  ViewVC Help
Powered by ViewVC 1.1.22