1 |
C $Header: /u/gcmpack/MITgcm/pkg/rw/read_mflds.F,v 1.9 2013/01/13 22:49:48 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_LEV_RS |
13 |
C-- o READ_MFLDS_CHECK |
14 |
C-- o READ_MFLDS_RENAME |
15 |
|
16 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
17 |
CBOP |
18 |
C !ROUTINE: READ_MFLDS_INIT |
19 |
C !INTERFACE: |
20 |
SUBROUTINE READ_MFLDS_INIT( |
21 |
I myThid ) |
22 |
|
23 |
C !DESCRIPTION: |
24 |
C Initialise Multi-Fields read variables in common block |
25 |
|
26 |
C !USES: |
27 |
IMPLICIT NONE |
28 |
c#include "SIZE.h" |
29 |
#include "EEPARAMS.h" |
30 |
#include "RW_MFLDS.h" |
31 |
|
32 |
C !INPUT/OUTPUT PARAMETERS: |
33 |
C myThid :: my Thread Id. number |
34 |
INTEGER myThid |
35 |
CEOP |
36 |
|
37 |
C !LOCAL VARIABLES: |
38 |
C i :: loop counter |
39 |
INTEGER i |
40 |
C- for debug print: |
41 |
c CHARACTER*(MAX_LEN_MBUF) msgBuf |
42 |
C----- |
43 |
|
44 |
C- Initialise variables in common block: |
45 |
thirdDim = 0 |
46 |
nFl3D = 0 |
47 |
nFlds = 0 |
48 |
nMissFld = 0 |
49 |
mFldsFile = ' ' |
50 |
DO i=1,sizFldList |
51 |
fldList(i) = ' ' |
52 |
fldMiss(i) = ' ' |
53 |
ENDDO |
54 |
|
55 |
RETURN |
56 |
END |
57 |
|
58 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
59 |
CBOP |
60 |
C !ROUTINE: READ_MFLDS_SET |
61 |
C !INTERFACE: |
62 |
SUBROUTINE READ_MFLDS_SET( |
63 |
I fName, |
64 |
O nbFields, filePrec, |
65 |
I fileDim3, myIter, myThid ) |
66 |
|
67 |
C !DESCRIPTION: |
68 |
C This is the controlling routine for preparing Multi-Fields read |
69 |
C by reading the corresponding meta file. |
70 |
C the meta-file content is stored in common block (header: RW_MFLDS.h) |
71 |
C to be reachable by all threads |
72 |
|
73 |
C Note: 1) Output arguments should not be shared variables (= not in common block) |
74 |
C 2) Only master-thread returns a valid filePrec (others just return 0) |
75 |
|
76 |
C !USES: |
77 |
IMPLICIT NONE |
78 |
#include "SIZE.h" |
79 |
#include "EEPARAMS.h" |
80 |
#include "PARAMS.h" |
81 |
#include "RW_MFLDS.h" |
82 |
|
83 |
C !INPUT/OUTPUT PARAMETERS: |
84 |
C fName :: current MFLDS file name (prefix) to read |
85 |
C nbFields :: Number of fields in current MFLDS file |
86 |
C filePrec :: data-precision in current MFLDS file |
87 |
C fileDim3 :: 3rd dimension of fields in current MFLDS file |
88 |
C myIter :: Iteration number |
89 |
C myThid :: my Thread Id. number |
90 |
CHARACTER*(MAX_LEN_FNAM) fName |
91 |
INTEGER nbFields |
92 |
INTEGER filePrec |
93 |
INTEGER fileDim3 |
94 |
INTEGER myIter |
95 |
INTEGER myThid |
96 |
CEOP |
97 |
|
98 |
C !FUNCTIONS |
99 |
INTEGER ILNBLNK |
100 |
EXTERNAL ILNBLNK |
101 |
|
102 |
C !LOCAL VARIABLES: |
103 |
C- do change dir. (using mdsioLocalDir): |
104 |
LOGICAL useCurrentDir |
105 |
C- output of MDS_READ_META : |
106 |
INTEGER nSizD, nSizT |
107 |
PARAMETER( nSizD = 5 , nSizT = 20 ) |
108 |
CHARACTER*(MAX_LEN_PREC/2) simulName |
109 |
CHARACTER*(MAX_LEN_MBUF/2) titleLine |
110 |
INTEGER nDims, nTimRec |
111 |
INTEGER dimList(3,nSizD) |
112 |
_RL timList(nSizT) |
113 |
_RL misVal |
114 |
INTEGER nRecords, fileIter |
115 |
C- for debug print: |
116 |
INTEGER i, j, ioUnit |
117 |
CHARACTER*(MAX_LEN_MBUF) msgBuf |
118 |
C----- |
119 |
|
120 |
C- Initialise output arguments: |
121 |
nbFields = 0 |
122 |
filePrec = 0 |
123 |
|
124 |
#ifdef RW_SAFE_MFLDS |
125 |
i = ILNBLNK(mFldsFile) |
126 |
IF ( i.NE.0 ) THEN |
127 |
i = MIN(i, MAX_LEN_MBUF-48-34 ) |
128 |
WRITE(msgBuf,'(4A)') 'READ_MFLDS_SET: ', |
129 |
& 'MFLDS file-name already set to: ',mFldsFile(1:i) |
130 |
CALL PRINT_ERROR( msgBuf, myThid ) |
131 |
CALL ALL_PROC_DIE( myThid ) |
132 |
STOP 'ABNORMAL END: S/R READ_MFLDS_SET (fileName)' |
133 |
ENDIF |
134 |
_BARRIER |
135 |
#endif /* RW_SAFE_MFLDS */ |
136 |
_BEGIN_MASTER( myThid ) |
137 |
|
138 |
C- Initialise variables in common block: |
139 |
thirdDim = fileDim3 |
140 |
nFl3D = 0 |
141 |
nFlds = 0 |
142 |
nMissFld = 0 |
143 |
mFldsFile = fName |
144 |
DO i=1,sizFldList |
145 |
fldList(i) = ' ' |
146 |
fldMiss(i) = ' ' |
147 |
ENDDO |
148 |
|
149 |
#ifdef ALLOW_MDSIO |
150 |
useCurrentDir = .FALSE. |
151 |
nDims = nSizD |
152 |
nFlds = sizFldList |
153 |
nTimRec = nSizT |
154 |
CALL MDS_READ_META( |
155 |
I fName, |
156 |
O simulName, |
157 |
O titleLine, |
158 |
O filePrec, |
159 |
U nDims, nFlds, nTimRec, |
160 |
O dimList, fldList, timList, |
161 |
O misVal, nRecords, fileIter, |
162 |
I useCurrentDir, myThid ) |
163 |
#endif /* ALLOW_MDSIO */ |
164 |
|
165 |
C- evaluate Nb of 3.D fields (used if mix 3-D & 2-D fields in file): |
166 |
nFl3D = 0 |
167 |
IF ( nFlds.GE.1 ) THEN |
168 |
IF ( nDims.EQ.2 .AND. thirdDim.GT.1 |
169 |
& .AND. nFlds.LT.nRecords ) THEN |
170 |
IF ( MOD( nRecords-nFlds , thirdDim-1 ) .EQ. 0 ) |
171 |
& nFl3D = (nRecords-nFlds)/(thirdDim-1) |
172 |
ENDIF |
173 |
IF ( nFlds.NE.nRecords .AND. nFl3D.EQ.0 ) THEN |
174 |
C- here we have a problem |
175 |
WRITE(msgBuf,'(A,I5,A,I4,A)') |
176 |
& 'READ_MFLDS_SET: Pb with Nb of records=', nRecords, |
177 |
& ' (3rd-Dim=', thirdDim,')' |
178 |
CALL PRINT_ERROR( msgBuf, myThid ) |
179 |
WRITE(msgBuf,'(A,I5,A,I4,A)') |
180 |
& ' does not match Nb of flds=', nFlds |
181 |
CALL PRINT_ERROR( msgBuf, myThid ) |
182 |
CALL ALL_PROC_DIE( 0 ) |
183 |
STOP 'ABNORMAL END: S/R READ_MFLDS_SET (Nb-records Pb)' |
184 |
ENDIF |
185 |
c IF ( nFl3D.EQ.0 ) nFl3D = nFlds |
186 |
ENDIF |
187 |
|
188 |
C- write to Standard Output |
189 |
IF ( debugLevel.GE.debLevA ) THEN |
190 |
ioUnit = standardMessageUnit |
191 |
i = ILNBLNK(simulName) |
192 |
IF ( i.GE.1 ) THEN |
193 |
WRITE(msgBuf,'(3A)') ' simulName=>', simulName(1:i), '<' |
194 |
CALL PRINT_MESSAGE(msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
195 |
ENDIF |
196 |
i = ILNBLNK(titleLine) |
197 |
IF ( i.GE.1 ) THEN |
198 |
WRITE(msgBuf,'(3A)') ' titleLine=>', titleLine(1:i), '<' |
199 |
CALL PRINT_MESSAGE(msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
200 |
ENDIF |
201 |
WRITE(msgBuf,'(2(A,I4),A,I10)') |
202 |
& ' nRecords =', nRecords, ' ; filePrec =', filePrec, |
203 |
& ' ; fileIter =', fileIter |
204 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
205 |
WRITE(msgBuf,'(A,I4,A)') ' nDims =', nDims, ' , dims:' |
206 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
207 |
DO j=1,nDims |
208 |
WRITE(msgBuf,'(I4,A,3I4)') j,':',(dimList(i,j),i=1,3) |
209 |
CALL PRINT_MESSAGE(msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
210 |
ENDDO |
211 |
WRITE(msgBuf,'(3(A,I4))') |
212 |
& ' nFlds =', nFlds, ' , nFl3D =', nFl3D, ' , fields:' |
213 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
214 |
DO j=1,nFlds,20 |
215 |
WRITE(msgBuf,'(20(A2,A8,A))') |
216 |
& (' >', fldList(i), '<', i=j,MIN(j+19,nFlds) ) |
217 |
CALL PRINT_MESSAGE(msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
218 |
ENDDO |
219 |
WRITE(msgBuf,'(A,1PE22.14,A,I4,A)') 'missingVal=', misVal, |
220 |
& ' ; nTimRec =',nTimRec,' , timeList:' |
221 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
222 |
IF ( nTimRec.GE.1 ) THEN |
223 |
WRITE(msgBuf,'(1P20E20.12)') (timList(i),i=1,nTimRec) |
224 |
CALL PRINT_MESSAGE(msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
225 |
ENDIF |
226 |
ENDIF |
227 |
|
228 |
_END_MASTER( myThid ) |
229 |
_BARRIER |
230 |
|
231 |
C- set output arguments: |
232 |
nbFields = nFlds |
233 |
|
234 |
RETURN |
235 |
END |
236 |
|
237 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
238 |
CBOP |
239 |
C !ROUTINE: READ_MFLDS_3D_RL |
240 |
C !INTERFACE: |
241 |
SUBROUTINE READ_MFLDS_3D_RL( |
242 |
I fldName, |
243 |
O field, |
244 |
U nj, |
245 |
I fPrec, nNz, myIter, myThid ) |
246 |
|
247 |
C !DESCRIPTION: |
248 |
C Read, from a Multi-Fields binary file, field "fldName" into array "field" |
249 |
C record Nb "nj" is search through the field-list (from meta-file) which |
250 |
C has been set before (calling READ_MFLDS_SET). |
251 |
C In case nFlds is <=0 , by-pass the search and directly read record number "nj" |
252 |
|
253 |
C !USES: |
254 |
IMPLICIT NONE |
255 |
#include "SIZE.h" |
256 |
#include "EEPARAMS.h" |
257 |
#include "PARAMS.h" |
258 |
#include "RW_MFLDS.h" |
259 |
|
260 |
C !INPUT/OUTPUT PARAMETERS: |
261 |
C fldName :: Name of the field to read |
262 |
C field :: Output array to read in |
263 |
C nj (in) :: number of the record (in file) just before the one to read |
264 |
C nj (out):: number of the record (from current file) which was read in |
265 |
C fPrec :: File precision (number of bits per word, = 32 or 64) |
266 |
C nNz :: Number of levels to read in |
267 |
C myIter :: Iteration number |
268 |
C myThid :: My Thread Id number |
269 |
CHARACTER*(8) fldName |
270 |
_RL field(*) |
271 |
INTEGER nj |
272 |
INTEGER fPrec |
273 |
INTEGER nNz |
274 |
INTEGER myIter |
275 |
INTEGER myThid |
276 |
CEOP |
277 |
|
278 |
C !FUNCTIONS |
279 |
INTEGER ILNBLNK |
280 |
EXTERNAL ILNBLNK |
281 |
|
282 |
C !LOCAL VARIABLES: |
283 |
INTEGER j, iL, ioUnit |
284 |
LOGICAL prtMsg |
285 |
LOGICAL useCurrentDir |
286 |
_RS dummyRS(1) |
287 |
CHARACTER*(2) fType |
288 |
CHARACTER*(MAX_LEN_FNAM) fName |
289 |
CHARACTER*(MAX_LEN_MBUF) msgBuf |
290 |
C----- |
291 |
|
292 |
iL = ILNBLNK(mFldsFile) |
293 |
#ifdef RW_SAFE_MFLDS |
294 |
IF ( iL.EQ.0 ) THEN |
295 |
WRITE(msgBuf,'(2A,I4)') 'READ_MFLDS_3D_RL: ', |
296 |
& 'empty MFLDS file-name' |
297 |
CALL PRINT_ERROR( msgBuf, myThid ) |
298 |
CALL ALL_PROC_DIE( myThid ) |
299 |
STOP 'ABNORMAL END: S/R READ_MFLDS_3D_RL (fileName)' |
300 |
ENDIF |
301 |
#endif /* RW_SAFE_MFLDS */ |
302 |
|
303 |
ioUnit = standardMessageUnit |
304 |
prtMsg = debugLevel.GE.debLevA .AND. myThid.EQ.1 |
305 |
IF ( nFlds.GE.1 ) THEN |
306 |
C-- Search for "fldName" in list of field-names: |
307 |
nj = 0 |
308 |
DO j=1,nFlds |
309 |
IF ( fldName.EQ.fldList(j) .AND. nj.EQ.0 ) nj = j |
310 |
ENDDO |
311 |
IF ( nj.EQ.0 ) THEN |
312 |
C- record unsuccessful search: |
313 |
_BEGIN_MASTER( myThid ) |
314 |
nMissFld = nMissFld + 1 |
315 |
j = MIN(nMissFld,sizFldList) |
316 |
fldMiss(j) = fldName |
317 |
_END_MASTER( myThid ) |
318 |
IF ( prtMsg ) THEN |
319 |
iL = ILNBLNK(mFldsFile) |
320 |
iL = MIN(iL,MAX_LEN_MBUF-54-20) |
321 |
WRITE(msgBuf,'(5A)') 'READ_MFLDS_3D_RL: ', |
322 |
& 'field: "',fldName,'" missing in file: ',mFldsFile(1:iL) |
323 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
324 |
ENDIF |
325 |
ELSE |
326 |
C- convert from field Number to record number (if mix of 3D & 2D flds) |
327 |
j = nj |
328 |
IF ( nj.GT.nFl3D ) nj = nj + nFl3D*(thirdDim-1) |
329 |
IF ( prtMsg ) THEN |
330 |
WRITE(msgBuf,'(3A,2(A,I4))') 'READ_MFLDS_3D_RL: ', |
331 |
& 'read field: "',fldName,'", #',j,' in fldList, rec=',nj |
332 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
333 |
ENDIF |
334 |
ENDIF |
335 |
ELSEIF ( nj.GE.0 ) THEN |
336 |
C- increment record number |
337 |
nj = nj + 1 |
338 |
IF ( prtMsg ) THEN |
339 |
WRITE(msgBuf,'(3A,2(A,I4))') 'READ_MFLDS_3D_RL: ', |
340 |
& 'no fldList, try to read field "',fldName, '", rec=',nj |
341 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
342 |
ENDIF |
343 |
ENDIF |
344 |
|
345 |
IF ( nj.GE.1 ) THEN |
346 |
C-- read in array "field" |
347 |
fName = mFldsFile |
348 |
useCurrentDir = .FALSE. |
349 |
fType = 'RL' |
350 |
#ifdef ALLOW_MDSIO |
351 |
CALL MDS_READ_FIELD( |
352 |
I fName, fPrec, useCurrentDir, |
353 |
I fType, nNz, 1, nNz, |
354 |
O field, dummyRS, |
355 |
I nj, myThid ) |
356 |
|
357 |
#endif |
358 |
ENDIF |
359 |
|
360 |
RETURN |
361 |
END |
362 |
|
363 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
364 |
CBOP |
365 |
C !ROUTINE: READ_MFLDS_LEV_RL |
366 |
C !INTERFACE: |
367 |
SUBROUTINE READ_MFLDS_LEV_RL( |
368 |
I fldName, |
369 |
O field, |
370 |
U nj, |
371 |
I fPrec, kSiz, kLo, kHi, myIter, myThid ) |
372 |
|
373 |
C !DESCRIPTION: |
374 |
C Read, from a Multi-Fields binary file, field "fldName", a set of |
375 |
C consecutive levels (from kLo to kHi) into 3D RL array "field" (size: kSiz) |
376 |
C record Nb "nj" is search through the field-list (from meta-file) which |
377 |
C has been set before (calling READ_MFLDS_SET). |
378 |
C In case nFlds is <=0, by-pass the search and directly read record number "nj" |
379 |
|
380 |
C !USES: |
381 |
IMPLICIT NONE |
382 |
#include "SIZE.h" |
383 |
#include "EEPARAMS.h" |
384 |
#include "PARAMS.h" |
385 |
#include "RW_MFLDS.h" |
386 |
|
387 |
C !INPUT/OUTPUT PARAMETERS: |
388 |
C fldName :: Name of the field to read |
389 |
C field :: Output array (RL type) to read in |
390 |
C nj (in) :: number of the record (in file) just before the one to read |
391 |
C nj (out):: number of the record (from current file) which was read in |
392 |
C fPrec :: File precision (number of bits per word, = 32 or 64) |
393 |
C kSiz :: size of third dimension of array "field" to read-in |
394 |
C kLo :: 1rst vertical level (of array "field") to read-in |
395 |
C kHi :: last vertical level (of array "field") to read-in |
396 |
C myIter :: Iteration number |
397 |
C myThid :: My Thread Id number |
398 |
CHARACTER*(8) fldName |
399 |
_RL field(*) |
400 |
INTEGER nj |
401 |
INTEGER fPrec |
402 |
INTEGER kSiz, kLo, kHi |
403 |
INTEGER myIter |
404 |
INTEGER myThid |
405 |
CEOP |
406 |
|
407 |
C !FUNCTIONS |
408 |
INTEGER ILNBLNK |
409 |
EXTERNAL ILNBLNK |
410 |
|
411 |
C !LOCAL VARIABLES: |
412 |
INTEGER j, iL, ioUnit |
413 |
LOGICAL prtMsg |
414 |
LOGICAL useCurrentDir |
415 |
_RS dummyRS(1) |
416 |
CHARACTER*(2) fType |
417 |
CHARACTER*(MAX_LEN_FNAM) fName |
418 |
CHARACTER*(MAX_LEN_MBUF) msgBuf |
419 |
C----- |
420 |
|
421 |
iL = ILNBLNK(mFldsFile) |
422 |
#ifdef RW_SAFE_MFLDS |
423 |
IF ( iL.EQ.0 ) THEN |
424 |
WRITE(msgBuf,'(2A,I4)') 'READ_MFLDS_LEV_RL: ', |
425 |
& 'empty MFLDS file-name' |
426 |
CALL PRINT_ERROR( msgBuf, myThid ) |
427 |
CALL ALL_PROC_DIE( myThid ) |
428 |
STOP 'ABNORMAL END: S/R READ_MFLDS_LEV_RL (fileName)' |
429 |
ENDIF |
430 |
#endif /* RW_SAFE_MFLDS */ |
431 |
|
432 |
ioUnit = standardMessageUnit |
433 |
prtMsg = debugLevel.GE.debLevA .AND. myThid.EQ.1 |
434 |
IF ( nFlds.GE.1 ) THEN |
435 |
C-- Search for "fldName" in list of field-names: |
436 |
nj = 0 |
437 |
DO j=1,nFlds |
438 |
IF ( fldName.EQ.fldList(j) .AND. nj.EQ.0 ) nj = j |
439 |
ENDDO |
440 |
IF ( nj.EQ.0 ) THEN |
441 |
C- record unsuccessful search: |
442 |
_BEGIN_MASTER( myThid ) |
443 |
nMissFld = nMissFld + 1 |
444 |
j = MIN(nMissFld,sizFldList) |
445 |
fldMiss(j) = fldName |
446 |
_END_MASTER( myThid ) |
447 |
IF ( prtMsg ) THEN |
448 |
iL = ILNBLNK(mFldsFile) |
449 |
iL = MIN(iL,MAX_LEN_MBUF-54-20) |
450 |
WRITE(msgBuf,'(5A)') 'READ_MFLDS_LEV_RL: ', |
451 |
& 'field: "',fldName,'" missing in file: ',mFldsFile(1:iL) |
452 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
453 |
ENDIF |
454 |
ELSE |
455 |
C- convert from field Number to record number (if mix of 3D & 2D flds) |
456 |
j = nj |
457 |
IF ( nj.GT.nFl3D ) nj = nj + nFl3D*(thirdDim-1) |
458 |
IF ( prtMsg ) THEN |
459 |
WRITE(msgBuf,'(3A,2(A,I4))') 'READ_MFLDS_LEV_RL: ', |
460 |
& 'read field: "',fldName,'", #',j,' in fldList, rec=',nj |
461 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
462 |
ENDIF |
463 |
ENDIF |
464 |
ELSEIF ( nj.GE.0 ) THEN |
465 |
C- increment record number |
466 |
nj = nj + 1 |
467 |
IF ( prtMsg ) THEN |
468 |
WRITE(msgBuf,'(3A,2(A,I4))') 'READ_MFLDS_LEV_RL: ', |
469 |
& 'no fldList, try to read field "',fldName, '", rec=',nj |
470 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
471 |
ENDIF |
472 |
ENDIF |
473 |
|
474 |
IF ( nj.GE.1 ) THEN |
475 |
C-- read in array "field" |
476 |
fName = mFldsFile |
477 |
useCurrentDir = .FALSE. |
478 |
fType = 'RL' |
479 |
#ifdef ALLOW_MDSIO |
480 |
CALL MDS_READ_FIELD( |
481 |
I fName, fPrec, useCurrentDir, |
482 |
I fType, kSiz, kLo, kHi, |
483 |
O field, dummyRS, |
484 |
I nj, myThid ) |
485 |
|
486 |
#endif |
487 |
ENDIF |
488 |
|
489 |
RETURN |
490 |
END |
491 |
|
492 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
493 |
CBOP |
494 |
C !ROUTINE: READ_MFLDS_LEV_RS |
495 |
C !INTERFACE: |
496 |
SUBROUTINE READ_MFLDS_LEV_RS( |
497 |
I fldName, |
498 |
O field, |
499 |
U nj, |
500 |
I fPrec, kSiz, kLo, kHi, myIter, myThid ) |
501 |
|
502 |
C !DESCRIPTION: |
503 |
C Read, from a Multi-Fields binary file, field "fldName", a set of |
504 |
C consecutive levels (from kLo to kHi) into 3D RS array "field" (size: kSiz) |
505 |
C record Nb "nj" is search through the field-list (from meta-file) which |
506 |
C has been set before (calling READ_MFLDS_SET). |
507 |
C In case nFlds is <=0, by-pass the search and directly read record number "nj" |
508 |
|
509 |
C !USES: |
510 |
IMPLICIT NONE |
511 |
#include "SIZE.h" |
512 |
#include "EEPARAMS.h" |
513 |
#include "PARAMS.h" |
514 |
#include "RW_MFLDS.h" |
515 |
|
516 |
C !INPUT/OUTPUT PARAMETERS: |
517 |
C fldName :: Name of the field to read |
518 |
C field :: Output array (RS type) to read in |
519 |
C nj (in) :: number of the record (in file) just before the one to read |
520 |
C nj (out):: number of the record (from current file) which was read in |
521 |
C fPrec :: File precision (number of bits per word, = 32 or 64) |
522 |
C kSiz :: size of third dimension of array "field" to read-in |
523 |
C kLo :: 1rst vertical level (of array "field") to read-in |
524 |
C kHi :: last vertical level (of array "field") to read-in |
525 |
C myIter :: Iteration number |
526 |
C myThid :: My Thread Id number |
527 |
CHARACTER*(8) fldName |
528 |
_RS field(*) |
529 |
INTEGER nj |
530 |
INTEGER fPrec |
531 |
INTEGER kSiz, kLo, kHi |
532 |
INTEGER myIter |
533 |
INTEGER myThid |
534 |
CEOP |
535 |
|
536 |
C !FUNCTIONS |
537 |
INTEGER ILNBLNK |
538 |
EXTERNAL ILNBLNK |
539 |
|
540 |
C !LOCAL VARIABLES: |
541 |
INTEGER j, iL, ioUnit |
542 |
LOGICAL prtMsg |
543 |
LOGICAL useCurrentDir |
544 |
_RL dummyRL(1) |
545 |
CHARACTER*(2) fType |
546 |
CHARACTER*(MAX_LEN_FNAM) fName |
547 |
CHARACTER*(MAX_LEN_MBUF) msgBuf |
548 |
C----- |
549 |
|
550 |
iL = ILNBLNK(mFldsFile) |
551 |
#ifdef RW_SAFE_MFLDS |
552 |
IF ( iL.EQ.0 ) THEN |
553 |
WRITE(msgBuf,'(2A,I4)') 'READ_MFLDS_LEV_RS: ', |
554 |
& 'empty MFLDS file-name' |
555 |
CALL PRINT_ERROR( msgBuf, myThid ) |
556 |
CALL ALL_PROC_DIE( myThid ) |
557 |
STOP 'ABNORMAL END: S/R READ_MFLDS_LEV_RS (fileName)' |
558 |
ENDIF |
559 |
#endif /* RW_SAFE_MFLDS */ |
560 |
|
561 |
ioUnit = standardMessageUnit |
562 |
prtMsg = debugLevel.GE.debLevA .AND. myThid.EQ.1 |
563 |
IF ( nFlds.GE.1 ) THEN |
564 |
C-- Search for "fldName" in list of field-names: |
565 |
nj = 0 |
566 |
DO j=1,nFlds |
567 |
IF ( fldName.EQ.fldList(j) .AND. nj.EQ.0 ) nj = j |
568 |
ENDDO |
569 |
IF ( nj.EQ.0 ) THEN |
570 |
C- record unsuccessful search: |
571 |
_BEGIN_MASTER( myThid ) |
572 |
nMissFld = nMissFld + 1 |
573 |
j = MIN(nMissFld,sizFldList) |
574 |
fldMiss(j) = fldName |
575 |
_END_MASTER( myThid ) |
576 |
IF ( prtMsg ) THEN |
577 |
iL = ILNBLNK(mFldsFile) |
578 |
iL = MIN(iL,MAX_LEN_MBUF-54-20) |
579 |
WRITE(msgBuf,'(5A)') 'READ_MFLDS_LEV_RS: ', |
580 |
& 'field: "',fldName,'" missing in file: ',mFldsFile(1:iL) |
581 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
582 |
ENDIF |
583 |
ELSE |
584 |
C- convert from field Number to record number (if mix of 3D & 2D flds) |
585 |
j = nj |
586 |
IF ( nj.GT.nFl3D ) nj = nj + nFl3D*(thirdDim-1) |
587 |
IF ( prtMsg ) THEN |
588 |
WRITE(msgBuf,'(3A,2(A,I4))') 'READ_MFLDS_LEV_RS: ', |
589 |
& 'read field: "',fldName,'", #',j,' in fldList, rec=',nj |
590 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
591 |
ENDIF |
592 |
ENDIF |
593 |
ELSEIF ( nj.GE.0 ) THEN |
594 |
C- increment record number |
595 |
nj = nj + 1 |
596 |
IF ( prtMsg ) THEN |
597 |
WRITE(msgBuf,'(3A,2(A,I4))') 'READ_MFLDS_LEV_RS: ', |
598 |
& 'no fldList, try to read field "',fldName, '", rec=',nj |
599 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
600 |
ENDIF |
601 |
ENDIF |
602 |
|
603 |
IF ( nj.GE.1 ) THEN |
604 |
C-- read in array "field" |
605 |
fName = mFldsFile |
606 |
useCurrentDir = .FALSE. |
607 |
fType = 'RS' |
608 |
#ifdef ALLOW_MDSIO |
609 |
CALL MDS_READ_FIELD( |
610 |
I fName, fPrec, useCurrentDir, |
611 |
I fType, kSiz, kLo, kHi, |
612 |
O dummyRL, field, |
613 |
I nj, myThid ) |
614 |
|
615 |
#endif |
616 |
ENDIF |
617 |
|
618 |
RETURN |
619 |
END |
620 |
|
621 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
622 |
CBOP |
623 |
C !ROUTINE: READ_MFLDS_CHECK |
624 |
C !INTERFACE: |
625 |
SUBROUTINE READ_MFLDS_CHECK( |
626 |
O errList, |
627 |
U nbErr, |
628 |
I myIter, myThid ) |
629 |
|
630 |
C !DESCRIPTION: |
631 |
C After reading a Multi-Fields binary file, check (and report) |
632 |
C for missing fields (attempted to read but not found). |
633 |
C |
634 |
C Note: If missing fields, print error msg but take no action (no stop) |
635 |
C but return number of missing fields (+ list, if nbErr_inputArg > 0) |
636 |
C Depending on the calling context, may choose to stop or to continue |
637 |
|
638 |
C !USES: |
639 |
IMPLICIT NONE |
640 |
#include "SIZE.h" |
641 |
#include "EEPARAMS.h" |
642 |
#include "PARAMS.h" |
643 |
#include "RW_MFLDS.h" |
644 |
|
645 |
C !INPUT PARAMETERS: |
646 |
C nbErr :: max size of array errList |
647 |
C myIter :: Iteration number |
648 |
C myThid :: My Thread Id number |
649 |
C !OUTPUT PARAMETERS: |
650 |
C errList :: List of missing fields (attempted to read but not found) |
651 |
C nbErr :: Number of missing fields (attempted to read but not found) |
652 |
CHARACTER*(8) errList(*) |
653 |
INTEGER nbErr |
654 |
INTEGER myIter |
655 |
INTEGER myThid |
656 |
CEOP |
657 |
|
658 |
C !FUNCTIONS |
659 |
INTEGER ILNBLNK |
660 |
EXTERNAL ILNBLNK |
661 |
|
662 |
C !LOCAL VARIABLES: |
663 |
INTEGER i, j, nj, iL, ioUnit |
664 |
LOGICAL prtMsg |
665 |
CHARACTER*(MAX_LEN_MBUF) msgBuf |
666 |
C----- |
667 |
|
668 |
iL = ILNBLNK(mFldsFile) |
669 |
#ifdef RW_SAFE_MFLDS |
670 |
IF ( iL.EQ.0 ) THEN |
671 |
WRITE(msgBuf,'(2A,I4)') 'READ_MFLDS_CHECK: ', |
672 |
& 'empty MFLDS file-name' |
673 |
CALL PRINT_ERROR( msgBuf, myThid ) |
674 |
CALL ALL_PROC_DIE( myThid ) |
675 |
STOP 'ABNORMAL END: S/R READ_MFLDS_CHECK (fileName)' |
676 |
ENDIF |
677 |
#endif /* RW_SAFE_MFLDS */ |
678 |
|
679 |
C-- Initialise output arguments |
680 |
DO j=1,nbErr |
681 |
errList(j) = ' ' |
682 |
ENDDO |
683 |
|
684 |
C-- every one waits for master thread to finish the update of |
685 |
C missing fields number & list. |
686 |
_BARRIER |
687 |
|
688 |
IF ( nMissFld.GE.1 ) THEN |
689 |
C-- Attempted to read some fields that were not in the current MFLDS file |
690 |
C => report by printing Error Msg: |
691 |
ioUnit = errorMessageUnit |
692 |
_BEGIN_MASTER( myThid ) |
693 |
WRITE(msgBuf,'(3A)') 'READ_MFLDS_CHECK: ', |
694 |
& 'reading from file: ', mFldsFile(1:iL) |
695 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
696 |
WRITE(msgBuf,'(2A,I4,A)') 'READ_MFLDS_CHECK: ', |
697 |
& 'which contains ', nFlds, ' fields :' |
698 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
699 |
DO j=1,nFlds,20 |
700 |
WRITE(msgBuf,'(20(A2,A8,A))') |
701 |
& (' >', fldList(i), '<', i=j,MIN(j+19,nFlds) ) |
702 |
CALL PRINT_MESSAGE(msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
703 |
ENDDO |
704 |
WRITE(msgBuf,'(A,I4,A)') 'READ_MFLDS_CHECK: ', |
705 |
& nMissFld, ' field(s) is/are missing :' |
706 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
707 |
nj = MIN( nMissFld, sizFldList ) |
708 |
DO j=1,nj,20 |
709 |
WRITE(msgBuf,'(20(A2,A8,A))') |
710 |
& (' >', fldMiss(i), '<', i=j,MIN(j+19,nj) ) |
711 |
CALL PRINT_MESSAGE(msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
712 |
ENDDO |
713 |
_END_MASTER( myThid ) |
714 |
|
715 |
C- Size problem: |
716 |
IF ( nMissFld.GT.sizFldList ) THEN |
717 |
WRITE(msgBuf,'(2A,I4)') 'READ_MFLDS_CHECK: ', |
718 |
& 'missing fields list has been truncated to', sizFldList |
719 |
CALL PRINT_ERROR( msgBuf, myThid ) |
720 |
CALL ALL_PROC_DIE( myThid ) |
721 |
STOP 'ABNORMAL END: S/R READ_MFLDS_CHECK (list-size Pb)' |
722 |
ENDIF |
723 |
|
724 |
C- Fill the error output list (up to the Max size: nbErr) |
725 |
nj = MIN( nMissFld, nbErr ) |
726 |
DO j=1,nj |
727 |
errList(j) = fldMiss(j) |
728 |
ENDDO |
729 |
ELSE |
730 |
C-- Normal end : print msg before resetting "mFldsFile" |
731 |
ioUnit = standardMessageUnit |
732 |
prtMsg = debugLevel.GE.debLevA .AND. myThid.EQ.1 |
733 |
IF ( prtMsg ) THEN |
734 |
WRITE(msgBuf,'(3A)') 'READ_MFLDS_CHECK: ', |
735 |
& '- normal end ; reset MFLDS file-name: ', mFldsFile(1:iL) |
736 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT, myThid ) |
737 |
ENDIF |
738 |
|
739 |
ENDIF |
740 |
|
741 |
C- Return the number of missing fields |
742 |
nbErr = nMissFld |
743 |
|
744 |
#ifdef RW_SAFE_MFLDS |
745 |
_BARRIER |
746 |
_BEGIN_MASTER( myThid ) |
747 |
C-- Reset MFLDS file name: |
748 |
mFldsFile = ' ' |
749 |
_END_MASTER( myThid ) |
750 |
_BARRIER |
751 |
#endif /* RW_SAFE_MFLDS */ |
752 |
|
753 |
RETURN |
754 |
END |
755 |
|
756 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
757 |
CBOP |
758 |
C !ROUTINE: READ_MFLDS_RENAME |
759 |
C !INTERFACE: |
760 |
SUBROUTINE READ_MFLDS_RENAME( |
761 |
I fldName, newName, |
762 |
O errCode, |
763 |
I myThid ) |
764 |
|
765 |
C !DESCRIPTION: |
766 |
C Rename one field in fldList |
767 |
|
768 |
C !USES: |
769 |
IMPLICIT NONE |
770 |
c#include "SIZE.h" |
771 |
#include "EEPARAMS.h" |
772 |
#include "RW_MFLDS.h" |
773 |
|
774 |
C !INPUT/OUTPUT PARAMETERS: |
775 |
C fldName :: field name to rename |
776 |
C newName :: new name to replace fldName |
777 |
C errCode :: returned error code: |
778 |
C 0 = succesful ; 1 = fldName not found ; > 1 : error |
779 |
C myThid :: my Thread Id. number |
780 |
CHARACTER*(8) fldName |
781 |
CHARACTER*(8) newName |
782 |
INTEGER errCode |
783 |
INTEGER myThid |
784 |
CEOP |
785 |
|
786 |
C !LOCAL VARIABLES: |
787 |
C i , j :: loop counter |
788 |
INTEGER i , j |
789 |
C- for debug print: |
790 |
c CHARACTER*(MAX_LEN_MBUF) msgBuf |
791 |
|
792 |
errCode = 1 |
793 |
|
794 |
C- search for fldName in fldList: |
795 |
j = 0 |
796 |
DO i=1,nFlds |
797 |
IF ( fldList(i) .EQ. fldName ) THEN |
798 |
IF ( j.EQ.0 ) THEN |
799 |
errCode = 0 |
800 |
j = i |
801 |
ELSE |
802 |
C-- fldName appears more than once in fldList (errCode=3): |
803 |
errCode = 3 |
804 |
ENDIF |
805 |
ENDIF |
806 |
ENDDO |
807 |
|
808 |
IF ( errCode.EQ.0 ) THEN |
809 |
C-- Do not replace if newName is already in the list (errCode=2): |
810 |
DO i=1,nFlds |
811 |
IF ( fldList(i).EQ.newName ) errCode = 2 |
812 |
ENDDO |
813 |
ENDIF |
814 |
|
815 |
IF ( errCode.EQ.0 ) THEN |
816 |
_BARRIER |
817 |
_BEGIN_MASTER( myThid ) |
818 |
fldList(j) = newName |
819 |
_END_MASTER( myThid ) |
820 |
_BARRIER |
821 |
ENDIF |
822 |
|
823 |
RETURN |
824 |
END |