1 |
C $Header: /u/gcmpack/MITgcm/eesupp/src/dfile.F,v 1.13 2009/04/21 16:02:42 jmc Exp $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "CPP_EEOPTIONS.h" |
5 |
|
6 |
C-- File dfile.F: Routines that handle actual I/O |
7 |
C-- to model "dump" files. |
8 |
C-- These low-level routines could be replaced |
9 |
C-- by platform/environment specific C or |
10 |
C-- MPI-2 routines one day! In some situations the |
11 |
C-- functionality of these low-level routines is |
12 |
C-- encompassed by the data handling package. For |
13 |
C-- example netCDF provides primitive that are |
14 |
C-- higher level |
15 |
C-- Contents |
16 |
C-- DFILE_INIT - Initialisation procedure for subsequent DFILE |
17 |
C data-structures. Only called once per run. |
18 |
C-- DFILE_CLOSE - Closes dump file |
19 |
C-- DFILE_OPEN - Opens dump file |
20 |
C-- DFILE_READ_R8 - Reads from a dump file |
21 |
C-- DFILE_READ_R4 - Reads from a dump file |
22 |
C-- DFILE_SET_RO - Sets new connections to be read-only |
23 |
C-- DFILE_SET_RW - Sets new connections to be read-write |
24 |
C-- DFILE_SET_STOP_ON_ERROR - Sets new connections to STOP on error |
25 |
C-- DFILE_SET_CONT_ON_ERROR - Sets new connections to continue |
26 |
C on error |
27 |
C-- DFILE_WRITE_R4 - Writes to a dump file |
28 |
C-- DFILE_WRITE_R8 - Writes to a dump file |
29 |
C |
30 |
C Notes: |
31 |
C ====== |
32 |
C The default behaviour is for the model to stop if an |
33 |
C input errors occur but to continue if output errors occur. |
34 |
C However, this policy is not enforced in these low-level routines. |
35 |
C Instead these routines are coded to allow either continue |
36 |
C on error or stop on error. Which action is taken |
37 |
C is controlled via a mode flag which is set from the higher |
38 |
C level calls to these routines. A mode flag is also used to |
39 |
C control whether the DFILE_OPEN routine opens a file in |
40 |
C read-write or read-only mode. On some systems this is necessary |
41 |
C as the default is read-write and will fail for read-only files or |
42 |
C file systems. Other systems do not support the OPEN(...='READ_ONLY') |
43 |
C so this feature may need to be switched on or off as appropriate. |
44 |
C The DFILE_SET routines provide this mechanism. They work by setting |
45 |
C a "context" flag which is applied to IO ahndles when the DFILE_OPEN |
46 |
C call is made. IO handles that are already open are not affected by |
47 |
C subsequent calls to DFILE_SET routines. |
48 |
|
49 |
SUBROUTINE DFILE_INIT |
50 |
C /==========================================================\ |
51 |
C | SUBROUTINE DFILE_INIT | |
52 |
C | o Model "dump" file initialisation procedure | |
53 |
C |==========================================================| |
54 |
C | Initalises data structures used by MITgcmUV "dump file" | |
55 |
C | procedures. | |
56 |
C | As coded this routine sets the unit number used for | |
57 |
C | dump file IO. Two numbers are used one for data and one | |
58 |
C | for meta data. It is possible to use more unit numbers | |
59 |
C | and/or have different unit numbers per thread. This is | |
60 |
C | not done here. | |
61 |
C \==========================================================/ |
62 |
IMPLICIT NONE |
63 |
|
64 |
C == Global variables == |
65 |
#include "SIZE.h" |
66 |
#include "EEPARAMS.h" |
67 |
#include "DFILE.h" |
68 |
|
69 |
#ifdef USE_DFILE |
70 |
|
71 |
C == Local variables == |
72 |
C I, J - Loop counters |
73 |
INTEGER I, J |
74 |
|
75 |
DO j=1,MAX_NO_THREADS |
76 |
DO i=1,ioUnitsPerThread |
77 |
mUnitNumber(i,j) = 20+i*2-1 |
78 |
dUnitNumber(i,j) = 20+i*2 |
79 |
unitStatus (i,j) = freeUnit |
80 |
metaDataStatus(i,j) = metaDataNotWritten |
81 |
ENDDO |
82 |
ENDDO |
83 |
|
84 |
C-- Set initial access and error modes |
85 |
CALL DFILE_SET_RW |
86 |
CALL DFILE_SET_STOP_ON_ERROR |
87 |
|
88 |
#endif /* USE_DFILE */ |
89 |
|
90 |
RETURN |
91 |
END |
92 |
|
93 |
#ifdef USE_DFILE |
94 |
SUBROUTINE DFILE_CLOSE( |
95 |
I fileHandle, myThid) |
96 |
C /==========================================================\ |
97 |
C | SUBROUTINE DFILE\_CLOSE | |
98 |
C | o Close model "dump" file. | |
99 |
C |==========================================================| |
100 |
C | Controlling routine for doing actual I/O operations. | |
101 |
C | Close the file referred to by handle fielHandle. | |
102 |
C \==========================================================/ |
103 |
IMPLICIT NONE |
104 |
|
105 |
C == Global variables == |
106 |
#include "SIZE.h" |
107 |
#include "EEPARAMS.h" |
108 |
#include "EESUPPORT.h" |
109 |
#include "DFILE.h" |
110 |
|
111 |
C == Routine arguments == |
112 |
INTEGER myThid |
113 |
INTEGER fileHandle |
114 |
|
115 |
C == Local variables == |
116 |
C msgBuf - Error message buffer |
117 |
C I - Work variables |
118 |
C dUnit Data unit |
119 |
C mUnit Meta data unit |
120 |
C eMode Error mode |
121 |
CHARACTER*(MAX_LEN_MBUF) msgBuf |
122 |
INTEGER I |
123 |
INTEGER dUnit |
124 |
INTEGER mUnit |
125 |
INTEGER eMode |
126 |
|
127 |
I = fileHandle |
128 |
|
129 |
C-- Check that the fileHandle passed in is open |
130 |
IF ( unitStatus(I,myThid) .NE. busyUnit ) GOTO 1000 |
131 |
|
132 |
unitStatus(I,myThid) = freeUnit |
133 |
dUnit = dUnitNumber(I,myThid) |
134 |
mUnit = mUnitNumber(I,myThid) |
135 |
eMode = errorMode(I,myThid) |
136 |
CLOSE(dUnit,ERR=999) |
137 |
CLOSE(mUnit,ERR=999) |
138 |
|
139 |
1000 CONTINUE |
140 |
RETURN |
141 |
999 CONTINUE |
142 |
WRITE(msgBuf,'(A)') ' S/R DFILE_CLOSE' |
143 |
CALL PRINT_ERROR( msgBuf , 1) |
144 |
WRITE(msgBuf,'(A,A)') ' Thread ', myThid,' Close file failed' |
145 |
CALL PRINT_ERROR( msgBuf , 1) |
146 |
IF ( eMode .EQ. errorModeSTOP ) THEN |
147 |
STOP 'ABNORMAL END: S/R DFILE_CLOSE' |
148 |
ENDIF |
149 |
ioErrorCount(myThid) = ioErrorCount(myThid)+1 |
150 |
GOTO 1000 |
151 |
|
152 |
END |
153 |
|
154 |
SUBROUTINE DFILE_OPEN( |
155 |
I fNam, fNamMeta, myThid, |
156 |
O fileHandle) |
157 |
C /==========================================================\ |
158 |
C | SUBROUTINE DFILE_OPEN | |
159 |
C | o Open model "dump" file. | |
160 |
C |==========================================================| |
161 |
C | Controlling routine for doing actual I/O operations. | |
162 |
C | Routine returns a handle to the caller that can be used | |
163 |
C | in subsequent read and write operations. | |
164 |
C \==========================================================/ |
165 |
IMPLICIT NONE |
166 |
|
167 |
C == Global variables == |
168 |
#include "SIZE.h" |
169 |
#include "EEPARAMS.h" |
170 |
#include "EESUPPORT.h" |
171 |
#include "DFILE.h" |
172 |
|
173 |
INTEGER IFNBLNK |
174 |
EXTERNAL IFNBLNK |
175 |
INTEGER ILNBLNK |
176 |
EXTERNAL ILNBLNK |
177 |
|
178 |
C == Routine arguments == |
179 |
CHARACTER*(*) fNam |
180 |
CHARACTER*(*) fNamMeta |
181 |
INTEGER myThid |
182 |
INTEGER fileHandle |
183 |
|
184 |
C == Local variables == |
185 |
C msgBuf - Error message buffer |
186 |
C dUnit - Unit number for data |
187 |
C mUnit - Unit number for meta data |
188 |
C eMode - Error mode |
189 |
C aMode - Access mode |
190 |
C I - Loop counters |
191 |
INTEGER dUnit |
192 |
INTEGER mUnit |
193 |
INTEGER eMode |
194 |
INTEGER aMode |
195 |
CHARACTER*(MAX_LEN_MBUF) msgBuf |
196 |
INTEGER I |
197 |
INTEGER i1Lo, i1Hi, i2Lo, i2Hi |
198 |
|
199 |
C-- Get statistics on names |
200 |
i1Lo = IFNBLNK(fNam) |
201 |
i1Hi = ILNBLNK(fNam) |
202 |
i2Lo = IFNBLNK(fNamMeta) |
203 |
i2Hi = ILNBLNK(fNamMeta) |
204 |
|
205 |
C-- Choose a free I/O unit |
206 |
fileHandle = -1 |
207 |
dUnit = 0 |
208 |
DO I=1, ioUnitsPerThread |
209 |
IF ( unitStatus(I,myThid) .EQ. freeUnit ) THEN |
210 |
dUnit = dUnitNumber(I,myThid) |
211 |
mUnit = mUnitNumber(I,myThid) |
212 |
unitStatus(I,myThid) = busyUnit |
213 |
errorMode(I,myThid) = theErrorMode |
214 |
accessMode(I,myThid) = theAccessMode |
215 |
eMode = theErrorMode |
216 |
aMode = theAccessMode |
217 |
fileHandle = I |
218 |
GOTO 10 |
219 |
ENDIF |
220 |
ENDDO |
221 |
10 CONTINUE |
222 |
IF ( dUnit .EQ. 0 ) GOTO 999 |
223 |
|
224 |
C-- Remove previous meta information if there was any |
225 |
metaDataStatus(fileHandle,myThid) = metaDataWritten |
226 |
IF ( fNamMeta .NE. ' ' ) THEN |
227 |
IF ( aMode .EQ. accessModeRW ) THEN |
228 |
OPEN(UNIT=mUnit,FILE=fNamMeta(i2Lo:i2Hi), |
229 |
& STATUS='UNKNOWN',ERR=899) |
230 |
CLOSE(mUnit,ERR=899) |
231 |
OPEN(UNIT=mUnit,FILE=fNamMeta(i2Lo:i2Hi), |
232 |
& STATUS='UNKNOWN',ERR=899) |
233 |
metaDataStatus(fileHandle,myThid) = metaDataNotWritten |
234 |
nameOfMFile(fileHandle,myThid) = fNamMeta(i2Lo:i2Hi) |
235 |
ENDIF |
236 |
ENDIF |
237 |
|
238 |
C-- Open data file |
239 |
nameOfDFile(fileHandle,myThid) = fNam(i1Lo:i1Hi) |
240 |
OPEN(UNIT=dUnit,FILE=fNam(i1Lo:i1Hi),STATUS='UNKNOWN', ERR=799, |
241 |
& FORM='UNFORMATTED',ACCESS='SEQUENTIAL') |
242 |
|
243 |
|
244 |
1000 CONTINUE |
245 |
RETURN |
246 |
|
247 |
999 CONTINUE |
248 |
WRITE(msgBuf,'(A)') ' S/R DFILE_OPEN ' |
249 |
CALL PRINT_ERROR( msgBuf , 1) |
250 |
WRITE(msgBuf,'(A,A)') ' Too many open files ' |
251 |
CALL PRINT_ERROR( msgBuf , 1) |
252 |
WRITE(msgBuf,'(A,I4,A,A)') ' Thread ', myThid,' trying to open ', |
253 |
& fNam(i1Lo:i1Hi) |
254 |
CALL PRINT_ERROR( msgBuf , 1) |
255 |
IF ( eMode .EQ. errorModeSTOP ) THEN |
256 |
STOP 'ABNORMAL END: S/R DFILE_OPEN ' |
257 |
ENDIF |
258 |
ioErrorCount(myThid) = ioErrorCount(myThid) + 1 |
259 |
GOTO 1000 |
260 |
|
261 |
899 CONTINUE |
262 |
WRITE(msgBuf,'(A)') ' S/R DFILE_OPEN ' |
263 |
CALL PRINT_ERROR( msgBuf , 1) |
264 |
WRITE(msgBuf,'(A,I4,A,A)') ' Thread ',myThid,' failed open for ', |
265 |
& fNamMeta(i2Lo:i2Hi) |
266 |
CALL PRINT_ERROR( msgBuf , 1) |
267 |
IF ( eMode .EQ. errorModeSTOP ) THEN |
268 |
STOP 'ABNORMAL END: S/R DFILE_OPEN ' |
269 |
ENDIF |
270 |
ioErrorCount(myThid) = ioErrorCount(myThid) + 1 |
271 |
GOTO 1000 |
272 |
|
273 |
799 CONTINUE |
274 |
WRITE(msgBuf,'(A)') ' S/R DFILE_OPEN ' |
275 |
CALL PRINT_ERROR( msgBuf , 1) |
276 |
WRITE(msgBuf,'(A,I4,A,A)') ' Thread ',myThid,' failed open for ', |
277 |
& fNam(i1Lo:i1Hi) |
278 |
CALL PRINT_ERROR( msgBuf , 1) |
279 |
IF ( eMode .EQ. errorModeSTOP ) THEN |
280 |
STOP 'ABNORMAL END: S/R DFILE_OPEN ' |
281 |
ENDIF |
282 |
ioErrorCount(myThid) = ioErrorCount(myThid) + 1 |
283 |
GOTO 1000 |
284 |
|
285 |
END |
286 |
|
287 |
SUBROUTINE DFILE_READ_R4( |
288 |
I lBuffer, |
289 |
I fileHandle, myThid) |
290 |
C /==========================================================\ |
291 |
C | SUBROUTINE DFILE_READ_R4 | |
292 |
C | o Read record(s) from model dump file. | |
293 |
C |==========================================================| |
294 |
C | Controlling routine for doing actual I/O operations. | |
295 |
C | Routine reads data from binary files formatted for | |
296 |
C | model input. Could do elaborate reads from netCDF or | |
297 |
C | using regular C I/O primitives. For now we use plain | |
298 |
C | F77. | |
299 |
C \==========================================================/ |
300 |
IMPLICIT NONE |
301 |
|
302 |
C == Global variables == |
303 |
#include "SIZE.h" |
304 |
#include "EEPARAMS.h" |
305 |
#include "DFILE.h" |
306 |
|
307 |
INTEGER IFNBLNK |
308 |
EXTERNAL IFNBLNK |
309 |
INTEGER ILNBLNK |
310 |
EXTERNAL ILNBLNK |
311 |
|
312 |
C == Routine arguments == |
313 |
C lBuffer - Length of buffer data will be read into |
314 |
C fileHandle - Handle of already opened file |
315 |
C myThid - Thread id calling this routine |
316 |
INTEGER lBuffer |
317 |
INTEGER fileHandle |
318 |
INTEGER myThid |
319 |
|
320 |
C == Local variables == |
321 |
C ioUnit - Unit number associated with fileHandle |
322 |
C I - Loop counter |
323 |
C eMode - fileHandles error mode |
324 |
CHARACTER*(MAX_LEN_FNAM) fNam |
325 |
CHARACTER*(MAX_LEN_MBUF) msgBuf |
326 |
INTEGER ioUnit |
327 |
INTEGER I, iLo, iHi |
328 |
INTEGER eMode |
329 |
|
330 |
C-- Get error mode |
331 |
eMode = errorMode(fileHandle,myThid) |
332 |
|
333 |
C-- Check that file is active |
334 |
IF ( unitStatus(fileHandle,myThid) .NE. busyUnit ) GOTO 999 |
335 |
|
336 |
fNam = nameOfDFile(fileHandle,myThid) |
337 |
iLo = IFNBLNK(fNam) |
338 |
iHi = ILNBLNK(fNam) |
339 |
ioUnit = dUnitNumber(fileHandle,myThid) |
340 |
READ(ioUnit,ERR=899) (ioBuf_R4(I),I=1,lBuffer) |
341 |
|
342 |
|
343 |
1000 CONTINUE |
344 |
RETURN |
345 |
|
346 |
999 CONTINUE |
347 |
WRITE(msgBuf,'(A)') ' S/R DFILE_READ_R4 ' |
348 |
CALL PRINT_ERROR( msgBuf , 1) |
349 |
WRITE(msgBuf,'(A,I4,A)') ' Thread ', myThid, ' unit not open ' |
350 |
CALL PRINT_ERROR( msgBuf , 1) |
351 |
IF ( eMode .EQ. errorModeSTOP ) THEN |
352 |
STOP 'ABNORMAL END: S/R DFILE_READ_R4' |
353 |
ENDIF |
354 |
ioErrorCount(myThid) = ioErrorCount(myThid) + 1 |
355 |
GOTO 1000 |
356 |
|
357 |
899 CONTINUE |
358 |
WRITE(msgBuf,'(A)') ' S/R DFILE_READ_R4 ' |
359 |
CALL PRINT_ERROR( msgBuf , 1) |
360 |
WRITE(msgBuf,'(A,I4,A)') ' Thread ', myThid,' error reading file' |
361 |
CALL PRINT_ERROR( msgBuf , 1) |
362 |
WRITE(msgBuf,'(A,A,A)') ' "', fNam(iLo:iHi),'"' |
363 |
CALL PRINT_ERROR( msgBuf , 1) |
364 |
IF ( eMode .EQ. errorModeSTOP ) THEN |
365 |
STOP 'ABNORMAL END: S/R DFILE_READ_R4' |
366 |
ENDIF |
367 |
ioErrorCount(myThid) = ioErrorCount(myThid) + 1 |
368 |
GOTO 1000 |
369 |
|
370 |
END |
371 |
SUBROUTINE DFILE_READ_R8( |
372 |
I lBuffer, |
373 |
I fileHandle, myThid) |
374 |
C /==========================================================\ |
375 |
C | SUBROUTINE DFILE_READ_R8 | |
376 |
C | o Read record(s) from model dump file. | |
377 |
C |==========================================================| |
378 |
C | Controlling routine for doing actual I/O operations. | |
379 |
C | Routine reads data from binary files formatted for | |
380 |
C | model input. Could do elaborate reads from netCDF or | |
381 |
C | using regular C I/O primitives. For now we use plain | |
382 |
C | F77. | |
383 |
C \==========================================================/ |
384 |
IMPLICIT NONE |
385 |
|
386 |
C == Global variables == |
387 |
#include "SIZE.h" |
388 |
#include "EEPARAMS.h" |
389 |
#include "DFILE.h" |
390 |
|
391 |
INTEGER IFNBLNK |
392 |
EXTERNAL IFNBLNK |
393 |
INTEGER ILNBLNK |
394 |
EXTERNAL ILNBLNK |
395 |
|
396 |
C == Routine arguments == |
397 |
C lBuffer - Length of buffer data will be read into |
398 |
C fileHandle - Handle of already opened file |
399 |
C myThid - Thread id calling this routine |
400 |
INTEGER lBuffer |
401 |
INTEGER fileHandle |
402 |
INTEGER myThid |
403 |
|
404 |
C == Local variables == |
405 |
C ioUnit - Unit number associated with fileHandle |
406 |
C I - Loop counter |
407 |
C eMode - fileHandles error mode |
408 |
CHARACTER*(MAX_LEN_FNAM) fNam |
409 |
CHARACTER*(MAX_LEN_MBUF) msgBuf |
410 |
INTEGER ioUnit |
411 |
INTEGER I, iLo, iHi |
412 |
INTEGER eMode |
413 |
|
414 |
C-- Get error mode |
415 |
eMode = errorMode(fileHandle,myThid) |
416 |
|
417 |
C-- Check that file is active |
418 |
IF ( unitStatus(fileHandle,myThid) .NE. busyUnit ) GOTO 999 |
419 |
|
420 |
fNam = nameOfDFile(fileHandle,myThid) |
421 |
iLo = IFNBLNK(fNam) |
422 |
iHi = ILNBLNK(fNam) |
423 |
ioUnit = dUnitNumber(fileHandle,myThid) |
424 |
READ(ioUnit,ERR=899) (ioBuf_R8(I),I=1,lBuffer) |
425 |
|
426 |
|
427 |
1000 CONTINUE |
428 |
RETURN |
429 |
|
430 |
999 CONTINUE |
431 |
WRITE(msgBuf,'(A)') ' S/R DFILE_READ_R8 ' |
432 |
CALL PRINT_ERROR( msgBuf , 1) |
433 |
WRITE(msgBuf,'(A,I4,A)') ' Thread ', myThid, ' unit not open ' |
434 |
CALL PRINT_ERROR( msgBuf , 1) |
435 |
IF ( eMode .EQ. errorModeSTOP ) THEN |
436 |
STOP 'ABNORMAL END: S/R DFILE_READ_R8' |
437 |
ENDIF |
438 |
ioErrorCount(myThid) = ioErrorCount(myThid) + 1 |
439 |
GOTO 1000 |
440 |
|
441 |
899 CONTINUE |
442 |
WRITE(msgBuf,'(A)') ' S/R DFILE_READ_R8 ' |
443 |
CALL PRINT_ERROR( msgBuf , 1) |
444 |
WRITE(msgBuf,'(A,I4,A)') ' Thread ', myThid,' error reading file' |
445 |
CALL PRINT_ERROR( msgBuf , 1) |
446 |
WRITE(msgBuf,'(A,A,A)') ' "', fNam(iLo:iHi),'"' |
447 |
CALL PRINT_ERROR( msgBuf , 1) |
448 |
IF ( eMode .EQ. errorModeSTOP ) THEN |
449 |
STOP 'ABNORMAL END: S/R DFILE_READ_R8' |
450 |
ENDIF |
451 |
ioErrorCount(myThid) = ioErrorCount(myThid) + 1 |
452 |
GOTO 1000 |
453 |
|
454 |
END |
455 |
|
456 |
SUBROUTINE DFILE_SET_RO |
457 |
C /==========================================================\ |
458 |
C | SUBROUTINE DFILE_SET_RO | |
459 |
C | o Sets new connections to be read-only. | |
460 |
C \==========================================================/ |
461 |
IMPLICIT NONE |
462 |
|
463 |
C == Global variables == |
464 |
#include "SIZE.h" |
465 |
#include "EEPARAMS.h" |
466 |
#include "DFILE.h" |
467 |
|
468 |
theAccessMode = accessModeRO |
469 |
|
470 |
RETURN |
471 |
END |
472 |
|
473 |
SUBROUTINE DFILE_SET_RW |
474 |
C /==========================================================\ |
475 |
C | SUBROUTINE DFILE_SET_RW | |
476 |
C | o Sets new connections to be read-write | |
477 |
C \==========================================================/ |
478 |
IMPLICIT NONE |
479 |
|
480 |
C == Global variables == |
481 |
#include "SIZE.h" |
482 |
#include "EEPARAMS.h" |
483 |
#include "DFILE.h" |
484 |
|
485 |
theAccessMode = accessModeRW |
486 |
|
487 |
RETURN |
488 |
END |
489 |
|
490 |
SUBROUTINE DFILE_SET_STOP_ON_ERROR |
491 |
C /==========================================================\ |
492 |
C | SUBROUTINE DFILE_SET_STOP_ON_ERROR | |
493 |
C | o Sets new connections to STOP on error | |
494 |
C \==========================================================/ |
495 |
IMPLICIT NONE |
496 |
|
497 |
C == Global variables == |
498 |
#include "SIZE.h" |
499 |
#include "EEPARAMS.h" |
500 |
#include "DFILE.h" |
501 |
|
502 |
theErrorMode = errorModeSTOP |
503 |
|
504 |
RETURN |
505 |
END |
506 |
|
507 |
SUBROUTINE DFILE_SET_CONT_ON_ERROR |
508 |
C /==========================================================\ |
509 |
C | SUBROUTINE DFILE_SET_CONT_ON_ERROR | |
510 |
C | o Sets new connections to continue on error | |
511 |
C \==========================================================/ |
512 |
IMPLICIT NONE |
513 |
|
514 |
C == Global variables == |
515 |
#include "SIZE.h" |
516 |
#include "EEPARAMS.h" |
517 |
#include "DFILE.h" |
518 |
|
519 |
theErrorMode = errorModeCONT |
520 |
|
521 |
RETURN |
522 |
END |
523 |
|
524 |
SUBROUTINE DFILE_WRITE_R4( |
525 |
I lBuffer, |
526 |
I nDims, dimList, |
527 |
I fileHandle, fileId, myThid ) |
528 |
C /==========================================================\ |
529 |
C | SUBROUTINE DFILE_WRITE_R4 | |
530 |
C | o Write record(s) to model dump file. | |
531 |
C |==========================================================| |
532 |
C | Controlling routine for doing actual I/O operations. | |
533 |
C | Routine writes data to binary files. | |
534 |
C | Could do elaborate write to netCDF or | |
535 |
C | use C I/O primitives. For now we use plain F77 but the | |
536 |
C | routine does write both data and metadata. Metadata is | |
537 |
C | extra info. which describes the data - in this case it | |
538 |
C | is information indicating the subregion of the global | |
539 |
C | dataset being written out. | |
540 |
C \==========================================================/ |
541 |
IMPLICIT NONE |
542 |
|
543 |
C == Global variables == |
544 |
#include "SIZE.h" |
545 |
#include "EEPARAMS.h" |
546 |
#include "DFILE.h" |
547 |
|
548 |
C == Routine arguments == |
549 |
C lBuffer - Amount of data written |
550 |
C nDims - Global and subset dimensionality |
551 |
C dimList - List of global and subset extents |
552 |
C fileHandle - Handle identifying actual IO unit |
553 |
C myThid - Thread number of thread calling this |
554 |
C routine |
555 |
C eMode - error mode for this fileHandle |
556 |
INTEGER lBuffer |
557 |
INTEGER nDims |
558 |
INTEGER dimList(nDims*3) |
559 |
INTEGER fileHandle |
560 |
INTEGER fileId |
561 |
INTEGER myThid |
562 |
|
563 |
C == Local variables == |
564 |
C ioUnit - Unit number for I/O |
565 |
C msgBuf - Textual printing message buffer |
566 |
C eMode - Error mode for this file handle |
567 |
INTEGER ioUnit |
568 |
CHARACTER*(MAX_LEN_MBUF) msgBuf |
569 |
CHARACTER*(MAX_LEN_FNAM) fNam |
570 |
INTEGER eMode |
571 |
INTEGER I |
572 |
|
573 |
C-- Set error mode |
574 |
eMode = errorMode(fileHandle,myThid) |
575 |
|
576 |
C-- Check that file is active |
577 |
IF ( unitStatus(fileHandle,myThid) .NE. busyUnit ) GOTO 999 |
578 |
|
579 |
C-- Write data |
580 |
ioUnit = dUnitNumber(fileHandle,myThid) |
581 |
fNam = nameOfDFile(fileHandle,myThid) |
582 |
WRITE(ioUnit,ERR=899) (ioBuf_R4(I),I=1,lBuffer) |
583 |
|
584 |
C-- Now write meta information |
585 |
IF ( metaDataStatus(fileHandle,myThid) .EQ. |
586 |
& metaDataNotWritten ) THEN |
587 |
ioUnit = mUnitNumber(fileHandle,myThid) |
588 |
|
589 |
WRITE(msgBuf,'(A)') '// START OF META DATA' |
590 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT , 1) |
591 |
|
592 |
WRITE(msgBuf,'(A,A)') ' id =[ ','/* Identifier */' |
593 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT , 1) |
594 |
CALL PRINT_LIST_I( fileId, 1,1, INDEX_NONE, .FALSE., .TRUE., |
595 |
& ioUnit ) |
596 |
WRITE(msgBuf,'(A)') ' ]; ' |
597 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT , 1) |
598 |
|
599 |
WRITE(msgBuf,'(A,A)') ' nDims =[ ','/* Number of dimensions */' |
600 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT , 1) |
601 |
CALL PRINT_LIST_I( nDims, 1,1, INDEX_NONE, .FALSE., .TRUE., |
602 |
& ioUnit ) |
603 |
WRITE(msgBuf,'(A)') ' ]; ' |
604 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT , 1) |
605 |
|
606 |
WRITE(msgBuf,'(A,A)') ' dimList =[ ', |
607 |
& '/* Global1, local min1, local max1, ... */' |
608 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT , 1) |
609 |
DO I=1,nDims |
610 |
CALL PRINT_LIST_I( dimList((I-1)*3+1), 1,3, INDEX_NONE, |
611 |
& I.NE.nDims, .FALSE., ioUnit ) |
612 |
ENDDO |
613 |
WRITE(msgBuf,'(A)') ' ]; ' |
614 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT , 1) |
615 |
|
616 |
WRITE(msgBuf,'(A,A)') ' format =[ ','/* Field format */' |
617 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT , 1) |
618 |
WRITE(msgBuf,'(16X,A)') '''float32''' |
619 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT , 1) |
620 |
WRITE(msgBuf,'(A)') ' ]; ' |
621 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT , 1) |
622 |
|
623 |
WRITE(msgBuf,'(A)') '// END OF META DATA' |
624 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT , 1) |
625 |
metaDataStatus(fileHandle,myThid) = metaDataWritten |
626 |
ENDIF |
627 |
|
628 |
1000 CONTINUE |
629 |
RETURN |
630 |
|
631 |
999 CONTINUE |
632 |
WRITE(msgBuf,'(A)') ' S/R DFILE_WRITE_R4 ' |
633 |
CALL PRINT_ERROR( msgBuf , 1) |
634 |
WRITE(msgBuf,'(A,A)') ' Thread ', myThid, ' unit not open ' |
635 |
CALL PRINT_ERROR( msgBuf , 1) |
636 |
IF ( eMode .EQ. errorModeSTOP ) THEN |
637 |
STOP 'ABNORMAL END: S/R DFILE_WRITE_R4' |
638 |
ENDIF |
639 |
ioErrorCount(myThid) = ioErrorCount(myThid) + 1 |
640 |
GOTO 1000 |
641 |
|
642 |
899 CONTINUE |
643 |
WRITE(msgBuf,'(A)') ' S/R DFILE_WRITE_R4 ' |
644 |
CALL PRINT_ERROR( msgBuf , 1) |
645 |
WRITE(msgBuf,'(A,A)') ' Thread ', myThid, ' write error ' |
646 |
CALL PRINT_ERROR( msgBuf , 1) |
647 |
WRITE(msgBuf,'(A,A)') ' File ', fNam |
648 |
CALL PRINT_ERROR( msgBuf , 1) |
649 |
IF ( eMode .EQ. errorModeSTOP ) THEN |
650 |
STOP 'ABNORMAL END: S/R DFILE_WRITE_R4' |
651 |
ENDIF |
652 |
ioErrorCount(myThid) = ioErrorCount(myThid) + 1 |
653 |
GOTO 1000 |
654 |
|
655 |
END |
656 |
|
657 |
SUBROUTINE DFILE_WRITE_R8( |
658 |
I lBuffer, |
659 |
I nDims, dimList, |
660 |
I fileHandle, fileId, myThid ) |
661 |
C /==========================================================\ |
662 |
C | SUBROUTINE DFILE_WRITE_R8 | |
663 |
C | o Write record(s) to model dump file. | |
664 |
C |==========================================================| |
665 |
C | Controlling routine for doing actual I/O operations. | |
666 |
C | Routine writes data to binary files. | |
667 |
C | Could do elaborate write to netCDF or | |
668 |
C | use C I/O primitives. For now we use plain F77 but the | |
669 |
C | routine does write both data and metadata. Metadata is | |
670 |
C | extra info. which describes the data - in this case it | |
671 |
C | is information indicating the subregion of the global | |
672 |
C | dataset being written out. | |
673 |
C \==========================================================/ |
674 |
IMPLICIT NONE |
675 |
|
676 |
C == Global variables == |
677 |
#include "SIZE.h" |
678 |
#include "EEPARAMS.h" |
679 |
#include "DFILE.h" |
680 |
|
681 |
C == Routine arguments == |
682 |
C buffer - Subset data to write |
683 |
C lBuffer - Amount of data written |
684 |
C nDims - Global and subset dimensionality |
685 |
C dimList - List of global and subset extents |
686 |
C fileHandle - Handle identifying actual IO unit |
687 |
C myThid - Thread number of thread calling this |
688 |
C routine |
689 |
C eMode - error mode for this fileHandle |
690 |
INTEGER lBuffer |
691 |
INTEGER nDims |
692 |
INTEGER dimList(nDims*3) |
693 |
INTEGER fileHandle |
694 |
INTEGER fileId |
695 |
INTEGER myThid |
696 |
|
697 |
C == Local variables == |
698 |
C ioUnit - Unit number for I/O |
699 |
C msgBuf - Textual printing message buffer |
700 |
C eMode - Error mode for this file handle |
701 |
INTEGER ioUnit |
702 |
CHARACTER*(MAX_LEN_MBUF) msgBuf |
703 |
CHARACTER*(MAX_LEN_FNAM) fNam |
704 |
INTEGER eMode |
705 |
INTEGER I |
706 |
|
707 |
C-- Set error mode |
708 |
eMode = errorMode(fileHandle,myThid) |
709 |
|
710 |
C-- Check that file is active |
711 |
IF ( unitStatus(fileHandle,myThid) .NE. busyUnit ) GOTO 999 |
712 |
|
713 |
C-- Write data |
714 |
ioUnit = dUnitNumber(fileHandle,myThid) |
715 |
fNam = nameOfDFile(fileHandle,myThid) |
716 |
WRITE(ioUnit,ERR=899) (ioBuf_R8(I),I=1,lBuffer) |
717 |
|
718 |
C-- Now write meta information |
719 |
IF ( metaDataStatus(fileHandle,myThid) .EQ. |
720 |
& metaDataNotWritten ) THEN |
721 |
ioUnit = mUnitNumber(fileHandle,myThid) |
722 |
|
723 |
WRITE(msgBuf,'(A)') '// START OF META DATA' |
724 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT , 1) |
725 |
|
726 |
WRITE(msgBuf,'(A,A)') ' id =[ ','/* Identifier */' |
727 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT , 1) |
728 |
CALL PRINT_LIST_I( fileId, 1,1, INDEX_NONE, .FALSE., .TRUE., |
729 |
& ioUnit ) |
730 |
WRITE(msgBuf,'(A)') ' ]; ' |
731 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT , 1) |
732 |
|
733 |
WRITE(msgBuf,'(A,A)') ' nDims =[ ','/* Number of dimensions */' |
734 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT , 1) |
735 |
CALL PRINT_LIST_I( nDims, 1,1, INDEX_NONE, .FALSE., .TRUE., |
736 |
& ioUnit ) |
737 |
WRITE(msgBuf,'(A)') ' ]; ' |
738 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT , 1) |
739 |
|
740 |
WRITE(msgBuf,'(A,A)') ' dimList =[ ', |
741 |
& '/* Global1, local min1, local max1, ... */' |
742 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT , 1) |
743 |
DO I=1,nDims |
744 |
CALL PRINT_LIST_I( dimList((I-1)*3+1), 1,3, INDEX_NONE, |
745 |
& I.NE.nDims, .FALSE., ioUnit ) |
746 |
ENDDO |
747 |
WRITE(msgBuf,'(A)') ' ]; ' |
748 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT , 1) |
749 |
|
750 |
WRITE(msgBuf,'(A,A)') ' format =[ ','/* Field format */' |
751 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT , 1) |
752 |
WRITE(msgBuf,'(16X,A)') '''float64''' |
753 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT , 1) |
754 |
WRITE(msgBuf,'(A)') ' ]; ' |
755 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT , 1) |
756 |
|
757 |
WRITE(msgBuf,'(A)') '// END OF META DATA' |
758 |
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT , 1) |
759 |
metaDataStatus(fileHandle,myThid) = metaDataWritten |
760 |
ENDIF |
761 |
|
762 |
1000 CONTINUE |
763 |
RETURN |
764 |
|
765 |
999 CONTINUE |
766 |
WRITE(msgBuf,'(A)') ' S/R DFILE_WRITE_R8 ' |
767 |
CALL PRINT_ERROR( msgBuf , 1) |
768 |
WRITE(msgBuf,'(A,A)') ' Thread ', myThid, ' unit not open ' |
769 |
CALL PRINT_ERROR( msgBuf , 1) |
770 |
IF ( eMode .EQ. errorModeSTOP ) THEN |
771 |
STOP 'ABNORMAL END: S/R DFILE_WRITE_R8' |
772 |
ENDIF |
773 |
ioErrorCount(myThid) = ioErrorCount(myThid) + 1 |
774 |
GOTO 1000 |
775 |
|
776 |
899 CONTINUE |
777 |
WRITE(msgBuf,'(A)') ' S/R DFILE_WRITE_R8 ' |
778 |
CALL PRINT_ERROR( msgBuf , 1) |
779 |
WRITE(msgBuf,'(A,A)') ' Thread ', myThid, ' write error ' |
780 |
CALL PRINT_ERROR( msgBuf , 1) |
781 |
WRITE(msgBuf,'(A,A)') ' File ', fNam |
782 |
CALL PRINT_ERROR( msgBuf , 1) |
783 |
IF ( eMode .EQ. errorModeSTOP ) THEN |
784 |
STOP 'ABNORMAL END: S/R DFILE_WRITE_R8' |
785 |
ENDIF |
786 |
ioErrorCount(myThid) = ioErrorCount(myThid) + 1 |
787 |
GOTO 1000 |
788 |
|
789 |
END |
790 |
#endif /* USE_DFILE */ |