Format codes specify either how data should be transferred or how input/output is handled.
The syntax of an IDL format code is:
[n]FC[+][-][width]
Where:
|
n
|
is an optional repeat count (1 £ n) specifying the number of times the format code should be processed. If n is not specified, a repeat count of one is used.
|
|
FC
|
is the format code. See Available Format Codes, below.
|
|
+
|
is an optional flag that specifies that positive numbers should be output with a "+" prefix. The "+" flag is only valid for numeric format codes. Normally, negative numbers are output with a "-" prefix and positive numbers have no sign prefix. Non-decimal numeric codes (B, O, and Z) allow the specification of the "+" flag, but ignore it.
|
|
-
|
is an optional flag that specifies that string or numeric values should be output with the text left-justified. Normally, output is right-justified.
|
|
width
|
is an optional width specification. Width specifications and default values are format-code specific, and are described in detail along with the format code.
See Padding and Natural Width Formatting, below, for additional information on how output values are formatted based on the width parameter.
|
The value being formatted may be shorter than the output width specified by the width parameter. When this happens, IDL will adjust either the contents of the output value or the width of the field, using the following mechanisms:
By default, if the value being formatted uses fewer characters than specified by the width parameter, IDL pads the value with whitespace characters on the left to create a string of the specified width. For example, the following IDL statement
PRINT, FORMAT='(I12)', 300
produces the following output:
bbbbbbbbb300
where b represents a space character.
For numeric format codes, if the first digit of the width parameter is a zero, IDL will pad the value with zeroes rather than blanks. For example:
PRINT, FORMAT='(I08)', 300
produces the following output:
00000300
When padding values with zeroes, note the following:
If the numeral zero is specified for the width parameter, IDL uses the "natural" width for the value. The value is read or output using a default format without any leading or trailing whitespace, in the style of the standard C library printf() function.
Using a value of zero for the width parameter is useful when reading tables of data in which individual elements may be of varying lengths. For example, if your data reside in tables of the following form:
26.01 92.555 344.2 101.0 6.123 99.845 23.723 200.02 141.93
setting the format to
FORMAT = '(3F0)'
ensures that the correct number of digits are read or output for each element.
IDL supports the following format codes:
For examples using different format codes, see: