1 |
C $Header: /u/gcmpack/MITgcm/pkg/mnc/mnc_dim.F,v 1.9 2004/03/29 03:33:51 edhill Exp $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "MNC_OPTIONS.h" |
5 |
|
6 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
7 |
CBOP 0 |
8 |
C !ROUTINE: MNC_DIM_INIT |
9 |
|
10 |
C !INTERFACE: |
11 |
SUBROUTINE MNC_DIM_INIT( |
12 |
I fname, |
13 |
I dname, |
14 |
I dlen, |
15 |
I myThid ) |
16 |
|
17 |
C !DESCRIPTION: |
18 |
C Create a dimension within the MNC look-up tables. |
19 |
|
20 |
C !INPUT PARAMETERS: |
21 |
integer myThid, dlen |
22 |
character*(*) fname, dname |
23 |
CEOP |
24 |
|
25 |
CALL MNC_DIM_INIT_ALL(fname, dname, dlen, 'Y', myThid) |
26 |
|
27 |
RETURN |
28 |
END |
29 |
|
30 |
|
31 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
32 |
CBOP 1 |
33 |
C !ROUTINE: MNC_DIM_INIT_ALL |
34 |
|
35 |
C !INTERFACE: |
36 |
SUBROUTINE MNC_DIM_INIT_ALL( |
37 |
I fname, |
38 |
I dname, |
39 |
I dlen, |
40 |
I doWrite, |
41 |
I myThid ) |
42 |
|
43 |
C !DESCRIPTION: |
44 |
C Create a dimension within the MNC look-up tables. |
45 |
|
46 |
C !USES: |
47 |
implicit none |
48 |
#include "netcdf.inc" |
49 |
#include "mnc_common.h" |
50 |
#include "EEPARAMS.h" |
51 |
|
52 |
C !INPUT PARAMETERS: |
53 |
integer myThid, dlen |
54 |
character*(*) fname, dname |
55 |
character*(1) doWrite |
56 |
CEOP |
57 |
|
58 |
C !LOCAL VARIABLES: |
59 |
integer i,j, indf,indd, n,nf, dnf,dnl |
60 |
integer ntmp, idd, err, tlen |
61 |
character*(MAX_LEN_MBUF) msgbuf |
62 |
|
63 |
C Functions |
64 |
integer ILNBLNK, IFNBLNK |
65 |
|
66 |
nf = ILNBLNK(fname) |
67 |
|
68 |
dnf = IFNBLNK(dname) |
69 |
dnl = ILNBLNK(dname) |
70 |
|
71 |
C Verify that the file exists |
72 |
CALL MNC_GET_IND(MNC_MAX_ID, fname, mnc_f_names, indf, myThid) |
73 |
IF ( indf .LT. 1 ) THEN |
74 |
write(msgbuf,'(3a)') 'MNC ERROR: file ''', fname(1:nf), |
75 |
& ''' does not exist' |
76 |
CALL print_error( msgbuf, mythid ) |
77 |
stop 'ABNORMAL END: S/R MNC_DIM_INIT' |
78 |
ENDIF |
79 |
|
80 |
C Verify that the dim is not currently defined within the file |
81 |
n = mnc_f_alld(indf,1) |
82 |
DO i = 1,n |
83 |
j = mnc_f_alld(indf,i+1) |
84 |
ntmp = ILNBLNK(mnc_d_names(j)) |
85 |
IF ((ntmp .EQ. (dnl-dnf+1)) |
86 |
& .AND. (dname(dnf:dnl) .EQ. mnc_d_names(j)(1:ntmp))) THEN |
87 |
IF (mnc_d_size(j) .NE. dlen) THEN |
88 |
IF ((mnc_d_size(j) .GT. 0) .OR. (dlen .GT. 0)) THEN |
89 |
write(msgbuf,'(5a)') 'MNC ERROR: dimension ''', |
90 |
& dname(dnf:dnl), ''' already exists within file ''', |
91 |
& fname(1:nf), ''' and its size cannot be changed' |
92 |
CALL print_error(msgbuf, mythid) |
93 |
stop 'ABNORMAL END: S/R MNC_DIM_INIT' |
94 |
ELSE |
95 |
C Its OK, the names are the same and both are specifying the |
96 |
C unlimited dimension |
97 |
RETURN |
98 |
ENDIF |
99 |
ELSE |
100 |
C Its OK, the names and sizes are identical |
101 |
RETURN |
102 |
ENDIF |
103 |
ENDIF |
104 |
ENDDO |
105 |
|
106 |
CALL MNC_GET_NEXT_EMPTY_IND(MNC_MAX_ID, mnc_d_names, indd, myThid) |
107 |
|
108 |
C Create the dim within the file |
109 |
IF (doWrite(1:1) .EQ. 'Y') THEN |
110 |
|
111 |
tlen = dlen |
112 |
IF (dlen .LT. 1) tlen = NF_UNLIMITED |
113 |
|
114 |
CALL MNC_FILE_REDEF(fname, myThid) |
115 |
err = NF_DEF_DIM(mnc_f_info(indf,2), dname(dnf:dnl), tlen, idd) |
116 |
write(msgbuf,'(5a)') 'MNC_DIM_INIT ERROR: cannot create ', |
117 |
& 'dim ''', dname(dnf:dnl), ''' in file ''', fname(1:nf) |
118 |
CALL MNC_HANDLE_ERR(err, msgbuf, myThid) |
119 |
|
120 |
ENDIF |
121 |
|
122 |
C Add to tables |
123 |
mnc_d_names(indd)(1:(dnl-dnf+1)) = dname(dnf:dnl) |
124 |
mnc_d_size(indd) = dlen |
125 |
mnc_d_ids(indd) = idd |
126 |
mnc_f_alld(indf,1) = n + 1 |
127 |
mnc_f_alld(indf,n+2) = indd |
128 |
|
129 |
RETURN |
130 |
END |
131 |
|
132 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
133 |
CBOP 1 |
134 |
C !ROUTINE: MNC_DIM_UNLIM_SIZE |
135 |
|
136 |
C !INTERFACE: |
137 |
SUBROUTINE MNC_DIM_UNLIM_SIZE( |
138 |
I fname, |
139 |
I unlim_sz, |
140 |
I myThid ) |
141 |
|
142 |
C !DESCRIPTION: |
143 |
C Get the size of the unlimited dimension. |
144 |
|
145 |
C !USES: |
146 |
implicit none |
147 |
#include "netcdf.inc" |
148 |
#include "mnc_common.h" |
149 |
#include "EEPARAMS.h" |
150 |
|
151 |
C !INPUT PARAMETERS: |
152 |
integer myThid, unlim_sz |
153 |
character*(*) fname |
154 |
CEOP |
155 |
|
156 |
C !LOCAL VARIABLES: |
157 |
integer i,j, nf, indf, fid, unlimid, err |
158 |
character*(MAX_LEN_MBUF) msgbuf |
159 |
|
160 |
C Functions |
161 |
integer ILNBLNK, IFNBLNK |
162 |
|
163 |
nf = ILNBLNK(fname) |
164 |
|
165 |
C Verify that the file exists |
166 |
CALL MNC_GET_IND(MNC_MAX_ID, fname, mnc_f_names, indf, myThid) |
167 |
IF (indf .LT. 1) THEN |
168 |
write(msgbuf,'(3a)') 'MNC ERROR: file ''', fname(1:nf), |
169 |
& ''' does not exist' |
170 |
CALL print_error(msgbuf, mythid) |
171 |
stop 'ABNORMAL END: S/R MNC_DIM_UNLIM_SIZE' |
172 |
ENDIF |
173 |
fid = mnc_f_info(indf,2) |
174 |
|
175 |
C Find the unlimited dim and its current size |
176 |
unlim_sz = -1 |
177 |
DO i = 1,mnc_f_alld(indf,1) |
178 |
j = mnc_f_alld(indf,i+1) |
179 |
IF (mnc_d_size(j) .EQ. -1) THEN |
180 |
unlimid = mnc_d_ids(j) |
181 |
err = NF_INQ_DIMLEN(fid, unlimid, unlim_sz) |
182 |
write(msgbuf,'(3a)') 'MNC_DIM_UNLIM_SIZE ERROR: cannot ', |
183 |
& 'determine unlimited dim size in file ''', fname(1:nf) |
184 |
CALL MNC_HANDLE_ERR(err, msgbuf, myThid) |
185 |
RETURN |
186 |
ENDIF |
187 |
ENDDO |
188 |
|
189 |
RETURN |
190 |
END |
191 |
|
192 |
|
193 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
194 |
|