The WRITE_CSV procedure writes data to a “comma-separated value” (comma-delimited) text file consisting of columns of data.

This routine writes CSV files consisting of one or more optional table header lines, followed by one optional column header line, followed by columnar data, with commas separating each field. Each row is a new record.

This routine is written in the IDL language. Its source code can be found in the file write_csv.pro in the lib subdirectory of the IDL distribution.

Syntax


WRITE_CSV, Filename, Data1 [, Data2,..., Data8] [, HEADER=variable] [, TABLE_HEADER=string array]

Arguments


Filename

A scalar string containing the full pathname of the CSV file to write.

Data1...Data8

The data values to be written out to the CSV file. The data arguments can have the following forms:

  • Data1 can be an IDL structure in which each field contains a vector of data that corresponds to a separate column in the output file. The vectors must all have the same number of elements, but can have different data types. If Data1 is an IDL structure, all other Data arguments are ignored.
  • Data1 can be a two-dimensional array in which each column in the array corresponds to a separate column in the output file. If Data1 is a two-dimensional array, all other Data arguments are ignored.
  • Data1...Data8 can be vectors, where each vector corresponds to a separate column in the output file. The vectors must all have the same number of elements, but can have different data types.

Keywords


HEADER

Set this keyword equal to a string array containing the column header names. The number of elements in HEADER must match the number of columns provided in Data1...Data8. If HEADER is not present, then no header row is written.

TABLE_HEADER

Set this keyword equal to an array of strings that will be inserted at the beginning of the CSV file, one string per line. Table header information is inserted before column header information specified by the HEADER keyword (if present).

Version History


7.1

Introduced

8.0

TABLE_HEADER keyword added

See Also


QUERY_ASCII, QUERY_CSV, READ_ASCII, READ_CSV