Types of Output

PV-WAVE divides I/O into two categories. Comparison of Binary and Human-Readable Input/Output summarizes these categories and includes a brief discussion of advantages and disadvantages of each.

 

Comparison of Binary and Human-Readable Input/Output

Category

Advantages

Disadvantages

Binary I/O

Binary I/O is the simplest and most efficient form of I/O.

Binary data is more compact than ASCII data.

Binary data is not always portable. Binary data files can only be moved easily to and from computers that share the same internal data representation.

Binary data is not directly human readable, so you can’t type it to a workstation’s screen or edit it with a text editor.

ASCII I/O

 

ASCII data is very portable. It is easy to move ASCII data files to various computers, even computers running different operating systems, as long as they all use the ASCII character set.

ASCII data can be edited with a text editor or typed to the workstation’s screen because it uses a human readable format.

ASCII I/O is slower than binary I/O because of the need to convert between the internal binary representation and the equivalent ASCII characters.

ASCII data requires more space than binary data to store the same information.

Each Type of I/O has Pros and Cons

The type of I/O you use is determined by considering the advantages and disadvantages of each method. Also, when transferring data to or from other programs or systems, the type of I/O is determined by the application. The following suggestions are intended to provide an idea of the issues involved, although there are always exceptions:

Data that needs to be human readable should be written using a human-readable character set. Two character sets are ASCII and EBCDIC; PV-WAVE assumes that you are using ASCII.

Images stored in TIFF format can be transferred using the IMAGE_READ and IMAGE_WRITE functions. Images and large data sets are usually stored and manipulated using binary I/O in order to minimize processing overhead. The ASSOC function is often the natural way to access such data, and thus is an important function to understand.

Device Independent Bitmap (DIB) images can be transferred with DC_READ_DIB and DC_WRITE_DIB functions. Other images, either 8-bit or 24-bit, are transferred with the DC_READ_*_BIT and DC_WRITE_*_BIT functions, where the * represents either an 8 or a 24, depending on the type of image data that you have.

Data that needs to be portable should be written using the ASCII character set. Another option is to use XDR (eXternal Data Representation) binary files by specifying the Xdr keyword with the OPEN procedures. This is especially important if you intend to exchange data between computers with different, or unknown internal binary data formats.

For ASCII files, freely formatted I/O is easier to use than explicitly formatted I/O, and is almost as easy as binary I/O, so it is often a good choice for small files.

The easiest routines to use for the transfer of both images and formatted ASCII data are the DC_READ and DC_WRITE routines. They are easy to use because they automatically handle many aspects of data transfer, such as opening and closing the data file.

Functions for Simplified Data Connection

PV-WAVE includes a group of I/O functions that begin with the two letters “DC”; this group of functions has been provided to simplify the process of getting your data in to and out of PV-WAVE. This group of I/O functions does not replace the READ, WRITE, and PRINT commands, but does provide an easy-to-understand alternative for most I/O situations.

 

Note

The DC_* routines that import and export ASCII data do not support the transfer of data into or from structures. An exception to this is the !DT, or date/time, structure. It is possible to transfer date/time data using DC_* routines.

The functions DC_WRITE_FREE and DC_WRITE_FIXED are equally well-suited for writing column-oriented ASCII data files.

The DC functions are easy to use because they automatically handle many aspects of data transfer, such as opening and closing the data file. Another advantage of the DC I/O commands is that they recognize C-style format strings, even though all other PV-WAVE I/O routines recognize only FORTRAN-style format strings.

 

Note

By default, DC_WRITE_FREE generates CSV (Comma Separated Value) ASCII data files, and the corresponding function, DC_READ_FREE, easily reads CSV files.

For specific information about any of the DC routines, refer to the (Undefined variable: pvwave.waveur).

Binary I/O Routines

Binary I/O transfers the internal binary representation of the data directly between memory and the file without any data conversion. Use it for transferring images or large data sets that require higher efficiency. Routines for Binary Input/Output shows the routines for binary I/O.

 

Routines for Binary Input/Output

Function

Description

READU

Read binary data from the specified file unit.

WRITEU

Write binary data to the specified file unit.

DC_WRITE_8_BIT
DC_READ_8_BIT

Write (or read) binary 8-bit data to (or from) a file without having to explicitly choose a LUN.

DC_WRITE_24_BIT
DC_READ_24_BIT

Write (or read) binary 24-bit data to (or from) a file without having to explicitly choose a LUN.

ASSOC

Map an array definition to a data file, providing efficient and convenient direct access to binary data.

GET_KBRD

Read single characters from the keyboard.

ASCII I/O Routines

ASCII data is useful for storing data that needs to be human readable or easily portable. ASCII I/O works in the following manner:

Input—ASCII characters are read from the input file and converted to an internal form.

Output—The internal binary representation of the data is converted to ASCII characters that are then written to the output file.

PV-WAVE provides a number of routines for transferring ASCII data.

Choosing Free or Fixed (Explicitly Formatted) ASCII I/O

ASCII I/O is subdivided further into two categories; the two categories are compared in the following sections.