Tutorial > Reading Data into PV-WAVE > Lesson 2: Reading Unformatted Binary Data
  

Lesson 2: Reading Unformatted Binary Data
This example demonstrates how to read unformatted binary data from the data file, pv_wave.spd, which is a digitized speech sample of “PV-WAVE” spoken aloud. First, define the initial variables describing the data, and then open a dataset to display. This file is located in <RW_DIR>\wave\data, where <RW_DIR> is your installation directory.
To read the unformatted binary data, do the following in PV-WAVE:
1. Specify the size of the sample and store it in a variable called original:
sig_len = 7519
original = INTARR(sig_len)
2. Create string variable sig_file to contain the name and path to the data:
sig_file = !Data_Dir + 'pv_wave.spd'
Normally, binary data is not portable between different machine architectures because of the way different machines represent binary data. XDR (External Data Representation, developed by Sun Microsystems) converts between the machine’s internal and a standard external binary representation for data. XDR is supported to encourage data portability across machine architectures. The Xdr keyword is used to access XDR files. OPENW and OPENU normally open files for both input and output. However, XDR files can be open in only one direction at a time.
 
note
Reading binary XDR data into a PV-WAVE LONG variable on a 64-bit machine causes 8 bytes to be extracted from the XDR file. In order to read 4 byte values from a binary XDR file you must pass the READ routine a PV-WAVE INT32 variable.
3. Open the file and read the data into the variable named original:
OPENR, 1, sig_file, /Xdr
READU, 1, original
4. Display information about the file. Enter:
INFO, /Files 
This displays information about all open files, including the logical unit numberof each, filenames, and attributes such as read/write access.
5. Close the file:
CLOSE, 1
6. Verify that the file is closed by re-entering:
INFO, /Files
7. Display information about the variable. Enter:
INFO, original

Version 2017.1
Copyright © 2019, Rogue Wave Software, Inc. All Rights Reserved.