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 |
215 |
ENDIF |
ENDIF |
216 |
|
|
217 |
C Append to an existing or create a new file |
C Append to an existing or create a new file |
218 |
CALL MNC_CW_FILE_AORC(fname, indf, myThid) |
CALL MNC_CW_FILE_AORC(fname,indf, lbi,lbj,uniq_tnum, myThid) |
219 |
fid = mnc_f_info(indf,2) |
fid = mnc_f_info(indf,2) |
220 |
|
|
221 |
#ifdef HAVE_STAT |
#ifdef HAVE_STAT |
222 |
IF ((mnc_cw_fgig(indfg) .EQ. 1) |
IF ((mnc_cw_fgig(indfg) .EQ. 1) |
223 |
& .AND. (fs_isdone .EQ. 0)) THEN |
& .AND. (fs_isdone .EQ. 0)) THEN |
224 |
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 |
225 |
C based on the byte count per unlimited dimension |
C file based on the byte count per unlimited dimension |
226 |
ncenc = 70 |
ncenc = 70 |
227 |
cenc(1:26) = 'abcdefghijklmnopqrstuvwxyz' |
cenc(1:26) = 'abcdefghijklmnopqrstuvwxyz' |
228 |
cenc(27:52) = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
cenc(27:52) = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
246 |
fsnu = (1.0 _d 0 + 1.0 _d 0 / DBLE(unlim_sz)) |
fsnu = (1.0 _d 0 + 1.0 _d 0 / DBLE(unlim_sz)) |
247 |
& * DBLE(nbytes) |
& * DBLE(nbytes) |
248 |
IF (fsnu .GT. mnc_max_fsize) THEN |
IF (fsnu .GT. mnc_max_fsize) THEN |
249 |
|
C Delete the now-full fname from the lookup tables since |
250 |
|
C we are all done writing to it. |
251 |
|
CALL MNC_FILE_CLOSE(fname, myThid) |
252 |
iseq = iseq + 1 |
iseq = iseq + 1 |
253 |
indu = 1 |
indu = 1 |
254 |
mnc_cw_fgud(indfg) = 1 |
mnc_cw_fgud(indfg) = 1 |
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 |
274 |
CALL MNC_DIM_INIT(fname, |
|
275 |
& mnc_cw_dn(i,igrid), dimnc(i), myThid) |
C Add the coordinate variables |
276 |
|
CALL MNC_DIM_INIT_ALL_CV(fname, |
277 |
|
& mnc_cw_dn(i,igrid), dimnc(i), 'Y', lbi,lbj, myThid) |
278 |
|
|
279 |
ENDDO |
ENDDO |
280 |
|
|
281 |
C Ensure that the "grid" is defined |
C Ensure that the "grid" is defined |
384 |
ENDIF |
ENDIF |
385 |
ENDDO |
ENDDO |
386 |
|
|
|
C Add the global attributes |
|
|
CALL MNC_CW_SET_GATTR( fname, lbi,lbj, uniq_tnum, myThid) |
|
|
|
|
387 |
C Add the per-variable attributes |
C Add the per-variable attributes |
388 |
DO i = 1,mnc_cw_vnat(1,indv) |
DO i = 1,mnc_cw_vnat(1,indv) |
389 |
CALL MNC_VAR_ADD_ATTR_STR( fname, vtype, |
CALL MNC_VAR_ADD_ATTR_STR( fname, vtype, |
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 |
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 ) |
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 |
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 |
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), '''' |
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 |
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 |
861 |
ENDDO |
ENDDO |
862 |
ENDIF |
ENDIF |
863 |
|
|
|
|
|
864 |
|
|
865 |
ENDDO |
ENDDO |
866 |
ENDDO |
ENDDO |
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 |