Home Online Manual
Top
Back: link related functions
Forward: Ssi links
FastBack: intvec
FastForward: list
Up: link
Top: Singular Manual
Contents: Table of Contents
Index: Index
About: About this document

4.9.4 ASCII links

Via ASCII links data that can be converted to a string can be written into files for storage or communication with other programs. The data is written in plain ASCII format. The output format of polynomials is done w.r.t. the value of the global variable short (see short). Reading from an ASCII link returns a string -- conversion into other data is up to the user. This can be done, for example, using the command execute (see execute).

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

  1. "ASCII: " + filename
    the mode (read or append) is set by the first read or write command.
  2. "ASCII:r " + filename
    opens the file for reading.
  3. "ASCII:w " + filename
    opens the file for overwriting.
  4. "ASCII:a " + filename
    opens the file for appending.

There are the following default values:

  • the type ASCII may be omitted since ASCII links are the default links.

  • if non 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).

  • if the filename is omitted, read reads from stdin and write writes to stdout.

Using these default rules, the string ":r temp" describes a link which is equivalent to the link "ASCII:r temp": an ASCII link to the file temp which is opened for reading. The string "temp" describes an ASCII link to the file temp, where the mode is set by the first read or write command. See also the example below.

Note that the filename may contain a path. On Microsoft Windows (resp. MS-DOS) platforms, names of a drive can precede the filename, but must be started with a // (as in //c/temp/ex. An ASCII 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. Types without a conversion to string cannot be written.


Example:

 
  ring r=32003,(x,y,z),dp;
  link l=":w example.txt";     // type is ASCII, mode is overwrite
  l;
==> // type : ASCII
==> // mode : w
==> // name : example.txt
==> // open : no
==> // read : not ready
==> // write: not ready
  status(l, "open", "yes");    // link is not yet opened
==> 0
  ideal i=x2,y2,z2;
  write (l,1,";",2,";","ideal i=",i,";");
  status(l, "open", "yes");    // now link is open
==> 1
  status(l, "mode");           // for writing
==> w
  close(l);                    // link is closed
  write("example.txt","int j=5;");// data is appended to file
  read("example.txt");         // data is returned as string
==> 1
==> ;
==> 2
==> ;
==> ideal i=
==> x2,y2,z2;
==> int j=5;
==> 
  execute(read(l));            // read string is executed
==> 1
==> 2
==> // ** redefining i (ideal i=) ./examples/ASCII_links.sing:14
  close(l);                    // link is closed