+------------------------Fortran 2003 Draft Standard-------------------------+

FLUSH

Purpose

The FLUSH statement allows you to make data from an external file available to other processes. In addition, you can use the FLUSH statement to make data written to an external file by a means other than Fortran available to a READ statement.

Syntax



>>-FLUSH--+-u----------+---------------------------------------><
          '-flush_list-'
 
 

u
is an integer scalar expression with a value in a range from 0 through 2,147,483,647. This unit references an external file. The value of must not be an asterisk or a Hollerith constant.

flush_list
a list of specifiers that must contain UNIT=, and can also contain one of each of the following specifiers:

If you do not specify ERR or IOSTAT, the program terminates on encountering a severe error.

Rules

The FLUSH statement must not appear in a pure subprogram.

A FLUSH statement has no effect on file position.

The buffering run-time option does not affect the execution of the FLUSH statement.

Examples

Example 1: In the following example a data file written by a Fortran program is read by a C routine. The program specifies a FLUSH statement for the buffered I/O.

! The following Fortran program writes data to an external file.
subroutine process_data()
  integer data(10)
  external read_data
 
  data = (/(i,i=1,10)/)
  open(50, file="data_file")
  write(50, *) data             ! write data to an external file
  flush(50)                     ! since Fortran I/O is buffered, a FLUSH
                                ! statement is needed for the C routine to
                                ! to read the data
  call read_data(10)            ! call C routine to read the file
end subroutine
 
/* The following C routine reads data from the external file. */
void read_data(int *sz) {
 
#include < stdio.h>
#include < stdlib.h> 
int *data, i;
  FILE  *fp;
 
  data = (int *) malloc((*sz)*sizeof(int));
  fp = fopen("data_file", "r");
  for (i=0; i<*sz-1; i++) {
    fscanf(fp, "%d", &dat5[i]);
  }
}
 

+---------------------End of Fortran 2003 Draft Standard---------------------+

IBM Copyright 2003