1 |
C $Header: /u/gcmpack/MITgcm/pkg/mdsio/mdsio_read_field.F,v 1.17 2011/06/07 22:33:35 jmc Exp $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "MDSIO_OPTIONS.h" |
5 |
|
6 |
CBOP |
7 |
C !ROUTINE: MDS_READ_FIELD |
8 |
C !INTERFACE: |
9 |
SUBROUTINE MDS_READ_FIELD( |
10 |
I fName, |
11 |
I filePrec, |
12 |
I useCurrentDir, |
13 |
I arrType, |
14 |
I kSize,kLo,kHi, |
15 |
O fldRL, fldRS, |
16 |
I irecord, |
17 |
I myThid ) |
18 |
|
19 |
C !DESCRIPTION: |
20 |
C Arguments: |
21 |
C |
22 |
C fName (string) :: base name for file to read |
23 |
C filePrec (integer) :: number of bits per word in file (32 or 64) |
24 |
C useCurrentDir(logic):: always read from the current directory (even if |
25 |
C "mdsioLocalDir" is set) |
26 |
C arrType (char(2)) :: which array (fldRL/RS) to read into, either "RL" or "RS" |
27 |
C kSize (integer) :: size of third dimension: normally either 1 or Nr |
28 |
C kLo (integer) :: 1rst vertical level (of array fldRL/RS) to read-in |
29 |
C kHi (integer) :: last vertical level (of array fldRL/RS) to read-in |
30 |
C fldRL ( RL ) :: array to read into if arrType="RL", fldRL(:,:,kSize,:,:) |
31 |
C fldRS ( RS ) :: array to read into if arrType="RS", fldRS(:,:,kSize,:,:) |
32 |
C irecord (integer) :: record number to read |
33 |
C myIter (integer) :: time step number |
34 |
C myThid (integer) :: thread identifier |
35 |
C |
36 |
C MDS_READ_FIELD first checks to see IF the file "fName" exists, then |
37 |
C IF the file "fName.data" exists and finally the tiled files of the |
38 |
C form "fName.xxx.yyy.data" exist. Currently, the meta-files are not |
39 |
C read because it is difficult to parse files in fortran. |
40 |
C The precision of the file is decsribed by filePrec, set either |
41 |
C to floatPrec32 or floatPrec64. The char*(2) string arrType, either "RL" |
42 |
C or "RS", selects which array is filled in, either fldRL or fldRS. |
43 |
C (kSize,kLo,kHi) allows for both 2-D and 3-D arrays to be handled, with |
44 |
C the option to only read and fill-in a sub-set of consecutive vertical |
45 |
C levels (from kLo to kHi) ; (kSize,kLo,kHi)=(1,1,1) implies a 2-D model |
46 |
C field and (kSize,kLo,kHi)=(Nr,1,Nr) implies a 3-D model field. |
47 |
C irecord is the record number to be read and must be >= 1. |
48 |
C The file data is stored in fldRL/RS *but* the overlaps are *not* updated, |
49 |
C i.e., an exchange must be called. |
50 |
C |
51 |
C- Multi-threaded: Only Master thread does IO (and MPI calls) and put data |
52 |
C to a shared buffer that any thread can get access to. |
53 |
C- Convention regarding thread synchronisation (BARRIER): |
54 |
C A per-thread (or per tile) partition of the 2-D shared-buffer (sharedLocBuf_r4/r8) |
55 |
C is readily available => any access (e.g., by master-thread) to a portion |
56 |
C owned by an other thread is put between BARRIER (protected). |
57 |
C No thread partition exist for the 3-D shared buffer (shared3dBuf_r4/r8). |
58 |
C Therefore, the 3-D buffer is considered to be owned by master-thread and |
59 |
C any access by other than master thread is put between BARRIER (protected). |
60 |
C |
61 |
C Created: 03/16/99 adcroft@mit.edu |
62 |
CEOP |
63 |
|
64 |
C !USES: |
65 |
IMPLICIT NONE |
66 |
C Global variables / common blocks |
67 |
#include "SIZE.h" |
68 |
#include "EEPARAMS.h" |
69 |
#include "PARAMS.h" |
70 |
#ifdef ALLOW_EXCH2 |
71 |
#include "W2_EXCH2_SIZE.h" |
72 |
#include "W2_EXCH2_TOPOLOGY.h" |
73 |
#include "W2_EXCH2_PARAMS.h" |
74 |
#endif /* ALLOW_EXCH2 */ |
75 |
#include "EEBUFF_SCPU.h" |
76 |
#ifdef ALLOW_FIZHI |
77 |
# include "fizhi_SIZE.h" |
78 |
#endif /* ALLOW_FIZHI */ |
79 |
#include "MDSIO_BUFF_3D.h" |
80 |
|
81 |
C !INPUT PARAMETERS: |
82 |
CHARACTER*(*) fName |
83 |
INTEGER filePrec |
84 |
LOGICAL useCurrentDir |
85 |
CHARACTER*(2) arrType |
86 |
INTEGER kSize, kLo, kHi |
87 |
INTEGER irecord |
88 |
INTEGER myThid |
89 |
C !OUTPUT PARAMETERS: |
90 |
_RL fldRL(*) |
91 |
_RS fldRS(*) |
92 |
|
93 |
C !FUNCTIONS |
94 |
INTEGER ILNBLNK |
95 |
INTEGER MDS_RECLEN |
96 |
LOGICAL MASTER_CPU_IO |
97 |
EXTERNAL ILNBLNK |
98 |
EXTERNAL MDS_RECLEN |
99 |
EXTERNAL MASTER_CPU_IO |
100 |
|
101 |
C !LOCAL VARIABLES: |
102 |
C bBij :: base shift in Buffer index for tile bi,bj |
103 |
CHARACTER*(MAX_LEN_FNAM) dataFName,pfName |
104 |
CHARACTER*(MAX_LEN_MBUF) msgBuf |
105 |
LOGICAL exst |
106 |
LOGICAL globalFile, fileIsOpen |
107 |
LOGICAL iAmDoingIO |
108 |
LOGICAL useExch2ioLayOut |
109 |
INTEGER xSize, ySize |
110 |
INTEGER iG,jG,bi,bj |
111 |
INTEGER i1,i2,i,j,k,nNz |
112 |
INTEGER irec,dUnit,IL,pIL |
113 |
INTEGER length_of_rec |
114 |
INTEGER bBij |
115 |
INTEGER tNx, tNy, global_nTx |
116 |
INTEGER tBx, tBy, iGjLoc, jGjLoc |
117 |
#ifdef ALLOW_EXCH2 |
118 |
INTEGER tN |
119 |
#endif /* ALLOW_EXCH2 */ |
120 |
|
121 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
122 |
C Set dimensions: |
123 |
xSize = Nx |
124 |
ySize = Ny |
125 |
useExch2ioLayOut = .FALSE. |
126 |
#ifdef ALLOW_EXCH2 |
127 |
IF ( W2_useE2ioLayOut ) THEN |
128 |
xSize = exch2_global_Nx |
129 |
ySize = exch2_global_Ny |
130 |
useExch2ioLayOut = .TRUE. |
131 |
ENDIF |
132 |
#endif /* ALLOW_EXCH2 */ |
133 |
|
134 |
C Assume nothing |
135 |
globalFile = .FALSE. |
136 |
fileIsOpen = .FALSE. |
137 |
IL = ILNBLNK( fName ) |
138 |
pIL = ILNBLNK( mdsioLocalDir ) |
139 |
nNz = 1 + kHi - kLo |
140 |
|
141 |
C Only do I/O if I am the master thread (and mpi process 0 IF useSingleCpuIO): |
142 |
iAmDoingIO = MASTER_CPU_IO(myThid) |
143 |
|
144 |
C File name should not be too long: |
145 |
C IL(+pIL if not useCurrentDir)(+5: '.data')(+8: bi,bj) =< MAX_LEN_FNAM |
146 |
C and shorter enough to be written to msgBuf with other informations |
147 |
IF ( useCurrentDir .AND. (90+IL).GT.MAX_LEN_MBUF ) THEN |
148 |
WRITE(msgBuf,'(2A,2(I4,A))') 'MDS_READ_FIELD: ', |
149 |
& 'Too long (IL=',IL,') file name:' |
150 |
CALL PRINT_ERROR( msgBuf, myThid ) |
151 |
WRITE(errorMessageUnit,'(3A)')'file: >',fName(1:IL),'<' |
152 |
CALL ALL_PROC_DIE( myThid ) |
153 |
STOP 'ABNORMAL END: S/R MDS_READ_FIELD' |
154 |
ELSEIF ( (90+IL+pIL).GT.MAX_LEN_MBUF ) THEN |
155 |
WRITE(msgBuf,'(2A,2(I4,A))') 'MDS_READ_FIELD: ', |
156 |
& 'Too long (pIL=',pIL,', IL=',IL,') pfix + file name:' |
157 |
CALL PRINT_ERROR( msgBuf, myThid ) |
158 |
WRITE(errorMessageUnit,'(3A)')'pfix: >',mdsioLocalDir(1:pIL),'<' |
159 |
WRITE(errorMessageUnit,'(3A)')'file: >',fName(1:IL),'<' |
160 |
CALL ALL_PROC_DIE( myThid ) |
161 |
STOP 'ABNORMAL END: S/R MDS_READ_FIELD' |
162 |
ENDIF |
163 |
C Record number must be >= 1 |
164 |
IF (irecord .LT. 1) THEN |
165 |
WRITE(msgBuf,'(3A,I10)') |
166 |
& ' MDS_READ_FIELD: file="', fName(1:IL), '"' |
167 |
CALL PRINT_MESSAGE( msgBuf, errorMessageUnit, |
168 |
& SQUEEZE_RIGHT, myThid ) |
169 |
WRITE(msgBuf,'(A,I9.8)') |
170 |
& ' MDS_READ_FIELD: argument irecord = ',irecord |
171 |
CALL PRINT_MESSAGE( msgBuf, errorMessageUnit, |
172 |
& SQUEEZE_RIGHT, myThid ) |
173 |
WRITE(msgBuf,'(A)') |
174 |
& ' MDS_READ_FIELD: Invalid value for irecord' |
175 |
CALL PRINT_ERROR( msgBuf, myThid ) |
176 |
CALL ALL_PROC_DIE( myThid ) |
177 |
STOP 'ABNORMAL END: S/R MDS_READ_FIELD' |
178 |
ENDIF |
179 |
C check for valid sub-set of levels: |
180 |
IF ( kLo.LT.1 .OR. kHi.GT.kSize ) THEN |
181 |
WRITE(msgBuf,'(3A,I10)') |
182 |
& ' MDS_READ_FIELD: file="', fName(1:IL), '"' |
183 |
CALL PRINT_MESSAGE( msgBuf, errorMessageUnit, |
184 |
& SQUEEZE_RIGHT, myThid ) |
185 |
WRITE(msgBuf,'(3(A,I6))') |
186 |
& ' MDS_READ_FIELD: arguments kSize=', kSize, |
187 |
& ' , kLo=', kLo, ' , kHi=', kHi |
188 |
CALL PRINT_MESSAGE( msgBuf, errorMessageUnit, |
189 |
& SQUEEZE_RIGHT, myThid ) |
190 |
WRITE(msgBuf,'(A)') |
191 |
& ' MDS_READ_FIELD: invalid sub-set of levels' |
192 |
CALL PRINT_ERROR( msgBuf, myThid ) |
193 |
CALL ALL_PROC_DIE( myThid ) |
194 |
STOP 'ABNORMAL END: S/R MDS_READ_FIELD' |
195 |
ENDIF |
196 |
C check for 3-D Buffer size: |
197 |
IF ( .NOT.useSingleCpuIO .AND. nNz.GT.size3dBuf ) THEN |
198 |
WRITE(msgBuf,'(3A,I10)') |
199 |
& ' MDS_READ_FIELD: file="', fName(1:IL), '"' |
200 |
CALL PRINT_MESSAGE( msgBuf, errorMessageUnit, |
201 |
& SQUEEZE_RIGHT, myThid ) |
202 |
WRITE(msgBuf,'(3(A,I6))') |
203 |
& ' MDS_READ_FIELD: Nb Lev to read =', nNz, |
204 |
& ' >', size3dBuf, ' = buffer 3rd Dim' |
205 |
CALL PRINT_MESSAGE( msgBuf, errorMessageUnit, |
206 |
& SQUEEZE_RIGHT, myThid ) |
207 |
WRITE(msgBuf,'(A)') |
208 |
& ' MDS_READ_FIELD: buffer 3rd Dim. too small' |
209 |
CALL PRINT_ERROR( msgBuf, myThid ) |
210 |
WRITE(msgBuf,'(A)') |
211 |
& ' increase "size3dBuf" in "MDSIO_BUFF_3D.h" and recompile' |
212 |
CALL PRINT_MESSAGE( msgBuf, errorMessageUnit, |
213 |
& SQUEEZE_RIGHT, myThid ) |
214 |
CALL ALL_PROC_DIE( myThid ) |
215 |
STOP 'ABNORMAL END: S/R MDS_READ_FIELD' |
216 |
ENDIF |
217 |
|
218 |
C Only do I/O if I am the master thread |
219 |
IF ( iAmDoingIO ) THEN |
220 |
|
221 |
C Assign special directory |
222 |
IF ( useCurrentDir .OR. pIL.EQ.0 ) THEN |
223 |
pfName= fName |
224 |
ELSE |
225 |
WRITE(pfName,'(2a)') mdsioLocalDir(1:pIL), fName(1:IL) |
226 |
ENDIF |
227 |
pIL=ILNBLNK( pfName ) |
228 |
|
229 |
C Assign a free unit number as the I/O channel for this routine |
230 |
CALL MDSFINDUNIT( dUnit, myThid ) |
231 |
|
232 |
C Check first for global file with simple name (ie. fName) |
233 |
dataFName = fName |
234 |
INQUIRE( file=dataFName, exist=exst ) |
235 |
IF (exst) THEN |
236 |
IF ( debugLevel .GE. debLevB ) THEN |
237 |
WRITE(msgBuf,'(A,A)') |
238 |
& ' MDS_READ_FIELD: opening global file: ',dataFName(1:IL) |
239 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
240 |
& SQUEEZE_RIGHT, myThid) |
241 |
ENDIF |
242 |
globalFile = .TRUE. |
243 |
ENDIF |
244 |
|
245 |
C If negative check for global file with MDS name (ie. fName.data) |
246 |
IF (.NOT. globalFile) THEN |
247 |
WRITE(dataFName,'(2a)') fName(1:IL),'.data' |
248 |
INQUIRE( file=dataFName, exist=exst ) |
249 |
IF (exst) THEN |
250 |
IF ( debugLevel .GE. debLevB ) THEN |
251 |
WRITE(msgBuf,'(A,A)') |
252 |
& ' MDS_READ_FIELD: opening global file: ',dataFName(1:IL+5) |
253 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
254 |
& SQUEEZE_RIGHT, myThid) |
255 |
ENDIF |
256 |
globalFile = .TRUE. |
257 |
ENDIF |
258 |
ENDIF |
259 |
|
260 |
C- endif iAmDoingIO |
261 |
ENDIF |
262 |
|
263 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
264 |
|
265 |
IF ( useSingleCPUIO ) THEN |
266 |
|
267 |
C master thread of process 0, only, opens a global file |
268 |
IF ( iAmDoingIO ) THEN |
269 |
C If global file is visible to process 0, then open it here. |
270 |
C Otherwise stop program. |
271 |
IF ( globalFile) THEN |
272 |
length_of_rec = MDS_RECLEN( filePrec, xSize*ySize, myThid ) |
273 |
OPEN( dUnit, file=dataFName, status='old', |
274 |
& access='direct', recl=length_of_rec ) |
275 |
ELSE |
276 |
WRITE(msgBuf,'(2A)') |
277 |
& ' MDS_READ_FIELD: filename: ', dataFName(1:IL+5) |
278 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
279 |
& SQUEEZE_RIGHT, myThid) |
280 |
CALL PRINT_ERROR( msgBuf, myThid ) |
281 |
WRITE(msgBuf,'(A)') |
282 |
& ' MDS_READ_FIELD: File does not exist' |
283 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
284 |
& SQUEEZE_RIGHT, myThid) |
285 |
CALL PRINT_ERROR( msgBuf, myThid ) |
286 |
STOP 'ABNORMAL END: S/R MDS_READ_FIELD' |
287 |
ENDIF |
288 |
C- endif iAmDoingIO |
289 |
ENDIF |
290 |
|
291 |
DO k=kLo,kHi |
292 |
|
293 |
C master thread of process 0, only, read from file |
294 |
IF ( iAmDoingIO ) THEN |
295 |
irec = 1 + k-kLo + (irecord-1)*nNz |
296 |
IF (filePrec .EQ. precFloat32) THEN |
297 |
READ(dUnit,rec=irec) ( xy_buffer_r4(i),i=1,xSize*ySize ) |
298 |
#ifdef _BYTESWAPIO |
299 |
CALL MDS_BYTESWAPR4( xSize*ySize, xy_buffer_r4 ) |
300 |
#endif |
301 |
ELSE |
302 |
READ(dUnit,rec=irec) ( xy_buffer_r8(i),i=1,xSize*ySize ) |
303 |
#ifdef _BYTESWAPIO |
304 |
CALL MDS_BYTESWAPR8( xSize*ySize, xy_buffer_r8 ) |
305 |
#endif |
306 |
ENDIF |
307 |
C- endif iAmDoingIO |
308 |
ENDIF |
309 |
|
310 |
C Wait for all thread to finish. This prevents other threads to continue |
311 |
C to acces shared buffer while master thread is loading data into |
312 |
CALL BAR2( myThid ) |
313 |
|
314 |
IF ( filePrec.EQ.precFloat32 ) THEN |
315 |
CALL SCATTER_2D_R4( |
316 |
U xy_buffer_r4, |
317 |
O sharedLocBuf_r4, |
318 |
I xSize, ySize, |
319 |
I useExch2ioLayOut, .FALSE., myThid ) |
320 |
C All threads wait for Master to finish loading into shared buffer |
321 |
CALL BAR2( myThid ) |
322 |
IF ( arrType.EQ.'RS' ) THEN |
323 |
CALL MDS_PASS_R4toRS( sharedLocBuf_r4, fldRS, |
324 |
I 0, 0, 1, k, kSize, 0, 0, .TRUE., myThid ) |
325 |
ELSEIF ( arrType.EQ.'RL' ) THEN |
326 |
CALL MDS_PASS_R4toRL( sharedLocBuf_r4, fldRL, |
327 |
I 0, 0, 1, k, kSize, 0, 0, .TRUE., myThid ) |
328 |
ELSE |
329 |
WRITE(msgBuf,'(A)') |
330 |
& ' MDS_READ_FIELD: illegal value for arrType' |
331 |
CALL PRINT_ERROR( msgBuf, myThid ) |
332 |
CALL ALL_PROC_DIE( myThid ) |
333 |
STOP 'ABNORMAL END: S/R MDS_READ_FIELD' |
334 |
ENDIF |
335 |
ELSEIF ( filePrec.EQ.precFloat64 ) THEN |
336 |
CALL SCATTER_2D_R8( |
337 |
U xy_buffer_r8, |
338 |
O sharedLocBuf_r8, |
339 |
I xSize, ySize, |
340 |
I useExch2ioLayOut, .FALSE., myThid ) |
341 |
C All threads wait for Master to finish loading into shared buffer |
342 |
CALL BAR2( myThid ) |
343 |
IF ( arrType.EQ.'RS' ) THEN |
344 |
CALL MDS_PASS_R8toRS( sharedLocBuf_r8, fldRS, |
345 |
I 0, 0, 1, k, kSize, 0, 0, .TRUE., myThid ) |
346 |
ELSEIF ( arrType.EQ.'RL' ) THEN |
347 |
CALL MDS_PASS_R8toRL( sharedLocBuf_r8, fldRL, |
348 |
I 0, 0, 1, k, kSize, 0, 0, .TRUE., myThid ) |
349 |
ELSE |
350 |
WRITE(msgBuf,'(A)') |
351 |
& ' MDS_READ_FIELD: illegal value for arrType' |
352 |
CALL PRINT_ERROR( msgBuf, myThid ) |
353 |
CALL ALL_PROC_DIE( myThid ) |
354 |
STOP 'ABNORMAL END: S/R MDS_READ_FIELD' |
355 |
ENDIF |
356 |
ELSE |
357 |
WRITE(msgBuf,'(A)') |
358 |
& ' MDS_READ_FIELD: illegal value for filePrec' |
359 |
CALL PRINT_ERROR( msgBuf, myThid ) |
360 |
CALL ALL_PROC_DIE( myThid ) |
361 |
STOP 'ABNORMAL END: S/R MDS_READ_FIELD' |
362 |
ENDIF |
363 |
|
364 |
ENDDO |
365 |
c ENDDO k=kLo,kHi |
366 |
|
367 |
IF ( iAmDoingIO ) THEN |
368 |
CLOSE( dUnit ) |
369 |
ENDIF |
370 |
|
371 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
372 |
C--- else .NOT.useSingleCpuIO |
373 |
ELSE |
374 |
|
375 |
C Wait for all thread to finish. This prevents other threads to continue |
376 |
C to acces 3-D buffer while master thread is reading |
377 |
c CALL BAR2( myThid ) |
378 |
|
379 |
C Only do I/O if I am the master thread |
380 |
IF ( iAmDoingIO ) THEN |
381 |
|
382 |
C If we are reading from a global file then we open it here |
383 |
IF (globalFile) THEN |
384 |
length_of_rec = MDS_RECLEN( filePrec, sNx, myThid ) |
385 |
OPEN( dUnit, file=dataFName, status='old', |
386 |
& access='direct', recl=length_of_rec ) |
387 |
fileIsOpen=.TRUE. |
388 |
ENDIF |
389 |
|
390 |
C Loop over all tiles |
391 |
DO bj=1,nSy |
392 |
DO bi=1,nSx |
393 |
bBij = sNx*sNy*nNz*( bi-1 + (bj-1)*nSx ) |
394 |
|
395 |
IF (globalFile) THEN |
396 |
C--- Case of 1 Global file: |
397 |
|
398 |
c IF (fileIsOpen) THEN |
399 |
tNx = sNx |
400 |
tNy = sNy |
401 |
global_nTx = xSize/sNx |
402 |
tBx = myXGlobalLo-1 + (bi-1)*sNx |
403 |
tBy = myYGlobalLo-1 + (bj-1)*sNy |
404 |
iGjLoc = 0 |
405 |
jGjLoc = 1 |
406 |
#ifdef ALLOW_EXCH2 |
407 |
IF ( useExch2ioLayOut ) THEN |
408 |
tN = W2_myTileList(bi,bj) |
409 |
c tNx = exch2_tNx(tN) |
410 |
c tNy = exch2_tNy(tN) |
411 |
c global_nTx = exch2_global_Nx/tNx |
412 |
tBx = exch2_txGlobalo(tN) - 1 |
413 |
tBy = exch2_tyGlobalo(tN) - 1 |
414 |
IF ( exch2_mydNx(tN) .GT. xSize ) THEN |
415 |
C- face x-size larger than glob-size : fold it |
416 |
iGjLoc = 0 |
417 |
jGjLoc = exch2_mydNx(tN) / xSize |
418 |
ELSEIF ( exch2_tNy(tN) .GT. ySize ) THEN |
419 |
C- tile y-size larger than glob-size : make a long line |
420 |
iGjLoc = exch2_mydNx(tN) |
421 |
jGjLoc = 0 |
422 |
ELSE |
423 |
C- default (face fit into global-IO-array) |
424 |
iGjLoc = 0 |
425 |
jGjLoc = 1 |
426 |
ENDIF |
427 |
ENDIF |
428 |
#endif /* ALLOW_EXCH2 */ |
429 |
|
430 |
DO k=kLo,kHi |
431 |
DO j=1,tNy |
432 |
irec = 1 + ( tBx + (j-1)*iGjLoc )/sNx |
433 |
& + ( tBy + (j-1)*jGjLoc )*global_nTx |
434 |
& +( k-kLo + (irecord-1)*nNz )*global_nTx*ySize |
435 |
i1 = bBij + 1 + (j-1)*sNx + (k-kLo)*sNx*sNy |
436 |
i2 = bBij + j*sNx + (k-kLo)*sNx*sNy |
437 |
IF ( filePrec.EQ.precFloat32 ) THEN |
438 |
READ(dUnit,rec=irec) (shared3dBuf_r4(i),i=i1,i2) |
439 |
ELSE |
440 |
READ(dUnit,rec=irec) (shared3dBuf_r8(i),i=i1,i2) |
441 |
ENDIF |
442 |
C End of j,k loops |
443 |
ENDDO |
444 |
ENDDO |
445 |
|
446 |
C end if fileIsOpen |
447 |
c ENDIF |
448 |
|
449 |
ELSE |
450 |
C--- Case of 1 file per tile (globalFile=F): |
451 |
|
452 |
C If we are reading from a tiled MDS file then we open each one here |
453 |
iG=bi+(myXGlobalLo-1)/sNx |
454 |
jG=bj+(myYGlobalLo-1)/sNy |
455 |
WRITE(dataFName,'(2A,I3.3,A,I3.3,A)') |
456 |
& pfName(1:pIL),'.',iG,'.',jG,'.data' |
457 |
INQUIRE( file=dataFName, exist=exst ) |
458 |
C Of course, we only open the file if the tile is "active" |
459 |
C (This is a place-holder for the active/passive mechanism |
460 |
IF (exst) THEN |
461 |
IF ( debugLevel .GE. debLevB ) THEN |
462 |
WRITE(msgBuf,'(A,A)') |
463 |
& ' MDS_READ_FIELD: opening file: ',dataFName(1:pIL+13) |
464 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
465 |
& SQUEEZE_RIGHT, myThid) |
466 |
ENDIF |
467 |
length_of_rec = MDS_RECLEN( filePrec, sNx*sNy*nNz, myThid ) |
468 |
OPEN( dUnit, file=dataFName, status='old', |
469 |
& access='direct', recl=length_of_rec ) |
470 |
fileIsOpen=.TRUE. |
471 |
ELSE |
472 |
fileIsOpen=.FALSE. |
473 |
WRITE(msgBuf,'(4A)') ' MDS_READ_FIELD: filename: ', |
474 |
& fName(1:IL),' , ', dataFName(1:pIL+13) |
475 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
476 |
& SQUEEZE_RIGHT, myThid) |
477 |
CALL PRINT_ERROR( msgBuf, myThid ) |
478 |
WRITE(msgBuf,'(A)') |
479 |
& ' MDS_READ_FIELD: Files DO not exist' |
480 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
481 |
& SQUEEZE_RIGHT, myThid) |
482 |
CALL PRINT_ERROR( msgBuf, myThid ) |
483 |
STOP 'ABNORMAL END: S/R MDS_READ_FIELD' |
484 |
ENDIF |
485 |
|
486 |
irec = irecord |
487 |
i1 = bBij + 1 |
488 |
i2 = bBij + sNx*sNy*nNz |
489 |
IF ( filePrec.EQ.precFloat32 ) THEN |
490 |
READ(dUnit,rec=irec) (shared3dBuf_r4(i),i=i1,i2) |
491 |
ELSE |
492 |
READ(dUnit,rec=irec) (shared3dBuf_r8(i),i=i1,i2) |
493 |
ENDIF |
494 |
|
495 |
C here We close the tiled MDS file |
496 |
IF ( fileIsOpen ) THEN |
497 |
CLOSE( dUnit ) |
498 |
fileIsOpen = .FALSE. |
499 |
ENDIF |
500 |
|
501 |
C--- End Global File / tile-file cases |
502 |
ENDIF |
503 |
|
504 |
C End of bi,bj loops |
505 |
ENDDO |
506 |
ENDDO |
507 |
|
508 |
C If global file was opened then close it |
509 |
IF (fileIsOpen .AND. globalFile) THEN |
510 |
CLOSE( dUnit ) |
511 |
fileIsOpen = .FALSE. |
512 |
ENDIF |
513 |
|
514 |
#ifdef _BYTESWAPIO |
515 |
IF ( filePrec.EQ.precFloat32 ) THEN |
516 |
CALL MDS_BYTESWAPR4( sNx*sNy*nNz*nSx*nSy, shared3dBuf_r4 ) |
517 |
ELSE |
518 |
CALL MDS_BYTESWAPR8( sNx*sNy*nNz*nSx*nSy, shared3dBuf_r8 ) |
519 |
ENDIF |
520 |
#endif |
521 |
|
522 |
C- endif iAmDoingIO |
523 |
ENDIF |
524 |
|
525 |
C All threads wait for Master to finish reading into shared buffer |
526 |
CALL BAR2( myThid ) |
527 |
|
528 |
C--- Copy from 3-D buffer to fldRL/RS (multi-threads): |
529 |
IF ( filePrec.EQ.precFloat32 ) THEN |
530 |
IF ( arrType.EQ.'RS' ) THEN |
531 |
CALL MDS_PASS_R4toRS( shared3dBuf_r4, fldRS, |
532 |
I 0, 0, nNz, kLo, kSize, 0, 0, .TRUE., myThid ) |
533 |
ELSEIF ( arrType.EQ.'RL' ) THEN |
534 |
CALL MDS_PASS_R4toRL( shared3dBuf_r4, fldRL, |
535 |
I 0, 0, nNz, kLo, kSize, 0, 0, .TRUE., myThid ) |
536 |
ELSE |
537 |
WRITE(msgBuf,'(A)') |
538 |
& ' MDS_READ_FIELD: illegal value for arrType' |
539 |
CALL PRINT_ERROR( msgBuf, myThid ) |
540 |
CALL ALL_PROC_DIE( myThid ) |
541 |
STOP 'ABNORMAL END: S/R MDS_READ_FIELD' |
542 |
ENDIF |
543 |
ELSEIF ( filePrec.EQ.precFloat64 ) THEN |
544 |
IF ( arrType.EQ.'RS' ) THEN |
545 |
CALL MDS_PASS_R8toRS( shared3dBuf_r8, fldRS, |
546 |
I 0, 0, nNz, kLo, kSize, 0, 0, .TRUE., myThid ) |
547 |
ELSEIF ( arrType.EQ.'RL' ) THEN |
548 |
CALL MDS_PASS_R8toRL( shared3dBuf_r8, fldRL, |
549 |
I 0, 0, nNz, kLo, kSize, 0, 0, .TRUE., myThid ) |
550 |
ELSE |
551 |
WRITE(msgBuf,'(A)') |
552 |
& ' MDS_READ_FIELD: illegal value for arrType' |
553 |
CALL PRINT_ERROR( msgBuf, myThid ) |
554 |
CALL ALL_PROC_DIE( myThid ) |
555 |
STOP 'ABNORMAL END: S/R MDS_READ_FIELD' |
556 |
ENDIF |
557 |
ELSE |
558 |
WRITE(msgBuf,'(A)') |
559 |
& ' MDS_READ_FIELD: illegal value for filePrec' |
560 |
CALL PRINT_ERROR( msgBuf, myThid ) |
561 |
CALL ALL_PROC_DIE( myThid ) |
562 |
STOP 'ABNORMAL END: S/R MDS_READ_FIELD' |
563 |
ENDIF |
564 |
|
565 |
C Wait for all threads to finish getting data from 3-D shared buffer. |
566 |
C This prevents the master-thread to change the buffer content before |
567 |
C every one got his data. |
568 |
CALL BAR2( myThid ) |
569 |
|
570 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
571 |
C if useSingleCpuIO / else / end |
572 |
ENDIF |
573 |
|
574 |
RETURN |
575 |
END |