annotate src/pr-output.cc @ 10706:6f34e781aed2

Second try at removing extra newlines from NDArrays
author Rik <octave@nomad.inbox5.com>
date Tue, 15 Jun 2010 09:55:00 -0700
parents d500acdcf2dd
children 38bdcbb58df7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1 /*
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2
7017
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
8920
eb63fbe60fab update copyright notices
John W. Eaton <jwe@octave.org>
parents: 8891
diff changeset
4 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 John W. Eaton
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
5
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
6 This file is part of Octave.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
7
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
8 Octave is free software; you can redistribute it and/or modify it
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
10 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
11 option) any later version.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
12
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
13 Octave is distributed in the hope that it will be useful, but WITHOUT
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
16 for more details.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
17
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
19 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
20 <http://www.gnu.org/licenses/>.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
21
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
22 */
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
23
240
a99f28f5e351 [project @ 1993-11-30 20:24:36 by jwe]
jwe
parents: 217
diff changeset
24 #ifdef HAVE_CONFIG_H
1192
b6360f2d4fa6 [project @ 1995-03-30 21:38:35 by jwe]
jwe
parents: 1186
diff changeset
25 #include <config.h>
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
26 #endif
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
27
1346
9e41dbb74bca [project @ 1995-09-05 06:37:49 by jwe]
jwe
parents: 1343
diff changeset
28 #include <cfloat>
2825
60ae49e1284f [project @ 1997-03-25 23:17:36 by jwe]
jwe
parents: 2804
diff changeset
29 #include <cstdio>
1346
9e41dbb74bca [project @ 1995-09-05 06:37:49 by jwe]
jwe
parents: 1343
diff changeset
30 #include <cstring>
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1328
diff changeset
31
3503
d14c483b3c12 [project @ 2000-02-01 04:06:07 by jwe]
jwe
parents: 3373
diff changeset
32 #include <iomanip>
d14c483b3c12 [project @ 2000-02-01 04:06:07 by jwe]
jwe
parents: 3373
diff changeset
33 #include <iostream>
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5759
diff changeset
34 #include <sstream>
1728
42b4f904f1af [project @ 1996-01-09 11:36:01 by jwe]
jwe
parents: 1716
diff changeset
35 #include <string>
42b4f904f1af [project @ 1996-01-09 11:36:01 by jwe]
jwe
parents: 1716
diff changeset
36
4655
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
37 #include "Array-util.h"
453
393e95f46b51 [project @ 1994-06-06 00:05:20 by jwe]
jwe
parents: 296
diff changeset
38 #include "CMatrix.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
39 #include "Range.h"
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
40 #include "cmd-edit.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1346
diff changeset
41 #include "dMatrix.h"
2891
1a30f46e1870 [project @ 1997-04-28 01:49:00 by jwe]
jwe
parents: 2847
diff changeset
42 #include "lo-mappers.h"
7231
2eb392d058bb [project @ 2007-11-30 18:53:29 by jwe]
jwe
parents: 7215
diff changeset
43 #include "lo-math.h"
2317
8c09c04f7747 [project @ 1996-07-14 22:30:15 by jwe]
jwe
parents: 2305
diff changeset
44 #include "mach-info.h"
1651
e846e361a265 [project @ 1995-12-20 06:59:12 by jwe]
jwe
parents: 1588
diff changeset
45 #include "oct-cmplx.h"
4153
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents: 4051
diff changeset
46 #include "quit.h"
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
47 #include "str-vec.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
48
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
49 #include "Cell.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1346
diff changeset
50 #include "defun.h"
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1346
diff changeset
51 #include "error.h"
2165
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
52 #include "gripes.h"
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
53 #include "oct-obj.h"
3685
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
54 #include "oct-stream.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1346
diff changeset
55 #include "pager.h"
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1346
diff changeset
56 #include "pr-output.h"
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
57 #include "sysdep.h"
6803
fe19c6cb5bc6 [project @ 2007-07-26 18:04:05 by jwe]
jwe
parents: 6788
diff changeset
58 #include "unwind-prot.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
59 #include "utils.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1346
diff changeset
60 #include "variables.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
61
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
62 // TRUE means use a scaled fixed point format for `format long' and
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
63 // `format short'.
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
64 static bool Vfixed_point_format = false;
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
65
2165
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
66 // The maximum field width for a number printed by the default output
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
67 // routines.
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
68 static int Voutput_max_field_width = 10;
2165
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
69
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
70 // The precision of the numbers printed by the default output
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
71 // routines.
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
72 static int Voutput_precision = 5;
2165
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
73
5360
33adb987c033 [project @ 2005-05-23 16:19:56 by jwe]
jwe
parents: 5331
diff changeset
74 // TRUE means that the dimensions of empty objects should be printed
2165
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
75 // like this: x = [](2x0).
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
76 bool Vprint_empty_dimensions = true;
2165
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
77
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
78 // TRUE means that the rows of big matrices should be split into
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
79 // smaller slices that fit on the screen.
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
80 static bool Vsplit_long_rows = true;
2165
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
81
5759
ce79d238f142 [project @ 2006-04-13 13:04:32 by jwe]
jwe
parents: 5748
diff changeset
82 // How many levels of structure elements should we print?
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
83 int Vstruct_levels_to_print = 2;
5759
ce79d238f142 [project @ 2006-04-13 13:04:32 by jwe]
jwe
parents: 5748
diff changeset
84
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3014
diff changeset
85 // TRUE means don't do any fancy formatting.
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
86 static bool free_format = false;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
87
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3014
diff changeset
88 // TRUE means print plus sign for nonzero, blank for zero.
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
89 static bool plus_format = false;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
90
4632
0e28461651f2 [project @ 2003-11-18 19:07:13 by jwe]
jwe
parents: 4574
diff changeset
91 // First char for > 0, second for < 0, third for == 0.
0e28461651f2 [project @ 2003-11-18 19:07:13 by jwe]
jwe
parents: 4574
diff changeset
92 static std::string plus_format_chars = "+ ";
0e28461651f2 [project @ 2003-11-18 19:07:13 by jwe]
jwe
parents: 4574
diff changeset
93
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
94 // TRUE means always print in a rational approximation
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
95 static bool rat_format = false;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
96
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
97 // Used to force the length of the rational approximation string for Frats
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
98 static int rat_string_len = -1;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
99
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3014
diff changeset
100 // TRUE means always print like dollars and cents.
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
101 static bool bank_format = false;
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
102
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3014
diff changeset
103 // TRUE means print data in hexadecimal format.
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
104 static int hex_format = 0;
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
105
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3014
diff changeset
106 // TRUE means print data in binary-bit-pattern format.
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
107 static int bit_format = 0;
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
108
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3014
diff changeset
109 // TRUE means don't put newlines around the column number headers.
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
110 static bool compact_format = false;
1186
d94bcafabac2 [project @ 1995-03-30 04:57:32 by jwe]
jwe
parents: 1086
diff changeset
111
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3014
diff changeset
112 // TRUE means use an e format.
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
113 static bool print_e = false;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
114
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
115 // TRUE means use a g format.
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
116 static bool print_g = false;
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
117
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3014
diff changeset
118 // TRUE means print E instead of e for exponent field.
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
119 static bool print_big_e = false;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
120
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
121 class pr_formatted_float;
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
122 class pr_rational_float;
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
123
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
124 static int
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
125 current_output_max_field_width (void)
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
126 {
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
127 return Voutput_max_field_width;
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
128 }
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
129
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
130 static int
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
131 current_output_precision (void)
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
132 {
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
133 return Voutput_precision;
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
134 }
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
135
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
136 class
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
137 float_format
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
138 {
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
139 public:
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
140
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
141 float_format (int w = current_output_max_field_width (),
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
142 int p = current_output_precision (), int f = 0)
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
143 : fw (w), prec (p), fmt (f), up (0), sp (0) { }
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
144
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
145 float_format (const float_format& ff)
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
146 : fw (ff.fw), prec (ff.prec), fmt (ff.fmt), up (ff.up), sp (ff.sp) { }
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
147
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
148 float_format& operator = (const float_format& ff)
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
149 {
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
150 if (&ff != this)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
151 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
152 fw = ff.fw;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
153 prec = ff.prec;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
154 fmt = ff.fmt;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
155 up = ff.up;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
156 sp = ff.sp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
157 }
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
158
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
159 return *this;
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
160 }
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
161
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
162 ~float_format (void) { }
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
163
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
164 float_format& scientific (void) { fmt = std::ios::scientific; return *this; }
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
165 float_format& fixed (void) { fmt = std::ios::fixed; return *this; }
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
166 float_format& general (void) { fmt = 0; return *this; }
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
167
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
168 float_format& uppercase (void) { up = std::ios::uppercase; return *this; }
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
169 float_format& lowercase (void) { up = 0; return *this; }
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
170
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
171 float_format& precision (int p) { prec = p; return *this; }
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
172
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
173 float_format& width (int w) { fw = w; return *this; }
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
174
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
175 float_format& trailing_zeros (bool tz = true)
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
176 { sp = tz ? std::ios::showpoint : 0; return *this; }
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
177
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
178 friend std::ostream& operator << (std::ostream& os,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
179 const pr_formatted_float& pff);
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
180
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
181 friend std::ostream& operator << (std::ostream& os,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
182 const pr_rational_float& pff);
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
183
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
184 private:
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
185
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
186 // Field width. Zero means as wide as necessary.
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
187 int fw;
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
188
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
189 // Precision.
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
190 int prec;
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
191
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
192 // Format.
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
193 int fmt;
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
194
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
195 // E or e.
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
196 int up;
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
197
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
198 // Show trailing zeros.
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
199 int sp;
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
200 };
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
201
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
202 class
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
203 pr_formatted_float
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
204 {
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
205 public:
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
206
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
207 const float_format& f;
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
208
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
209 double val;
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
210
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
211 pr_formatted_float (const float_format& f_arg, double val_arg)
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
212 : f (f_arg), val (val_arg) { }
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
213 };
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
214
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
215 std::ostream&
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
216 operator << (std::ostream& os, const pr_formatted_float& pff)
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
217 {
3682
19e1ac7359fb [project @ 2000-06-27 03:23:10 by jwe]
jwe
parents: 3611
diff changeset
218 if (pff.f.fw >= 0)
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
219 os << std::setw (pff.f.fw);
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
220
3682
19e1ac7359fb [project @ 2000-06-27 03:23:10 by jwe]
jwe
parents: 3611
diff changeset
221 if (pff.f.prec >= 0)
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
222 os << std::setprecision (pff.f.prec);
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
223
3775
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3769
diff changeset
224 std::ios::fmtflags oflags =
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3769
diff changeset
225 os.flags (static_cast<std::ios::fmtflags>
13905c3a24af [project @ 2001-02-06 01:56:59 by jwe]
jwe
parents: 3769
diff changeset
226 (pff.f.fmt | pff.f.up | pff.f.sp));
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
227
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
228 os << pff.val;
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
229
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
230 os.flags (oflags);
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
231
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
232 return os;
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
233 }
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
234
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
235 static inline std::string
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
236 rational_approx (double val, int len)
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
237 {
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
238 std::string s;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
239
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
240 if (len <= 0)
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
241 len = 10;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
242
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
243 if (xisinf (val))
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
244 s = "1/0";
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
245 else if (xisnan (val))
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
246 s = "0/0";
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
247 else if (val < INT_MIN || val > INT_MAX || D_NINT (val) == val)
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
248 {
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
249 std::ostringstream buf;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
250 buf.flags (std::ios::fixed);
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
251 buf << std::setprecision (0) << xround(val);
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
252 s = buf.str ();
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
253 }
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
254 else
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
255 {
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
256 double lastn = 1.;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
257 double lastd = 0.;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
258 double n = xround (val);
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
259 double d = 1.;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
260 double frac = val - n;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
261 int m = 0;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
262
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
263 std::ostringstream buf2;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
264 buf2.flags (std::ios::fixed);
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
265 buf2 << std::setprecision (0) << static_cast<int>(n);
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
266 s = buf2.str();
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
267
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
268 while (1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
269 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
270 double flip = 1. / frac;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
271 double step = xround (flip);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
272 double nextn = n;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
273 double nextd = d;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
274
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
275 // Have we converged to 1/intmax ?
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
276 if (m > 100 || fabs (frac) < 1 / static_cast<double>(INT_MAX))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
277 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
278 lastn = n;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
279 lastd = d;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
280 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
281 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
282
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
283 frac = flip - step;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
284 n = n * step + lastn;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
285 d = d * step + lastd;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
286 lastn = nextn;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
287 lastd = nextd;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
288
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
289 std::ostringstream buf;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
290 buf.flags (std::ios::fixed);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
291 buf << std::setprecision (0) << static_cast<int>(n)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
292 << "/" << static_cast<int>(d);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
293 m++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
294
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
295 if (n < 0 && d < 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
296 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
297 // Double negative, string can be two characters longer..
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
298 if (buf.str().length() > static_cast<unsigned int>(len + 2) &&
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
299 m > 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
300 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
301 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
302 else if (buf.str().length() > static_cast<unsigned int>(len) &&
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
303 m > 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
304 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
305
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
306 s = buf.str();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
307 }
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
308
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
309 if (lastd < 0.)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
310 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
311 // Move sign to the top
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
312 lastd = - lastd;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
313 lastn = - lastn;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
314 std::ostringstream buf;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
315 buf.flags (std::ios::fixed);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
316 buf << std::setprecision (0) << static_cast<int>(lastn)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
317 << "/" << static_cast<int>(lastd);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
318 s = buf.str();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
319 }
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
320 }
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
321
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
322 return s;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
323 }
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
324
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
325 class
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
326 pr_rational_float
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
327 {
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
328 public:
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
329
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
330 const float_format& f;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
331
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
332 double val;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
333
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
334 pr_rational_float (const float_format& f_arg, double val_arg)
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
335 : f (f_arg), val (val_arg) { }
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
336 };
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
337
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
338 std::ostream&
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
339 operator << (std::ostream& os, const pr_rational_float& prf)
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
340 {
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
341 int fw = (rat_string_len > 0 ? rat_string_len : prf.f.fw);
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
342 std::string s = rational_approx (prf.val, fw);
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
343
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
344 if (fw >= 0)
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
345 os << std::setw (fw);
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
346
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
347 std::ios::fmtflags oflags =
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
348 os.flags (static_cast<std::ios::fmtflags>
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
349 (prf.f.fmt | prf.f.up | prf.f.sp));
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
350
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
351 if (fw > 0 && s.length() > static_cast<unsigned int>(fw))
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
352 os << "*";
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
353 else
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
354 os << s;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
355
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
356 os.flags (oflags);
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
357
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
358 return os;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
359 }
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
360
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
361 // Current format for real numbers and the real part of complex
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
362 // numbers.
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
363 static float_format *curr_real_fmt = 0;
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
364
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
365 // Current format for the imaginary part of complex numbers.
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
366 static float_format *curr_imag_fmt = 0;
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
367
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
368 static double
164
e2c950dd96d2 [project @ 1993-10-18 19:32:00 by jwe]
jwe
parents: 127
diff changeset
369 pr_max_internal (const Matrix& m)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
370 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
371 octave_idx_type nr = m.rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
372 octave_idx_type nc = m.columns ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
373
3130
02766207b74c [project @ 1998-01-25 08:27:23 by jwe]
jwe
parents: 3124
diff changeset
374 double result = -DBL_MAX;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
375
5748
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
376 bool all_inf_or_nan = true;
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
377
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
378 for (octave_idx_type j = 0; j < nc; j++)
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
379 for (octave_idx_type i = 0; i < nr; i++)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
380 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
381 double val = m(i,j);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
382 if (xisinf (val) || xisnan (val))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
383 continue;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
384
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
385 all_inf_or_nan = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
386
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
387 if (val > result)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
388 result = val;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
389 }
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
390
5748
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
391 if (all_inf_or_nan)
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
392 result = 0.0;
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
393
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
394 return result;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
395 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
396
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
397 static double
164
e2c950dd96d2 [project @ 1993-10-18 19:32:00 by jwe]
jwe
parents: 127
diff changeset
398 pr_min_internal (const Matrix& m)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
399 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
400 octave_idx_type nr = m.rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
401 octave_idx_type nc = m.columns ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
402
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
403 double result = DBL_MAX;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
404
5748
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
405 bool all_inf_or_nan = true;
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
406
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
407 for (octave_idx_type j = 0; j < nc; j++)
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
408 for (octave_idx_type i = 0; i < nr; i++)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
409 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
410 double val = m(i,j);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
411 if (xisinf (val) || xisnan (val))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
412 continue;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
413
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
414 all_inf_or_nan = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
415
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
416 if (val < result)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
417 result = val;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
418 }
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
419
5748
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
420 if (all_inf_or_nan)
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
421 result = 0.0;
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
422
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
423 return result;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
424 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
425
5775
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5770
diff changeset
426 // FIXME -- it would be nice to share more code among these
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
427 // functions,..
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
428
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
429 static void
6959
47f4f4e88166 [project @ 2007-10-04 20:43:32 by jwe]
jwe
parents: 6803
diff changeset
430 set_real_format (int digits, bool inf_or_nan, bool int_only, int &fw)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
431 {
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
432 static float_format fmt;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
433
2165
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
434 int prec = Voutput_precision;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
435
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
436 int ld, rd;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
437
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
438 if (rat_format)
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
439 {
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
440 fw = 0;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
441 rd = 0;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
442 }
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
443 else if (bank_format)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
444 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
445 fw = digits < 0 ? 4 : digits + 3;
5748
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
446 if (inf_or_nan && fw < 4)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
447 fw = 4;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
448 rd = 2;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
449 }
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
450 else if (hex_format)
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
451 {
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
452 fw = 2 * sizeof (double);
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
453 rd = 0;
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
454 }
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
455 else if (bit_format)
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
456 {
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
457 fw = 8 * sizeof (double);
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
458 rd = 0;
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
459 }
3611
b1ff6597576f [project @ 2000-03-17 09:44:29 by jwe]
jwe
parents: 3608
diff changeset
460 else if (inf_or_nan || int_only)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
461 {
5832
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
462 fw = 1 + digits;
5748
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
463 if (inf_or_nan && fw < 4)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
464 fw = 4;
3682
19e1ac7359fb [project @ 2000-06-27 03:23:10 by jwe]
jwe
parents: 3611
diff changeset
465 rd = fw;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
466 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
467 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
468 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
469 if (digits > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
470 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
471 ld = digits;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
472 rd = prec > digits ? prec - digits : prec;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
473 digits++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
474 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
475 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
476 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
477 ld = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
478 rd = prec > digits ? prec - digits : prec;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
479 digits = -digits + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
480 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
481
5832
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
482 fw = 1 + ld + 1 + rd;
5748
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
483 if (inf_or_nan && fw < 4)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
484 fw = 4;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
485 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
486
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
487 if (! (rat_format || bank_format || hex_format || bit_format)
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
488 && (fw > Voutput_max_field_width || print_e || print_g))
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
489 {
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
490 if (print_g)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
491 fmt = float_format ();
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
492 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
493 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
494 int exp_field = 4;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
495 if (digits > 100)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
496 exp_field++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
497
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
498 fw = 2 + prec + exp_field;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
499 if (inf_or_nan && fw < 4)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
500 fw = 4;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
501
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
502 fmt = float_format (fw, prec - 1, std::ios::scientific);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
503 }
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
504
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
505 if (print_big_e)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
506 fmt.uppercase ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
507 }
5086
55f5b61d74b7 [project @ 2004-11-19 21:50:50 by jwe]
jwe
parents: 5030
diff changeset
508 else if (! bank_format && (inf_or_nan || int_only))
3611
b1ff6597576f [project @ 2000-03-17 09:44:29 by jwe]
jwe
parents: 3608
diff changeset
509 fmt = float_format (fw, rd);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
510 else
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
511 fmt = float_format (fw, rd, std::ios::fixed);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
512
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
513 curr_real_fmt = &fmt;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
514 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
515
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
516 static void
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
517 set_format (double d, int& fw)
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
518 {
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
519 curr_real_fmt = 0;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
520 curr_imag_fmt = 0;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
521
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
522 if (free_format)
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
523 return;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
524
5389
25c8956d2204 [project @ 2005-06-15 03:45:46 by jwe]
jwe
parents: 5388
diff changeset
525 bool inf_or_nan = (xisinf (d) || xisnan (d));
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
526
3611
b1ff6597576f [project @ 2000-03-17 09:44:29 by jwe]
jwe
parents: 3608
diff changeset
527 bool int_only = (! inf_or_nan && D_NINT (d) == d);
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
528
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
529 double d_abs = d < 0.0 ? -d : d;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
530
2800
9aeba8e006a4 [project @ 1997-03-09 09:50:20 by jwe]
jwe
parents: 2664
diff changeset
531 int digits = (inf_or_nan || d_abs == 0.0)
9aeba8e006a4 [project @ 1997-03-09 09:50:20 by jwe]
jwe
parents: 2664
diff changeset
532 ? 0 : static_cast<int> (floor (log10 (d_abs) + 1.0));
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
533
6959
47f4f4e88166 [project @ 2007-10-04 20:43:32 by jwe]
jwe
parents: 6803
diff changeset
534 set_real_format (digits, inf_or_nan, int_only, fw);
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
535 }
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
536
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
537 static inline void
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
538 set_format (double d)
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
539 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
540 int fw;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
541 set_format (d, fw);
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
542 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
543
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
544 static void
6959
47f4f4e88166 [project @ 2007-10-04 20:43:32 by jwe]
jwe
parents: 6803
diff changeset
545 set_real_matrix_format (int x_max, int x_min, bool inf_or_nan,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
546 int int_or_inf_or_nan, int& fw)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
547 {
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
548 static float_format fmt;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
549
2165
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
550 int prec = Voutput_precision;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
551
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
552 int ld, rd;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
553
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
554 if (rat_format)
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
555 {
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
556 fw = 9;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
557 rd = 0;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
558 }
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
559 else if (bank_format)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
560 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
561 int digits = x_max > x_min ? x_max : x_min;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
562 fw = digits <= 0 ? 4 : digits + 3;
5748
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
563 if (inf_or_nan && fw < 4)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
564 fw = 4;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
565 rd = 2;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
566 }
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
567 else if (hex_format)
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
568 {
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
569 fw = 2 * sizeof (double);
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
570 rd = 0;
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
571 }
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
572 else if (bit_format)
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
573 {
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
574 fw = 8 * sizeof (double);
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
575 rd = 0;
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
576 }
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
577 else if (Vfixed_point_format && ! print_g)
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3258
diff changeset
578 {
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3258
diff changeset
579 rd = prec;
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3258
diff changeset
580 fw = rd + 2;
5748
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
581 if (inf_or_nan && fw < 4)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
582 fw = 4;
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3258
diff changeset
583 }
1715
6f4631c7118c [project @ 1996-01-08 07:57:04 by jwe]
jwe
parents: 1658
diff changeset
584 else if (int_or_inf_or_nan)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
585 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
586 int digits = x_max > x_min ? x_max : x_min;
5945
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
587 fw = digits <= 0 ? 2 : digits + 1;
5748
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
588 if (inf_or_nan && fw < 4)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
589 fw = 4;
3682
19e1ac7359fb [project @ 2000-06-27 03:23:10 by jwe]
jwe
parents: 3611
diff changeset
590 rd = fw;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
591 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
592 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
593 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
594 int ld_max, rd_max;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
595 if (x_max > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
596 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
597 ld_max = x_max;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
598 rd_max = prec > x_max ? prec - x_max : prec;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
599 x_max++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
600 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
601 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
602 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
603 ld_max = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
604 rd_max = prec > x_max ? prec - x_max : prec;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
605 x_max = -x_max + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
606 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
607
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
608 int ld_min, rd_min;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
609 if (x_min > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
610 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
611 ld_min = x_min;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
612 rd_min = prec > x_min ? prec - x_min : prec;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
613 x_min++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
614 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
615 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
616 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
617 ld_min = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
618 rd_min = prec > x_min ? prec - x_min : prec;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
619 x_min = -x_min + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
620 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
621
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
622 ld = ld_max > ld_min ? ld_max : ld_min;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
623 rd = rd_max > rd_min ? rd_max : rd_min;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
624
5832
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
625 fw = 1 + ld + 1 + rd;
5748
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
626 if (inf_or_nan && fw < 4)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
627 fw = 4;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
628 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
629
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
630 if (! (rat_format || bank_format || hex_format || bit_format)
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
631 && (print_e
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
632 || print_g
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
633 || (! Vfixed_point_format && fw > Voutput_max_field_width)))
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
634 {
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
635 if (print_g)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
636 fmt = float_format ();
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
637 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
638 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
639 int exp_field = 4;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
640 if (x_max > 100 || x_min > 100)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
641 exp_field++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
642
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
643 fw = 2 + prec + exp_field;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
644 if (inf_or_nan && fw < 4)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
645 fw = 4;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
646
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
647 fmt = float_format (fw, prec - 1, std::ios::scientific);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
648 }
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
649
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
650 if (print_big_e)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
651 fmt.uppercase ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
652 }
5086
55f5b61d74b7 [project @ 2004-11-19 21:50:50 by jwe]
jwe
parents: 5030
diff changeset
653 else if (! bank_format && int_or_inf_or_nan)
3611
b1ff6597576f [project @ 2000-03-17 09:44:29 by jwe]
jwe
parents: 3608
diff changeset
654 fmt = float_format (fw, rd);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
655 else
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
656 fmt = float_format (fw, rd, std::ios::fixed);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
657
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
658 curr_real_fmt = &fmt;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
659 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
660
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
661 static void
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
662 set_format (const Matrix& m, int& fw, double& scale)
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
663 {
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
664 curr_real_fmt = 0;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
665 curr_imag_fmt = 0;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
666
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
667 if (free_format)
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
668 return;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
669
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
670 bool inf_or_nan = m.any_element_is_inf_or_nan ();
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
671
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
672 bool int_or_inf_or_nan = m.all_elements_are_int_or_inf_or_nan ();
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
673
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
674 Matrix m_abs = m.abs ();
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
675 double max_abs = pr_max_internal (m_abs);
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
676 double min_abs = pr_min_internal (m_abs);
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
677
2800
9aeba8e006a4 [project @ 1997-03-09 09:50:20 by jwe]
jwe
parents: 2664
diff changeset
678 int x_max = max_abs == 0.0
9aeba8e006a4 [project @ 1997-03-09 09:50:20 by jwe]
jwe
parents: 2664
diff changeset
679 ? 0 : static_cast<int> (floor (log10 (max_abs) + 1.0));
9aeba8e006a4 [project @ 1997-03-09 09:50:20 by jwe]
jwe
parents: 2664
diff changeset
680
9aeba8e006a4 [project @ 1997-03-09 09:50:20 by jwe]
jwe
parents: 2664
diff changeset
681 int x_min = min_abs == 0.0
9aeba8e006a4 [project @ 1997-03-09 09:50:20 by jwe]
jwe
parents: 2664
diff changeset
682 ? 0 : static_cast<int> (floor (log10 (min_abs) + 1.0));
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
683
4270
e7e10ce42860 [project @ 2003-01-03 18:52:59 by jwe]
jwe
parents: 4269
diff changeset
684 scale = (x_max == 0 || int_or_inf_or_nan) ? 1.0 : std::pow (10.0, x_max - 1);
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
685
6959
47f4f4e88166 [project @ 2007-10-04 20:43:32 by jwe]
jwe
parents: 6803
diff changeset
686 set_real_matrix_format (x_max, x_min, inf_or_nan, int_or_inf_or_nan, fw);
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
687 }
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
688
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
689 static inline void
164
e2c950dd96d2 [project @ 1993-10-18 19:32:00 by jwe]
jwe
parents: 127
diff changeset
690 set_format (const Matrix& m)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
691 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
692 int fw;
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
693 double scale;
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
694 set_format (m, fw, scale);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
695 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
696
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
697 static void
6959
47f4f4e88166 [project @ 2007-10-04 20:43:32 by jwe]
jwe
parents: 6803
diff changeset
698 set_complex_format (int x_max, int x_min, int r_x, bool inf_or_nan,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
699 int int_only, int& r_fw, int& i_fw)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
700 {
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
701 static float_format r_fmt;
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
702 static float_format i_fmt;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
703
2165
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
704 int prec = Voutput_precision;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
705
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
706 int ld, rd;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
707
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
708 if (rat_format)
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
709 {
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
710 i_fw = 0;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
711 r_fw = 0;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
712 rd = 0;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
713 }
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
714 else if (bank_format)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
715 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
716 int digits = r_x;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
717 i_fw = 0;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
718 r_fw = digits <= 0 ? 4 : digits + 3;
5748
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
719 if (inf_or_nan && r_fw < 4)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
720 r_fw = 4;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
721 rd = 2;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
722 }
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
723 else if (hex_format)
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
724 {
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
725 r_fw = 2 * sizeof (double);
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
726 i_fw = 2 * sizeof (double);
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
727 rd = 0;
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
728 }
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
729 else if (bit_format)
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
730 {
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
731 r_fw = 8 * sizeof (double);
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
732 i_fw = 8 * sizeof (double);
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
733 rd = 0;
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
734 }
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
735 else if (inf_or_nan || int_only)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
736 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
737 int digits = x_max > x_min ? x_max : x_min;
5945
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
738 i_fw = digits <= 0 ? 1 : digits;
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
739 r_fw = i_fw + 1;
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
740 if (inf_or_nan && i_fw < 3)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
741 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
742 i_fw = 3;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
743 r_fw = 4;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
744 }
3682
19e1ac7359fb [project @ 2000-06-27 03:23:10 by jwe]
jwe
parents: 3611
diff changeset
745 rd = r_fw;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
746 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
747 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
748 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
749 int ld_max, rd_max;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
750 if (x_max > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
751 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
752 ld_max = x_max;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
753 rd_max = prec > x_max ? prec - x_max : prec;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
754 x_max++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
755 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
756 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
757 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
758 ld_max = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
759 rd_max = prec > x_max ? prec - x_max : prec;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
760 x_max = -x_max + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
761 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
762
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
763 int ld_min, rd_min;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
764 if (x_min > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
765 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
766 ld_min = x_min;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
767 rd_min = prec > x_min ? prec - x_min : prec;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
768 x_min++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
769 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
770 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
771 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
772 ld_min = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
773 rd_min = prec > x_min ? prec - x_min : prec;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
774 x_min = -x_min + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
775 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
776
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
777 ld = ld_max > ld_min ? ld_max : ld_min;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
778 rd = rd_max > rd_min ? rd_max : rd_min;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
779
5945
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
780 i_fw = ld + 1 + rd;
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
781 r_fw = i_fw + 1;
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
782 if (inf_or_nan && i_fw < 3)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
783 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
784 i_fw = 3;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
785 r_fw = 4;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
786 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
787 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
788
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
789 if (! (rat_format || bank_format || hex_format || bit_format)
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
790 && (r_fw > Voutput_max_field_width || print_e || print_g))
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
791 {
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
792 if (print_g)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
793 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
794 r_fmt = float_format ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
795 i_fmt = float_format ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
796 }
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
797 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
798 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
799 int exp_field = 4;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
800 if (x_max > 100 || x_min > 100)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
801 exp_field++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
802
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
803 i_fw = prec + exp_field;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
804 r_fw = i_fw + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
805 if (inf_or_nan && i_fw < 3)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
806 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
807 i_fw = 3;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
808 r_fw = 4;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
809 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
810
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
811 r_fmt = float_format (r_fw, prec - 1, std::ios::scientific);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
812 i_fmt = float_format (i_fw, prec - 1, std::ios::scientific);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
813 }
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
814
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
815 if (print_big_e)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
816 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
817 r_fmt.uppercase ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
818 i_fmt.uppercase ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
819 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
820 }
5086
55f5b61d74b7 [project @ 2004-11-19 21:50:50 by jwe]
jwe
parents: 5030
diff changeset
821 else if (! bank_format && (inf_or_nan || int_only))
3611
b1ff6597576f [project @ 2000-03-17 09:44:29 by jwe]
jwe
parents: 3608
diff changeset
822 {
b1ff6597576f [project @ 2000-03-17 09:44:29 by jwe]
jwe
parents: 3608
diff changeset
823 r_fmt = float_format (r_fw, rd);
b1ff6597576f [project @ 2000-03-17 09:44:29 by jwe]
jwe
parents: 3608
diff changeset
824 i_fmt = float_format (i_fw, rd);
b1ff6597576f [project @ 2000-03-17 09:44:29 by jwe]
jwe
parents: 3608
diff changeset
825 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
826 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
827 {
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
828 r_fmt = float_format (r_fw, rd, std::ios::fixed);
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
829 i_fmt = float_format (i_fw, rd, std::ios::fixed);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
830 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
831
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
832 curr_real_fmt = &r_fmt;
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
833 curr_imag_fmt = &i_fmt;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
834 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
835
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
836 static void
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
837 set_format (const Complex& c, int& r_fw, int& i_fw)
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
838 {
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
839 curr_real_fmt = 0;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
840 curr_imag_fmt = 0;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
841
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
842 if (free_format)
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
843 return;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
844
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
845 double rp = c.real ();
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
846 double ip = c.imag ();
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
847
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
848 bool inf_or_nan = (xisinf (c) || xisnan (c));
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
849
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
850 bool int_only = (D_NINT (rp) == rp && D_NINT (ip) == ip);
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
851
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
852 double r_abs = rp < 0.0 ? -rp : rp;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
853 double i_abs = ip < 0.0 ? -ip : ip;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
854
9612
66970dd627f6 further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9611
diff changeset
855 int r_x = (xisinf (rp) || xisnan (rp) || r_abs == 0.0)
2800
9aeba8e006a4 [project @ 1997-03-09 09:50:20 by jwe]
jwe
parents: 2664
diff changeset
856 ? 0 : static_cast<int> (floor (log10 (r_abs) + 1.0));
9aeba8e006a4 [project @ 1997-03-09 09:50:20 by jwe]
jwe
parents: 2664
diff changeset
857
9611
6f42ea240b3a pr-output.cc (set_format (const Complex&, int&, int&)): avoid passing NaN or Inf to log10
John W. Eaton <jwe@octave.org>
parents: 9412
diff changeset
858 int i_x = (xisinf (ip) || xisnan (ip) || i_abs == 0.0)
2800
9aeba8e006a4 [project @ 1997-03-09 09:50:20 by jwe]
jwe
parents: 2664
diff changeset
859 ? 0 : static_cast<int> (floor (log10 (i_abs) + 1.0));
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
860
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
861 int x_max, x_min;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
862
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
863 if (r_x > i_x)
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
864 {
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
865 x_max = r_x;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
866 x_min = i_x;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
867 }
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
868 else
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
869 {
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
870 x_max = i_x;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
871 x_min = r_x;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
872 }
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
873
6959
47f4f4e88166 [project @ 2007-10-04 20:43:32 by jwe]
jwe
parents: 6803
diff changeset
874 set_complex_format (x_max, x_min, r_x, inf_or_nan, int_only, r_fw, i_fw);
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
875 }
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
876
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
877 static inline void
164
e2c950dd96d2 [project @ 1993-10-18 19:32:00 by jwe]
jwe
parents: 127
diff changeset
878 set_format (const Complex& c)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
879 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
880 int r_fw, i_fw;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
881 set_format (c, r_fw, i_fw);
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
882 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
883
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
884 static void
6959
47f4f4e88166 [project @ 2007-10-04 20:43:32 by jwe]
jwe
parents: 6803
diff changeset
885 set_complex_matrix_format (int x_max, int x_min, int r_x_max,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
886 int r_x_min, bool inf_or_nan,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
887 int int_or_inf_or_nan, int& r_fw, int& i_fw)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
888 {
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
889 static float_format r_fmt;
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
890 static float_format i_fmt;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
891
2165
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
892 int prec = Voutput_precision;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
893
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
894 int ld, rd;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
895
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
896 if (rat_format)
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
897 {
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
898 i_fw = 9;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
899 r_fw = 9;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
900 rd = 0;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
901 }
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
902 else if (bank_format)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
903 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
904 int digits = r_x_max > r_x_min ? r_x_max : r_x_min;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
905 i_fw = 0;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
906 r_fw = digits <= 0 ? 4 : digits + 3;
5945
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
907 if (inf_or_nan && r_fw < 4)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
908 r_fw = 4;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
909 rd = 2;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
910 }
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
911 else if (hex_format)
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
912 {
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
913 r_fw = 2 * sizeof (double);
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
914 i_fw = 2 * sizeof (double);
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
915 rd = 0;
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
916 }
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
917 else if (bit_format)
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
918 {
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
919 r_fw = 8 * sizeof (double);
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
920 i_fw = 8 * sizeof (double);
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
921 rd = 0;
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
922 }
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
923 else if (Vfixed_point_format && ! print_g)
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3258
diff changeset
924 {
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3258
diff changeset
925 rd = prec;
5945
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
926 i_fw = rd + 1;
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
927 r_fw = i_fw + 1;
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
928 if (inf_or_nan && i_fw < 3)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
929 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
930 i_fw = 3;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
931 r_fw = 4;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
932 }
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3258
diff changeset
933 }
1715
6f4631c7118c [project @ 1996-01-08 07:57:04 by jwe]
jwe
parents: 1658
diff changeset
934 else if (int_or_inf_or_nan)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
935 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
936 int digits = x_max > x_min ? x_max : x_min;
5945
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
937 i_fw = digits <= 0 ? 1 : digits;
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
938 r_fw = i_fw + 1;
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
939 if (inf_or_nan && i_fw < 3)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
940 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
941 i_fw = 3;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
942 r_fw = 4;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
943 }
3682
19e1ac7359fb [project @ 2000-06-27 03:23:10 by jwe]
jwe
parents: 3611
diff changeset
944 rd = r_fw;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
945 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
946 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
947 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
948 int ld_max, rd_max;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
949 if (x_max > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
950 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
951 ld_max = x_max;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
952 rd_max = prec > x_max ? prec - x_max : prec;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
953 x_max++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
954 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
955 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
956 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
957 ld_max = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
958 rd_max = prec > x_max ? prec - x_max : prec;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
959 x_max = -x_max + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
960 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
961
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
962 int ld_min, rd_min;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
963 if (x_min > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
964 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
965 ld_min = x_min;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
966 rd_min = prec > x_min ? prec - x_min : prec;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
967 x_min++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
968 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
969 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
970 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
971 ld_min = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
972 rd_min = prec > x_min ? prec - x_min : prec;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
973 x_min = -x_min + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
974 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
975
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
976 ld = ld_max > ld_min ? ld_max : ld_min;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
977 rd = rd_max > rd_min ? rd_max : rd_min;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
978
5945
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
979 i_fw = ld + 1 + rd;
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
980 r_fw = i_fw + 1;
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
981 if (inf_or_nan && i_fw < 3)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
982 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
983 i_fw = 3;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
984 r_fw = 4;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
985 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
986 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
987
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
988 if (! (rat_format || bank_format || hex_format || bit_format)
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
989 && (print_e
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
990 || print_g
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
991 || (! Vfixed_point_format && r_fw > Voutput_max_field_width)))
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
992 {
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
993 if (print_g)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
994 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
995 r_fmt = float_format ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
996 i_fmt = float_format ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
997 }
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
998 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
999 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1000 int exp_field = 4;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1001 if (x_max > 100 || x_min > 100)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1002 exp_field++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1003
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1004 i_fw = prec + exp_field;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1005 r_fw = i_fw + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1006 if (inf_or_nan && i_fw < 3)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1007 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1008 i_fw = 3;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1009 r_fw = 4;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1010 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1011
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1012 r_fmt = float_format (r_fw, prec - 1, std::ios::scientific);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1013 i_fmt = float_format (i_fw, prec - 1, std::ios::scientific);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1014 }
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1015
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1016 if (print_big_e)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1017 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1018 r_fmt.uppercase ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1019 i_fmt.uppercase ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1020 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1021 }
5086
55f5b61d74b7 [project @ 2004-11-19 21:50:50 by jwe]
jwe
parents: 5030
diff changeset
1022 else if (! bank_format && int_or_inf_or_nan)
3611
b1ff6597576f [project @ 2000-03-17 09:44:29 by jwe]
jwe
parents: 3608
diff changeset
1023 {
b1ff6597576f [project @ 2000-03-17 09:44:29 by jwe]
jwe
parents: 3608
diff changeset
1024 r_fmt = float_format (r_fw, rd);
b1ff6597576f [project @ 2000-03-17 09:44:29 by jwe]
jwe
parents: 3608
diff changeset
1025 i_fmt = float_format (i_fw, rd);
b1ff6597576f [project @ 2000-03-17 09:44:29 by jwe]
jwe
parents: 3608
diff changeset
1026 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1027 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1028 {
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1029 r_fmt = float_format (r_fw, rd, std::ios::fixed);
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1030 i_fmt = float_format (i_fw, rd, std::ios::fixed);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1031 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1032
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1033 curr_real_fmt = &r_fmt;
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1034 curr_imag_fmt = &i_fmt;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1035 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1036
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1037 static void
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1038 set_format (const ComplexMatrix& cm, int& r_fw, int& i_fw, double& scale)
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1039 {
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1040 curr_real_fmt = 0;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1041 curr_imag_fmt = 0;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1042
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1043 if (free_format)
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1044 return;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1045
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1046 Matrix rp = real (cm);
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1047 Matrix ip = imag (cm);
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1048
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
1049 bool inf_or_nan = cm.any_element_is_inf_or_nan ();
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1050
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
1051 bool int_or_inf_or_nan = (rp.all_elements_are_int_or_inf_or_nan ()
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1052 && ip.all_elements_are_int_or_inf_or_nan ());
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1053
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
1054 Matrix r_m_abs = rp.abs ();
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1055 double r_max_abs = pr_max_internal (r_m_abs);
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1056 double r_min_abs = pr_min_internal (r_m_abs);
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1057
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
1058 Matrix i_m_abs = ip.abs ();
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1059 double i_max_abs = pr_max_internal (i_m_abs);
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1060 double i_min_abs = pr_min_internal (i_m_abs);
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1061
2800
9aeba8e006a4 [project @ 1997-03-09 09:50:20 by jwe]
jwe
parents: 2664
diff changeset
1062 int r_x_max = r_max_abs == 0.0
9aeba8e006a4 [project @ 1997-03-09 09:50:20 by jwe]
jwe
parents: 2664
diff changeset
1063 ? 0 : static_cast<int> (floor (log10 (r_max_abs) + 1.0));
9aeba8e006a4 [project @ 1997-03-09 09:50:20 by jwe]
jwe
parents: 2664
diff changeset
1064
9aeba8e006a4 [project @ 1997-03-09 09:50:20 by jwe]
jwe
parents: 2664
diff changeset
1065 int r_x_min = r_min_abs == 0.0
9aeba8e006a4 [project @ 1997-03-09 09:50:20 by jwe]
jwe
parents: 2664
diff changeset
1066 ? 0 : static_cast<int> (floor (log10 (r_min_abs) + 1.0));
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1067
2800
9aeba8e006a4 [project @ 1997-03-09 09:50:20 by jwe]
jwe
parents: 2664
diff changeset
1068 int i_x_max = i_max_abs == 0.0
9aeba8e006a4 [project @ 1997-03-09 09:50:20 by jwe]
jwe
parents: 2664
diff changeset
1069 ? 0 : static_cast<int> (floor (log10 (i_max_abs) + 1.0));
9aeba8e006a4 [project @ 1997-03-09 09:50:20 by jwe]
jwe
parents: 2664
diff changeset
1070
9aeba8e006a4 [project @ 1997-03-09 09:50:20 by jwe]
jwe
parents: 2664
diff changeset
1071 int i_x_min = i_min_abs == 0.0
9aeba8e006a4 [project @ 1997-03-09 09:50:20 by jwe]
jwe
parents: 2664
diff changeset
1072 ? 0 : static_cast<int> (floor (log10 (i_min_abs) + 1.0));
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1073
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1074 int x_max = r_x_max > i_x_max ? r_x_max : i_x_max;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1075 int x_min = r_x_min > i_x_min ? r_x_min : i_x_min;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1076
4270
e7e10ce42860 [project @ 2003-01-03 18:52:59 by jwe]
jwe
parents: 4269
diff changeset
1077 scale = (x_max == 0 || int_or_inf_or_nan) ? 1.0 : std::pow (10.0, x_max - 1);
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1078
6959
47f4f4e88166 [project @ 2007-10-04 20:43:32 by jwe]
jwe
parents: 6803
diff changeset
1079 set_complex_matrix_format (x_max, x_min, r_x_max, r_x_min, inf_or_nan,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1080 int_or_inf_or_nan, r_fw, i_fw);
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1081 }
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1082
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1083 static inline void
164
e2c950dd96d2 [project @ 1993-10-18 19:32:00 by jwe]
jwe
parents: 127
diff changeset
1084 set_format (const ComplexMatrix& cm)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1085 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1086 int r_fw, i_fw;
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1087 double scale;
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1088 set_format (cm, r_fw, i_fw, scale);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1089 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1090
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1091 static void
7465
8d6ab12f8fda format Range output more like N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7231
diff changeset
1092 set_range_format (int x_max, int x_min, int all_ints, int& fw)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1093 {
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1094 static float_format fmt;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1095
2165
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
1096 int prec = Voutput_precision;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1097
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1098 int ld, rd;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1099
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
1100 if (rat_format)
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
1101 {
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
1102 fw = 9;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
1103 rd = 0;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
1104 }
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
1105 else if (bank_format)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1106 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1107 int digits = x_max > x_min ? x_max : x_min;
7465
8d6ab12f8fda format Range output more like N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7231
diff changeset
1108 fw = digits < 0 ? 5 : digits + 4;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1109 rd = 2;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1110 }
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
1111 else if (hex_format)
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
1112 {
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
1113 fw = 2 * sizeof (double);
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
1114 rd = 0;
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
1115 }
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1116 else if (bit_format)
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1117 {
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1118 fw = 8 * sizeof (double);
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1119 rd = 0;
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1120 }
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1121 else if (all_ints)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1122 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1123 int digits = x_max > x_min ? x_max : x_min;
7465
8d6ab12f8fda format Range output more like N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7231
diff changeset
1124 fw = digits + 1;
3682
19e1ac7359fb [project @ 2000-06-27 03:23:10 by jwe]
jwe
parents: 3611
diff changeset
1125 rd = fw;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1126 }
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
1127 else if (Vfixed_point_format && ! print_g)
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1128 {
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1129 rd = prec;
7465
8d6ab12f8fda format Range output more like N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7231
diff changeset
1130 fw = rd + 3;
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1131 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1132 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1133 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1134 int ld_max, rd_max;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1135 if (x_max > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1136 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1137 ld_max = x_max;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1138 rd_max = prec > x_max ? prec - x_max : prec;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1139 x_max++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1140 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1141 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1142 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1143 ld_max = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1144 rd_max = prec > x_max ? prec - x_max : prec;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1145 x_max = -x_max + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1146 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1147
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1148 int ld_min, rd_min;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1149 if (x_min > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1150 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1151 ld_min = x_min;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1152 rd_min = prec > x_min ? prec - x_min : prec;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1153 x_min++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1154 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1155 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1156 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1157 ld_min = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1158 rd_min = prec > x_min ? prec - x_min : prec;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1159 x_min = -x_min + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1160 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1161
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1162 ld = ld_max > ld_min ? ld_max : ld_min;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1163 rd = rd_max > rd_min ? rd_max : rd_min;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1164
7465
8d6ab12f8fda format Range output more like N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7231
diff changeset
1165 fw = ld + rd + 3;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1166 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1167
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
1168 if (! (rat_format || bank_format || hex_format || bit_format)
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1169 && (print_e
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1170 || print_g
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1171 || (! Vfixed_point_format && fw > Voutput_max_field_width)))
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1172 {
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
1173 if (print_g)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1174 fmt = float_format ();
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
1175 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1176 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1177 int exp_field = 4;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1178 if (x_max > 100 || x_min > 100)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1179 exp_field++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1180
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1181 fw = 3 + prec + exp_field;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1182
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1183 fmt = float_format (fw, prec - 1, std::ios::scientific);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1184 }
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1185
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1186 if (print_big_e)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1187 fmt.uppercase ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1188 }
5086
55f5b61d74b7 [project @ 2004-11-19 21:50:50 by jwe]
jwe
parents: 5030
diff changeset
1189 else if (! bank_format && all_ints)
3611
b1ff6597576f [project @ 2000-03-17 09:44:29 by jwe]
jwe
parents: 3608
diff changeset
1190 fmt = float_format (fw, rd);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1191 else
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1192 fmt = float_format (fw, rd, std::ios::fixed);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1193
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1194 curr_real_fmt = &fmt;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1195 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1196
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1197 static void
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1198 set_format (const Range& r, int& fw, double& scale)
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1199 {
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1200 curr_real_fmt = 0;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1201 curr_imag_fmt = 0;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1202
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1203 if (free_format)
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1204 return;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1205
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1206 double r_min = r.base ();
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1207 double r_max = r.limit ();
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1208
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1209 if (r_max < r_min)
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1210 {
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1211 double tmp = r_max;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1212 r_max = r_min;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1213 r_min = tmp;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1214 }
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1215
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
1216 bool all_ints = r.all_elements_are_ints ();
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1217
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1218 double max_abs = r_max < 0.0 ? -r_max : r_max;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1219 double min_abs = r_min < 0.0 ? -r_min : r_min;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1220
2800
9aeba8e006a4 [project @ 1997-03-09 09:50:20 by jwe]
jwe
parents: 2664
diff changeset
1221 int x_max = max_abs == 0.0
9aeba8e006a4 [project @ 1997-03-09 09:50:20 by jwe]
jwe
parents: 2664
diff changeset
1222 ? 0 : static_cast<int> (floor (log10 (max_abs) + 1.0));
9aeba8e006a4 [project @ 1997-03-09 09:50:20 by jwe]
jwe
parents: 2664
diff changeset
1223
9aeba8e006a4 [project @ 1997-03-09 09:50:20 by jwe]
jwe
parents: 2664
diff changeset
1224 int x_min = min_abs == 0.0
9aeba8e006a4 [project @ 1997-03-09 09:50:20 by jwe]
jwe
parents: 2664
diff changeset
1225 ? 0 : static_cast<int> (floor (log10 (min_abs) + 1.0));
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1226
4270
e7e10ce42860 [project @ 2003-01-03 18:52:59 by jwe]
jwe
parents: 4269
diff changeset
1227 scale = (x_max == 0 || all_ints) ? 1.0 : std::pow (10.0, x_max - 1);
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1228
7465
8d6ab12f8fda format Range output more like N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7231
diff changeset
1229 set_range_format (x_max, x_min, all_ints, fw);
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1230 }
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1231
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1232 static inline void
164
e2c950dd96d2 [project @ 1993-10-18 19:32:00 by jwe]
jwe
parents: 127
diff changeset
1233 set_format (const Range& r)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1234 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1235 int fw;
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1236 double scale;
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1237 set_format (r, fw, scale);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1238 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1239
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
1240 union equiv
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
1241 {
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
1242 double d;
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
1243 unsigned char i[sizeof (double)];
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
1244 };
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
1245
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1246 #define PRINT_CHAR_BITS(os, c) \
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1247 do \
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1248 { \
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1249 unsigned char ctmp = c; \
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1250 char stmp[9]; \
1488
89c587478067 [project @ 1995-09-26 22:49:48 by jwe]
jwe
parents: 1352
diff changeset
1251 stmp[0] = (ctmp & 0x80) ? '1' : '0'; \
89c587478067 [project @ 1995-09-26 22:49:48 by jwe]
jwe
parents: 1352
diff changeset
1252 stmp[1] = (ctmp & 0x40) ? '1' : '0'; \
89c587478067 [project @ 1995-09-26 22:49:48 by jwe]
jwe
parents: 1352
diff changeset
1253 stmp[2] = (ctmp & 0x20) ? '1' : '0'; \
89c587478067 [project @ 1995-09-26 22:49:48 by jwe]
jwe
parents: 1352
diff changeset
1254 stmp[3] = (ctmp & 0x10) ? '1' : '0'; \
89c587478067 [project @ 1995-09-26 22:49:48 by jwe]
jwe
parents: 1352
diff changeset
1255 stmp[4] = (ctmp & 0x08) ? '1' : '0'; \
89c587478067 [project @ 1995-09-26 22:49:48 by jwe]
jwe
parents: 1352
diff changeset
1256 stmp[5] = (ctmp & 0x04) ? '1' : '0'; \
89c587478067 [project @ 1995-09-26 22:49:48 by jwe]
jwe
parents: 1352
diff changeset
1257 stmp[6] = (ctmp & 0x02) ? '1' : '0'; \
89c587478067 [project @ 1995-09-26 22:49:48 by jwe]
jwe
parents: 1352
diff changeset
1258 stmp[7] = (ctmp & 0x01) ? '1' : '0'; \
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1259 stmp[8] = '\0'; \
3013
66a1cede95e7 [project @ 1997-06-02 19:35:05 by jwe]
jwe
parents: 2926
diff changeset
1260 os << stmp; \
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1261 } \
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1262 while (0)
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1263
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1264 #define PRINT_CHAR_BITS_SWAPPED(os, c) \
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1265 do \
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1266 { \
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1267 unsigned char ctmp = c; \
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1268 char stmp[9]; \
1488
89c587478067 [project @ 1995-09-26 22:49:48 by jwe]
jwe
parents: 1352
diff changeset
1269 stmp[0] = (ctmp & 0x01) ? '1' : '0'; \
89c587478067 [project @ 1995-09-26 22:49:48 by jwe]
jwe
parents: 1352
diff changeset
1270 stmp[1] = (ctmp & 0x02) ? '1' : '0'; \
89c587478067 [project @ 1995-09-26 22:49:48 by jwe]
jwe
parents: 1352
diff changeset
1271 stmp[2] = (ctmp & 0x04) ? '1' : '0'; \
89c587478067 [project @ 1995-09-26 22:49:48 by jwe]
jwe
parents: 1352
diff changeset
1272 stmp[3] = (ctmp & 0x08) ? '1' : '0'; \
89c587478067 [project @ 1995-09-26 22:49:48 by jwe]
jwe
parents: 1352
diff changeset
1273 stmp[4] = (ctmp & 0x10) ? '1' : '0'; \
89c587478067 [project @ 1995-09-26 22:49:48 by jwe]
jwe
parents: 1352
diff changeset
1274 stmp[5] = (ctmp & 0x20) ? '1' : '0'; \
89c587478067 [project @ 1995-09-26 22:49:48 by jwe]
jwe
parents: 1352
diff changeset
1275 stmp[6] = (ctmp & 0x40) ? '1' : '0'; \
89c587478067 [project @ 1995-09-26 22:49:48 by jwe]
jwe
parents: 1352
diff changeset
1276 stmp[7] = (ctmp & 0x80) ? '1' : '0'; \
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1277 stmp[8] = '\0'; \
3013
66a1cede95e7 [project @ 1997-06-02 19:35:05 by jwe]
jwe
parents: 2926
diff changeset
1278 os << stmp; \
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1279 } \
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1280 while (0)
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1281
2522
4f095783ee43 [project @ 1996-11-15 20:00:59 by jwe]
jwe
parents: 2447
diff changeset
1282 static void
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1283 pr_any_float (const float_format *fmt, std::ostream& os, double d, int fw = 0)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1284 {
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 453
diff changeset
1285 if (fmt)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1286 {
5544
2286fa5f2e5d [project @ 2005-11-21 18:44:31 by jwe]
jwe
parents: 5404
diff changeset
1287 // Unless explicitly asked for, always print in big-endian
2286fa5f2e5d [project @ 2005-11-21 18:44:31 by jwe]
jwe
parents: 5404
diff changeset
1288 // format for hex and bit formats.
2286fa5f2e5d [project @ 2005-11-21 18:44:31 by jwe]
jwe
parents: 5404
diff changeset
1289 //
2286fa5f2e5d [project @ 2005-11-21 18:44:31 by jwe]
jwe
parents: 5404
diff changeset
1290 // {bit,hex}_format == 1: print big-endian
2286fa5f2e5d [project @ 2005-11-21 18:44:31 by jwe]
jwe
parents: 5404
diff changeset
1291 // {bit,hex}_format == 2: print native
2286fa5f2e5d [project @ 2005-11-21 18:44:31 by jwe]
jwe
parents: 5404
diff changeset
1292
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
1293 if (hex_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1294 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1295 equiv tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1296 tmp.d = d;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1297
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1298 // Unless explicitly asked for, always print in big-endian
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1299 // format.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1300
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1301 // FIXME -- is it correct to swap bytes for VAX
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1302 // formats and not for Cray?
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1303
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1304 // FIXME -- will bad things happen if we are
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1305 // interrupted before resetting the format flags and fill
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1306 // character?
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1307
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1308 oct_mach_info::float_format flt_fmt =
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1309 oct_mach_info::native_float_format ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1310
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1311 char ofill = os.fill ('0');
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1312
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1313 std::ios::fmtflags oflags
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1314 = os.flags (std::ios::right | std::ios::hex);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1316 if (hex_format > 1
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1317 || flt_fmt == oct_mach_info::flt_fmt_ieee_big_endian
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1318 || flt_fmt == oct_mach_info::flt_fmt_cray
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1319 || flt_fmt == oct_mach_info::flt_fmt_unknown)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1320 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1321 for (size_t i = 0; i < sizeof (double); i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1322 os << std::setw (2) << static_cast<int> (tmp.i[i]);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1323 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1324 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1325 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1326 for (int i = sizeof (double) - 1; i >= 0; i--)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1327 os << std::setw (2) << static_cast<int> (tmp.i[i]);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1328 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1329
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1330 os.fill (ofill);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1331 os.setf (oflags);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1332 }
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1333 else if (bit_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1334 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1335 equiv tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1336 tmp.d = d;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1337
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1338 // FIXME -- is it correct to swap bytes for VAX
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1339 // formats and not for Cray?
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1340
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1341 oct_mach_info::float_format flt_fmt =
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1342 oct_mach_info::native_float_format ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1343
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1344 if (flt_fmt == oct_mach_info::flt_fmt_ieee_big_endian
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1345 || flt_fmt == oct_mach_info::flt_fmt_cray
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1346 || flt_fmt == oct_mach_info::flt_fmt_unknown)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1347 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1348 for (size_t i = 0; i < sizeof (double); i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1349 PRINT_CHAR_BITS (os, tmp.i[i]);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1350 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1351 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1352 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1353 if (bit_format > 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1354 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1355 for (size_t i = 0; i < sizeof (double); i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1356 PRINT_CHAR_BITS_SWAPPED (os, tmp.i[i]);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1357 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1358 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1359 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1360 for (int i = sizeof (double) - 1; i >= 0; i--)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1361 PRINT_CHAR_BITS (os, tmp.i[i]);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1362 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1363 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1364 }
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
1365 else if (octave_is_NA (d))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1366 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1367 if (fw > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1368 os << std::setw (fw) << "NA";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1369 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1370 os << "NA";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1371 }
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
1372 else if (rat_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1373 os << pr_rational_float (*fmt, d);
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
1374 else if (xisinf (d))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1375 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1376 const char *s;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1377 if (d < 0.0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1378 s = "-Inf";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1379 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1380 s = "Inf";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1381
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1382 if (fw > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1383 os << std::setw (fw) << s;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1384 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1385 os << s;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1386 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1387 else if (xisnan (d))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1388 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1389 if (fw > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1390 os << std::setw (fw) << "NaN";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1391 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1392 os << "NaN";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1393 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1394 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1395 os << pr_formatted_float (*fmt, d);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1396 }
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 453
diff changeset
1397 else
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 453
diff changeset
1398 os << d;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1399 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1400
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1401 static inline void
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1402 pr_float (std::ostream& os, double d, int fw = 0, double scale = 1.0)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1403 {
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
1404 if (Vfixed_point_format && ! print_g && scale != 1.0)
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1405 d /= scale;
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1406
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1407 pr_any_float (curr_real_fmt, os, d, fw);
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1408 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1409
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1410 static inline void
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
1411 pr_imag_float (std::ostream& os, double d, int fw = 0)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1412 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1413 pr_any_float (curr_imag_fmt, os, d, fw);
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1414 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1415
2522
4f095783ee43 [project @ 1996-11-15 20:00:59 by jwe]
jwe
parents: 2447
diff changeset
1416 static void
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1417 pr_complex (std::ostream& os, const Complex& c, int r_fw = 0,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1418 int i_fw = 0, double scale = 1.0)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1419 {
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
1420 Complex tmp
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
1421 = (Vfixed_point_format && ! print_g && scale != 1.0) ? c / scale : c;
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1422
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1423 double r = tmp.real ();
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1424
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1425 pr_float (os, r, r_fw);
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1426
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1427 if (! bank_format)
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1428 {
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1429 double i = tmp.imag ();
4349
a6c22c2c9b09 [project @ 2003-02-21 18:59:07 by jwe]
jwe
parents: 4270
diff changeset
1430 if (! (hex_format || bit_format) && lo_ieee_signbit (i))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1431 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1432 os << " - ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1433 i = -i;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1434 pr_imag_float (os, i, i_fw);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1435 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1436 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1437 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1438 if (hex_format || bit_format)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1439 os << " ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1440 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1441 os << " + ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1442
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1443 pr_imag_float (os, i, i_fw);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1444 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1445 os << "i";
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1446 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1447 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1448
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1449 static void
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
1450 print_empty_matrix (std::ostream& os, octave_idx_type nr, octave_idx_type nc, bool pr_as_read_syntax)
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1451 {
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1452 assert (nr == 0 || nc == 0);
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1453
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1454 if (pr_as_read_syntax)
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1455 {
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1456 if (nr == 0 && nc == 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1457 os << "[]";
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1458 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1459 os << "zeros (" << nr << ", " << nc << ")";
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1460 }
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1461 else
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1462 {
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1463 os << "[]";
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1464
2165
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
1465 if (Vprint_empty_dimensions)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1466 os << "(" << nr << "x" << nc << ")";
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1467 }
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1468 }
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1469
1186
d94bcafabac2 [project @ 1995-03-30 04:57:32 by jwe]
jwe
parents: 1086
diff changeset
1470 static void
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1471 print_empty_nd_array (std::ostream& os, const dim_vector& dims,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1472 bool pr_as_read_syntax)
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1473 {
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1474 assert (dims.any_zero ());
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1475
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1476 if (pr_as_read_syntax)
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1477 os << "zeros (" << dims.str (',') << ")";
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1478 else
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1479 {
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1480 os << "[]";
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1481
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1482 if (Vprint_empty_dimensions)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1483 os << "(" << dims.str () << ")";
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1484 }
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1485 }
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1486
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1487 static void
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
1488 pr_scale_header (std::ostream& os, double scale)
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1489 {
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
1490 if (Vfixed_point_format && ! print_g && scale != 1.0)
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1491 {
3568
58549b931ad5 [project @ 2000-02-03 10:21:54 by jwe]
jwe
parents: 3548
diff changeset
1492 os << " "
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1493 << std::setw (8) << std::setprecision (1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1494 << std::setiosflags (std::ios::scientific|std::ios::left)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1495 << scale
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1496 << std::resetiosflags (std::ios::scientific|std::ios::left)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1497 << " *\n";
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1498
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1499 if (! compact_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1500 os << "\n";
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1501 }
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1502 }
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1503
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1504 static void
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
1505 pr_col_num_header (std::ostream& os, octave_idx_type total_width, int max_width,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1506 octave_idx_type lim, octave_idx_type col, int extra_indent)
1186
d94bcafabac2 [project @ 1995-03-30 04:57:32 by jwe]
jwe
parents: 1086
diff changeset
1507 {
2165
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
1508 if (total_width > max_width && Vsplit_long_rows)
1186
d94bcafabac2 [project @ 1995-03-30 04:57:32 by jwe]
jwe
parents: 1086
diff changeset
1509 {
4833
399e8681b774 [project @ 2004-03-10 20:49:48 by jwe]
jwe
parents: 4791
diff changeset
1510 if (col != 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1511 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1512 if (compact_format)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1513 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1514 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1515 os << "\n\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1516 }
1186
d94bcafabac2 [project @ 1995-03-30 04:57:32 by jwe]
jwe
parents: 1086
diff changeset
1517
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
1518 octave_idx_type num_cols = lim - col;
1186
d94bcafabac2 [project @ 1995-03-30 04:57:32 by jwe]
jwe
parents: 1086
diff changeset
1519
3548
ab7fa5a8f23f [project @ 2000-02-03 01:17:15 by jwe]
jwe
parents: 3538
diff changeset
1520 os << std::setw (extra_indent) << "";
1972
58ac5f889c64 [project @ 1996-02-24 07:12:58 by jwe]
jwe
parents: 1968
diff changeset
1521
1186
d94bcafabac2 [project @ 1995-03-30 04:57:32 by jwe]
jwe
parents: 1086
diff changeset
1522 if (num_cols == 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1523 os << " Column " << col + 1 << ":\n";
1186
d94bcafabac2 [project @ 1995-03-30 04:57:32 by jwe]
jwe
parents: 1086
diff changeset
1524 else if (num_cols == 2)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1525 os << " Columns " << col + 1 << " and " << lim << ":\n";
1186
d94bcafabac2 [project @ 1995-03-30 04:57:32 by jwe]
jwe
parents: 1086
diff changeset
1526 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1527 os << " Columns " << col + 1 << " through " << lim << ":\n";
2915
649549662cf6 [project @ 1997-04-30 20:51:40 by jwe]
jwe
parents: 2907
diff changeset
1528
649549662cf6 [project @ 1997-04-30 20:51:40 by jwe]
jwe
parents: 2907
diff changeset
1529 if (! compact_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1530 os << "\n";
1186
d94bcafabac2 [project @ 1995-03-30 04:57:32 by jwe]
jwe
parents: 1086
diff changeset
1531 }
d94bcafabac2 [project @ 1995-03-30 04:57:32 by jwe]
jwe
parents: 1086
diff changeset
1532 }
d94bcafabac2 [project @ 1995-03-30 04:57:32 by jwe]
jwe
parents: 1086
diff changeset
1533
5030
160365410ad4 [project @ 2004-09-24 03:22:23 by jwe]
jwe
parents: 4949
diff changeset
1534 template <class T>
6018
bda649f500bd [project @ 2006-10-02 17:23:18 by jwe]
jwe
parents: 6015
diff changeset
1535 /* static */ inline void
5030
160365410ad4 [project @ 2004-09-24 03:22:23 by jwe]
jwe
parents: 4949
diff changeset
1536 pr_plus_format (std::ostream& os, const T& val)
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
1537 {
5030
160365410ad4 [project @ 2004-09-24 03:22:23 by jwe]
jwe
parents: 4949
diff changeset
1538 if (val > T (0))
4632
0e28461651f2 [project @ 2003-11-18 19:07:13 by jwe]
jwe
parents: 4574
diff changeset
1539 os << plus_format_chars[0];
5030
160365410ad4 [project @ 2004-09-24 03:22:23 by jwe]
jwe
parents: 4949
diff changeset
1540 else if (val < T (0))
4632
0e28461651f2 [project @ 2003-11-18 19:07:13 by jwe]
jwe
parents: 4574
diff changeset
1541 os << plus_format_chars[1];
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
1542 else
4632
0e28461651f2 [project @ 2003-11-18 19:07:13 by jwe]
jwe
parents: 4574
diff changeset
1543 os << plus_format_chars[2];
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
1544 }
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
1545
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1546 void
4661
12b6fbd57436 [project @ 2003-11-25 05:41:35 by jwe]
jwe
parents: 4655
diff changeset
1547 octave_print_internal (std::ostream& os, double d,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1548 bool /* pr_as_read_syntax */)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1549 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1550 if (plus_format)
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1551 {
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1552 pr_plus_format (os, d);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1553 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1554 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1555 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1556 set_format (d);
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1557 if (free_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1558 os << d;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1559 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1560 pr_float (os, d);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1561 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1562 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1563
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1564 void
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1565 octave_print_internal (std::ostream& os, const Matrix& m,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1566 bool pr_as_read_syntax, int extra_indent)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1567 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
1568 octave_idx_type nr = m.rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
1569 octave_idx_type nc = m.columns ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1570
2408
e22aae3ccfad [project @ 1996-10-15 16:37:52 by jwe]
jwe
parents: 2387
diff changeset
1571 if (nr == 0 || nc == 0)
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1572 print_empty_matrix (os, nr, nc, pr_as_read_syntax);
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1573 else if (plus_format && ! pr_as_read_syntax)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1574 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
1575 for (octave_idx_type i = 0; i < nr; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1576 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1577 for (octave_idx_type j = 0; j < nc; j++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1578 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1579 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1580
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1581 pr_plus_format (os, m(i,j));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1582 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1583
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1584 if (i < nr - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1585 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1586 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1587 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1588 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1589 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1590 int fw;
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1591 double scale = 1.0;
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1592 set_format (m, fw, scale);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1593 int column_width = fw + 2;
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
1594 octave_idx_type total_width = nc * column_width;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
1595 octave_idx_type max_width = command_editor::terminal_cols ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1596
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1597 if (pr_as_read_syntax)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1598 max_width -= 4;
1972
58ac5f889c64 [project @ 1996-02-24 07:12:58 by jwe]
jwe
parents: 1968
diff changeset
1599 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1600 max_width -= extra_indent;
1972
58ac5f889c64 [project @ 1996-02-24 07:12:58 by jwe]
jwe
parents: 1968
diff changeset
1601
58ac5f889c64 [project @ 1996-02-24 07:12:58 by jwe]
jwe
parents: 1968
diff changeset
1602 if (max_width < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1603 max_width = 0;
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1604
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1605 if (free_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1606 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1607 if (pr_as_read_syntax)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1608 os << "[\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1609
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1610 os << m;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1611
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1612 if (pr_as_read_syntax)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1613 os << "]";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1614
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1615 return;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1616 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1617
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
1618 octave_idx_type inc = nc;
2165
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
1619 if (total_width > max_width && Vsplit_long_rows)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1620 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1621 inc = max_width / column_width;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1622 if (inc == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1623 inc++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1624 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1625
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1626 if (pr_as_read_syntax)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1627 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1628 for (octave_idx_type i = 0; i < nr; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1629 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1630 octave_idx_type col = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1631 while (col < nc)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1632 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1633 octave_idx_type lim = col + inc < nc ? col + inc : nc;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1634
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1635 for (octave_idx_type j = col; j < lim; j++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1636 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1637 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1638
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1639 if (i == 0 && j == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1640 os << "[ ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1641 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1642 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1643 if (j > col && j < lim)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1644 os << ", ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1645 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1646 os << " ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1647 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1648
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1649 pr_float (os, m(i,j));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1650 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1651
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1652 col += inc;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1653
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1654 if (col >= nc)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1655 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1656 if (i == nr - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1657 os << " ]";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1658 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1659 os << ";\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1660 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1661 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1662 os << " ...\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1663 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1664 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1665 }
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1666 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1667 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1668 pr_scale_header (os, scale);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1669
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1670 for (octave_idx_type col = 0; col < nc; col += inc)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1671 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1672 octave_idx_type lim = col + inc < nc ? col + inc : nc;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1673
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1674 pr_col_num_header (os, total_width, max_width, lim, col,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1675 extra_indent);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1676
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1677 for (octave_idx_type i = 0; i < nr; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1678 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1679 os << std::setw (extra_indent) << "";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1680
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1681 for (octave_idx_type j = col; j < lim; j++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1682 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1683 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1684
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1685 os << " ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1686
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1687 pr_float (os, m(i,j), fw, scale);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1688 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1689
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1690 if (i < nr - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1691 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1692 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1693 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1694 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1695 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1696 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1697
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1698 void
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1699 octave_print_internal (std::ostream& os, const DiagMatrix& m,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1700 bool pr_as_read_syntax, int extra_indent)
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1701 {
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1702 octave_idx_type nr = m.rows ();
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1703 octave_idx_type nc = m.columns ();
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1704
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1705 if (nr == 0 || nc == 0)
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1706 print_empty_matrix (os, nr, nc, pr_as_read_syntax);
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1707 else if (plus_format && ! pr_as_read_syntax)
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1708 {
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1709 for (octave_idx_type i = 0; i < nr; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1710 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1711 for (octave_idx_type j = 0; j < nc; j++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1712 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1713 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1714
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1715 pr_plus_format (os, m(i,j));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1716 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1717
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1718 if (i < nr - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1719 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1720 }
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1721 }
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1722 else
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1723 {
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1724 int fw;
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1725 double scale = 1.0;
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1726 set_format (Matrix (m.diag ()), fw, scale);
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1727 int column_width = fw + 2;
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1728 octave_idx_type total_width = nc * column_width;
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1729 octave_idx_type max_width = command_editor::terminal_cols ();
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1730
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1731 if (pr_as_read_syntax)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1732 max_width -= 4;
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1733 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1734 max_width -= extra_indent;
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1735
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1736 if (max_width < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1737 max_width = 0;
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1738
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1739 if (free_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1740 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1741 if (pr_as_read_syntax)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1742 os << "[\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1743
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1744 os << Matrix (m);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1745
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1746 if (pr_as_read_syntax)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1747 os << "]";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1748
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1749 return;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1750 }
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1751
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1752 octave_idx_type inc = nc;
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1753 if (total_width > max_width && Vsplit_long_rows)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1754 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1755 inc = max_width / column_width;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1756 if (inc == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1757 inc++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1758 }
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1759
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1760 if (pr_as_read_syntax)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1761 {
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1762 os << "diag (";
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1763
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1764 octave_idx_type col = 0;
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1765 while (col < nc)
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1766 {
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1767 octave_idx_type lim = col + inc < nc ? col + inc : nc;
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1768
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1769 for (octave_idx_type j = col; j < lim; j++)
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1770 {
10142
829e69ec3110 make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents: 10066
diff changeset
1771 octave_quit ();
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1772
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1773 if (j == 0)
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1774 os << "[ ";
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1775 else
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1776 {
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1777 if (j > col && j < lim)
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1778 os << ", ";
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1779 else
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1780 os << " ";
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1781 }
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1782
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1783 pr_float (os, m(j,j));
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1784 }
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1785
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1786 col += inc;
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1787
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1788 if (col >= nc)
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1789 os << " ]";
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1790 else
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1791 os << " ...\n";
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1792 }
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1793 os << ")";
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1794 }
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1795 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1796 {
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
1797 os << "Diagonal Matrix\n\n";
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1798 pr_scale_header (os, scale);
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1799
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1800 // kluge. Get the true width of a number.
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1801 int zero_fw;
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1802
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1803 {
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1804 std::ostringstream tmp_oss;
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1805 pr_float (tmp_oss, 0.0, fw, scale);
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1806 zero_fw = tmp_oss.str ().length ();
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1807 }
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1808
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1809 for (octave_idx_type col = 0; col < nc; col += inc)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1810 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1811 octave_idx_type lim = col + inc < nc ? col + inc : nc;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1812
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1813 pr_col_num_header (os, total_width, max_width, lim, col,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1814 extra_indent);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1815
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1816 for (octave_idx_type i = 0; i < nr; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1817 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1818 os << std::setw (extra_indent) << "";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1819
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1820 for (octave_idx_type j = col; j < lim; j++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1821 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1822 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1823
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1824 os << " ";
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1825
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1826 if (i == j)
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1827 pr_float (os, m(i,j), fw, scale);
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1828 else
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1829 os << std::setw (zero_fw) << '0';
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1830
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1831 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1832
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1833 if (i < nr - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1834 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1835 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1836 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1837 }
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1838 }
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1839 }
4532
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4513
diff changeset
1840 #define PRINT_ND_ARRAY(os, nda, NDA_T, ELT_T, MAT_T) \
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4513
diff changeset
1841 do \
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4513
diff changeset
1842 { \
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1843 if (nda.is_empty ()) \
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1844 print_empty_nd_array (os, nda.dims (), pr_as_read_syntax); \
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1845 else \
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1846 { \
4532
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4513
diff changeset
1847 \
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1848 int ndims = nda.ndims (); \
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1849 \
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1850 dim_vector dims = nda.dims (); \
4532
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4513
diff changeset
1851 \
10350
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1852 Array<octave_idx_type> ra_idx (ndims, 1, 0); \
4532
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4513
diff changeset
1853 \
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
1854 octave_idx_type m = 1; \
4532
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4513
diff changeset
1855 \
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1856 for (int i = 2; i < ndims; i++) \
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1857 m *= dims(i); \
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1858 \
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
1859 octave_idx_type nr = dims(0); \
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
1860 octave_idx_type nc = dims(1); \
4532
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4513
diff changeset
1861 \
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
1862 for (octave_idx_type i = 0; i < m; i++) \
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1863 { \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1864 octave_quit (); \
4655
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
1865 \
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1866 std::string nm = "ans"; \
4532
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4513
diff changeset
1867 \
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1868 if (m > 1) \
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1869 { \
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1870 nm += "(:,:,"; \
4532
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4513
diff changeset
1871 \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1872 std::ostringstream buf; \
4532
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4513
diff changeset
1873 \
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1874 for (int k = 2; k < ndims; k++) \
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1875 { \
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1876 buf << ra_idx(k) + 1; \
4532
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4513
diff changeset
1877 \
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1878 if (k < ndims - 1) \
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1879 buf << ","; \
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1880 else \
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1881 buf << ")"; \
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1882 } \
4532
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4513
diff changeset
1883 \
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5759
diff changeset
1884 nm += buf.str (); \
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1885 } \
4532
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4513
diff changeset
1886 \
10350
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1887 Array<idx_vector> idx (ndims, 1); \
4532
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4513
diff changeset
1888 \
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1889 idx(0) = idx_vector (':'); \
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1890 idx(1) = idx_vector (':'); \
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1891 \
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1892 for (int k = 2; k < ndims; k++) \
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
1893 idx(k) = idx_vector (ra_idx(k)); \
4532
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4513
diff changeset
1894 \
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1895 octave_value page \
10352
a3635bc1ea19 remove Array2
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
1896 = MAT_T (Array<ELT_T> (nda.index (idx), nr, nc)); \
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1897 \
10706
6f34e781aed2 Second try at removing extra newlines from NDArrays
Rik <octave@nomad.inbox5.com>
parents: 10705
diff changeset
1898 if (i != m - 1) \
10705
d500acdcf2dd Remove extra newlines when displaying multi-dimensional arrays.
Rik <octave@nomad.inbox5.com>
parents: 10352
diff changeset
1899 { \
d500acdcf2dd Remove extra newlines when displaying multi-dimensional arrays.
Rik <octave@nomad.inbox5.com>
parents: 10352
diff changeset
1900 page.print_with_name (os, nm); \
d500acdcf2dd Remove extra newlines when displaying multi-dimensional arrays.
Rik <octave@nomad.inbox5.com>
parents: 10352
diff changeset
1901 } \
d500acdcf2dd Remove extra newlines when displaying multi-dimensional arrays.
Rik <octave@nomad.inbox5.com>
parents: 10352
diff changeset
1902 else \
d500acdcf2dd Remove extra newlines when displaying multi-dimensional arrays.
Rik <octave@nomad.inbox5.com>
parents: 10352
diff changeset
1903 { \
d500acdcf2dd Remove extra newlines when displaying multi-dimensional arrays.
Rik <octave@nomad.inbox5.com>
parents: 10352
diff changeset
1904 page.print_name_tag (os, nm); \
10706
6f34e781aed2 Second try at removing extra newlines from NDArrays
Rik <octave@nomad.inbox5.com>
parents: 10705
diff changeset
1905 page.print_raw (os); \
10705
d500acdcf2dd Remove extra newlines when displaying multi-dimensional arrays.
Rik <octave@nomad.inbox5.com>
parents: 10352
diff changeset
1906 } \
d500acdcf2dd Remove extra newlines when displaying multi-dimensional arrays.
Rik <octave@nomad.inbox5.com>
parents: 10352
diff changeset
1907 \
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1908 if (i < m) \
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1909 NDA_T::increment_index (ra_idx, dims, 2); \
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1910 } \
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1911 } \
4532
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4513
diff changeset
1912 } \
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4513
diff changeset
1913 while (0)
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4513
diff changeset
1914
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
1915 void
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
1916 octave_print_internal (std::ostream& os, const NDArray& nda,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1917 bool pr_as_read_syntax, int extra_indent)
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
1918 {
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
1919 switch (nda.ndims ())
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
1920 {
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
1921 case 1:
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
1922 case 2:
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
1923 octave_print_internal (os, nda.matrix_value (),
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1924 pr_as_read_syntax, extra_indent);
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
1925 break;
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
1926
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
1927 default:
4532
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4513
diff changeset
1928 PRINT_ND_ARRAY (os, nda, NDArray, double, Matrix);
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
1929 break;
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
1930 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
1931 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
1932
5030
160365410ad4 [project @ 2004-09-24 03:22:23 by jwe]
jwe
parents: 4949
diff changeset
1933 template <>
6018
bda649f500bd [project @ 2006-10-02 17:23:18 by jwe]
jwe
parents: 6015
diff changeset
1934 /* static */ inline void
6015
a104f362b5d4 [project @ 2006-10-02 02:13:53 by jwe]
jwe
parents: 6008
diff changeset
1935 pr_plus_format<> (std::ostream& os, const Complex& c)
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
1936 {
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
1937 double rp = c.real ();
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
1938 double ip = c.imag ();
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
1939
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
1940 if (rp == 0.0)
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
1941 {
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
1942 if (ip == 0.0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1943 os << " ";
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
1944 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1945 os << "i";
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
1946 }
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
1947 else if (ip == 0.0)
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1948 pr_plus_format (os, rp);
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
1949 else
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
1950 os << "c";
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
1951 }
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
1952
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1953 void
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
1954 octave_print_internal (std::ostream& os, const Complex& c,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1955 bool /* pr_as_read_syntax */)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1956 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1957 if (plus_format)
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1958 {
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1959 pr_plus_format (os, c);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1960 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1961 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1962 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1963 set_format (c);
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1964 if (free_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1965 os << c;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1966 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1967 pr_complex (os, c);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1968 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1969 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1970
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1971 void
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
1972 octave_print_internal (std::ostream& os, const ComplexMatrix& cm,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1973 bool pr_as_read_syntax, int extra_indent)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1974 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
1975 octave_idx_type nr = cm.rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
1976 octave_idx_type nc = cm.columns ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1977
2408
e22aae3ccfad [project @ 1996-10-15 16:37:52 by jwe]
jwe
parents: 2387
diff changeset
1978 if (nr == 0 || nc == 0)
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1979 print_empty_matrix (os, nr, nc, pr_as_read_syntax);
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1980 else if (plus_format && ! pr_as_read_syntax)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1981 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
1982 for (octave_idx_type i = 0; i < nr; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1983 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1984 for (octave_idx_type j = 0; j < nc; j++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1985 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1986 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1987
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1988 pr_plus_format (os, cm(i,j));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1989 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1990
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1991 if (i < nr - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1992 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1993 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1994 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1995 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1996 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1997 int r_fw, i_fw;
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1998 double scale = 1.0;
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1999 set_format (cm, r_fw, i_fw, scale);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2000 int column_width = i_fw + r_fw;
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
2001 column_width += (rat_format || bank_format || hex_format
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2002 || bit_format) ? 2 : 7;
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2003 octave_idx_type total_width = nc * column_width;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2004 octave_idx_type max_width = command_editor::terminal_cols ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2005
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
2006 if (pr_as_read_syntax)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2007 max_width -= 4;
1972
58ac5f889c64 [project @ 1996-02-24 07:12:58 by jwe]
jwe
parents: 1968
diff changeset
2008 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2009 max_width -= extra_indent;
1972
58ac5f889c64 [project @ 1996-02-24 07:12:58 by jwe]
jwe
parents: 1968
diff changeset
2010
58ac5f889c64 [project @ 1996-02-24 07:12:58 by jwe]
jwe
parents: 1968
diff changeset
2011 if (max_width < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2012 max_width = 0;
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
2013
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2014 if (free_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2015 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2016 if (pr_as_read_syntax)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2017 os << "[\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2018
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2019 os << cm;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2020
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2021 if (pr_as_read_syntax)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2022 os << "]";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2023
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2024 return;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2025 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2026
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2027 octave_idx_type inc = nc;
2165
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
2028 if (total_width > max_width && Vsplit_long_rows)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2029 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2030 inc = max_width / column_width;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2031 if (inc == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2032 inc++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2033 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2034
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
2035 if (pr_as_read_syntax)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2036 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2037 for (octave_idx_type i = 0; i < nr; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2038 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2039 octave_idx_type col = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2040 while (col < nc)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2041 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2042 octave_idx_type lim = col + inc < nc ? col + inc : nc;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2043
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2044 for (octave_idx_type j = col; j < lim; j++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2045 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2046 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2047
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2048 if (i == 0 && j == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2049 os << "[ ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2050 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2051 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2052 if (j > col && j < lim)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2053 os << ", ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2054 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2055 os << " ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2056 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2057
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2058 pr_complex (os, cm(i,j));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2059 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2060
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2061 col += inc;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2062
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2063 if (col >= nc)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2064 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2065 if (i == nr - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2066 os << " ]";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2067 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2068 os << ";\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2069 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2070 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2071 os << " ...\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2072 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2073 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2074 }
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
2075 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2076 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2077 pr_scale_header (os, scale);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2078
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2079 for (octave_idx_type col = 0; col < nc; col += inc)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2080 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2081 octave_idx_type lim = col + inc < nc ? col + inc : nc;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2082
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2083 pr_col_num_header (os, total_width, max_width, lim, col,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2084 extra_indent);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2085
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2086 for (octave_idx_type i = 0; i < nr; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2087 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2088 os << std::setw (extra_indent) << "";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2089
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2090 for (octave_idx_type j = col; j < lim; j++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2091 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2092 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2093
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2094 os << " ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2095
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2096 pr_complex (os, cm(i,j), r_fw, i_fw, scale);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2097 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2098
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2099 if (i < nr - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2100 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2101 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2102 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2103 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2104 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2105 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2106
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2107 void
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2108 octave_print_internal (std::ostream& os, const ComplexDiagMatrix& cm,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2109 bool pr_as_read_syntax, int extra_indent)
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2110 {
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2111 octave_idx_type nr = cm.rows ();
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2112 octave_idx_type nc = cm.columns ();
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2113
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2114 if (nr == 0 || nc == 0)
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2115 print_empty_matrix (os, nr, nc, pr_as_read_syntax);
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2116 else if (plus_format && ! pr_as_read_syntax)
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2117 {
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2118 for (octave_idx_type i = 0; i < nr; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2119 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2120 for (octave_idx_type j = 0; j < nc; j++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2121 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2122 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2123
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2124 pr_plus_format (os, cm(i,j));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2125 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2126
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2127 if (i < nr - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2128 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2129 }
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2130 }
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2131 else
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2132 {
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2133 int r_fw, i_fw;
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2134 double scale = 1.0;
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2135 set_format (ComplexMatrix (cm.diag ()), r_fw, i_fw, scale);
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2136 int column_width = i_fw + r_fw;
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2137 column_width += (rat_format || bank_format || hex_format
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2138 || bit_format) ? 2 : 7;
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2139 octave_idx_type total_width = nc * column_width;
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2140 octave_idx_type max_width = command_editor::terminal_cols ();
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2141
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2142 if (pr_as_read_syntax)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2143 max_width -= 4;
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2144 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2145 max_width -= extra_indent;
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2146
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2147 if (max_width < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2148 max_width = 0;
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2149
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2150 if (free_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2151 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2152 if (pr_as_read_syntax)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2153 os << "[\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2154
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2155 os << ComplexMatrix (cm);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2156
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2157 if (pr_as_read_syntax)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2158 os << "]";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2159
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2160 return;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2161 }
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2162
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2163 octave_idx_type inc = nc;
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2164 if (total_width > max_width && Vsplit_long_rows)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2165 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2166 inc = max_width / column_width;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2167 if (inc == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2168 inc++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2169 }
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2170
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2171 if (pr_as_read_syntax)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2172 {
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2173 os << "diag (";
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2174
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2175 octave_idx_type col = 0;
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2176 while (col < nc)
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2177 {
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2178 octave_idx_type lim = col + inc < nc ? col + inc : nc;
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2179
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2180 for (octave_idx_type j = col; j < lim; j++)
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2181 {
10142
829e69ec3110 make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents: 10066
diff changeset
2182 octave_quit ();
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2183
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2184 if (j == 0)
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2185 os << "[ ";
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2186 else
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2187 {
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2188 if (j > col && j < lim)
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2189 os << ", ";
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2190 else
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2191 os << " ";
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2192 }
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2193
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2194 pr_complex (os, cm(j,j));
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2195 }
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2196
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2197 col += inc;
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2198
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2199 if (col >= nc)
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2200 os << " ]";
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2201 else
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2202 os << " ...\n";
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2203 }
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2204 os << ")";
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2205 }
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2206 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2207 {
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2208 os << "Diagonal Matrix\n\n";
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2209 pr_scale_header (os, scale);
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2210
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2211 // kluge. Get the true width of a number.
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2212 int zero_fw;
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2213
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2214 {
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2215 std::ostringstream tmp_oss;
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2216 pr_complex (tmp_oss, Complex (0.0), r_fw, i_fw, scale);
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2217 zero_fw = tmp_oss.str ().length ();
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2218 }
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2219
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2220 for (octave_idx_type col = 0; col < nc; col += inc)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2221 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2222 octave_idx_type lim = col + inc < nc ? col + inc : nc;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2223
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2224 pr_col_num_header (os, total_width, max_width, lim, col,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2225 extra_indent);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2226
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2227 for (octave_idx_type i = 0; i < nr; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2228 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2229 os << std::setw (extra_indent) << "";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2230
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2231 for (octave_idx_type j = col; j < lim; j++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2232 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2233 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2234
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2235 os << " ";
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2236
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2237 if (i == j)
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2238 pr_complex (os, cm(i,j), r_fw, i_fw, scale);
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2239 else
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2240 os << std::setw (zero_fw) << '0';
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2241 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2242
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2243 if (i < nr - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2244 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2245 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2246 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2247 }
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2248 }
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2249 }
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2250
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2251 void
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2252 octave_print_internal (std::ostream& os, const PermMatrix& m,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2253 bool pr_as_read_syntax, int extra_indent)
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2254 {
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2255 octave_idx_type nr = m.rows ();
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2256 octave_idx_type nc = m.columns ();
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2257
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2258 if (nr == 0 || nc == 0)
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2259 print_empty_matrix (os, nr, nc, pr_as_read_syntax);
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2260 else if (plus_format && ! pr_as_read_syntax)
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2261 {
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2262 for (octave_idx_type i = 0; i < nr; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2263 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2264 for (octave_idx_type j = 0; j < nc; j++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2265 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2266 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2267
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2268 pr_plus_format (os, m(i,j));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2269 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2270
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2271 if (i < nr - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2272 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2273 }
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2274 }
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2275 else
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2276 {
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2277 int fw = 2;
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2278 int column_width = fw + 2;
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2279 octave_idx_type total_width = nc * column_width;
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2280 octave_idx_type max_width = command_editor::terminal_cols ();
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2281
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2282 if (pr_as_read_syntax)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2283 max_width -= 4;
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2284 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2285 max_width -= extra_indent;
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2286
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2287 if (max_width < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2288 max_width = 0;
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2289
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2290 if (free_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2291 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2292 if (pr_as_read_syntax)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2293 os << "[\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2294
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2295 os << Matrix (m);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2296
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2297 if (pr_as_read_syntax)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2298 os << "]";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2299
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2300 return;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2301 }
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2302
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2303 octave_idx_type inc = nc;
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2304 if (total_width > max_width && Vsplit_long_rows)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2305 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2306 inc = max_width / column_width;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2307 if (inc == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2308 inc++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2309 }
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2310
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2311 if (pr_as_read_syntax)
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2312 {
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2313 Array<octave_idx_type> pvec = m.pvec ();
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2314 bool colp = m.is_col_perm ();
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2315
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2316 os << "eye (";
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2317 if (colp) os << ":, ";
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2318
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2319 octave_idx_type col = 0;
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2320 while (col < nc)
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2321 {
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2322 octave_idx_type lim = col + inc < nc ? col + inc : nc;
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2323
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2324 for (octave_idx_type j = col; j < lim; j++)
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2325 {
10142
829e69ec3110 make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents: 10066
diff changeset
2326 octave_quit ();
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2327
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2328 if (j == 0)
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2329 os << "[ ";
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2330 else
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2331 {
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2332 if (j > col && j < lim)
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2333 os << ", ";
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2334 else
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2335 os << " ";
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2336 }
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2337
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2338 os << pvec (j);
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2339 }
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2340
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2341 col += inc;
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2342
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2343 if (col >= nc)
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2344 os << " ]";
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2345 else
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2346 os << " ...\n";
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2347 }
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2348 if (! colp) os << ", :";
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2349 os << ")";
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2350 }
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2351 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2352 {
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2353 os << "Permutation Matrix\n\n";
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2354
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2355 for (octave_idx_type col = 0; col < nc; col += inc)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2356 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2357 octave_idx_type lim = col + inc < nc ? col + inc : nc;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2358
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2359 pr_col_num_header (os, total_width, max_width, lim, col,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2360 extra_indent);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2361
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2362 for (octave_idx_type i = 0; i < nr; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2363 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2364 os << std::setw (extra_indent) << "";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2365
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2366 for (octave_idx_type j = col; j < lim; j++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2367 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2368 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2369
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2370 os << " ";
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2371
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2372 os << std::setw (fw) << m(i,j);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2373 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2374
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2375 if (i < nr - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2376 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2377 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2378 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2379 }
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2380 }
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2381 }
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2382
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2383 void
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2384 octave_print_internal (std::ostream& os, const ComplexNDArray& nda,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2385 bool pr_as_read_syntax, int extra_indent)
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2386 {
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2387 switch (nda.ndims ())
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2388 {
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2389 case 1:
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2390 case 2:
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2391 octave_print_internal (os, nda.matrix_value (),
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2392 pr_as_read_syntax, extra_indent);
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2393 break;
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2394
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2395 default:
4532
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4513
diff changeset
2396 PRINT_ND_ARRAY (os, nda, ComplexNDArray, Complex, ComplexMatrix);
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2397 break;
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2398 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2399 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2400
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2401 void
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2402 octave_print_internal (std::ostream& os, bool d, bool pr_as_read_syntax)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2403 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2404 octave_print_internal (os, double (d), pr_as_read_syntax);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2405 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2406
8333
9238637cb81c style fixes
John W. Eaton <jwe@octave.org>
parents: 8290
diff changeset
2407 // FIXME -- write single precision versions of the printing functions.
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2408
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2409 void
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2410 octave_print_internal (std::ostream& os, float d, bool pr_as_read_syntax)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2411 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2412 octave_print_internal (os, double (d), pr_as_read_syntax);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2413 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2414
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2415 void
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2416 octave_print_internal (std::ostream& os, const FloatMatrix& m,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2417 bool pr_as_read_syntax, int extra_indent)
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2418 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2419 octave_print_internal (os, Matrix (m), pr_as_read_syntax, extra_indent);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2420 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2421
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2422 void
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2423 octave_print_internal (std::ostream& os, const FloatDiagMatrix& m,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2424 bool pr_as_read_syntax, int extra_indent)
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2425 {
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2426 octave_print_internal (os, DiagMatrix (m), pr_as_read_syntax, extra_indent);
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2427 }
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2428
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2429 void
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2430 octave_print_internal (std::ostream& os, const FloatNDArray& nda,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2431 bool pr_as_read_syntax, int extra_indent)
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2432 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2433 octave_print_internal (os, NDArray (nda), pr_as_read_syntax, extra_indent);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2434 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2435
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2436 void
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2437 octave_print_internal (std::ostream& os, const FloatComplex& c,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2438 bool pr_as_read_syntax)
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2439 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2440 octave_print_internal (os, Complex (c), pr_as_read_syntax);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2441 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2442
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2443 void
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2444 octave_print_internal (std::ostream& os, const FloatComplexMatrix& cm,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2445 bool pr_as_read_syntax, int extra_indent)
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2446 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2447 octave_print_internal (os, ComplexMatrix (cm), pr_as_read_syntax, extra_indent);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2448 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2449
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2450 void
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2451 octave_print_internal (std::ostream& os, const FloatComplexDiagMatrix& cm,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2452 bool pr_as_read_syntax, int extra_indent)
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2453 {
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2454 octave_print_internal (os, ComplexDiagMatrix (cm), pr_as_read_syntax, extra_indent);
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2455 }
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2456
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2457 void
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2458 octave_print_internal (std::ostream& os, const FloatComplexNDArray& nda,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2459 bool pr_as_read_syntax, int extra_indent)
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2460 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2461 octave_print_internal (os, ComplexNDArray (nda), pr_as_read_syntax, extra_indent);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2462 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2463
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2464 void
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2465 octave_print_internal (std::ostream& os, const Range& r,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2466 bool pr_as_read_syntax, int extra_indent)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2467 {
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
2468 double base = r.base ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2469 double increment = r.inc ();
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
2470 double limit = r.limit ();
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2471 octave_idx_type num_elem = r.nelem ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2472
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
2473 if (plus_format && ! pr_as_read_syntax)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2474 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2475 for (octave_idx_type i = 0; i < num_elem; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2476 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2477 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2478
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2479 double val = base + i * increment;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2480
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2481 pr_plus_format (os, val);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2482 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2483 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2484 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2485 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2486 int fw;
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
2487 double scale = 1.0;
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
2488 set_format (r, fw, scale);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2489
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
2490 if (pr_as_read_syntax)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2491 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2492 if (free_format)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2493 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2494 os << base << " : ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2495 if (increment != 1.0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2496 os << increment << " : ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2497 os << limit;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2498 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2499 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2500 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2501 pr_float (os, base, fw);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2502 os << " : ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2503 if (increment != 1.0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2504 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2505 pr_float (os, increment, fw);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2506 os << " : ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2507 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2508 pr_float (os, limit, fw);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2509 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2510 }
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
2511 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2512 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2513 int column_width = fw + 2;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2514 octave_idx_type total_width = num_elem * column_width;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2515 octave_idx_type max_width = command_editor::terminal_cols ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2516
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2517 if (free_format)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2518 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2519 os << r;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2520 return;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2521 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2522
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2523 octave_idx_type inc = num_elem;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2524 if (total_width > max_width && Vsplit_long_rows)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2525 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2526 inc = max_width / column_width;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2527 if (inc == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2528 inc++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2529 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2530
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2531 max_width -= extra_indent;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2532
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2533 if (max_width < 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2534 max_width = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2535
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2536 pr_scale_header (os, scale);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2537
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2538 octave_idx_type col = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2539 while (col < num_elem)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2540 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2541 octave_idx_type lim = col + inc < num_elem ? col + inc : num_elem;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2542
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2543 pr_col_num_header (os, total_width, max_width, lim, col,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2544 extra_indent);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2545
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2546 os << std::setw (extra_indent) << "";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2547
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2548 for (octave_idx_type i = col; i < lim; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2549 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2550 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2551
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2552 double val = base + i * increment;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2553
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2554 if (i == num_elem - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2555 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2556 // See the comments in Range::matrix_value.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2557
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2558 if ((increment > 0 && val > limit)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2559 || (increment < 0 && val < limit))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2560 val = limit;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2561 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2562
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2563 os << " ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2564
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2565 pr_float (os, val, fw, scale);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2566 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2567
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2568 col += inc;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2569 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2570 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2571 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2572 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2573
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1328
diff changeset
2574 void
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2575 octave_print_internal (std::ostream& os, const boolMatrix& bm,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2576 bool pr_as_read_syntax,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2577 int extra_indent)
3215
bc3fdfe311a3 [project @ 1998-11-10 14:06:21 by jwe]
jwe
parents: 3164
diff changeset
2578 {
bc3fdfe311a3 [project @ 1998-11-10 14:06:21 by jwe]
jwe
parents: 3164
diff changeset
2579 Matrix tmp (bm);
bc3fdfe311a3 [project @ 1998-11-10 14:06:21 by jwe]
jwe
parents: 3164
diff changeset
2580 octave_print_internal (os, tmp, pr_as_read_syntax, extra_indent);
bc3fdfe311a3 [project @ 1998-11-10 14:06:21 by jwe]
jwe
parents: 3164
diff changeset
2581 }
bc3fdfe311a3 [project @ 1998-11-10 14:06:21 by jwe]
jwe
parents: 3164
diff changeset
2582
bc3fdfe311a3 [project @ 1998-11-10 14:06:21 by jwe]
jwe
parents: 3164
diff changeset
2583 void
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2584 octave_print_internal (std::ostream& os, const boolNDArray& nda,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2585 bool pr_as_read_syntax,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2586 int extra_indent)
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2587 {
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2588 switch (nda.ndims ())
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2589 {
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2590 case 1:
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2591 case 2:
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2592 octave_print_internal (os, nda.matrix_value (),
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2593 pr_as_read_syntax, extra_indent);
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2594 break;
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2595
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2596 default:
4532
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4513
diff changeset
2597 PRINT_ND_ARRAY (os, nda, boolNDArray, bool, boolMatrix);
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2598 break;
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2599 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2600 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2601
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2602 void
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2603 octave_print_internal (std::ostream& os, const charMatrix& chm,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2604 bool pr_as_read_syntax,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2605 int /* extra_indent FIXME */,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2606 bool pr_as_string)
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1328
diff changeset
2607 {
1572
0d9e10d10bd7 [project @ 1995-10-19 04:31:30 by jwe]
jwe
parents: 1488
diff changeset
2608 if (pr_as_string)
0d9e10d10bd7 [project @ 1995-10-19 04:31:30 by jwe]
jwe
parents: 1488
diff changeset
2609 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2610 octave_idx_type nstr = chm.rows ();
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1328
diff changeset
2611
1572
0d9e10d10bd7 [project @ 1995-10-19 04:31:30 by jwe]
jwe
parents: 1488
diff changeset
2612 if (pr_as_read_syntax && nstr > 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2613 os << "[ ";
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1328
diff changeset
2614
2907
8bb31a2b480b [project @ 1997-04-30 05:01:46 by jwe]
jwe
parents: 2903
diff changeset
2615 if (nstr != 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2616 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2617 for (octave_idx_type i = 0; i < nstr; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2618 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2619 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2620
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2621 std::string row = chm.row_as_string (i);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2622
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2623 if (pr_as_read_syntax)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2624 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2625 os << "\"" << undo_string_escapes (row) << "\"";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2626
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2627 if (i < nstr - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2628 os << "; ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2629 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2630 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2631 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2632 os << row;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2633
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2634 if (i < nstr - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2635 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2636 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2637 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2638 }
1572
0d9e10d10bd7 [project @ 1995-10-19 04:31:30 by jwe]
jwe
parents: 1488
diff changeset
2639
0d9e10d10bd7 [project @ 1995-10-19 04:31:30 by jwe]
jwe
parents: 1488
diff changeset
2640 if (pr_as_read_syntax && nstr > 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2641 os << " ]";
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1328
diff changeset
2642 }
1572
0d9e10d10bd7 [project @ 1995-10-19 04:31:30 by jwe]
jwe
parents: 1488
diff changeset
2643 else
0d9e10d10bd7 [project @ 1995-10-19 04:31:30 by jwe]
jwe
parents: 1488
diff changeset
2644 {
0d9e10d10bd7 [project @ 1995-10-19 04:31:30 by jwe]
jwe
parents: 1488
diff changeset
2645 os << "sorry, printing char matrices not implemented yet\n";
0d9e10d10bd7 [project @ 1995-10-19 04:31:30 by jwe]
jwe
parents: 1488
diff changeset
2646 }
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1328
diff changeset
2647 }
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1328
diff changeset
2648
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2649 void
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2650 octave_print_internal (std::ostream& os, const charNDArray& nda,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2651 bool pr_as_read_syntax, int extra_indent,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2652 bool pr_as_string)
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2653 {
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2654 switch (nda.ndims ())
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2655 {
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2656 case 1:
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2657 case 2:
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2658 octave_print_internal (os, nda.matrix_value (),
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2659 pr_as_read_syntax, extra_indent, pr_as_string);
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2660 break;
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2661
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2662 default:
4532
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4513
diff changeset
2663 PRINT_ND_ARRAY (os, nda, charNDArray, char, charMatrix);
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2664 break;
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2665 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2666 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2667
4655
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2668 void
4925
90f51232d751 [project @ 2004-08-02 22:09:47 by jwe]
jwe
parents: 4901
diff changeset
2669 octave_print_internal (std::ostream& os, const std::string& s,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2670 bool pr_as_read_syntax, int extra_indent)
4925
90f51232d751 [project @ 2004-08-02 22:09:47 by jwe]
jwe
parents: 4901
diff changeset
2671 {
9732
b4fdfee405b5 remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents: 9643
diff changeset
2672 Array<std::string> nda (dim_vector (1, 1), s);
4925
90f51232d751 [project @ 2004-08-02 22:09:47 by jwe]
jwe
parents: 4901
diff changeset
2673
90f51232d751 [project @ 2004-08-02 22:09:47 by jwe]
jwe
parents: 4901
diff changeset
2674 octave_print_internal (os, nda, pr_as_read_syntax, extra_indent);
90f51232d751 [project @ 2004-08-02 22:09:47 by jwe]
jwe
parents: 4901
diff changeset
2675 }
90f51232d751 [project @ 2004-08-02 22:09:47 by jwe]
jwe
parents: 4901
diff changeset
2676
90f51232d751 [project @ 2004-08-02 22:09:47 by jwe]
jwe
parents: 4901
diff changeset
2677 void
9732
b4fdfee405b5 remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents: 9643
diff changeset
2678 octave_print_internal (std::ostream& os, const Array<std::string>& nda,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2679 bool pr_as_read_syntax, int /* extra_indent */)
4655
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2680 {
5775
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5770
diff changeset
2681 // FIXME -- this mostly duplicates the code in the
4655
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2682 // PRINT_ND_ARRAY macro.
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2683
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2684 if (nda.is_empty ())
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2685 print_empty_nd_array (os, nda.dims (), pr_as_read_syntax);
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2686 else if (nda.length () == 1)
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2687 {
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2688 os << nda(0);
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2689 }
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2690 else
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2691 {
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2692 int ndims = nda.ndims ();
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2693
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2694 dim_vector dims = nda.dims ();
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2695
10350
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
2696 Array<octave_idx_type> ra_idx (ndims, 1, 0);
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2697
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2698 octave_idx_type m = 1;
4655
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2699
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2700 for (int i = 2; i < ndims; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2701 m *= dims(i);
4655
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2702
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2703 octave_idx_type nr = dims(0);
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2704 octave_idx_type nc = dims(1);
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2705
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2706 for (octave_idx_type i = 0; i < m; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2707 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2708 std::string nm = "ans";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2709
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2710 if (m > 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2711 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2712 nm += "(:,:,";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2713
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2714 std::ostringstream buf;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2715
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2716 for (int k = 2; k < ndims; k++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2717 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2718 buf << ra_idx(k) + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2719
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2720 if (k < ndims - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2721 buf << ",";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2722 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2723 buf << ")";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2724 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2725
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2726 nm += buf.str ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2727 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2728
10350
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
2729 Array<idx_vector> idx (ndims, 1);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2730
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2731 idx(0) = idx_vector (':');
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2732 idx(1) = idx_vector (':');
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2733
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2734 for (int k = 2; k < ndims; k++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2735 idx(k) = idx_vector (ra_idx(k));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2736
10352
a3635bc1ea19 remove Array2
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
2737 Array<std::string> page (nda.index (idx), nr, nc);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2738
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2739 // FIXME -- need to do some more work to put these
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2740 // in neatly aligned columns...
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2741
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2742 octave_idx_type n_rows = page.rows ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2743 octave_idx_type n_cols = page.cols ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2744
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2745 os << nm << " =\n\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2746
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2747 for (octave_idx_type ii = 0; ii < n_rows; ii++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2748 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2749 for (octave_idx_type jj = 0; jj < n_cols; jj++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2750 os << " " << page(ii,jj);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2751
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2752 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2753 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2754
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2755 if (i < m - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2756 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2757
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2758 if (i < m)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2759 increment_index (ra_idx, dims, 2);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2760 }
4655
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2761 }
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2762 }
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2763
4901
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2764 template <class T>
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2765 class
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2766 octave_print_conv
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2767 {
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2768 public:
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2769 typedef T print_conv_type;
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2770 };
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2771
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2772 #define PRINT_CONV(T1, T2) \
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2773 template <> \
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2774 class \
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2775 octave_print_conv<T1> \
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2776 { \
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2777 public: \
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2778 typedef T2 print_conv_type; \
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2779 }
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2780
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2781 PRINT_CONV (octave_int8, octave_int16);
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2782 PRINT_CONV (octave_uint8, octave_uint16);
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2783
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2784 #undef PRINT_CONV
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2785
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2786 template <class T>
6018
bda649f500bd [project @ 2006-10-02 17:23:18 by jwe]
jwe
parents: 6015
diff changeset
2787 /* static */ inline void
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2788 pr_int (std::ostream& os, const T& d, int fw = 0)
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2789 {
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2790 size_t sz = d.byte_size();
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2791 const unsigned char * tmpi = d.iptr();
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2792
5544
2286fa5f2e5d [project @ 2005-11-21 18:44:31 by jwe]
jwe
parents: 5404
diff changeset
2793 // Unless explicitly asked for, always print in big-endian
2286fa5f2e5d [project @ 2005-11-21 18:44:31 by jwe]
jwe
parents: 5404
diff changeset
2794 // format for hex and bit formats.
2286fa5f2e5d [project @ 2005-11-21 18:44:31 by jwe]
jwe
parents: 5404
diff changeset
2795 //
2286fa5f2e5d [project @ 2005-11-21 18:44:31 by jwe]
jwe
parents: 5404
diff changeset
2796 // {bit,hex}_format == 1: print big-endian
2286fa5f2e5d [project @ 2005-11-21 18:44:31 by jwe]
jwe
parents: 5404
diff changeset
2797 // {bit,hex}_format == 2: print native
2286fa5f2e5d [project @ 2005-11-21 18:44:31 by jwe]
jwe
parents: 5404
diff changeset
2798
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2799 if (hex_format)
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2800 {
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2801 char ofill = os.fill ('0');
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2802
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2803 std::ios::fmtflags oflags
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2804 = os.flags (std::ios::right | std::ios::hex);
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2805
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2806 if (hex_format > 1 || oct_mach_info::words_big_endian ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2807 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2808 for (size_t i = 0; i < sz; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2809 os << std::setw (2) << static_cast<int> (tmpi[i]);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2810 }
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2811 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2812 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2813 for (int i = sz - 1; i >= 0; i--)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2814 os << std::setw (2) << static_cast<int> (tmpi[i]);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2815 }
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2816
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2817 os.fill (ofill);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2818 os.setf (oflags);
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2819 }
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2820 else if (bit_format)
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2821 {
5544
2286fa5f2e5d [project @ 2005-11-21 18:44:31 by jwe]
jwe
parents: 5404
diff changeset
2822 if (oct_mach_info::words_big_endian ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2823 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2824 for (size_t i = 0; i < sz; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2825 PRINT_CHAR_BITS (os, tmpi[i]);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2826 }
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2827 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2828 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2829 if (bit_format > 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2830 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2831 for (size_t i = 0; i < sz; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2832 PRINT_CHAR_BITS_SWAPPED (os, tmpi[i]);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2833 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2834 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2835 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2836 for (int i = sz - 1; i >= 0; i--)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2837 PRINT_CHAR_BITS (os, tmpi[i]);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2838 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2839 }
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2840 }
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2841 else
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2842 {
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2843 os << std::setw (fw)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2844 << typename octave_print_conv<T>::print_conv_type (d);
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2845
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2846 if (bank_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2847 os << ".00";
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2848 }
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2849 }
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2850
6120
ba9db42a1fe0 [project @ 2006-10-28 02:45:48 by jwe]
jwe
parents: 6109
diff changeset
2851 // FIXME -- all this mess with abs is an attempt to avoid seeing
ba9db42a1fe0 [project @ 2006-10-28 02:45:48 by jwe]
jwe
parents: 6109
diff changeset
2852 //
ba9db42a1fe0 [project @ 2006-10-28 02:45:48 by jwe]
jwe
parents: 6109
diff changeset
2853 // warning: comparison of unsigned expression < 0 is always false
ba9db42a1fe0 [project @ 2006-10-28 02:45:48 by jwe]
jwe
parents: 6109
diff changeset
2854 //
ba9db42a1fe0 [project @ 2006-10-28 02:45:48 by jwe]
jwe
parents: 6109
diff changeset
2855 // from GCC. Isn't there a better way
ba9db42a1fe0 [project @ 2006-10-28 02:45:48 by jwe]
jwe
parents: 6109
diff changeset
2856
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2857 template <class T>
6018
bda649f500bd [project @ 2006-10-02 17:23:18 by jwe]
jwe
parents: 6015
diff changeset
2858 /* static */ inline T
6008
0f5bc819fdb8 [project @ 2006-09-27 15:34:28 by jwe]
jwe
parents: 5945
diff changeset
2859 abs (T x)
0f5bc819fdb8 [project @ 2006-09-27 15:34:28 by jwe]
jwe
parents: 5945
diff changeset
2860 {
6120
ba9db42a1fe0 [project @ 2006-10-28 02:45:48 by jwe]
jwe
parents: 6109
diff changeset
2861 return x < 0 ? -x : x;
6008
0f5bc819fdb8 [project @ 2006-09-27 15:34:28 by jwe]
jwe
parents: 5945
diff changeset
2862 }
0f5bc819fdb8 [project @ 2006-09-27 15:34:28 by jwe]
jwe
parents: 5945
diff changeset
2863
6120
ba9db42a1fe0 [project @ 2006-10-28 02:45:48 by jwe]
jwe
parents: 6109
diff changeset
2864 #define INSTANTIATE_ABS(T) \
ba9db42a1fe0 [project @ 2006-10-28 02:45:48 by jwe]
jwe
parents: 6109
diff changeset
2865 template /* static */ inline T abs (T)
ba9db42a1fe0 [project @ 2006-10-28 02:45:48 by jwe]
jwe
parents: 6109
diff changeset
2866
ba9db42a1fe0 [project @ 2006-10-28 02:45:48 by jwe]
jwe
parents: 6109
diff changeset
2867 INSTANTIATE_ABS(signed char);
ba9db42a1fe0 [project @ 2006-10-28 02:45:48 by jwe]
jwe
parents: 6109
diff changeset
2868 INSTANTIATE_ABS(short);
ba9db42a1fe0 [project @ 2006-10-28 02:45:48 by jwe]
jwe
parents: 6109
diff changeset
2869 INSTANTIATE_ABS(int);
ba9db42a1fe0 [project @ 2006-10-28 02:45:48 by jwe]
jwe
parents: 6109
diff changeset
2870 INSTANTIATE_ABS(long);
ba9db42a1fe0 [project @ 2006-10-28 02:45:48 by jwe]
jwe
parents: 6109
diff changeset
2871 INSTANTIATE_ABS(long long);
ba9db42a1fe0 [project @ 2006-10-28 02:45:48 by jwe]
jwe
parents: 6109
diff changeset
2872
ba9db42a1fe0 [project @ 2006-10-28 02:45:48 by jwe]
jwe
parents: 6109
diff changeset
2873 #define SPECIALIZE_UABS(T) \
ba9db42a1fe0 [project @ 2006-10-28 02:45:48 by jwe]
jwe
parents: 6109
diff changeset
2874 template <> \
ba9db42a1fe0 [project @ 2006-10-28 02:45:48 by jwe]
jwe
parents: 6109
diff changeset
2875 /* static */ inline unsigned T \
ba9db42a1fe0 [project @ 2006-10-28 02:45:48 by jwe]
jwe
parents: 6109
diff changeset
2876 abs (unsigned T x) \
ba9db42a1fe0 [project @ 2006-10-28 02:45:48 by jwe]
jwe
parents: 6109
diff changeset
2877 { \
ba9db42a1fe0 [project @ 2006-10-28 02:45:48 by jwe]
jwe
parents: 6109
diff changeset
2878 return x; \
ba9db42a1fe0 [project @ 2006-10-28 02:45:48 by jwe]
jwe
parents: 6109
diff changeset
2879 }
ba9db42a1fe0 [project @ 2006-10-28 02:45:48 by jwe]
jwe
parents: 6109
diff changeset
2880
ba9db42a1fe0 [project @ 2006-10-28 02:45:48 by jwe]
jwe
parents: 6109
diff changeset
2881 SPECIALIZE_UABS(char)
ba9db42a1fe0 [project @ 2006-10-28 02:45:48 by jwe]
jwe
parents: 6109
diff changeset
2882 SPECIALIZE_UABS(short)
ba9db42a1fe0 [project @ 2006-10-28 02:45:48 by jwe]
jwe
parents: 6109
diff changeset
2883 SPECIALIZE_UABS(int)
ba9db42a1fe0 [project @ 2006-10-28 02:45:48 by jwe]
jwe
parents: 6109
diff changeset
2884 SPECIALIZE_UABS(long)
ba9db42a1fe0 [project @ 2006-10-28 02:45:48 by jwe]
jwe
parents: 6109
diff changeset
2885 SPECIALIZE_UABS(long long)
6008
0f5bc819fdb8 [project @ 2006-09-27 15:34:28 by jwe]
jwe
parents: 5945
diff changeset
2886
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2887 template void
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2888 pr_int (std::ostream&, const octave_int8&, int);
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2889
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2890 template void
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2891 pr_int (std::ostream&, const octave_int16&, int);
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2892
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2893 template void
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2894 pr_int (std::ostream&, const octave_int32&, int);
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2895
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2896 template void
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2897 pr_int (std::ostream&, const octave_int64&, int);
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2898
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2899 template void
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2900 pr_int (std::ostream&, const octave_uint8&, int);
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2901
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2902 template void
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2903 pr_int (std::ostream&, const octave_uint16&, int);
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2904
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2905 template void
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2906 pr_int (std::ostream&, const octave_uint32&, int);
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2907
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2908 template void
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2909 pr_int (std::ostream&, const octave_uint64&, int);
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2910
6008
0f5bc819fdb8 [project @ 2006-09-27 15:34:28 by jwe]
jwe
parents: 5945
diff changeset
2911 template <class T>
4901
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2912 void
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2913 octave_print_internal_template (std::ostream& os, const octave_int<T>& val,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2914 bool)
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2915 {
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2916 if (plus_format)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2917 {
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2918 pr_plus_format (os, val);
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2919 }
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2920 else
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2921 {
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2922 if (free_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2923 os << typename octave_print_conv<octave_int<T> >::print_conv_type (val);
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2924 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2925 pr_int (os, val);
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2926 }
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2927 }
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2928
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2929 #define PRINT_INT_SCALAR_INTERNAL(TYPE) \
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2930 OCTINTERP_API void \
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2931 octave_print_internal (std::ostream& os, const octave_int<TYPE>& val, bool dummy) \
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2932 { \
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2933 octave_print_internal_template (os, val, dummy); \
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2934 }
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2935
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2936 PRINT_INT_SCALAR_INTERNAL (int8_t)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2937 PRINT_INT_SCALAR_INTERNAL (uint8_t)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2938 PRINT_INT_SCALAR_INTERNAL (int16_t)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2939 PRINT_INT_SCALAR_INTERNAL (uint16_t)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2940 PRINT_INT_SCALAR_INTERNAL (int32_t)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2941 PRINT_INT_SCALAR_INTERNAL (uint32_t)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2942 PRINT_INT_SCALAR_INTERNAL (int64_t)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2943 PRINT_INT_SCALAR_INTERNAL (uint64_t)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2944
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2945 template <class T>
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2946 /* static */ inline void
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2947 octave_print_internal_template (std::ostream& os, const intNDArray<T>& nda,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2948 bool pr_as_read_syntax, int extra_indent)
4901
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2949 {
5775
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5770
diff changeset
2950 // FIXME -- this mostly duplicates the code in the
4901
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2951 // PRINT_ND_ARRAY macro.
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2952
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2953 if (nda.is_empty ())
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2954 print_empty_nd_array (os, nda.dims (), pr_as_read_syntax);
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2955 else if (nda.length () == 1)
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2956 octave_print_internal_template (os, nda(0), pr_as_read_syntax);
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2957 else if (plus_format && ! pr_as_read_syntax)
4901
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2958 {
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2959 int ndims = nda.ndims ();
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2960
10350
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
2961 Array<octave_idx_type> ra_idx (ndims, 1, 0);
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2962
4901
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2963 dim_vector dims = nda.dims ();
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2964
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2965 octave_idx_type m = 1;
4901
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2966
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2967 for (int i = 2; i < ndims; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2968 m *= dims(i);
4901
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2969
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2970 octave_idx_type nr = dims(0);
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2971 octave_idx_type nc = dims(1);
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2972
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2973 for (octave_idx_type i = 0; i < m; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2974 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2975 if (m > 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2976 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2977 std::string nm = "ans(:,:,";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2978
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2979 std::ostringstream buf;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2980
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2981 for (int k = 2; k < ndims; k++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2982 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2983 buf << ra_idx(k) + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2984
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2985 if (k < ndims - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2986 buf << ",";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2987 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2988 buf << ")";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2989 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2990
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2991 nm += buf.str ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2992
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2993 os << nm << " =\n\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2994 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2995
10350
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
2996 Array<idx_vector> idx (ndims, 1);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2997
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2998 idx(0) = idx_vector (':');
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2999 idx(1) = idx_vector (':');
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3000
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3001 for (int k = 2; k < ndims; k++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3002 idx(k) = idx_vector (ra_idx(k));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3003
10352
a3635bc1ea19 remove Array2
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
3004 Array<T> page (nda.index (idx), nr, nc);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3005
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3006 for (octave_idx_type ii = 0; ii < nr; ii++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3007 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3008 for (octave_idx_type jj = 0; jj < nc; jj++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3009 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3010 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3011
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3012 pr_plus_format (os, page(ii,jj));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3013 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3014
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3015 if ((ii < nr - 1) || (i < m -1))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3016 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3017 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3018
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3019 if (i < m - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3020 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3021 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3022 increment_index (ra_idx, dims, 2);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3023 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3024 }
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3025 }
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3026 else
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3027 {
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3028 int ndims = nda.ndims ();
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3029
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3030 dim_vector dims = nda.dims ();
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3031
10350
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
3032 Array<octave_idx_type> ra_idx (ndims, 1, 0);
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
3033
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
3034 octave_idx_type m = 1;
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3035
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3036 for (int i = 2; i < ndims; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3037 m *= dims(i);
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3038
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
3039 octave_idx_type nr = dims(0);
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
3040 octave_idx_type nc = dims(1);
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3041
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3042 int fw = 0;
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3043 if (hex_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3044 fw = 2 * nda(0).byte_size ();
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3045 else if (bit_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3046 fw = nda(0).nbits ();
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3047 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3048 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3049 bool isneg = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3050 int digits = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3051
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3052 for (octave_idx_type i = 0; i < dims.numel (); i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3053 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3054 int new_digits = static_cast<int>
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3055 (floor (log10 (double (abs (nda(i).value ()))) + 1.0));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3056
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3057 if (new_digits > digits)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3058 digits = new_digits;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3059
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3060 if (! isneg)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3061 isneg = (abs (nda(i).value ()) != nda(i).value ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3062 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3063
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3064 fw = digits + isneg;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3065 }
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3066
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3067 int column_width = fw + (rat_format ? 0 : (bank_format ? 5 : 2));
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
3068 octave_idx_type total_width = nc * column_width;
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3069 int max_width = command_editor::terminal_cols () - extra_indent;
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
3070 octave_idx_type inc = nc;
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3071 if (total_width > max_width && Vsplit_long_rows)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3072 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3073 inc = max_width / column_width;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3074 if (inc == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3075 inc++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3076 }
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3077
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
3078 for (octave_idx_type i = 0; i < m; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3079 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3080 if (m > 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3081 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3082 std::string nm = "ans(:,:,";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3083
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3084 std::ostringstream buf;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3085
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3086 for (int k = 2; k < ndims; k++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3087 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3088 buf << ra_idx(k) + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3089
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3090 if (k < ndims - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3091 buf << ",";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3092 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3093 buf << ")";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3094 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3095
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3096 nm += buf.str ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3097
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3098 os << nm << " =\n\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3099 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3100
10350
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
3101 Array<idx_vector> idx (ndims, 1);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3102
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3103 idx(0) = idx_vector (':');
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3104 idx(1) = idx_vector (':');
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3105
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3106 for (int k = 2; k < ndims; k++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3107 idx(k) = idx_vector (ra_idx(k));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3108
10352
a3635bc1ea19 remove Array2
Jaroslav Hajek <highegg@gmail.com>
parents: 10350
diff changeset
3109 Array<T> page (nda.index (idx), nr, nc);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3110
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3111 if (free_format)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3112 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3113 if (pr_as_read_syntax)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3114 os << "[\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3115
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3116 for (octave_idx_type ii = 0; ii < nr; ii++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3117 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3118 for (octave_idx_type jj = 0; jj < nc; jj++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3119 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3120 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3121 os << " ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3122 os << typename octave_print_conv<T>::print_conv_type (page(ii,jj));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3123 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3124 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3125 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3126
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3127 if (pr_as_read_syntax)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3128 os << "]";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3129 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3130 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3131 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3132 octave_idx_type n_rows = page.rows ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3133 octave_idx_type n_cols = page.cols ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3134
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3135 for (octave_idx_type col = 0; col < n_cols; col += inc)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3136 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3137 octave_idx_type lim = col + inc < n_cols ? col + inc : n_cols;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3138
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3139 pr_col_num_header (os, total_width, max_width, lim, col,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3140 extra_indent);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3141
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3142 for (octave_idx_type ii = 0; ii < n_rows; ii++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3143 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3144 os << std::setw (extra_indent) << "";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3145
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3146 for (octave_idx_type jj = col; jj < lim; jj++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3147 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3148 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3149 os << " ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3150 pr_int (os, page(ii,jj), fw);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3151 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3152 if ((ii < n_rows - 1) || (i < m -1))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3153 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3154 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3155 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3156 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3157
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3158 if (i < m - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3159 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3160 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3161 increment_index (ra_idx, dims, 2);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3162 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3163 }
4901
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
3164 }
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
3165 }
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
3166
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3167 #define PRINT_INT_ARRAY_INTERNAL(TYPE) \
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3168 OCTINTERP_API void \
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3169 octave_print_internal (std::ostream& os, const intNDArray<TYPE>& nda, \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3170 bool pr_as_read_syntax, int extra_indent) \
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3171 { \
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3172 octave_print_internal_template (os, nda, pr_as_read_syntax, extra_indent); \
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3173 }
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3174
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3175 PRINT_INT_ARRAY_INTERNAL (octave_int8)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3176 PRINT_INT_ARRAY_INTERNAL (octave_uint8)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3177 PRINT_INT_ARRAY_INTERNAL (octave_int16)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3178 PRINT_INT_ARRAY_INTERNAL (octave_uint16)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3179 PRINT_INT_ARRAY_INTERNAL (octave_int32)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3180 PRINT_INT_ARRAY_INTERNAL (octave_uint32)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3181 PRINT_INT_ARRAY_INTERNAL (octave_int64)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3182 PRINT_INT_ARRAY_INTERNAL (octave_uint64)
4901
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
3183
8012
63dbb85452cc fix extern decls in .cc files
John W. Eaton <jwe@octave.org>
parents: 7896
diff changeset
3184 void
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
3185 octave_print_internal (std::ostream&, const Cell&, bool, int, bool)
3928
e8627dc4bdf2 [project @ 2002-05-03 19:56:01 by jwe]
jwe
parents: 3776
diff changeset
3186 {
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
3187 panic_impossible ();
3928
e8627dc4bdf2 [project @ 2002-05-03 19:56:01 by jwe]
jwe
parents: 3776
diff changeset
3188 }
e8627dc4bdf2 [project @ 2002-05-03 19:56:01 by jwe]
jwe
parents: 3776
diff changeset
3189
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3190 DEFUN (rats, args, nargout,
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3191 "-*- texinfo -*-\n\
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3192 @deftypefn {Built-in Function} {} rats (@var{x}, @var{len})\n\
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3193 Convert @var{x} into a rational approximation represented as a string.\n\
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3194 You can convert the string back into a matrix as follows:\n\
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3195 \n\
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3196 @example\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 9039
diff changeset
3197 @group\n\
7097
e8c94e473c68 [project @ 2007-11-02 17:24:23 by jwe]
jwe
parents: 7017
diff changeset
3198 r = rats(hilb(4));\n\
e8c94e473c68 [project @ 2007-11-02 17:24:23 by jwe]
jwe
parents: 7017
diff changeset
3199 x = str2num(r)\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 9039
diff changeset
3200 @end group\n\
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3201 @end example\n\
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3202 \n\
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3203 The optional second argument defines the maximum length of the string\n\
9039
51dc9691f23f Cleanup documentation files errors.texi, debug.texi, io.texi
Rik <rdrider0-list@yahoo.com>
parents: 8930
diff changeset
3204 representing the elements of @var{x}. By default @var{len} is 9.\n\
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3205 @seealso{format, rat}\n\
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3206 @end deftypefn")
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3207 {
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3208 octave_value retval;
6803
fe19c6cb5bc6 [project @ 2007-07-26 18:04:05 by jwe]
jwe
parents: 6788
diff changeset
3209
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3210 int nargin = args.length ();
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3211
7896
92c26470fe56 Frats fix for nargin==0
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3212 if (nargin < 1 || nargin > 2 || nargout > 1)
92c26470fe56 Frats fix for nargin==0
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3213 print_usage ();
92c26470fe56 Frats fix for nargin==0
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3214 else
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3215 {
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9758
diff changeset
3216 unwind_protect frame;
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9758
diff changeset
3217
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9758
diff changeset
3218 frame.protect_var (rat_string_len);
7896
92c26470fe56 Frats fix for nargin==0
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3219
92c26470fe56 Frats fix for nargin==0
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3220 rat_string_len = 9;
92c26470fe56 Frats fix for nargin==0
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3221
92c26470fe56 Frats fix for nargin==0
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3222 if (nargin == 2)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3223 rat_string_len = args(1).nint_value ();
7896
92c26470fe56 Frats fix for nargin==0
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3224
92c26470fe56 Frats fix for nargin==0
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3225 if (! error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3226 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3227 octave_value arg = args(0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3228
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3229 if (arg.is_numeric_type ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3230 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3231 frame.protect_var (rat_format);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3232
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3233 rat_format = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3234
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3235 std::ostringstream buf;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3236 args(0).print (buf);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3237 std::string s = buf.str ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3238
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3239 std::list<std::string> lst;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3240
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3241 size_t n = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3242 size_t s_len = s.length ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3243
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3244 while (n < s_len)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3245 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3246 size_t m = s.find ('\n', n);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3247
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3248 if (m == std::string::npos)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3249 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3250 lst.push_back (s.substr (n));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3251 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3252 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3253 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3254 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3255 lst.push_back (s.substr (n, m - n));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3256 n = m + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3257 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3258 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3259
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3260 retval = string_vector (lst);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3261 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3262 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3263 error ("rats: expecting numeric input");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3264 }
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3265 }
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3266
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3267 return retval;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3268 }
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3269
3685
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3270 DEFUN (disp, args, nargout,
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3271 "-*- texinfo -*-\n\
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3272 @deftypefn {Built-in Function} {} disp (@var{x})\n\
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3273 Display the value of @var{x}. For example,\n\
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3274 \n\
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3275 @example\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 9039
diff changeset
3276 @group\n\
3685
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3277 disp (\"The value of pi is:\"), disp (pi)\n\
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3278 \n\
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3279 @print{} the value of pi is:\n\
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3280 @print{} 3.1416\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 9039
diff changeset
3281 @end group\n\
3685
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3282 @end example\n\
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3283 \n\
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3284 @noindent\n\
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3285 Note that the output from @code{disp} always ends with a newline.\n\
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3286 \n\
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3287 If an output value is requested, @code{disp} prints nothing and\n\
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3288 returns the formatted output in a string.\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5544
diff changeset
3289 @seealso{fdisp}\n\
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5544
diff changeset
3290 @end deftypefn")
3685
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3291 {
9643
85dd3a2c9355 avoid returning undefined values from disp & fdisp
Jaroslav Hajek <highegg@gmail.com>
parents: 9629
diff changeset
3292 octave_value_list retval;
3685
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3293
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3294 int nargin = args.length ();
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3295
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3296 if (nargin == 1 && nargout < 2)
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3297 {
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3298 if (nargout == 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3299 args(0).print (octave_stdout);
3685
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3300 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3301 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3302 octave_value arg = args(0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3303 std::ostringstream buf;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3304 arg.print (buf);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3305 retval = octave_value (buf.str (), arg.is_dq_string () ? '"' : '\'');
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3306 }
3685
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3307 }
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3308 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5794
diff changeset
3309 print_usage ();
3685
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3310
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3311 return retval;
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3312 }
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3313
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3314 DEFUN (fdisp, args, ,
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3315 "-*- texinfo -*-\n\
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3316 @deftypefn {Built-in Function} {} fdisp (@var{fid}, @var{x})\n\
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3317 Display the value of @var{x} on the stream @var{fid}. For example,\n\
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3318 \n\
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3319 @example\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 9039
diff changeset
3320 @group\n\
4869
b92d59213e63 [project @ 2004-04-21 17:03:02 by jwe]
jwe
parents: 4833
diff changeset
3321 fdisp (stdout, \"The value of pi is:\"), fdisp (stdout, pi)\n\
3685
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3322 \n\
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3323 @print{} the value of pi is:\n\
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3324 @print{} 3.1416\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 9039
diff changeset
3325 @end group\n\
3685
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3326 @end example\n\
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3327 \n\
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3328 @noindent\n\
4869
b92d59213e63 [project @ 2004-04-21 17:03:02 by jwe]
jwe
parents: 4833
diff changeset
3329 Note that the output from @code{fdisp} always ends with a newline.\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5544
diff changeset
3330 @seealso{disp}\n\
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5544
diff changeset
3331 @end deftypefn")
3685
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3332 {
9643
85dd3a2c9355 avoid returning undefined values from disp & fdisp
Jaroslav Hajek <highegg@gmail.com>
parents: 9629
diff changeset
3333 octave_value_list retval;
3685
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3334
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3335 int nargin = args.length ();
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3336
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3337 if (nargin == 2)
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3338 {
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3339 int fid = octave_stream_list::get_file_number (args (0));
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3340
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3341 octave_stream os = octave_stream_list::lookup (fid, "fdisp");
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3342
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3343 if (! error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3344 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3345 std::ostream *osp = os.output_stream ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3346
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3347 if (osp)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3348 args(1).print (*osp);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3349 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3350 error ("fdisp: stream not open for writing");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3351 }
3685
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3352 }
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3353 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5794
diff changeset
3354 print_usage ();
3685
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3355
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3356 return retval;
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3357 }
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3358
9629
e1345a9002e8 pr-output.cc: new test
John W. Eaton <jwe@octave.org>
parents: 9612
diff changeset
3359 /*
e1345a9002e8 pr-output.cc: new test
John W. Eaton <jwe@octave.org>
parents: 9612
diff changeset
3360 %!test
e1345a9002e8 pr-output.cc: new test
John W. Eaton <jwe@octave.org>
parents: 9612
diff changeset
3361 %! format short
e1345a9002e8 pr-output.cc: new test
John W. Eaton <jwe@octave.org>
parents: 9612
diff changeset
3362 %! fd = tmpfile ();
e1345a9002e8 pr-output.cc: new test
John W. Eaton <jwe@octave.org>
parents: 9612
diff changeset
3363 %! for r = [0, Inf -Inf, NaN]
e1345a9002e8 pr-output.cc: new test
John W. Eaton <jwe@octave.org>
parents: 9612
diff changeset
3364 %! for i = [0, Inf -Inf, NaN]
e1345a9002e8 pr-output.cc: new test
John W. Eaton <jwe@octave.org>
parents: 9612
diff changeset
3365 %! fdisp (fd, complex (r, i));
e1345a9002e8 pr-output.cc: new test
John W. Eaton <jwe@octave.org>
parents: 9612
diff changeset
3366 %! endfor
e1345a9002e8 pr-output.cc: new test
John W. Eaton <jwe@octave.org>
parents: 9612
diff changeset
3367 %! endfor
e1345a9002e8 pr-output.cc: new test
John W. Eaton <jwe@octave.org>
parents: 9612
diff changeset
3368 %! fclose (fd);
e1345a9002e8 pr-output.cc: new test
John W. Eaton <jwe@octave.org>
parents: 9612
diff changeset
3369 */
e1345a9002e8 pr-output.cc: new test
John W. Eaton <jwe@octave.org>
parents: 9612
diff changeset
3370
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3371 static void
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3372 init_format_state (void)
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3373 {
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
3374 free_format = false;
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
3375 plus_format = false;
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3376 rat_format = false;
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
3377 bank_format = false;
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
3378 hex_format = 0;
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
3379 bit_format = 0;
4833
399e8681b774 [project @ 2004-03-10 20:49:48 by jwe]
jwe
parents: 4791
diff changeset
3380 compact_format = false;
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
3381 print_e = false;
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
3382 print_big_e = false;
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
3383 print_g = false;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3384 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3385
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3386 static void
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3387 set_output_prec_and_fw (int prec, int fw)
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3388 {
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3389 Voutput_precision = prec;
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3390 Voutput_max_field_width = fw;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3391 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3392
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3393 static void
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3394 set_format_style (int argc, const string_vector& argv)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3395 {
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3396 int idx = 1;
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3397
1899
2f19333b1e72 [project @ 1996-02-09 17:46:58 by jwe]
jwe
parents: 1884
diff changeset
3398 if (--argc > 0)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3399 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
3400 std::string arg = argv[idx++];
2584
5e41d9c42283 [project @ 1996-12-10 09:39:44 by jwe]
jwe
parents: 2522
diff changeset
3401
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3402 if (arg == "short")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3403 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3404 if (--argc > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3405 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3406 arg = argv[idx++];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3407
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3408 if (arg == "e")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3409 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3410 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3411 print_e = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3412 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3413 else if (arg == "E")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3414 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3415 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3416 print_e = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3417 print_big_e = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3418 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3419 else if (arg == "g")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3420 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3421 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3422 print_g = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3423 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3424 else if (arg == "G")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3425 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3426 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3427 print_g = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3428 print_big_e = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3429 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3430 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3431 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3432 error ("format: unrecognized option `short %s'",
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3433 arg.c_str ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3434 return;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3435 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3436 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3437 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3438 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3439
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3440 set_output_prec_and_fw (5, 10);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3441 }
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3442 else if (arg == "long")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3443 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3444 if (--argc > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3445 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3446 arg = argv[idx++];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3447
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3448 if (arg == "e")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3449 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3450 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3451 print_e = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3452 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3453 else if (arg == "E")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3454 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3455 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3456 print_e = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3457 print_big_e = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3458 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3459 else if (arg == "g")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3460 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3461 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3462 print_g = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3463 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3464 else if (arg == "G")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3465 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3466 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3467 print_g = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3468 print_big_e = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3469 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3470 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3471 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3472 error ("format: unrecognized option `long %s'",
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3473 arg.c_str ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3474 return;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3475 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3476 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3477 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3478 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3479
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3480 set_output_prec_and_fw (15, 20);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3481 }
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3482 else if (arg == "hex")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3483 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3484 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3485 hex_format = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3486 }
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3487 else if (arg == "native-hex")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3488 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3489 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3490 hex_format = 2;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3491 }
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3492 else if (arg == "bit")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3493 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3494 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3495 bit_format = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3496 }
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3497 else if (arg == "native-bit")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3498 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3499 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3500 bit_format = 2;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3501 }
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3502 else if (arg == "+" || arg == "plus")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3503 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3504 if (--argc > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3505 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3506 arg = argv[idx++];
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3507
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3508 if (arg.length () == 3)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3509 plus_format_chars = arg;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3510 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3511 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3512 error ("format: invalid option for plus format");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3513 return;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3514 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3515 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3516 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3517 plus_format_chars = "+ ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3518
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3519 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3520 plus_format = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3521 }
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3522 else if (arg == "rat")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3523 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3524 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3525 rat_format = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3526 }
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3527 else if (arg == "bank")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3528 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3529 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3530 bank_format = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3531 }
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3532 else if (arg == "free")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3533 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3534 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3535 free_format = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3536 }
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3537 else if (arg == "none")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3538 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3539 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3540 free_format = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3541 }
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3542 else if (arg == "compact")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3543 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3544 compact_format = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3545 }
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3546 else if (arg == "loose")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3547 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3548 compact_format = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3549 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3550 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3551 error ("format: unrecognized format state `%s'", arg.c_str ());
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3552 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3553 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3554 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3555 init_format_state ();
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3556 set_output_prec_and_fw (5, 10);
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3557 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3558 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3559
8746
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8625
diff changeset
3560 DEFUN (format, args, ,
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3333
diff changeset
3561 "-*- texinfo -*-\n\
9305
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3562 @deffn {Command} format\n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3563 @deffnx {Command} format options\n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3564 Reset or specify the format of the output produced by @code{disp} and\n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3565 Octave's normal echoing mechanism. This command only affects the display\n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3566 of numbers but not how they are stored or computed. To change the internal\n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3567 representation from the default double use one of the conversion functions\n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3568 such as @code{single}, @code{uint8}, @code{int64}, etc.\n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3569 \n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3570 By default, Octave displays 5 significant digits in a human readable form\n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3571 (option @samp{short} paired with @samp{loose} format for matrices).\n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3572 If @code{format} is invoked without any options, this default format\n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3573 is restored.\n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3574 \n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3575 Valid formats for floating point numbers are listed in the following\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3333
diff changeset
3576 table.\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3333
diff changeset
3577 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3333
diff changeset
3578 @table @code\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3333
diff changeset
3579 @item short\n\
9305
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3580 Fixed point format with 5 significant figures in a field that is a maximum\n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3581 of 10 characters wide. (default).\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3333
diff changeset
3582 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3333
diff changeset
3583 If Octave is unable to format a matrix so that columns line up on the\n\
9305
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3584 decimal point and all numbers fit within the maximum field width then\n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3585 it switches to an exponential @samp{e} format.\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3333
diff changeset
3586 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3333
diff changeset
3587 @item long\n\
9305
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3588 Fixed point format with 15 significant figures in a field that is a maximum\n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3589 of 20 characters wide.\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3333
diff changeset
3590 \n\
9305
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3591 As with the @samp{short} format, Octave will switch to an exponential\n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3592 @samp{e} format if it is unable to format a matrix properly using the\n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3593 current format.\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3333
diff changeset
3594 \n\
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9732
diff changeset
3595 @item short e\n\
9305
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3596 @itemx long e\n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3597 Exponential format. The number to be represented is split between a mantissa\n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3598 and an exponent (power of 10). The mantissa has 5 significant digits in the\n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3599 short format and 15 digits in the long format.\n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3600 For example, with the @samp{short e} format, @code{pi} is displayed as\n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3601 @code{3.1416e+00}.\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3333
diff changeset
3602 \n\
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9732
diff changeset
3603 @item short E\n\
9305
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3604 @itemx long E\n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3605 Identical to @samp{short e} or @samp{long e} but displays an uppercase\n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3606 @samp{E} to indicate the exponent.\n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3607 For example, with the @samp{long E} format, @code{pi} is displayed as\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3333
diff changeset
3608 @code{3.14159265358979E+00}.\n\
9305
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3609 \n\
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9732
diff changeset
3610 @item short g\n\
9305
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3611 @itemx long g\n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3612 Optimally choose between fixed point and exponential format based on\n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3613 the magnitude of the number.\n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3614 For example, with the @samp{short g} format,\n\
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
3615 @code{pi .^ [2; 4; 8; 16; 32]} is displayed as\n\
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
3616 \n\
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
3617 @example\n\
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
3618 @group\n\
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
3619 ans =\n\
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
3620 \n\
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
3621 9.8696\n\
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
3622 97.409\n\
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
3623 9488.5\n\
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
3624 9.0032e+07\n\
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
3625 8.1058e+15\n\
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
3626 @end group\n\
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
3627 @end example\n\
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
3628 \n\
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
3629 @item long G\n\
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
3630 @itemx short G\n\
9305
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3631 Identical to @samp{short g} or @samp{long g} but displays an uppercase\n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3632 @samp{E} to indicate the exponent.\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3333
diff changeset
3633 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3333
diff changeset
3634 @item free\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3333
diff changeset
3635 @itemx none\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3333
diff changeset
3636 Print output in free format, without trying to line up columns of\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3333
diff changeset
3637 matrices on the decimal point. This also causes complex numbers to be\n\
9305
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3638 formatted as numeric pairs like this @samp{(0.60419, 0.60709)} instead\n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3639 of like this @samp{0.60419 + 0.60709i}.\n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3640 @end table\n\
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 453
diff changeset
3641 \n\
9305
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3642 The following formats affect all numeric output (floating point and\n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3643 integer types).\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3333
diff changeset
3644 \n\
9305
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3645 @table @code\n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3646 @item +\n\
4632
0e28461651f2 [project @ 2003-11-18 19:07:13 by jwe]
jwe
parents: 4574
diff changeset
3647 @itemx + @var{chars}\n\
0e28461651f2 [project @ 2003-11-18 19:07:13 by jwe]
jwe
parents: 4574
diff changeset
3648 @itemx plus\n\
0e28461651f2 [project @ 2003-11-18 19:07:13 by jwe]
jwe
parents: 4574
diff changeset
3649 @itemx plus @var{chars}\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3333
diff changeset
3650 Print a @samp{+} symbol for nonzero matrix elements and a space for zero\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3333
diff changeset
3651 matrix elements. This format can be very useful for examining the\n\
9305
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3652 structure of a large sparse matrix.\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3333
diff changeset
3653 \n\
4632
0e28461651f2 [project @ 2003-11-18 19:07:13 by jwe]
jwe
parents: 4574
diff changeset
3654 The optional argument @var{chars} specifies a list of 3 characters to use\n\
0e28461651f2 [project @ 2003-11-18 19:07:13 by jwe]
jwe
parents: 4574
diff changeset
3655 for printing values greater than zero, less than zero and equal to zero.\n\
0e28461651f2 [project @ 2003-11-18 19:07:13 by jwe]
jwe
parents: 4574
diff changeset
3656 For example, with the @samp{+ \"+-.\"} format, @code{[1, 0, -1; -1, 0, 1]}\n\
0e28461651f2 [project @ 2003-11-18 19:07:13 by jwe]
jwe
parents: 4574
diff changeset
3657 is displayed as\n\
0e28461651f2 [project @ 2003-11-18 19:07:13 by jwe]
jwe
parents: 4574
diff changeset
3658 \n\
0e28461651f2 [project @ 2003-11-18 19:07:13 by jwe]
jwe
parents: 4574
diff changeset
3659 @example\n\
0e28461651f2 [project @ 2003-11-18 19:07:13 by jwe]
jwe
parents: 4574
diff changeset
3660 @group\n\
0e28461651f2 [project @ 2003-11-18 19:07:13 by jwe]
jwe
parents: 4574
diff changeset
3661 ans =\n\
0e28461651f2 [project @ 2003-11-18 19:07:13 by jwe]
jwe
parents: 4574
diff changeset
3662 \n\
0e28461651f2 [project @ 2003-11-18 19:07:13 by jwe]
jwe
parents: 4574
diff changeset
3663 +.-\n\
0e28461651f2 [project @ 2003-11-18 19:07:13 by jwe]
jwe
parents: 4574
diff changeset
3664 -.+\n\
0e28461651f2 [project @ 2003-11-18 19:07:13 by jwe]
jwe
parents: 4574
diff changeset
3665 @end group\n\
0e28461651f2 [project @ 2003-11-18 19:07:13 by jwe]
jwe
parents: 4574
diff changeset
3666 @end example\n\
0e28461651f2 [project @ 2003-11-18 19:07:13 by jwe]
jwe
parents: 4574
diff changeset
3667 \n\
9305
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3668 @item bank\n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3669 Print in a fixed format with two digits to the right of the decimal\n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3670 point.\n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3671 \n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3672 @item native-hex\n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3673 Print the hexadecimal representation of numbers as they are stored in\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3333
diff changeset
3674 memory. For example, on a workstation which stores 8 byte real values\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3333
diff changeset
3675 in IEEE format with the least significant byte first, the value of\n\
9305
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3676 @code{pi} when printed in @code{native-hex} format is @code{400921fb54442d18}.\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3333
diff changeset
3677 \n\
4833
399e8681b774 [project @ 2004-03-10 20:49:48 by jwe]
jwe
parents: 4791
diff changeset
3678 @item hex\n\
399e8681b774 [project @ 2004-03-10 20:49:48 by jwe]
jwe
parents: 4791
diff changeset
3679 The same as @code{native-hex}, but always print the most significant\n\
399e8681b774 [project @ 2004-03-10 20:49:48 by jwe]
jwe
parents: 4791
diff changeset
3680 byte first.\n\
399e8681b774 [project @ 2004-03-10 20:49:48 by jwe]
jwe
parents: 4791
diff changeset
3681 @item native-bit\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3333
diff changeset
3682 Print the bit representation of numbers as stored in memory.\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3333
diff changeset
3683 For example, the value of @code{pi} is\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3333
diff changeset
3684 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3333
diff changeset
3685 @example\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3333
diff changeset
3686 @group\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3333
diff changeset
3687 01000000000010010010000111111011\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3333
diff changeset
3688 01010100010001000010110100011000\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3333
diff changeset
3689 @end group\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3333
diff changeset
3690 @end example\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3333
diff changeset
3691 \n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3333
diff changeset
3692 (shown here in two 32 bit sections for typesetting purposes) when\n\
9305
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3693 printed in native-bit format on a workstation which stores 8 byte real values\n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3694 in IEEE format with the least significant byte first.\n\
4833
399e8681b774 [project @ 2004-03-10 20:49:48 by jwe]
jwe
parents: 4791
diff changeset
3695 @item bit\n\
399e8681b774 [project @ 2004-03-10 20:49:48 by jwe]
jwe
parents: 4791
diff changeset
3696 The same as @code{native-bit}, but always print the most significant\n\
399e8681b774 [project @ 2004-03-10 20:49:48 by jwe]
jwe
parents: 4791
diff changeset
3697 bits first.\n\
9305
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3698 \n\
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3699 @item rat\n\
9305
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3700 Print a rational approximation, i.e., values are approximated\n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3701 as the ratio of small integers.\n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3702 For example, with the @samp{rat} format,\n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3703 @code{pi} is displayed as @code{355/113}.\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3333
diff changeset
3704 @end table\n\
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3333
diff changeset
3705 \n\
9305
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3706 The following two options affect the display of all matrices.\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3333
diff changeset
3707 \n\
9305
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3708 @table @code\n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3709 @item compact\n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3710 Remove extra blank space around column number labels producing more compact\n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3711 output with more data per page.\n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3712 @item loose\n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3713 Insert blank lines above and below column number labels to produce a more\n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3714 readable output with less data per page. (default).\n\
52b4d82e5b4f Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents: 9064
diff changeset
3715 @end table\n\
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3333
diff changeset
3716 @end deffn")
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 453
diff changeset
3717 {
2086
bfb775fb6fe8 [project @ 1996-04-25 05:55:19 by jwe]
jwe
parents: 1996
diff changeset
3718 octave_value_list retval;
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 453
diff changeset
3719
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3720 int argc = args.length () + 1;
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3721
1968
a2e206524aa0 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents: 1961
diff changeset
3722 string_vector argv = args.make_argv ("format");
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3723
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3724 if (error_state)
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3725 return retval;
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 453
diff changeset
3726
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 453
diff changeset
3727 set_format_style (argc, argv);
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 453
diff changeset
3728
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 453
diff changeset
3729 return retval;
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 453
diff changeset
3730 }
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 453
diff changeset
3731
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3732 DEFUN (fixed_point_format, args, nargout,
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3733 "-*- texinfo -*-\n\
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3734 @deftypefn {Built-in Function} {@var{val} =} fixed_point_format ()\n\
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3735 @deftypefnx {Built-in Function} {@var{old_val} =} fixed_point_format (@var{new_val})\n\
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3736 Query or set the internal variable that controls whether Octave will\n\
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3737 use a scaled format to print matrix values such that the largest\n\
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3738 element may be written with a single leading digit with the scaling\n\
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3739 factor is printed on the first line of output. For example,\n\
3321
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3268
diff changeset
3740 \n\
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3268
diff changeset
3741 @example\n\
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3268
diff changeset
3742 @group\n\
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3268
diff changeset
3743 octave:1> logspace (1, 7, 5)'\n\
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3268
diff changeset
3744 ans =\n\
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3268
diff changeset
3745 \n\
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3268
diff changeset
3746 1.0e+07 *\n\
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3268
diff changeset
3747 \n\
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3268
diff changeset
3748 0.00000\n\
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3268
diff changeset
3749 0.00003\n\
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3268
diff changeset
3750 0.00100\n\
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3268
diff changeset
3751 0.03162\n\
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3268
diff changeset
3752 1.00000\n\
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3268
diff changeset
3753 @end group\n\
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3268
diff changeset
3754 @end example\n\
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3268
diff changeset
3755 \n\
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3268
diff changeset
3756 @noindent\n\
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3268
diff changeset
3757 Notice that first value appears to be zero when it is actually 1. For\n\
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3268
diff changeset
3758 this reason, you should be careful when setting\n\
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3268
diff changeset
3759 @code{fixed_point_format} to a nonzero value.\n\
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3760 @end deftypefn")
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3761 {
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3762 return SET_INTERNAL_VARIABLE (fixed_point_format);
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3763 }
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3764
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3765 DEFUN (print_empty_dimensions, args, nargout,
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3766 "-*- texinfo -*-\n\
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3767 @deftypefn {Built-in Function} {@var{val} =} print_empty_dimensions ()\n\
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3768 @deftypefnx {Built-in Function} {@var{old_val} =} print_empty_dimensions (@var{new_val})\n\
7001
8b0cfeb06365 [project @ 2007-10-10 18:02:59 by jwe]
jwe
parents: 6959
diff changeset
3769 Query or set the internal variable that controls whether the\n\
3321
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3268
diff changeset
3770 dimensions of empty matrices are printed along with the empty matrix\n\
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3268
diff changeset
3771 symbol, @samp{[]}. For example, the expression\n\
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3268
diff changeset
3772 \n\
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3268
diff changeset
3773 @example\n\
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3268
diff changeset
3774 zeros (3, 0)\n\
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3268
diff changeset
3775 @end example\n\
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3268
diff changeset
3776 \n\
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3268
diff changeset
3777 @noindent\n\
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3268
diff changeset
3778 will print\n\
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3268
diff changeset
3779 \n\
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3268
diff changeset
3780 @example\n\
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3268
diff changeset
3781 ans = [](3x0)\n\
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3268
diff changeset
3782 @end example\n\
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3783 @end deftypefn")
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3784 {
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3785 return SET_INTERNAL_VARIABLE (print_empty_dimensions);
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3786 }
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3787
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3788 DEFUN (split_long_rows, args, nargout,
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3789 "-*- texinfo -*-\n\
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3790 @deftypefn {Built-in Function} {@var{val} =} split_long_rows ()\n\
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3791 @deftypefnx {Built-in Function} {@var{old_val} =} split_long_rows (@var{new_val})\n\
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3792 Query or set the internal variable that controls whether rows of a matrix\n\
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3793 may be split when displayed to a terminal window. If the rows are split,\n\
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3794 Octave will display the matrix in a series of smaller pieces, each of\n\
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3795 which can fit within the limits of your terminal width and each set of\n\
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3796 rows is labeled so that you can easily see which columns are currently\n\
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3797 being displayed. For example:\n\
3321
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3268
diff changeset
3798 \n\
6670
14992092ab06 [project @ 2007-05-29 17:51:37 by jwe]
jwe
parents: 6120
diff changeset
3799 @example\n\
3321
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3268
diff changeset
3800 @group\n\
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3268
diff changeset
3801 octave:13> rand (2,10)\n\
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3268
diff changeset
3802 ans =\n\
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3268
diff changeset
3803 \n\
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3268
diff changeset
3804 Columns 1 through 6:\n\
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3268
diff changeset
3805 \n\
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3268
diff changeset
3806 0.75883 0.93290 0.40064 0.43818 0.94958 0.16467\n\
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3268
diff changeset
3807 0.75697 0.51942 0.40031 0.61784 0.92309 0.40201\n\
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3268
diff changeset
3808 \n\
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3268
diff changeset
3809 Columns 7 through 10:\n\
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3268
diff changeset
3810 \n\
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3268
diff changeset
3811 0.90174 0.11854 0.72313 0.73326\n\
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3268
diff changeset
3812 0.44672 0.94303 0.56564 0.82150\n\
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3268
diff changeset
3813 @end group\n\
6670
14992092ab06 [project @ 2007-05-29 17:51:37 by jwe]
jwe
parents: 6120
diff changeset
3814 @end example\n\
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3815 @end deftypefn")
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3816 {
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3817 return SET_INTERNAL_VARIABLE (split_long_rows);
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3818 }
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3819
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3820 DEFUN (output_max_field_width, args, nargout,
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3821 "-*- texinfo -*-\n\
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3822 @deftypefn {Built-in Function} {@var{val} =} output_max_field_width ()\n\
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3823 @deftypefnx {Built-in Function} {@var{old_val} =} output_max_field_width (@var{new_val})\n\
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3824 Query or set the internal variable that specifies the maximum width\n\
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3825 of a numeric output field.\n\
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3826 @seealso{format, output_precision}\n\
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3827 @end deftypefn")
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3828 {
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3829 return SET_INTERNAL_VARIABLE_WITH_LIMITS (output_precision, 0, INT_MAX);
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3830 }
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3831
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3832 DEFUN (output_precision, args, nargout,
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3833 "-*- texinfo -*-\n\
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3834 @deftypefn {Built-in Function} {@var{val} =} output_precision ()\n\
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3835 @deftypefnx {Built-in Function} {@var{old_val} =} output_precision (@var{new_val})\n\
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3836 Query or set the internal variable that specifies the minimum number of\n\
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3837 significant figures to display for numeric output.\n\
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3838 @seealso{format, output_max_field_width}\n\
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3839 @end deftypefn")
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3840 {
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3841 return SET_INTERNAL_VARIABLE_WITH_LIMITS (output_precision, -1, INT_MAX);
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3842 }
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3843
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3844 DEFUN (struct_levels_to_print, args, nargout,
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3845 "-*- texinfo -*-\n\
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3846 @deftypefn {Built-in Function} {@var{val} =} struct_levels_to_print ()\n\
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3847 @deftypefnx {Built-in Function} {@var{old_val} =} struct_levels_to_print (@var{new_val})\n\
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3848 Query or set the internal variable that specifies the number of\n\
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3849 structure levels to display.\n\
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3850 @end deftypefn")
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3851 {
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3852 return SET_INTERNAL_VARIABLE_WITH_LIMITS (struct_levels_to_print,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3853 -1, INT_MAX);
2165
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
3854 }