Open a specifiedfile for input/output:
CAUTION: When you use OPENW to create a new file under UNIX, if the file exists, it is truncated and its old contents destroyed. Under OpenVMS, a new file with the same name and a higher version number is created.
OPENU, unit, filename [, record_length]
OPENW, unit, filename [, record_length]
filename
SHELL
environment variable. However, it is faster not to use wildcards because PV-WAVE doesn't use the shell to expand filenames unless it has to. No wildcard characters are allowed under OpenVMS.
.DAT
extension. No such processing of filenames occurs under UNIX.
NOTE: Due to limitations in RMS, the length of records must always be an even number of bytes. Therefore, odd record lengths are automatically rounded up to the nearest even boundary.
Block
Files created in block mode can be accessed only in block mode. Block mode files are treated as an uninterpreted stream of bytes in a manner similar to UNIX stream files.
NOTE: With some controller/disk combinations, RMS does not allow transfer of an odd number of bytes.
.log
be the default file extension and open a new file named data
, you might enter the following when you open the file:
OPENW, 'data', Default='.log'
CAUTION: Delete will cause the file to be deleted even if it was opened for read-only access. In addition, once a file is opened with this keyword, there is no way to cancel its operation.
The OPEN procedures always return to the caller without generating an error message when Error is present. A nonzero error status indicates that an error occurred. The error message can then be found in the system variable !Err_String.
For example, statements similar to the following can be used to detect errors:
OPENR, 1, 'demo.dat', Error=err
IF (err NE 0) then PRINTF, -2, !Err_String
File extension is a relatively slow operation, and it is desirable to minimize the number of times it is done. In order to avoid the unacceptable performance that would result from extending a file a single block at a time, OpenVMS extends its size by a default number of blocks in an attempt to trade a small amount of wasted disk space for better performance.
OPENW, 1, 'data', /Fixed, 512
F77_Unformatted
Unformatted, variable-length record files produced by UNIX FORTRAN programs contain extra information along with the data in order to allow the data to be properly recovered. This is necessary because FORTRAN is based on record-oriented files, while UNIX files are simple byte streams that do not impose any record structure.
Get_Lun
GET_LUN, unit OPENR, unit, 'data.dat'
OPENR, unit, 'data.dat', /Get_Lun
Keyed
List
![]() ![]() | Causes the next page of text to be displayed. |
![]() ![]() | Causes the next line of text to be displayed. |
![]() ![]() | Suppresses all following output. |
![]() ![]() | Displays the list of available options at this point. |
text.dat
to the terminal:
OPENR, inunit, 'test.dat', /Get_Lun
OPENW, outunit, '/dev/tty', /Get_Lun, /More
line = '' & readf, inunit, line
while not eof(inunit) do begin
printf, outunit, line
readf, inunit, line
ENDWHILE FREE_LUN, inunit & FREE_LUN, outunit
SYS$PRINT
(the default system printer) when it is closed.Segmented
CAUTION: It is not a good idea to allow shared write access to files open in RMS block mode. In block mode, OpenVMS cannot perform the usual record locking which avoids file corruption. It is therefore possible for multiple writers to corrupt a block mode file. This same warning also applies to fixed-length-record disk files, which are also processed in block mode.
Submit
SYS$BATCH
(the default system batch queue) when it is closed.Truncate_On_Close
Truncate_On_Close has no effect if the Shared keyword is present, or if the file is open for read-only access.
Variable
Width
Using this keyword makes binary data portable across different machine architectures by reading and writing all data in a standard format. When a file is open for XDR access, the only I/O data transfer procedures that can be used with it are READU and WRITEU.
If you open an XDR file with OPENU, you must use the Append keyword in the OPENU call to move the file pointer to the end of the file. By default, when an existing XDR file is opened with OPENU, the I/O transfer is set for writing, and the file pointer is set to the beginning of the file.
head.img
file for reading. This file is in the subdirectory data
, under the main PV-WAVE distribution directory. The image is read from the file, and the file is closed.
OPENR, unit, FILEPATH('head.img', $
Subdir = 'data'), /Get_Lun
; Open head.img for reading.
ct = BYTARR(512, 512)
; Create a 256-by-256 byte array to hold the image.
READU, unit, ct
; Read the image.
FREE_LUN, unit
; Close head.img and free the file unit number associated with it.
TVSCL, ct
For background information, see Chapter 8, Working with Data Files, in the PV-WAVE Programmer's Guide.
For more information on XDR, see External Data Representation (XDR) Files in Chapter 8 of the PV-WAVE Programmer's Guide.