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.
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 PV‑WAVE Reference.
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.
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.
Fixed Format I/O
You provide an explicit format string to control the exact format for the input or output of the data. For a column-oriented data file, with data going into more than one variable, this implies that the values in the input or output file line up in well-defined, fixed-width columns.
Because the data values end up being restricted to certain locations on the line, this style of I/O is called fixed format I/O. The exact format of the character data is specified to the I/O procedure using a format string (via the Format keyword). If no format string is given, default formats for each type of data are applied.
For the routines shown in
Explicitly Formatted ASCII I/O Routines, you use the
Format keyword to provide the format string used to transfer the data. The first routines listed (PRINT, READ, PRINTF, READF) recognize FORTRAN-like formats; the DC routines accept either C or FORTRAN format strings.
note | The STRING function can also generate ASCII output that is sent to a string variable instead of a file. |
Free Format I/O
PV-WAVE uses default rules to format the data and uses delimiters to differentiate between different data values in the file. During input, the values in the file do not have to line up with one another because PV-WAVE is not imposing a rigid structure (format) on the file.
You do not have to decide how the data should be formatted because, in the case of input, PV-WAVE automatically looks for delimiters separating data values, and in the case of output, automatically places delimiters between adjacent data values. Because the values are “free” to be anywhere on the line, as long as they are clearly separated by delimiters, this style of I/O is called free format I/O.
For the routines listed in
Freely Formatted ASCII I/O Routines, you do not have to provide a format string to transfer the data. (Because the values are all separated with delimiters, no format string is needed.)
Other I/O Related Routines
In addition to performing I/O to an open file, there are several routines that provide other file management capabilities. These additional routines are shown in
Additional I/O Routines:
For additional information about DC_ERROR_MSG and DC_OPTIONS, refer to their descriptions in the PV‑WAVE Reference.
Version 2017.0
Copyright © 2017, Rogue Wave Software, Inc. All Rights Reserved.