Previous Page Next Page Contents

write -- write the values of variables into a file

Introduction

write(filename) stores all assigned identifiers of the MuPAD session with their current values in a file specified by filename.

write(filename, x1, x2...) stores the current values of the identifiers x1, x2 etc.

write(n) and write(n, x1, x2...) store the data in the file associated with the file descriptor n.

Call(s)

write( <format>, filename)
write( <format>, filename, x1, x2...)
write(n)
write(n, x1, x2...)

Parameters

filename - the name of a file: a character string
x1, x2... - identifiers
n - a file descriptor provided by fopen: a nonnegative integer

Options

format - the write format: either Bin or Text. With Bin, the data are stored in MuPAD's binary format. With Text, standard ASCII format is used. The default is Bin.

Returns

the void object of type DOM_NULL.

Side Effects

The function is sensitive to the environment variable WRITEPATH. If this variable has a value, the file is created in the corresponding directory. Otherwise, the file is created in the ``working directory''.

Related Functions

fclose, finput, fopen, fprint, fread, ftextinput, pathname, print, protocol, read, READPATH, WRITEPATH

Details

Option: Text

Example 1

The variable a and its value b + 1 are stored in a file named test:

>> a := b + 1: write(Text, "test", a):

The content of this file is displayed via ftextinput:

>> ftextinput("test")
                       "sysassign(a, hold(b + 1)):"

We delete the value of a. Reading the file test restores the previous value:

>> delete a: read("test"): a
                                   b + 1
>> delete a:

Example 2

The file test is opened for writing using MuPAD's binary format:

>> n := fopen("test", Write)
                                    18

This number is the descriptor of the file and can be used in a write command:

>> a := b + 1: write(n, a):
>> delete a: read("test"): a
                                   b + 1

We close the file and clean up:

>> fclose(n): delete n, a:

Example 3

The value b + 1 is assigned to the identifier a. After assigning the value 2 to b, complete evaluation of a yields 3:

>> a := b + 1: b := 2: a 
                                     3

Note, however, that the value of a is the expression b + 1. This value is stored by a write command:

>> write(Text, "test", a): ftextinput("test")
                       "sysassign(a, hold(b + 1)):"

Consequently, this value is restored after reading the file into a MuPAD session:

>> delete a, b: read("test"): a
                                   b + 1
>> delete a:

Changes




Do you have questions or comments?


Copyright © SciFace Software GmbH & Co. KG 2000