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 The name of the file to be opened. The following differences exist between the UNIX and OpenVMS versions of PV-WAVE regarding wildcard characters and file extensions:
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 (OpenVMS only) If present and nonzero, specifies that the file should be processed using RMS block mode. In this mode, most RMS processing is bypassed and PV-WAVE reads and writes to the file in disk block units. Such files can be accessed only via unformatted I/O commands.
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 (UNIX only) If present and nonzero, specifies that PV-WAVE is to read and write extra information in the same manner as F77. This allows data to be processed by both FORTRAN and PV-WAVE.
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 If present and nonzero, calls the GET_LUN procedure to set the value of unit before the file is opened. Thus, the two statements:
GET_LUN, unit OPENR, unit, 'data.dat'
OPENR, unit, 'data.dat', /Get_Lun
Keyed (OpenVMS only) Specifies that the file has indexed organization.
List (OpenVMS only) Specifies that carriage return carriage control will be used when you create a new file. If no other carriage control keyword is specified, List is the default.
Space | Causes the next page of text to be displayed. |
Return | Causes the next line of text to be displayed. |
Q | Suppresses all following output. |
H | 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
Print (OpenVMS only) If present, sends the file to
SYS$PRINT
(the default system printer) when it is closed.Segmented (OpenVMS only) Specifies that the file has OpenVMS FORTRAN-style segmented records. Segmented records allow logical records to exist with record sizes that exceed the maximum possible physical record sizes supported by OpenVMS. Segmented record files are useful primarily for passing data between FORTRAN and PV-WAVE programs.
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 (OpenVMS only) If present, specifies that the file will be submitted to
SYS$BATCH
(the default system batch queue) when it is closed.Truncate_On_Close (OpenVMS only) If present, causes any unused disk space allocated to the file to be freed when the file is closed. This keyword can be used to get rid of excess allocations caused by the Extendsize and Initialsize keywords.
Truncate_On_Close has no effect if the Shared keyword is present, or if the file is open for read-only access.
Variable (OpenVMS only) Specifies that the file has variable-length records. If the record_size parameter is present, this keyword specifies the maximum record size. Otherwise, the only limit is that imposed by RMS (32,767 bytes). If no file organization is specified, variable-length records are the default.
Width Specifies the desired width for output. If this keyword is not present, PV-WAVE uses the following rules to determine where to break lines:
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.