1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
% 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}
%
|