Write - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


FileTools[Binary]

  

Write

  

write binary data to a file

  

WriteFile

  

write binary data to a file and close the file

 

Calling Sequence

Parameters

Description

Examples

Compatibility

Calling Sequence

Write(file, rtab, opts, ...)

Write(file, type, data, opts, ...)

WriteFile(file, rtab, opt1, opts, ...)

WriteFile(file, type, data, opts, ...)

Parameters

file

-

file descriptor or filename

type

-

type of data to write

data

-

set or list

rtab

-

rtable

opts, ...

-

(optional) arguments of the form 'name' or 'name'=value

Description

• 

The Write(file, rtab) and WriteFile(file, rtab) commands write the elements from the rtable rtab to file.  The type used in the file encoding is automatically determined from rtab.  Therefore, the data type of rtab must be supported by Write.

• 

The Write(file, type, data) and WriteFile(file, type, data) commands write the elements from data to file in type format.

• 

The following are valid values for type: integer[1], integer[2], integer[4], integer[8], float[4], float[8].  These types represent hardware data types. The integer[n] is an n byte integer, and float[n] is an n byte float.

• 

There are two optional arguments for the Write command: byteorder and notrunc.

• 

The byteorder argument specifies the order in which bytes are written for multi-byte data types.  The byteorder function can have one of four values: big, little, network, and native.

  

- big and little specify big endian and little endian, respectively

  

- network specifies network ordering (big endian)

  

- native uses the byte ordering of the current platform

  

If byteorder is not specified, it defaults to network.

• 

The default byte order for Write and Read is a system independent format.  This means that if the default is used, then binary files can be exchanged across platforms without conversion.

• 

The notrunc argument controls the behavior when an integer value does not fit in the given hardware type.  By default, the integer is truncated and written as the hardware value nearest to the requested value.  If notrunc is specified, an exception is raised and the write will be incomplete.  The notrunc argument has no effect when writing floating-point values.  Floats with large positive exponents are represented as positive or negative floating-point infinity, (see Float).  Those with large negative exponents are represented by floating-point zero.

• 

If file is the name of a file that has not been opened, Maple attempts to open the file before attempting to read the data.

• 

An error is raised if file is not a valid descriptor or if it is the name of a file that does not exist.

• 

WriteFile behaves identically to Write, except that if the file is not open prior to calling WriteFile, it will be closed before returning.  Therefore, WriteFile offers a convenient syntax to write the data to disk with a single command, without the need to open or close the file explicitly.

Examples

num12563+22562+3256+4

num16909060

(1)

num242563+32562+2256+1

num267305985

(2)

FileToolsBinaryWritetestfile,integer4,num

4

(3)

FileToolsBinaryClosetestfile:

FileToolsBinaryReadtestfile,integer4

16909060

(4)

FileToolsBinaryClosetestfile:

FileToolsBinaryReadtestfile,integer4,byteorder=little

67305985

(5)

FileToolsRemovetestfile

FileToolsBinaryWriteFiletestfile,integer4,num

4

(6)

FileToolsBinaryReadtestfile,integer4

16909060

(7)

FileToolsRemovetestfile

Compatibility

• 

The FileTools[Binary][WriteFile] command was introduced in Maple 18.

• 

For more information on Maple 18 changes, see Updates in Maple 18.

See Also

file

FileTools[AtEndOfFile]

FileTools[Binary]

FileTools[Binary][Close]

FileTools[Binary][Read]

FileTools[Remove]

IO_errors