Reading Data from a File

Data files fall into two general categories: formatted files, which are usually human-readable ASCII files; and unformatted files, which are machine-readable binary files.

Binary files require less storage space than ASCII files and, for this reason, are often used to store large data sets. The disadvantage of binary files is that they are often not readily portable from one computer architecture to another without knowledge of the underlying data formats and bit ordering of the source architecture. (The XDR format enables you to overcome this problem, however.)

On the other hand, formatted files are almost always portable from one machine to another.

Opening Files using the OPEN* Functions

Work in PV-WAVE begins by opening a file with one of the following:

OPENR—Opens a file for reading only.

OPENW—Opens a file for reading and writing.

OPENU—Opens a file for updating.

When a file is opened, it is associated with a number called a Logical Unit Number, or LUN. All input and output in PV-WAVE is done referring to the LUN, not the file name. You can use the GET_LUN procedure to retrieve an unused logical unit number.

Reading Data using the READ* Functions

When reading data into PV-WAVE, files may contain either unformatted data in a binary, machine readable representation, or formatted data represented by a character format.

If you want to read unformatted data, use the READU procedure. With READU, the internal binary representation of the data is transferred directly between the file and memory with no data conversion taking place.

If you want to read formatted data, use the READF procedure. You can also use explicit FORTRAN-style formats. The PV-WAVE READ procedures are summarized below:

READU—Reads unformatted data from the specified LUN.

READF—Reads free and explicitly formatted data from the specified LUN.

READ—Reads free and explicitly formatted data from the standard input, usually the keyboard. (A LUN does not need to be specified for the READ procedure.)

Reading Data using the DC_READ_* Functions

These functions simplify the process of reading many kinds of files. They automate many of the steps required to read data by other methods:

opening the file

assigning it a logical unit number (LUN)

closing the file

These functions include the following:

DC_READ_FREE—Reads freely-formatted ASCII files. Furthermore, relieves you of the task of composing a format string that describes the organization of the data in the input file.

DC_READ_FIXED — Reads fixed-formatted ASCII data using a PV‑WAVE format that you specify.

DC_READ_8_BIT—Reads an 8-bit image file.

DC_READ_24_BIT—Reads a 24-bit image file.

1.Read and close the data file, using status as the value returned by DC_READ_FREE. Enter:

status = DC_READ_FREE(!Data_Dir + 'wd_pike_elev.dat', $
lat, lon, elev, depth, /Column)

2. Use the INFO command to verify that the new variables lat, lon, elev, and depth were created. This command also tells you about the size and data type of the arrays:

INFO