02.07.2013 Views

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>HP</strong> <strong>Fortran</strong> statements<br />

INQUIRE<br />

The INQUIRE statement in this example returns the following information about the file<br />

named my_file:<br />

The EXIST= specifier determines if the file is connected.<br />

The DIRECT= specifier determines if it is connected for direct access.<br />

The READWRITE= specifier determines if it can be read and written.<br />

LOGICAL :: exist<br />

CHARACTER(LEN=9) :: dir_acc, rw_sts<br />

INQUIRE (FILE='my_file', EXIST=exist, &<br />

DIRECT=dir_acc, READWRITE=rw_sts)<br />

Inquiry by unit<br />

The following INQUIRE statement returns the following information about the file connected<br />

to the unit in u_num:<br />

The OPENED= specifier determines if the file is connected to u_num.<br />

The NAMED= specifier determines if it is a named file or a scratch file.<br />

The NAME= specifier returns its name.<br />

LOGICAL :: opened, named<br />

INTEGER :: u_num<br />

CHARACTER(LEN=80) :: fname<br />

...<br />

INQUIRE (UNIT=u_num, NAMED=named, OPENED=opened, NAME=fname)<br />

Inquiry by output list<br />

When using the OPEN statement to create a direct-access file, you must specify the record<br />

length for the file with the RECL= specifier. Previous to <strong>Fortran</strong> 90, you had to resort to a<br />

nonportable strategy to determine record length. The <strong>Fortran</strong> 90 INQUIRE statement provides<br />

a portable solution: use the INQUIRE statement to inquire by output list, and specify the<br />

return value from the INQUIRE statement as the argument to the OPEN statement. The<br />

following is an example:<br />

INTEGER :: rec_len, ios<br />

INQUIRE (IOLENGTH=rec_len) x, y, i, j<br />

OPEN (UNIT=32, FILE='new_file', IOSTAT=ios, &<br />

ACCESS='DIRECT', RECL=rec_len)<br />

Related statements<br />

OPEN<br />

Chapter 10 349

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

Saved successfully!

Ooh no, something went wrong!