/[MITgcm]/MITgcm/eesupp/src/dfile.F
ViewVC logotype

Annotation of /MITgcm/eesupp/src/dfile.F

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (hide annotations) (download)
Thu May 21 18:30:08 1998 UTC (26 years, 1 month ago) by cnh
Branch: MAIN
CVS Tags: checkpoint5, checkpoint4, checkpoint3, checkpoint2
Added support for binary IO of model fields for restart and/or
postprocessing

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

  ViewVC Help
Powered by ViewVC 1.1.22