formatted and unformatted input
TRANSCRIPT
8/4/2019 Formatted and Unformatted Input
http://slidepdf.com/reader/full/formatted-and-unformatted-input 1/2
Formatted and Unformatted Input/Output
Unformatted Input/Output is the most basic form of input/output. Unformattedinput/output transfers the internal binary representation of the data directlybetween memory and the file. Formatted output converts the internal binaryrepresentation 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 internalform. Formatted I/O can be either "Free" format or "Explicit" format, as describedbelow.
Advantages and Disadvantages of Unformatted I/O
Unformatted input/output is the simplest and most efficient form of input/output. Itis usually the most compact way to store data. Unformatted input/output is theleast portable form of input/output. Unformatted data files can only be moved
easily to and from computers that share the same internal data representation. Itshould be noted that XDR (eXternal Data Representation) files, described inPortable Unformatted Input/Output, can be used to produce portable binary data.Unformatted input/output is not directly human readable, so you cannot type it outon a terminal screen or edit it with a text editor.
Advantages and Disadvantages of Formatted I/O
Formatted input/output is very portable. It is a simple process to move formatteddata files to various computers, even computers running different operatingsystems, as long as they all use the ASCII character set. (ASCII is the American
Standard Code for Information Interchange. It is the character set used by almostall current computers, with the notable exception of large IBM mainframes.)Formatted files are human readable and can be typed to the terminal screen oredited with a text editor.
However, formatted input/output is more computationally expensive thanunformatted input/output because of the need to convert between internal binarydata and ASCII text. Formatted data requires more space than unformatted torepresent the same information. Inaccuracies can result when converting databetween text and the internal representation.
Free Format I/O
With free format input/output, IDL uses default rules to format the data.
Advantages and Disadvantages of Free Format I/O
The user is free of the chore of deciding how the data should be formatted. Freeformat is extremely simple and easy to use. It provides the ability to handle themajority of formatted input/output needs with a minimum of effort. However, thedefault formats used are not always exactly what is required. In this case, explicit
formatting is necessary.
8/4/2019 Formatted and Unformatted Input
http://slidepdf.com/reader/full/formatted-and-unformatted-input 2/2
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 datawill be formatted. Formats are specified using a syntax that is similar to that usedin FORTRAN format statements. Scientists and engineers already familiar withFORTRAN will find IDL formats easy to write. Commonly used FORTRAN formatcodes are supported. In addition, IDL formats have been extended to providemany of the capabilities found in the scanf () and printf () functions commonlyfound in the C language runtime library.
However, there are some disadvantages to using Explicit I/O. Using explicitlyspecified formats requires the user to specify more detail—they are, therefore,more complicated to use than free format.
The type of input/output to use in a given situation is usually determined byconsidering the advantages and disadvantages of each method as they relate tothe problem to be solved. Also, when transferring data to or from other programsor systems, the type of input/output is determined by the application. The followingsuggestions are intended to give a rough idea of the issues involved, though thereare always exceptions:
Images and large data sets are usually stored and manipulated usingunformatted input/output in order to minimize processing overhead. TheIDL ASSOC function is often the natural way to access such data.
Data that need to be human readable should be written using formattedinput/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 XDRkeyword with the OPEN procedures. This is especially important if movingbetween 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/outputand about as easy as unformatted input/output, so it is often a good choicefor small files where there is no strong reason to prefer one method overanother.
Special well-known complex file formats are usually supported directly withspecial IDL routines (e.g. READ_JPEG for JPEG images).
See Using Explicitly Formatted Input/Output for more information and examples