This command writes a string with a number of embedded numbers to the Output Window, or optionally writes the string and embedded numbers to the named file. The output string is not terminated with a newline unless the format string ends with a newline character. The newline character is '\n'. If present, keywords must be in the order shown, i.e., file followed by the file name followed by the optional append keyword. If the file keyword is present, it must be followed by a filename in quotes or by a String Variable containing a filename. The filename may be the complete path name or a relative path. A relative path will be relative to the current user directory (the directory containing the statistics101.jar file). If the append keyword is present along with the file keyword, the OUTPUT command will append the string to the named file, if it exists, or will create a file by that name and write the string to the file. The default behavior in the absence of the append keyword, is to create the file if it doesn't exist and write the string to it, or if the file already exists, to overwrite it with the string. If the file keyword is absent, append will be ignored. The argument(s), number, is a variable or a constant. Only the first element of any number argument will be used. The argument formatString contains zero or more format specifications. The formatString must be enclosed in double-quotes. There should be one format specification in the formatString for each number. If there are more numbers than format specifications, the extra numbers will be ignored. If there are fewer numbers than format specifications, the extra format specifications will be treated simply as text and sent to the output unchanged. The format specification can use any of the format codes (f, e, g, b, or c) that are valid for the WRITE command. There is one difference between the behavior of the format codes for OUTPUT from that of WRITE: When used for the OUTPUT command, the formats do not generate delimiters such as space, comma, or tab. Not automatically generating such delimiters gives you more control over the formatting. You put your formatting characters in the format string wherever you want them. Here is the list of special formatting characters you can use in the format string:
The general format specification is: %width[.precision[code]] where:
The codes may be entered in either upper or lower case. No distinction is made by Statistics101. |
The simplest OUTPUT command, with only a string argument, would be equivalent to the PRINT command except that the OUTPUT command does not automatically terminate with a newline. Therefore, multiple OUTPUT commands would print successively to the same line: OUTPUT "First output," OUTPUT " second output," OUTPUT " third output\n" 'This \n is a newline. The result is this: First output, second output, third output Here's an example embedding two constants into a single line: COPY 1,100 a STDEV a sd MEAN a avg OUTPUT "Standard Deviation is %5.2e and the Mean is %4\n" sd avg The above program produces this one line output: Standard Deviation is 2.9E01 and the Mean is 5E01 The following program produces the same result using two output commands: COPY 1,100 a STDEV a sd MEAN a avg OUTPUT "Standard Deviation is %5.2e" sd OUTPUT " and the Mean is %4\n" avg Result: Standard Deviation is 2.9E01 and the Mean is 5E01 The numbers are inserted into the format string, in order, replacing the format specifications. Here's an example showing the use of tabs to format the output: COPY 1,100 population SAMPLE 15 population sample1 SAMPLE 15 population sample2 SAMPLE 15 population sample3 MEAN population mean MEAN sample1 mean1 MEAN sample2 mean2 MEAN sample3 mean3 OUTPUT "Population mean: %3.2f\n" mean OUTPUT "Sample 1 mean:\t%3.2f\n" mean1 OUTPUT "Sample 2 mean:\t%3.2f\n" mean2 OUTPUT "Sample 3 mean:\t%3.2f\n" mean3 Result of one run: Population mean: 50.5 Sample 1 mean: 59 Sample 2 mean: 49.8 Sample 3 mean: 56.6 An example containing quotes: OUTPUT "He said, \"I can do it.\"" produces the following output: He said, "I can do it." |