4.6.5.1 MPfile links
....................

MPfile links provide the possibility to store data in a file using the
binary MP format. Read and write operations are very fast compared to
ASCII links. Therefore, for storing large amounts of data, MPfile links
should be used instead of ASCII links. Unlike ASCII links, data read
from MPfile links is returned as expressions one at a time, and not as a
string containing the entire content of the file. Furthermore, ring-dependent
data is stored together with a ring description. Therefore,
reading ring-dependent data might change the current ring.

The MPfile link describing string has to be one of the following:

1. "MPfile: " + filename

the mode (read or append) is set by the first read or
write command.
2. "MPfile:r " + filename

opens the file for reading.
3. "MPfile:w " + filename

opens the file for overwriting.
4. "MPfile:a " + filename

opens the file for appending.

There are the following default values:
* if none of r, w, or a is specified, the mode of
the link is set by the first read or write command on the
link. If the first command is write, the mode is set to a
(append mode).

Note that the filename may contain a path. An MPfile link can be used
either for reading or for writing, but not for both at the same time. A
close command must be used before a change of I/O direction.


Example:
  ring r;
  link l="MPfile:w example.mp"; // type=MPfile, mode=overwrite
  l;
==> // type : MPfile
==> // mode : w
==> // name : example.mp
==> // open : no
==> // read : not ready
==> // write: not ready
  ideal i=x2,y2,z2;
  write (l,1, i, "hello world");// write three expressions
  write(l,4);                   // append one more expression
  close(l);                     // link is closed
  // open the file for reading now
  read(l);                      // only first expression is read
==> 1
  kill r;                       // no basering active now
  def i = read(l);              // second expression
  // notice that current ring was set, the name was assigned
  // automatically
  listvar(ring);
==> // mpsr_r0              [0]  *ring
  def s = read(l);              // third expression
  listvar();
==> // s                    [0]  string hello world
==> // mpsr_r0              [0]  *ring
==> //      i                    [0]  ideal, 3 generator(s)
==> // l                    [0]  link
==> // LIB                  [0]  string standard.lib
  close(l);                     // link is closed
  dump("MPfile:w example.mp");  // dump everything to example.mp
  kill i, s;                    // kill i and s
  getdump("MPfile: example.mp");// get previous dump
  listvar();                    // got all variables and values back
==> // mpsr_r0              [0]  *ring
==> //      i                    [0]  ideal, 3 generator(s)
==> // s                    [0]  string hello world
==> // l                    [0]  link
==> // LIB                  [0]  string standard.lib

<font size="-1">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; User manual for <a href="http://www.singular.uni-kl.de/"><i>Singular</i></a> version 2-0-4, October 2002,
generated by <a href="http://www.gnu.org/software/texinfo/"><i>texi2html</i></a>.
</font>

</body>
</html>
