/[MITgcm]/MITgcm/pkg/mnc/mnc_grid.F
ViewVC logotype

Contents of /MITgcm/pkg/mnc/mnc_grid.F

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.20 - (show annotations) (download)
Fri Jun 20 20:36:58 2008 UTC (15 years, 10 months ago) by utke
Branch: MAIN
CVS Tags: checkpoint64y, checkpoint64x, checkpoint64z, checkpoint64q, checkpoint64p, checkpoint64s, checkpoint64r, checkpoint64u, checkpoint64t, checkpoint64w, checkpoint64v, checkpoint64i, checkpoint64h, checkpoint64k, checkpoint64j, checkpoint64m, checkpoint64l, checkpoint64o, checkpoint64n, checkpoint64a, checkpoint64c, checkpoint64b, checkpoint64e, checkpoint64d, checkpoint64g, checkpoint64f, checkpoint63p, checkpoint63q, checkpoint63r, checkpoint63s, checkpoint63l, checkpoint63m, checkpoint63n, checkpoint63o, checkpoint63h, checkpoint63i, checkpoint63j, checkpoint63k, checkpoint63d, checkpoint63e, checkpoint63f, checkpoint63g, checkpoint63a, checkpoint63b, checkpoint63c, checkpoint64, checkpoint65, checkpoint61, checkpoint62, checkpoint63, checkpoint66g, checkpoint66f, checkpoint66e, checkpoint66d, checkpoint66c, checkpoint66b, checkpoint66a, checkpoint66o, checkpoint66n, checkpoint66m, checkpoint66l, checkpoint66k, checkpoint66j, checkpoint66i, checkpoint66h, checkpoint65z, checkpoint65x, checkpoint65y, checkpoint65r, checkpoint65s, checkpoint65p, checkpoint65q, checkpoint65v, checkpoint65w, checkpoint65t, checkpoint65u, checkpoint65j, checkpoint65k, checkpoint65h, checkpoint65i, checkpoint65n, checkpoint65o, checkpoint65l, checkpoint65m, checkpoint65b, checkpoint65c, checkpoint65a, checkpoint65f, checkpoint65g, checkpoint65d, checkpoint65e, checkpoint62c, checkpoint62b, checkpoint62a, checkpoint62g, checkpoint62f, checkpoint62e, checkpoint62d, checkpoint62k, checkpoint62j, checkpoint62i, checkpoint62h, checkpoint62o, checkpoint62n, checkpoint62m, checkpoint62l, checkpoint62s, checkpoint62r, checkpoint62q, checkpoint62p, checkpoint62w, checkpoint62v, checkpoint62u, checkpoint62t, checkpoint62z, checkpoint62y, checkpoint62x, checkpoint61f, checkpoint61g, checkpoint61d, checkpoint61e, checkpoint61b, checkpoint61c, checkpoint61a, checkpoint61n, checkpoint61o, checkpoint61l, checkpoint61m, checkpoint61j, checkpoint61k, checkpoint61h, checkpoint61i, checkpoint61v, checkpoint61w, checkpoint61t, checkpoint61u, checkpoint61r, checkpoint61s, checkpoint61p, checkpoint61q, checkpoint61z, checkpoint61x, checkpoint61y, HEAD
Changes since 1.19: +2 -2 lines
move netcdf.inc includes
to avoid conflict when common block includes are turned into module uses

1 C $Header: /u/gcmpack/MITgcm/pkg/mnc/mnc_grid.F,v 1.19 2008/05/22 12:21:19 mlosch Exp $
2 C $Name: $
3
4 #include "MNC_OPTIONS.h"
5
6 C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
7 CBOP 1
8 C !ROUTINE: MNC_GRID_INIT
9
10 C !INTERFACE:
11 SUBROUTINE MNC_GRID_INIT(
12 I fname,
13 I gname,
14 I ndim,
15 I dnames,
16 I myThid )
17
18 C !DESCRIPTION:
19 C Create an MNC grid within a NetCDF file context.
20
21 C !USES:
22 implicit none
23
24 C !INPUT PARAMETERS:
25 integer myThid, ndim
26 character*(*) fname,gname
27 character*(*) dnames(ndim)
28 CEOP
29
30 C !LOCAL VARIABLES:
31 integer ind
32
33 CALL MNC_GRID_INIT_ALL(fname, gname, ndim, dnames, ind, myThid)
34
35 RETURN
36 END
37
38 C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
39 CBOP 1
40 C !ROUTINE: MNC_GRID_INIT_ALL
41
42 C !INTERFACE:
43 SUBROUTINE MNC_GRID_INIT_ALL(
44 I fname,
45 I gname,
46 I ndim,
47 I dnames,
48 O ind,
49 I myThid )
50
51 C !DESCRIPTION:
52 C Initialize a new conceptual (MNC inner layer) grid within a NetCDF
53 C file context. If the requested grid name already exists, then
54 C verify that it has exactly the same number of dimensions, each
55 C with exactly the same size and report a fatal error if not. This
56 C is a necessary check since the MNC inner layer does not support
57 C grid name re--definition.
58
59 C !USES:
60 implicit none
61 #include "MNC_COMMON.h"
62 #include "EEPARAMS.h"
63 #include "netcdf.inc"
64
65 C !INPUT PARAMETERS:
66 integer myThid, ndim, ind
67 character*(*) fname,gname
68 character*(*) dnames(ndim)
69 CEOP
70
71 C !LOCAL VARIABLES:
72 integer i,j,k,ii,jj,kk, n,nf, indf,indg,indd, fid, ngrid
73 integer ng_ind,lg_ind, ds_last, ndim_file, igr,ig1,ig2
74 integer ngt, ngn
75 character*(MAX_LEN_MBUF) msgbuf
76 character*(MNC_MAX_PATH) file_name
77
78 C Functions
79 integer ILNBLNK
80
81 C Get the file ID and indicies
82 DO i =1,MNC_MAX_PATH
83 file_name(i:i) = ' '
84 ENDDO
85 nf = ILNBLNK(fname)
86 IF (nf .GT. MNC_MAX_PATH) nf = MNC_MAX_PATH
87 file_name(1:nf) = fname(1:nf)
88 CALL MNC_GET_IND(MNC_MAX_FID,file_name,mnc_f_names,indf,myThid)
89 IF (indf .LT. 1) THEN
90 write(msgbuf,'(3a)') 'MNC ERROR: file ''', file_name(1:nf),
91 & ''' does not exist'
92 CALL print_error( msgbuf, mythid )
93 stop 'ABNORMAL END: S/R MNC_GRID_INIT'
94 ENDIF
95 fid = mnc_f_info(indf,2)
96 ngrid = mnc_f_info(indf,3)
97 ng_ind = 4 + 3*ngrid
98 IF (ngrid .EQ. 0) THEN
99 ds_last = 0
100 ELSE
101 lg_ind = 4 + 3*(ngrid - 1)
102 ds_last = mnc_f_info(indf,(lg_ind+2))
103 ENDIF
104
105 C Check for sufficient space in memory
106 i = ds_last + ndim
107 j = 3 + 3*(ngrid + 1)
108 IF ((i .GE. MNC_MAX_INFO) .OR. (j .GE. MNC_MAX_INFO)) THEN
109 write(msgbuf,'(2a)') 'MNC_GRID_INIT_ALL ERROR: insufficient',
110 & ' space--please increase MNC_MAX_INFO'
111 CALL print_error( msgbuf, mythid )
112 stop 'ABNORMAL END: S/R MNC_GRID_INIT_ALL'
113 ENDIF
114
115 C Enter DEFINE mode
116 CALL MNC_FILE_REDEF(fname, myThid)
117
118 ngn = ILNBLNK(gname)
119
120 C Check for grid re-definition
121 DO igr = 1,mnc_f_info(indf,3)
122 ii = 4 + 3*(igr - 1)
123 ngt = ILNBLNK(mnc_g_names(mnc_f_info(indf,ii)))
124 IF ( (ngt .EQ. ngn)
125 & .AND. (mnc_g_names(mnc_f_info(indf,ii))(1:ngt)
126 & .EQ. gname(1:ngn)) ) THEN
127
128 ig1 = mnc_f_info(indf,ii+1)
129 ig2 = mnc_f_info(indf,ii+2)
130
131 C Check if different number of dims
132 IF (ndim .NE. (ig2-ig1+1)) THEN
133 kk = ILNBLNK( mnc_f_names(indf) )
134 write(msgbuf,'(6a)') 'MNC ERROR: grid ''', gname(1:ngn),
135 & ''' was previously defined for file ''',
136 & mnc_f_names(indf)(1:kk), ''' with a different ',
137 & 'number of dimensions'
138 CALL print_error(msgbuf, mythid)
139 stop 'ABNORMAL END: S/R MNC_GRID_INIT'
140 ENDIF
141
142 C Check if same number of dims but different dim names
143 k = 0
144 DO jj = ig1,ig2
145 k = k + 1
146 IF (mnc_d_names(mnc_fd_ind(indf,jj)) .NE. dnames(k)) THEN
147 kk = ILNBLNK( mnc_f_names(indf) )
148 write(msgbuf,'(6a)') 'MNC ERROR: grid ''', gname(1:ngn),
149 & ''' was previously defined for file ''',
150 & mnc_f_names(indf)(1:kk), ''' with a different ',
151 & 'combination of dimensions'
152 CALL print_error(msgbuf, mythid)
153 stop 'ABNORMAL END: S/R MNC_GRID_INIT'
154 ENDIF
155 ENDDO
156
157 C Reaching this point means that the grid name WAS previously
158 C defined and the number and sizes of the associated dimensions
159 C exactly match so everything is OK and we do not need to create
160 C a new definition for this grid.
161 RETURN
162
163 ENDIF
164 ENDDO
165
166 C Reaching this point means the grid was NOT previously defined and
167 C we must therefore create a new definition.
168 CALL MNC_GET_NEXT_EMPTY_IND(MNC_MAX_ID, mnc_g_names,
169 & 'mnc_g_names', indg, myThid)
170 mnc_g_names(indg)(1:MNC_MAX_CHAR) =
171 & mnc_blank_name(1:MNC_MAX_CHAR)
172 n = ILNBLNK(gname)
173 mnc_g_names(indg)(1:n) = gname(1:n)
174
175 C Add the dimensions
176 DO i = 1,ndim
177
178 j = ds_last + i
179 n = ILNBLNK(dnames(i))
180
181 C Search for the dimension ID within the list of dimensions
182 C defined for this file
183 ndim_file = mnc_f_alld(indf,1)
184 indd = 0
185 DO ii = 1,ndim_file
186 jj = mnc_f_alld(indf,ii+1)
187 kk = ILNBLNK(mnc_d_names(jj))
188 IF ((n .EQ. kk)
189 & .AND. (dnames(i)(1:n) .EQ. mnc_d_names(jj)(1:kk))) THEN
190 indd = jj
191 GOTO 20
192 ENDIF
193 ENDDO
194 20 CONTINUE
195 IF (indd .LT. 1) THEN
196 write(msgbuf,'(5a)') 'MNC ERROR: dimension ''',
197 & dnames(i)(1:n), ''' does not exist for file ''',
198 & fname(1:nf), ''''
199 CALL print_error( msgbuf, mythid )
200 stop 'ABNORMAL END: S/R MNC_GRID_INIT'
201 ENDIF
202
203 mnc_fd_ind(indf,j) = indd
204
205 ENDDO
206
207 C Grid successfully added, so update file table
208 mnc_f_info(indf,ng_ind) = indg
209 mnc_f_info(indf,ng_ind+1) = ds_last + 1
210 mnc_f_info(indf,ng_ind+2) = ds_last + ndim
211 mnc_f_info(indf,3) = ngrid + 1
212 ind = indg
213
214 RETURN
215 END
216
217 C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
218 CBOP 1
219 C !ROUTINE: MNC_GRID_GET_DIMIND
220
221 C !INTERFACE:
222 SUBROUTINE MNC_GRID_GET_DIMIND(
223 I indf,
224 I dname,
225 O ind_fg_ids,
226 I myThid )
227
228 C !DESCRIPTION:
229 C Get the dimension ID (index) for the named dimension.
230
231 C !USES:
232 implicit none
233 #include "MNC_COMMON.h"
234
235 C !INPUT PARAMETERS:
236 integer indf, ind_fg_ids, myThid
237 character*(*) dname
238 CEOP
239
240 C !LOCAL VARIABLES:
241 integer i,j,k,l, n,n1, ngrid, ds,de
242
243 C Functions
244 integer ILNBLNK
245
246
247 ind_fg_ids = -1
248 n = ILNBLNK(dname)
249 ngrid = mnc_f_info(indf,3)
250 DO i = 1,ngrid
251 j = 4 + 3*(i - 1)
252 ds = mnc_f_info(indf,j+1)
253 de = mnc_f_info(indf,j+2)
254 DO k = ds,de
255 l = mnc_fd_ind(indf,k)
256 n1 = ILNBLNK(mnc_d_names(l))
257 IF ((n .EQ. n1)
258 & .AND. (mnc_d_names(l)(1:n1) .EQ. dname(1:n))) THEN
259 ind_fg_ids = k
260 RETURN
261 ENDIF
262 ENDDO
263 ENDDO
264 RETURN
265 END
266
267 C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|

  ViewVC Help
Powered by ViewVC 1.1.22