1 |
C $Header: /u/gcmpack/MITgcm/pkg/rw/read_mflds.F,v 1.3 2007/11/13 19:41:05 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 |
CHARACTER*(2) fType |
282 |
CHARACTER*(MAX_LEN_FNAM) fName |
283 |
CHARACTER*(MAX_LEN_MBUF) msgBuf |
284 |
|
285 |
C----- |
286 |
|
287 |
iL = ILNBLNK(mFldsFile) |
288 |
#ifdef RW_SAFE_MFLDS |
289 |
IF ( iL.EQ.0 ) THEN |
290 |
WRITE(msgBuf,'(2A,I4)') 'READ_MFLDS_3D_RL: ', |
291 |
& 'empty MFLDS file-name' |
292 |
CALL PRINT_ERROR( msgBuf, myThid ) |
293 |
STOP 'ABNORMAL END: S/R READ_MFLDS_3D_RL (fileName)' |
294 |
ENDIF |
295 |
#endif /* RW_SAFE_MFLDS */ |
296 |
|
297 |
ioUnit = standardMessageUnit |
298 |
IF ( nFlds.GE.1 ) THEN |
299 |
C-- Search for "fldName" in list of field-names: |
300 |
nj = 0 |
301 |
DO j=1,nFlds |
302 |
IF ( fldName.EQ.fldList(j) .AND. nj.EQ.0 ) nj = j |
303 |
ENDDO |
304 |
IF ( nj.EQ.0 ) THEN |
305 |
C- record unsuccessful search: |
306 |
_BEGIN_MASTER( myThid ) |
307 |
nMissFld = nMissFld + 1 |
308 |
j = MIN(nMissFld,sizFldList) |
309 |
fldMiss(j) = fldName |
310 |
_END_MASTER( myThid ) |
311 |
IF ( debugLevel.GE.debLevA ) THEN |
312 |
iL = ILNBLNK(mFldsFile) |
313 |
iL = MIN(iL,MAX_LEN_MBUF-54-20) |
314 |
WRITE(msgBuf,'(5A)') 'READ_MFLDS_3D_RL: ', |
315 |
& 'field: "',fldName,'" missing in file: ',mFldsFile(1:iL) |
316 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
317 |
ENDIF |
318 |
ELSE |
319 |
C- convert from field Number to record number (if mix of 3D & 2D flds) |
320 |
j = nj |
321 |
IF ( nj.GT.nFl3D ) nj = nj + nFl3D*(thirdDim-1) |
322 |
IF ( debugLevel.GE.debLevA ) THEN |
323 |
WRITE(msgBuf,'(3A,2(A,I4))') 'READ_MFLDS_3D_RL: ', |
324 |
& 'read field: "',fldName,'", #',j,' in fldList, rec=',nj |
325 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
326 |
ENDIF |
327 |
ENDIF |
328 |
ELSEIF ( nj.GE.0 ) THEN |
329 |
C- increment record number |
330 |
nj = nj + 1 |
331 |
IF ( debugLevel.GE.debLevA ) THEN |
332 |
WRITE(msgBuf,'(3A,2(A,I4))') 'READ_MFLDS_3D_RL: ', |
333 |
& 'no fldList, try to read field "',fldName, '", rec=',nj |
334 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
335 |
ENDIF |
336 |
ENDIF |
337 |
|
338 |
IF ( nj.GE.1 ) THEN |
339 |
C-- read in array "field" |
340 |
fName = mFldsFile |
341 |
useCurrentDir = .FALSE. |
342 |
fType = 'RL' |
343 |
#ifdef ALLOW_MDSIO |
344 |
CALL MDS_READ_FIELD( |
345 |
I fName, fPrec, useCurrentDir, |
346 |
I fType, nNz, 1, nNz, |
347 |
O field, |
348 |
I nj, myThid ) |
349 |
|
350 |
#endif |
351 |
ENDIF |
352 |
|
353 |
RETURN |
354 |
END |
355 |
|
356 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
357 |
CBOP |
358 |
C !ROUTINE: READ_MFLDS_LEV_RL |
359 |
C !INTERFACE: |
360 |
SUBROUTINE READ_MFLDS_LEV_RL( |
361 |
I fldName, |
362 |
O field, |
363 |
U nj, |
364 |
I fPrec, kSiz, kLo, kHi, myIter, myThid ) |
365 |
|
366 |
C !DESCRIPTION: |
367 |
C Read, from a Multi-Fields binary file, field "fldName", a set of |
368 |
C consecutive levels (from kLo to kHi) into 3D array "field" (size: kSiz) |
369 |
C record Nb "nj" is search through the field-list (from meta-file) which |
370 |
C has been set before (calling READ_MFLDS_SET). |
371 |
C In case nFlds is <=0 , by-pass the search and directly read record number "nj" |
372 |
|
373 |
C !USES: |
374 |
IMPLICIT NONE |
375 |
#include "SIZE.h" |
376 |
#include "EEPARAMS.h" |
377 |
#include "PARAMS.h" |
378 |
#include "RW_MFLDS.h" |
379 |
|
380 |
C !INPUT/OUTPUT PARAMETERS: |
381 |
C fldName :: Name of the field to read |
382 |
C field :: Output array to read in |
383 |
C nj (in) :: number of the record (in file) just before the one to read |
384 |
C nj (out):: number of the record (from current file) which was read in |
385 |
C fPrec :: File precision (number of bits per word, = 32 or 64) |
386 |
C kSiz :: size of third dimension of array "field" to read-in |
387 |
C kLo :: 1rst vertical level (of array "field") to read-in |
388 |
C kHi :: last vertical level (of array "field") to read-in |
389 |
C myIter :: Iteration number |
390 |
C myThid :: My Thread Id number |
391 |
CHARACTER*(8) fldName |
392 |
_RL field(*) |
393 |
INTEGER nj |
394 |
INTEGER fPrec |
395 |
INTEGER kSiz, kLo, kHi |
396 |
INTEGER myIter |
397 |
INTEGER myThid |
398 |
CEOP |
399 |
|
400 |
C !FUNCTIONS |
401 |
INTEGER ILNBLNK |
402 |
EXTERNAL ILNBLNK |
403 |
|
404 |
C !LOCAL VARIABLES: |
405 |
INTEGER j, iL, ioUnit |
406 |
LOGICAL useCurrentDir |
407 |
CHARACTER*(2) fType |
408 |
CHARACTER*(MAX_LEN_FNAM) fName |
409 |
CHARACTER*(MAX_LEN_MBUF) msgBuf |
410 |
|
411 |
C----- |
412 |
|
413 |
iL = ILNBLNK(mFldsFile) |
414 |
#ifdef RW_SAFE_MFLDS |
415 |
IF ( iL.EQ.0 ) THEN |
416 |
WRITE(msgBuf,'(2A,I4)') 'READ_MFLDS_LEV_RL: ', |
417 |
& 'empty MFLDS file-name' |
418 |
CALL PRINT_ERROR( msgBuf, myThid ) |
419 |
STOP 'ABNORMAL END: S/R READ_MFLDS_LEV_RL (fileName)' |
420 |
ENDIF |
421 |
#endif /* RW_SAFE_MFLDS */ |
422 |
|
423 |
ioUnit = standardMessageUnit |
424 |
IF ( nFlds.GE.1 ) THEN |
425 |
C-- Search for "fldName" in list of field-names: |
426 |
nj = 0 |
427 |
DO j=1,nFlds |
428 |
IF ( fldName.EQ.fldList(j) .AND. nj.EQ.0 ) nj = j |
429 |
ENDDO |
430 |
IF ( nj.EQ.0 ) THEN |
431 |
C- record unsuccessful search: |
432 |
_BEGIN_MASTER( myThid ) |
433 |
nMissFld = nMissFld + 1 |
434 |
j = MIN(nMissFld,sizFldList) |
435 |
fldMiss(j) = fldName |
436 |
_END_MASTER( myThid ) |
437 |
IF ( debugLevel.GE.debLevA ) THEN |
438 |
iL = ILNBLNK(mFldsFile) |
439 |
iL = MIN(iL,MAX_LEN_MBUF-54-20) |
440 |
WRITE(msgBuf,'(5A)') 'READ_MFLDS_LEV_RL: ', |
441 |
& 'field: "',fldName,'" missing in file: ',mFldsFile(1:iL) |
442 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
443 |
ENDIF |
444 |
ELSE |
445 |
C- convert from field Number to record number (if mix of 3D & 2D flds) |
446 |
j = nj |
447 |
IF ( nj.GT.nFl3D ) nj = nj + nFl3D*(thirdDim-1) |
448 |
IF ( debugLevel.GE.debLevA ) THEN |
449 |
WRITE(msgBuf,'(3A,2(A,I4))') 'READ_MFLDS_LEV_RL: ', |
450 |
& 'read field: "',fldName,'", #',j,' in fldList, rec=',nj |
451 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
452 |
ENDIF |
453 |
ENDIF |
454 |
ELSEIF ( nj.GE.0 ) THEN |
455 |
C- increment record number |
456 |
nj = nj + 1 |
457 |
IF ( debugLevel.GE.debLevA ) THEN |
458 |
WRITE(msgBuf,'(3A,2(A,I4))') 'READ_MFLDS_LEV_RL: ', |
459 |
& 'no fldList, try to read field "',fldName, '", rec=',nj |
460 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
461 |
ENDIF |
462 |
ENDIF |
463 |
|
464 |
IF ( nj.GE.1 ) THEN |
465 |
C-- read in array "field" |
466 |
fName = mFldsFile |
467 |
useCurrentDir = .FALSE. |
468 |
fType = 'RL' |
469 |
#ifdef ALLOW_MDSIO |
470 |
CALL MDS_READ_FIELD( |
471 |
I fName, fPrec, useCurrentDir, |
472 |
I fType, kSiz, kLo, kHi, |
473 |
O field, |
474 |
I nj, myThid ) |
475 |
|
476 |
#endif |
477 |
ENDIF |
478 |
|
479 |
RETURN |
480 |
END |
481 |
|
482 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
483 |
CBOP |
484 |
C !ROUTINE: READ_MFLDS_CHECK |
485 |
C !INTERFACE: |
486 |
SUBROUTINE READ_MFLDS_CHECK( |
487 |
O errList, |
488 |
U nbErr, |
489 |
I myIter, myThid ) |
490 |
|
491 |
C !DESCRIPTION: |
492 |
C After reading a Multi-Fields binary file, check (and report) |
493 |
C for missing fields (attempted to read but not found). |
494 |
C |
495 |
C Note: If missing fields, print error msg but take no action (no stop) |
496 |
C but return number of missing fields (+ list, if nbErr_inputArg > 0) |
497 |
C Depending on the calling context, may choose to stop or to continue |
498 |
|
499 |
C !USES: |
500 |
IMPLICIT NONE |
501 |
#include "SIZE.h" |
502 |
#include "EEPARAMS.h" |
503 |
#include "PARAMS.h" |
504 |
#include "RW_MFLDS.h" |
505 |
|
506 |
C !INPUT PARAMETERS: |
507 |
C nbErr :: max size of array errList |
508 |
C myIter :: Iteration number |
509 |
C myThid :: My Thread Id number |
510 |
C !OUTPUT PARAMETERS: |
511 |
C errList :: List of missing fields (attempted to read but not found) |
512 |
C nbErr :: Number of missing fields (attempted to read but not found) |
513 |
CHARACTER*(8) errList(*) |
514 |
INTEGER nbErr |
515 |
INTEGER myIter |
516 |
INTEGER myThid |
517 |
CEOP |
518 |
|
519 |
C !FUNCTIONS |
520 |
INTEGER ILNBLNK |
521 |
EXTERNAL ILNBLNK |
522 |
|
523 |
C !LOCAL VARIABLES: |
524 |
INTEGER i, j, nj, iL, ioUnit |
525 |
CHARACTER*(MAX_LEN_MBUF) msgBuf |
526 |
|
527 |
C----- |
528 |
|
529 |
iL = ILNBLNK(mFldsFile) |
530 |
#ifdef RW_SAFE_MFLDS |
531 |
IF ( iL.EQ.0 ) THEN |
532 |
WRITE(msgBuf,'(2A,I4)') 'READ_MFLDS_CHECK: ', |
533 |
& 'empty MFLDS file-name' |
534 |
CALL PRINT_ERROR( msgBuf, myThid ) |
535 |
STOP 'ABNORMAL END: S/R READ_MFLDS_CHECK (fileName)' |
536 |
ENDIF |
537 |
#endif /* RW_SAFE_MFLDS */ |
538 |
|
539 |
|
540 |
C-- Initialise output arguments |
541 |
DO j=1,nbErr |
542 |
errList(j) = ' ' |
543 |
ENDDO |
544 |
|
545 |
C-- every one waits for master thread to finish the update of |
546 |
C missing fields number & list. |
547 |
_BARRIER |
548 |
|
549 |
IF ( nMissFld.GE.1 ) THEN |
550 |
C-- Attempted to read some fields that were not in the current MFLDS file |
551 |
C => report by printing Error Msg: |
552 |
ioUnit = errorMessageUnit |
553 |
WRITE(msgBuf,'(3A)') 'READ_MFLDS_CHECK: ', |
554 |
& 'reading from file: ', mFldsFile(1:iL) |
555 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
556 |
WRITE(msgBuf,'(2A,I4,A)') 'READ_MFLDS_CHECK: ', |
557 |
& 'which contains ', nFlds, ' fields :' |
558 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
559 |
DO j=1,nFlds,20 |
560 |
WRITE(msgBuf,'(20(A2,A8,A))') |
561 |
& (' >', fldList(i), '<', i=j,MIN(j+19,nFlds) ) |
562 |
CALL PRINT_MESSAGE(msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
563 |
ENDDO |
564 |
WRITE(msgBuf,'(A,I4,A)') 'READ_MFLDS_CHECK: ', |
565 |
& nMissFld, ' field(s) is/are missing :' |
566 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
567 |
nj = MIN( nMissFld, sizFldList ) |
568 |
DO j=1,nj,20 |
569 |
WRITE(msgBuf,'(20(A2,A8,A))') |
570 |
& (' >', fldMiss(i), '<', i=j,MIN(j+19,nj) ) |
571 |
CALL PRINT_MESSAGE(msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
572 |
ENDDO |
573 |
|
574 |
C- Size problem: |
575 |
IF ( nMissFld.GT.sizFldList ) THEN |
576 |
WRITE(msgBuf,'(2A,I4)') 'READ_MFLDS_CHECK: ', |
577 |
& 'missing fields list has been truncated to', sizFldList |
578 |
CALL PRINT_ERROR( msgBuf, myThid ) |
579 |
STOP 'ABNORMAL END: S/R READ_MFLDS_CHECK (list-size Pb)' |
580 |
ENDIF |
581 |
|
582 |
C- Fill the error output list (up to the Max size: nbErr) |
583 |
nj = MIN( nMissFld, nbErr ) |
584 |
DO j=1,nj |
585 |
errList(j) = fldMiss(j) |
586 |
ENDDO |
587 |
ELSE |
588 |
C-- Normal end : print msg before resetting "mFldsFile" |
589 |
ioUnit = standardMessageUnit |
590 |
IF ( debugLevel .GE. debLevA ) THEN |
591 |
WRITE(msgBuf,'(3A)') 'READ_MFLDS_CHECK: ', |
592 |
c & '- end reading file: ', mFldsFile(1:iL) |
593 |
c & '- normal end ; reset mFldsFile: ', mFldsFile(1:iL) |
594 |
& '- normal end ; reset MFLDS file-name: ', mFldsFile(1:iL) |
595 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
596 |
ENDIF |
597 |
|
598 |
ENDIF |
599 |
|
600 |
C- Return the number of missing fields |
601 |
nbErr = nMissFld |
602 |
|
603 |
#ifdef RW_SAFE_MFLDS |
604 |
_BARRIER |
605 |
_BEGIN_MASTER( myThid ) |
606 |
C-- Reset MFLDS file name: |
607 |
mFldsFile = ' ' |
608 |
_END_MASTER( myThid ) |
609 |
_BARRIER |
610 |
#endif /* RW_SAFE_MFLDS */ |
611 |
|
612 |
RETURN |
613 |
END |