93 |
#include "netcdf.inc" |
#include "netcdf.inc" |
94 |
#include "mnc_common.h" |
#include "mnc_common.h" |
95 |
#include "SIZE.h" |
#include "SIZE.h" |
96 |
|
#include "MNC_SIZE.h" |
97 |
#include "EEPARAMS.h" |
#include "EEPARAMS.h" |
98 |
#include "PARAMS.h" |
#include "PARAMS.h" |
99 |
#include "MNC_PARAMS.h" |
#include "MNC_PARAMS.h" |
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 |
character*(MNC_MAX_CHAR) path_fname |
120 |
REAL*8 resh_d( sNx + 2*OLx + sNy + 2*OLy ) |
REAL*8 resh_d( MNC_MAX_BUFF ) |
121 |
REAL*4 resh_r( sNx + 2*OLx + sNy + 2*OLy ) |
REAL*4 resh_r( MNC_MAX_BUFF ) |
122 |
INTEGER resh_i( sNx + 2*OLx + sNy + 2*OLy ) |
INTEGER resh_i( MNC_MAX_BUFF ) |
123 |
|
#ifdef HAVE_STAT |
124 |
|
integer ntotenc, ncenc, nbytes, fs_isdone |
125 |
|
character*(200) cenc |
126 |
|
integer ienc(200) |
127 |
|
REAL*8 fsnu |
128 |
|
#endif |
129 |
|
|
130 |
C Functions |
C Functions |
131 |
integer IFNBLNK, ILNBLNK |
integer IFNBLNK, ILNBLNK |
147 |
ENDIF |
ENDIF |
148 |
indu = mnc_cw_fgud(indfg) |
indu = mnc_cw_fgud(indfg) |
149 |
iseq = mnc_cw_fgis(indfg) |
iseq = mnc_cw_fgis(indfg) |
150 |
|
C write(*,*) 'indu,iseq = ', indu, iseq |
151 |
|
|
152 |
C Check that the Variable Type exists |
C Check that the Variable Type exists |
153 |
nvf = IFNBLNK(vtype) |
nvf = IFNBLNK(vtype) |
178 |
DO lbj = bjs,bje |
DO lbj = bjs,bje |
179 |
DO lbi = bis,bie |
DO lbi = bis,bie |
180 |
|
|
181 |
|
#ifdef HAVE_STAT |
182 |
|
fs_isdone = 0 |
183 |
|
#endif |
184 |
|
10 CONTINUE |
185 |
|
|
186 |
C Create the file name |
C Create the file name |
187 |
CALL MNC_CW_GET_TILE_NUM(lbi,lbj, uniq_tnum, myThid) |
CALL MNC_CW_GET_TILE_NUM(lbi,lbj, uniq_tnum, myThid) |
188 |
fname(1:MNC_MAX_CHAR) = mnc_blank_name(1:MNC_MAX_CHAR) |
fname(1:MNC_MAX_CHAR) = mnc_blank_name(1:MNC_MAX_CHAR) |
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 |
214 |
|
IF ((mnc_cw_fgig(indfg) .EQ. 1) |
215 |
|
& .AND. (fs_isdone .EQ. 0)) THEN |
216 |
|
C Decide whether to append to the existing or create a new |
217 |
|
C file based on the byte count per unlimited dimension |
218 |
|
ncenc = 70 |
219 |
|
cenc(1:26) = 'abcdefghijklmnopqrstuvwxyz' |
220 |
|
cenc(27:52) = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
221 |
|
cenc(53:70) = '0123456789_.,+-=/~' |
222 |
|
k = nfname |
223 |
|
IF (k .GT. 200) k = 200 |
224 |
|
ntotenc = 0 |
225 |
|
DO i = 1,k |
226 |
|
DO j = 1,ncenc |
227 |
|
IF (fname(i:i) .EQ. cenc(j:j)) THEN |
228 |
|
ntotenc = ntotenc + 1 |
229 |
|
ienc(ntotenc) = j |
230 |
|
GOTO 20 |
231 |
|
ENDIF |
232 |
|
ENDDO |
233 |
|
20 CONTINUE |
234 |
|
ENDDO |
235 |
|
CALL mncfsize(ntotenc, ienc, nbytes) |
236 |
|
IF (nbytes .GT. 0) THEN |
237 |
|
CALL MNC_DIM_UNLIM_SIZE(fname, unlim_sz, myThid) |
238 |
|
fsnu = (1.0 _d 0 + 1.0 _d 0 / DBLE(unlim_sz)) |
239 |
|
& * DBLE(nbytes) |
240 |
|
IF (fsnu .GT. mnc_max_fsize) THEN |
241 |
|
C Delete the now-full fname from the lookup tables since |
242 |
|
C we are all done writing to it. |
243 |
|
CALL MNC_FILE_CLOSE(fname, myThid) |
244 |
|
iseq = iseq + 1 |
245 |
|
indu = 1 |
246 |
|
mnc_cw_fgud(indfg) = 1 |
247 |
|
mnc_cw_fgis(indfg) = iseq |
248 |
|
fs_isdone = 1 |
249 |
|
GOTO 10 |
250 |
|
ENDIF |
251 |
|
ENDIF |
252 |
|
ENDIF |
253 |
|
#endif /* HAVE_STAT */ |
254 |
|
|
255 |
C Ensure that all the NetCDF dimensions are defined and create a |
C Ensure that all the NetCDF dimensions are defined and create a |
256 |
C local copy of them |
C local copy of them |
257 |
DO i = 1,9 |
DO i = 1,9 |
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 |
291 |
idv = mnc_fv_ids(indf,j+1) |
idv = mnc_fv_ids(indf,j+1) |
292 |
indvids = mnc_fd_ind(indf, mnc_f_info(indf, |
indvids = mnc_fd_ind(indf, mnc_f_info(indf, |
293 |
& (mnc_fv_ids(indf,j+2) + 1)) ) |
& (mnc_fv_ids(indf,j+2) + 1)) ) |
294 |
GOTO 10 |
GOTO 30 |
295 |
ENDIF |
ENDIF |
296 |
ENDDO |
ENDDO |
297 |
write(msgbuf,'(4a)') 'MNC_MNC_CW_RX_W ERROR: ', |
write(msgbuf,'(4a)') 'MNC_MNC_CW_RX_W ERROR: ', |
298 |
& 'cannot reference variable ''', vtype, '''' |
& 'cannot reference variable ''', vtype, '''' |
299 |
CALL print_error(msgbuf, mythid) |
CALL print_error(msgbuf, mythid) |
300 |
STOP 'ABNORMAL END: package MNC' |
STOP 'ABNORMAL END: package MNC' |
301 |
10 CONTINUE |
30 CONTINUE |
302 |
|
|
303 |
C Check for bi,bj indicies |
C Check for bi,bj indicies |
304 |
bidim = mnc_cw_vbij(1,indv) |
bidim = mnc_cw_vbij(1,indv) |
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, |
431 |
vstart(1) = udo(1) + 1 |
vstart(1) = udo(1) + 1 |
432 |
vcount(1) = e(1) - s(1) + 1 |
vcount(1) = e(1) - s(1) + 1 |
433 |
|
|
434 |
|
IF (vcount(1) .GT. MNC_MAX_BUFF) THEN |
435 |
|
write(msgbuf,'(2a,I7,a)') 'MNC_MAX_BUFF is too small', |
436 |
|
& '--please increase to at least ', |
437 |
|
& vcount(1), ' in ''MNC_SIZE.h''' |
438 |
|
CALL PRINT_ERROR(msgBuf , 1) |
439 |
|
STOP 'ABNORMAL END: S/R MNC_CW_RX_W_OFFSET' |
440 |
|
ENDIF |
441 |
|
|
442 |
IF (stype(1:1) .EQ. 'D') THEN |
IF (stype(1:1) .EQ. 'D') THEN |
443 |
DO j1 = s(1),e(1) |
DO j1 = s(1),e(1) |
444 |
k1 = k2 + j1 |
k1 = k2 + j1 |
542 |
#include "netcdf.inc" |
#include "netcdf.inc" |
543 |
#include "mnc_common.h" |
#include "mnc_common.h" |
544 |
#include "SIZE.h" |
#include "SIZE.h" |
545 |
|
#include "MNC_SIZE.h" |
546 |
#include "EEPARAMS.h" |
#include "EEPARAMS.h" |
547 |
#include "PARAMS.h" |
#include "PARAMS.h" |
548 |
#include "MNC_PARAMS.h" |
#include "MNC_PARAMS.h" |
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) path_fname |
character*(MNC_MAX_CHAR) path_fname |
567 |
integer indfg, fg1,fg2 |
integer indfg, fg1,fg2 |
568 |
REAL*8 resh_d( sNx + 2*OLx + sNy + 2*OLy ) |
REAL*8 resh_d( MNC_MAX_BUFF ) |
569 |
REAL*4 resh_r( sNx + 2*OLx + sNy + 2*OLy ) |
REAL*4 resh_r( MNC_MAX_BUFF ) |
570 |
INTEGER resh_i( sNx + 2*OLx + sNy + 2*OLy ) |
INTEGER resh_i( MNC_MAX_BUFF ) |
571 |
|
|
572 |
C Functions |
C Functions |
573 |
integer IFNBLNK, ILNBLNK |
integer IFNBLNK, ILNBLNK |
645 |
ENDIF |
ENDIF |
646 |
|
|
647 |
C Open the existing file |
C Open the existing file |
648 |
CALL MNC_FILE_TRY_READ( fname, ierr, indf, myThid) |
C CALL MNC_FILE_TRY_READ( fname, ierr, indf, myThid) |
649 |
|
|
650 |
C Check that the variable (VType) is defined within the file |
C Check that the variable (VType) is defined within the file |
651 |
CALL MNC_GET_FVINDS( fname, vtype, indf, ind_fv_ids, myThid) |
C CALL MNC_GET_FVINDS( fname, vtype, indf, ind_fv_ids, myThid) |
652 |
IF ((indf .LT. 1) .OR. (ind_fv_ids .LT. 1)) THEN |
C IF ((indf .LT. 1) .OR. (ind_fv_ids .LT. 1)) THEN |
653 |
write(msgbuf,'(4a)') 'MNC_CW_RX_R ERROR: vtype ''', |
C write(msgbuf,'(4a)') 'MNC_CW_RX_R ERROR: vtype ''', |
654 |
& vtype(nvf:nvl), ''' is not defined within file ''', |
C & vtype(nvf:nvl), ''' is not defined within file ''', |
655 |
& fname(1:nfname) |
C & fname(1:nfname) |
656 |
CALL print_error(msgbuf, mythid) |
C CALL print_error(msgbuf, mythid) |
657 |
STOP 'ABNORMAL END: S/R MNC_CW_RX_R' |
C STOP 'ABNORMAL END: S/R MNC_CW_RX_R' |
658 |
ENDIF |
C ENDIF |
659 |
fid = mnc_f_info(indf,2) |
|
660 |
idv = mnc_fv_ids(indf,ind_fv_ids+1) |
C The previous old junk is completely unnecessary. All we |
661 |
|
C should do is (1) open the file in a READ-ONLY mode, (2) get |
662 |
|
C the var id for the current variable, (3) read the data, and |
663 |
|
C then (4) quickly close the file since theres no need to keep |
664 |
|
C it open. |
665 |
|
write(msgbuf,'(4a)') 'MNC_CW_RX_R: cannot open', |
666 |
|
& ' file ''', fname(1:nfname), ''' in read-only mode' |
667 |
|
err = NF_OPEN(fname, NF_NOWRITE, fid) |
668 |
|
CALL MNC_HANDLE_ERR(err, msgbuf, myThid) |
669 |
|
|
670 |
|
write(msgbuf,'(6a)') |
671 |
|
& 'MNC_CW_RX_R: cannot get id for variable ''', |
672 |
|
& vtype(nvf:nvl), '''in file ''', fname(1:nfname), '''' |
673 |
|
err = NF_INQ_VARID(fid, vtype, idv) |
674 |
|
CALL MNC_HANDLE_ERR(err, msgbuf, myThid) |
675 |
|
|
676 |
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 |
677 |
C are compatible and WARN (only warn) if not |
C are compatible and WARN (only warn) if not |
678 |
f_sNx = -1 |
C f_sNx = -1 |
679 |
f_sNy = -1 |
C f_sNy = -1 |
680 |
err = NF_INQ_ATT(fid,NF_GLOBAL, 'sNx',atype,alen) |
C err = NF_INQ_ATT(fid,NF_GLOBAL, 'sNx',atype,alen) |
681 |
IF ((err .EQ. NF_NOERR) .AND. (alen .EQ. 1)) THEN |
C IF ((err .EQ. NF_NOERR) .AND. (alen .EQ. 1)) THEN |
682 |
err = NF_GET_ATT_INT(fid, NF_GLOBAL, 'sNx', f_sNx) |
C err = NF_GET_ATT_INT(fid, NF_GLOBAL, 'sNx', f_sNx) |
683 |
CALL MNC_HANDLE_ERR(err, |
C CALL MNC_HANDLE_ERR(err, |
684 |
& 'reading attribute ''sNx'' in S/R MNC_CW_RX_R', |
C & 'reading attribute ''sNx'' in S/R MNC_CW_RX_R', |
685 |
& myThid) |
C & myThid) |
686 |
ENDIF |
C ENDIF |
687 |
err = NF_INQ_ATT(fid,NF_GLOBAL, 'sNy',atype,alen) |
C err = NF_INQ_ATT(fid,NF_GLOBAL, 'sNy',atype,alen) |
688 |
IF ((err .EQ. NF_NOERR) .AND. (alen .EQ. 1)) THEN |
C IF ((err .EQ. NF_NOERR) .AND. (alen .EQ. 1)) THEN |
689 |
err = NF_GET_ATT_INT(fid, NF_GLOBAL, 'sNy', f_sNy) |
C err = NF_GET_ATT_INT(fid, NF_GLOBAL, 'sNy', f_sNy) |
690 |
CALL MNC_HANDLE_ERR(err, |
C CALL MNC_HANDLE_ERR(err, |
691 |
& 'reading attribute ''sNy'' in S/R MNC_CW_RX_R', |
C & 'reading attribute ''sNy'' in S/R MNC_CW_RX_R', |
692 |
& myThid) |
C & myThid) |
693 |
ENDIF |
C ENDIF |
694 |
IF ((f_sNx .NE. sNx) .OR. (f_sNy .NE. sNy)) THEN |
C IF ((f_sNx .NE. sNx) .OR. (f_sNy .NE. sNy)) THEN |
695 |
write(msgbuf,'(5a)') 'MNC_CW_RX_R WARNING: the ', |
C write(msgbuf,'(5a)') 'MNC_CW_RX_R WARNING: the ', |
696 |
& 'attributes ''sNx'' and ''sNy'' within the file ''', |
C & 'attributes ''sNx'' and ''sNy'' within the file ''', |
697 |
& fname(1:nfname), ''' do not exist or do not match ', |
C & fname(1:nfname), ''' do not exist or do not match ', |
698 |
& 'the current sizes within the model' |
C & 'the current sizes within the model' |
699 |
CALL print_error(msgbuf, mythid) |
C CALL print_error(msgbuf, mythid) |
700 |
ENDIF |
C ENDIF |
701 |
|
|
702 |
C Check that the in-memory variable and the in-file variables |
C Check that the in-memory variable and the in-file variables |
703 |
C are of compatible sizes |
C are of compatible sizes |
756 |
IF (indu .GT. 0) THEN |
IF (indu .GT. 0) THEN |
757 |
C Use the indu value |
C Use the indu value |
758 |
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 |
|
759 |
ELSE |
ELSE |
760 |
C Use the current unlimited dim size |
C We need the current unlim dim size |
761 |
CALL MNC_DIM_UNLIM_SIZE( fname, unlim_sz, myThid) |
write(msgbuf,'(5a)') 'MNC_CW_RX_R: getting the ', |
762 |
udo(i) = unlim_sz - 1 |
& 'unlim dim id within file ''', |
763 |
|
& fname(1:nfname), '''' |
764 |
|
err = NF_INQ_UNLIMDIM(fid, unlid) |
765 |
|
CALL MNC_HANDLE_ERR(err, msgbuf, myThid) |
766 |
|
write(msgbuf,'(5a)') 'MNC_CW_RX_R: getting the ', |
767 |
|
& 'unlim dim size within file ''', |
768 |
|
& fname(1:nfname), '''' |
769 |
|
err = NF_INQ_DIMLEN(fid, unlid, unlim_sz) |
770 |
|
CALL MNC_HANDLE_ERR(err, msgbuf, myThid) |
771 |
|
udo(i) = unlim_sz |
772 |
ENDIF |
ENDIF |
773 |
ENDIF |
ENDIF |
774 |
ENDDO |
ENDDO |
785 |
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) |
786 |
C ENDDO |
C ENDDO |
787 |
|
|
|
CALL MNC_FILE_ENDDEF(fname, myThid) |
|
|
|
|
788 |
write(msgbuf,'(5a)') 'reading variable type ''', |
write(msgbuf,'(5a)') 'reading variable type ''', |
789 |
& vtype(nvf:nvl), ''' within file ''', |
& vtype(nvf:nvl), ''' within file ''', |
790 |
& fname(1:nfname), '''' |
& fname(1:nfname), '''' |
818 |
kr = 0 |
kr = 0 |
819 |
vstart(1) = udo(1) + 1 |
vstart(1) = udo(1) + 1 |
820 |
vcount(1) = e(1) - s(1) + 1 |
vcount(1) = e(1) - s(1) + 1 |
821 |
|
|
822 |
|
IF (vcount(1) .GT. MNC_MAX_BUFF) THEN |
823 |
|
write(msgbuf,'(2a,I7,a)') 'MNC_MAX_BUFF is too small', |
824 |
|
& '--please increase to at least ', |
825 |
|
& vcount(1), ' in ''MNC_SIZE.h''' |
826 |
|
CALL PRINT_ERROR(msgBuf , 1) |
827 |
|
STOP 'ABNORMAL END: S/R MNC_CW_RX_R_OFFSET' |
828 |
|
ENDIF |
829 |
|
|
830 |
IF (stype(1:1) .EQ. 'D') THEN |
IF (stype(1:1) .EQ. 'D') THEN |
831 |
err = NF_GET_VARA_DOUBLE(fid, idv, vstart, vcount, resh_d) |
err = NF_GET_VARA_DOUBLE(fid, idv, vstart, vcount, resh_d) |
832 |
CALL MNC_HANDLE_ERR(err, msgbuf, myThid) |
CALL MNC_HANDLE_ERR(err, msgbuf, myThid) |
855 |
ENDDO |
ENDDO |
856 |
ENDIF |
ENDIF |
857 |
|
|
|
|
|
858 |
|
|
859 |
ENDDO |
ENDDO |
860 |
ENDDO |
ENDDO |
864 |
ENDDO |
ENDDO |
865 |
|
|
866 |
C Close the file |
C Close the file |
867 |
CALL MNC_FILE_CLOSE(fname, myThid) |
C CALL MNC_FILE_CLOSE(fname, myThid) |
868 |
|
err = NF_CLOSE(fid) |
869 |
|
write(msgbuf,'(3a)') 'MNC_CW_RX_R: cannot close file ''', |
870 |
|
& fname(1:nfname), '''' |
871 |
|
CALL MNC_HANDLE_ERR(err, msgbuf, myThid) |
872 |
|
|
873 |
|
|
874 |
C End the lbj,lbi loops |
C End the lbj,lbi loops |
875 |
ENDDO |
ENDDO |