1 |
C $Header: /u/gcmpack/MITgcm/pkg/rw/read_mflds.F,v 1.4 2007/11/25 21:34:01 jmc Exp $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "RW_OPTIONS.h" |
5 |
|
6 |
C-- File read_mflds.F: Routines to handle reading Multi-Fields File (+ meta file) |
7 |
C-- Contents |
8 |
C-- o READ_MFLDS_INIT |
9 |
C-- o READ_MFLDS_SET |
10 |
C-- o READ_MFLDS_3D_RL |
11 |
C-- o READ_MFLDS_LEV_RL |
12 |
C-- o READ_MFLDS_CHECK |
13 |
|
14 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
15 |
CBOP |
16 |
C !ROUTINE: READ_MFLDS_INIT |
17 |
C !INTERFACE: |
18 |
SUBROUTINE READ_MFLDS_INIT( |
19 |
I myThid ) |
20 |
|
21 |
C !DESCRIPTION: |
22 |
C Initialise Multi-Fields read variables in common block |
23 |
|
24 |
C !USES: |
25 |
IMPLICIT NONE |
26 |
c#include "SIZE.h" |
27 |
#include "EEPARAMS.h" |
28 |
#include "RW_MFLDS.h" |
29 |
|
30 |
C !INPUT/OUTPUT PARAMETERS: |
31 |
C myThid :: my Thread Id. number |
32 |
INTEGER myThid |
33 |
CEOP |
34 |
|
35 |
C !LOCAL VARIABLES: |
36 |
C i :: loop counter |
37 |
INTEGER i |
38 |
C- for debug print: |
39 |
c CHARACTER*(MAX_LEN_MBUF) msgBuf |
40 |
|
41 |
C----- |
42 |
|
43 |
C- Initialise variables in common block: |
44 |
thirdDim = 0 |
45 |
nFl3D = 0 |
46 |
nFlds = 0 |
47 |
nMissFld = 0 |
48 |
mFldsFile = ' ' |
49 |
DO i=1,sizFldList |
50 |
fldList(i) = ' ' |
51 |
fldMiss(i) = ' ' |
52 |
ENDDO |
53 |
|
54 |
RETURN |
55 |
END |
56 |
|
57 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
58 |
CBOP |
59 |
C !ROUTINE: READ_MFLDS_SET |
60 |
C !INTERFACE: |
61 |
SUBROUTINE READ_MFLDS_SET( |
62 |
I fName, |
63 |
O nbFields, filePrec, |
64 |
I fileDim3, myIter, myThid ) |
65 |
|
66 |
C !DESCRIPTION: |
67 |
C This is the controlling routine for preparing Multi-Fields read |
68 |
C by reading the corresponding meta file. |
69 |
C the meta-file content is stored in common block (header: RW_MFLDS.h) |
70 |
C to be reachable by all threads |
71 |
|
72 |
C Note: 1) Output arguments should not be shared variables (= not in common block) |
73 |
C 2) Only master-thread returns a valid filePrec (others just return 0) |
74 |
|
75 |
C !USES: |
76 |
IMPLICIT NONE |
77 |
#include "SIZE.h" |
78 |
#include "EEPARAMS.h" |
79 |
#include "PARAMS.h" |
80 |
#include "RW_MFLDS.h" |
81 |
|
82 |
C !INPUT/OUTPUT PARAMETERS: |
83 |
C fName :: current MFLDS file name (prefix) to read |
84 |
C nbFields :: Number of fields in current MFLDS file |
85 |
C filePrec :: data-precision in current MFLDS file |
86 |
C fileDim3 :: 3rd dimension of fields in current MFLDS file |
87 |
C myIter :: Iteration number |
88 |
C myThid :: my Thread Id. number |
89 |
CHARACTER*(MAX_LEN_FNAM) fName |
90 |
INTEGER nbFields |
91 |
INTEGER filePrec |
92 |
INTEGER fileDim3 |
93 |
INTEGER myIter |
94 |
INTEGER myThid |
95 |
CEOP |
96 |
|
97 |
C !FUNCTIONS |
98 |
INTEGER ILNBLNK |
99 |
EXTERNAL ILNBLNK |
100 |
|
101 |
C !LOCAL VARIABLES: |
102 |
C- do change dir. (using mdsioLocalDir): |
103 |
LOGICAL useCurrentDir |
104 |
C- output of MDS_READ_META : |
105 |
INTEGER nSizD, nSizT |
106 |
PARAMETER( nSizD = 5 , nSizT = 20 ) |
107 |
CHARACTER*(MAX_LEN_PREC/2) simulName |
108 |
CHARACTER*(MAX_LEN_MBUF/2) titleLine |
109 |
INTEGER nDims, nTimRec |
110 |
INTEGER dimList(3,nSizD) |
111 |
_RL timList(nSizT) |
112 |
INTEGER nRecords, fileIter |
113 |
C- for debug print: |
114 |
INTEGER i, j, ioUnit |
115 |
CHARACTER*(MAX_LEN_MBUF) msgBuf |
116 |
|
117 |
C----- |
118 |
|
119 |
C- Initialise output arguments: |
120 |
nbFields = 0 |
121 |
filePrec = 0 |
122 |
|
123 |
#ifdef RW_SAFE_MFLDS |
124 |
i = ILNBLNK(mFldsFile) |
125 |
IF ( i.NE.0 ) THEN |
126 |
i = MIN(i, MAX_LEN_MBUF-48-34 ) |
127 |
WRITE(msgBuf,'(4A)') 'READ_MFLDS_SET: ', |
128 |
& 'MFLDS file-name already set to: ',mFldsFile(1:i) |
129 |
CALL PRINT_ERROR( msgBuf, myThid ) |
130 |
STOP 'ABNORMAL END: S/R READ_MFLDS_SET (fileName)' |
131 |
ENDIF |
132 |
_BARRIER |
133 |
#endif /* RW_SAFE_MFLDS */ |
134 |
_BEGIN_MASTER( myThid ) |
135 |
|
136 |
C- Initialise variables in common block: |
137 |
thirdDim = fileDim3 |
138 |
nFl3D = 0 |
139 |
nFlds = 0 |
140 |
nMissFld = 0 |
141 |
mFldsFile = fName |
142 |
DO i=1,sizFldList |
143 |
fldList(i) = ' ' |
144 |
fldMiss(i) = ' ' |
145 |
ENDDO |
146 |
|
147 |
#ifdef ALLOW_MDSIO |
148 |
useCurrentDir = .FALSE. |
149 |
nDims = nSizD |
150 |
nFlds = sizFldList |
151 |
nTimRec = nSizT |
152 |
CALL MDS_READ_META( |
153 |
I fName, |
154 |
O simulName, |
155 |
O titleLine, |
156 |
O filePrec, |
157 |
U nDims, nFlds, nTimRec, |
158 |
O dimList, fldList, timList, |
159 |
O nRecords, fileIter, |
160 |
I useCurrentDir, myThid ) |
161 |
#endif /* ALLOW_MDSIO */ |
162 |
|
163 |
C- evaluate Nb of 3.D fields (used if mix 3-D & 2-D fields in file): |
164 |
nFl3D = 0 |
165 |
IF ( nFlds.GE.1 ) THEN |
166 |
IF ( nDims.EQ.2 .AND. thirdDim.GT.1 |
167 |
& .AND. nFlds.LT.nRecords ) THEN |
168 |
IF ( MOD( nRecords-nFlds , thirdDim-1 ) .EQ. 0 ) |
169 |
& nFl3D = (nRecords-nFlds)/(thirdDim-1) |
170 |
ENDIF |
171 |
IF ( nFlds.NE.nRecords .AND. nFl3D.EQ.0 ) THEN |
172 |
C- here we have a problem |
173 |
WRITE(msgBuf,'(A,I5,A,I4,A)') |
174 |
& 'READ_MFLDS_SET: Pb with Nb of records=', nRecords, |
175 |
& ' (3rd-Dim=', thirdDim,')' |
176 |
CALL PRINT_ERROR( msgBuf, myThid ) |
177 |
WRITE(msgBuf,'(A,I5,A,I4,A)') |
178 |
& ' does not match Nb of flds=', nFlds |
179 |
CALL PRINT_ERROR( msgBuf, myThid ) |
180 |
STOP 'ABNORMAL END: S/R READ_MFLDS_SET (Nb-records Pb)' |
181 |
ENDIF |
182 |
c IF ( nFl3D.EQ.0 ) nFl3D = nFlds |
183 |
ENDIF |
184 |
|
185 |
C- write to Standard Output |
186 |
IF ( debugLevel.GE.debLevA ) THEN |
187 |
ioUnit = standardMessageUnit |
188 |
i = ILNBLNK(simulName) |
189 |
IF ( i.GE.1 ) THEN |
190 |
WRITE(msgBuf,'(3A)') ' simulName=>', simulName(1:i), '<' |
191 |
CALL PRINT_MESSAGE(msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
192 |
ENDIF |
193 |
i = ILNBLNK(titleLine) |
194 |
IF ( i.GE.1 ) THEN |
195 |
WRITE(msgBuf,'(3A)') ' titleLine=>', titleLine(1:i), '<' |
196 |
CALL PRINT_MESSAGE(msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
197 |
ENDIF |
198 |
WRITE(msgBuf,'(2(A,I4),A,I10)') |
199 |
& ' nRecords =', nRecords, ' ; filePrec =', filePrec, |
200 |
& ' ; fileIter =', fileIter |
201 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
202 |
WRITE(msgBuf,'(A,I4,A)') ' nDims =', nDims, ' , dims:' |
203 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
204 |
DO j=1,nDims |
205 |
WRITE(msgBuf,'(I4,A,3I4)') j,':',(dimList(i,j),i=1,3) |
206 |
CALL PRINT_MESSAGE(msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
207 |
ENDDO |
208 |
WRITE(msgBuf,'(3(A,I4))') |
209 |
& ' nFlds =', nFlds, ' , nFl3D =', nFl3D, ' , fields:' |
210 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
211 |
DO j=1,nFlds,20 |
212 |
WRITE(msgBuf,'(20(A2,A8,A))') |
213 |
& (' >', fldList(i), '<', i=j,MIN(j+19,nFlds) ) |
214 |
CALL PRINT_MESSAGE(msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
215 |
ENDDO |
216 |
WRITE(msgBuf,'(A,I4,A)') ' nTimRec =',nTimRec,' , timeList:' |
217 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
218 |
IF ( nTimRec.GE.1 ) THEN |
219 |
WRITE(msgBuf,'(1P20E20.12)') (timList(i),i=1,nTimRec) |
220 |
CALL PRINT_MESSAGE(msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
221 |
ENDIF |
222 |
ENDIF |
223 |
|
224 |
_END_MASTER( myThid ) |
225 |
_BARRIER |
226 |
|
227 |
C- set output arguments: |
228 |
nbFields = nFlds |
229 |
|
230 |
RETURN |
231 |
END |
232 |
|
233 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
234 |
CBOP |
235 |
C !ROUTINE: READ_MFLDS_3D_RL |
236 |
C !INTERFACE: |
237 |
SUBROUTINE READ_MFLDS_3D_RL( |
238 |
I fldName, |
239 |
O field, |
240 |
U nj, |
241 |
I fPrec, nNz, myIter, myThid ) |
242 |
|
243 |
C !DESCRIPTION: |
244 |
C Read, from a Multi-Fields binary file, field "fldName" into array "field" |
245 |
C record Nb "nj" is search through the field-list (from meta-file) which |
246 |
C has been set before (calling READ_MFLDS_SET). |
247 |
C In case nFlds is <=0 , by-pass the search and directly read record number "nj" |
248 |
|
249 |
C !USES: |
250 |
IMPLICIT NONE |
251 |
#include "SIZE.h" |
252 |
#include "EEPARAMS.h" |
253 |
#include "PARAMS.h" |
254 |
#include "RW_MFLDS.h" |
255 |
|
256 |
C !INPUT/OUTPUT PARAMETERS: |
257 |
C fldName :: Name of the field to read |
258 |
C field :: Output array to read in |
259 |
C nj (in) :: number of the record (in file) just before the one to read |
260 |
C nj (out):: number of the record (from current file) which was read in |
261 |
C fPrec :: File precision (number of bits per word, = 32 or 64) |
262 |
C nNz :: Number of levels to read in |
263 |
C myIter :: Iteration number |
264 |
C myThid :: My Thread Id number |
265 |
CHARACTER*(8) fldName |
266 |
_RL field(*) |
267 |
INTEGER nj |
268 |
INTEGER fPrec |
269 |
INTEGER nNz |
270 |
INTEGER myIter |
271 |
INTEGER myThid |
272 |
CEOP |
273 |
|
274 |
C !FUNCTIONS |
275 |
INTEGER ILNBLNK |
276 |
EXTERNAL ILNBLNK |
277 |
|
278 |
C !LOCAL VARIABLES: |
279 |
INTEGER j, iL, ioUnit |
280 |
LOGICAL useCurrentDir |
281 |
_RS dummyRS(1) |
282 |
CHARACTER*(2) fType |
283 |
CHARACTER*(MAX_LEN_FNAM) fName |
284 |
CHARACTER*(MAX_LEN_MBUF) msgBuf |
285 |
|
286 |
C----- |
287 |
|
288 |
iL = ILNBLNK(mFldsFile) |
289 |
#ifdef RW_SAFE_MFLDS |
290 |
IF ( iL.EQ.0 ) THEN |
291 |
WRITE(msgBuf,'(2A,I4)') 'READ_MFLDS_3D_RL: ', |
292 |
& 'empty MFLDS file-name' |
293 |
CALL PRINT_ERROR( msgBuf, myThid ) |
294 |
STOP 'ABNORMAL END: S/R READ_MFLDS_3D_RL (fileName)' |
295 |
ENDIF |
296 |
#endif /* RW_SAFE_MFLDS */ |
297 |
|
298 |
ioUnit = standardMessageUnit |
299 |
IF ( nFlds.GE.1 ) THEN |
300 |
C-- Search for "fldName" in list of field-names: |
301 |
nj = 0 |
302 |
DO j=1,nFlds |
303 |
IF ( fldName.EQ.fldList(j) .AND. nj.EQ.0 ) nj = j |
304 |
ENDDO |
305 |
IF ( nj.EQ.0 ) THEN |
306 |
C- record unsuccessful search: |
307 |
_BEGIN_MASTER( myThid ) |
308 |
nMissFld = nMissFld + 1 |
309 |
j = MIN(nMissFld,sizFldList) |
310 |
fldMiss(j) = fldName |
311 |
_END_MASTER( myThid ) |
312 |
IF ( debugLevel.GE.debLevA ) THEN |
313 |
iL = ILNBLNK(mFldsFile) |
314 |
iL = MIN(iL,MAX_LEN_MBUF-54-20) |
315 |
WRITE(msgBuf,'(5A)') 'READ_MFLDS_3D_RL: ', |
316 |
& 'field: "',fldName,'" missing in file: ',mFldsFile(1:iL) |
317 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
318 |
ENDIF |
319 |
ELSE |
320 |
C- convert from field Number to record number (if mix of 3D & 2D flds) |
321 |
j = nj |
322 |
IF ( nj.GT.nFl3D ) nj = nj + nFl3D*(thirdDim-1) |
323 |
IF ( debugLevel.GE.debLevA ) THEN |
324 |
WRITE(msgBuf,'(3A,2(A,I4))') 'READ_MFLDS_3D_RL: ', |
325 |
& 'read field: "',fldName,'", #',j,' in fldList, rec=',nj |
326 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
327 |
ENDIF |
328 |
ENDIF |
329 |
ELSEIF ( nj.GE.0 ) THEN |
330 |
C- increment record number |
331 |
nj = nj + 1 |
332 |
IF ( debugLevel.GE.debLevA ) THEN |
333 |
WRITE(msgBuf,'(3A,2(A,I4))') 'READ_MFLDS_3D_RL: ', |
334 |
& 'no fldList, try to read field "',fldName, '", rec=',nj |
335 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
336 |
ENDIF |
337 |
ENDIF |
338 |
|
339 |
IF ( nj.GE.1 ) THEN |
340 |
C-- read in array "field" |
341 |
fName = mFldsFile |
342 |
useCurrentDir = .FALSE. |
343 |
fType = 'RL' |
344 |
#ifdef ALLOW_MDSIO |
345 |
CALL MDS_READ_FIELD( |
346 |
I fName, fPrec, useCurrentDir, |
347 |
I fType, nNz, 1, nNz, |
348 |
O field, dummyRS, |
349 |
I nj, myThid ) |
350 |
|
351 |
#endif |
352 |
ENDIF |
353 |
|
354 |
RETURN |
355 |
END |
356 |
|
357 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
358 |
CBOP |
359 |
C !ROUTINE: READ_MFLDS_LEV_RL |
360 |
C !INTERFACE: |
361 |
SUBROUTINE READ_MFLDS_LEV_RL( |
362 |
I fldName, |
363 |
O field, |
364 |
U nj, |
365 |
I fPrec, kSiz, kLo, kHi, myIter, myThid ) |
366 |
|
367 |
C !DESCRIPTION: |
368 |
C Read, from a Multi-Fields binary file, field "fldName", a set of |
369 |
C consecutive levels (from kLo to kHi) into 3D array "field" (size: kSiz) |
370 |
C record Nb "nj" is search through the field-list (from meta-file) which |
371 |
C has been set before (calling READ_MFLDS_SET). |
372 |
C In case nFlds is <=0 , by-pass the search and directly read record number "nj" |
373 |
|
374 |
C !USES: |
375 |
IMPLICIT NONE |
376 |
#include "SIZE.h" |
377 |
#include "EEPARAMS.h" |
378 |
#include "PARAMS.h" |
379 |
#include "RW_MFLDS.h" |
380 |
|
381 |
C !INPUT/OUTPUT PARAMETERS: |
382 |
C fldName :: Name of the field to read |
383 |
C field :: Output array to read in |
384 |
C nj (in) :: number of the record (in file) just before the one to read |
385 |
C nj (out):: number of the record (from current file) which was read in |
386 |
C fPrec :: File precision (number of bits per word, = 32 or 64) |
387 |
C kSiz :: size of third dimension of array "field" to read-in |
388 |
C kLo :: 1rst vertical level (of array "field") to read-in |
389 |
C kHi :: last vertical level (of array "field") to read-in |
390 |
C myIter :: Iteration number |
391 |
C myThid :: My Thread Id number |
392 |
CHARACTER*(8) fldName |
393 |
_RL field(*) |
394 |
INTEGER nj |
395 |
INTEGER fPrec |
396 |
INTEGER kSiz, kLo, kHi |
397 |
INTEGER myIter |
398 |
INTEGER myThid |
399 |
CEOP |
400 |
|
401 |
C !FUNCTIONS |
402 |
INTEGER ILNBLNK |
403 |
EXTERNAL ILNBLNK |
404 |
|
405 |
C !LOCAL VARIABLES: |
406 |
INTEGER j, iL, ioUnit |
407 |
LOGICAL useCurrentDir |
408 |
_RS dummyRS(1) |
409 |
CHARACTER*(2) fType |
410 |
CHARACTER*(MAX_LEN_FNAM) fName |
411 |
CHARACTER*(MAX_LEN_MBUF) msgBuf |
412 |
|
413 |
C----- |
414 |
|
415 |
iL = ILNBLNK(mFldsFile) |
416 |
#ifdef RW_SAFE_MFLDS |
417 |
IF ( iL.EQ.0 ) THEN |
418 |
WRITE(msgBuf,'(2A,I4)') 'READ_MFLDS_LEV_RL: ', |
419 |
& 'empty MFLDS file-name' |
420 |
CALL PRINT_ERROR( msgBuf, myThid ) |
421 |
STOP 'ABNORMAL END: S/R READ_MFLDS_LEV_RL (fileName)' |
422 |
ENDIF |
423 |
#endif /* RW_SAFE_MFLDS */ |
424 |
|
425 |
ioUnit = standardMessageUnit |
426 |
IF ( nFlds.GE.1 ) THEN |
427 |
C-- Search for "fldName" in list of field-names: |
428 |
nj = 0 |
429 |
DO j=1,nFlds |
430 |
IF ( fldName.EQ.fldList(j) .AND. nj.EQ.0 ) nj = j |
431 |
ENDDO |
432 |
IF ( nj.EQ.0 ) THEN |
433 |
C- record unsuccessful search: |
434 |
_BEGIN_MASTER( myThid ) |
435 |
nMissFld = nMissFld + 1 |
436 |
j = MIN(nMissFld,sizFldList) |
437 |
fldMiss(j) = fldName |
438 |
_END_MASTER( myThid ) |
439 |
IF ( debugLevel.GE.debLevA ) THEN |
440 |
iL = ILNBLNK(mFldsFile) |
441 |
iL = MIN(iL,MAX_LEN_MBUF-54-20) |
442 |
WRITE(msgBuf,'(5A)') 'READ_MFLDS_LEV_RL: ', |
443 |
& 'field: "',fldName,'" missing in file: ',mFldsFile(1:iL) |
444 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
445 |
ENDIF |
446 |
ELSE |
447 |
C- convert from field Number to record number (if mix of 3D & 2D flds) |
448 |
j = nj |
449 |
IF ( nj.GT.nFl3D ) nj = nj + nFl3D*(thirdDim-1) |
450 |
IF ( debugLevel.GE.debLevA ) THEN |
451 |
WRITE(msgBuf,'(3A,2(A,I4))') 'READ_MFLDS_LEV_RL: ', |
452 |
& 'read field: "',fldName,'", #',j,' in fldList, rec=',nj |
453 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
454 |
ENDIF |
455 |
ENDIF |
456 |
ELSEIF ( nj.GE.0 ) THEN |
457 |
C- increment record number |
458 |
nj = nj + 1 |
459 |
IF ( debugLevel.GE.debLevA ) THEN |
460 |
WRITE(msgBuf,'(3A,2(A,I4))') 'READ_MFLDS_LEV_RL: ', |
461 |
& 'no fldList, try to read field "',fldName, '", rec=',nj |
462 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
463 |
ENDIF |
464 |
ENDIF |
465 |
|
466 |
IF ( nj.GE.1 ) THEN |
467 |
C-- read in array "field" |
468 |
fName = mFldsFile |
469 |
useCurrentDir = .FALSE. |
470 |
fType = 'RL' |
471 |
#ifdef ALLOW_MDSIO |
472 |
CALL MDS_READ_FIELD( |
473 |
I fName, fPrec, useCurrentDir, |
474 |
I fType, kSiz, kLo, kHi, |
475 |
O field, dummyRS, |
476 |
I nj, myThid ) |
477 |
|
478 |
#endif |
479 |
ENDIF |
480 |
|
481 |
RETURN |
482 |
END |
483 |
|
484 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
485 |
CBOP |
486 |
C !ROUTINE: READ_MFLDS_CHECK |
487 |
C !INTERFACE: |
488 |
SUBROUTINE READ_MFLDS_CHECK( |
489 |
O errList, |
490 |
U nbErr, |
491 |
I myIter, myThid ) |
492 |
|
493 |
C !DESCRIPTION: |
494 |
C After reading a Multi-Fields binary file, check (and report) |
495 |
C for missing fields (attempted to read but not found). |
496 |
C |
497 |
C Note: If missing fields, print error msg but take no action (no stop) |
498 |
C but return number of missing fields (+ list, if nbErr_inputArg > 0) |
499 |
C Depending on the calling context, may choose to stop or to continue |
500 |
|
501 |
C !USES: |
502 |
IMPLICIT NONE |
503 |
#include "SIZE.h" |
504 |
#include "EEPARAMS.h" |
505 |
#include "PARAMS.h" |
506 |
#include "RW_MFLDS.h" |
507 |
|
508 |
C !INPUT PARAMETERS: |
509 |
C nbErr :: max size of array errList |
510 |
C myIter :: Iteration number |
511 |
C myThid :: My Thread Id number |
512 |
C !OUTPUT PARAMETERS: |
513 |
C errList :: List of missing fields (attempted to read but not found) |
514 |
C nbErr :: Number of missing fields (attempted to read but not found) |
515 |
CHARACTER*(8) errList(*) |
516 |
INTEGER nbErr |
517 |
INTEGER myIter |
518 |
INTEGER myThid |
519 |
CEOP |
520 |
|
521 |
C !FUNCTIONS |
522 |
INTEGER ILNBLNK |
523 |
EXTERNAL ILNBLNK |
524 |
|
525 |
C !LOCAL VARIABLES: |
526 |
INTEGER i, j, nj, iL, ioUnit |
527 |
CHARACTER*(MAX_LEN_MBUF) msgBuf |
528 |
|
529 |
C----- |
530 |
|
531 |
iL = ILNBLNK(mFldsFile) |
532 |
#ifdef RW_SAFE_MFLDS |
533 |
IF ( iL.EQ.0 ) THEN |
534 |
WRITE(msgBuf,'(2A,I4)') 'READ_MFLDS_CHECK: ', |
535 |
& 'empty MFLDS file-name' |
536 |
CALL PRINT_ERROR( msgBuf, myThid ) |
537 |
STOP 'ABNORMAL END: S/R READ_MFLDS_CHECK (fileName)' |
538 |
ENDIF |
539 |
#endif /* RW_SAFE_MFLDS */ |
540 |
|
541 |
|
542 |
C-- Initialise output arguments |
543 |
DO j=1,nbErr |
544 |
errList(j) = ' ' |
545 |
ENDDO |
546 |
|
547 |
C-- every one waits for master thread to finish the update of |
548 |
C missing fields number & list. |
549 |
_BARRIER |
550 |
|
551 |
IF ( nMissFld.GE.1 ) THEN |
552 |
C-- Attempted to read some fields that were not in the current MFLDS file |
553 |
C => report by printing Error Msg: |
554 |
ioUnit = errorMessageUnit |
555 |
WRITE(msgBuf,'(3A)') 'READ_MFLDS_CHECK: ', |
556 |
& 'reading from file: ', mFldsFile(1:iL) |
557 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
558 |
WRITE(msgBuf,'(2A,I4,A)') 'READ_MFLDS_CHECK: ', |
559 |
& 'which contains ', nFlds, ' fields :' |
560 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
561 |
DO j=1,nFlds,20 |
562 |
WRITE(msgBuf,'(20(A2,A8,A))') |
563 |
& (' >', fldList(i), '<', i=j,MIN(j+19,nFlds) ) |
564 |
CALL PRINT_MESSAGE(msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
565 |
ENDDO |
566 |
WRITE(msgBuf,'(A,I4,A)') 'READ_MFLDS_CHECK: ', |
567 |
& nMissFld, ' field(s) is/are missing :' |
568 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
569 |
nj = MIN( nMissFld, sizFldList ) |
570 |
DO j=1,nj,20 |
571 |
WRITE(msgBuf,'(20(A2,A8,A))') |
572 |
& (' >', fldMiss(i), '<', i=j,MIN(j+19,nj) ) |
573 |
CALL PRINT_MESSAGE(msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
574 |
ENDDO |
575 |
|
576 |
C- Size problem: |
577 |
IF ( nMissFld.GT.sizFldList ) THEN |
578 |
WRITE(msgBuf,'(2A,I4)') 'READ_MFLDS_CHECK: ', |
579 |
& 'missing fields list has been truncated to', sizFldList |
580 |
CALL PRINT_ERROR( msgBuf, myThid ) |
581 |
STOP 'ABNORMAL END: S/R READ_MFLDS_CHECK (list-size Pb)' |
582 |
ENDIF |
583 |
|
584 |
C- Fill the error output list (up to the Max size: nbErr) |
585 |
nj = MIN( nMissFld, nbErr ) |
586 |
DO j=1,nj |
587 |
errList(j) = fldMiss(j) |
588 |
ENDDO |
589 |
ELSE |
590 |
C-- Normal end : print msg before resetting "mFldsFile" |
591 |
ioUnit = standardMessageUnit |
592 |
IF ( debugLevel .GE. debLevA ) THEN |
593 |
WRITE(msgBuf,'(3A)') 'READ_MFLDS_CHECK: ', |
594 |
c & '- end reading file: ', mFldsFile(1:iL) |
595 |
c & '- normal end ; reset mFldsFile: ', mFldsFile(1:iL) |
596 |
& '- normal end ; reset MFLDS file-name: ', mFldsFile(1:iL) |
597 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
598 |
ENDIF |
599 |
|
600 |
ENDIF |
601 |
|
602 |
C- Return the number of missing fields |
603 |
nbErr = nMissFld |
604 |
|
605 |
#ifdef RW_SAFE_MFLDS |
606 |
_BARRIER |
607 |
_BEGIN_MASTER( myThid ) |
608 |
C-- Reset MFLDS file name: |
609 |
mFldsFile = ' ' |
610 |
_END_MASTER( myThid ) |
611 |
_BARRIER |
612 |
#endif /* RW_SAFE_MFLDS */ |
613 |
|
614 |
RETURN |
615 |
END |