HP-UX file-processing routines can be used as an alternative
to Fortran file I/O routines. This section discusses HP-UX
stream I/O routines and I/O system calls.
Stream I/O using FSTREAM |
 |
The HP-UX operating system uses the term stream
to refer to a file as a contiguous set of bytes. There are a number
of HP-UX subroutines for performing stream I/O;
see stdio(3S) in the HP-UX Reference.
Unlike Fortran I/O, which requires a logical unit
number to access a file, stream I/O routines require a
stream pointer—an integer variable that contains the address
of a C-language structure of type FILE
(as defined in the C-language header file /usr/include/stdio.h.)
The following Fortran 90 statement declares a variable
for use as a stream pointer in HP Fortran 90:
To obtain a stream pointer, use the Fortran intrinsic FSTREAM,
which returns a stream pointer for an open file, given the file"s
Fortran logical unit number:
stream-ptr = FSTREAM(logical-unit)
The logical-unit parameter must
be the logical unit number obtained from opening a Fortran file,
and stream-ptr must be of type integer.
If stream-ptr is not of type integer,
type conversion takes place with unpredictable results. The stream-ptr
should never be manipulated as an integer.
Once you obtain stream-ptr, use
the ALIAS directive
to pass it by value to stream I/O routines. (For an example
of how to use the ALIAS directive,
see “File handling ”.) All HP Fortran 90
directives are described in the HP Fortran 90 Programmer's
Reference.)
Performing I/O using HP-UX system calls |
 |
File I/O can also be performed with HP-UX system
calls (for example, open,
read, write,
and close), which
provide low-level access to the HP-UX kernel. These routines are
discussed in the HP-UX Reference; see also
the online man pages for these routines. For an example program
that shows how to call the write
routine, see “File handling ”.
Establishing a connection to
a file |
 |
HP-UX I/O system calls require an HP-UX file
descriptor, which establishes a connection to the file
being accessed. A file descriptor is an integer whose function
is similar to a Fortran logical unit number. For example, the following
open system call
(called from a C-language program) opens a file named DATA.DAT
for reading and writing, and returns the value of an HP-UX file
descriptor:
#include <fcntl.h> /* definition of O_RDWR contained here */ ... fildes = open("DATA.DAT", O_RDWR) |