Readsinput into variables:
READF, unit, var1, ... , varn
READU, unit, var1, ... , varn
vari The named variables to receive the input.
If the Format keyword is not present, PV-WAVE uses its default rules for formatting the output. These rules are described in Free Format Output in Chapter 8 of the PV-WAVE Programmer's Guide.
READU Procedure For nonstring variables, the number of bytes required for vari is input. For string variables, PV-WAVE reads exactly the number of bytes contained in the existing string.
b = ' '
Define a variable with string type.
READ, 'Enter a string: ', b
Enter a string: This is a string.
Read a string from the terminal.
PRINT, b
This is a string.
Display the contents of b.
readex.dat
is then opened for writing, and the integers in nums are written to the file using PRINTF. The file is then closed. The Format keyword is used with PRINTF to specify the format of the integers in the file. The readex.dat
file is then opened for reading, and the integers are read into a three-element integer array using READF with the Format keyword. The file is then closed and the values that were read from readex.dat
are displayed.
nums = INTARR(3)
Create a three-element integer array.
READ, 'Enter 3 integers: ', nums
Enter 3 integers: 3 5 7
Read three integers from the standard input stream.
PRINT, nums
3 5 7
OPENW, unit, 'readex.dat', /Get_Lun
Open the readex.dat file for writing.
PRINTF, unit, nums, Format = '(3i1)'
Write the integers to the file using a specified format.
FREE_LUN, unit
Close the file and free the file unit number.
OPENR, unit, 'readex.dat', /Get_Lun
Open the readex.dat file for reading.
ints = INTARR(3)
Create a new three-element integer array.
READF, unit, ints, Format = '(3i1)'
Read the three integers from the readex.dat file using the same
; specified format as when they were written.
PRINT, ints
3 5 7
Display the integers read from the file.
FREE_LUN, unit
Close the file and free the file unit number.
whirlpool.img
, which is contained in the subdirectory data
under the main PV-WAVE distribution directory.
OPENR, unit, FILEPATH('whirlpool.img', $
Subdir = 'data'), /Get_Lun
Open the file galaxy.dat for reading.
a = BYTARR(512, 512)
Create a byte array large enough to hold the galaxy image.
READU, unit, a
Read the image data.
FREE_LUN, unit
Close the file and free the file unit number.
For more information and examples, see READU and WRITEU in Chapter 8 of the PV-WAVE Programmer's Guide.
For more information on format specification codes, see the PV-WAVE Programmer's Guide.