HP Fortran Programmer Guide (766160-001, March 2014)
For more information about the IGETARG and IARGC intrinsics, see the HP Fortran Programmer's
Reference. GETARGC is also available as a libU77 routine; see the HP Fortran Programmer's
Reference.
Calling HP-UX system and library routines
System calls provide low-level access to kernel-level resources, such as thewrite system routine.
or example, see “File handling” (page 120) for an example of a program that calls the write routine.
For information about system calls, see the HP-UX Reference.
HP-UX library routines provide many capabilities, such as getting system information and file stream
processing. Library routines are also discussed in the HP-UX Reference.
You can access many HP-UX system calls and library routines from HP Fortran programs using
theBSD 3F library, libU77.a. Another library provided with HP Fortran is the Basic Linear Algebra
Subroutine (BLAS) library, libblas.a. These subroutines perform low-level vector and matrix
operations, tuned for maximum performance. See “Additional HP Fortran libraries” (page 53) for
information about linking to these libraries. For detailed information about the both libraries, see
the HP Fortran Programmer's Reference.
Using HP-UX file I/O
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 stdioin 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 statement declares a variable for use as a stream pointer in HP Fortran:
INTEGER(4):: stream_ptr
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 ALIASdirective to pass it by value to stream I/O routines.
(For an example of how to use the ALIASdirective, see “File handling” (page 120).) All HP Fortran
directives are described in the HP Fortran 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 writeroutine, see “File handling” (page 120).
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
108 Writing HP-UX applications