Previous Page Next Page Contents

fprint -- write data to a file

Introduction

fprint(filename, objects) writes MuPAD objects to the file filename.

fprint(n, objects) writes to the file associated with the file descriptor n.

Call(s)

fprint( <style,> <format,> filename, object1, object2...)
fprint( <style,> n, object1, object2...)

Parameters

filename - the name of a file: a character string
object1, object2... - arbitrary MuPAD objects
n - a file descriptor provided by fopen: a nonnegative integer

Options

style - either Unquoted or NoNL. These options are relevant for text files only. Both options make fprint store character strings without quotation marks. All objects are stored without separating colons in the text file. With Unquoted, a newline character is appended to the line generated by fprint. With NoNL, no newline character is appended to the line.
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

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

Details

Option: Unquoted

Option: NoNL

Example 1

We write some data to the file test. By default, this file is created as a binary file. For syntactical reasons, the assignment d := 5 must be enclosed in additional brackets:

>> fprint("test", (d := 5), d*3):

The file is read into the MuPAD session. The assignment d := 5 is executed, its return value is assigned to the identifier e. The value d*3 is assigned to the identifier f:

>> finput("test", e, f): d, e, f; 
                                 5, 5, 15
>> delete d, e, f:

Example 2

We use a file descriptor to access the file test. Several calls to fprint append data to the file:

>> n := fopen("test", Write): 
   fprint(n, (d := 5), d*3): 
   fprint(n, "more data"):

Using a file descriptor, we have to call fclose to close the file:

>> fclose(n):

The file is read into the MuPAD session, assigning the stored values to the identifiers e, f, and g:

>> finput("test", e, f, g ): e, f, g; 
                            5, 15, "more data"
>> delete n, d, e, f, g:

Example 3

With the option Unquoted, character strings are written without quotation marks:

>> fprint(Text, "test1", "Hello World!", MuPAD + 1):
   fprint(Unquoted, Text, "test2", "Hello World!", MuPAD + 1):

Now, the files test1 and test2 have the following content:

      test1:
      "Hello World!":MuPAD + 1:
      
      test2:
      Hello World!MuPAD + 1

We can use finput or ftextinput to read the data from the file:

>> finput("test1", a, b): a, b;
                         "Hello World!", MuPAD + 1
>> ftextinput("test2", c): c 
                          "Hello World!MuPAD + 1"
>> delete a, b, c:

Example 4

The text version of a MuPAD object does not necessarily reflect its data structure. E.g., the function matrix creates matrices of domain type Dom::Matrix(). The text version, however, is an array:

>> fprint(Text, "test", matrix([1, 2])):
   finput("test")
                 array(1..2, 1..1, (1, 1) = 1, (2, 1) = 2)

Use the binary mode to guarantee that stored objects can be read in their original form:

>> fprint("test", matrix([1, 2])):
   finput("test"); domtype(%)
                                  +-   -+
                                  |  1  |
                                  |     |
                                  |  2  |
                                  +-   -+
      
                               Dom::Matrix()

Changes




Do you have questions or comments?


Copyright © SciFace Software GmbH & Co. KG 2000