1 |
C $Header: /u/gcmpack/MITgcm/pkg/mnc/mnc_cw_cvars.F,v 1.15 2009/06/28 01:08:25 jmc 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_CW_WRITE_CVAR |
9 |
|
10 |
C !INTERFACE: |
11 |
SUBROUTINE MNC_CW_WRITE_CVAR( |
12 |
I fname, |
13 |
I cvname, |
14 |
I fid, |
15 |
I did, |
16 |
I bi, bj, |
17 |
I myThid ) |
18 |
|
19 |
C !DESCRIPTION: |
20 |
C Write a CF-convention coordinate variable (a vector). |
21 |
|
22 |
C !USES: |
23 |
implicit none |
24 |
#include "MNC_COMMON.h" |
25 |
#include "SIZE.h" |
26 |
#include "EEPARAMS.h" |
27 |
#include "PARAMS.h" |
28 |
#include "GRID.h" |
29 |
#ifdef ALLOW_EXCH2 |
30 |
#include "W2_EXCH2_SIZE.h" |
31 |
#include "W2_EXCH2_TOPOLOGY.h" |
32 |
#endif |
33 |
#include "netcdf.inc" |
34 |
|
35 |
C Functions |
36 |
integer IFNBLNK, ILNBLNK |
37 |
|
38 |
C !INPUT PARAMETERS: |
39 |
character*(*) fname |
40 |
character*(*) cvname |
41 |
integer fid, did, bi,bj |
42 |
integer myThid |
43 |
CEOP |
44 |
|
45 |
C !LOCAL VARIABLES: |
46 |
integer i, vid, nnf, nnl, doit, err |
47 |
integer nids, cv_did(1), xtmin,ytmin |
48 |
character*(MAX_LEN_MBUF) msgbuf |
49 |
integer cv_start(1), cv_count(1) |
50 |
_RS rtmp(sNx + 2*OLx + sNy + 2*OLy + Nr) |
51 |
C variables for text attributes |
52 |
integer MAX_LEN_NAME, ia |
53 |
PARAMETER ( MAX_LEN_NAME = 128 ) |
54 |
character*(MAX_LEN_NAME) units, long_name, positive |
55 |
|
56 |
DO i=1,MAX_LEN_NAME |
57 |
units(i:i) = ' ' |
58 |
long_name(i:i) = ' ' |
59 |
positive(i:i) = ' ' |
60 |
ENDDO |
61 |
|
62 |
nnf = IFNBLNK(cvname) |
63 |
nnl = ILNBLNK(cvname) |
64 |
|
65 |
xtmin = 0 |
66 |
ytmin = 0 |
67 |
#ifdef ALLOW_EXCH2 |
68 |
xtmin = exch2_tbasex(W2_myTileList(bi,bj)) |
69 |
ytmin = exch2_tbasey(W2_myTileList(bi,bj)) |
70 |
#else |
71 |
IF ( .NOT. useCubedSphereExchange ) THEN |
72 |
C make sure for a non-cubed-sphere curvi-linear grid, |
73 |
C that the X/Y coordinate variables are monotonous |
74 |
C bi+(myXGlobalLo-1)/sNx is the i-tile number |
75 |
C bj+(myYGlobalLo-1)/sNy is the j-tile number |
76 |
xtmin = sNx * ( bi+(myXGlobalLo-1)/sNx - 1 ) |
77 |
ytmin = sNy * ( bj+(myYGlobalLo-1)/sNy - 1 ) |
78 |
ENDIF |
79 |
#endif |
80 |
doit = 1 |
81 |
nids = 1 |
82 |
cv_did(1)= did |
83 |
|
84 |
C Check all the coordinate variables that we know about |
85 |
IF (cvname(nnf:nnl) .EQ. 'X') THEN |
86 |
|
87 |
cv_start(1) = 1 |
88 |
cv_count(1) = sNx |
89 |
#ifdef ALLOW_EXCH2 |
90 |
DO i = cv_start(1),cv_count(1) |
91 |
rtmp(i) = xtmin + i |
92 |
ENDDO |
93 |
#else |
94 |
IF ( usingCurvilinearGrid .OR. rotateGrid ) THEN |
95 |
DO i = cv_start(1),cv_count(1) |
96 |
rtmp(i) = xtmin + i |
97 |
ENDDO |
98 |
ELSE |
99 |
DO i = cv_start(1),cv_count(1) |
100 |
rtmp(i) = xC(i,1,bi,bj) |
101 |
ENDDO |
102 |
ENDIF |
103 |
#endif |
104 |
IF ( usingCartesianGrid ) THEN |
105 |
long_name = 'X-coordinate of cell center' |
106 |
units = 'meters' |
107 |
ELSEIF ( usingCurvilinearGrid .OR. rotateGrid ) THEN |
108 |
long_name = 'i-index of cell center' |
109 |
units = 'none' |
110 |
ELSEIF ( usingSphericalPolarGrid ) THEN |
111 |
long_name = 'longitude of cell center' |
112 |
units = 'degrees_east' |
113 |
ELSEIF ( usingCylindricalGrid ) THEN |
114 |
long_name = 'polar angle coordinate of cell center' |
115 |
units = 'degrees' |
116 |
ELSE |
117 |
C unknown grid type |
118 |
print *, 'S/R MNC_CW_CVARS: Ooops, unknown horizontal grid!' |
119 |
ENDIF |
120 |
|
121 |
ELSEIF (cvname(nnf:nnl) .EQ. 'Xp1') THEN |
122 |
|
123 |
cv_start(1) = 1 |
124 |
cv_count(1) = sNx + 1 |
125 |
#ifdef ALLOW_EXCH2 |
126 |
DO i = cv_start(1),cv_count(1) |
127 |
rtmp(i) = xtmin + i |
128 |
ENDDO |
129 |
#else |
130 |
IF ( usingCurvilinearGrid .OR. rotateGrid ) THEN |
131 |
DO i = cv_start(1),cv_count(1) |
132 |
rtmp(i) = xtmin + i |
133 |
ENDDO |
134 |
ELSE |
135 |
DO i = cv_start(1),cv_count(1) |
136 |
rtmp(i) = xG(i,1,bi,bj) |
137 |
ENDDO |
138 |
ENDIF |
139 |
#endif |
140 |
IF ( usingCartesianGrid ) THEN |
141 |
long_name = 'X-Coordinate of cell corner' |
142 |
units = 'meters' |
143 |
ELSEIF ( usingCurvilinearGrid .OR. rotateGrid ) THEN |
144 |
long_name = 'i-index of cell corner' |
145 |
units = 'none' |
146 |
ELSEIF ( usingSphericalPolarGrid ) THEN |
147 |
long_name = 'longitude of cell corner' |
148 |
units = 'degrees_east' |
149 |
ELSEIF ( usingCylindricalGrid ) THEN |
150 |
long_name = 'polar angle of cell corner' |
151 |
units = 'degrees' |
152 |
ELSE |
153 |
C unknown grid type |
154 |
print *, 'S/R MNC_CW_CVARS: Ooops, unknown horizontal grid!' |
155 |
ENDIF |
156 |
|
157 |
ELSEIF (cvname(nnf:nnl) .EQ. 'Xwh') THEN |
158 |
|
159 |
cv_start(1) = 1 |
160 |
cv_count(1) = sNx + 2*OLx |
161 |
#ifdef ALLOW_EXCH2 |
162 |
DO i = cv_start(1),cv_count(1) |
163 |
rtmp(i) = xtmin + i |
164 |
ENDDO |
165 |
#else |
166 |
IF ( usingCurvilinearGrid .OR. rotateGrid ) THEN |
167 |
DO i = cv_start(1),cv_count(1) |
168 |
rtmp(i) = xtmin - OLx + i |
169 |
ENDDO |
170 |
ELSE |
171 |
DO i = cv_start(1),cv_count(1) |
172 |
rtmp(i) = xC(i,1,bi,bj) |
173 |
CML???? rtmp(i) = xC(i-Olx,1,bi,bj) |
174 |
ENDDO |
175 |
ENDIF |
176 |
#endif |
177 |
IF ( usingCartesianGrid ) THEN |
178 |
long_name = 'X-Coordinate of cell center including overlaps' |
179 |
units = 'meters' |
180 |
ELSEIF ( usingCurvilinearGrid .OR. rotateGrid ) THEN |
181 |
long_name = 'i-index of cell center including overlaps' |
182 |
units = 'none' |
183 |
ELSEIF ( usingSphericalPolarGrid ) THEN |
184 |
long_name = 'longitude of cell center including overlaps' |
185 |
units = 'degrees_east' |
186 |
ELSEIF ( usingCylindricalGrid ) THEN |
187 |
long_name = |
188 |
& 'polar angle coordinate of cell center including overlaps' |
189 |
units = 'degrees' |
190 |
ELSE |
191 |
C unknown grid type |
192 |
print *, 'S/R MNC_CW_CVARS: Ooops, unknown horizontal grid!' |
193 |
ENDIF |
194 |
|
195 |
ELSEIF (cvname(nnf:nnl) .EQ. 'Y') THEN |
196 |
|
197 |
cv_start(1) = 1 |
198 |
cv_count(1) = sNy |
199 |
#ifdef ALLOW_EXCH2 |
200 |
DO i = cv_start(1),cv_count(1) |
201 |
rtmp(i) = ytmin + i |
202 |
ENDDO |
203 |
#else |
204 |
IF ( usingCurvilinearGrid .OR. rotateGrid ) THEN |
205 |
DO i = cv_start(1),cv_count(1) |
206 |
rtmp(i) = ytmin + i |
207 |
ENDDO |
208 |
ELSE |
209 |
DO i = cv_start(1),cv_count(1) |
210 |
rtmp(i) = yC(1,i,bi,bj) |
211 |
ENDDO |
212 |
ENDIF |
213 |
#endif |
214 |
IF ( usingCartesianGrid ) THEN |
215 |
long_name = 'Y-Coordinate of cell center' |
216 |
units = 'meters' |
217 |
ELSEIF ( usingCurvilinearGrid .OR. rotateGrid ) THEN |
218 |
long_name = 'j-index of cell center' |
219 |
units = 'none' |
220 |
ELSEIF ( usingSphericalPolarGrid ) THEN |
221 |
long_name = 'latitude of cell center' |
222 |
units = 'degrees_north' |
223 |
ELSEIF ( usingCylindricalGrid ) THEN |
224 |
long_name = 'radial coordinate of cell center' |
225 |
units = 'meters' |
226 |
ELSE |
227 |
C unknown grid type |
228 |
print *, 'S/R MNC_CW_CVARS: Ooops, unknown horizontal grid!' |
229 |
ENDIF |
230 |
|
231 |
ELSEIF (cvname(nnf:nnl) .EQ. 'Yp1') THEN |
232 |
|
233 |
cv_start(1) = 1 |
234 |
cv_count(1) = sNy + 1 |
235 |
#ifdef ALLOW_EXCH2 |
236 |
DO i = cv_start(1),cv_count(1) |
237 |
rtmp(i) = ytmin + i |
238 |
ENDDO |
239 |
#else |
240 |
IF ( usingCurvilinearGrid .OR. rotateGrid ) THEN |
241 |
DO i = cv_start(1),cv_count(1) |
242 |
rtmp(i) = ytmin + i |
243 |
ENDDO |
244 |
ELSE |
245 |
DO i = cv_start(1),cv_count(1) |
246 |
rtmp(i) = yG(1,i,bi,bj) |
247 |
ENDDO |
248 |
ENDIF |
249 |
#endif |
250 |
IF ( usingCartesianGrid ) THEN |
251 |
long_name = 'Y-Coordinate of cell corner' |
252 |
units = 'meters' |
253 |
ELSEIF ( usingCurvilinearGrid .OR. rotateGrid ) THEN |
254 |
long_name = 'j-index of cell corner' |
255 |
units = 'none' |
256 |
ELSEIF ( usingSphericalPolarGrid ) THEN |
257 |
long_name = 'latitude of cell corner' |
258 |
units = 'degrees_north' |
259 |
ELSEIF ( usingCylindricalGrid ) THEN |
260 |
long_name = 'radial coordinate of cell corner' |
261 |
units = 'meters' |
262 |
ELSE |
263 |
C unknown grid type |
264 |
print *, 'S/R MNC_CW_CVARS: Ooops, unknown horizontal grid!' |
265 |
ENDIF |
266 |
|
267 |
ELSEIF (cvname(nnf:nnl) .EQ. 'Ywh') THEN |
268 |
|
269 |
cv_start(1) = 1 |
270 |
cv_count(1) = sNy + 2*OLy |
271 |
#ifdef ALLOW_EXCH2 |
272 |
DO i = cv_start(1),cv_count(1) |
273 |
rtmp(i) = ytmin + i |
274 |
ENDDO |
275 |
#else |
276 |
IF ( usingCurvilinearGrid .OR. rotateGrid ) THEN |
277 |
DO i = cv_start(1),cv_count(1) |
278 |
rtmp(i) = ytmin - OLy + i |
279 |
ENDDO |
280 |
ELSE |
281 |
DO i = cv_start(1),cv_count(1) |
282 |
rtmp(i) = yC(1,i-OLy,bi,bj) |
283 |
ENDDO |
284 |
ENDIF |
285 |
#endif |
286 |
IF ( usingCartesianGrid ) THEN |
287 |
long_name = 'Y-Coordinate of cell center including overlaps' |
288 |
units = 'meters' |
289 |
ELSEIF ( usingCurvilinearGrid .OR. rotateGrid ) THEN |
290 |
long_name = 'j-index of cell center including overlaps' |
291 |
units = 'none' |
292 |
ELSEIF ( usingSphericalPolarGrid ) THEN |
293 |
long_name = 'latitude of cell center including overlaps' |
294 |
units = 'degrees_north' |
295 |
ELSEIF ( usingCylindricalGrid ) THEN |
296 |
long_name = |
297 |
& 'radial coordinate of cell center including overlaps' |
298 |
units = 'meters' |
299 |
ELSE |
300 |
C unknown grid type |
301 |
print *, 'S/R MNC_CW_CVARS: Ooops, unknown horizontal grid!' |
302 |
ENDIF |
303 |
|
304 |
ELSEIF (cvname(nnf:nnl) .EQ. 'Z') THEN |
305 |
|
306 |
cv_start(1) = 1 |
307 |
cv_count(1) = Nr |
308 |
DO i = cv_start(1),cv_count(1) |
309 |
rtmp(i) = rC(i) |
310 |
ENDDO |
311 |
C |
312 |
long_name = 'vertical coordinate of cell center' |
313 |
IF ( usingZCoords ) THEN |
314 |
units = 'meters' |
315 |
positive = 'up' |
316 |
ELSEIF ( usingPCoords ) THEN |
317 |
units = 'pascal' |
318 |
ELSE |
319 |
C unknown grid type |
320 |
print *, 'S/R MNC_CW_CVARS: Ooops, unknown vertical grid!' |
321 |
ENDIF |
322 |
|
323 |
ELSEIF (cvname(nnf:nnl) .EQ. 'Zp1') THEN |
324 |
|
325 |
cv_start(1) = 1 |
326 |
cv_count(1) = Nr + 1 |
327 |
DO i = cv_start(1),cv_count(1) |
328 |
rtmp(i) = rF(i) |
329 |
ENDDO |
330 |
C |
331 |
long_name = 'vertical coordinate of cell interface' |
332 |
IF ( usingZCoords ) THEN |
333 |
units = 'meters' |
334 |
positive = 'up' |
335 |
ELSEIF ( usingPCoords ) THEN |
336 |
units = 'pascal' |
337 |
ELSE |
338 |
C unknown grid type |
339 |
print *, 'S/R MNC_CW_CVARS: Ooops, unknown vertical grid!' |
340 |
ENDIF |
341 |
|
342 |
ELSEIF (cvname(nnf:nnl) .EQ. 'Zu') THEN |
343 |
|
344 |
cv_start(1) = 1 |
345 |
cv_count(1) = Nr |
346 |
DO i = cv_start(1),cv_count(1) |
347 |
rtmp(i) = rF(i + 1) |
348 |
ENDDO |
349 |
C |
350 |
IF ( usingZCoords ) THEN |
351 |
long_name = 'vertical coordinate of lower cell interface' |
352 |
units = 'meters' |
353 |
positive = 'up' |
354 |
ELSEIF ( usingPCoords ) THEN |
355 |
long_name = 'vertical coordinate of upper cell interface' |
356 |
units = 'pascal' |
357 |
ELSE |
358 |
C unknown grid type |
359 |
print *, 'S/R MNC_CW_CVARS: Ooops, unknown vertical grid!' |
360 |
ENDIF |
361 |
|
362 |
ELSEIF (cvname(nnf:nnl) .EQ. 'Zl') THEN |
363 |
|
364 |
cv_start(1) = 1 |
365 |
cv_count(1) = Nr |
366 |
DO i = cv_start(1),cv_count(1) |
367 |
rtmp(i) = rF(i) |
368 |
ENDDO |
369 |
C |
370 |
IF ( usingZCoords ) THEN |
371 |
long_name = 'vertical coordinate of upper cell interface' |
372 |
units = 'meters' |
373 |
positive = 'up' |
374 |
ELSEIF ( usingPCoords ) THEN |
375 |
long_name = 'vertical coordinate of lower cell interface' |
376 |
units = 'pascal' |
377 |
ELSE |
378 |
C unknown grid type |
379 |
print *, 'S/R MNC_CW_CVARS: Ooops, unknown vertical grid!' |
380 |
ENDIF |
381 |
|
382 |
ELSEIF (cvname(nnf:nnl) .EQ. 'Zm1') THEN |
383 |
|
384 |
cv_start(1) = 1 |
385 |
cv_count(1) = Nr - 1 |
386 |
DO i = cv_start(1),cv_count(1) |
387 |
rtmp(i) = rF(i + 1) |
388 |
ENDDO |
389 |
C |
390 |
IF ( usingZCoords ) THEN |
391 |
long_name = 'vertical coordinate of lower cell interface' |
392 |
units = 'meters' |
393 |
positive = 'up' |
394 |
ELSEIF ( usingPCoords ) THEN |
395 |
long_name = 'vertical coordinate of upper cell interface' |
396 |
units = 'pascal' |
397 |
ELSE |
398 |
C unknown grid type |
399 |
print *, 'S/R MNC_CW_CVARS: Ooops, unknown vertical grid!' |
400 |
ENDIF |
401 |
|
402 |
ELSE |
403 |
|
404 |
doit = 0 |
405 |
|
406 |
ENDIF |
407 |
|
408 |
IF ( doit .EQ. 1 ) THEN |
409 |
|
410 |
CALL MNC_FILE_REDEF(fname, myThid) |
411 |
#ifdef REAL4_IS_SLOW |
412 |
err = NF_DEF_VAR(fid, cvname, NF_DOUBLE, |
413 |
& nids, cv_did, vid) |
414 |
#else |
415 |
err = NF_DEF_VAR(fid, cvname, NF_FLOAT, |
416 |
& nids, cv_did, vid) |
417 |
#endif /* REAL4_IS_SLOW */ |
418 |
i = ILNBLNK( fname ) |
419 |
write(msgbuf,'(5a)') 'defining coordinate variable ''', |
420 |
& cvname(nnf:nnl), ''' in file ''', fname(1:i), '''' |
421 |
CALL MNC_HANDLE_ERR(err, msgbuf, myThid) |
422 |
C add attributes if set |
423 |
ia = ILNBLNK(long_name) |
424 |
IF ( ia .GT. 0 ) THEN |
425 |
err = NF_PUT_ATT_TEXT(fid, vid, 'long_name', ia, long_name) |
426 |
write(msgbuf,'(5a)') |
427 |
& 'adding attribute ''long_name'' to coordinate variable ''', |
428 |
& cvname(nnf:nnl), ''' in file ''', fname(1:i), '''' |
429 |
CALL MNC_HANDLE_ERR(err, msgbuf, myThid) |
430 |
ENDIF |
431 |
ia = ILNBLNK(units) |
432 |
IF ( ia .GT. 0 ) THEN |
433 |
err = NF_PUT_ATT_TEXT(fid, vid, 'units', ia, units) |
434 |
write(msgbuf,'(5a)') |
435 |
& 'adding attribute ''units'' to coordinate variable ''', |
436 |
& cvname(nnf:nnl), ''' in file ''', fname(1:i), '''' |
437 |
CALL MNC_HANDLE_ERR(err, msgbuf, myThid) |
438 |
ENDIF |
439 |
ia = ILNBLNK(positive) |
440 |
IF ( ia .GT. 0 ) THEN |
441 |
err = NF_PUT_ATT_TEXT(fid, vid, 'positive', ia, positive) |
442 |
write(msgbuf,'(5a)') |
443 |
& 'adding attribute ''positive'' to coordinate variable ''', |
444 |
& cvname(nnf:nnl), ''' in file ''', fname(1:i), '''' |
445 |
CALL MNC_HANDLE_ERR(err, msgbuf, myThid) |
446 |
ENDIF |
447 |
C |
448 |
CALL MNC_FILE_ENDDEF(fname, myThid) |
449 |
#ifdef REAL4_IS_SLOW |
450 |
err = NF_PUT_VARA_DOUBLE(fid, vid, |
451 |
& cv_start, cv_count, rtmp) |
452 |
#else |
453 |
err = NF_PUT_VARA_REAL(fid, vid, |
454 |
& cv_start, cv_count, rtmp) |
455 |
#endif /* REAL4_IS_SLOW */ |
456 |
write(msgbuf,'(5a)') 'writing coordinate variable ''', |
457 |
& cvname(nnf:nnl), ''' in file ''', fname(1:i), '''' |
458 |
CALL MNC_HANDLE_ERR(err, msgbuf, myThid) |
459 |
|
460 |
ENDIF |
461 |
|
462 |
RETURN |
463 |
END |
464 |
|
465 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
466 |
|