Site Menu Project Specification Implementation Recommendations Reference Needs Updating Work in Progress Wastebasket Wiki Manual |
Universal Write FPROCEDURE WriteF( f : File; fmtStr : ARRAY OF CHAR; items : ARGLIST OF <Type> ); (* Writes the textual representation of one or more data items to output stream f. The output format is determined by fmtStr. *) BYTE outputA The syntax of a format string for byte output is as follows: ByteFmtStr : '"' noFormatting? numeralOptions? alignOptions? columnOptions? '"' ; noFormatting : 'N' ; numeralOptions : 'b' | 'x' | "d" ; alignOptions : alignment fieldWidth ; alignment : '<' | '>' ; fieldWidth : digit digit? digit? ; columnOptions : concatenator | columns ; concatenator : '~' ; columns : '!" digit? digit? ; The meaning of formatting options is as follows: byte1 := CAST (BYTE, 0); byte2 := CAST (BYTE, 123); ByteIO.WriteF(f, "N", byte1, byte2); => 00, 7B BYTE.WriteF( f, "b", byte1, byte2 ); => 0b0, 0b01111001 BYTE.WriteF( f, "x", byte1, byte2 ); => 0x0, 0x7B WORD and ADDRESS outputFor word and address output one The syntax of a format string for word and address output is as follows: wordOrAddrFmtStr : '"' noFormatting? numeralOptions? alignOptions? columnOptions? '"' ; noFormatting : 'N' ; numeralOptions : literalOptions | digit digit? digitGrouping? ; literalOptions : 'b' | 'x' | "d" ; digitGrouping : ( '_' | '.' | ':' ) digit digit? ; alignOptions : alignment fieldWidth ; alignment : '<' | '>' ; fieldWidth : digit digit? digit? ; columnOptions : concatenator | columns ; concatenator : '~' ; columns : '!" digit? digit? ; The meaning of formatting options is as follows: word1 := CAST (WORD, 0); word2 := CAST (WORD, 123); word3 := CAST (WORD, 65535); WordIO.Write3F( f, "N|\n", word1, word2, word3 ); (* first two in default array format *) WordIO.Write3F( f, "b|\n", word1, word2, word3 ); WordIO.Write3F( f, "x\n", word1, word2, word3 ); WordIO.Write3F( f, "d\n", word1, word2, word3 ); WordIO.Write3F( f, "_4\n", word1, word2, word3 ); => { 00000000, 0000007B, 0000FFFF } { 0b0, 0b00000000'00000000'00000000'01111011, 0b00000000'00000000'11111111'11111111 } 0x0, 0x0000007B, 0x0000FFFF 0, 123, 65535 0000 0000, 0000 007B, 0000 FFFF BOOLEAN outputFor boolean value output one The syntax of a format string for character based output is as follows: boolFmtStr : '"' noFormatting? boolOptions? alignOptions? columnOptions? '"' ; noFormatting : 'N' ; boolOptions : 'T' | 'Y' ; alignOptions : alignment fieldWidth ; alignment : '<' | '>' ; fieldWidth : digit digit? digit? ; columnOptions : concatenator | columns ; concatenator : '~' ; columns : '!" digit? digit? ; The meaning of formatting options is as follows: BooleanIO.WriteF( f, "T", TRUE, FALSE ); => TRUE, FALSE BooleanIO.WriteF( f, "Y", TRUE, FALSE ); => YES, NO BITSET outputFor bitset output one The syntax of a format string for bitset output is as follows: bitsetFmtStr : '"' noFormatting? bitsetOptions alignOptions? columnOptions? '"' ; noFormatting : 'N' ; bitsetOptions : setLiteral | groupedBinary? ; setLiteral : 'S' ; groupedBinary : ( '_' | '.' ) digit digit? ; alignOptions : alignment fieldWidth ; alignment : '<' | '>' ; fieldWidth : digit digit? digit? ; columnOptions : concatenator | columns ; concatenator : '~' ; columns : '!" digit? digit? ; The meaning of formatting options is as follows: BitsetIO.WriteF( f, "N", { } , { 2, 5, 7 } ); => { }, { 2, 5, 7 } BitsetIO.WriteF( f, "S", { } , { 2, 5, 7 } ); => { }, { 2, 5, 7 } BitsetIO.WriteF( f, "_4", { } , { 2, 5, 7 } ); (* assuming 8-bit bitset *) => { 0000 0000 }, { 0010 0101 } Character based data outputFor character based data output one The syntax of a format string for character based output is as follows: charFmtStr : '"' noFormatting? literalOption? quotingOptions? alignOptions? columnOptions? '"' ; noFormatting : 'N' ; literalOption : 'u' ; quotingOptions : 'Q' | 'D' ; alignOptions : alignment fieldWidth ; alignment : '<' | '>' ; fieldWidth : digit digit? digit? ; columnOptions : concatenator | columns ; concatenator : '~' ; columns : '!" digit? digit? ; The meaning of formatting options is as follows: CharIO.WriteF( f, "~", "A", "B", "C", "D", "E" ); => ABCDE CharIO.WriteF( f, "N", "A", "B", "C", "D", "E" ); => A, B, C, D, E CharIO.WriteF( f, "Q", "A", "B", "C", "D", "E" ); => 'A', 'B', 'C', 'D', 'E' CharIO.WriteF ("u", "A"); => 0u41 ARRAYOFCHAR.WriteF( f, "N", "foo", "bar", "baz" ); => foo, bar, baz ARRAYOFCHAR.WriteF( f, "Q", "foo", "bar", "baz" ); => 'foo', 'bar', 'baz' ARRAYOFCHAR.WriteF( f, "<16!5", "ALIAS","AND","ARGLIST","ARRAY","BEGIN" "BLUEPRINT","BY","CASE","CONST","COPY" "DEFINITION","DIV","DO","ELSE","ELSIF" "END","EXIT","FOR","FROM","GENLIB" "IF","IMPLEMENTATION","IMPORT","IN","INDETERMINATE" "LITERAL","LOOP","MOD","MODULE","NEW" "NONE","NOT","OF","OPAQUE","OR" "POINTER","PROCEDURE","RECORD","REFERENTIAL","RELEASE" "REPEAT","RETAIN","RETURN","SET","THEN" "TO","TYPE","UNTIL","VAR","WHILE" ); => ALIAS AND ARGLIST ARRAY BEGIN BLUEPRINT BY CASE CONST COPY DEFINITION DIV DO ELSE ELSIF END EXIT FOR FROM GENLIB IF IMPLEMENTATION IMPORT IN INDETERMINATE LITERAL LOOP MOD MODULE NEW NONE NOT OF OPAQUE OR POINTER PROCEDURE RECORD REFERENTIAL RELEASE REPEAT RETAIN RETURN SET THEN TO TYPE UNTIL VAR WHILE Whole number outputFor whole number output one The syntax of a format string for whole number output is as follows: wholeNumFmtStr : '"' noFormatting? numeralOptions alignOptions? columnOptions? '"' ; noFormatting : 'N' ; numeralOptions : base16Options | decimalOptions ; base16Options : ( 'b' | 'x' ) digit? digit? ; decimalOptions : sign? digitOptions? digitGrouping? suffix? ; digitOptions : fillChar? digit digit? ; sign : '+' | '-' ; fillChar : '*' | 'z' ; digitGrouping : '_' | ':' | ';' ; suffix : "'" printableCharacter+ "'" ; alignOptions : alignment fieldWidth ; alignment : '<' | '>' ; fieldWidth : digit digit? digit? ; columnOptions : concatenator | columns ; concatenator : '~' ; columns : '!" digit? digit? ; The meaning of formatting options is as follows: (* Base-16 literal format, no fill, no padding *) IntegerIO.WriteF( f, "x", 0, -123 ); => 0x0, 0xFFFFFF85 (* Base-16 literal format, no fill, no padding *) CardinalIO.WriteF( f, "x", 0, 123, 3456789 ); => 0x0, 0x7B, 0x34BF15 (* decimal format, force sign, no fill, no grouping no padding *) IntegerIO.WriteF( f, "+", 123, -3456789 ); => +123, -3456789 (* decimal format, force sign, no fill, show eight digits, no grouping, no padding *) IntegerIO.WriteF( f, "+8", 123, -3456789 ); => + 123, - 3456789 (* decimal format, force sign, zero fill, show eight digits, no grouping, no padding *) IntegerIO.WriteF( f, "+z8", 123, -3456789 ); => +00000123, -03456789 (* decimal format, force sign, asterisk fill, show eight digits, no grouping, no padding *) IntegerIO.WriteF( f, "+*8", 123, -3456789 ); => +*****123, -*3456789 (* decimal format, force sign, asterisk fill, show eight digits, digit grouping, no padding *) IntegerIO.WriteF( f, "+*8;", 123, -3456789 ); => +******123, -*3,456,789 (* decimal format, force sign, asterisk fill, show eight digits, digit grouping, padding to right align into a field of width 15 *) IntegerIO.WriteF( f, "+*8;>15", 123, -3456789 ); => +*******123, -*3,456,789 (* same as previous example but separate items with newline by specifying one column *) IntegerIO.WriteF( f, "+*8;>15!1", 123, -3456789 ); => +*******123 -*3,456,789 (* note that to end the entire output with a newline, one appends \n to the format string *) Real number outputFor real number output one The syntax of a format string for real number output is as follows: realNumFmtStr : '"' noFormatting? realOptions? numeralOptions alignOptions? columnOptions? '"' ; noFormatting : 'N' ; realOptions : 'S' digit? digit?| 'F' | 'E' | '$' numeralOptions : sign? intDigitOptions? fracDigitOptions? digitGrouping? suffix?; intDigitOptions : fillChar? digit digit? ; fracDigitOptions : ( '.' | ',' ) digit digit? ; sign : '+' | '-' ; fillChar : '*' | 'z' | 's' ; digitGrouping : '_' | ';' ; suffix : "'" printableCharacter+ "'" ; alignOptions : alignment fieldWidth ; alignment : '<' | '>' ; fieldWidth : digit digit? digit? ; columnOptions : concatenator | columns ; concatenator : '~' ; columns : '!" digit? digit? ; The meaning of formatting options is as follows: (* asterisk fill, fixed point eight integral digits, two fractional digits, single column comma digit grouping *) LongRealIO.WriteF( f, "F*8.2!1", 123.0, 123456789.0 ); =>*****123.00 123456789.00 (* asterisk fill, dollar format which is fixed point eight integral digits, two fractional digits, plus comma digit grouping, append " USD" *) LongRealIO.WriteF( f, "$*8;' USD'", 123.0, 123456789.0 ); => $*****123.00 USD, $123,456,789.00 USD (* zero fill, fixed point eight integral digits, three fractional digits, comma digit grouping *) LongRealIO.WriteF( f, "Fz8.3;", 0.0, 123.0, 123456789.0 ); => 00,000,000.000, 00,000,123.000, 123,456,789.000 (* asterisk fill, scientific notation eight integral digits, six fractional digits, space digit grouping *) LongRealIO.WriteF( f, "S*8.6_", 0.0, 123.0, 123456789.0 ); => *******0.000 000e+00, *******1.230 000e+002, *******1.234 568e+008 (* asterisk fill, engineering notation eight integral digits, two fractional digits, two columns, space digit grouping *) (* note no comma separators in column format *) LongRealIO.WriteF( f, "E*8.2_!2", 0.0, 123.0, 123456789.0 ); => *******0.00e+000*****123.00e+000 *****123.46e+006 (* space fill, modified floating point notation requiring six sig figs before decimal, adjusted exponent, eight integral digits, two fractional digits, space digit grouping *) (* note no comma separators in column format *) LongRealIO.WriteF( f, "S6s8.6_", 123.0, 123456789.0 ); => 123 000.000 000e-003, 123 456.789 000e+003 (* the space fill trigger "s" is only needed when necessary to separate other elements; it is the default if it can be skipped. *). Complex number outputFor complex number output one The syntax of a format string for complex number output is as follows: realNumFmtStr : '"' noFormatting? realOptions? complexOptions? numeralOptions alignOptions? columnOptions? '"' ; noFormatting : 'N' ; realOptions : 'S' digit? digit?| 'F' | 'E' complexOptions : 'i', | 'j', 'r' numeralOptions : sign? intDigitOptions? fracDigitOptions? digitGrouping? suffix?; intDigitOptions : fillChar? digit digit? ; fracDigitOptions : ( '.' | ',' ) digit digit? ; sign : '+' | '-' ; fillChar : '*' | 'z' ; digitGrouping : '_' | ';' ; suffix : "'" printableCharacter+ "'" ; alignOptions : alignment fieldWidth ; alignment : '<' | '>' ; fieldWidth : digit digit? digit? ; columnOptions : concatenator | columns ; concatenator : '~' ; columns : '!" digit? digit? ; The meaning of formatting options for each of the two real components is as follows: The meaning of the complex formatting options is as follows: Examples: COMPLEX.WriteF( f, "i", {3.5, 6.75} ); => 3.5+6.75i COMPLEX.WriteF( f, "j", {3.5, 6.75} ); => 3.5+6.75j COMPLEX.WriteF( f, "r", {3.5, 6.75} ); => ( 3.5, 6.75 ) COMPLEX.WriteF( f, <format-string>, {3.5, 6.75} ); => ( 3.500000000e+00, 6.750000000e+00 ) Output of non-character ARRAY typesFor non-character array output the The syntax of a format string for non-character array output is based on the syntax of format strings for the respective base type: nonChrArrayFmtStr : '"' baseTypeFmtOptions arrayOptions? '"' ; arrayOptions : '|' enclosureStart, separator, enclosureEnd | concatenator ; enclosureStart : '{' | '[' | '(' ; enclosureEnd : '}' | ']' | ')' ; enclosure : ',' | ';[' | ' )' ; concatenator : '~' ; The meaning of array specific formatting options is as follows: VAR x : ARRAY 2 OF REAL = { 1.23, 4.5 }; y : ARRAY 3 OF REAL = { 67.5, 78.0, 99.2 }; RealIO.Write2ArrayF( f, "F2.2|{,}\n", x, y ); RealIO.Write2ArrayF( f, "F2.2|[;]\n", x, y ); RealIO.Write2ArrayF( f, "F2.2|{ }\n", x, y ); RealIO.Write2ArrayF( f, "F2.2|~\n", x, y ); => { 1.23, 4.50 }, { 67.50, 78.00, 99.20 } [ 1.23; 4.50 ]; [ 67.50; 78.00; 99.20 ] { 1.23 4.50 } { 67.50 78.00 99.20 } 1.23, 4.50, 67.50, 78.00, 99.20 |