annotate doc/interpreter/io.texi @ 2670:18192eea4973

[project @ 1997-02-13 18:29:53 by jwe]
author jwe
date Thu, 13 Feb 1997 18:34:06 +0000
parents e7908588548a
children 8c7955a8d49f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2670
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
1 @c Copyright (C) 1996, 1997 John W. Eaton
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
2 @c This is part of the Octave manual.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
3 @c For copying conditions, see the file gpl.texi.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
4
2670
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
5 @node Input and Output, Plotting, Error Handling, Top
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
6 @chapter Input and Output
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
7
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
8 There are two distinct classes of input and output functions. The first
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
9 set are modeled after the functions available in @sc{Matlab}. The
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
10 second set are modeled after the standard I/O library used by the C
2653
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
11 programming language and offer more flexibility and control over the
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
12 output.
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
13
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
14 When running interactively, Octave normally sends any output intended
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
15 for your terminal that is more than one screen long to a paging program,
2653
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
16 such as @code{less} or @code{more}. This avoids the problem of having a
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
17 large volume of output stream by before you can read it. With
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
18 @code{less} (and some versions of @code{more}) you can also scan forward
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
19 and backward, and search for specific items.
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
20
2653
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
21 Normally, no output is displayed by the pager until just before Octave
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
22 is ready to print the top level prompt, or read from the standard input
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
23 (for example, by using the @code{fscanf} or @code{scanf} functions).
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
24 This means that there may be some delay before any output appears on
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
25 your screen if you have asked Octave to perform a significant amount of
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
26 work with a single command statement. The function @code{fflush} may be
2670
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
27 used to force output to be sent to the pager (or any other stream)
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
28 immediately.
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
29
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
30 You can select the program to run as the pager by setting the variable
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
31 @code{PAGER}, and you can turn paging off by setting the value of the
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
32 variable @code{page_screen_output} to 0.
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
33
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
34 @deffn {Command} more
2653
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
35 @deffnx {Command} more on
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
36 @deffnx {Command} more off
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
37 Turn output pagination on or off. Without an argument, @code{more}
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
38 toggles the current state.
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
39 @end deffn
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
40
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
41 @defvr {Built-in Variable} PAGER
2653
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
42 The default value is normally @code{"less"}, @code{"more"}, or
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
43 @code{"pg"}, depending on what programs are installed on your system.
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
44 @xref{Installation}.
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
45
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
46 When running interactively, Octave sends any output intended for your
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
47 terminal that is more than one screen long to the program named by the
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
48 value of the variable @code{PAGER}.
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
49 @end defvr
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
50
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
51 @defvr {Built-in Variable} page_screen_output
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
52 If the value of @code{page_screen_output} is nonzero, all output
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
53 intended for the screen that is longer than one page is sent through a
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
54 pager. This allows you to view one screenful at a time. Some pagers
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
55 (such as @code{less}---see @ref{Installation}) are also capable of moving
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
56 backward on the output. The default value is 1.
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
57 @end defvr
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
58
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
59 @defvr {Built-in Variable} page_output_immediately
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
60 If the value of @code{page_output_immediately} is nonzero, Octave sends
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
61 output to the pager as soon as it is available. Otherwise, Octave
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
62 buffers its output and waits until just before the prompt is printed to
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
63 flush it to the pager. The default value is 0.
2653
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
64
2670
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
65 @deftypefn {Built-in Function} {} fflush (@var{fid})
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
66 Flush output to @var{fid}. This is useful for ensuring that all
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
67 pending output makes it to the screen before some other event occurs.
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
68 For example, it is always a good idea to flush the standard output
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
69 stream before calling @code{input}.
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
70 @end deftypefn
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
71
2653
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
72 @c XXX FIXME XXX -- maybe this would be a good place to describe the
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
73 @c following message:
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
74 @c
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
75 @c warning: connection to external pager (pid = 9334) lost --
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
76 @c warning: pending computations and output may be lost
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
77 @c warning: broken pipe
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
78 @end defvr
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
79
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
80 @menu
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
81 * Basic Input and Output::
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
82 * C-Style I/O Functions::
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
83 @end menu
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
84
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
85 @node Basic Input and Output, C-Style I/O Functions, Input and Output, Input and Output
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
86 @section Basic Input and Output
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
87
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
88 @menu
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
89 * Terminal Output::
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
90 * Terminal Input::
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
91 * Simple File I/O::
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
92 @end menu
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
93
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
94 @node Terminal Output, Terminal Input, Basic Input and Output, Basic Input and Output
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
95 @subsection Terminal Output
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
96
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
97 Since Octave normally prints the value of an expression as soon as it
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
98 has been evaluated, the simplest of all I/O functions is a simple
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
99 expression. For example, the following expression will display the
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
100 value of pi
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
101
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
102 @example
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
103 octave:13> pi
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
104 pi = 3.1416
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
105 @end example
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
106
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
107 This works well as long as it is acceptable to have the name of the
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
108 variable (or @samp{ans}) printed along with the value. To print the
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
109 value of a variable without printing its name, use the function
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
110 @code{disp}.
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
111
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
112 The @code{format} command offers some control over the way Octave prints
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
113 values with @code{disp} and through the normal echoing mechanism.
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
114
2653
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
115 @defvr {Built-in Variable} ans
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
116 This variable holds the most recently computed result that was not
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
117 explicitly assigned to a variable. For example, after the expression
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
118
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
119 @example
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
120 3^2 + 4^2
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
121 @end example
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
122
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
123 @noindent
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
124 is evaluated, the value of @code{ans} is @samp{25}.
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
125 @end defvr
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
126
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
127 @deftypefn {Built-in Function} {} disp (@var{x})
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
128 Display the value of @var{x}. For example, the following expression
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
129
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
130 @example
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
131 disp ("The value of pi is:"), disp (pi)
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
132 @end example
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
133
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
134 @noindent
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
135 will print
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
136
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
137 @example
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
138 The value of pi is:
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
139 3.1416
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
140 @end example
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
141
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
142 @noindent
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
143 Note that the output from @code{disp} always ends with a newline.
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
144 @end deftypefn
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
145
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
146 @deffn {Command} format options
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
147 Control the format of the output produced by @code{disp} and Octave's
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
148 normal echoing mechanism. Valid options are listed in the following
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
149 table.
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
150
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
151 @table @code
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
152 @item short
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
153 This is the default format. Octave will try to print numbers with at
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
154 least 5 significant figures within a field that is a maximum of 10
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
155 characters wide.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
156
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
157 If Octave is unable to format a matrix so that columns line up on the
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
158 decimal point and all the numbers fit within the maximum field width,
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
159 it switches to an @samp{e} format.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
160
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
161 @item long
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
162 Octave will try to print numbers with at least 15 significant figures
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
163 within a field that is a maximum of 24 characters wide.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
164
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
165 As will the @samp{short} format, Octave will switch to an @samp{e}
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
166 format if it is unable to format a matrix so that columns line up on the
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
167 decimal point and all the numbers fit within the maximum field width.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
168
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
169 @item long e
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
170 @itemx short e
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
171 The same as @samp{format long} or @samp{format short} but always display
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
172 output with an @samp{e} format. For example, with the @samp{short e}
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
173 format, pi is displayed as
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
174
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
175 @example
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
176 3.14e+00
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
177 @end example
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
178
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
179 @item long E
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
180 @itemx short E
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
181 The same as @samp{format long e} or @samp{format short e} but always
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
182 display output with an uppercase @samp{E} format. For example, with
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
183 the @samp{long E} format, pi is displayed as
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
184
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
185 @example
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
186 3.14159265358979E+00
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
187 @end example
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
188
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
189 @item free
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
190 @itemx none
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
191 Print output in free format, without trying to line up columns of
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
192 matrices on the decimal point. This also causes complex numbers to be
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
193 formatted like this @samp{(0.604194, 0.607088)} instead of like this
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
194 @samp{0.60419 + 0.60709i}.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
195
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
196 @item bank
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
197 Print in a fixed format with two places to the right of the decimal
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
198 point.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
199
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
200 @item +
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
201 Print a @samp{+} symbol for nonzero matrix elements and a space for zero
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
202 matrix elements. This format can be very useful for examining the
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
203 structure of a large matrix.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
204
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
205 @item hex
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
206 Print the hexadecimal representation numbers as they are stored in
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
207 memory. For example, on a workstation which stores 8 byte real values
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
208 in IEEE format with the least significant byte first, the value of
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
209 @code{pi} when printed in @code{hex} format is @code{400921fb54442d18}.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
210 This format only works for numeric values.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
211
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
212 @item bit
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
213 Print the bit representation of numbers as stored in memory.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
214 For example, the value of @code{pi} is
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
215
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
216 @example
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
217 @group
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
218 01000000000010010010000111111011
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
219 01010100010001000010110100011000
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
220 @end group
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
221 @end example
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
222
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
223 (shown here in two 32 bit sections for typesetting purposes) when
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
224 printed in bit format on a workstation which stores 8 byte real values
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
225 in IEEE format with the least significant byte first. This format only
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
226 works for numeric types.
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
227 @end table
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
228 @end deffn
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
229
2653
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
230 @defvr {Built-in Variable} print_answer_id_name
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
231 If the value of @code{print_answer_id_name} is nonzero, variable
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
232 names are printed along with the result. Otherwise, only the result
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
233 values are printed. The default value is 1.
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
234 @end defvr
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
235
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
236 @node Terminal Input, Simple File I/O, Terminal Output, Basic Input and Output
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
237 @subsection Terminal Input
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
238
2670
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
239 Octave has three functions that make it easy to prompt users for
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
240 input. The @code{input} and @code{menu} functions are normally
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
241 used for managing an interactive dialog with a user, and the
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
242 @code{keyboard} function is normally used for doing simple debugging.
2653
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
243
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
244 @deftypefn {Built-in Function} {} input (@var{prompt})
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
245 @deftypefnx {Built-in Function} {} input (@var{prompt}, "s")
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
246 Print a prompt and wait for user input. For example,
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
247
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
248 @example
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
249 input ("Pick a number, any number! ")
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
250 @end example
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
251
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
252 @noindent
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
253 prints the prompt
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
254
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
255 @example
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
256 Pick a number, any number!
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
257 @end example
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
258
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
259 @noindent
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
260 and waits for the user to enter a value. The string entered by the user
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
261 is evaluated as an expression, so it may be a literal constant, a
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
262 variable name, or any other valid expression.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
263
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
264 Currently, @code{input} only returns one value, regardless of the number
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
265 of values produced by the evaluation of the expression.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
266
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
267 If you are only interested in getting a literal string value, you can
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
268 call @code{input} with the character string @code{"s"} as the second
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
269 argument. This tells Octave to return the string entered by the user
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
270 directly, without evaluating it first.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
271
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
272 Because there may be output waiting to be displayed by the pager, it is
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
273 a good idea to always call @code{fflush (stdout)} before calling
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
274 @code{input}. This will ensure that all pending output is written to
2670
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
275 the screen before your prompt. @xref{Input and Output}.
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
276 @end deftypefn
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
277
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
278 @deftypefn {Function File} {} menu (@var{title}, @var{opt1}, @dots{})
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
279 Print a title string followed by a series of options. Each option will
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
280 be printed along with a number. The return value is the number of the
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
281 option selected by the user. This function is useful for interactive
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
282 programs. There is no limit to the number of options that may be passed
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
283 in, but it may be confusing to present more than will fit easily on one
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
284 screen.
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
285 @end deftypefn
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
286
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
287 @deftypefn {Built-in Function} {} keyboard (@var{prompt})
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
288 This function is normally used for simple debugging. When the
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
289 @code{keyboard} function is executed, Octave prints a prompt and waits
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
290 for user input. The input strings are then evaluated and the results
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
291 are printed. This makes it possible to examine the values of variables
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
292 within a function, and to assign new values to variables. No value is
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
293 returned from the @code{keyboard} function, and it continues to prompt
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
294 for input until the user types @samp{quit}, or @samp{exit}.
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
295
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
296 If @code{keyboard} is invoked without any arguments, a default prompt of
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
297 @samp{debug> } is used.
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
298 @end deftypefn
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
299
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
300 For both @code{input} and @code{keyboard}, the normal command line
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
301 history and editing functions are available at the prompt.
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
302
2670
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
303 Octave also has a function that makes it possible to get a single
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
304 character from the keyboard without requiring the user to type a
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
305 carriage return.
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
306
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
307 @c XXX FIXME XXX -- perhaps kbhit should also be able to print a prompt
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
308 @c string?
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
309
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
310 @deftypefn {Built-in Function} {} kbhit ()
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
311 Read a single keystroke from the keyboard. For example,
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
312
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
313 @example
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
314 x = kbhit ();
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
315 @end example
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
316
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
317 @noindent
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
318 will set @var{x} to the next character typed at the keyboard as soon as
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
319 it is typed.
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
320 @end deftypefn
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
321
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
322 @node Simple File I/O, , Terminal Input, Basic Input and Output
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
323 @subsection Simple File I/O
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
324
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
325 The @code{save} and @code{load} commands allow data to be written to and
2653
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
326 read from disk files in various formats. The default format of files
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
327 written by the @code{save} command can be controlled using the built-in
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
328 variables @code{default_save_format} and @code{save_precision}.
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
329
2670
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
330 Note that Octave can not yet save or load structure variables or any
2653
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
331 user-defined types.
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
332
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
333 @deffn {Command} save options file v1 v2 @dots{}
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
334 Save the named variables @var{v1}, @var{v2}, @dots{} in the file
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
335 @var{file}. The special filename @samp{-} can be used to write the
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
336 output to your terminal. If no variable names are listed, Octave saves
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
337 all the variables in the current scope. Valid options for the
2653
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
338 @code{save} command are listed in the following table. Options that
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
339 modify the output format override the format specified by the built-in
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
340 variable @code{default_save_format}.
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
341
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
342 @table @code
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
343 @item -ascii
2653
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
344 Save the data in Octave's text data format.
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
345
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
346 @item -binary
2653
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
347 Save the data in Octave's binary data format.
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
348
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
349 @item -float-binary
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
350 Save the data in Octave's binary data format but only using single
2653
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
351 precision. You should use this format only if you know that all the
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
352 values to be saved can be represented in single precision.
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
353
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
354 @item -mat-binary
2653
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
355 Save the data in @sc{Matlab}'s binary data format.
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
356
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
357 @item -save-builtins
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
358 Force Octave to save the values of built-in variables too. By default,
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
359 Octave does not save built-in variables.
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
360 @end table
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
361
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
362 The list of variables to save may include wildcard patterns containing
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
363 the following special characters:
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
364 @table @code
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
365 @item ?
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
366 Match any single character.
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
367
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
368 @item *
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
369 Match zero or more characters.
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
370
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
371 @item [ @var{list} ]
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
372 Match the list of characters specified by @var{list}. If the first
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
373 character is @code{!} or @code{^}, match all characters except those
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
374 specified by @var{list}. For example, the pattern @samp{[a-zA-Z]} will
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
375 match all lower and upper case alphabetic characters.
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
376 @end table
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
377
2653
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
378 Except when using hte @sc{Matlab} binary data file format, saving global
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
379 variables also saves the global status of the variable, so that if it is
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
380 restored at a later time using @samp{load}, it will be restored as a
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
381 global variable.
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
382
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
383 The command
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
384
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
385 @example
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
386 save -binary data a b*
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
387 @end example
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
388
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
389 @noindent
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
390 saves the variable @samp{a} and all variables beginning with @samp{b} to
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
391 the file @file{data} in Octave's binary format.
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
392 @end deffn
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
393
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
394 There are two variables that modify the behavior of @code{save}.
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
395
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
396 @defvr {Built-in Variable} default_save_format
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
397 This variable specifies the default format for the @code{save} command.
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
398 It should have one of the following values: @code{"ascii"},
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
399 @code{"binary"}, @code{float-binary}, or @code{"mat-binary"}. The
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
400 initial default save format is Octave's text format.
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
401 @end defvr
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
402
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
403 @defvr {Built-in Variable} save_precision
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
404 This variable specifies the number of digits to keep when saving data in
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
405 text format. The default value is 17.
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
406 @end defvr
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
407
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
408 @deffn {Command} load options file v1 v2 @dots{}
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
409 To restore the values from a file, use the @code{load} command. As with
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
410 @code{save}, you may specify a list of variables and @code{load} will
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
411 only extract those variables with names that match. For example, to
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
412 restore the variables saved in the file @file{data}, use the command
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
413
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
414 @example
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
415 load data
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
416 @end example
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
417
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
418 Octave will refuse to overwrite existing variables unless you use the
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
419 option @samp{-force}.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
420
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
421 If a variable that is not marked as global is loaded from a file when a
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
422 global symbol with the same name already exists, it is loaded in the
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
423 global symbol table. Also, if a variable is marked as global in a file
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
424 and a local symbol exists, the local symbol is moved to the global
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
425 symbol table and given the value from the file. Since it seems that
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
426 both of these cases are likely to be the result of some sort of error,
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
427 they will generate warnings.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
428
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
429 The @code{load} command can read data stored in Octave's text and
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
430 binary formats, and @sc{Matlab}'s binary format. It will automatically
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
431 detect the type of file and do conversion from different floating point
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
432 formats (currently only IEEE big and little endian, though other formats
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
433 may added in the future).
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
434
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
435 Valid options for @code{load} are listed in the following table.
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
436
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
437 @table @code
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
438 @item -force
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
439 Force variables currently in memory to be overwritten by variables with
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
440 the same name found in the file.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
441
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
442 @item -ascii
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
443 Force Octave to assume the file is in Octave's text format.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
444
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
445 @item -binary
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
446 Force Octave to assume the file is in Octave's binary format.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
447
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
448 @item -mat-binary
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
449 Force Octave to assume the file is in @sc{Matlab}'s binary format.
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
450 @end table
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
451 @end deffn
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
452
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
453 @node C-Style I/O Functions, , Basic Input and Output, Input and Output
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
454 @section C-Style I/O Functions
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
455
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
456 Octave's C-style input and output functions provide most of the
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
457 functionality of the C programming language's standard I/O library. The
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
458 argument lists for some of the input functions are slightly different,
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
459 however, because Octave has no way of passing arguments by reference.
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
460
2653
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
461 In the following, @var{file} refers to a file name and @code{fid} returs
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
462 to an integer file number, as returned by @code{fopen}.
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
463
2653
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
464 There are three files that are always available. Although these files
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
465 can be accessed using their corresponding numeric file ids, you should
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
466 always use the symbolic names given in the table below, since it will
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
467 make your programs easier to understand.
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
468
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
469 @defvr {Built-in Variable} stdin
2653
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
470 The standard input stream (file id 0). When Octave is used
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
471 interactively, this is filtered through the command line editing
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
472 functions.
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
473 @end defvr
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
474
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
475 @defvr {Built-in Variable} stdout
2653
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
476 The standard output stream (file id 1). Data written to the
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
477 standard output is normally filtered through the pager.
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
478 @end defvr
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
479
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
480 @defvr {Built-in Variable} stderr
2653
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
481 The standard error stream (file id 2). Even if paging is turned on,
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
482 the standard error is not sent to the pager. It is useful for error
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
483 messages and prompts.
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
484 @end defvr
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
485
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
486 @menu
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
487 * Opening and Closing Files::
2670
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
488 * Simple Output::
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
489 * Line-Oriented Input::
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
490 * Formatted Output::
2653
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
491 * Output Conversion for Matrices::
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
492 * Output Conversion Syntax::
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
493 * Table of Output Conversions::
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
494 * Integer Conversions::
2653
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
495 * Floating-Point Conversions:: Other Output Conversions::
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
496 * Other Output Conversions::
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
497 * Formatted Input::
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
498 * Input Conversion Syntax::
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
499 * Table of Input Conversions::
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
500 * Numeric Input Conversions::
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
501 * String Input Conversions::
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
502 * Binary I/O::
2670
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
503 * Temporary Files::
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
504 * EOF and Errors::
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
505 * File Positioning::
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
506 @end menu
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
507
2670
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
508 @node Opening and Closing Files, Simple Output, C-Style I/O Functions, C-Style I/O Functions
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
509 @subsection Opening and Closing Files
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
510
2653
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
511 @deftypefn {Built-in Function} {[fid, msg] =} fopen (@var{name}, @var{mode}, @var{arch})
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
512 @deftypefnx {Built-in Function} {fid_list =} fopen ("all")
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
513 @deftypefnx {Built-in Function} {file =} fopen (@var{fid})
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
514 The first form of the @code{fopen} function opens the named file with
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
515 the specified mode (read-write, read-only, etc.) and architecture
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
516 interpretation (IEEE big endian, IEEE little endian, etc.), and returns
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
517 an integer value that may be used to refer to the file later. If an
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
518 error occurs, @var{fid} is set to -1 and @var{msg} contains the
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
519 corresponding system error message. The @var{mode} is a one or two
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
520 character string that specifies whether the file is to be opened for
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
521 reading, writing, or both.
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
522
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
523 The second form of the @code{fopen} function returns a vector of file ids
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
524 corresponding to all the currently open files, excluding the
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
525 @code{stdin}, @code{stdout}, and @code{stderr} streams.
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
526
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
527 The third form of the @code{fopen} function returns the name of a
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
528 currently open file given its file id.
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
529
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
530 For example,
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
531
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
532 @example
2653
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
533 myfile = fopen ("splat.dat", "r", "ieee-le");
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
534 @end example
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
535
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
536 @noindent
2653
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
537 opens the file @file{splat.dat} for reading. If necessary, binary
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
538 numeric values will be read assuming they are stored in IEEE format with
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
539 the least significant bit first, and then converted to the native
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
540 representation.
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
541
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
542 Opening a file that is already open simply opens it again and returns a
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
543 separate file id. It is not an error to open a file several times,
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
544 though writing to the same file through several different file ids may
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
545 produce unexpected results.
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
546
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
547 The possible values @samp{mode} may have are
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
548
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
549 @table @asis
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
550 @item @samp{r}
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
551 Open a file for reading.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
552
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
553 @item @samp{w}
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
554 Open a file for writing. The previous contents are discared.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
555
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
556 @item @samp{a}
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
557 Open or create a file for writing at the end of the file.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
558
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
559 @item @samp{r+}
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
560 Open an existing file for reading and writing.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
561
2653
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
562 item @samp{w+}
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
563 Open a file for reading or writing. The previous contents are
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
564 discared.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
565
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
566 @item @samp{a+}
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
567 Open or create a file for reading or writing at the end of the
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
568 file.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
569 @end table
2653
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
570
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
571 The parameter @var{arch} is a string specifying the default data format
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
572 for the file. Valid values for @var{arch} are:
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
573
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
574 @table @asis
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
575 @samp{native}
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
576 The format of the current machine (this is the default).
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
577
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
578 @samp{ieee-le}
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
579 IEEE big endian format.
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
580
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
581 @samp{ieee-be}
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
582 IEEE little endian format.
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
583
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
584 @samp{vaxd}
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
585 VAX D floating format.
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
586
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
587 @samp{vaxg}
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
588 VAX G floating format.
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
589
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
590 @samp{cray}
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
591 Cray floating format.
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
592 @end table
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
593
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
594 @noindent
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
595 however, conversions are currently only supported for @samp{native}
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
596 @samp{ieee-be}, and @samp{ieee-le} formats.
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
597 @end deftypefn
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
598
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
599 @deftypefn {Built-in Function} {} fclose (@var{fid})
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
600 Closes the specified file. If an error is encountered while trying to
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
601 close the file, an error message is printed and @code{fclose} returns
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
602 0. Otherwise, it returns 1.
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
603 @end deftypefn
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
604
2670
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
605 @node Simple Output, Line-Oriented Input, Opening and Closing Files, C-Style I/O Functions
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
606 @subsection Simple Output
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
607
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
608 @deftypefn {Built-in Function} {} fputs (@var{fid}, @var{string})
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
609 Write a string to a file with no formatting.
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
610 @end deftypefn
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
611
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
612 @deftypefn {Built-in Function} {} puts (@var{string})
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
613 Write a string to the standard output with no formatting.
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
614 @end deftypefn
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
615
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
616 @node Line-Oriented Input, Formatted Output, Simple Output, C-Style I/O Functions
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
617 @subsection Line-Oriented Input
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
618
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
619 @deftypefn {Built-in Function} {} fgetl (@var{fid}, @var{len})
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
620 Read characters from a file, stopping at the first newline character
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
621 that is encountered or after @var{len} characters have been read, and
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
622 returning the characters as a string. The newline is not included in
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
623 the returned value.
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
624
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
625 If @var{len} is omitted, @code{fgetl} reads until the next newline
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
626 character.
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
627
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
628 If there are no more characters to read, @code{fgetl} returns -1.
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
629 @end deftypefn
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
630
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
631 @deftypefn {Built-in Function} {} fgets (@var{fid}, @var{len})
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
632 Read characters from a file, stopping at the first newline character
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
633 that is encountered or after @var{len} characters have been read, and
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
634 returning the characters as a string. The newline is included in the
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
635 returned value.
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
636
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
637 If @var{len} is omitted, @code{fgets} reads until the next newline
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
638 character.
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
639
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
640 If there are no more characters to read, @code{fgets} returns -1.
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
641 @end deftypefn
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
642
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
643 @node Formatted Output, Output Conversion for Matrices, Line-Oriented Input, C-Style I/O Functions
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
644 @subsection Formatted Output
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
645
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
646 This section describes how to call @code{printf} and related functions.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
647
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
648 The following functions are available for formatted output. They are
2653
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
649 modelled after the C language functions of the same name, but they
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
650 interpret the format template differently in order to improve the
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
651 performance of printing vector and matrix values.
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
652
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
653 @deftypefn {Function File} {} printf (@var{template}, @dots{})
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
654 The @code{printf} function prints the optional arguments under the
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
655 control of the template string @var{template} to the stream
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
656 @code{stdout}.
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
657 @end deftypefn
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
658
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
659 @deftypefn {Built-in Function} {} fprintf (@var{fid}, @var{template}, @dots{})
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
660 This function is just like @code{printf}, except that the output is
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
661 written to the stream @var{fid} instead of @code{stdout}.
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
662 @end deftypefn
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
663
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
664 @deftypefn {Built-in Function} {} sprintf (@var{template}, @dots{})
2653
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
665 This is like @code{printf}, except that the output is returned as a
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
666 string. Unlike the C library function, which requires you to provide a
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
667 suitably sized string as an argument, Octave's @code{sprintf} function
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
668 returns the string, automatically sized to hold all of the items
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
669 converted.
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
670 @end deftypefn
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
671
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
672 The @code{printf} function can be used to print any number of arguments.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
673 The template string argument you supply in a call provides
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
674 information not only about the number of additional arguments, but also
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
675 about their types and what style should be used for printing them.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
676
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
677 Ordinary characters in the template string are simply written to the
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
678 output stream as-is, while @dfn{conversion specifications} introduced by
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
679 a @samp{%} character in the template cause subsequent arguments to be
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
680 formatted and written to the output stream. For example,
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
681 @cindex conversion specifications (@code{printf})
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
682
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
683 @smallexample
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
684 pct = 37;
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
685 filename = "foo.txt";
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
686 printf ("Processing of `%s' is %d%% finished.\nPlease be patient.\n",
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
687 filename, pct);
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
688 @end smallexample
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
689
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
690 @noindent
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
691 produces output like
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
692
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
693 @smallexample
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
694 Processing of `foo.txt' is 37% finished.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
695 Please be patient.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
696 @end smallexample
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
697
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
698 This example shows the use of the @samp{%d} conversion to specify that a
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
699 scalar argument should be printed in decimal notation, the @samp{%s}
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
700 conversion to specify printing of a string argument, and the @samp{%%}
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
701 conversion to print a literal @samp{%} character.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
702
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
703 There are also conversions for printing an integer argument as an
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
704 unsigned value in octal, decimal, or hexadecimal radix (@samp{%o},
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
705 @samp{%u}, or @samp{%x}, respectively); or as a character value
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
706 (@samp{%c}).
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
707
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
708 Floating-point numbers can be printed in normal, fixed-point notation
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
709 using the @samp{%f} conversion or in exponential notation using the
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
710 @samp{%e} conversion. The @samp{%g} conversion uses either @samp{%e}
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
711 or @samp{%f} format, depending on what is more appropriate for the
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
712 magnitude of the particular number.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
713
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
714 You can control formatting more precisely by writing @dfn{modifiers}
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
715 between the @samp{%} and the character that indicates which conversion
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
716 to apply. These slightly alter the ordinary behavior of the conversion.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
717 For example, most conversion specifications permit you to specify a
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
718 minimum field width and a flag indicating whether you want the result
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
719 left- or right-justified within the field.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
720
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
721 The specific flags and modifiers that are permitted and their
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
722 interpretation vary depending on the particular conversion. They're all
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
723 described in more detail in the following sections.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
724
2653
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
725 @node Output Conversion for Matrices, Output Conversion Syntax, Formatted Output, C-Style I/O Functions
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
726 @subsection Output Conversion for Matrices
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
727
2670
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
728 When given a matrix value, Octave's formatted output functions cycle
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
729 through the format template until all the values in the matrix have been
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
730 printed. For example,
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
731
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
732 @example
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
733 @group
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
734 printf ("%4.2f %10.2e %8.4g\n", hilb (3));
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
735
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
736 @print{} 1.00 5.00e-01 0.3333
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
737 @print{} 0.50 3.33e-01 0.25
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
738 @print{} 0.33 2.50e-01 0.2
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
739 @end group
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
740 @end example
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
741
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
742 If more than one value is to be printed in a single call, the output
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
743 functions do not return to the beginning of the format template when
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
744 moving on from one value to the next. This can lead to confusing output
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
745 if the number of elements in the matrices are not exact multiples of the
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
746 number of conversions in the format template. For example,
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
747
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
748 @example
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
749 @group
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
750 printf ("%4.2f %10.2e %8.4g\n", [1, 2], [3, 4]);
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
751
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
752 @print{} 1.00 2.00e+00 3
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
753 @print{} 4.00
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
754 @end group
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
755 @end example
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
756
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
757 If this is not what you want, use a series of calls instead of just one.
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
758
2653
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
759 @node Output Conversion Syntax, Table of Output Conversions, Output Conversion for Matrices, C-Style I/O Functions
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
760 @subsection Output Conversion Syntax
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
761
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
762 This section provides details about the precise syntax of conversion
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
763 specifications that can appear in a @code{printf} template
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
764 string.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
765
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
766 Characters in the template string that are not part of a
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
767 conversion specification are printed as-is to the output stream.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
768
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
769 The conversion specifications in a @code{printf} template string have
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
770 the general form:
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
771
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
772 @smallexample
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
773 % @var{flags} @var{width} @r{[} . @var{precision} @r{]} @var{type} @var{conversion}
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
774 @end smallexample
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
775
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
776 For example, in the conversion specifier @samp{%-10.8ld}, the @samp{-}
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
777 is a flag, @samp{10} specifies the field width, the precision is
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
778 @samp{8}, the letter @samp{l} is a type modifier, and @samp{d} specifies
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
779 the conversion style. (This particular type specifier says to print a
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
780 numeric argument in decimal notation, with a minimum of 8 digits
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
781 left-justified in a field at least 10 characters wide.)
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
782
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
783 In more detail, output conversion specifications consist of an
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
784 initial @samp{%} character followed in sequence by:
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
785
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
786 @itemize @bullet
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
787 @item
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
788 Zero or more @dfn{flag characters} that modify the normal behavior of
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
789 the conversion specification.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
790 @cindex flag character (@code{printf})
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
791
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
792 @item
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
793 An optional decimal integer specifying the @dfn{minimum field width}.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
794 If the normal conversion produces fewer characters than this, the field
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
795 is padded with spaces to the specified width. This is a @emph{minimum}
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
796 value; if the normal conversion produces more characters than this, the
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
797 field is @emph{not} truncated. Normally, the output is right-justified
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
798 within the field.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
799 @cindex minimum field width (@code{printf})
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
800
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
801 You can also specify a field width of @samp{*}. This means that the
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
802 next argument in the argument list (before the actual value to be
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
803 printed) is used as the field width. The value is rounded to the
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
804 nearest integer. If the value is negative, this means to set the
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
805 @samp{-} flag (see below) and to use the absolute value as the field
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
806 width.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
807
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
808 @item
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
809 An optional @dfn{precision} to specify the number of digits to be
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
810 written for the numeric conversions. If the precision is specified, it
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
811 consists of a period (@samp{.}) followed optionally by a decimal integer
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
812 (which defaults to zero if omitted).
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
813 @cindex precision (@code{printf})
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
814
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
815 You can also specify a precision of @samp{*}. This means that the next
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
816 argument in the argument list (before the actual value to be printed) is
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
817 used as the precision. The value must be an integer, and is ignored
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
818 if it is negative.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
819
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
820 @item
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
821 An optional @dfn{type modifier character}. This character is ignored by
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
822 Octave's @code{printf} function, but is recognized to provide
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
823 compatibility with the C language @code{printf}.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
824
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
825 @item
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
826 A character that specifies the conversion to be applied.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
827 @end itemize
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
828
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
829 The exact options that are permitted and how they are interpreted vary
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
830 between the different conversion specifiers. See the descriptions of the
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
831 individual conversions for information about the particular options that
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
832 they use.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
833
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
834 @node Table of Output Conversions, Integer Conversions, Output Conversion Syntax, C-Style I/O Functions
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
835 @subsection Table of Output Conversions
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
836 @cindex output conversions, for @code{printf}
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
837
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
838 Here is a table summarizing what all the different conversions do:
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
839
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
840 @table @asis
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
841 @item @samp{%d}, @samp{%i}
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
842 Print an integer as a signed decimal number. @xref{Integer
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
843 Conversions}, for details. @samp{%d} and @samp{%i} are synonymous for
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
844 output, but are different when used with @code{scanf} for input
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
845 (@pxref{Table of Input Conversions}).
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
846
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
847 @item @samp{%o}
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
848 Print an integer as an unsigned octal number. @xref{Integer
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
849 Conversions}, for details.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
850
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
851 @item @samp{%u}
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
852 Print an integer as an unsigned decimal number. @xref{Integer
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
853 Conversions}, for details.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
854
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
855 @item @samp{%x}, @samp{%X}
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
856 Print an integer as an unsigned hexadecimal number. @samp{%x} uses
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
857 lower-case letters and @samp{%X} uses upper-case. @xref{Integer
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
858 Conversions}, for details.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
859
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
860 @item @samp{%f}
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
861 Print a floating-point number in normal (fixed-point) notation.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
862 @xref{Floating-Point Conversions}, for details.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
863
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
864 @item @samp{%e}, @samp{%E}
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
865 Print a floating-point number in exponential notation. @samp{%e} uses
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
866 lower-case letters and @samp{%E} uses upper-case. @xref{Floating-Point
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
867 Conversions}, for details.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
868
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
869 @item @samp{%g}, @samp{%G}
2535
caa21ce81913 [project @ 1996-11-19 19:53:55 by jwe]
jwe
parents: 2449
diff changeset
870 Print a floating-point number in either normal (fixed-point) or
caa21ce81913 [project @ 1996-11-19 19:53:55 by jwe]
jwe
parents: 2449
diff changeset
871 exponential notation, whichever is more appropriate for its magnitude.
caa21ce81913 [project @ 1996-11-19 19:53:55 by jwe]
jwe
parents: 2449
diff changeset
872 @samp{%g} uses lower-case letters and @samp{%G} uses upper-case.
caa21ce81913 [project @ 1996-11-19 19:53:55 by jwe]
jwe
parents: 2449
diff changeset
873 @xref{Floating-Point Conversions}, for details.
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
874
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
875 @item @samp{%c}
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
876 Print a single character. @xref{Other Output Conversions}.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
877
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
878 @item @samp{%s}
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
879 Print a string. @xref{Other Output Conversions}.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
880
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
881 @item @samp{%%}
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
882 Print a literal @samp{%} character. @xref{Other Output Conversions}.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
883 @end table
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
884
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
885 If the syntax of a conversion specification is invalid, unpredictable
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
886 things will happen, so don't do this. If there aren't enough function
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
887 arguments provided to supply values for all the conversion
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
888 specifications in the template string, or if the arguments are not of
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
889 the correct types, the results are unpredictable. If you supply more
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
890 arguments than conversion specifications, the extra argument values are
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
891 simply ignored; this is sometimes useful.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
892
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
893 @node Integer Conversions, Floating-Point Conversions, Table of Output Conversions, C-Style I/O Functions
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
894 @subsection Integer Conversions
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
895
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
896 This section describes the options for the @samp{%d}, @samp{%i},
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
897 @samp{%o}, @samp{%u}, @samp{%x}, and @samp{%X} conversion
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
898 specifications. These conversions print integers in various formats.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
899
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
900 The @samp{%d} and @samp{%i} conversion specifications both print an
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
901 numeric argument as a signed decimal number; while @samp{%o},
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
902 @samp{%u}, and @samp{%x} print the argument as an unsigned octal,
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
903 decimal, or hexadecimal number (respectively). The @samp{%X} conversion
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
904 specification is just like @samp{%x} except that it uses the characters
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
905 @samp{ABCDEF} as digits instead of @samp{abcdef}.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
906
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
907 The following flags are meaningful:
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
908
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
909 @table @asis
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
910 @item @samp{-}
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
911 Left-justify the result in the field (instead of the normal
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
912 right-justification).
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
913
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
914 @item @samp{+}
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
915 For the signed @samp{%d} and @samp{%i} conversions, print a
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
916 plus sign if the value is positive.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
917
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
918 @item @samp{ }
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
919 For the signed @samp{%d} and @samp{%i} conversions, if the result
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
920 doesn't start with a plus or minus sign, prefix it with a space
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
921 character instead. Since the @samp{+} flag ensures that the result
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
922 includes a sign, this flag is ignored if you supply both of them.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
923
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
924 @item @samp{#}
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
925 For the @samp{%o} conversion, this forces the leading digit to be
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
926 @samp{0}, as if by increasing the precision. For @samp{%x} or
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
927 @samp{%X}, this prefixes a leading @samp{0x} or @samp{0X} (respectively)
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
928 to the result. This doesn't do anything useful for the @samp{%d},
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
929 @samp{%i}, or @samp{%u} conversions.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
930
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
931 @item @samp{0}
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
932 Pad the field with zeros instead of spaces. The zeros are placed after
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
933 any indication of sign or base. This flag is ignored if the @samp{-}
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
934 flag is also specified, or if a precision is specified.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
935 @end table
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
936
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
937 If a precision is supplied, it specifies the minimum number of digits to
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
938 appear; leading zeros are produced if necessary. If you don't specify a
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
939 precision, the number is printed with as many digits as it needs. If
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
940 you convert a value of zero with an explicit precision of zero, then no
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
941 characters at all are produced.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
942
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
943 @node Floating-Point Conversions, Other Output Conversions, Integer Conversions, C-Style I/O Functions
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
944 @subsection Floating-Point Conversions
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
945
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
946 This section discusses the conversion specifications for floating-point
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
947 numbers: the @samp{%f}, @samp{%e}, @samp{%E}, @samp{%g}, and @samp{%G}
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
948 conversions.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
949
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
950 The @samp{%f} conversion prints its argument in fixed-point notation,
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
951 producing output of the form
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
952 @w{[@code{-}]@var{ddd}@code{.}@var{ddd}},
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
953 where the number of digits following the decimal point is controlled
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
954 by the precision you specify.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
955
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
956 The @samp{%e} conversion prints its argument in exponential notation,
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
957 producing output of the form
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
958 @w{[@code{-}]@var{d}@code{.}@var{ddd}@code{e}[@code{+}|@code{-}]@var{dd}}.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
959 Again, the number of digits following the decimal point is controlled by
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
960 the precision. The exponent always contains at least two digits. The
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
961 @samp{%E} conversion is similar but the exponent is marked with the letter
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
962 @samp{E} instead of @samp{e}.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
963
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
964 The @samp{%g} and @samp{%G} conversions print the argument in the style
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
965 of @samp{%e} or @samp{%E} (respectively) if the exponent would be less
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
966 than -4 or greater than or equal to the precision; otherwise they use the
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
967 @samp{%f} style. Trailing zeros are removed from the fractional portion
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
968 of the result and a decimal-point character appears only if it is
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
969 followed by a digit.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
970
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
971 The following flags can be used to modify the behavior:
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
972
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
973 @c Not @samp so we can have ` ' as an item.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
974 @table @asis
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
975 @item @samp{-}
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
976 Left-justify the result in the field. Normally the result is
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
977 right-justified.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
978
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
979 @item @samp{+}
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
980 Always include a plus or minus sign in the result.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
981
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
982 @item @samp{ }
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
983 If the result doesn't start with a plus or minus sign, prefix it with a
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
984 space instead. Since the @samp{+} flag ensures that the result includes
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
985 a sign, this flag is ignored if you supply both of them.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
986
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
987 @item @samp{#}
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
988 Specifies that the result should always include a decimal point, even
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
989 if no digits follow it. For the @samp{%g} and @samp{%G} conversions,
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
990 this also forces trailing zeros after the decimal point to be left
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
991 in place where they would otherwise be removed.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
992
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
993 @item @samp{0}
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
994 Pad the field with zeros instead of spaces; the zeros are placed
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
995 after any sign. This flag is ignored if the @samp{-} flag is also
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
996 specified.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
997 @end table
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
998
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
999 The precision specifies how many digits follow the decimal-point
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1000 character for the @samp{%f}, @samp{%e}, and @samp{%E} conversions. For
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1001 these conversions, the default precision is @code{6}. If the precision
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1002 is explicitly @code{0}, this suppresses the decimal point character
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1003 entirely. For the @samp{%g} and @samp{%G} conversions, the precision
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1004 specifies how many significant digits to print. Significant digits are
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1005 the first digit before the decimal point, and all the digits after it.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1006 If the precision is @code{0} or not specified for @samp{%g} or
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1007 @samp{%G}, it is treated like a value of @code{1}. If the value being
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1008 printed cannot be expressed precisely in the specified number of digits,
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1009 the value is rounded to the nearest number that fits.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1010
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1011 @node Other Output Conversions, Formatted Input, Floating-Point Conversions, C-Style I/O Functions
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1012 @subsection Other Output Conversions
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1013
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1014 This section describes miscellaneous conversions for @code{printf}.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1015
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1016 The @samp{%c} conversion prints a single character. The @samp{-}
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1017 flag can be used to specify left-justification in the field, but no
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1018 other flags are defined, and no precision or type modifier can be given.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1019 For example:
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1020
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1021 @smallexample
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1022 printf ("%c%c%c%c%c", "h", "e", "l", "l", "o");
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1023 @end smallexample
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1024
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1025 @noindent
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1026 prints @samp{hello}.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1027
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1028 The @samp{%s} conversion prints a string. The corresponding argument
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1029 must be a string. A precision can be specified to indicate the maximum
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1030 number of characters to write; otherwise characters in the string up to
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1031 but not including the terminating null character are written to the
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1032 output stream. The @samp{-} flag can be used to specify
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1033 left-justification in the field, but no other flags or type modifiers
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1034 are defined for this conversion. For example:
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1035
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1036 @smallexample
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1037 printf ("%3s%-6s", "no", "where");
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1038 @end smallexample
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1039
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1040 @noindent
2653
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
1041 prints @samp{ nowhere } (note the leading and trailing spaces).
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1042
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1043 @node Formatted Input, Input Conversion Syntax, Other Output Conversions, C-Style I/O Functions
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1044 @subsection Formatted Input
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1045
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1046 Here are the descriptions of the functions for performing formatted
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1047 input.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1048
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
1049 @deftypefn {Built-in Function} {} scanf (@var{template})
2653
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
1050 @deftypefnx {Built-in Function} {} scanf (@var{template}, "C")
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1051 The @code{scanf} function reads formatted input from the stream
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1052 @code{stdin} under the control of the template string @var{template}.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1053 The resulting values are returned.
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
1054 @end deftypefn
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1055
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
1056 @deftypefn {Built-in Function} {} fscanf (@var{fid}, @var{template})
2653
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
1057 @deftypefnx {Built-in Function} {} fscanf (@var{fid}, @var{template}, "C")
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1058 This function is just like @code{scanf}, except that the input is read
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
1059 from the stream @var{fid} instead of @code{stdin}.
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
1060 @end deftypefn
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1061
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
1062 @deftypefn {Built-in Function} {} sscanf (@var{string}, @var{template})
2653
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
1063 @deftypefnx {Built-in Function} {} sscanf (@var{string}, @var{template}, "C")
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1064 This is like @code{scanf}, except that the characters are taken from the
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1065 string @var{string} instead of from a stream. Reaching the end of the
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1066 string is treated as an end-of-file condition.
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
1067 @end deftypefn
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1068
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1069 Calls to @code{scanf} are superficially similar to calls to
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1070 @code{printf} in that arbitrary arguments are read under the control of
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1071 a template string. While the syntax of the conversion specifications in
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1072 the template is very similar to that for @code{printf}, the
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1073 interpretation of the template is oriented more towards free-format
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1074 input and simple pattern matching, rather than fixed-field formatting.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1075 For example, most @code{scanf} conversions skip over any amount of
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1076 ``white space'' (including spaces, tabs, and newlines) in the input
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1077 file, and there is no concept of precision for the numeric input
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1078 conversions as there is for the corresponding output conversions.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1079 Ordinarily, non-whitespace characters in the template are expected to
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1080 match characters in the input stream exactly.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1081 @cindex conversion specifications (@code{scanf})
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1082
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1083 When a @dfn{matching failure} occurs, @code{scanf} returns immediately,
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1084 leaving the first non-matching character as the next character to be
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1085 read from the stream, and @code{scanf} returns all the items that were
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1086 successfully converted.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1087 @cindex matching failure, in @code{scanf}
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1088
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1089 The formatted input functions are not used as frequently as the
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1090 formatted output functions. Partly, this is because it takes some care
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1091 to use them properly. Another reason is that it is difficult to recover
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1092 from a matching error.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1093
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1094 @node Input Conversion Syntax, Table of Input Conversions, Formatted Input, C-Style I/O Functions
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1095 @subsection Input Conversion Syntax
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1096
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1097 A @code{scanf} template string is a string that contains ordinary
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1098 multibyte characters interspersed with conversion specifications that
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1099 start with @samp{%}.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1100
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1101 Any whitespace character in the template causes any number of whitespace
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1102 characters in the input stream to be read and discarded. The whitespace
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1103 characters that are matched need not be exactly the same whitespace
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1104 characters that appear in the template string. For example, write
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1105 @samp{ , } in the template to recognize a comma with optional whitespace
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1106 before and after.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1107
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1108 Other characters in the template string that are not part of conversion
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1109 specifications must match characters in the input stream exactly; if
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1110 this is not the case, a matching failure occurs.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1111
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1112 The conversion specifications in a @code{scanf} template string
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1113 have the general form:
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1114
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1115 @smallexample
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1116 % @var{flags} @var{width} @var{type} @var{conversion}
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1117 @end smallexample
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1118
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1119 In more detail, an input conversion specification consists of an initial
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1120 @samp{%} character followed in sequence by:
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1121
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1122 @itemize @bullet
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1123 @item
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1124 An optional @dfn{flag character} @samp{*}, which says to ignore the text
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1125 read for this specification. When @code{scanf} finds a conversion
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1126 specification that uses this flag, it reads input as directed by the
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1127 rest of the conversion specification, but it discards this input, does
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1128 not use a pointer argument, and does not increment the count of
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1129 successful assignments.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1130 @cindex flag character (@code{scanf})
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1131
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1132 @item
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1133 An optional decimal integer that specifies the @dfn{maximum field
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1134 width}. Reading of characters from the input stream stops either when
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1135 this maximum is reached or when a non-matching character is found,
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1136 whichever happens first. Most conversions discard initial whitespace
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1137 characters (those that don't are explicitly documented), and these
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1138 discarded characters don't count towards the maximum field width.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1139 @cindex maximum field width (@code{scanf})
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1140
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1141 @item
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1142 An optional type modifier character. This character is ignored by
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1143 Octave's @code{scanf} function, but is recognized to provide
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1144 compatibility with the C language @code{scanf}.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1145
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1146 @item
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1147 A character that specifies the conversion to be applied.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1148 @end itemize
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1149
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1150 The exact options that are permitted and how they are interpreted vary
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1151 between the different conversion specifiers. See the descriptions of the
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1152 individual conversions for information about the particular options that
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1153 they allow.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1154
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1155 @node Table of Input Conversions, Numeric Input Conversions, Input Conversion Syntax, C-Style I/O Functions
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1156 @subsection Table of Input Conversions
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1157 @cindex input conversions, for @code{scanf}
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1158
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1159 Here is a table that summarizes the various conversion specifications:
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1160
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1161 @table @asis
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1162 @item @samp{%d}
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1163 Matches an optionally signed integer written in decimal. @xref{Numeric
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1164 Input Conversions}.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1165
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1166 @item @samp{%i}
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1167 Matches an optionally signed integer in any of the formats that the C
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1168 language defines for specifying an integer constant. @xref{Numeric
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1169 Input Conversions}.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1170
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1171 @item @samp{%o}
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1172 Matches an unsigned integer written in octal radix.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1173 @xref{Numeric Input Conversions}.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1174
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1175 @item @samp{%u}
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1176 Matches an unsigned integer written in decimal radix.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1177 @xref{Numeric Input Conversions}.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1178
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1179 @item @samp{%x}, @samp{%X}
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1180 Matches an unsigned integer written in hexadecimal radix.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1181 @xref{Numeric Input Conversions}.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1182
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1183 @item @samp{%e}, @samp{%f}, @samp{%g}, @samp{%E}, @samp{%G}
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1184 Matches an optionally signed floating-point number. @xref{Numeric Input
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1185 Conversions}.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1186
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1187 @item @samp{%s}
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1188 Matches a string containing only non-whitespace characters.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1189 @xref{String Input Conversions}.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1190
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1191 @item @samp{%c}
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1192 Matches a string of one or more characters; the number of characters
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1193 read is controlled by the maximum field width given for the conversion.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1194 @xref{String Input Conversions}.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1195
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1196 @item @samp{%%}
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1197 This matches a literal @samp{%} character in the input stream. No
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1198 corresponding argument is used.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1199 @end table
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1200
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1201 If the syntax of a conversion specification is invalid, the behavior is
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1202 undefined. If there aren't enough function arguments provided to supply
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1203 addresses for all the conversion specifications in the template strings
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1204 that perform assignments, or if the arguments are not of the correct
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1205 types, the behavior is also undefined. On the other hand, extra
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1206 arguments are simply ignored.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1207
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1208 @node Numeric Input Conversions, String Input Conversions, Table of Input Conversions, C-Style I/O Functions
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1209 @subsection Numeric Input Conversions
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1210
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1211 This section describes the @code{scanf} conversions for reading numeric
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1212 values.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1213
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1214 The @samp{%d} conversion matches an optionally signed integer in decimal
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1215 radix.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1216
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1217 The @samp{%i} conversion matches an optionally signed integer in any of
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1218 the formats that the C language defines for specifying an integer
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1219 constant.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1220
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1221 For example, any of the strings @samp{10}, @samp{0xa}, or @samp{012}
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1222 could be read in as integers under the @samp{%i} conversion. Each of
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1223 these specifies a number with decimal value @code{10}.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1224
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1225 The @samp{%o}, @samp{%u}, and @samp{%x} conversions match unsigned
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1226 integers in octal, decimal, and hexadecimal radices, respectively.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1227
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1228 The @samp{%X} conversion is identical to the @samp{%x} conversion. They
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1229 both permit either uppercase or lowercase letters to be used as digits.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1230
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1231 Unlike the C language @code{scanf}, Octave ignores the @samp{h},
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1232 @samp{l}, and @samp{L} modifiers.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1233
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1234 @node String Input Conversions, Binary I/O, Numeric Input Conversions, C-Style I/O Functions
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1235 @subsection String Input Conversions
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1236
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1237 This section describes the @code{scanf} input conversions for reading
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1238 string and character values: @samp{%s} and @samp{%c}.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1239
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1240 The @samp{%c} conversion is the simplest: it matches a fixed number of
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1241 characters, always. The maximum field with says how many characters to
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1242 read; if you don't specify the maximum, the default is 1. This
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1243 conversion does not skip over initial whitespace characters. It reads
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1244 precisely the next @var{n} characters, and fails if it cannot get that
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1245 many.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1246
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1247 The @samp{%s} conversion matches a string of non-whitespace characters.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1248 It skips and discards initial whitespace, but stops when it encounters
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1249 more whitespace after having read something.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1250
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1251 For example, reading the input:
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1252
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1253 @smallexample
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1254 hello, world
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1255 @end smallexample
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1256
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1257 @noindent
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1258 with the conversion @samp{%10c} produces @code{" hello, wo"}, but
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1259 reading the same input with the conversion @samp{%10s} produces
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1260 @code{"hello,"}.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1261
2670
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
1262 @node Binary I/O, Temporary Files, String Input Conversions, C-Style I/O Functions
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1263 @subsection Binary I/O
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1264
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1265 Octave has to C-style functions for reading and writing binary data.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1266 They are @code{fread} and @code{fwrite} and are patterned after the
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1267 standard C functions with the same names.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1268
2653
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
1269 @deftypefn {Built-in Function} {} fread (@var{fid}, @var{size}, @var{precision}, @var{arch})
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1270 This function reads data in binary form of type @var{precision} from the
2653
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
1271 specified @var{fid}, which may be either a file name, or a file id
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1272 as returned from @code{fopen}.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1273
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1274 The argument @var{size} specifies the size of the matrix to return. It
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1275 may be a scalar or a two-element vector. If it is a scalar,
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1276 @code{fread} returns a column vector of the specified length. If it is
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1277 a two-element vector, it specifies the number of rows and columns of the
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1278 result matrix, and @code{fread} fills the elements of the matrix in
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1279 column-major order.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1280
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1281 The argument @var{precision} is a string specifying the type of data to
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1282 read and may be one of @code{"char"}, @code{"schar"}, @code{"short"},
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1283 @code{"int"}, @code{"long"}, @code{"float"}, @code{"double"},
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1284 @code{"uchar"}, @code{"ushort"}, @code{"uint"}, or @code{"ulong"}. The
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1285 default precision is @code{"uchar"}.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1286
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1287 The @code{fread} function returns two values, @code{data}, which is the
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1288 data read from the file, and @code{count}, which is the number of
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1289 elements read.
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
1290 @end deftypefn
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1291
2653
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
1292 @deftypefn {Built-in Function} {} fwrite (@var{fid}, @var{data}, @var{precision}, @var{arch})
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1293 This function writes data in binary form of type @var{precision} to the
2653
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
1294 specified @var{fid}, which may be either a file name, or a file id
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1295 as returned from @code{fopen}.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1296
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1297 The argument @var{data} is a matrix of values that are to be written to
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1298 the file. The values are extracted in column-major order.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1299
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1300 The argument @var{precision} is a string specifying the type of data to
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1301 read and may be one of @code{"char"}, @code{"schar"}, @code{"short"},
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1302 @code{"int"}, @code{"long"}, @code{"float"}, @code{"double"},
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1303 @code{"uchar"}, @code{"ushort"}, @code{"uint"}, or @code{"ulong"}. The
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1304 default precision is @code{"uchar"}.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1305
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1306 The @code{fwrite} function returns the number of elements written.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1307
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1308 The behavior of @code{fwrite} is undefined if the values in @var{data}
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1309 are too large to fit in the specified precision.
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
1310 @end deftypefn
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1311
2670
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
1312 @node Temporary Files, EOF and Errors, Binary I/O, C-Style I/O Functions
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
1313 @subsection Temporary Files
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1314
2670
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
1315 @deftypefn {Built-in Function} {} tmpnam ()
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
1316 Return a unique temporary file name as a string.
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
1317
2670
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
1318 Since the named file is not opened, by @code{tmpnam}, it
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
1319 is possible (though relatively unlikely) that it will not be available
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
1320 by the time your program attempts to open it.
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
1321 @end deftypefn
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1322
2670
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
1323 @node EOF and Errors, File Positioning, Temporary Files, C-Style I/O Functions
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
1324 @subsection End of File and Errors
2653
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
1325
2670
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
1326 @deftypefn {Built-in Function} {} feof (@var{fid})
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
1327 Returns 1 if an end-of-file condition has been encountered for a given
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
1328 file and 0 otherwise. Note that it will only return 1 if the end of the
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
1329 file has already been encountered, not if the next read operation will
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
1330 result in an end-of-file condition.
2653
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
1331 @end deftypefn
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
1332
2670
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
1333 @deftypefn {Built-in Function} {} ferror (@var{fid})
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
1334 Returns 1 if an error condition has been encountered for a given file
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
1335 and 0 otherwise. Note that it will only return 1 if an error has
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
1336 already been encountered, not if the next operation will result in an
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
1337 error condition.
2653
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
1338 @end deftypefn
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
1339
2670
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
1340 @deftypefn {Built-in Function} {} freport ()
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
1341 Print a list of which files have been opened, and whether they are open
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
1342 for reading, writing, or both. For example,
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
1343
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
1344 @example
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
1345 @group
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
1346 freport ()
2653
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
1347
2670
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
1348 @print{} number mode name
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
1349 @print{}
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
1350 @print{} 0 r stdin
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
1351 @print{} 1 w stdout
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
1352 @print{} 2 w stderr
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
1353 @print{} 3 r myfile
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
1354 @end group
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
1355 @end example
2653
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
1356 @end deftypefn
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
1357
2670
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
1358 @node File Positioning, , EOF and Errors, C-Style I/O Functions
18192eea4973 [project @ 1997-02-13 18:29:53 by jwe]
jwe
parents: 2653
diff changeset
1359 @subsection File Positioning
2653
e7908588548a [project @ 1997-02-01 16:53:52 by jwe]
jwe
parents: 2535
diff changeset
1360
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1361 Three functions are available for setting and determining the position of
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1362 the file pointer for a given file.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1363
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
1364 @deftypefn {Built-in Function} {} ftell (@var{fid})
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
1365 Return the position of the file pointer as the number of characters
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
1366 from the beginning of the file @var{fid}.
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
1367 @end deftypefn
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1368
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
1369 @deftypefn {Built-in Function} {} fseek (@var{fid}, offset, origin)
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
1370 Set the file pointer to any location within the file @var{fid}. The
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
1371 pointer is positioned @code{offset} characters from the @code{origin},
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
1372 which may be one of the predefined variables @code{SEEK_CUR} (current
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
1373 position), @code{SEEK_SET} (beginning), or @code{SEEK_END} (end of
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
1374 file). If @code{origin} is omitted, @code{SEEK_SET} is assumed. The
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
1375 offset must be zero, or a value returned by @code{ftell} (in which case
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
1376 @code{origin} must be @code{SEEK_SET}.
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
1377 @end deftypefn
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1378
2449
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
1379 @defvr {Built-in Variable} SEEK_SET
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
1380 @defvrx {Built-in Variable} SEEK_CUR
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
1381 @defvrx {Built-in Variable} SEEK_END
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
1382 These variables may be used as the optional third argument for the
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
1383 function @code{fseek}.
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
1384 @end defvr
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
1385
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
1386 @deftypefn {Built-in Function} {} frewind (@var{fid})
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
1387 Move the file pointer to the beginning of the file @var{fid}, returning
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
1388 1 for success, and 0 if an error was encountered. It is equivalent to
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
1389 @code{fseek (@var{fid}, 0, SEEK_SET)}.
31d5588dbb61 [project @ 1996-10-30 22:58:44 by jwe]
jwe
parents: 2333
diff changeset
1390 @end deftypefn
2333
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1391
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1392 The following example stores the current file position in the variable
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1393 @samp{marker}, moves the pointer to the beginning of the file, reads
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1394 four characters, and then returns to the original position.
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1395
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1396 @example
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1397 marker = ftell (myfile);
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1398 frewind (myfile);
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1399 fourch = fgets (myfile, 4);
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1400 fseek (myfile, marker, SEEK_SET);
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1401 @end example
b1a56412c385 [project @ 1996-07-19 02:20:16 by jwe]
jwe
parents:
diff changeset
1402