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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Flushing I/O Buffers<br />

PROGRAM RTEOPTS<br />

USE <strong>XL</strong>FUTILITY<br />

CALL SETRTEOPTS("err_recovery=no") ! Change setting.<br />

... some I/O statements ...<br />

CALL SETRTEOPTS("err_recovery=yes") ! Change it back.<br />

... some more I/O statements ...<br />

END<br />

Because a user can change these settings through the <strong>XL</strong>FRTEOPTS environment<br />

variable, be sure to use SETRTEOPTS to set all the run-time options that might<br />

affect the desired operation of the program.<br />

To protect data from being lost if a program ends unexpectedly, you can use the<br />

FLUSH statement or the flush_ subroutine to write any buffered data to a file.<br />

(The FLUSH statement is recommended <strong>for</strong> better portability.) The following<br />

example shows use of the flush_ subroutine:<br />

USE <strong>XL</strong>FUTILITY<br />

PARAMETER (UNIT=10)<br />

DO I=1,1000000<br />

WRITE (10,*) I<br />

CALL MIGHT_CRASH<br />

! If the program ends in the middle of the loop, some data<br />

! may be lost.<br />

END DO<br />

DO I=1,1000000<br />

WRITE (10,*) I<br />

CALL FLUSH_(UNIT)<br />

CALL MIGHT_CRASH<br />

! If the program ends in the middle of the loop, all data written<br />

! up to that point will be safely in the file.<br />

END DO<br />

END<br />

Related In<strong>for</strong>mation: See “Mixed-Language Input and Output” on page 346 and<br />

the FLUSH statement in the <strong>XL</strong> <strong>Fortran</strong> <strong>Enterprise</strong> <strong>Edition</strong> <strong>for</strong><br />

<strong>AIX</strong> Language Reference.<br />

Choosing Locations and Names <strong>for</strong> Input/Output Files<br />

If you need to override the default locations and names <strong>for</strong> input/output files, you<br />

can use the following methods without making any changes to the source code.<br />

Naming Files That Are Connected with No Explicit Name<br />

To give a specific name to a file that would usually have a name of the <strong>for</strong>m<br />

<strong>for</strong>t.unit, you must set the run-time option unit_vars and then set an environment<br />

variable with a name of the <strong>for</strong>m <strong>XL</strong>FUNIT_unit <strong>for</strong> each scratch file. The<br />

association is between a unit number in the <strong>Fortran</strong> program and a path name in<br />

the file system.<br />

For example, suppose that the <strong>Fortran</strong> program contains the following statements:<br />

OPEN (UNIT=1, FORM=’FORMATTED’, ACCESS=’SEQUENTIAL’, RECL=1024)<br />

...<br />

OPEN (UNIT=12, FORM=’UNFORMATTED’, ACCESS=’DIRECT’, RECL=131072)<br />

...<br />

OPEN (UNIT=123, FORM=’UNFORMATTED’, ACCESS=’SEQUENTIAL’, RECL=997)<br />

Implementation Details of <strong>XL</strong> <strong>Fortran</strong> Input/Output 331

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

Saved successfully!

Ooh no, something went wrong!