Formatted and Unformatted Input
Formatted and Unformatted Input
Formatted and Unformatted Input
Unformatted Input/Output is the most basic form of input/output. Unformatted input/output transfers the internal binary representation of the data directly between memory and the file. Formatted output converts the internal binary representation of the data to ASCII characters which are written to the output file. Formatted input reads characters from the input file and converts them to internal form. Formatted I/O can be either "Free" format or "Explicit" format, as described below.
The user is free of the chore of deciding how the data should be formatted. Free format is extremely simple and easy to use. It provides the ability to handle the majority of formatted input/output needs with a minimum of effort. However, the default formats used are not always exactly what is required. In this case, explicit formatting is necessary.
See Using Free Format Input/Output for more information. Explicit Format I/O Explicit format I/O allows you to specify the exact format for input/output.
Advantages and Disadvantages of Explicit I/O
Explicit formatting allows a great deal of flexibility in specifying exactly how data will be formatted. Formats are specified using a syntax that is similar to that used in FORTRAN format statements. Scientists and engineers already familiar with FORTRAN will find IDL formats easy to write. Commonly used FORTRAN format codes are supported. In addition, IDL formats have been extended to provide many of the capabilities found in the scanf () and printf () functions commonly found in the C language runtime library. However, there are some disadvantages to using Explicit I/O. Using explicitly specified formats requires the user to specify more detailthey are, therefore, more complicated to use than free format. The type of input/output to use in a given situation is usually determined by considering the advantages and disadvantages of each method as they relate to the problem to be solved. Also, when transferring data to or from other programs or systems, the type of input/output is determined by the application. The following suggestions are intended to give a rough idea of the issues involved, though there are always exceptions:
Images and large data sets are usually stored and manipulated using unformatted input/output in order to minimize processing overhead. The IDL ASSOC function is often the natural way to access such data. Data that need to be human readable should be written using formatted input/output. Data that need to be portable should be written using formatted input/output. Another option is to use unformatted XDR files by specifying the XDR keyword with the OPEN procedures. This is especially important if moving between computers with markedly different internal binary data formats. XDR is discussed in Portable Unformatted Input/Output. Free format input/output is easier to use than explicitly formatted input/output and about as easy as unformatted input/output, so it is often a good choice for small files where there is no strong reason to prefer one method over another. Special well-known complex file formats are usually supported directly with special IDL routines (e.g. READ_JPEG for JPEG images).
See Using Explicitly Formatted Input/Output for more information and examples