% Copyright The Numerical Algorithms Group Limited 1992-94. All rights reserved. % !! DO NOT MODIFY THIS FILE BY HAND !! Created by ht.awk. \newcommand{\FileXmpTitle}{File} \newcommand{\FileXmpNumber}{9.24} % % ===================================================================== \begin{page}{FileXmpPage}{9.24 File} % ===================================================================== \beginscroll The \spadtype{File(S)} domain provides a basic interface to read and write values of type \spad{S} in files. \xtc{ Before working with a file, it must be made accessible to \Language{} with the \spadfunFrom{open}{File} operation. }{ \spadpaste{ifile:File List Integer:=open("/tmp/jazz1","output") \bound{ifile}} } The \spadfunFrom{open}{File} function arguments are a \spadtype{FileName} and a \spadtype{String} specifying the mode. If a full pathname is not specified, the current default directory is assumed. The mode must be one of \spad{"input"} or \spad{"output"}. If it is not specified, \spad{"input"} is assumed. Once the file has been opened, you can read or write data. \xtc{ The operations \spadfunFromX{read}{File} and \spadfunFromX{write}{File} are provided. }{ \spadpaste{write!(ifile, [-1,2,3]) \free{ifile}\bound{ifile1}} } \xtc{ }{ \spadpaste{write!(ifile, [10,-10,0,111]) \free{ifile1}\bound{ifile2}} } \xtc{ }{ \spadpaste{write!(ifile, [7]) \free{ifile2}\bound{ifile3}} } \xtc{ You can change from writing to reading (or vice versa) by reopening a file. }{ \spadpaste{reopen!(ifile, "input") \free{ifile3}\bound{ifile4}} } \xtc{ }{ \spadpaste{read! ifile \free{ifile4}\bound{ifile5}} } \xtc{ }{ \spadpaste{read! ifile \free{ifile5}\bound{ifile6}} } \xtc{ The \spadfunFromX{read}{File} operation can cause an error if one tries to read more data than is in the file. To guard against this possibility the \spadfunFromX{readIfCan}{File} operation should be used. }{ \spadpaste{readIfCan! ifile \free{ifile6}\bound{ifile7}} } \xtc{ }{ \spadpaste{readIfCan! ifile \free{ifile7}\bound{ifile8}} } \xtc{ You can find the current mode of the file, and the file's name. }{ \spadpaste{iomode ifile \free{ifile}} } \xtc{ }{ \spadpaste{name ifile \free{ifile}} } \xtc{ When you are finished with a file, you should close it. }{ \spadpaste{close! ifile \free{ifile}\bound{ifileA}} } \noOutputXtc{ }{ \spadpaste{)system rm /tmp/jazz1 \free{ifileA}} } %\xtc{ %}{ %\spadcommand{)clear all \free{}\bound{}} %} A limitation of the underlying LISP system is that not all values can be represented in a file. In particular, delayed values containing compiled functions cannot be saved. For more information on related topics, see \downlink{`TextFile'}{TextFileXmpPage}\ignore{TextFile}, \downlink{`KeyedAccessFile'}{KeyedAccessFileXmpPage}\ignore{KeyedAccessFile}, \downlink{`Library'}{LibraryXmpPage}\ignore{Library}, and \downlink{`FileName'}{FileNameXmpPage}\ignore{FileName}. \showBlurb{File} \endscroll \autobuttons \end{page} %