Write a character string

Syntax: WRITE\TEXT file txtvar
Qualifiers: \APPEND
Examples: WRITE\TEXT FILE.DAT T
WRITE\TEXT\APPEND FILE.DAT T

The WRITE\TEXT command writes writes a character string to a file. If \APPEND is used, and if the output file already exists, the string will be appended onto the end of the file.

Example 1

The values of scalar variables can be written by using the RCHAR function and the append operator, //. For example:

 WRITE\TEXT FILE.EXT `The value of A is '//RCHAR(A)
 WRITE\TEXT FILE.EXT `The value of X['//RCHAR(J)//`] = '//RCHAR(X[J])
 

Example 2

Suppose you want to write a header line to a file and then write some data stored in vectors to that file. For example:

 WRITE\TEXT FILE.DAT `This is a header line'
 WRITE\APPEND FILE.DAT X Y Z
 

Suppose X is a vector, X = [ 1.1; 2.2; 3.3; 4.4 ], and you want to write the values of X to a file, with some text. For example:

 DO J = 1, LEN(X)
  WRITE\TEXT\APPEND FILE.DAT `X['//RCHAR(J)//`] = '//RCHAR(X[J])
 ENDDO
 

  Write a matrix