Write File

Writes data to an open file specified by refnum. Writing begins at a location specified by pos mode and pos offset for byte stream files and at the end of the file for datalog files. data, header, and the format of the specified file determine the amount of data written.

convert eol determines whether the function converts the end of line markers it reads into LabVIEW end of line markers. You can wire convert eol only if data is a string. The system-specific end of line marker is a carriage return followed by a line feed on Windows, a carriage return on Macintosh, and a line feed on UNIX. The LabVIEW end of line marker is a line feed.

If convert eol is TRUE, the function converts all end of line markers it encounters into line feeds. If convert eol is FALSE (default), the function does not convert the end of line markers it reads.

If header is TRUE, LabVIEW ignores convert eol.

header can be wired only if the top-level data type of data has variable length, that is if data is a string or an array. If the top-level data type of data is a string or an array, this function can write a header to the file that specifies the size of the data. Later, if you want to read the string or array back as a single object, set header to TRUE.

If header is TRUE, this function writes the top-level data type of data with a header specifying its size. header must be TRUE to write out dynamic structures. If header is FALSE (default), this function writes the top-level data type of data without a header. LabVIEW always writes a variable-length data type below the top-level (that is, contained in the top-level data type) with a header specifying its size.

The header that LabVIEW generates is in big endian form. If you need to change the endian form of the file, set header to FALSE and create the header before you write data to the file. Refer to the LabVIEW Data Storage Application Note for more information about endian forms.

refnum is the file refnum associated with the file to which you want to write. If refnum is a byte stream file refnum, the Write File function writes to a location specified by pos mode and pos offset in the byte stream file specified by refnum. If the top-level data type of data is of variable length, that is a string or an array, the function can write a header to the file that specifies the size of the data. LabVIEW sets the file mark to the byte following the last byte written.

If refnum is a datalog file refnum, the Write File function writes data as records to the datalog file specified by refnum. You can only append data to datalog files, so writing always starts at the end of the datalog file. Therefore, LabVIEW sets the file mark to the record following the last record written and you do not need to wire the convert eol, header, pos mode, and pos offset parameters for datalog files.

pos mode, together with pos offset, specifies where the read or write operation begins. If the computed location does not exist in the file, for example, pos mode = 0 and pos offset = –10, the file mark does not move, no data is read or written, and the function returns an error.

If you wire pos offset, pos mode defaults to 0, and the offset is relative to the beginning of the file. If you do not wire pos offset it defaults to 0, pos mode defaults to 2, and the operation starts at the current file mark. Do not wire these inputs if you want to read or write the data following the most recently read or written data.

0Start—The operation begins at the beginning of the file plus pos offset.
1End—The operation begins at the end of the file plus pos offset.
2Current—The operation begins at the current location of the file mark plus pos offset.
pos offset specifies how far from the location specified by pos mode to start reading or writing. You express pos offset in units of bytes. The default is 0.

Do not wire pos mode and pos offset if you want to read the data following the most recently read or written data.

error in describes error conditions that occur before this VI or function runs. The default is no error. If an error occurred before this VI or function runs, the VI or function passes the error in value to error out. This VI or function runs normally only if no error occurs before this VI or function runs. If an error occurs while this VI or function runs, it runs normally and sets its own error status in error out. Use the Simple Error Handler or General Error Handler VIs to display the description of the error code. Use error in and error out to check errors and to specify execution order by wiring error out from one node to error in of the next node.
status is TRUE (X) if an error occurred before this VI or function ran or FALSE (checkmark) to indicate a warning or that no error occurred before this VI or function ran. The default is FALSE.
code is the error or warning code. The default is 0. If status is TRUE, code is a non-zero error code. If status is FALSE, code is 0 or a warning code.
source describes the origin of the error or warning and is, in most cases, the name of the VI or function that produced the error or warning. The default is an empty string.
data contains the data to write to the file and can be any data type. To perform character-oriented I/O, wire a string to data and do not wire header, because its default is FALSE. The VI writes the characters of data in sequence without any header information.

If refnum is a datalog file refnum, data must be either a data type that matches the data type specified when you open or create the file or an array of such data types. In the former case, this function writes data as a single record in the datalog file. If necessary, the function coerces numeric data to the representation of the data type of this parameter. In the latter case, this function writes each element of data as a separate record in the datalog file in row-major order.

dup refnum returns refnum unedited.
offset indicates the new location of the current file mark relative to the beginning of the file. offset is expressed in the same terms as pos offset, that is records for datalog files and bytes for byte stream files.
error out contains error information. If error in indicates that an error occurred before this VI or function ran, error out contains the same error information. Otherwise, it describes the error status that this VI or function produces. Right-click the error out indicator on the front panel and select Explain Error from the shortcut menu for more information about the error.
status is TRUE (X) if an error occurred or FALSE (checkmark) to indicate a warning or that no error occurred.
code is the error or warning code. If status is TRUE, code is a non-zero error code. If status is FALSE, code is 0 or a warning code.
source describes the origin of the error or warning and is, in most cases, the name of the VI or function that produced the error or warning.