/[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.27 by edhill, Fri Dec 17 21:28:25 2004 UTC revision 1.31 by edhill, Mon Jun 27 20:19:52 2005 UTC
# Line 192  C         Create the file name Line 192  C         Create the file name
192            fname(1:ntot) = fbname(n1:n2)            fname(1:ntot) = fbname(n1:n2)
193            ntot = ntot + 1            ntot = ntot + 1
194            fname(ntot:ntot) = '.'            fname(ntot:ntot) = '.'
195            write(fname((ntot+1):(ntot+14)),'(i4.4,a1,i6.6,a3)')            IF ( mnc_use_name_ni0 ) THEN
196       &         iseq,'.',uniq_tnum, '.nc'              write(fname((ntot+1):(ntot+17)),'(i10.10,a1,i6.6)')
197            nfname = ntot + 14       &           nIter0,'.',uniq_tnum
198                write(fname((ntot+18):(ntot+25)),'(a1,i4.4,a3)')
199         &           '.', iseq, '.nc'
200                nfname = ntot + 25
201              ELSE
202                write(fname((ntot+1):(ntot+14)),'(i4.4,a1,i6.6,a3)')
203         &           iseq,'.',uniq_tnum, '.nc'
204                nfname = ntot + 14
205              ENDIF
206    
207  C         Add the path to the file name  C         Add the path to the file name
208            IF (mnc_use_outdir) THEN            IF (mnc_use_outdir) THEN
# Line 263  C         local copy of them Line 271  C         local copy of them
271              ELSE              ELSE
272                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
273              ENDIF              ENDIF
 C           CALL MNC_DIM_INIT(fname,  
 C           &           mnc_cw_dn(i,igrid), dimnc(i), myThid)  
274    
275  C           Add the coordinate variables  C           Add the coordinate variables
276              CALL MNC_DIM_INIT_ALL_CV(fname,              CALL MNC_DIM_INIT_ALL_CV(fname,
# Line 461  C         Write the variable one vector Line 467  C         Write the variable one vector
467          DO j1 = s(1),e(1)          DO j1 = s(1),e(1)
468            k1 = k2 + j1            k1 = k2 + j1
469            kr = kr + 1            kr = kr + 1
470            resh_i(kr) = var(k1)            resh_i(kr) = MNC2I( var(k1) )
471          ENDDO          ENDDO
472          err = NF_PUT_VARA_INT(fid, idv, vstart, vcount, resh_i)          err = NF_PUT_VARA_INT(fid, idv, vstart, vcount, resh_i)
473        ENDIF        ENDIF
# Line 558  CEOP Line 564  CEOP
564  C     !LOCAL VARIABLES:  C     !LOCAL VARIABLES:
565        integer i,k, nvf,nvl, n1,n2, igrid, ntot, indu        integer i,k, nvf,nvl, n1,n2, igrid, ntot, indu
566        integer bis,bie, bjs,bje, uniq_tnum, nfname, fid, idv        integer bis,bie, bjs,bje, uniq_tnum, nfname, fid, idv
567        integer ndim, indf, err, lbi,lbj, bidim,bjdim, unlim_sz, kr        integer ndim, err, lbi,lbj, bidim,bjdim, unlim_sz, kr
568        integer ind_fv_ids, ind_vt, ierr, atype, alen        integer ind_vt, npath, unlid
569        integer f_sNx,f_sNy, npath  C     integer f_sNx,f_sNy, alen, atype, ind_fv_ids, ierr, indf
570        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)
571        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
572        character*(MAX_LEN_MBUF) msgbuf        character*(MAX_LEN_MBUF) msgbuf
573        character*(MNC_MAX_CHAR) fname        character*(MNC_MAX_CHAR) fname
574          character*(MNC_MAX_CHAR) fname_zs
575        character*(MNC_MAX_CHAR) path_fname        character*(MNC_MAX_CHAR) path_fname
576        integer indfg, fg1,fg2        integer indfg, fg1,fg2
577        REAL*8  resh_d( MNC_MAX_BUFF )        REAL*8  resh_d( MNC_MAX_BUFF )
# Line 646  C         Add the path to the file name Line 653  C         Add the path to the file name
653              nfname = npath + nfname              nfname = npath + nfname
654            ENDIF            ENDIF
655    
656  C         Open the existing file            WRITE(fname_zs,'(2a,i4.4,a1,i6.6,a3)')
657            CALL MNC_FILE_TRY_READ( fname, ierr, indf, myThid)       &         mnc_indir_str(1:npath), fbname(n1:n2),
658         &         0, '.', uniq_tnum, '.nc'
659  C         Check that the variable (VType) is defined within the file  
660            CALL MNC_GET_FVINDS( fname, vtype, indf, ind_fv_ids, myThid)  C         The steps are:
661            IF ((indf .LT. 1) .OR. (ind_fv_ids .LT. 1)) THEN  C         (1) open the file in a READ-ONLY mode,
662              write(msgbuf,'(4a)') 'MNC_CW_RX_R ERROR: vtype ''',  C         (2) get the var id for the current variable,
663       &           vtype(nvf:nvl), ''' is not defined within file ''',  C         (3) read the data, and then
664       &           fname(1:nfname)  C         (4) close the file--theres no need to keep it open!
665              CALL print_error(msgbuf, mythid)  
666              STOP 'ABNORMAL END: S/R MNC_CW_RX_R'            write(msgbuf,'(4a)') 'MNC_CW_RX_R: cannot open',
667         &         ' file ''', fname(1:nfname), ''' in read-only mode'
668              err = NF_OPEN(fname, NF_NOWRITE, fid)
669              IF ( err .NE. NF_NOERR ) THEN
670    C           If the initial open fails, try again using a name with a
671    C           zero sequence number inserted
672                err = NF_OPEN(fname_zs, NF_NOWRITE, fid)
673            ENDIF            ENDIF
674            fid = mnc_f_info(indf,2)            CALL MNC_HANDLE_ERR(err, msgbuf, myThid)
675            idv = mnc_fv_ids(indf,ind_fv_ids+1)  
676              write(msgbuf,'(6a)')
677         &         'MNC_CW_RX_R: cannot get id for variable ''',
678         &         vtype(nvf:nvl), '''in file ''', fname(1:nfname), ''''
679              err = NF_INQ_VARID(fid, vtype, idv)
680              CALL MNC_HANDLE_ERR(err, msgbuf, myThid)
681    
682  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
683  C         are compatible and WARN (only warn) if not  C         are compatible and WARN (only warn) if not
684            f_sNx = -1  C           f_sNx = -1
685            f_sNy = -1  C           f_sNy = -1
686            err = NF_INQ_ATT(fid,NF_GLOBAL, 'sNx',atype,alen)  C           err = NF_INQ_ATT(fid,NF_GLOBAL, 'sNx',atype,alen)
687            IF ((err .EQ. NF_NOERR) .AND. (alen .EQ. 1)) THEN  C           IF ((err .EQ. NF_NOERR) .AND. (alen .EQ. 1)) THEN
688              err = NF_GET_ATT_INT(fid, NF_GLOBAL, 'sNx', f_sNx)  C             err = NF_GET_ATT_INT(fid, NF_GLOBAL, 'sNx', f_sNx)
689              CALL MNC_HANDLE_ERR(err,  C             CALL MNC_HANDLE_ERR(err,
690       &           'reading attribute ''sNx'' in S/R MNC_CW_RX_R',  C      &           'reading attribute ''sNx'' in S/R MNC_CW_RX_R',
691       &           myThid)  C      &           myThid)
692            ENDIF  C           ENDIF
693            err = NF_INQ_ATT(fid,NF_GLOBAL, 'sNy',atype,alen)  C           err = NF_INQ_ATT(fid,NF_GLOBAL, 'sNy',atype,alen)
694            IF ((err .EQ. NF_NOERR) .AND. (alen .EQ. 1)) THEN  C           IF ((err .EQ. NF_NOERR) .AND. (alen .EQ. 1)) THEN
695              err = NF_GET_ATT_INT(fid, NF_GLOBAL, 'sNy', f_sNy)  C             err = NF_GET_ATT_INT(fid, NF_GLOBAL, 'sNy', f_sNy)
696              CALL MNC_HANDLE_ERR(err,  C             CALL MNC_HANDLE_ERR(err,
697       &           'reading attribute ''sNy'' in S/R MNC_CW_RX_R',  C      &           'reading attribute ''sNy'' in S/R MNC_CW_RX_R',
698       &           myThid)  C      &           myThid)
699            ENDIF  C           ENDIF
700            IF ((f_sNx .NE. sNx) .OR. (f_sNy .NE. sNy)) THEN  C           IF ((f_sNx .NE. sNx) .OR. (f_sNy .NE. sNy)) THEN
701              write(msgbuf,'(5a)') 'MNC_CW_RX_R WARNING: the ',  C             write(msgbuf,'(5a)') 'MNC_CW_RX_R WARNING: the ',
702       &           'attributes ''sNx'' and ''sNy'' within the file ''',  C      &           'attributes ''sNx'' and ''sNy'' within the file ''',
703       &           fname(1:nfname), ''' do not exist or do not match ',  C      &           fname(1:nfname), ''' do not exist or do not match ',
704       &           'the current sizes within the model'  C      &           'the current sizes within the model'
705              CALL print_error(msgbuf, mythid)  C             CALL print_error(msgbuf, mythid)
706            ENDIF  C           ENDIF
707    
708  C         Check that the in-memory variable and the in-file variables  C         Check that the in-memory variable and the in-file variables
709  C         are of compatible sizes  C         are of compatible sizes
# Line 744  C           Check for the unlimited dime Line 762  C           Check for the unlimited dime
762                IF (indu .GT. 0) THEN                IF (indu .GT. 0) THEN
763  C               Use the indu value  C               Use the indu value
764                  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  
765                ELSE                ELSE
766  C               Use the current unlimited dim size  C               We need the current unlim dim size
767                  CALL MNC_DIM_UNLIM_SIZE( fname, unlim_sz, myThid)                  write(msgbuf,'(5a)') 'MNC_CW_RX_R: getting the ',
768                  udo(i) = unlim_sz - 1       &               'unlim dim id within file ''',
769         &               fname(1:nfname), ''''
770                    err = NF_INQ_UNLIMDIM(fid, unlid)
771                    CALL MNC_HANDLE_ERR(err, msgbuf, myThid)
772                    write(msgbuf,'(5a)') 'MNC_CW_RX_R: getting the ',
773         &               'unlim dim size within file ''',
774         &               fname(1:nfname), ''''
775                    err = NF_INQ_DIMLEN(fid, unlid, unlim_sz)
776                    CALL MNC_HANDLE_ERR(err, msgbuf, myThid)
777                    udo(i) = unlim_sz
778                ENDIF                ENDIF
779              ENDIF              ENDIF
780            ENDDO            ENDDO
# Line 768  C     DO i = 9,1,-1 Line 791  C     DO i = 9,1,-1
791  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)
792  C     ENDDO  C     ENDDO
793                        
           CALL MNC_FILE_ENDDEF(fname, myThid)  
   
794            write(msgbuf,'(5a)') 'reading variable type ''',            write(msgbuf,'(5a)') 'reading variable type ''',
795       &         vtype(nvf:nvl), ''' within file ''',       &         vtype(nvf:nvl), ''' within file ''',
796       &         fname(1:nfname), ''''       &         fname(1:nfname), ''''
# Line 818  C         Read the variable one vector a Line 839  C         Read the variable one vector a
839          DO j1 = s(1),e(1)          DO j1 = s(1),e(1)
840            k1 = k2 + j1            k1 = k2 + j1
841            kr = kr + 1            kr = kr + 1
842            var(k1) = resh_d(kr)            var(k1) = MNCI2( resh_d(kr) )
843          ENDDO          ENDDO
844        ENDIF        ENDIF
845        IF (stype(1:1) .EQ. 'R') THEN        IF (stype(1:1) .EQ. 'R') THEN
# Line 827  C         Read the variable one vector a Line 848  C         Read the variable one vector a
848          DO j1 = s(1),e(1)          DO j1 = s(1),e(1)
849            k1 = k2 + j1            k1 = k2 + j1
850            kr = kr + 1            kr = kr + 1
851            var(k1) = resh_r(kr)            var(k1) = MNCI2( resh_r(kr) )
852          ENDDO          ENDDO
853        ENDIF        ENDIF
854        IF (stype(1:1) .EQ. 'I') THEN        IF (stype(1:1) .EQ. 'I') THEN
# Line 840  C         Read the variable one vector a Line 861  C         Read the variable one vector a
861          ENDDO          ENDDO
862        ENDIF        ENDIF
863    
         
864    
865                      ENDDO                      ENDDO
866                    ENDDO                    ENDDO
# Line 850  C         Read the variable one vector a Line 870  C         Read the variable one vector a
870            ENDDO            ENDDO
871    
872  C         Close the file  C         Close the file
873            CALL MNC_FILE_CLOSE(fname, myThid)  C         CALL MNC_FILE_CLOSE(fname, myThid)
874              err = NF_CLOSE(fid)
875              write(msgbuf,'(3a)') 'MNC_CW_RX_R:  cannot close file ''',
876         &         fname(1:nfname), ''''
877              CALL MNC_HANDLE_ERR(err, msgbuf, myThid)
878    
879    
880  C         End the lbj,lbi loops  C         End the lbj,lbi loops
881          ENDDO          ENDDO

Legend:
Removed from v.1.27  
changed lines
  Added in v.1.31

  ViewVC Help
Powered by ViewVC 1.1.22