HP Fortran Programmer's Reference (September 2007)

I/O and file handling
File access methods
Chapter 8 213
Namelist-directed I/O
Namelist-directed I/O enables you to transfer a group of variables by referencing the name of
the group, using the NML= specifier in the data transfer statement. The NAMELIST statement
specifies the variables in the group and gives the group a name.
Like list-directed I/O, namelist-directed I/O does not use a format specification when
formatting data but uses default formats, as determined by the data types.
In the following example, the NAMELIST statement defines the group name_group, which
consists of the variables i, j, and c. The READ statement reads a record from the file connected
to unit number 27 into name_group. The PRINT statement then writes the data from the
variables in name_group to standard output. (As an extension, HP Fortran allows this use of
the PRINT statement in namelist I/O.)
INTEGER :: i, j
CHARACTER(LEN=10) :: c
NAMELIST /name_group/ i, j, c
...
READ (UNIT=27,NML=name_group)
PRINT name_group
Each namelist-directed output record begins with a blank character to provide for ASA
carriage control if the records are to be printed (see “ASA carriage control” on page 227).
Namelist-directed I/O can be performed only on formatted, sequential external files.
The following program illustrates namelist-directed I/O:
PROGRAM namelist
INTEGER, DIMENSION(4) :: ivar
CHARACTER(LEN=3), DIMENSION(3,2) :: cvar
LOGICAL :: lvar
REAL :: rvar
NAMELIST /nl/ ivar, cvar, lvar, rvar
READ (*,nl)
PRINT nl
END PROGRAM namelist
If the input data is:
&nl
ivar = 4,3,2,1
lvar=toodles
cvar=,,'QRS',2*,2*'XXX'
rvar=5.75E25, cvar(3,2)(1:2)='AB'
/
then the output will be: