1 |
heimbach |
1.8 |
C $Header: /u/gcmpack/models/MITgcmUV/eesupp/src/mdsio.F,v 1.7 2000/06/09 14:25:54 heimbach Exp $ |
2 |
adcroft |
1.1 |
|
3 |
|
|
#include "CPP_OPTIONS.h" |
4 |
|
|
|
5 |
adcroft |
1.4 |
C The five "public" routines supplied here are: |
6 |
adcroft |
1.1 |
C |
7 |
adcroft |
1.4 |
C MDSREADFIELD - read model field from direct access global or tiled MDS file |
8 |
|
|
C MDSWRITEFIELD - write model field to direct access global or tiled MDS file |
9 |
|
|
C MDSFINDUNIT - returns an available (unused) I/O channel |
10 |
|
|
C MDSREADVECTOR - read vector from direct access global or tiled MDS file |
11 |
|
|
C MDSWRITEVECTOR - write vector to direct access global or tiled MDS file |
12 |
adcroft |
1.1 |
C |
13 |
|
|
C all other routines are "private" to these utilities and ought |
14 |
|
|
C not be accessed directly from the main code. |
15 |
|
|
C |
16 |
|
|
C Created: 03/16/99 adcroft@mit.edu |
17 |
|
|
C Modified: 03/23/99 adcroft@mit.edu |
18 |
|
|
C To work with multiple records |
19 |
|
|
C Modified: 03/29/99 eckert@mit.edu |
20 |
|
|
C Added arbitrary vector capability |
21 |
adcroft |
1.4 |
C Modified: 07/27/99 eckert@mit.edu |
22 |
|
|
C Customized for state estimation (--> active_file_control.F) |
23 |
|
|
C this relates only to *mdsreadvector* and *mdswritevector* |
24 |
|
|
C Modified: 07/28/99 eckert@mit.edu |
25 |
|
|
C inserted calls to *print_message* and *print_error* |
26 |
|
|
C |
27 |
|
|
C To be modified to work with MITgcmuv message routines. |
28 |
adcroft |
1.1 |
|
29 |
|
|
#undef SAFE_IO |
30 |
|
|
|
31 |
|
|
#ifdef SAFE_IO |
32 |
|
|
#define _NEW_STATUS 'new' |
33 |
|
|
#else |
34 |
|
|
#define _NEW_STATUS 'unknown' |
35 |
|
|
#endif |
36 |
|
|
|
37 |
heimbach |
1.7 |
#ifdef ALLOW_AUTODIFF_TAMC |
38 |
|
|
#define _OLD_STATUS 'unknown' |
39 |
|
|
#else |
40 |
|
|
#define _OLD_STATUS 'old' |
41 |
|
|
#endif |
42 |
|
|
|
43 |
|
|
|
44 |
adcroft |
1.1 |
C======================================================================= |
45 |
|
|
SUBROUTINE MDSREADFIELD( |
46 |
|
|
I fName, |
47 |
|
|
I filePrec, |
48 |
|
|
I arrType, |
49 |
|
|
I nNz, |
50 |
|
|
O arr, |
51 |
|
|
I irecord, |
52 |
|
|
I myThid ) |
53 |
|
|
C |
54 |
|
|
C Arguments: |
55 |
|
|
C |
56 |
|
|
C fName string base name for file to read |
57 |
|
|
C filePrec integer number of bits per word in file (32 or 64) |
58 |
|
|
C arrType char(2) declaration of "arr": either "RS" or "RL" |
59 |
|
|
C nNz integer size of third dimension: normally either 1 or Nr |
60 |
|
|
C arr RS/RL array to read into, arr(:,:,nNz,:,:) |
61 |
|
|
C irecord integer record number to read |
62 |
|
|
C myThid integer thread identifier |
63 |
|
|
C |
64 |
|
|
C MDSREADFIELD first checks to see if the file "fName" exists, then |
65 |
|
|
C if the file "fName.data" exists and finally the tiled files of the |
66 |
|
|
C form "fName.xxx.yyy.data" exist. Currently, the meta-files are not |
67 |
|
|
C read because it is difficult to parse files in fortran. |
68 |
|
|
C The precision of the file is decsribed by filePrec, set either |
69 |
|
|
C to floatPrec32 or floatPrec64. The precision or declaration of |
70 |
|
|
C the array argument must be consistently described by the char*(2) |
71 |
|
|
C string arrType, either "RS" or "RL". nNz allows for both 2-D and |
72 |
|
|
C 3-D arrays to be handled. nNz=1 implies a 2-D model field and |
73 |
|
|
C nNz=Nr implies a 3-D model field. irecord is the record number |
74 |
|
|
C to be read and must be >= 1. The file data is stored in |
75 |
|
|
C arr *but* the overlaps are *not* updated. ie. An exchange must |
76 |
|
|
C be called. This is because the routine is sometimes called from |
77 |
|
|
C within a MASTER_THID region. |
78 |
|
|
C |
79 |
|
|
C Created: 03/16/99 adcroft@mit.edu |
80 |
|
|
|
81 |
|
|
implicit none |
82 |
|
|
C Global variables / common blocks |
83 |
|
|
#include "SIZE.h" |
84 |
|
|
#include "EEPARAMS.h" |
85 |
|
|
#include "PARAMS.h" |
86 |
|
|
|
87 |
|
|
C Routine arguments |
88 |
|
|
character*(*) fName |
89 |
|
|
integer filePrec |
90 |
|
|
character*(2) arrType |
91 |
|
|
integer nNz |
92 |
|
|
Real arr(*) |
93 |
|
|
integer irecord |
94 |
|
|
integer myThid |
95 |
|
|
C Functions |
96 |
|
|
integer ILNBLNK |
97 |
|
|
integer MDS_RECLEN |
98 |
|
|
C Local variables |
99 |
|
|
character*(80) dataFName |
100 |
|
|
integer iG,jG,irec,bi,bj,j,k,dUnit,IL |
101 |
|
|
logical exst |
102 |
|
|
Real*4 r4seg(sNx) |
103 |
|
|
Real*8 r8seg(sNx) |
104 |
|
|
logical globalFile,fileIsOpen |
105 |
|
|
integer length_of_rec |
106 |
adcroft |
1.4 |
character*(max_len_mbuf) msgbuf |
107 |
adcroft |
1.1 |
C ------------------------------------------------------------------ |
108 |
|
|
|
109 |
|
|
C Only do I/O if I am the master thread |
110 |
|
|
_BEGIN_MASTER( myThid ) |
111 |
|
|
|
112 |
|
|
C Record number must be >= 1 |
113 |
|
|
if (irecord .LT. 1) then |
114 |
adcroft |
1.4 |
write(msgbuf,'(a,i9.8)') |
115 |
|
|
& ' MDSREADFIELD: argument irecord = ',irecord |
116 |
|
|
call print_message( msgbuf, standardmessageunit, |
117 |
|
|
& SQUEEZE_RIGHT , mythid) |
118 |
|
|
write(msgbuf,'(a)') |
119 |
|
|
& ' MDSREADFIELD: Invalid value for irecord' |
120 |
|
|
call print_error( msgbuf, mythid ) |
121 |
|
|
stop 'ABNORMAL END: S/R MDSREADFIELD' |
122 |
adcroft |
1.1 |
endif |
123 |
|
|
|
124 |
|
|
C Assume nothing |
125 |
|
|
globalFile = .FALSE. |
126 |
|
|
fileIsOpen = .FALSE. |
127 |
|
|
IL=ILNBLNK( fName ) |
128 |
|
|
|
129 |
|
|
C Assign a free unit number as the I/O channel for this routine |
130 |
adcroft |
1.4 |
call MDSFINDUNIT( dUnit, mythid ) |
131 |
adcroft |
1.1 |
|
132 |
|
|
C Check first for global file with simple name (ie. fName) |
133 |
|
|
dataFName = fName |
134 |
|
|
inquire( file=dataFname, exist=exst ) |
135 |
|
|
if (exst) then |
136 |
adcroft |
1.4 |
write(msgbuf,'(a,a)') |
137 |
|
|
& ' MDSREADFIELD: opening global file: ',dataFName |
138 |
|
|
call print_message( msgbuf, standardmessageunit, |
139 |
|
|
& SQUEEZE_RIGHT , mythid) |
140 |
adcroft |
1.1 |
globalFile = .TRUE. |
141 |
|
|
endif |
142 |
|
|
|
143 |
|
|
C If negative check for global file with MDS name (ie. fName.data) |
144 |
|
|
if (.NOT. globalFile) then |
145 |
|
|
write(dataFname(1:80),'(2a)') fName(1:IL),'.data' |
146 |
|
|
inquire( file=dataFname, exist=exst ) |
147 |
|
|
if (exst) then |
148 |
adcroft |
1.4 |
write(msgbuf,'(a,a)') |
149 |
|
|
& ' MDSREADFIELD: opening global file: ',dataFName |
150 |
|
|
call print_message( msgbuf, standardmessageunit, |
151 |
|
|
& SQUEEZE_RIGHT , mythid) |
152 |
adcroft |
1.1 |
globalFile = .TRUE. |
153 |
|
|
endif |
154 |
|
|
endif |
155 |
|
|
|
156 |
|
|
C If we are reading from a global file then we open it here |
157 |
|
|
if (globalFile) then |
158 |
adcroft |
1.4 |
length_of_rec=MDS_RECLEN( filePrec, sNx, mythid ) |
159 |
adcroft |
1.1 |
open( dUnit, file=dataFName, status='old', |
160 |
|
|
& access='direct', recl=length_of_rec ) |
161 |
|
|
fileIsOpen=.TRUE. |
162 |
|
|
endif |
163 |
|
|
|
164 |
|
|
C Loop over all tiles |
165 |
|
|
do bj=1,nSy |
166 |
|
|
do bi=1,nSx |
167 |
|
|
C If we are reading from a tiled MDS file then we open each one here |
168 |
|
|
if (.NOT. globalFile) then |
169 |
|
|
iG=bi+(myXGlobalLo-1)/sNx ! Kludge until unstructered tiles |
170 |
|
|
jG=bj+(myYGlobalLo-1)/sNy ! Kludge until unstructered tiles |
171 |
|
|
write(dataFname(1:80),'(2a,i3.3,a,i3.3,a)') |
172 |
|
|
& fName(1:IL),'.',iG,'.',jG,'.data' |
173 |
|
|
inquire( file=dataFname, exist=exst ) |
174 |
|
|
C Of course, we only open the file if the tile is "active" |
175 |
|
|
C (This is a place-holder for the active/passive mechanism |
176 |
|
|
if (exst) then |
177 |
adcroft |
1.4 |
write(msgbuf,'(a,a)') |
178 |
|
|
& ' MDSREADFIELD: opening file: ',dataFName |
179 |
|
|
call print_message( msgbuf, standardmessageunit, |
180 |
|
|
& SQUEEZE_RIGHT , mythid) |
181 |
|
|
length_of_rec=MDS_RECLEN( filePrec, sNx, mythid ) |
182 |
adcroft |
1.1 |
open( dUnit, file=dataFName, status='old', |
183 |
|
|
& access='direct', recl=length_of_rec ) |
184 |
|
|
fileIsOpen=.TRUE. |
185 |
|
|
else |
186 |
|
|
fileIsOpen=.FALSE. |
187 |
adcroft |
1.4 |
write(msgbuf,'(a,a)') |
188 |
|
|
& ' MDSREADFIELD: filename: ',dataFName |
189 |
|
|
call print_message( msgbuf, standardmessageunit, |
190 |
|
|
& SQUEEZE_RIGHT , mythid) |
191 |
|
|
write(msgbuf,'(a)') |
192 |
|
|
& ' MDSREADFIELD: File does not exist' |
193 |
|
|
call print_error( msgbuf, mythid ) |
194 |
|
|
stop 'ABNORMAL END: S/R MDSREADFIELD' |
195 |
adcroft |
1.1 |
endif |
196 |
|
|
endif |
197 |
|
|
|
198 |
|
|
if (fileIsOpen) then |
199 |
|
|
do k=1,nNz |
200 |
|
|
do j=1,sNy |
201 |
|
|
if (globalFile) then |
202 |
|
|
iG = myXGlobalLo-1 + (bi-1)*sNx |
203 |
|
|
jG = myYGlobalLo-1 + (bj-1)*sNy |
204 |
|
|
irec=1 + INT(iG/sNx) + nSx*nPx*(jG+j-1) + nSx*nPx*Ny*(k-1) |
205 |
|
|
& + nSx*nPx*Ny*nNz*(irecord-1) |
206 |
|
|
else |
207 |
|
|
iG = 0 |
208 |
|
|
jG = 0 |
209 |
|
|
irec=j + sNy*(k-1) + sNy*nNz*(irecord-1) |
210 |
|
|
endif |
211 |
|
|
if (filePrec .eq. precFloat32) then |
212 |
|
|
read(dUnit,rec=irec) r4seg |
213 |
adcroft |
1.2 |
#ifdef _BYTESWAPIO |
214 |
|
|
call MDS_BYTESWAPR4( sNx, r4seg ) |
215 |
|
|
#endif |
216 |
adcroft |
1.1 |
if (arrType .eq. 'RS') then |
217 |
|
|
call MDS_SEG4toRS( j,bi,bj,k,nNz, r4seg, .TRUE., arr ) |
218 |
|
|
elseif (arrType .eq. 'RL') then |
219 |
|
|
call MDS_SEG4toRL( j,bi,bj,k,nNz, r4seg, .TRUE., arr ) |
220 |
|
|
else |
221 |
adcroft |
1.4 |
write(msgbuf,'(a)') |
222 |
|
|
& ' MDSREADFIELD: illegal value for arrType' |
223 |
|
|
call print_error( msgbuf, mythid ) |
224 |
|
|
stop 'ABNORMAL END: S/R MDSREADFIELD' |
225 |
adcroft |
1.1 |
endif |
226 |
|
|
elseif (filePrec .eq. precFloat64) then |
227 |
|
|
read(dUnit,rec=irec) r8seg |
228 |
adcroft |
1.2 |
#ifdef _BYTESWAPIO |
229 |
|
|
call MDS_BYTESWAPR8( sNx, r8seg ) |
230 |
|
|
#endif |
231 |
adcroft |
1.1 |
if (arrType .eq. 'RS') then |
232 |
|
|
call MDS_SEG8toRS( j,bi,bj,k,nNz, r8seg, .TRUE., arr ) |
233 |
|
|
elseif (arrType .eq. 'RL') then |
234 |
|
|
call MDS_SEG8toRL( j,bi,bj,k,nNz, r8seg, .TRUE., arr ) |
235 |
|
|
else |
236 |
adcroft |
1.4 |
write(msgbuf,'(a)') |
237 |
|
|
& ' MDSREADFIELD: illegal value for arrType' |
238 |
|
|
call print_error( msgbuf, mythid ) |
239 |
|
|
stop 'ABNORMAL END: S/R MDSREADFIELD' |
240 |
adcroft |
1.1 |
endif |
241 |
|
|
else |
242 |
adcroft |
1.4 |
write(msgbuf,'(a)') |
243 |
|
|
& ' MDSREADFIELD: illegal value for filePrec' |
244 |
|
|
call print_error( msgbuf, mythid ) |
245 |
|
|
stop 'ABNORMAL END: S/R MDSREADFIELD' |
246 |
adcroft |
1.1 |
endif |
247 |
|
|
C End of j loop |
248 |
|
|
enddo |
249 |
|
|
C End of k loop |
250 |
|
|
enddo |
251 |
|
|
if (.NOT. globalFile) then |
252 |
|
|
close( dUnit ) |
253 |
|
|
fileIsOpen = .FALSE. |
254 |
|
|
endif |
255 |
|
|
endif |
256 |
|
|
C End of bi,bj loops |
257 |
|
|
enddo |
258 |
|
|
enddo |
259 |
|
|
|
260 |
|
|
C If global file was opened then close it |
261 |
|
|
if (fileIsOpen .AND. globalFile) then |
262 |
|
|
close( dUnit ) |
263 |
|
|
fileIsOpen = .FALSE. |
264 |
|
|
endif |
265 |
|
|
|
266 |
|
|
_END_MASTER( myThid ) |
267 |
|
|
|
268 |
|
|
C ------------------------------------------------------------------ |
269 |
|
|
return |
270 |
|
|
end |
271 |
|
|
C======================================================================= |
272 |
|
|
|
273 |
|
|
C======================================================================= |
274 |
|
|
SUBROUTINE MDSWRITEFIELD( |
275 |
|
|
I fName, |
276 |
|
|
I filePrec, |
277 |
|
|
I globalFile, |
278 |
|
|
I arrType, |
279 |
|
|
I nNz, |
280 |
|
|
I arr, |
281 |
|
|
I irecord, |
282 |
|
|
I myIter, |
283 |
|
|
I myThid ) |
284 |
|
|
C |
285 |
|
|
C Arguments: |
286 |
|
|
C |
287 |
|
|
C fName string base name for file to written |
288 |
|
|
C filePrec integer number of bits per word in file (32 or 64) |
289 |
|
|
C globalFile logical selects between writing a global or tiled file |
290 |
|
|
C arrType char(2) declaration of "arr": either "RS" or "RL" |
291 |
|
|
C nNz integer size of third dimension: normally either 1 or Nr |
292 |
|
|
C arr RS/RL array to write, arr(:,:,nNz,:,:) |
293 |
|
|
C irecord integer record number to read |
294 |
|
|
C myIter integer time step number |
295 |
|
|
C myThid integer thread identifier |
296 |
|
|
C |
297 |
|
|
C MDSWRITEFIELD creates either a file of the form "fName.data" and |
298 |
|
|
C "fName.meta" if the logical flag "globalFile" is set true. Otherwise |
299 |
|
|
C it creates MDS tiled files of the form "fName.xxx.yyy.data" and |
300 |
|
|
C "fName.xxx.yyy.meta". A meta-file is always created. |
301 |
|
|
C Currently, the meta-files are not read because it is difficult |
302 |
|
|
C to parse files in fortran. We should read meta information before |
303 |
|
|
C adding records to an existing multi-record file. |
304 |
|
|
C The precision of the file is decsribed by filePrec, set either |
305 |
|
|
C to floatPrec32 or floatPrec64. The precision or declaration of |
306 |
|
|
C the array argument must be consistently described by the char*(2) |
307 |
|
|
C string arrType, either "RS" or "RL". nNz allows for both 2-D and |
308 |
|
|
C 3-D arrays to be handled. nNz=1 implies a 2-D model field and |
309 |
|
|
C nNz=Nr implies a 3-D model field. irecord is the record number |
310 |
|
|
C to be read and must be >= 1. NOTE: It is currently assumed that |
311 |
|
|
C the highest record number in the file was the last record written. |
312 |
|
|
C Nor is there a consistency check between the routine arguments and file. |
313 |
|
|
C ie. if your write record 2 after record 4 the meta information |
314 |
|
|
C will record the number of records to be 2. This, again, is because |
315 |
|
|
C we have read the meta information. To be fixed. |
316 |
|
|
C |
317 |
|
|
C Created: 03/16/99 adcroft@mit.edu |
318 |
heimbach |
1.7 |
C |
319 |
|
|
C Changed: 05/31/00 heimbach@mit.edu |
320 |
|
|
C open(dUnit, ..., status='old', ... -> status='unknown' |
321 |
adcroft |
1.1 |
|
322 |
|
|
implicit none |
323 |
|
|
C Global variables / common blocks |
324 |
|
|
#include "SIZE.h" |
325 |
|
|
#include "EEPARAMS.h" |
326 |
|
|
#include "PARAMS.h" |
327 |
|
|
|
328 |
|
|
C Routine arguments |
329 |
|
|
character*(*) fName |
330 |
|
|
integer filePrec |
331 |
|
|
logical globalFile |
332 |
|
|
character*(2) arrType |
333 |
|
|
integer nNz |
334 |
heimbach |
1.8 |
cph( |
335 |
|
|
cph Real arr(*) |
336 |
|
|
_RL arr(1-oLx:sNx+oLx,1-oLy:sNy+oLy,nNz,nSx,nSy) |
337 |
|
|
cph) |
338 |
adcroft |
1.1 |
integer irecord |
339 |
|
|
integer myIter |
340 |
|
|
integer myThid |
341 |
|
|
C Functions |
342 |
|
|
integer ILNBLNK |
343 |
|
|
integer MDS_RECLEN |
344 |
|
|
C Local variables |
345 |
|
|
character*(80) dataFName,metaFName |
346 |
|
|
integer iG,jG,irec,bi,bj,j,k,dUnit,IL |
347 |
|
|
Real*4 r4seg(sNx) |
348 |
|
|
Real*8 r8seg(sNx) |
349 |
|
|
integer dimList(3,3),ndims |
350 |
|
|
integer length_of_rec |
351 |
|
|
logical fileIsOpen |
352 |
adcroft |
1.4 |
character*(max_len_mbuf) msgbuf |
353 |
adcroft |
1.1 |
C ------------------------------------------------------------------ |
354 |
|
|
|
355 |
|
|
C Only do I/O if I am the master thread |
356 |
|
|
_BEGIN_MASTER( myThid ) |
357 |
|
|
|
358 |
|
|
C Record number must be >= 1 |
359 |
|
|
if (irecord .LT. 1) then |
360 |
adcroft |
1.4 |
write(msgbuf,'(a,i9.8)') |
361 |
|
|
& ' MDSWRITEFIELD: argument irecord = ',irecord |
362 |
|
|
call print_message( msgbuf, standardmessageunit, |
363 |
|
|
& SQUEEZE_RIGHT , mythid) |
364 |
|
|
write(msgbuf,'(a)') |
365 |
|
|
& ' MDSWRITEFIELD: invalid value for irecord' |
366 |
|
|
call print_error( msgbuf, mythid ) |
367 |
|
|
stop 'ABNORMAL END: S/R MDSWRITEFIELD' |
368 |
adcroft |
1.1 |
endif |
369 |
|
|
|
370 |
|
|
C Assume nothing |
371 |
|
|
fileIsOpen=.FALSE. |
372 |
|
|
IL=ILNBLNK( fName ) |
373 |
|
|
|
374 |
|
|
C Assign a free unit number as the I/O channel for this routine |
375 |
adcroft |
1.4 |
call MDSFINDUNIT( dUnit, mythid ) |
376 |
adcroft |
1.1 |
|
377 |
|
|
C If we are writing to a global file then we open it here |
378 |
|
|
if (globalFile) then |
379 |
|
|
write(dataFname(1:80),'(2a)') fName(1:IL),'.data' |
380 |
|
|
if (irecord .EQ. 1) then |
381 |
adcroft |
1.4 |
length_of_rec=MDS_RECLEN( filePrec, sNx, mythid ) |
382 |
adcroft |
1.1 |
open( dUnit, file=dataFName, status=_NEW_STATUS, |
383 |
|
|
& access='direct', recl=length_of_rec ) |
384 |
|
|
fileIsOpen=.TRUE. |
385 |
|
|
else |
386 |
adcroft |
1.4 |
length_of_rec=MDS_RECLEN( filePrec, sNx, mythid ) |
387 |
heimbach |
1.7 |
open( dUnit, file=dataFName, status=_OLD_STATUS, |
388 |
adcroft |
1.1 |
& access='direct', recl=length_of_rec ) |
389 |
|
|
fileIsOpen=.TRUE. |
390 |
|
|
endif |
391 |
|
|
endif |
392 |
|
|
|
393 |
|
|
C Loop over all tiles |
394 |
|
|
do bj=1,nSy |
395 |
|
|
do bi=1,nSx |
396 |
|
|
C If we are writing to a tiled MDS file then we open each one here |
397 |
|
|
if (.NOT. globalFile) then |
398 |
|
|
iG=bi+(myXGlobalLo-1)/sNx ! Kludge until unstructered tiles |
399 |
|
|
jG=bj+(myYGlobalLo-1)/sNy ! Kludge until unstructered tiles |
400 |
|
|
write(dataFname(1:80),'(2a,i3.3,a,i3.3,a)') |
401 |
|
|
& fName(1:IL),'.',iG,'.',jG,'.data' |
402 |
|
|
if (irecord .EQ. 1) then |
403 |
adcroft |
1.4 |
length_of_rec=MDS_RECLEN( filePrec, sNx, mythid ) |
404 |
adcroft |
1.1 |
open( dUnit, file=dataFName, status=_NEW_STATUS, |
405 |
|
|
& access='direct', recl=length_of_rec ) |
406 |
|
|
fileIsOpen=.TRUE. |
407 |
|
|
else |
408 |
adcroft |
1.4 |
length_of_rec=MDS_RECLEN( filePrec, sNx, mythid ) |
409 |
heimbach |
1.7 |
open( dUnit, file=dataFName, status=_OLD_STATUS, |
410 |
adcroft |
1.1 |
& access='direct', recl=length_of_rec ) |
411 |
|
|
fileIsOpen=.TRUE. |
412 |
|
|
endif |
413 |
|
|
endif |
414 |
|
|
if (fileIsOpen) then |
415 |
|
|
do k=1,nNz |
416 |
|
|
do j=1,sNy |
417 |
|
|
if (globalFile) then |
418 |
|
|
iG = myXGlobalLo-1+(bi-1)*sNx |
419 |
|
|
jG = myYGlobalLo-1+(bj-1)*sNy |
420 |
|
|
irec=1+INT(iG/sNx)+nSx*nPx*(jG+j-1)+nSx*nPx*Ny*(k-1) |
421 |
|
|
& +nSx*nPx*Ny*nNz*(irecord-1) |
422 |
|
|
else |
423 |
|
|
iG = 0 |
424 |
|
|
jG = 0 |
425 |
|
|
irec=j + sNy*(k-1) + sNy*nNz*(irecord-1) |
426 |
|
|
endif |
427 |
|
|
if (filePrec .eq. precFloat32) then |
428 |
|
|
if (arrType .eq. 'RS') then |
429 |
|
|
call MDS_SEG4toRS( j,bi,bj,k,nNz, r4seg, .FALSE., arr ) |
430 |
|
|
elseif (arrType .eq. 'RL') then |
431 |
|
|
call MDS_SEG4toRL( j,bi,bj,k,nNz, r4seg, .FALSE., arr ) |
432 |
|
|
else |
433 |
adcroft |
1.4 |
write(msgbuf,'(a)') |
434 |
|
|
& ' MDSWRITEFIELD: illegal value for arrType' |
435 |
|
|
call print_error( msgbuf, mythid ) |
436 |
|
|
stop 'ABNORMAL END: S/R MDSWRITEFIELD' |
437 |
adcroft |
1.1 |
endif |
438 |
adcroft |
1.2 |
#ifdef _BYTESWAPIO |
439 |
|
|
call MDS_BYTESWAPR4( sNx, r4seg ) |
440 |
|
|
#endif |
441 |
adcroft |
1.1 |
write(dUnit,rec=irec) r4seg |
442 |
|
|
elseif (filePrec .eq. precFloat64) then |
443 |
|
|
if (arrType .eq. 'RS') then |
444 |
|
|
call MDS_SEG8toRS( j,bi,bj,k,nNz, r8seg, .FALSE., arr ) |
445 |
|
|
elseif (arrType .eq. 'RL') then |
446 |
|
|
call MDS_SEG8toRL( j,bi,bj,k,nNz, r8seg, .FALSE., arr ) |
447 |
|
|
else |
448 |
adcroft |
1.4 |
write(msgbuf,'(a)') |
449 |
|
|
& ' MDSWRITEFIELD: illegal value for arrType' |
450 |
|
|
call print_error( msgbuf, mythid ) |
451 |
|
|
stop 'ABNORMAL END: S/R MDSWRITEFIELD' |
452 |
adcroft |
1.1 |
endif |
453 |
adcroft |
1.2 |
#ifdef _BYTESWAPIO |
454 |
|
|
call MDS_BYTESWAPR8( sNx, r8seg ) |
455 |
|
|
#endif |
456 |
adcroft |
1.1 |
write(dUnit,rec=irec) r8seg |
457 |
|
|
else |
458 |
adcroft |
1.4 |
write(msgbuf,'(a)') |
459 |
|
|
& ' MDSWRITEFIELD: illegal value for filePrec' |
460 |
|
|
call print_error( msgbuf, mythid ) |
461 |
|
|
stop 'ABNORMAL END: S/R MDSWRITEFIELD' |
462 |
adcroft |
1.1 |
endif |
463 |
|
|
C End of j loop |
464 |
|
|
enddo |
465 |
|
|
C End of k loop |
466 |
|
|
enddo |
467 |
|
|
else |
468 |
adcroft |
1.4 |
write(msgbuf,'(a)') |
469 |
|
|
& ' MDSWRITEFIELD: I should never get to this point' |
470 |
|
|
call print_error( msgbuf, mythid ) |
471 |
|
|
stop 'ABNORMAL END: S/R MDSWRITEFIELD' |
472 |
adcroft |
1.1 |
endif |
473 |
|
|
C If we were writing to a tiled MDS file then we close it here |
474 |
|
|
if (fileIsOpen .AND. (.NOT. globalFile)) then |
475 |
|
|
close( dUnit ) |
476 |
|
|
fileIsOpen = .FALSE. |
477 |
|
|
endif |
478 |
|
|
C Create meta-file for each tile if we are tiling |
479 |
|
|
if (.NOT. globalFile) then |
480 |
adcroft |
1.3 |
iG=bi+(myXGlobalLo-1)/sNx ! Kludge until unstructered tiles |
481 |
|
|
jG=bj+(myYGlobalLo-1)/sNy ! Kludge until unstructered tiles |
482 |
adcroft |
1.1 |
write(metaFname(1:80),'(2a,i3.3,a,i3.3,a)') |
483 |
adcroft |
1.3 |
& fName(1:IL),'.',iG,'.',jG,'.meta' |
484 |
adcroft |
1.1 |
dimList(1,1)=Nx |
485 |
|
|
dimList(2,1)=myXGlobalLo+(bi-1)*sNx |
486 |
|
|
dimList(3,1)=myXGlobalLo+bi*sNx-1 |
487 |
|
|
dimList(1,2)=Ny |
488 |
|
|
dimList(2,2)=myYGlobalLo+(bj-1)*sNy |
489 |
|
|
dimList(3,2)=myYGlobalLo+bj*sNy-1 |
490 |
|
|
dimList(1,3)=Nr |
491 |
|
|
dimList(2,3)=1 |
492 |
|
|
dimList(3,3)=Nr |
493 |
|
|
ndims=3 |
494 |
|
|
if (nNz .EQ. 1) ndims=2 |
495 |
|
|
call MDSWRITEMETA( metaFName, dataFName, |
496 |
adcroft |
1.4 |
& filePrec, ndims, dimList, irecord, myIter, mythid ) |
497 |
adcroft |
1.1 |
endif |
498 |
|
|
C End of bi,bj loops |
499 |
|
|
enddo |
500 |
|
|
enddo |
501 |
|
|
|
502 |
|
|
C If global file was opened then close it |
503 |
|
|
if (fileIsOpen .AND. globalFile) then |
504 |
|
|
close( dUnit ) |
505 |
|
|
fileIsOpen = .FALSE. |
506 |
|
|
endif |
507 |
|
|
|
508 |
|
|
C Create meta-file for the global-file |
509 |
|
|
if (globalFile) then |
510 |
adcroft |
1.5 |
C We can not do this operation using threads (yet) because of the |
511 |
adcroft |
1.1 |
C "barrier" at the next step. The barrier could be removed but |
512 |
|
|
C at the cost of "safe" distributed I/O. |
513 |
|
|
if (nThreads.NE.1) then |
514 |
adcroft |
1.4 |
write(msgbuf,'(a,a)') |
515 |
|
|
& ' MDSWRITEFIELD: A threads version of this routine', |
516 |
|
|
& ' does not exist.' |
517 |
|
|
call print_message( msgbuf, standardmessageunit, |
518 |
|
|
& SQUEEZE_RIGHT , mythid) |
519 |
|
|
write(msgbuf,'(a)') |
520 |
|
|
& ' MDSWRITEFIELD: This needs to be fixed...' |
521 |
|
|
call print_message( msgbuf, standardmessageunit, |
522 |
|
|
& SQUEEZE_RIGHT , mythid) |
523 |
|
|
write(msgbuf,'(a,i3.2)') |
524 |
|
|
& ' MDSWRITEFIELD: nThreads = ',nThreads |
525 |
|
|
call print_message( msgbuf, standardmessageunit, |
526 |
|
|
& SQUEEZE_RIGHT , mythid) |
527 |
|
|
write(msgbuf,'(a)') |
528 |
|
|
& ' MDSWRITEFIELD: Stopping because you are using threads' |
529 |
|
|
call print_error( msgbuf, mythid ) |
530 |
|
|
stop 'ABNORMAL END: S/R MDSWRITEFIELD' |
531 |
adcroft |
1.1 |
endif |
532 |
|
|
C We put a barrier here to ensure that all processes have finished |
533 |
|
|
C writing their data before we update the meta-file |
534 |
|
|
_BARRIER |
535 |
|
|
write(metaFName(1:80),'(2a)') fName(1:IL),'.meta' |
536 |
|
|
dimList(1,1)=Nx |
537 |
|
|
dimList(2,1)=1 |
538 |
|
|
dimList(3,1)=Nx |
539 |
|
|
dimList(1,2)=Ny |
540 |
|
|
dimList(2,2)=1 |
541 |
|
|
dimList(3,2)=Ny |
542 |
|
|
dimList(1,3)=Nr |
543 |
|
|
dimList(2,3)=1 |
544 |
|
|
dimList(3,3)=Nr |
545 |
|
|
ndims=3 |
546 |
|
|
if (nNz .EQ. 1) ndims=2 |
547 |
|
|
call MDSWRITEMETA( metaFName, dataFName, |
548 |
adcroft |
1.4 |
& filePrec, ndims, dimList, irecord, myIter, mythid ) |
549 |
adcroft |
1.1 |
fileIsOpen=.TRUE. |
550 |
|
|
endif |
551 |
|
|
|
552 |
|
|
_END_MASTER( myThid ) |
553 |
|
|
|
554 |
|
|
C ------------------------------------------------------------------ |
555 |
|
|
return |
556 |
|
|
end |
557 |
|
|
C======================================================================= |
558 |
|
|
|
559 |
|
|
C======================================================================= |
560 |
|
|
subroutine MDS_SEG4toRS( j,bi,bj,k,nNz, seg, copyTo, arr ) |
561 |
|
|
C IN: |
562 |
|
|
C j,bi,bj,k integer - indices to array "arr" |
563 |
|
|
C nNz integer - K dimension of array "arr" |
564 |
|
|
C seg Real*4 - 1-D vector of length sNx |
565 |
|
|
C OUT: |
566 |
|
|
C arr _RS - model tiled array |
567 |
|
|
C |
568 |
|
|
C Created: 03/20/99 adcroft@mit.edu |
569 |
|
|
|
570 |
|
|
implicit none |
571 |
|
|
C Global variables / common blocks |
572 |
|
|
#include "SIZE.h" |
573 |
|
|
|
574 |
|
|
C Arguments |
575 |
|
|
integer j,bi,bj,k,nNz |
576 |
|
|
_RS arr(1-oLx:sNx+oLx,1-oLy:sNy+oLy,nNz,nSx,nSy) |
577 |
|
|
logical copyTo |
578 |
|
|
Real*4 seg(sNx) |
579 |
|
|
C Local |
580 |
|
|
integer ii |
581 |
|
|
|
582 |
|
|
C ------------------------------------------------------------------ |
583 |
|
|
|
584 |
|
|
if (copyTo) then |
585 |
|
|
do ii=1,sNx |
586 |
|
|
arr(ii,j,k,bi,bj)=seg(ii) |
587 |
|
|
enddo |
588 |
|
|
else |
589 |
|
|
do ii=1,sNx |
590 |
|
|
seg(ii)=arr(ii,j,k,bi,bj) |
591 |
|
|
enddo |
592 |
|
|
endif |
593 |
|
|
|
594 |
|
|
C ------------------------------------------------------------------ |
595 |
|
|
return |
596 |
|
|
end |
597 |
|
|
C======================================================================= |
598 |
|
|
|
599 |
|
|
C======================================================================= |
600 |
|
|
subroutine MDS_SEG4toRL( j,bi,bj,k,nNz, seg, copyTo, arr ) |
601 |
|
|
C IN: |
602 |
|
|
C j,bi,bj,k integer - indices to array "arr" |
603 |
|
|
C nNz integer - K dimension of array "arr" |
604 |
|
|
C seg Real*4 - 1-D vector of length sNx |
605 |
|
|
C OUT: |
606 |
|
|
C arr _RL - model tiled array |
607 |
|
|
C |
608 |
|
|
C Created: 03/20/99 adcroft@mit.edu |
609 |
|
|
|
610 |
|
|
implicit none |
611 |
|
|
C Global variables / common blocks |
612 |
|
|
#include "SIZE.h" |
613 |
|
|
|
614 |
|
|
C Arguments |
615 |
|
|
integer j,bi,bj,k,nNz |
616 |
|
|
_RL arr(1-oLx:sNx+oLx,1-oLy:sNy+oLy,nNz,nSx,nSy) |
617 |
|
|
logical copyTo |
618 |
|
|
Real*4 seg(sNx) |
619 |
|
|
C Local |
620 |
|
|
integer ii |
621 |
|
|
C ------------------------------------------------------------------ |
622 |
|
|
if (copyTo) then |
623 |
|
|
do ii=1,sNx |
624 |
|
|
arr(ii,j,k,bi,bj)=seg(ii) |
625 |
|
|
enddo |
626 |
|
|
else |
627 |
|
|
do ii=1,sNx |
628 |
|
|
seg(ii)=arr(ii,j,k,bi,bj) |
629 |
|
|
enddo |
630 |
|
|
endif |
631 |
|
|
C ------------------------------------------------------------------ |
632 |
|
|
return |
633 |
|
|
end |
634 |
|
|
C======================================================================= |
635 |
|
|
|
636 |
|
|
C======================================================================= |
637 |
|
|
subroutine MDS_SEG8toRS( j,bi,bj,k,nNz, seg, copyTo, arr ) |
638 |
|
|
C IN: |
639 |
|
|
C j,bi,bj,k integer - indices to array "arr" |
640 |
|
|
C nNz integer - K dimension of array "arr" |
641 |
|
|
C seg Real*8 - 1-D vector of length sNx |
642 |
|
|
C OUT: |
643 |
|
|
C arr _RS - model tiled array |
644 |
|
|
C |
645 |
|
|
C Created: 03/20/99 adcroft@mit.edu |
646 |
|
|
|
647 |
|
|
implicit none |
648 |
|
|
C Global variables / common blocks |
649 |
|
|
#include "SIZE.h" |
650 |
|
|
|
651 |
|
|
C Arguments |
652 |
|
|
integer j,bi,bj,k,nNz |
653 |
|
|
_RS arr(1-oLx:sNx+oLx,1-oLy:sNy+oLy,nNz,nSx,nSy) |
654 |
|
|
logical copyTo |
655 |
|
|
Real*8 seg(sNx) |
656 |
|
|
C Local |
657 |
|
|
integer ii |
658 |
|
|
C ------------------------------------------------------------------ |
659 |
|
|
if (copyTo) then |
660 |
|
|
do ii=1,sNx |
661 |
|
|
arr(ii,j,k,bi,bj)=seg(ii) |
662 |
|
|
enddo |
663 |
|
|
else |
664 |
|
|
do ii=1,sNx |
665 |
|
|
seg(ii)=arr(ii,j,k,bi,bj) |
666 |
|
|
enddo |
667 |
|
|
endif |
668 |
|
|
C ------------------------------------------------------------------ |
669 |
|
|
return |
670 |
|
|
end |
671 |
|
|
C======================================================================= |
672 |
|
|
|
673 |
|
|
C======================================================================= |
674 |
|
|
subroutine MDS_SEG8toRL( j,bi,bj,k,nNz, seg, copyTo, arr ) |
675 |
|
|
C IN: |
676 |
|
|
C j,bi,bj,k integer - indices to array "arr" |
677 |
|
|
C nNz integer - K dimension of array "arr" |
678 |
|
|
C seg Real*8 - 1-D vector of length sNx |
679 |
|
|
C OUT: |
680 |
|
|
C arr _RL - model tiled array |
681 |
|
|
C |
682 |
|
|
C Created: 03/20/99 adcroft@mit.edu |
683 |
|
|
|
684 |
|
|
implicit none |
685 |
|
|
C Global variables / common blocks |
686 |
|
|
#include "SIZE.h" |
687 |
|
|
|
688 |
|
|
C Arguments |
689 |
|
|
integer j,bi,bj,k,nNz |
690 |
|
|
_RL arr(1-oLx:sNx+oLx,1-oLy:sNy+oLy,nNz,nSx,nSy) |
691 |
|
|
logical copyTo |
692 |
|
|
Real*8 seg(sNx) |
693 |
|
|
C Local |
694 |
|
|
integer ii |
695 |
|
|
C ------------------------------------------------------------------ |
696 |
|
|
if (copyTo) then |
697 |
|
|
do ii=1,sNx |
698 |
|
|
arr(ii,j,k,bi,bj)=seg(ii) |
699 |
|
|
enddo |
700 |
|
|
else |
701 |
|
|
do ii=1,sNx |
702 |
|
|
seg(ii)=arr(ii,j,k,bi,bj) |
703 |
|
|
enddo |
704 |
|
|
endif |
705 |
|
|
C ------------------------------------------------------------------ |
706 |
|
|
return |
707 |
|
|
end |
708 |
|
|
C======================================================================= |
709 |
|
|
|
710 |
|
|
C======================================================================= |
711 |
|
|
subroutine MDSWRITEMETA( |
712 |
|
|
I mFileName, |
713 |
|
|
I dFileName, |
714 |
|
|
I filePrec, |
715 |
|
|
I ndims, |
716 |
|
|
I dimList, |
717 |
|
|
I nrecords, |
718 |
adcroft |
1.4 |
I myIter, |
719 |
|
|
I mythid ) |
720 |
adcroft |
1.1 |
|
721 |
|
|
C IN: |
722 |
|
|
C mFileName string - complete name of meta-file |
723 |
adcroft |
1.3 |
C dFileName string - complete name of data-file |
724 |
adcroft |
1.1 |
C ndims integer - number of dimensions |
725 |
|
|
C dimList integer - array of dimensions, etc. |
726 |
|
|
C nrecords integer - record number |
727 |
|
|
C myIter integer - time-step number |
728 |
adcroft |
1.4 |
C mythid integer - thread id |
729 |
adcroft |
1.1 |
C OUT: |
730 |
|
|
C |
731 |
|
|
C Created: 03/20/99 adcroft@mit.edu |
732 |
|
|
|
733 |
|
|
implicit none |
734 |
|
|
C Arguments |
735 |
|
|
character*(*) mFileName |
736 |
|
|
character*(*) dFileName |
737 |
|
|
integer filePrec |
738 |
|
|
integer ndims |
739 |
|
|
integer dimList(3,ndims) |
740 |
|
|
integer nrecords |
741 |
|
|
integer myIter |
742 |
adcroft |
1.4 |
integer mythid |
743 |
adcroft |
1.1 |
|
744 |
|
|
C Global variables / common blocks |
745 |
|
|
#include "SIZE.h" |
746 |
|
|
#include "EEPARAMS.h" |
747 |
|
|
#include "PARAMS.h" |
748 |
|
|
|
749 |
|
|
C Functions |
750 |
adcroft |
1.6 |
|
751 |
adcroft |
1.1 |
C Local |
752 |
|
|
integer i,ii,mUnit |
753 |
|
|
logical ex |
754 |
adcroft |
1.4 |
character*(max_len_mbuf) msgbuf |
755 |
adcroft |
1.1 |
C ------------------------------------------------------------------ |
756 |
|
|
|
757 |
|
|
C We should *read* the met-file if it exists to check |
758 |
|
|
C that the information we are writing is consistent |
759 |
|
|
C with the current contents |
760 |
|
|
inquire( file=mFileName, exist=ex ) |
761 |
|
|
C However, it is bloody difficult to parse files |
762 |
|
|
C in fortran so someone else can do this. |
763 |
|
|
C For now, we will assume everything is ok |
764 |
|
|
C and that the last record is written to the |
765 |
|
|
C last consecutive record in the file. |
766 |
|
|
|
767 |
|
|
C Assign a free unit number as the I/O channel for this subroutine |
768 |
adcroft |
1.4 |
call MDSFINDUNIT( mUnit, mythid ) |
769 |
adcroft |
1.1 |
|
770 |
|
|
C Open meta-file |
771 |
|
|
open( mUnit, file=mFileName, status='unknown', |
772 |
|
|
& form='formatted' ) |
773 |
|
|
|
774 |
|
|
C Write the number of dimensions |
775 |
|
|
write(mUnit,'(x,a,i3,a)') 'nDims = [ ',ndims,' ];' |
776 |
|
|
|
777 |
|
|
C For each dimension, write the following: |
778 |
|
|
C 1 global size (ie. the size of the global dimension of all files) |
779 |
|
|
C 2 global start (ie. the global position of the start of this file) |
780 |
|
|
C 3 global end (ie. the global position of the end of this file) |
781 |
|
|
|
782 |
|
|
write(mUnit,'(x,a)') 'dimList = [' |
783 |
|
|
do ii=1,ndims |
784 |
|
|
if (ii.lt.ndims) then |
785 |
|
|
write(mUnit,'(10x,3(i5,","))') (dimList(i,ii),i=1,3) |
786 |
|
|
else |
787 |
|
|
write(mUnit,'(10x,i5,",",i5,",",i5)') (dimList(i,ii),i=1,3) |
788 |
|
|
endif |
789 |
|
|
enddo |
790 |
|
|
write(mUnit,'(10x,a)') '];' |
791 |
|
|
|
792 |
|
|
C Record the precision of the file |
793 |
|
|
if (filePrec .EQ. precFloat32) then |
794 |
|
|
write(mUnit,'(x,a)') "format = [ 'float32' ];" |
795 |
|
|
elseif (filePrec .EQ. precFloat64) then |
796 |
|
|
write(mUnit,'(x,a)') "format = [ 'float64' ];" |
797 |
|
|
else |
798 |
adcroft |
1.4 |
write(msgbuf,'(a)') |
799 |
|
|
& ' MDSWRITEMETA: invalid filePrec' |
800 |
|
|
call print_error( msgbuf, mythid ) |
801 |
|
|
stop 'ABNORMAL END: S/R MDSWRITEMETA' |
802 |
adcroft |
1.1 |
endif |
803 |
|
|
|
804 |
|
|
C Record the current record number |
805 |
|
|
C This is a proxy for the actual number of records in the file. |
806 |
|
|
C If we could read the file then we could do this properly. |
807 |
|
|
write(mUnit,'(x,a,i5,a)') 'nrecords = [ ',nrecords,' ];' |
808 |
|
|
|
809 |
|
|
C Record the file-name for the binary data |
810 |
|
|
Cveto ii=ILNBLNK( dFileName ) |
811 |
|
|
Cveto write(mUnit,'(x,3a)') 'binarydatafile = [ ',dFileName(1:ii),' ];' |
812 |
|
|
|
813 |
|
|
C Write the integer time (integer iteration number) for later record |
814 |
|
|
C keeping. If the timestep number is less than 0 then we assume |
815 |
|
|
C that the information is superfluous and do not write it. |
816 |
|
|
if (myIter .ge. 0) |
817 |
|
|
& write(mUnit,'(x,a,i8,a)') 'timeStepNumber = [ ',myIter,' ];' |
818 |
|
|
|
819 |
|
|
C Close meta-file |
820 |
|
|
close(mUnit) |
821 |
|
|
|
822 |
|
|
C ------------------------------------------------------------------ |
823 |
|
|
return |
824 |
|
|
end |
825 |
|
|
C======================================================================= |
826 |
|
|
|
827 |
|
|
C======================================================================= |
828 |
adcroft |
1.4 |
subroutine MDSFINDUNIT( iounit, mythid ) |
829 |
adcroft |
1.1 |
C OUT: |
830 |
|
|
C iounit integer - unit number |
831 |
|
|
C |
832 |
|
|
C MDSFINDUNIT returns a valid, unused unit number for f77 I/O |
833 |
|
|
C The routine stops the program is an error occurs in the process |
834 |
|
|
C of searching the I/O channels. |
835 |
|
|
C |
836 |
|
|
C Created: 03/20/99 adcroft@mit.edu |
837 |
|
|
|
838 |
|
|
implicit none |
839 |
adcroft |
1.4 |
|
840 |
|
|
#include "EEPARAMS.h" |
841 |
|
|
|
842 |
adcroft |
1.1 |
C Arguments |
843 |
|
|
integer iounit |
844 |
adcroft |
1.4 |
integer mythid |
845 |
adcroft |
1.1 |
C Local |
846 |
|
|
integer ii |
847 |
|
|
logical op |
848 |
|
|
integer ios |
849 |
adcroft |
1.4 |
character*(max_len_mbuf) msgbuf |
850 |
adcroft |
1.1 |
C ------------------------------------------------------------------ |
851 |
|
|
|
852 |
|
|
C Sweep through a valid range of unit numbers |
853 |
|
|
iounit=-1 |
854 |
|
|
do ii=9,99 |
855 |
|
|
if (iounit.eq.-1) then |
856 |
|
|
inquire(unit=ii,iostat=ios,opened=op) |
857 |
|
|
if (ios.ne.0) then |
858 |
adcroft |
1.4 |
write(msgbuf,'(a,i2.2)') |
859 |
|
|
& ' MDSFINDUNIT: inquiring unit number = ',ii |
860 |
|
|
call print_message( msgbuf, standardmessageunit, |
861 |
|
|
& SQUEEZE_RIGHT , mythid) |
862 |
|
|
write(msgbuf,'(a)') |
863 |
|
|
& ' MDSFINDUNIT: inquire statement failed!' |
864 |
|
|
call print_error( msgbuf, mythid ) |
865 |
|
|
stop 'ABNORMAL END: S/R MDSFINDUNIT' |
866 |
adcroft |
1.1 |
endif |
867 |
|
|
if (.NOT. op) then |
868 |
|
|
iounit=ii |
869 |
|
|
endif |
870 |
|
|
endif |
871 |
|
|
enddo |
872 |
|
|
|
873 |
|
|
C Was there an available unit number |
874 |
|
|
if (iounit.eq.-1) then |
875 |
adcroft |
1.4 |
write(msgbuf,'(a)') |
876 |
|
|
& ' MDSFINDUNIT: could not find an available unit number!' |
877 |
|
|
call print_error( msgbuf, mythid ) |
878 |
|
|
stop 'ABNORMAL END: S/R MDSFINDUNIT' |
879 |
adcroft |
1.1 |
endif |
880 |
|
|
|
881 |
|
|
C ------------------------------------------------------------------ |
882 |
|
|
return |
883 |
|
|
end |
884 |
|
|
C======================================================================= |
885 |
|
|
|
886 |
|
|
C======================================================================= |
887 |
adcroft |
1.4 |
integer function MDS_RECLEN( filePrec, nnn, mythid ) |
888 |
adcroft |
1.1 |
C IN: |
889 |
|
|
C filePrec integer - precision of file in bits |
890 |
|
|
C nnn integer - number of elements in record |
891 |
|
|
C OUT: |
892 |
|
|
C MDS_RECLEN integer - appropriate length of record in bytes or words |
893 |
|
|
C |
894 |
|
|
C Created: 03/29/99 eckert@mit.edu + adcroft@mit.edu |
895 |
|
|
|
896 |
|
|
implicit none |
897 |
|
|
C Arguments |
898 |
|
|
integer filePrec |
899 |
|
|
integer nnn |
900 |
adcroft |
1.4 |
integer mythid |
901 |
adcroft |
1.1 |
C Global variables |
902 |
|
|
#include "SIZE.h" |
903 |
|
|
#include "EEPARAMS.h" |
904 |
|
|
#include "PARAMS.h" |
905 |
|
|
C Local |
906 |
adcroft |
1.4 |
character*(max_len_mbuf) msgbuf |
907 |
adcroft |
1.1 |
C ------------------------------------------------------------------ |
908 |
|
|
|
909 |
|
|
if (filePrec .EQ. precFloat32) then |
910 |
|
|
MDS_RECLEN=nnn*WORDLENGTH |
911 |
|
|
elseif (filePrec .EQ. precFloat64) then |
912 |
|
|
MDS_RECLEN=nnn*WORDLENGTH*2 |
913 |
|
|
else |
914 |
adcroft |
1.4 |
write(msgbuf,'(a,i2.2)') |
915 |
|
|
& ' MDS_RECLEN: filePrec = ',filePrec |
916 |
|
|
call print_message( msgbuf, standardmessageunit, |
917 |
|
|
& SQUEEZE_RIGHT , mythid) |
918 |
|
|
write(msgbuf,'(a)') |
919 |
|
|
& ' MDS_RECLEN: illegal value for filePrec' |
920 |
|
|
call print_error( msgbuf, mythid ) |
921 |
|
|
stop 'ABNORMAL END: S/R MDS_RECLEN' |
922 |
adcroft |
1.1 |
endif |
923 |
|
|
|
924 |
|
|
C ------------------------------------------------------------------ |
925 |
|
|
return |
926 |
|
|
end |
927 |
|
|
C======================================================================= |
928 |
|
|
|
929 |
|
|
C======================================================================= |
930 |
|
|
SUBROUTINE MDSREADVECTOR( |
931 |
|
|
I fName, |
932 |
|
|
I filePrec, |
933 |
|
|
I arrType, |
934 |
|
|
I narr, |
935 |
|
|
O arr, |
936 |
adcroft |
1.4 |
I bi, |
937 |
|
|
I bj, |
938 |
adcroft |
1.1 |
I irecord, |
939 |
|
|
I myThid ) |
940 |
|
|
C |
941 |
|
|
C Arguments: |
942 |
|
|
C |
943 |
|
|
C fName string base name for file to read |
944 |
|
|
C filePrec integer number of bits per word in file (32 or 64) |
945 |
|
|
C arrType char(2) declaration of "arr": either "RS" or "RL" |
946 |
|
|
C narr integer size of third dimension: normally either 1 or Nr |
947 |
|
|
C arr RS/RL array to read into, arr(narr) |
948 |
adcroft |
1.4 |
ce bi integer x tile index |
949 |
|
|
ce bj integer y tile index |
950 |
adcroft |
1.1 |
C irecord integer record number to read |
951 |
|
|
C myThid integer thread identifier |
952 |
|
|
C |
953 |
|
|
C Created: 03/26/99 eckert@mit.edu |
954 |
|
|
C Modified: 03/29/99 adcroft@mit.edu + eckert@mit.edu |
955 |
|
|
C Fixed to work work with _RS and _RL declarations |
956 |
adcroft |
1.4 |
C Modified: 07/27/99 eckert@mit.edu |
957 |
|
|
C Customized for state estimation (--> active_file_control.F) |
958 |
adcroft |
1.1 |
|
959 |
|
|
implicit none |
960 |
|
|
C Global variables / common blocks |
961 |
|
|
#include "SIZE.h" |
962 |
|
|
#include "EEPARAMS.h" |
963 |
|
|
#include "PARAMS.h" |
964 |
|
|
|
965 |
|
|
C Routine arguments |
966 |
|
|
character*(*) fName |
967 |
|
|
integer filePrec |
968 |
|
|
character*(2) arrType |
969 |
|
|
integer narr |
970 |
|
|
Real arr(narr) |
971 |
|
|
integer irecord |
972 |
|
|
integer myThid |
973 |
adcroft |
1.4 |
ce |
974 |
|
|
integer bi,bj |
975 |
|
|
ce |
976 |
|
|
|
977 |
adcroft |
1.1 |
C Functions |
978 |
|
|
integer ILNBLNK |
979 |
|
|
integer MDS_RECLEN |
980 |
|
|
C Local variables |
981 |
|
|
character*(80) dataFName |
982 |
adcroft |
1.4 |
integer iG,jG,irec,dUnit,IL |
983 |
adcroft |
1.1 |
logical exst |
984 |
|
|
logical globalFile,fileIsOpen |
985 |
|
|
integer length_of_rec |
986 |
adcroft |
1.4 |
character*(max_len_mbuf) msgbuf |
987 |
adcroft |
1.1 |
C ------------------------------------------------------------------ |
988 |
|
|
|
989 |
|
|
C Only do I/O if I am the master thread |
990 |
|
|
_BEGIN_MASTER( myThid ) |
991 |
|
|
|
992 |
|
|
C Record number must be >= 1 |
993 |
|
|
if (irecord .LT. 1) then |
994 |
adcroft |
1.4 |
write(msgbuf,'(a,i9.8)') |
995 |
|
|
& ' MDSREADVECTOR: argument irecord = ',irecord |
996 |
|
|
call print_message( msgbuf, standardmessageunit, |
997 |
|
|
& SQUEEZE_RIGHT , mythid) |
998 |
|
|
write(msgbuf,'(a)') |
999 |
|
|
& ' MDSREADVECTOR: invalid value for irecord' |
1000 |
|
|
call print_error( msgbuf, mythid ) |
1001 |
|
|
stop 'ABNORMAL END: S/R MDSREADVECTOR' |
1002 |
adcroft |
1.1 |
endif |
1003 |
|
|
|
1004 |
|
|
C Assume nothing |
1005 |
|
|
globalFile = .FALSE. |
1006 |
|
|
fileIsOpen = .FALSE. |
1007 |
|
|
IL=ILNBLNK( fName ) |
1008 |
|
|
|
1009 |
|
|
C Assign a free unit number as the I/O channel for this routine |
1010 |
adcroft |
1.4 |
call MDSFINDUNIT( dUnit, mythid ) |
1011 |
adcroft |
1.1 |
|
1012 |
|
|
C Check first for global file with simple name (ie. fName) |
1013 |
|
|
dataFName = fName |
1014 |
|
|
inquire( file=dataFname, exist=exst ) |
1015 |
|
|
if (exst) then |
1016 |
adcroft |
1.4 |
write(msgbuf,'(a,a)') |
1017 |
|
|
& ' MDSREADVECTOR: opening global file: ',dataFName |
1018 |
|
|
call print_message( msgbuf, standardmessageunit, |
1019 |
|
|
& SQUEEZE_RIGHT , mythid) |
1020 |
adcroft |
1.1 |
globalFile = .TRUE. |
1021 |
|
|
endif |
1022 |
|
|
|
1023 |
|
|
C If negative check for global file with MDS name (ie. fName.data) |
1024 |
|
|
if (.NOT. globalFile) then |
1025 |
|
|
write(dataFname(1:80),'(2a)') fName(1:IL),'.data' |
1026 |
|
|
inquire( file=dataFname, exist=exst ) |
1027 |
|
|
if (exst) then |
1028 |
adcroft |
1.4 |
write(msgbuf,'(a,a)') |
1029 |
|
|
& ' MDSREADVECTOR: opening global file: ',dataFName |
1030 |
|
|
call print_message( msgbuf, standardmessageunit, |
1031 |
|
|
& SQUEEZE_RIGHT , mythid) |
1032 |
adcroft |
1.1 |
globalFile = .TRUE. |
1033 |
|
|
endif |
1034 |
|
|
endif |
1035 |
|
|
|
1036 |
|
|
C If we are reading from a global file then we open it here |
1037 |
|
|
if (globalFile) then |
1038 |
adcroft |
1.4 |
length_of_rec=MDS_RECLEN( filePrec, narr, mythid ) |
1039 |
adcroft |
1.1 |
open( dUnit, file=dataFName, status='old', |
1040 |
|
|
& access='direct', recl=length_of_rec ) |
1041 |
|
|
fileIsOpen=.TRUE. |
1042 |
|
|
endif |
1043 |
|
|
|
1044 |
|
|
C Loop over all tiles |
1045 |
adcroft |
1.4 |
ce do bj=1,nSy |
1046 |
|
|
ce do bi=1,nSx |
1047 |
adcroft |
1.1 |
C If we are reading from a tiled MDS file then we open each one here |
1048 |
|
|
if (.NOT. globalFile) then |
1049 |
|
|
iG=bi+(myXGlobalLo-1)/sNx ! Kludge until unstructered tiles |
1050 |
|
|
jG=bj+(myYGlobalLo-1)/sNy ! Kludge until unstructered tiles |
1051 |
|
|
write(dataFname(1:80),'(2a,i3.3,a,i3.3,a)') |
1052 |
|
|
& fName(1:IL),'.',iG,'.',jG,'.data' |
1053 |
|
|
inquire( file=dataFname, exist=exst ) |
1054 |
|
|
C Of course, we only open the file if the tile is "active" |
1055 |
|
|
C (This is a place-holder for the active/passive mechanism) |
1056 |
|
|
if (exst) then |
1057 |
adcroft |
1.4 |
write(msgbuf,'(a,a)') |
1058 |
|
|
& ' MDSREADVECTOR: opening file: ',dataFName |
1059 |
|
|
call print_message( msgbuf, standardmessageunit, |
1060 |
|
|
& SQUEEZE_RIGHT , mythid) |
1061 |
|
|
length_of_rec=MDS_RECLEN( filePrec, narr, mythid ) |
1062 |
adcroft |
1.1 |
open( dUnit, file=dataFName, status='old', |
1063 |
|
|
& access='direct', recl=length_of_rec ) |
1064 |
|
|
fileIsOpen=.TRUE. |
1065 |
|
|
else |
1066 |
|
|
fileIsOpen=.FALSE. |
1067 |
adcroft |
1.4 |
write(msgbuf,'(a)') |
1068 |
|
|
& ' MDSREADVECTOR: un-active tiles not implemented yet' |
1069 |
|
|
call print_error( msgbuf, mythid ) |
1070 |
|
|
stop 'ABNORMAL END: S/R MDSREADVECTOR' |
1071 |
adcroft |
1.1 |
endif |
1072 |
|
|
endif |
1073 |
|
|
if (fileIsOpen) then |
1074 |
|
|
if (globalFile) then |
1075 |
|
|
iG = myXGlobalLo-1+(bi-1)*sNx |
1076 |
|
|
jG = myYGlobalLo-1+(bj-1)*sNy |
1077 |
|
|
irec = 1 + int(iG/sNx) + (jG/sNy)*nSx*nPx + |
1078 |
|
|
& (irecord-1)*nSx*nPx*nSy*nPy |
1079 |
|
|
else |
1080 |
|
|
iG = 0 |
1081 |
|
|
jG = 0 |
1082 |
|
|
irec = irecord |
1083 |
|
|
endif |
1084 |
|
|
if (filePrec .eq. precFloat32) then |
1085 |
adcroft |
1.6 |
call MDS_READ_RS_VEC( dUnit, irec, narr, arr, myThid ) |
1086 |
adcroft |
1.1 |
elseif (filePrec .eq. precFloat64) then |
1087 |
adcroft |
1.6 |
call MDS_READ_RL_VEC( dUnit, irec, narr, arr, myThid ) |
1088 |
adcroft |
1.1 |
else |
1089 |
adcroft |
1.4 |
write(msgbuf,'(a)') |
1090 |
|
|
& ' MDSREADVECTOR: illegal value for filePrec' |
1091 |
|
|
call print_error( msgbuf, mythid ) |
1092 |
|
|
stop 'ABNORMAL END: S/R MDSREADVECTOR' |
1093 |
adcroft |
1.1 |
endif |
1094 |
|
|
if (.NOT. globalFile) then |
1095 |
|
|
close( dUnit ) |
1096 |
|
|
fileIsOpen = .FALSE. |
1097 |
|
|
endif |
1098 |
|
|
endif |
1099 |
|
|
C End of bi,bj loops |
1100 |
adcroft |
1.4 |
ce enddo |
1101 |
|
|
ce enddo |
1102 |
adcroft |
1.1 |
|
1103 |
|
|
C If global file was opened then close it |
1104 |
|
|
if (fileIsOpen .AND. globalFile) then |
1105 |
|
|
close( dUnit ) |
1106 |
|
|
fileIsOpen = .FALSE. |
1107 |
|
|
endif |
1108 |
|
|
|
1109 |
|
|
_END_MASTER( myThid ) |
1110 |
|
|
|
1111 |
|
|
C ------------------------------------------------------------------ |
1112 |
|
|
return |
1113 |
|
|
end |
1114 |
|
|
C======================================================================= |
1115 |
|
|
|
1116 |
|
|
C======================================================================= |
1117 |
|
|
SUBROUTINE MDSWRITEVECTOR( |
1118 |
|
|
I fName, |
1119 |
|
|
I filePrec, |
1120 |
|
|
I globalfile, |
1121 |
|
|
I arrType, |
1122 |
|
|
I narr, |
1123 |
|
|
I arr, |
1124 |
adcroft |
1.4 |
I bi, |
1125 |
|
|
I bj, |
1126 |
adcroft |
1.1 |
I irecord, |
1127 |
|
|
I myIter, |
1128 |
|
|
I myThid ) |
1129 |
|
|
C Arguments: |
1130 |
|
|
C |
1131 |
|
|
C fName string base name for file to written |
1132 |
|
|
C filePrec integer number of bits per word in file (32 or 64) |
1133 |
|
|
C globalFile logical selects between writing a global or tiled file |
1134 |
|
|
C arrType char(2) declaration of "arr": either "RS" or "RL" |
1135 |
|
|
C narr integer size of third dimension: normally either 1 or Nr |
1136 |
|
|
C arr RS/RL array to write, arr(narr) |
1137 |
adcroft |
1.4 |
ce bi integer x tile index |
1138 |
|
|
ce bj integer y tile index |
1139 |
adcroft |
1.1 |
C irecord integer record number to read |
1140 |
|
|
C myIter integer time step number |
1141 |
|
|
C myThid integer thread identifier |
1142 |
|
|
C |
1143 |
|
|
C Created: 03/26/99 eckert@mit.edu |
1144 |
|
|
C Modified: 03/29/99 adcroft@mit.edu + eckert@mit.edu |
1145 |
|
|
C Fixed to work work with _RS and _RL declarations |
1146 |
adcroft |
1.4 |
C Modified: 07/27/99 eckert@mit.edu |
1147 |
|
|
C Customized for state estimation (--> active_file_control.F) |
1148 |
heimbach |
1.7 |
C Changed: 05/31/00 heimbach@mit.edu |
1149 |
|
|
C open(dUnit, ..., status='old', ... -> status='unknown' |
1150 |
adcroft |
1.1 |
|
1151 |
|
|
implicit none |
1152 |
|
|
C Global variables / common blocks |
1153 |
|
|
#include "SIZE.h" |
1154 |
|
|
#include "EEPARAMS.h" |
1155 |
|
|
#include "PARAMS.h" |
1156 |
|
|
|
1157 |
|
|
C Routine arguments |
1158 |
|
|
character*(*) fName |
1159 |
|
|
integer filePrec |
1160 |
|
|
logical globalfile |
1161 |
|
|
character*(2) arrType |
1162 |
|
|
integer narr |
1163 |
|
|
Real arr(narr) |
1164 |
|
|
integer irecord |
1165 |
|
|
integer myIter |
1166 |
|
|
integer myThid |
1167 |
adcroft |
1.4 |
ce |
1168 |
|
|
integer bi,bj |
1169 |
|
|
ce |
1170 |
|
|
|
1171 |
adcroft |
1.1 |
C Functions |
1172 |
|
|
integer ILNBLNK |
1173 |
|
|
integer MDS_RECLEN |
1174 |
|
|
C Local variables |
1175 |
|
|
character*(80) dataFName,metaFName |
1176 |
adcroft |
1.4 |
integer iG,jG,irec,dUnit,IL |
1177 |
adcroft |
1.1 |
logical fileIsOpen |
1178 |
|
|
integer dimList(3,3),ndims |
1179 |
|
|
integer length_of_rec |
1180 |
adcroft |
1.4 |
character*(max_len_mbuf) msgbuf |
1181 |
adcroft |
1.1 |
C ------------------------------------------------------------------ |
1182 |
|
|
|
1183 |
|
|
C Only do I/O if I am the master thread |
1184 |
|
|
_BEGIN_MASTER( myThid ) |
1185 |
|
|
|
1186 |
|
|
C Record number must be >= 1 |
1187 |
|
|
if (irecord .LT. 1) then |
1188 |
adcroft |
1.4 |
write(msgbuf,'(a,i9.8)') |
1189 |
|
|
& ' MDSWRITEVECTOR: argument irecord = ',irecord |
1190 |
|
|
call print_message( msgbuf, standardmessageunit, |
1191 |
|
|
& SQUEEZE_RIGHT , mythid) |
1192 |
|
|
write(msgbuf,'(a)') |
1193 |
|
|
& ' MDSWRITEVECTOR: invalid value for irecord' |
1194 |
|
|
call print_error( msgbuf, mythid ) |
1195 |
|
|
stop 'ABNORMAL END: S/R MDSWRITEVECTOR' |
1196 |
adcroft |
1.1 |
endif |
1197 |
|
|
|
1198 |
|
|
C Assume nothing |
1199 |
|
|
fileIsOpen = .FALSE. |
1200 |
|
|
IL=ILNBLNK( fName ) |
1201 |
|
|
|
1202 |
|
|
C Assign a free unit number as the I/O channel for this routine |
1203 |
adcroft |
1.4 |
call MDSFINDUNIT( dUnit, mythid ) |
1204 |
adcroft |
1.1 |
|
1205 |
|
|
C If we are writing to a global file then we open it here |
1206 |
|
|
if (globalFile) then |
1207 |
|
|
write(dataFname(1:80),'(2a)') fName(1:IL),'.data' |
1208 |
|
|
if (irecord .EQ. 1) then |
1209 |
adcroft |
1.4 |
length_of_rec = MDS_RECLEN( filePrec, narr, mythid ) |
1210 |
adcroft |
1.1 |
open( dUnit, file=dataFName, status=_NEW_STATUS, |
1211 |
|
|
& access='direct', recl=length_of_rec ) |
1212 |
|
|
fileIsOpen=.TRUE. |
1213 |
|
|
else |
1214 |
adcroft |
1.4 |
length_of_rec = MDS_RECLEN( filePrec, narr, mythid ) |
1215 |
heimbach |
1.7 |
open( dUnit, file=dataFName, status=_OLD_STATUS, |
1216 |
adcroft |
1.1 |
& access='direct', recl=length_of_rec ) |
1217 |
|
|
fileIsOpen=.TRUE. |
1218 |
|
|
endif |
1219 |
|
|
endif |
1220 |
|
|
|
1221 |
|
|
C Loop over all tiles |
1222 |
adcroft |
1.4 |
ce do bj=1,nSy |
1223 |
|
|
ce do bi=1,nSx |
1224 |
adcroft |
1.1 |
C If we are writing to a tiled MDS file then we open each one here |
1225 |
|
|
if (.NOT. globalFile) then |
1226 |
|
|
iG=bi+(myXGlobalLo-1)/sNx ! Kludge until unstructered tiles |
1227 |
|
|
jG=bj+(myYGlobalLo-1)/sNy ! Kludge until unstructered tiles |
1228 |
|
|
write(dataFname(1:80),'(2a,i3.3,a,i3.3,a)') |
1229 |
|
|
& fName(1:IL),'.',iG,'.',jG,'.data' |
1230 |
|
|
if (irecord .EQ. 1) then |
1231 |
adcroft |
1.4 |
length_of_rec = MDS_RECLEN( filePrec, narr, mythid ) |
1232 |
adcroft |
1.1 |
open( dUnit, file=dataFName, status=_NEW_STATUS, |
1233 |
|
|
& access='direct', recl=length_of_rec ) |
1234 |
|
|
fileIsOpen=.TRUE. |
1235 |
|
|
else |
1236 |
adcroft |
1.4 |
length_of_rec = MDS_RECLEN( filePrec, narr, mythid ) |
1237 |
heimbach |
1.7 |
open( dUnit, file=dataFName, status=_OLD_STATUS, |
1238 |
adcroft |
1.1 |
& access='direct', recl=length_of_rec ) |
1239 |
|
|
fileIsOpen=.TRUE. |
1240 |
|
|
endif |
1241 |
|
|
endif |
1242 |
|
|
if (fileIsOpen) then |
1243 |
|
|
if (globalFile) then |
1244 |
|
|
iG = myXGlobalLo-1+(bi-1)*sNx |
1245 |
|
|
jG = myYGlobalLo-1+(bj-1)*sNy |
1246 |
|
|
irec = 1 + int(iG/sNx) + (jG/sNy)*nSx*nPx + |
1247 |
|
|
& (irecord-1)*nSx*nPx*nSy*nPy |
1248 |
|
|
else |
1249 |
|
|
iG = 0 |
1250 |
|
|
jG = 0 |
1251 |
|
|
irec = irecord |
1252 |
|
|
endif |
1253 |
|
|
if (filePrec .eq. precFloat32) then |
1254 |
adcroft |
1.6 |
call MDS_WRITE_RS_VEC( dUnit, irec, narr, arr, myThid ) |
1255 |
adcroft |
1.1 |
elseif (filePrec .eq. precFloat64) then |
1256 |
adcroft |
1.6 |
call MDS_WRITE_RL_VEC( dUnit, irec, narr, arr, myThid ) |
1257 |
adcroft |
1.1 |
else |
1258 |
adcroft |
1.4 |
write(msgbuf,'(a)') |
1259 |
|
|
& ' MDSWRITEVECTOR: illegal value for filePrec' |
1260 |
|
|
call print_error( msgbuf, mythid ) |
1261 |
|
|
stop 'ABNORMAL END: S/R MDSWRITEVECTOR' |
1262 |
adcroft |
1.1 |
endif |
1263 |
|
|
else |
1264 |
adcroft |
1.4 |
write(msgbuf,'(a)') |
1265 |
|
|
& ' MDSWRITEVECTOR: I should never get to this point' |
1266 |
|
|
call print_error( msgbuf, mythid ) |
1267 |
|
|
stop 'ABNORMAL END: S/R MDSWRITEVECTOR' |
1268 |
adcroft |
1.1 |
endif |
1269 |
|
|
C If we were writing to a tiled MDS file then we close it here |
1270 |
|
|
if (fileIsOpen .AND. (.NOT. globalFile)) then |
1271 |
|
|
close( dUnit ) |
1272 |
|
|
fileIsOpen = .FALSE. |
1273 |
|
|
endif |
1274 |
|
|
C Create meta-file for each tile file |
1275 |
|
|
if (.NOT. globalFile) then |
1276 |
adcroft |
1.3 |
iG=bi+(myXGlobalLo-1)/sNx ! Kludge until unstructered tiles |
1277 |
|
|
jG=bj+(myYGlobalLo-1)/sNy ! Kludge until unstructered tiles |
1278 |
adcroft |
1.1 |
write(metaFname(1:80),'(2a,i3.3,a,i3.3,a)') |
1279 |
adcroft |
1.3 |
& fName(1:IL),'.',iG,'.',jG,'.meta' |
1280 |
adcroft |
1.1 |
dimList(1,1) = nPx*nSx*narr |
1281 |
adcroft |
1.4 |
dimList(2,1) = ((myXGlobalLo-1)/sNx + (bi-1))*narr + 1 |
1282 |
|
|
dimList(3,1) = ((myXGlobalLo-1)/sNx + bi )*narr |
1283 |
adcroft |
1.1 |
dimList(1,2) = nPy*nSy |
1284 |
adcroft |
1.4 |
dimList(2,2) = (myYGlobalLo-1)/sNy + bj |
1285 |
|
|
dimList(3,2) = (myYGlobalLo-1)/sNy + bj |
1286 |
adcroft |
1.1 |
dimList(1,3) = 1 |
1287 |
|
|
dimList(2,3) = 1 |
1288 |
|
|
dimList(3,3) = 1 |
1289 |
|
|
ndims=1 |
1290 |
|
|
call MDSWRITEMETA( metaFName, dataFName, |
1291 |
adcroft |
1.4 |
& filePrec, ndims, dimList, irecord, myIter, mythid ) |
1292 |
adcroft |
1.1 |
endif |
1293 |
|
|
C End of bi,bj loops |
1294 |
adcroft |
1.4 |
ce enddo |
1295 |
|
|
ce enddo |
1296 |
adcroft |
1.1 |
|
1297 |
|
|
C If global file was opened then close it |
1298 |
|
|
if (fileIsOpen .AND. globalFile) then |
1299 |
|
|
close( dUnit ) |
1300 |
|
|
fileIsOpen = .FALSE. |
1301 |
|
|
endif |
1302 |
|
|
|
1303 |
|
|
C Create meta-file for global file |
1304 |
|
|
if (globalFile) then |
1305 |
|
|
write(metaFName(1:80),'(2a)') fName(1:IL),'.meta' |
1306 |
|
|
dimList(1,1) = nPx*nSx*narr |
1307 |
|
|
dimList(2,1) = 1 |
1308 |
|
|
dimList(3,1) = nPx*nSx*narr |
1309 |
|
|
dimList(1,2) = nPy*nSy |
1310 |
|
|
dimList(2,2) = 1 |
1311 |
|
|
dimList(3,2) = nPy*nSy |
1312 |
|
|
dimList(1,3) = 1 |
1313 |
|
|
dimList(2,3) = 1 |
1314 |
|
|
dimList(3,3) = 1 |
1315 |
|
|
ndims=1 |
1316 |
|
|
call MDSWRITEMETA( metaFName, dataFName, |
1317 |
adcroft |
1.4 |
& filePrec, ndims, dimList, irecord, myIter, mythid ) |
1318 |
adcroft |
1.1 |
endif |
1319 |
|
|
|
1320 |
|
|
_END_MASTER( myThid ) |
1321 |
|
|
C ------------------------------------------------------------------ |
1322 |
|
|
return |
1323 |
|
|
end |
1324 |
|
|
C======================================================================= |
1325 |
|
|
|
1326 |
|
|
C======================================================================= |
1327 |
adcroft |
1.4 |
subroutine MDS_WRITE_RS_VEC( dUnit, irec, narr, arr, mythid ) |
1328 |
adcroft |
1.1 |
C IN: |
1329 |
|
|
C dunit integer - 'Opened' I/O channel |
1330 |
|
|
C irec integer - record number to write |
1331 |
|
|
C narr integer - dimension off array "arr" |
1332 |
|
|
C arr _RS - model tiled vector |
1333 |
adcroft |
1.4 |
C mythid integer - thread id |
1334 |
adcroft |
1.1 |
C |
1335 |
|
|
C Created: 03/29/99 eckert@mit.edu + adcroft@mit.edu |
1336 |
|
|
|
1337 |
|
|
implicit none |
1338 |
adcroft |
1.4 |
|
1339 |
|
|
#include "EEPARAMS.h" |
1340 |
|
|
|
1341 |
adcroft |
1.1 |
C Arguments |
1342 |
|
|
integer dUnit |
1343 |
|
|
integer irec |
1344 |
|
|
integer narr |
1345 |
adcroft |
1.4 |
integer mythid |
1346 |
adcroft |
1.1 |
_RS arr(narr) |
1347 |
|
|
C Local |
1348 |
adcroft |
1.4 |
character*(max_len_mbuf) msgbuf |
1349 |
adcroft |
1.1 |
C ------------------------------------------------------------------ |
1350 |
adcroft |
1.4 |
write(msgbuf,'(a,i9.8,2x,i9.8)') |
1351 |
|
|
& ' MDS_WRITE_RS_VEC: irec = ',irec,narr |
1352 |
|
|
call print_message( msgbuf, standardmessageunit, |
1353 |
|
|
& SQUEEZE_RIGHT , mythid) |
1354 |
adcroft |
1.1 |
write(dUnit,rec=irec) arr |
1355 |
|
|
C ------------------------------------------------------------------ |
1356 |
|
|
return |
1357 |
|
|
end |
1358 |
|
|
C======================================================================= |
1359 |
|
|
|
1360 |
|
|
C======================================================================= |
1361 |
adcroft |
1.4 |
subroutine MDS_WRITE_RL_VEC( dUnit, irec, narr, arr, mythid ) |
1362 |
adcroft |
1.1 |
C IN: |
1363 |
|
|
C dunit integer - 'Opened' I/O channel |
1364 |
|
|
C irec integer - record number to write |
1365 |
|
|
C narr integer - dimension off array "arr" |
1366 |
|
|
C arr _RL - model tiled vector |
1367 |
adcroft |
1.4 |
C mythid integer - thread id |
1368 |
adcroft |
1.1 |
C |
1369 |
|
|
C Created: 03/29/99 eckert@mit.edu + adcroft@mit.edu |
1370 |
|
|
|
1371 |
|
|
implicit none |
1372 |
adcroft |
1.4 |
|
1373 |
|
|
#include "EEPARAMS.h" |
1374 |
|
|
|
1375 |
adcroft |
1.1 |
C Arguments |
1376 |
|
|
integer dUnit |
1377 |
|
|
integer irec |
1378 |
|
|
integer narr |
1379 |
adcroft |
1.4 |
integer mythid |
1380 |
adcroft |
1.1 |
_RL arr(narr) |
1381 |
|
|
C Local |
1382 |
adcroft |
1.4 |
character*(max_len_mbuf) msgbuf |
1383 |
adcroft |
1.1 |
C ------------------------------------------------------------------ |
1384 |
adcroft |
1.4 |
write(msgbuf,'(a,i9.8,2x,i9.8)') |
1385 |
|
|
& ' MDS_WRITE_RL_VEC: irec = ',irec,narr |
1386 |
|
|
call print_message( msgbuf, standardmessageunit, |
1387 |
|
|
& SQUEEZE_RIGHT , mythid) |
1388 |
adcroft |
1.1 |
write(dUnit,rec=irec) arr |
1389 |
|
|
C ------------------------------------------------------------------ |
1390 |
|
|
return |
1391 |
|
|
end |
1392 |
|
|
C======================================================================= |
1393 |
|
|
|
1394 |
|
|
C======================================================================= |
1395 |
adcroft |
1.4 |
subroutine MDS_READ_RS_VEC( dUnit, irec, narr, arr, mythid ) |
1396 |
adcroft |
1.1 |
C IN: |
1397 |
|
|
C dunit integer - 'Opened' I/O channel |
1398 |
|
|
C irec integer - record number to write |
1399 |
|
|
C narr integer - dimension off array "arr" |
1400 |
adcroft |
1.4 |
C mythid integer - thread id |
1401 |
adcroft |
1.1 |
C OUT: |
1402 |
|
|
C arr _RS - model tiled vector |
1403 |
|
|
C |
1404 |
|
|
C Created: 03/29/99 eckert@mit.edu + adcroft@mit.edu |
1405 |
|
|
|
1406 |
|
|
implicit none |
1407 |
adcroft |
1.4 |
|
1408 |
|
|
#include "EEPARAMS.h" |
1409 |
|
|
|
1410 |
adcroft |
1.1 |
C Arguments |
1411 |
|
|
integer dUnit |
1412 |
|
|
integer irec |
1413 |
|
|
integer narr |
1414 |
|
|
_RS arr(narr) |
1415 |
adcroft |
1.4 |
integer mythid |
1416 |
adcroft |
1.1 |
C Local |
1417 |
adcroft |
1.4 |
character*(max_len_mbuf) msgbuf |
1418 |
adcroft |
1.1 |
C ------------------------------------------------------------------ |
1419 |
adcroft |
1.4 |
write(msgbuf,'(a,i9.8,2x,i9.8)') |
1420 |
|
|
& ' MDS_READ_RS_VEC: irec = ',irec,narr |
1421 |
|
|
call print_message( msgbuf, standardmessageunit, |
1422 |
|
|
& SQUEEZE_RIGHT , mythid) |
1423 |
adcroft |
1.1 |
read(dUnit,rec=irec) arr |
1424 |
|
|
C ------------------------------------------------------------------ |
1425 |
|
|
return |
1426 |
|
|
end |
1427 |
|
|
C======================================================================= |
1428 |
|
|
|
1429 |
|
|
C======================================================================= |
1430 |
adcroft |
1.4 |
subroutine MDS_READ_RL_VEC( dUnit, irec, narr, arr, mythid ) |
1431 |
adcroft |
1.1 |
C IN: |
1432 |
|
|
C dunit integer - 'Opened' I/O channel |
1433 |
|
|
C irec integer - record number to write |
1434 |
|
|
C narr integer - dimension off array "arr" |
1435 |
adcroft |
1.4 |
C mythid integer - thread id |
1436 |
adcroft |
1.1 |
C OUT: |
1437 |
|
|
C arr _RL - model tiled vector |
1438 |
|
|
C |
1439 |
|
|
C Created: 03/29/99 eckert@mit.edu + adcroft@mit.edu |
1440 |
|
|
|
1441 |
|
|
implicit none |
1442 |
adcroft |
1.4 |
|
1443 |
|
|
#include "EEPARAMS.h" |
1444 |
|
|
|
1445 |
adcroft |
1.1 |
C Arguments |
1446 |
|
|
integer dUnit |
1447 |
|
|
integer irec |
1448 |
|
|
integer narr |
1449 |
|
|
_RL arr(narr) |
1450 |
adcroft |
1.4 |
integer mythid |
1451 |
adcroft |
1.1 |
C Local |
1452 |
adcroft |
1.4 |
character*(max_len_mbuf) msgbuf |
1453 |
adcroft |
1.1 |
C ------------------------------------------------------------------ |
1454 |
adcroft |
1.4 |
write(msgbuf,'(a,i9.8,2x,i9.8)') |
1455 |
|
|
& ' MDS_READ_RL_VEC: irec = ',irec,narr |
1456 |
|
|
call print_message( msgbuf, standardmessageunit, |
1457 |
|
|
& SQUEEZE_RIGHT , mythid) |
1458 |
adcroft |
1.1 |
read(dUnit,rec=irec) arr |
1459 |
|
|
C ------------------------------------------------------------------ |
1460 |
|
|
return |
1461 |
|
|
end |
1462 |
|
|
C======================================================================= |
1463 |
adcroft |
1.2 |
|
1464 |
|
|
#ifdef _BYTESWAPIO |
1465 |
|
|
C======================================================================= |
1466 |
|
|
subroutine MDS_BYTESWAPR4( n, arr ) |
1467 |
|
|
C IN: |
1468 |
|
|
C n integer - Number of 4-byte words in arr |
1469 |
|
|
C IN/OUT: |
1470 |
|
|
C arr real*4 - Array declared as real*4(n) |
1471 |
|
|
C |
1472 |
|
|
C Created: 05/05/99 adcroft@mit.edu (This is an unfortunate hack!!) |
1473 |
|
|
|
1474 |
|
|
implicit none |
1475 |
|
|
C Arguments |
1476 |
|
|
integer n |
1477 |
|
|
character*(*) arr |
1478 |
|
|
C Local |
1479 |
|
|
integer i |
1480 |
|
|
character*(1) cc |
1481 |
|
|
C ------------------------------------------------------------------ |
1482 |
|
|
do i=1,4*n,4 |
1483 |
|
|
cc=arr(i:i) |
1484 |
|
|
arr(i:i)=arr(i+3:i+3) |
1485 |
|
|
arr(i+3:i+3)=cc |
1486 |
|
|
cc=arr(i+1:i+1) |
1487 |
|
|
arr(i+1:i+1)=arr(i+2:i+2) |
1488 |
|
|
arr(i+2:i+2)=cc |
1489 |
|
|
enddo |
1490 |
|
|
C ------------------------------------------------------------------ |
1491 |
|
|
return |
1492 |
|
|
end |
1493 |
|
|
C======================================================================= |
1494 |
|
|
|
1495 |
|
|
C======================================================================= |
1496 |
|
|
subroutine MDS_BYTESWAPR8( n, arr ) |
1497 |
|
|
C IN: |
1498 |
|
|
C n integer - Number of 8-byte words in arr |
1499 |
|
|
C IN/OUT: |
1500 |
|
|
C arr real*8 - Array declared as real*4(n) |
1501 |
|
|
C |
1502 |
|
|
C Created: 05/05/99 adcroft@mit.edu (This is an unfortunate hack!!) |
1503 |
|
|
|
1504 |
|
|
implicit none |
1505 |
|
|
C Arguments |
1506 |
|
|
integer n |
1507 |
|
|
character*(*) arr |
1508 |
|
|
C Local |
1509 |
|
|
integer i |
1510 |
|
|
character*(1) cc |
1511 |
|
|
C ------------------------------------------------------------------ |
1512 |
|
|
do i=1,8*n,8 |
1513 |
|
|
cc=arr(i:i) |
1514 |
|
|
arr(i:i)=arr(i+7:i+7) |
1515 |
|
|
arr(i+7:i+7)=cc |
1516 |
|
|
cc=arr(i+1:i+1) |
1517 |
|
|
arr(i+1:i+1)=arr(i+6:i+6) |
1518 |
|
|
arr(i+6:i+6)=cc |
1519 |
|
|
cc=arr(i+2:i+2) |
1520 |
|
|
arr(i+2:i+2)=arr(i+5:i+5) |
1521 |
|
|
arr(i+5:i+5)=cc |
1522 |
|
|
cc=arr(i+3:i+3) |
1523 |
|
|
arr(i+3:i+3)=arr(i+4:i+4) |
1524 |
|
|
arr(i+4:i+4)=cc |
1525 |
|
|
enddo |
1526 |
|
|
C ------------------------------------------------------------------ |
1527 |
|
|
return |
1528 |
|
|
end |
1529 |
|
|
C======================================================================= |
1530 |
|
|
#endif |
1531 |
adcroft |
1.4 |
|