SED navigation bar go to SED home page go to Dataplot home page go to NIST home page SED Home Page SED Staff SED Projects SED Products and Publications Search SED Pages
Dataplot Vol 1 Vol 2

WRITE

Name:
    WRITE
Type:
    Support Command
Purpose:
    Writes variables (vectors), parameters (scalars), functions (including strings), and matrices to the screen or to a file.
Syntax 1:
    WRITE <variable list>             <SUBSET/EXCEPT/FOR qualification>
    where <variable list> is a list of parameters, variables, strings, or matrices (separated by spaces);
    and where the <SUBSET/EXCEPT/FOR qualification> is optional.
Syntax 2:
    WRITE <file name> <variable list>             <SUBSET/EXCEPT/FOR qualification>
    where <file name> specifies the name of the output file;
                <variable list> is a list of parameters, variables, strings, or matrices (separated by spaces);
    and where the <SUBSET/EXCEPT/FOR qualification> is optional.

    If the file name does not contain a period, place a period (no spaces) at the end of the file name.

Syntax 3:
    WRITE VARIABLES ALL

    This syntax writes all currently defined variables (up to 25 variables may be printed). Although this command was implemented primarily for the Tcl/Tk graphical interface, it can also be used directly.

Syntax 4:
    WRITE <HTML/LATEX/RTF> <file name> <variable list>
                <SUBSET/EXCEPT/FOR qualification>
    where <file name> specifies the name of the output file;
                <HTML/LATEX/RTF> specifies that variables will be written HTML (HTML), Latex (LATEX), or Rich Text Format (RTF) format;
                <variable list> is a list of variables;
    and where the <SUBSET/EXCEPT/FOR qualification> is optional.

    This syntax is used to write variables in either HTML, Latex, or RTF format. It is restricted to variables only (i.e., no parameters, strings, or matrices). In addition, HTML format is limited to 15 variables and Latex and RTF format are limited to 7 variables. Latex and RTF have a fixed width pages which is why we currently restrict the number of columns.

    This option is useful when you want to display output for web pages or you want to import output into documents. The output from the WRITE comamnd will be generated as a "table".

Examples:
    WRITE OUT. Y1 Y2 Y3 X
    WRITE DATA.SAVE X Y PRED RES
    WRITE X Y PRED RES
Note:
    The following methods can be used to control the format of the output.

    1. The default is to print in exponential format.

    2. You can enter the command
        SET WRITE DECIMALS <value>

      where <value> is an integer in the range 0 to 12. This specifies the number of digits to the right of the decimal point (use 0 to print data as integers).

      The primary drawback of this option is that all variables will be written with the same value.

    3. To specify an explcit format, enter

        SET WRITE FORMAT <string>

      where <string> is a Fortran-like format statement. Currently, only F, E, and X format are supported (you can use Fxx.0 to print integer values, although the decimal point will still be printed).

      Although this provides a flexible option, one drawback is that it cannot be used for the option.

      Enter HELP WRITE FORMAT for details.

    4. You can specify the total width and the number of digits to the right of the decimal point by entering the command

        TABLE WIDTH <ntot> <nright>

      where <ntot> and <nright> are variables that contain the total number of digits and the number of digits to the right of the decimal point, respectively.

      That is row 1 of <ntot> and <nright> applies to the first variable printed, row 2 applies to the second variable printed, and so on. Up to 200 rows may be specified.

      A few comments on what may be specified (assume NTOT and NRIGHT are the values for a given row).

      1. A value of -99 indicates that the default value should be used (15 for NTOT, 7 for NRIGHT).

      2. If NRIGHT is 0, then an integer format will be used.

      3. If NRIGHT is a positive integer, then a Fortran F format will be used. For example, NTOT = 4 and NRIGHT = 2 will print something like "3.26".

      4. If NRIGHT is between -3 and and -20, a Fortran E format (i.e., scientific notation) will be used and NRIGHT specifies the number of digits in the mantissa.

      5. If NRIGHT is -2, then a G15.7 format will be used. With the G format, the Fortran compiler will decide, at runtime, whether an F format or an E format is more appropriate for a given number.

    The precedence order is:

    1. First check to see if a SET WRITE FORMAT command was given (this step will be skipped if writing HTML, Latex, or RTF format).

    2. Next check to see if a TABLE WIDTH option was given. This option does apply to HTML, Latex, and RTF output.

    3. Next check to see if a SET WRITE DECIMALS option was given.

    4. If none of the above options were given, use the default format (i.e., scientific notation).
Note:
    By default, Dataplot will open the output file before performing the WRITE and then close the output file after performing the WRITE. This means that the output file will contain the contents of a single WRITE command (and the content will start in row 1 of the output file). If the file already exists (before the WRITE command) it is overwritten.

    However, sometimes you may want to append the output of several WRITE commands to the same output file.

    The SET WRITE REWIND OFF command suppresses the automatic closing of the file after the WRITE command. So a typical sequence would be something like

      SET WRITE REWIND OFF
      WRITE FILE.OUT ....
      WRITE FILE.OUT ....
      WRITE FILE.OUT ....
      SET WRITE REWIND ON
      WRITE FILE.OUT " "

    We specify the final write (just a blank line) after the SET WRITE REWIND command in order to insure that the ouput file is closed.

    Note that Dataplot currently only uses a single unit number for the WRITE command. This means that if you use the SET WRITE REWIND OFF command, you should write to the same file until the SET WRITE REWIND comamnd has been entered and the current file has been closed (i.e., the final WRITE after the SET WRITE REWIND ON command). If you try to write to multiple output files after a SET WRITE REWIND OFF, the results may be unpredictable.

Note:
    DATAPLOT writes to an ASCII text file. With one exception, no method of writing binary files is currently supported.

    The one exception is that you can use the command

      SET WRITE FORMAT UNFORMATTED

    to write variables in an unformatted Fortran file. Note that this is not a portable format. Its primary use is to speed up the read time for large files that will be read many times on the same system.

    It is not appropriate for archiving data since Fortran unformatted files are compiler dependent.

Note:
    The WRITE command supports the "TO" syntax. For example,

      WRITE FILE.OUT X1 X2 Y1 TO Y8 Y15

    The "Y1 TO Y8" will write variables Y1, Y2, Y3, Y4, Y5, Y6, Y7, and Y8.

Note:
    When writing variables, you can specify a title for the output by entering the command

      SET TABLE TITLE <string>

    You can also specify whether rule lines are drawn above and below the variable names in the output by entering the command

      SET TABLE BORDER <ON/OFF>

    The default is ON.

    If the VARIABLE LABEL command has been used to define labels for the variables, these will be used instead of the variable names in the header line. These variable labels will be truncated if they are longer than the width of the field (variable labels can be 24 characters long while fields in the WRITE command are ofter set to 15 or less).

    If you want to suppress the variable names, enter the command

      SET TABLE HEADER OFF

    To restore the default of printing the variable names, enter

      SET TABLE HEADER ON
Note:
    Literal text can be written by enclosing it in double quotes. For example,

      WRITE "Enter the value for X"
Note:
    DATAPLOT has no restrictions on the file name other than it be a valid file name on the local operating system and that it contain a period "." in the file name itself or as a trailing character. DATAPLOT strips off trailing periods on those systems where it is appropriate to do so. On systems where trailing periods can be a valid file name (e.g., Unix), DATAPLOT opens the file with the trailing period.
Note:
    File names are case sensitive on Unix file systems. For Unix, DATAPLOT opens the file as given. All other currently supported systems are not case sensitive regarding file names.

    As a further caution for Unix hosts, certain expansion characters (specifically ~ to refer to your home directory) are interperted by the shell and are not recognized by the Fortran compiler. These expansion characters are interperted as literal characters and do not yield the intended file name.

Note:
    Writing character variables, row labels, and group labels is not currently (4/2009) supported. We anticipate adding this in a future release.
Default:
    None
Synonyms:
    PRINT is a synonym for WRITE.
    WRITE ALL VARIABLES is a synonym for WRITE VARIABLES ALL.
Related Commands:
    SET WRITE FORMAT = Define a Fortran like format for writing data.
    SET WRITE DECIMALS = Specify the number of digits to the right of the decimal point when printing numbers.
    SET WRITE REWIND = Specify if the output file is rewound before writing.
    READ = Read variables, parameters, strings, and matrices from a file.
Applications:
    Data Output
Implementation Date:
    Pre-1987
    1997/12: Implemented Syntax 3.
    2003/9: Support for HTML and Latex output.
    2009/4: Support for RTF output.
    2009/4: Maximum number of variables for the WRITE command increased to 1024.
Program:
     
    LET Y1 = NORMAL RANDOM NUMBERS FOR I = 1 1 100
    LET Y2 = EXPONENTIAL RANDOM NUMBERS FOR I = 1 1 100
    LET Y3 = UNIFORM RANDOM NUMBERS FOR I = 1 1 100
    WRITE RANDOM.DAT Y1 Y2 Y3
        

Privacy Policy/Security Notice
Disclaimer | FOIA

NIST is an agency of the U.S. Commerce Department.

Date created: 4/27/2009
Last updated: 10/29/2015

Please email comments on this WWW page to alan.heckert@nist.gov.