24.05.2014 Views

XL Fortran Enterprise Edition for AIX : User's Guide - IBM

XL Fortran Enterprise Edition for AIX : User's Guide - IBM

XL Fortran Enterprise Edition for AIX : User's Guide - IBM

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

If you have applications in which <strong>Fortran</strong> routines work with routines in other<br />

languages or in which a <strong>Fortran</strong> process works with other processes on the<br />

same data file, the data written by <strong>Fortran</strong> routines may not be seen<br />

immediately by other parties (and vice versa), because of the buffering. Also, a<br />

<strong>Fortran</strong> READ statement may read more data than it needs into the I/O buffer<br />

and cause the input operation per<strong>for</strong>med by a routine in other languages or<br />

another process that is supposed to read the next data item to fail. In these<br />

cases, you can use the buffering run-time option to disable the buffering in the<br />

<strong>XL</strong> <strong>Fortran</strong> run-time library. As a result, a READ statement will read in exactly<br />

the data it needs from a file and the data written by a WRITE statement will<br />

be flushed out to the file system at the completion of the statement.<br />

Note: I/O buffering is always enabled <strong>for</strong> files on sequential access devices<br />

(such as pipes, terminals, sockets, and tape drives). The setting of the<br />

buffering option has no effect on these types of files.<br />

If you disable I/O buffering <strong>for</strong> a logical unit, you do not need to call the<br />

<strong>Fortran</strong> service routine flush_ to flush the contents of the I/O buffer <strong>for</strong> that<br />

logical unit.<br />

The suboptions <strong>for</strong> buffering are as follows:<br />

enable<br />

disable_preconn<br />

disable_all<br />

The <strong>Fortran</strong> run-time library maintains an I/O<br />

buffer <strong>for</strong> each connected logical unit. The<br />

current read-write file pointers that the<br />

run-time library maintains might not be<br />

synchronized with the read-write pointers of<br />

the corresponding files in the file system.<br />

The <strong>Fortran</strong> run-time library does not maintain<br />

an I/O buffer <strong>for</strong> each preconnected logical<br />

unit (0, 5, and 6). However, it does maintain<br />

I/O buffers <strong>for</strong> all other connected logical<br />

units. The current read-write file pointers that<br />

the run-time library maintains <strong>for</strong> the<br />

preconnected units are the same as the<br />

read-write pointers of the corresponding files<br />

in the file system.<br />

The <strong>Fortran</strong> run-time library does not maintain<br />

I/O buffers <strong>for</strong> any logical units. You should<br />

not specify the buffering=disable_all option<br />

with <strong>Fortran</strong> programs that per<strong>for</strong>m<br />

asynchronous I/O.<br />

In the following example, <strong>Fortran</strong> and C routines read a data file through<br />

redirected standard input. First, the main <strong>Fortran</strong> program reads one integer.<br />

Then, the C routine reads one integer. Finally, the main <strong>Fortran</strong> program reads<br />

another integer.<br />

<strong>Fortran</strong> main program:<br />

integer(4) p1,p2,p3<br />

print *,’Reading p1 in <strong>Fortran</strong>...’<br />

read(5,*) p1<br />

call c_func(p2)<br />

print *,’Reading p3 in <strong>Fortran</strong>...’<br />

read(5,*) p3<br />

print *,’p1 p2 p3 Read: ’,p1,p2,p3<br />

end<br />

52 <strong>XL</strong> <strong>Fortran</strong> <strong>Enterprise</strong> <strong>Edition</strong> <strong>for</strong> <strong>AIX</strong> : User’s <strong>Guide</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!