MATWRITECSV

MATWRITECSV

Top  Previous  Next

 

The MATWRITECSV statement builds a CSV form line of text from successive elements of a matrix and writes this to a file opened for sequential processing.

 

 

Format

 

MATWRITECSV mat {ENCODING name} TO file.var {ON ERROR statement(s)}

{THEN statement(s)}

{ELSE statement(s)}

 

where

 

matis the matrix from which data is to be taken.

 

nameevaluates to the name of a character encoding.

 

file.varis the file variable associated with the file previously opened with OPENSEQ.

 

statement(s)are statements to be executed depending on the outcome of the operation.

 

 

The keyword TO may be replaced by ON. At least one of the THEN and ELSE clauses must be present.

 

 

The optional ENCODING clause sets the character encoding to be used, overriding any encoding set in the VOC F-type record or when the file was opened. A null string as the encoding name is equivalent to not having the ENCODING clause at all. To disable the default encoding, the encoding name should be specified as "NULL".

 

The data in mat is transformed to comma separated variable form and written to the file opened to file.var. The THEN clause is executed if the write is successful.

 

The ELSE clause is executed if the MATWRITESEQ operation fails. On ECS mode systems, STATUS() value ER$ECS.DATA will be returned if data containing ECS characters is written to a file with no encoding. The write will have completed but only the low order byte of each character will have been written.

 

If a fatal error occurs, the ON ERROR clause is executed. The STATUS() function can be used to establish the cause of the error. If no ON ERROR clause is present, a fatal error causes an abort.

 

The FILEINFO() function can be used with key FL$LINE to determine the field number that will be written by the next WRITESEQ. This information is not valid if the SEEK, READBLK or WRITEBLK statements have been used.

 

If the record was opened with the SHARED option of OPENSEQ, the data will be appended to any existing record content.

 

 

Example

 

OPENSEQ 'LOG', DATE() APPEND TO LOG.F ELSE

  IF STATUS() THEN STOP "Cannot open log file"

END

MATWRITECSV LOGDATA TO LOG.F ELSE

  ABORT "Error " : STATUS() : " writing log data"

END

CLOSESEQ LOG.F

 

This program fragment opens a sequential file for appending and writes a line of text containing data from matrix LOGDATA in CSV format.