1 |
C $Header: /u/gcmpack/MITgcm/pkg/mdsio/mdsio_gl_slice.F,v 1.4 2003/10/09 04:19:19 edhill Exp $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "MDSIO_OPTIONS.h" |
5 |
|
6 |
C The five "public" routines supplied here are: |
7 |
C |
8 |
C MDSREADFIELD - read model field from direct access global or tiled MDS file |
9 |
C MDSWRITEFIELD - write model field to direct access global or tiled MDS file |
10 |
C MDSFINDUNIT - returns an available (unused) I/O channel |
11 |
C MDSREADVECTOR - read vector from direct access global or tiled MDS file |
12 |
C MDSWRITEVECTOR - write vector to direct access global or tiled MDS file |
13 |
C |
14 |
C all other routines are "private" to these utilities and ought |
15 |
C not be accessed directly from the main code. |
16 |
C |
17 |
C Created: 03/16/99 adcroft@mit.edu |
18 |
C Modified: 03/23/99 adcroft@mit.edu |
19 |
C To work with multiple records |
20 |
C Modified: 03/29/99 eckert@mit.edu |
21 |
C Added arbitrary vector capability |
22 |
C Modified: 07/27/99 eckert@mit.edu |
23 |
C Customized for state estimation (--> active_file_control.F) |
24 |
C this relates only to *mdsreadvector* and *mdswritevector* |
25 |
C Modified: 07/28/99 eckert@mit.edu |
26 |
C inserted calls to *print_message* and *print_error* |
27 |
C |
28 |
C To be modified to work with MITgcmuv message routines. |
29 |
|
30 |
C======================================================================= |
31 |
SUBROUTINE MDSREADFIELD_XZ_GL( |
32 |
I fName, |
33 |
I filePrec, |
34 |
I arrType, |
35 |
I nNz, |
36 |
O arr_gl, |
37 |
I irecord, |
38 |
I myThid ) |
39 |
C |
40 |
C Arguments: |
41 |
C |
42 |
C fName string base name for file to read |
43 |
C filePrec integer number of bits per word in file (32 or 64) |
44 |
C arrType char(2) declaration of "arr": either "RS" or "RL" |
45 |
C nNz integer size of third dimension: normally either 1 or Nr |
46 |
C arr RS/RL array to read into, arr(:,:,nNz,:,:) |
47 |
C irecord integer record number to read |
48 |
C myThid integer thread identifier |
49 |
C |
50 |
C MDSREADFIELD first checks to see if the file "fName" exists, then |
51 |
C if the file "fName.data" exists and finally the tiled files of the |
52 |
C form "fName.xxx.yyy.data" exist. Currently, the meta-files are not |
53 |
C read because it is difficult to parse files in fortran. |
54 |
C The precision of the file is decsribed by filePrec, set either |
55 |
C to floatPrec32 or floatPrec64. The precision or declaration of |
56 |
C the array argument must be consistently described by the char*(2) |
57 |
C string arrType, either "RS" or "RL". nNz allows for both 2-D and |
58 |
C 3-D arrays to be handled. nNz=1 implies a 2-D model field and |
59 |
C nNz=Nr implies a 3-D model field. irecord is the record number |
60 |
C to be read and must be >= 1. The file data is stored in |
61 |
C arr *but* the overlaps are *not* updated. ie. An exchange must |
62 |
C be called. This is because the routine is sometimes called from |
63 |
C within a MASTER_THID region. |
64 |
C |
65 |
C Created: 03/16/99 adcroft@mit.edu |
66 |
|
67 |
implicit none |
68 |
C Global variables / common blocks |
69 |
#include "SIZE.h" |
70 |
#include "EEPARAMS.h" |
71 |
#include "PARAMS.h" |
72 |
|
73 |
C Routine arguments |
74 |
character*(*) fName |
75 |
integer filePrec |
76 |
character*(2) arrType |
77 |
integer nNz |
78 |
_RL arr_gl(sNx,nSx,nPx,nSy,nPy,Nr) |
79 |
integer irecord |
80 |
integer myThid |
81 |
C Functions |
82 |
integer ILNBLNK |
83 |
integer MDS_RECLEN |
84 |
C Local variables |
85 |
character*(80) dataFName |
86 |
integer ip,jp,iG,jG,irec,bi,bj,ii,k,dUnit,IL |
87 |
logical exst |
88 |
_RL arr(1-oLx:sNx+oLx,Nr,nSx,nSy) |
89 |
Real*4 r4seg(sNx) |
90 |
Real*8 r8seg(sNx) |
91 |
logical globalFile,fileIsOpen |
92 |
integer length_of_rec |
93 |
character*(max_len_mbuf) msgbuf |
94 |
C ------------------------------------------------------------------ |
95 |
|
96 |
C Only do I/O if I am the master thread |
97 |
_BEGIN_MASTER( myThid ) |
98 |
|
99 |
C Record number must be >= 1 |
100 |
if (irecord .LT. 1) then |
101 |
write(msgbuf,'(a,i9.8)') |
102 |
& ' MDSREADFIELD_GL: argument irecord = ',irecord |
103 |
call print_message( msgbuf, standardmessageunit, |
104 |
& SQUEEZE_RIGHT , mythid) |
105 |
write(msgbuf,'(a)') |
106 |
& ' MDSREADFIELD_GL: Invalid value for irecord' |
107 |
call print_error( msgbuf, mythid ) |
108 |
stop 'ABNORMAL END: S/R MDSREADFIELD_GL' |
109 |
endif |
110 |
|
111 |
C Assume nothing |
112 |
globalFile = .FALSE. |
113 |
fileIsOpen = .FALSE. |
114 |
IL=ILNBLNK( fName ) |
115 |
|
116 |
C Assign a free unit number as the I/O channel for this routine |
117 |
call MDSFINDUNIT( dUnit, mythid ) |
118 |
|
119 |
C Check first for global file with simple name (ie. fName) |
120 |
dataFName = fName |
121 |
inquire( file=dataFname, exist=exst ) |
122 |
if (exst) then |
123 |
write(msgbuf,'(a,a)') |
124 |
& ' MDSREADFIELD: opening global file: ',dataFName |
125 |
call print_message( msgbuf, standardmessageunit, |
126 |
& SQUEEZE_RIGHT , mythid) |
127 |
stop " xx, adxx, weights and masks are not supposed to be global" |
128 |
endif |
129 |
|
130 |
C If negative check for global file with MDS name (ie. fName.data) |
131 |
if (.NOT. globalFile) then |
132 |
write(dataFname(1:80),'(2a)') fName(1:IL),'.data' |
133 |
inquire( file=dataFname, exist=exst ) |
134 |
if (exst) then |
135 |
write(msgbuf,'(a,a)') |
136 |
& ' MDSREADFIELD_XZ_GL: opening global file: ',dataFName |
137 |
call print_message( msgbuf, standardmessageunit, |
138 |
& SQUEEZE_RIGHT , mythid) |
139 |
globalFile = .TRUE. |
140 |
stop " xx, adxx, weights and masks are not supposed to be global" |
141 |
endif |
142 |
endif |
143 |
|
144 |
C Loop over all processors |
145 |
do jp=1,nPy |
146 |
do ip=1,nPx |
147 |
C Loop over all tiles |
148 |
do bj=1,nSy |
149 |
do bi=1,nSx |
150 |
C If we are reading from a tiled MDS file then we open each one here |
151 |
if (.NOT. globalFile) then |
152 |
iG=bi+(ip-1)*nsx ! Kludge until unstructered tiles |
153 |
jG=bj+(jp-1)*nsy ! Kludge until unstructered tiles |
154 |
write(dataFname(1:80),'(2a,i3.3,a,i3.3,a)') |
155 |
& fName(1:IL),'.',iG,'.',jG,'.data' |
156 |
inquire( file=dataFname, exist=exst ) |
157 |
C Of course, we only open the file if the tile is "active" |
158 |
C (This is a place-holder for the active/passive mechanism |
159 |
if (exst) then |
160 |
if ( debugLevel .GE. debLevA ) then |
161 |
write(msgbuf,'(a,a)') |
162 |
& ' MDSREADFIELD_XZ_GL: opening file: ',dataFName |
163 |
call print_message( msgbuf, standardmessageunit, |
164 |
& SQUEEZE_RIGHT , mythid) |
165 |
endif |
166 |
length_of_rec=MDS_RECLEN( filePrec, sNx, mythid ) |
167 |
open( dUnit, file=dataFName, status='old', |
168 |
& access='direct', recl=length_of_rec ) |
169 |
fileIsOpen=.TRUE. |
170 |
else |
171 |
fileIsOpen=.FALSE. |
172 |
write(msgbuf,'(a,a)') |
173 |
& ' MDSREADFIELD_XZ_GL: filename: ',dataFName |
174 |
call print_message( msgbuf, standardmessageunit, |
175 |
& SQUEEZE_RIGHT , mythid) |
176 |
write(msgbuf,'(a)') |
177 |
& ' MDSREADFIELD_XZ_GL: File does not exist' |
178 |
call print_error( msgbuf, mythid ) |
179 |
stop 'ABNORMAL END: S/R MDSREADFIELD_GL' |
180 |
endif |
181 |
endif |
182 |
|
183 |
if (fileIsOpen) then |
184 |
do k=1,Nr |
185 |
iG = 0 |
186 |
jG = 0 |
187 |
irec=k + Nr*(irecord-1) |
188 |
if (filePrec .eq. precFloat32) then |
189 |
read(dUnit,rec=irec) r4seg |
190 |
#ifdef _BYTESWAPIO |
191 |
call MDS_BYTESWAPR4( sNx, r4seg ) |
192 |
#endif |
193 |
if (arrType .eq. 'RS') then |
194 |
call MDS_SEG4toRS_2D(sNx,oLx,nNz,bi,bj,k,.TRUE.,r4seg,arr) |
195 |
elseif (arrType .eq. 'RL') then |
196 |
call MDS_SEG4toRL_2D(sNx,oLx,nNz,bi,bj,k,.TRUE.,r4seg,arr) |
197 |
else |
198 |
write(msgbuf,'(a)') |
199 |
& ' MDSREADFIELD_XZ_GL: illegal value for arrType' |
200 |
call print_error( msgbuf, mythid ) |
201 |
stop 'ABNORMAL END: S/R MDSREADFIELD_XZ_GL' |
202 |
endif |
203 |
elseif (filePrec .eq. precFloat64) then |
204 |
read(dUnit,rec=irec) r8seg |
205 |
#ifdef _BYTESWAPIO |
206 |
call MDS_BYTESWAPR8( sNx, r8seg ) |
207 |
#endif |
208 |
if (arrType .eq. 'RS') then |
209 |
call MDS_SEG8toRS_2D(sNx,oLx,nNz,bi,bj,k,.TRUE.,r8seg,arr) |
210 |
elseif (arrType .eq. 'RL') then |
211 |
call MDS_SEG8toRL_2D(sNx,oLx,nNz,bi,bj,k,.TRUE.,r8seg,arr) |
212 |
else |
213 |
write(msgbuf,'(a)') |
214 |
& ' MDSREADFIELD_XZ_GL: illegal value for arrType' |
215 |
call print_error( msgbuf, mythid ) |
216 |
stop 'ABNORMAL END: S/R MDSREADFIELD_XZ_GL' |
217 |
endif |
218 |
else |
219 |
write(msgbuf,'(a)') |
220 |
& ' MDSREADFIELD_XZ_GL: illegal value for filePrec' |
221 |
call print_error( msgbuf, mythid ) |
222 |
stop 'ABNORMAL END: S/R MDSREADFIELD_XZ_GL' |
223 |
endif |
224 |
do ii=1,sNx |
225 |
arr_gl(ii,bi,ip,bj,jp,k)=arr(ii,k,bi,bj) |
226 |
enddo |
227 |
|
228 |
C End of k loop |
229 |
enddo |
230 |
if (.NOT. globalFile) then |
231 |
close( dUnit ) |
232 |
fileIsOpen = .FALSE. |
233 |
endif |
234 |
endif |
235 |
C End of bi,bj loops |
236 |
enddo |
237 |
enddo |
238 |
C End of ip,jp loops |
239 |
enddo |
240 |
enddo |
241 |
|
242 |
C If global file was opened then close it |
243 |
if (fileIsOpen .AND. globalFile) then |
244 |
close( dUnit ) |
245 |
fileIsOpen = .FALSE. |
246 |
endif |
247 |
|
248 |
_END_MASTER( myThid ) |
249 |
|
250 |
C ------------------------------------------------------------------ |
251 |
return |
252 |
end |
253 |
C======================================================================= |
254 |
|
255 |
C======================================================================= |
256 |
SUBROUTINE MDSREADFIELD_YZ_GL( |
257 |
I fName, |
258 |
I filePrec, |
259 |
I arrType, |
260 |
I nNz, |
261 |
O arr_gl, |
262 |
I irecord, |
263 |
I myThid ) |
264 |
C |
265 |
C Arguments: |
266 |
C |
267 |
C fName string base name for file to read |
268 |
C filePrec integer number of bits per word in file (32 or 64) |
269 |
C arrType char(2) declaration of "arr": either "RS" or "RL" |
270 |
C nNz integer size of third dimension: normally either 1 or Nr |
271 |
C arr RS/RL array to read into, arr(:,:,nNz,:,:) |
272 |
C irecord integer record number to read |
273 |
C myThid integer thread identifier |
274 |
C |
275 |
C MDSREADFIELD first checks to see if the file "fName" exists, then |
276 |
C if the file "fName.data" exists and finally the tiled files of the |
277 |
C form "fName.xxx.yyy.data" exist. Currently, the meta-files are not |
278 |
C read because it is difficult to parse files in fortran. |
279 |
C The precision of the file is decsribed by filePrec, set either |
280 |
C to floatPrec32 or floatPrec64. The precision or declaration of |
281 |
C the array argument must be consistently described by the char*(2) |
282 |
C string arrType, either "RS" or "RL". nNz allows for both 2-D and |
283 |
C 3-D arrays to be handled. nNz=1 implies a 2-D model field and |
284 |
C nNz=Nr implies a 3-D model field. irecord is the record number |
285 |
C to be read and must be >= 1. The file data is stored in |
286 |
C arr *but* the overlaps are *not* updated. ie. An exchange must |
287 |
C be called. This is because the routine is sometimes called from |
288 |
C within a MASTER_THID region. |
289 |
C |
290 |
C Created: 03/16/99 adcroft@mit.edu |
291 |
|
292 |
implicit none |
293 |
C Global variables / common blocks |
294 |
#include "SIZE.h" |
295 |
#include "EEPARAMS.h" |
296 |
#include "PARAMS.h" |
297 |
|
298 |
C Routine arguments |
299 |
character*(*) fName |
300 |
integer filePrec |
301 |
character*(2) arrType |
302 |
integer nNz |
303 |
_RL arr_gl(nSx,nPx,sNy,nSy,nPy,Nr) |
304 |
integer irecord |
305 |
integer myThid |
306 |
C Functions |
307 |
integer ILNBLNK |
308 |
integer MDS_RECLEN |
309 |
C Local variables |
310 |
character*(80) dataFName |
311 |
integer ip,jp,iG,jG,irec,bi,bj,jj,k,dUnit,IL |
312 |
logical exst |
313 |
_RL arr(1-oLy:sNy+oLy,Nr,nSx,nSy) |
314 |
Real*4 r4seg(sNy) |
315 |
Real*8 r8seg(sNy) |
316 |
logical globalFile,fileIsOpen |
317 |
integer length_of_rec |
318 |
character*(max_len_mbuf) msgbuf |
319 |
C ------------------------------------------------------------------ |
320 |
|
321 |
C Only do I/O if I am the master thread |
322 |
_BEGIN_MASTER( myThid ) |
323 |
|
324 |
C Record number must be >= 1 |
325 |
if (irecord .LT. 1) then |
326 |
write(msgbuf,'(a,i9.8)') |
327 |
& ' MDSREADFIELD_YZ_GL: argument irecord = ',irecord |
328 |
call print_message( msgbuf, standardmessageunit, |
329 |
& SQUEEZE_RIGHT , mythid) |
330 |
write(msgbuf,'(a)') |
331 |
& ' MDSREADFIELD_YZ_GL: Invalid value for irecord' |
332 |
call print_error( msgbuf, mythid ) |
333 |
stop 'ABNORMAL END: S/R MDSREADFIELD_YZ_GL' |
334 |
endif |
335 |
|
336 |
C Assume nothing |
337 |
globalFile = .FALSE. |
338 |
fileIsOpen = .FALSE. |
339 |
IL=ILNBLNK( fName ) |
340 |
|
341 |
C Assign a free unit number as the I/O channel for this routine |
342 |
call MDSFINDUNIT( dUnit, mythid ) |
343 |
|
344 |
C Check first for global file with simple name (ie. fName) |
345 |
dataFName = fName |
346 |
inquire( file=dataFname, exist=exst ) |
347 |
if (exst) then |
348 |
write(msgbuf,'(a,a)') |
349 |
& ' MDSREADFIELD_YZ: opening global file: ',dataFName |
350 |
call print_message( msgbuf, standardmessageunit, |
351 |
& SQUEEZE_RIGHT , mythid) |
352 |
stop " xx, adxx, weights and masks are not supposed to be global" |
353 |
endif |
354 |
|
355 |
C If negative check for global file with MDS name (ie. fName.data) |
356 |
if (.NOT. globalFile) then |
357 |
write(dataFname(1:80),'(2a)') fName(1:IL),'.data' |
358 |
inquire( file=dataFname, exist=exst ) |
359 |
if (exst) then |
360 |
write(msgbuf,'(a,a)') |
361 |
& ' MDSREADFIELD_YZ_GL: opening global file: ',dataFName |
362 |
call print_message( msgbuf, standardmessageunit, |
363 |
& SQUEEZE_RIGHT , mythid) |
364 |
globalFile = .TRUE. |
365 |
stop " xx, adxx, weights and masks are not supposed to be global" |
366 |
endif |
367 |
endif |
368 |
C Loop over all processors |
369 |
do jp=1,nPy |
370 |
do ip=1,nPx |
371 |
C Loop over all tiles |
372 |
do bj=1,nSy |
373 |
do bi=1,nSx |
374 |
C If we are reading from a tiled MDS file then we open each one here |
375 |
if (.NOT. globalFile) then |
376 |
iG=bi+(ip-1)*nsx ! Kludge until unstructered tiles |
377 |
jG=bj+(jp-1)*nsy ! Kludge until unstructered tiles |
378 |
write(dataFname(1:80),'(2a,i3.3,a,i3.3,a)') |
379 |
& fName(1:IL),'.',iG,'.',jG,'.data' |
380 |
inquire( file=dataFname, exist=exst ) |
381 |
C Of course, we only open the file if the tile is "active" |
382 |
C (This is a place-holder for the active/passive mechanism |
383 |
if (exst) then |
384 |
if ( debugLevel .GE. debLevA ) then |
385 |
write(msgbuf,'(a,a)') |
386 |
& ' MDSREADFIELD_YZ_GL: opening file: ',dataFName |
387 |
call print_message( msgbuf, standardmessageunit, |
388 |
& SQUEEZE_RIGHT , mythid) |
389 |
endif |
390 |
length_of_rec=MDS_RECLEN( filePrec, sNy, mythid ) |
391 |
open( dUnit, file=dataFName, status='old', |
392 |
& access='direct', recl=length_of_rec ) |
393 |
fileIsOpen=.TRUE. |
394 |
else |
395 |
fileIsOpen=.FALSE. |
396 |
write(msgbuf,'(a,a)') |
397 |
& ' MDSREADFIELD_YZ_GL: filename: ',dataFName |
398 |
call print_message( msgbuf, standardmessageunit, |
399 |
& SQUEEZE_RIGHT , mythid) |
400 |
write(msgbuf,'(a)') |
401 |
& ' MDSREADFIELD_YZ_GL: File does not exist' |
402 |
call print_error( msgbuf, mythid ) |
403 |
stop 'ABNORMAL END: S/R MDSREADFIELD_YZ_GL' |
404 |
endif |
405 |
endif |
406 |
|
407 |
if (fileIsOpen) then |
408 |
do k=1,Nr |
409 |
iG = 0 |
410 |
jG = 0 |
411 |
irec=k + Nr*(irecord-1) |
412 |
if (filePrec .eq. precFloat32) then |
413 |
read(dUnit,rec=irec) r4seg |
414 |
#ifdef _BYTESWAPIO |
415 |
call MDS_BYTESWAPR4( sNy, r4seg ) |
416 |
#endif |
417 |
if (arrType .eq. 'RS') then |
418 |
call MDS_SEG4toRS_2D(sNy,oLy,nNz,bi,bj,k,.TRUE.,r4seg,arr) |
419 |
elseif (arrType .eq. 'RL') then |
420 |
call MDS_SEG4toRL_2D(sNy,oLy,nNz,bi,bj,k,.TRUE.,r4seg,arr) |
421 |
else |
422 |
write(msgbuf,'(a)') |
423 |
& ' MDSREADFIELD_YZ_GL: illegal value for arrType' |
424 |
call print_error( msgbuf, mythid ) |
425 |
stop 'ABNORMAL END: S/R MDSREADFIELD_YZ_GL' |
426 |
endif |
427 |
elseif (filePrec .eq. precFloat64) then |
428 |
read(dUnit,rec=irec) r8seg |
429 |
#ifdef _BYTESWAPIO |
430 |
call MDS_BYTESWAPR8( sNy, r8seg ) |
431 |
#endif |
432 |
if (arrType .eq. 'RS') then |
433 |
call MDS_SEG8toRS_2D(sNy,oLy,nNz,bi,bj,k,.TRUE.,r8seg,arr) |
434 |
elseif (arrType .eq. 'RL') then |
435 |
call MDS_SEG8toRL_2D(sNy,oLy,nNz,bi,bj,k,.TRUE.,r8seg,arr) |
436 |
else |
437 |
write(msgbuf,'(a)') |
438 |
& ' MDSREADFIELD_YZ_GL: illegal value for arrType' |
439 |
call print_error( msgbuf, mythid ) |
440 |
stop 'ABNORMAL END: S/R MDSREADFIELD_YZ_GL' |
441 |
endif |
442 |
else |
443 |
write(msgbuf,'(a)') |
444 |
& ' MDSREADFIELD_YZ_GL: illegal value for filePrec' |
445 |
call print_error( msgbuf, mythid ) |
446 |
stop 'ABNORMAL END: S/R MDSREADFIELD_YZ_GL' |
447 |
endif |
448 |
do jj=1,sNy |
449 |
arr_gl(bi,ip,jj,bj,jp,k)=arr(jj,k,bi,bj) |
450 |
enddo |
451 |
|
452 |
C End of k loop |
453 |
enddo |
454 |
if (.NOT. globalFile) then |
455 |
close( dUnit ) |
456 |
fileIsOpen = .FALSE. |
457 |
endif |
458 |
endif |
459 |
C End of bi,bj loops |
460 |
enddo |
461 |
enddo |
462 |
C End of ip,jp loops |
463 |
enddo |
464 |
enddo |
465 |
|
466 |
C If global file was opened then close it |
467 |
if (fileIsOpen .AND. globalFile) then |
468 |
close( dUnit ) |
469 |
fileIsOpen = .FALSE. |
470 |
endif |
471 |
|
472 |
_END_MASTER( myThid ) |
473 |
|
474 |
C ------------------------------------------------------------------ |
475 |
return |
476 |
end |
477 |
C======================================================================= |
478 |
|
479 |
C======================================================================= |
480 |
SUBROUTINE MDSWRITEFIELD_XZ_GL( |
481 |
I fName, |
482 |
I filePrec, |
483 |
I arrType, |
484 |
I nNz, |
485 |
I arr_gl, |
486 |
I irecord, |
487 |
I myIter, |
488 |
I myThid ) |
489 |
C |
490 |
C Arguments: |
491 |
C |
492 |
C fName string base name for file to written |
493 |
C filePrec integer number of bits per word in file (32 or 64) |
494 |
C arrType char(2) declaration of "arr": either "RS" or "RL" |
495 |
C nNz integer size of third dimension: normally either 1 or Nr |
496 |
C arr RS/RL array to write, arr(:,:,nNz,:,:) |
497 |
C irecord integer record number to read |
498 |
C myIter integer time step number |
499 |
C myThid integer thread identifier |
500 |
C |
501 |
C MDSWRITEFIELD creates either a file of the form "fName.data" and |
502 |
C "fName.meta" if the logical flag "globalFile" is set true. Otherwise |
503 |
C it creates MDS tiled files of the form "fName.xxx.yyy.data" and |
504 |
C "fName.xxx.yyy.meta". A meta-file is always created. |
505 |
C Currently, the meta-files are not read because it is difficult |
506 |
C to parse files in fortran. We should read meta information before |
507 |
C adding records to an existing multi-record file. |
508 |
C The precision of the file is decsribed by filePrec, set either |
509 |
C to floatPrec32 or floatPrec64. The precision or declaration of |
510 |
C the array argument must be consistently described by the char*(2) |
511 |
C string arrType, either "RS" or "RL". nNz allows for both 2-D and |
512 |
C 3-D arrays to be handled. nNz=1 implies a 2-D model field and |
513 |
C nNz=Nr implies a 3-D model field. irecord is the record number |
514 |
C to be read and must be >= 1. NOTE: It is currently assumed that |
515 |
C the highest record number in the file was the last record written. |
516 |
C Nor is there a consistency check between the routine arguments and file. |
517 |
C ie. if your write record 2 after record 4 the meta information |
518 |
C will record the number of records to be 2. This, again, is because |
519 |
C we have read the meta information. To be fixed. |
520 |
C |
521 |
C Created: 03/16/99 adcroft@mit.edu |
522 |
C |
523 |
C Changed: 05/31/00 heimbach@mit.edu |
524 |
C open(dUnit, ..., status='old', ... -> status='unknown' |
525 |
|
526 |
implicit none |
527 |
C Global variables / common blocks |
528 |
#include "SIZE.h" |
529 |
#include "EEPARAMS.h" |
530 |
#include "PARAMS.h" |
531 |
|
532 |
C Routine arguments |
533 |
character*(*) fName |
534 |
integer filePrec |
535 |
character*(2) arrType |
536 |
integer nNz |
537 |
cph( |
538 |
cph Real arr(*) |
539 |
_RL arr_gl(sNx,nSx,nPx,nSy,nPy,Nr) |
540 |
cph) |
541 |
integer irecord |
542 |
integer myIter |
543 |
integer myThid |
544 |
C Functions |
545 |
integer ILNBLNK |
546 |
integer MDS_RECLEN |
547 |
C Local variables |
548 |
character*(80) dataFName,metaFName |
549 |
integer ip,jp,iG,jG,irec,bi,bj,ii,k,dUnit,IL |
550 |
Real*4 r4seg(sNx) |
551 |
Real*8 r8seg(sNx) |
552 |
_RL arr(1-oLx:sNx+oLx,Nr,nSx,nSy) |
553 |
integer dimList(3,3),ndims |
554 |
integer length_of_rec |
555 |
logical fileIsOpen |
556 |
character*(max_len_mbuf) msgbuf |
557 |
C ------------------------------------------------------------------ |
558 |
|
559 |
C Only do I/O if I am the master thread |
560 |
_BEGIN_MASTER( myThid ) |
561 |
|
562 |
C Record number must be >= 1 |
563 |
if (irecord .LT. 1) then |
564 |
write(msgbuf,'(a,i9.8)') |
565 |
& ' MDSWRITEFIELD_XZ_GL: argument irecord = ',irecord |
566 |
call print_message( msgbuf, standardmessageunit, |
567 |
& SQUEEZE_RIGHT , mythid) |
568 |
write(msgbuf,'(a)') |
569 |
& ' MDSWRITEFIELD_XZ_GL: invalid value for irecord' |
570 |
call print_error( msgbuf, mythid ) |
571 |
stop 'ABNORMAL END: S/R MDSWRITEFIELD_XZ_GL' |
572 |
endif |
573 |
|
574 |
C Assume nothing |
575 |
fileIsOpen=.FALSE. |
576 |
IL=ILNBLNK( fName ) |
577 |
|
578 |
C Assign a free unit number as the I/O channel for this routine |
579 |
call MDSFINDUNIT( dUnit, mythid ) |
580 |
|
581 |
|
582 |
C Loop over all processors |
583 |
do jp=1,nPy |
584 |
do ip=1,nPx |
585 |
C Loop over all tiles |
586 |
do bj=1,nSy |
587 |
do bi=1,nSx |
588 |
C If we are writing to a tiled MDS file then we open each one here |
589 |
iG=bi+(ip-1)*nsx ! Kludge until unstructered tiles |
590 |
jG=bj+(jp-1)*nsy ! Kludge until unstructered tiles |
591 |
write(dataFname(1:80),'(2a,i3.3,a,i3.3,a)') |
592 |
& fName(1:IL),'.',iG,'.',jG,'.data' |
593 |
if (irecord .EQ. 1) then |
594 |
length_of_rec=MDS_RECLEN( filePrec, sNx, mythid ) |
595 |
open( dUnit, file=dataFName, status=_NEW_STATUS, |
596 |
& access='direct', recl=length_of_rec ) |
597 |
fileIsOpen=.TRUE. |
598 |
else |
599 |
length_of_rec=MDS_RECLEN( filePrec, sNx, mythid ) |
600 |
open( dUnit, file=dataFName, status=_OLD_STATUS, |
601 |
& access='direct', recl=length_of_rec ) |
602 |
fileIsOpen=.TRUE. |
603 |
endif |
604 |
if (fileIsOpen) then |
605 |
do k=1,Nr |
606 |
do ii=1,sNx |
607 |
arr(ii,k,bi,bj)=arr_gl(ii,bi,ip,bj,jp,k) |
608 |
enddo |
609 |
iG = 0 |
610 |
jG = 0 |
611 |
irec=k + Nr*(irecord-1) |
612 |
if (filePrec .eq. precFloat32) then |
613 |
if (arrType .eq. 'RS') then |
614 |
call MDS_SEG4toRS_2D(sNx,oLx,nNz,bi,bj,k,.FALSE.,r4seg,arr) |
615 |
elseif (arrType .eq. 'RL') then |
616 |
call MDS_SEG4toRL_2D(sNx,oLx,nNz,bi,bj,k,.FALSE.,r4seg,arr) |
617 |
else |
618 |
write(msgbuf,'(a)') |
619 |
& ' MDSWRITEFIELD_XZ_GL: illegal value for arrType' |
620 |
call print_error( msgbuf, mythid ) |
621 |
stop 'ABNORMAL END: S/R MDSWRITEFIELD_XZ_GL' |
622 |
endif |
623 |
#ifdef _BYTESWAPIO |
624 |
call MDS_BYTESWAPR4( sNx, r4seg ) |
625 |
#endif |
626 |
write(dUnit,rec=irec) r4seg |
627 |
elseif (filePrec .eq. precFloat64) then |
628 |
if (arrType .eq. 'RS') then |
629 |
call MDS_SEG8toRS_2D(sNx,oLx,nNz,bi,bj,k,.FALSE.,r8seg,arr) |
630 |
elseif (arrType .eq. 'RL') then |
631 |
call MDS_SEG8toRL_2D(sNx,oLx,nNz,bi,bj,k,.FALSE.,r8seg,arr) |
632 |
else |
633 |
write(msgbuf,'(a)') |
634 |
& ' MDSWRITEFIELD_XZ_GL: illegal value for arrType' |
635 |
call print_error( msgbuf, mythid ) |
636 |
stop 'ABNORMAL END: S/R MDSWRITEFIELD_XZ_GL' |
637 |
endif |
638 |
#ifdef _BYTESWAPIO |
639 |
call MDS_BYTESWAPR8( sNx, r8seg ) |
640 |
#endif |
641 |
write(dUnit,rec=irec) r8seg |
642 |
else |
643 |
write(msgbuf,'(a)') |
644 |
& ' MDSWRITEFIELD_XZ_GL: illegal value for filePrec' |
645 |
call print_error( msgbuf, mythid ) |
646 |
stop 'ABNORMAL END: S/R MDSWRITEFIELD_XZ_GL' |
647 |
endif |
648 |
C End of k loop |
649 |
enddo |
650 |
else |
651 |
write(msgbuf,'(a)') |
652 |
& ' MDSWRITEFIELD_XZ_GL: I should never get to this point' |
653 |
call print_error( msgbuf, mythid ) |
654 |
stop 'ABNORMAL END: S/R MDSWRITEFIELD_XZ_GL' |
655 |
endif |
656 |
C If we were writing to a tiled MDS file then we close it here |
657 |
if (fileIsOpen) then |
658 |
close( dUnit ) |
659 |
fileIsOpen = .FALSE. |
660 |
endif |
661 |
C Create meta-file for each tile if we are tiling |
662 |
iG=bi+(ip-1)*nsx ! Kludge until unstructered tiles |
663 |
jG=bj+(jp-1)*nsy ! Kludge until unstructered tiles |
664 |
write(metaFname(1:80),'(2a,i3.3,a,i3.3,a)') |
665 |
& fName(1:IL),'.',iG,'.',jG,'.meta' |
666 |
dimList(1,1)=Nx |
667 |
dimList(2,1)=((ip-1)*nSx+(bi-1))*sNx+1 |
668 |
dimList(3,1)=((ip-1)*nSx+bi)*sNx |
669 |
dimList(1,2)=nSy*nPy |
670 |
dimList(2,2)=(jp-1)*nSy+bj |
671 |
dimList(3,2)= jp*nSy+bj |
672 |
dimList(1,3)=Nr |
673 |
dimList(2,3)=1 |
674 |
dimList(3,3)=Nr |
675 |
ndims=3 |
676 |
if (Nr .EQ. 1) ndims=2 |
677 |
call MDSWRITEMETA( metaFName, dataFName, |
678 |
& filePrec, ndims, dimList, irecord, myIter, mythid ) |
679 |
C End of bi,bj loops |
680 |
enddo |
681 |
enddo |
682 |
C End of ip,jp loops |
683 |
enddo |
684 |
enddo |
685 |
|
686 |
|
687 |
_END_MASTER( myThid ) |
688 |
|
689 |
C ------------------------------------------------------------------ |
690 |
return |
691 |
end |
692 |
C======================================================================= |
693 |
|
694 |
C======================================================================= |
695 |
SUBROUTINE MDSWRITEFIELD_YZ_GL( |
696 |
I fName, |
697 |
I filePrec, |
698 |
I arrType, |
699 |
I nNz, |
700 |
I arr_gl, |
701 |
I irecord, |
702 |
I myIter, |
703 |
I myThid ) |
704 |
C |
705 |
C Arguments: |
706 |
C |
707 |
C fName string base name for file to written |
708 |
C filePrec integer number of bits per word in file (32 or 64) |
709 |
C arrType char(2) declaration of "arr": either "RS" or "RL" |
710 |
C nNz integer size of third dimension: normally either 1 or Nr |
711 |
C arr RS/RL array to write, arr(:,:,nNz,:,:) |
712 |
C irecord integer record number to read |
713 |
C myIter integer time step number |
714 |
C myThid integer thread identifier |
715 |
C |
716 |
C MDSWRITEFIELD creates either a file of the form "fName.data" and |
717 |
C "fName.meta" if the logical flag "globalFile" is set true. Otherwise |
718 |
C it creates MDS tiled files of the form "fName.xxx.yyy.data" and |
719 |
C "fName.xxx.yyy.meta". A meta-file is always created. |
720 |
C Currently, the meta-files are not read because it is difficult |
721 |
C to parse files in fortran. We should read meta information before |
722 |
C adding records to an existing multi-record file. |
723 |
C The precision of the file is decsribed by filePrec, set either |
724 |
C to floatPrec32 or floatPrec64. The precision or declaration of |
725 |
C the array argument must be consistently described by the char*(2) |
726 |
C string arrType, either "RS" or "RL". nNz allows for both 2-D and |
727 |
C 3-D arrays to be handled. nNz=1 implies a 2-D model field and |
728 |
C nNz=Nr implies a 3-D model field. irecord is the record number |
729 |
C to be read and must be >= 1. NOTE: It is currently assumed that |
730 |
C the highest record number in the file was the last record written. |
731 |
C Nor is there a consistency check between the routine arguments and file. |
732 |
C ie. if your write record 2 after record 4 the meta information |
733 |
C will record the number of records to be 2. This, again, is because |
734 |
C we have read the meta information. To be fixed. |
735 |
C |
736 |
C Created: 03/16/99 adcroft@mit.edu |
737 |
C |
738 |
C Changed: 05/31/00 heimbach@mit.edu |
739 |
C open(dUnit, ..., status='old', ... -> status='unknown' |
740 |
|
741 |
implicit none |
742 |
C Global variables / common blocks |
743 |
#include "SIZE.h" |
744 |
#include "EEPARAMS.h" |
745 |
#include "PARAMS.h" |
746 |
|
747 |
C Routine arguments |
748 |
character*(*) fName |
749 |
integer filePrec |
750 |
character*(2) arrType |
751 |
integer nNz |
752 |
cph( |
753 |
cph Real arr(*) |
754 |
_RL arr_gl(nSx,nPx,sNy,nSy,nPy,Nr) |
755 |
cph) |
756 |
integer irecord |
757 |
integer myIter |
758 |
integer myThid |
759 |
C Functions |
760 |
integer ILNBLNK |
761 |
integer MDS_RECLEN |
762 |
C Local variables |
763 |
character*(80) dataFName,metaFName |
764 |
integer ip,jp,iG,jG,irec,bi,bj,jj,k,dUnit,IL |
765 |
Real*4 r4seg(sNy) |
766 |
Real*8 r8seg(sNy) |
767 |
_RL arr(1-oLy:sNy+oLy,Nr,nSx,nSy) |
768 |
integer dimList(3,3),ndims |
769 |
integer length_of_rec |
770 |
logical fileIsOpen |
771 |
character*(max_len_mbuf) msgbuf |
772 |
C ------------------------------------------------------------------ |
773 |
|
774 |
C Only do I/O if I am the master thread |
775 |
_BEGIN_MASTER( myThid ) |
776 |
|
777 |
C Record number must be >= 1 |
778 |
if (irecord .LT. 1) then |
779 |
write(msgbuf,'(a,i9.8)') |
780 |
& ' MDSWRITEFIELD_YZ_GL: argument irecord = ',irecord |
781 |
call print_message( msgbuf, standardmessageunit, |
782 |
& SQUEEZE_RIGHT , mythid) |
783 |
write(msgbuf,'(a)') |
784 |
& ' MDSWRITEFIELD_YZ_GL: invalid value for irecord' |
785 |
call print_error( msgbuf, mythid ) |
786 |
stop 'ABNORMAL END: S/R MDSWRITEFIELD_YZ_GL' |
787 |
endif |
788 |
|
789 |
C Assume nothing |
790 |
fileIsOpen=.FALSE. |
791 |
IL=ILNBLNK( fName ) |
792 |
|
793 |
C Assign a free unit number as the I/O channel for this routine |
794 |
call MDSFINDUNIT( dUnit, mythid ) |
795 |
|
796 |
|
797 |
C Loop over all processors |
798 |
do jp=1,nPy |
799 |
do ip=1,nPx |
800 |
C Loop over all tiles |
801 |
do bj=1,nSy |
802 |
do bi=1,nSx |
803 |
C If we are writing to a tiled MDS file then we open each one here |
804 |
iG=bi+(ip-1)*nsx ! Kludge until unstructered tiles |
805 |
jG=bj+(jp-1)*nsy ! Kludge until unstructered tiles |
806 |
write(dataFname(1:80),'(2a,i3.3,a,i3.3,a)') |
807 |
& fName(1:IL),'.',iG,'.',jG,'.data' |
808 |
if (irecord .EQ. 1) then |
809 |
length_of_rec=MDS_RECLEN( filePrec, sNy, mythid ) |
810 |
open( dUnit, file=dataFName, status=_NEW_STATUS, |
811 |
& access='direct', recl=length_of_rec ) |
812 |
fileIsOpen=.TRUE. |
813 |
else |
814 |
length_of_rec=MDS_RECLEN( filePrec, sNy, mythid ) |
815 |
open( dUnit, file=dataFName, status=_OLD_STATUS, |
816 |
& access='direct', recl=length_of_rec ) |
817 |
fileIsOpen=.TRUE. |
818 |
endif |
819 |
if (fileIsOpen) then |
820 |
do k=1,Nr |
821 |
do jj=1,sNy |
822 |
arr(jj,k,bi,bj)=arr_gl(bi,ip,jj,bj,jp,k) |
823 |
enddo |
824 |
iG = 0 |
825 |
jG = 0 |
826 |
irec=k + Nr*(irecord-1) |
827 |
if (filePrec .eq. precFloat32) then |
828 |
if (arrType .eq. 'RS') then |
829 |
call MDS_SEG4toRS_2D(sNy,oLy,nNz,bi,bj,k,.FALSE.,r4seg,arr) |
830 |
elseif (arrType .eq. 'RL') then |
831 |
call MDS_SEG4toRL_2D(sNy,oLy,nNz,bi,bj,k,.FALSE.,r4seg,arr) |
832 |
else |
833 |
write(msgbuf,'(a)') |
834 |
& ' MDSWRITEFIELD_YZ_GL: illegal value for arrType' |
835 |
call print_error( msgbuf, mythid ) |
836 |
stop 'ABNORMAL END: S/R MDSWRITEFIELD_YZ_GL' |
837 |
endif |
838 |
#ifdef _BYTESWAPIO |
839 |
call MDS_BYTESWAPR4( sNy, r4seg ) |
840 |
#endif |
841 |
write(dUnit,rec=irec) r4seg |
842 |
elseif (filePrec .eq. precFloat64) then |
843 |
if (arrType .eq. 'RS') then |
844 |
call MDS_SEG8toRS_2D(sNy,oLy,nNz,bi,bj,k,.FALSE.,r8seg,arr) |
845 |
elseif (arrType .eq. 'RL') then |
846 |
call MDS_SEG8toRL_2D(sNy,oLy,nNz,bi,bj,k,.FALSE.,r8seg,arr) |
847 |
else |
848 |
write(msgbuf,'(a)') |
849 |
& ' MDSWRITEFIELD_YZ_GL: illegal value for arrType' |
850 |
call print_error( msgbuf, mythid ) |
851 |
stop 'ABNORMAL END: S/R MDSWRITEFIELD_YZ_GL' |
852 |
endif |
853 |
#ifdef _BYTESWAPIO |
854 |
call MDS_BYTESWAPR8( sNy, r8seg ) |
855 |
#endif |
856 |
write(dUnit,rec=irec) r8seg |
857 |
else |
858 |
write(msgbuf,'(a)') |
859 |
& ' MDSWRITEFIELD_YZ_GL: illegal value for filePrec' |
860 |
call print_error( msgbuf, mythid ) |
861 |
stop 'ABNORMAL END: S/R MDSWRITEFIELD_YZ_GL' |
862 |
endif |
863 |
C End of k loop |
864 |
enddo |
865 |
else |
866 |
write(msgbuf,'(a)') |
867 |
& ' MDSWRITEFIELD_YZ_GL: I should never get to this point' |
868 |
call print_error( msgbuf, mythid ) |
869 |
stop 'ABNORMAL END: S/R MDSWRITEFIELD_YZ_GL' |
870 |
endif |
871 |
C If we were writing to a tiled MDS file then we close it here |
872 |
if (fileIsOpen) then |
873 |
close( dUnit ) |
874 |
fileIsOpen = .FALSE. |
875 |
endif |
876 |
C Create meta-file for each tile if we are tiling |
877 |
iG=bi+(ip-1)*nsx ! Kludge until unstructered tiles |
878 |
jG=bj+(jp-1)*nsy ! Kludge until unstructered tiles |
879 |
write(metaFname(1:80),'(2a,i3.3,a,i3.3,a)') |
880 |
& fName(1:IL),'.',iG,'.',jG,'.meta' |
881 |
dimList(1,1)=Nx |
882 |
dimList(2,1)=(ip-1)*nSx+bi |
883 |
dimList(3,1)=ip*nSx+bi |
884 |
dimList(1,2)=Ny |
885 |
dimList(2,2)=((jp-1)*nSy+(bj-1))*sNy+1 |
886 |
dimList(3,2)=((jp-1)*nSy+bj)*sNy |
887 |
dimList(1,3)=Nr |
888 |
dimList(2,3)=1 |
889 |
dimList(3,3)=Nr |
890 |
ndims=3 |
891 |
if (Nr .EQ. 1) ndims=2 |
892 |
call MDSWRITEMETA( metaFName, dataFName, |
893 |
& filePrec, ndims, dimList, irecord, myIter, mythid ) |
894 |
C End of bi,bj loops |
895 |
enddo |
896 |
enddo |
897 |
C End of ip,jp loops |
898 |
enddo |
899 |
enddo |
900 |
|
901 |
|
902 |
_END_MASTER( myThid ) |
903 |
|
904 |
C ------------------------------------------------------------------ |
905 |
return |
906 |
end |
907 |
C======================================================================= |
908 |
|