本文共 4583 字,大约阅读时间需要 15 分钟。
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 nis not specified, a repeat count of one is used. |
FC | is the format code. See , 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 , 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
, 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:
, 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:
Format Code | Description |
| Transfers character values |
| Terminates processing |
| Suppresses newlines in output |
| Transfer floating-point values |
| Transfer integer values |
| Returns the number of characters that remain to be transferred during a read operation |
| Output string values directly |
| Specifies the absolute position within a record |
| Moves the position with a record to the left |
| Move the position within a record to the right |
| Transfers calendar data |
| Provides an alternative syntax for specifying the format of an output string |
For examples using different format codes, see:
The following table shows the results of the application of various format codes to given data values. Note that normally, the case of the format code is ignored by IDL. However, the case of the E and G format codes determines the case used to output the exponent in scientific notation.
Format | Internal Value | Formatted Output |
F | 100.0 | bbbb100.0000000 |
F | 100.0D | bbbbb100.0000000000000000 |
F10.0 | 100.0 | bbbbbb100. |
F10.1 | 100.0 | bbbbb100.0 |
F10.4 | 100.0 | bb100.0000 |
F2.1 | 100.0 | ** |
e11.4 | 100.0 | b1.0000e+02 1.0000e+002 (Windows) Note that “e10.4” displays “**********” under Windows because the extra “0” added after the “e” makes the string longer than 10 characters. |
E11.4 | 100.0 | b1.0000E+02 1.0000E+002 (Windows) |
g10.4 | 100.0 | bbbbb100.0 |
g10.4 | 10000000.0 | b1.000e+07 1.000e+007 (Windows) |
G10.4 | 10000000.0 | b1.000E+07 1.000E+007 (Windows) |
转载地址:http://atiqb.baihongyu.com/