
fopen - opens a file

Calling sequence:
fopen(string)
fopen( [ type, ]  string, mode )

Parameter:
type     --  one of the options Bin or Text
string   --  character string
mode     --  one of the options Write or Append

Summary:

fopen opens the file with the name string.  If, in MacMuPAD, an empty
character string is given by the argument string then a dialogue is opened
in which the user can choose a file.

fopen returns a positive integer as the return value; the so-called file descriptor.
This number is used to identify the file in later operations. FAIL is returned
if the file can't be opened. The file can be closed with the function fclose .

 o  If no further options are given then the file is opened for reading. fopen
    automatically identifies if the file is text or binary.

     Firstly the file is searched for in the directory given by the variable
     READ_PATH  and then in the current directory.  (This is the directory
     in which MuPAD was started.)  Finally the file is searched for in the
     directory given by the variable LIB_PATH .

  o  If one of the options Write or Append is given then the file is opened for
     writing. If necessary, a non-existing file is newly created. With Write
     the old contents of the file are overwritten. With Append the new data
     is appended at the end of the old data, i.e. the old data is not lost.

     If the variable WRITE_PATH has a value then the file is created in the given
     directory, if it does not then a file is created in the current directory.

     In MacMuPAD, if fopen is called with the option Write while in the
     interactive level then the user is warned about the overwriting of a file.
     He can then terminate the operation.

While opening the file with Write or Append optionally one of the options
Bin or Text can be given. Then the file is opened as a text, or respectively,
a binary file. If no option is given and a new file is created, it is opened as a
binary file.

If an existing text file is opened with Append and Bin then this leads to an
error. Analogue when an existing binary file is opened with Append and Text
an error is also returned. fopen is a kernel function.

>>  f := fopen(Bin, "test.mb", Append);

      123

See also:  fclose , finput , fprint , ftextinput , protocol , read, write


