1
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
1
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
1
|
20 |
|
21 */ |
|
22 |
240
|
23 #ifdef HAVE_CONFIG_H |
1192
|
24 #include <config.h> |
1
|
25 #endif |
|
26 |
1346
|
27 #include <cfloat> |
3124
|
28 #include <cmath> |
2825
|
29 #include <cstdio> |
1346
|
30 #include <cstring> |
1343
|
31 |
3503
|
32 #include <iomanip> |
|
33 #include <iostream> |
1728
|
34 #include <string> |
|
35 |
4655
|
36 #include "Array-util.h" |
453
|
37 #include "CMatrix.h" |
1
|
38 #include "Range.h" |
2926
|
39 #include "cmd-edit.h" |
1352
|
40 #include "dMatrix.h" |
2891
|
41 #include "lo-mappers.h" |
4051
|
42 #include "lo-sstream.h" |
2317
|
43 #include "mach-info.h" |
1651
|
44 #include "oct-cmplx.h" |
4153
|
45 #include "quit.h" |
1755
|
46 #include "str-vec.h" |
1
|
47 |
3933
|
48 #include "Cell.h" |
1352
|
49 #include "defun.h" |
|
50 #include "error.h" |
2165
|
51 #include "gripes.h" |
1755
|
52 #include "oct-obj.h" |
3685
|
53 #include "oct-stream.h" |
1352
|
54 #include "pager.h" |
|
55 #include "pr-output.h" |
1282
|
56 #include "sysdep.h" |
1
|
57 #include "utils.h" |
1352
|
58 #include "variables.h" |
1
|
59 |
3105
|
60 // TRUE means use a scaled fixed point format for `format long' and |
|
61 // `format short'. |
|
62 static bool Vfixed_point_format; |
|
63 |
2165
|
64 // The maximum field width for a number printed by the default output |
|
65 // routines. |
|
66 static int Voutput_max_field_width; |
|
67 |
|
68 // The precision of the numbers printed by the default output |
|
69 // routines. |
|
70 static int Voutput_precision; |
|
71 |
|
72 // TRUE means that the dimensions of empty matrices should be printed |
|
73 // like this: x = [](2x0). |
|
74 static bool Vprint_empty_dimensions; |
|
75 |
|
76 // TRUE means that the rows of big matrices should be split into |
|
77 // smaller slices that fit on the screen. |
|
78 static bool Vsplit_long_rows; |
|
79 |
3018
|
80 // TRUE means don't do any fancy formatting. |
2387
|
81 static bool free_format = false; |
1
|
82 |
3018
|
83 // TRUE means print plus sign for nonzero, blank for zero. |
2387
|
84 static bool plus_format = false; |
1
|
85 |
4632
|
86 // First char for > 0, second for < 0, third for == 0. |
|
87 static std::string plus_format_chars = "+ "; |
|
88 |
3018
|
89 // TRUE means always print like dollars and cents. |
2387
|
90 static bool bank_format = false; |
1282
|
91 |
3018
|
92 // TRUE means print data in hexadecimal format. |
3608
|
93 static int hex_format = 0; |
1282
|
94 |
3018
|
95 // TRUE means print data in binary-bit-pattern format. |
1309
|
96 static int bit_format = 0; |
|
97 |
3018
|
98 // TRUE means don't put newlines around the column number headers. |
2387
|
99 static bool compact_format = false; |
1186
|
100 |
3018
|
101 // TRUE means use an e format. |
2387
|
102 static bool print_e = false; |
1
|
103 |
4509
|
104 // TRUE means use a g format. |
|
105 static bool print_g = false; |
|
106 |
3018
|
107 // TRUE means print E instead of e for exponent field. |
2387
|
108 static bool print_big_e = false; |
1
|
109 |
3608
|
110 class pr_formatted_float; |
|
111 |
4509
|
112 static int |
|
113 current_output_max_field_width (void) |
|
114 { |
|
115 return Voutput_max_field_width; |
|
116 } |
|
117 |
|
118 static int |
|
119 current_output_precision (void) |
|
120 { |
|
121 return Voutput_precision; |
|
122 } |
|
123 |
3608
|
124 class |
|
125 float_format |
|
126 { |
|
127 public: |
|
128 |
4509
|
129 float_format (int w = current_output_max_field_width (), |
|
130 int p = current_output_precision (), int f = 0) |
3608
|
131 : fw (w), prec (p), fmt (f), up (0), sp (0) { } |
|
132 |
|
133 float_format (const float_format& ff) |
|
134 : fw (ff.fw), prec (ff.prec), fmt (ff.fmt), up (ff.up), sp (ff.sp) { } |
|
135 |
|
136 float_format& operator = (const float_format& ff) |
|
137 { |
|
138 if (&ff != this) |
|
139 { |
|
140 fw = ff.fw; |
|
141 prec = ff.prec; |
|
142 fmt = ff.fmt; |
|
143 up = ff.up; |
|
144 sp = ff.sp; |
|
145 } |
|
146 |
|
147 return *this; |
|
148 } |
|
149 |
|
150 ~float_format (void) { } |
|
151 |
|
152 float_format& scientific (void) { fmt = std::ios::scientific; return *this; } |
|
153 float_format& fixed (void) { fmt = std::ios::fixed; return *this; } |
|
154 float_format& general (void) { fmt = 0; return *this; } |
|
155 |
|
156 float_format& uppercase (void) { up = std::ios::uppercase; return *this; } |
|
157 float_format& lowercase (void) { up = 0; return *this; } |
|
158 |
|
159 float_format& precision (int p) { prec = p; return *this; } |
|
160 |
|
161 float_format& width (int w) { fw = w; return *this; } |
|
162 |
|
163 float_format& trailing_zeros (bool tz = true) |
|
164 { sp = tz ? std::ios::showpoint : 0; return *this; } |
|
165 |
|
166 friend std::ostream& operator << (std::ostream& os, |
|
167 const pr_formatted_float& pff); |
|
168 |
|
169 private: |
|
170 |
|
171 // Field width. Zero means as wide as necessary. |
|
172 int fw; |
|
173 |
|
174 // Precision. |
|
175 int prec; |
|
176 |
|
177 // Format. |
|
178 int fmt; |
|
179 |
|
180 // E or e. |
|
181 int up; |
|
182 |
|
183 // Show trailing zeros. |
|
184 int sp; |
|
185 }; |
|
186 |
|
187 class |
|
188 pr_formatted_float |
|
189 { |
|
190 public: |
|
191 |
|
192 const float_format& f; |
|
193 |
|
194 double val; |
|
195 |
|
196 pr_formatted_float (const float_format& f_arg, double val_arg) |
|
197 : f (f_arg), val (val_arg) { } |
|
198 }; |
|
199 |
|
200 std::ostream& |
|
201 operator << (std::ostream& os, const pr_formatted_float& pff) |
|
202 { |
3682
|
203 if (pff.f.fw >= 0) |
3608
|
204 os << std::setw (pff.f.fw); |
|
205 |
3682
|
206 if (pff.f.prec >= 0) |
3608
|
207 os << std::setprecision (pff.f.prec); |
|
208 |
3775
|
209 std::ios::fmtflags oflags = |
|
210 os.flags (static_cast<std::ios::fmtflags> |
|
211 (pff.f.fmt | pff.f.up | pff.f.sp)); |
3608
|
212 |
|
213 os << pff.val; |
|
214 |
|
215 os.flags (oflags); |
|
216 |
|
217 return os; |
|
218 } |
|
219 |
|
220 // Current format for real numbers and the real part of complex |
|
221 // numbers. |
|
222 static float_format *curr_real_fmt = 0; |
|
223 |
|
224 // Current format for the imaginary part of complex numbers. |
|
225 static float_format *curr_imag_fmt = 0; |
1309
|
226 |
1
|
227 static double |
164
|
228 pr_max_internal (const Matrix& m) |
1
|
229 { |
|
230 int nr = m.rows (); |
|
231 int nc = m.columns (); |
|
232 |
3130
|
233 double result = -DBL_MAX; |
1
|
234 |
|
235 for (int j = 0; j < nc; j++) |
|
236 for (int i = 0; i < nr; i++) |
|
237 { |
3608
|
238 double val = m(i,j); |
4025
|
239 if (xisinf (val) || octave_is_NaN_or_NA (val)) |
1
|
240 continue; |
|
241 |
|
242 if (val > result) |
|
243 result = val; |
|
244 } |
3608
|
245 |
1
|
246 return result; |
|
247 } |
|
248 |
|
249 static double |
164
|
250 pr_min_internal (const Matrix& m) |
1
|
251 { |
|
252 int nr = m.rows (); |
|
253 int nc = m.columns (); |
|
254 |
|
255 double result = DBL_MAX; |
|
256 |
|
257 for (int j = 0; j < nc; j++) |
|
258 for (int i = 0; i < nr; i++) |
|
259 { |
3608
|
260 double val = m(i,j); |
4025
|
261 if (xisinf (val) || octave_is_NaN_or_NA (val)) |
1
|
262 continue; |
|
263 |
|
264 if (val < result) |
|
265 result = val; |
|
266 } |
3608
|
267 |
1
|
268 return result; |
|
269 } |
|
270 |
1658
|
271 // XXX FIXME XXX -- it would be nice to share more code among these |
|
272 // functions,.. |
|
273 |
1
|
274 static void |
3611
|
275 set_real_format (bool sign, int digits, bool inf_or_nan, bool int_only, |
1658
|
276 int &fw) |
1
|
277 { |
3608
|
278 static float_format fmt; |
1
|
279 |
2165
|
280 int prec = Voutput_precision; |
1
|
281 |
|
282 int ld, rd; |
|
283 |
|
284 if (bank_format) |
|
285 { |
|
286 fw = digits < 0 ? 4 : digits + 3; |
|
287 if (inf_or_nan && fw < 3) |
|
288 fw = 3; |
|
289 fw += sign; |
|
290 rd = 2; |
|
291 } |
1282
|
292 else if (hex_format) |
|
293 { |
|
294 fw = 2 * sizeof (double); |
|
295 rd = 0; |
|
296 } |
1309
|
297 else if (bit_format) |
|
298 { |
|
299 fw = 8 * sizeof (double); |
|
300 rd = 0; |
|
301 } |
3611
|
302 else if (inf_or_nan || int_only) |
1
|
303 { |
|
304 fw = digits; |
|
305 if (inf_or_nan && fw < 3) |
|
306 fw = 3; |
|
307 fw += sign; |
3682
|
308 rd = fw; |
1
|
309 } |
|
310 else |
|
311 { |
|
312 if (digits > 0) |
|
313 { |
|
314 ld = digits; |
1658
|
315 rd = prec > digits ? prec - digits : prec; |
1
|
316 digits++; |
|
317 } |
|
318 else |
|
319 { |
|
320 ld = 1; |
1658
|
321 rd = prec > digits ? prec - digits : prec; |
1
|
322 digits = -digits + 1; |
|
323 } |
|
324 |
|
325 fw = ld + 1 + rd; |
|
326 if (inf_or_nan && fw < 3) |
|
327 fw = 3; |
|
328 fw += sign; |
|
329 } |
|
330 |
1309
|
331 if (! (bank_format || hex_format || bit_format) |
4509
|
332 && (fw > Voutput_max_field_width || print_e || print_g)) |
1
|
333 { |
4509
|
334 if (print_g) |
|
335 fmt = float_format (); |
|
336 else |
|
337 { |
|
338 int exp_field = 4; |
|
339 if (digits > 100) |
|
340 exp_field++; |
1
|
341 |
4509
|
342 fw = 2 + prec + exp_field; |
|
343 if (inf_or_nan && fw < 3) |
|
344 fw = 3; |
|
345 fw += sign; |
1
|
346 |
4509
|
347 fmt = float_format (fw, prec - 1, std::ios::scientific); |
|
348 } |
3608
|
349 |
1
|
350 if (print_big_e) |
3608
|
351 fmt.uppercase (); |
1
|
352 } |
3611
|
353 else if (inf_or_nan || int_only) |
|
354 fmt = float_format (fw, rd); |
1
|
355 else |
3608
|
356 fmt = float_format (fw, rd, std::ios::fixed); |
1
|
357 |
3608
|
358 curr_real_fmt = &fmt; |
1
|
359 } |
|
360 |
1658
|
361 static void |
|
362 set_format (double d, int& fw) |
|
363 { |
|
364 curr_real_fmt = 0; |
|
365 curr_imag_fmt = 0; |
|
366 |
|
367 if (free_format) |
|
368 return; |
|
369 |
2387
|
370 bool sign = (d < 0.0); |
1658
|
371 |
2387
|
372 bool inf_or_nan = (xisinf (d) || xisnan (d)); |
1658
|
373 |
3611
|
374 bool int_only = (! inf_or_nan && D_NINT (d) == d); |
1658
|
375 |
|
376 double d_abs = d < 0.0 ? -d : d; |
|
377 |
2800
|
378 int digits = (inf_or_nan || d_abs == 0.0) |
|
379 ? 0 : static_cast<int> (floor (log10 (d_abs) + 1.0)); |
1658
|
380 |
3611
|
381 set_real_format (sign, digits, inf_or_nan, int_only, fw); |
1658
|
382 } |
|
383 |
1
|
384 static inline void |
|
385 set_format (double d) |
|
386 { |
|
387 int fw; |
|
388 set_format (d, fw); |
|
389 } |
|
390 |
|
391 static void |
2387
|
392 set_real_matrix_format (bool sign, int x_max, int x_min, |
|
393 bool inf_or_nan, int int_or_inf_or_nan, int& fw) |
1
|
394 { |
3608
|
395 static float_format fmt; |
1
|
396 |
2165
|
397 int prec = Voutput_precision; |
1
|
398 |
|
399 int ld, rd; |
|
400 |
|
401 if (bank_format) |
|
402 { |
|
403 int digits = x_max > x_min ? x_max : x_min; |
|
404 fw = digits <= 0 ? 4 : digits + 3; |
|
405 if (inf_or_nan && fw < 3) |
|
406 fw = 3; |
|
407 fw += sign; |
|
408 rd = 2; |
|
409 } |
1282
|
410 else if (hex_format) |
|
411 { |
|
412 fw = 2 * sizeof (double); |
|
413 rd = 0; |
|
414 } |
1309
|
415 else if (bit_format) |
|
416 { |
|
417 fw = 8 * sizeof (double); |
|
418 rd = 0; |
|
419 } |
4509
|
420 else if (Vfixed_point_format && ! print_g) |
3268
|
421 { |
|
422 rd = prec; |
|
423 fw = rd + 2; |
|
424 if (inf_or_nan && fw < 3) |
|
425 fw = 3; |
|
426 fw += sign; |
|
427 } |
1715
|
428 else if (int_or_inf_or_nan) |
1
|
429 { |
|
430 int digits = x_max > x_min ? x_max : x_min; |
|
431 fw = digits <= 0 ? 1 : digits; |
|
432 if (inf_or_nan && fw < 3) |
|
433 fw = 3; |
|
434 fw += sign; |
3682
|
435 rd = fw; |
1
|
436 } |
|
437 else |
|
438 { |
|
439 int ld_max, rd_max; |
|
440 if (x_max > 0) |
|
441 { |
|
442 ld_max = x_max; |
1658
|
443 rd_max = prec > x_max ? prec - x_max : prec; |
1
|
444 x_max++; |
|
445 } |
|
446 else |
|
447 { |
|
448 ld_max = 1; |
1658
|
449 rd_max = prec > x_max ? prec - x_max : prec; |
1
|
450 x_max = -x_max + 1; |
|
451 } |
|
452 |
|
453 int ld_min, rd_min; |
|
454 if (x_min > 0) |
|
455 { |
|
456 ld_min = x_min; |
1658
|
457 rd_min = prec > x_min ? prec - x_min : prec; |
1
|
458 x_min++; |
|
459 } |
|
460 else |
|
461 { |
|
462 ld_min = 1; |
1658
|
463 rd_min = prec > x_min ? prec - x_min : prec; |
1
|
464 x_min = -x_min + 1; |
|
465 } |
|
466 |
|
467 ld = ld_max > ld_min ? ld_max : ld_min; |
|
468 rd = rd_max > rd_min ? rd_max : rd_min; |
|
469 |
|
470 fw = ld + 1 + rd; |
|
471 if (inf_or_nan && fw < 3) |
|
472 fw = 3; |
|
473 fw += sign; |
|
474 } |
|
475 |
1658
|
476 if (! (bank_format || hex_format || bit_format) |
3105
|
477 && (print_e |
4509
|
478 || print_g |
3105
|
479 || (! Vfixed_point_format && fw > Voutput_max_field_width))) |
1
|
480 { |
4509
|
481 if (print_g) |
|
482 fmt = float_format (); |
|
483 else |
|
484 { |
|
485 int exp_field = 4; |
|
486 if (x_max > 100 || x_min > 100) |
|
487 exp_field++; |
1
|
488 |
4509
|
489 fw = 2 + prec + exp_field; |
|
490 if (inf_or_nan && fw < 3) |
|
491 fw = 3; |
|
492 fw += sign; |
1
|
493 |
4509
|
494 fmt = float_format (fw, prec - 1, std::ios::scientific); |
|
495 } |
3608
|
496 |
1
|
497 if (print_big_e) |
3608
|
498 fmt.uppercase (); |
1
|
499 } |
3611
|
500 else if (int_or_inf_or_nan) |
|
501 fmt = float_format (fw, rd); |
1
|
502 else |
3608
|
503 fmt = float_format (fw, rd, std::ios::fixed); |
1
|
504 |
3608
|
505 curr_real_fmt = &fmt; |
1
|
506 } |
|
507 |
1658
|
508 static void |
3105
|
509 set_format (const Matrix& m, int& fw, double& scale) |
1658
|
510 { |
|
511 curr_real_fmt = 0; |
|
512 curr_imag_fmt = 0; |
|
513 |
|
514 if (free_format) |
|
515 return; |
|
516 |
4431
|
517 bool sign = m.any_element_is_negative (true); |
1658
|
518 |
2387
|
519 bool inf_or_nan = m.any_element_is_inf_or_nan (); |
1658
|
520 |
2387
|
521 bool int_or_inf_or_nan = m.all_elements_are_int_or_inf_or_nan (); |
1658
|
522 |
2387
|
523 Matrix m_abs = m.abs (); |
1658
|
524 double max_abs = pr_max_internal (m_abs); |
|
525 double min_abs = pr_min_internal (m_abs); |
|
526 |
2800
|
527 int x_max = max_abs == 0.0 |
|
528 ? 0 : static_cast<int> (floor (log10 (max_abs) + 1.0)); |
|
529 |
|
530 int x_min = min_abs == 0.0 |
|
531 ? 0 : static_cast<int> (floor (log10 (min_abs) + 1.0)); |
1658
|
532 |
4270
|
533 scale = (x_max == 0 || int_or_inf_or_nan) ? 1.0 : std::pow (10.0, x_max - 1); |
3105
|
534 |
1658
|
535 set_real_matrix_format (sign, x_max, x_min, inf_or_nan, |
1715
|
536 int_or_inf_or_nan, fw); |
1658
|
537 } |
|
538 |
1
|
539 static inline void |
164
|
540 set_format (const Matrix& m) |
1
|
541 { |
|
542 int fw; |
3105
|
543 double scale; |
|
544 set_format (m, fw, scale); |
1
|
545 } |
|
546 |
|
547 static void |
2387
|
548 set_complex_format (bool sign, int x_max, int x_min, int r_x, |
|
549 bool inf_or_nan, int int_only, int& r_fw, int& i_fw) |
1
|
550 { |
3608
|
551 static float_format r_fmt; |
|
552 static float_format i_fmt; |
1
|
553 |
2165
|
554 int prec = Voutput_precision; |
1
|
555 |
|
556 int ld, rd; |
|
557 |
|
558 if (bank_format) |
|
559 { |
|
560 int digits = r_x; |
|
561 i_fw = 0; |
|
562 r_fw = digits <= 0 ? 4 : digits + 3; |
|
563 if (inf_or_nan && r_fw < 3) |
|
564 r_fw = 3; |
|
565 r_fw += sign; |
|
566 rd = 2; |
|
567 } |
1282
|
568 else if (hex_format) |
|
569 { |
|
570 r_fw = 2 * sizeof (double); |
|
571 i_fw = 2 * sizeof (double); |
|
572 rd = 0; |
|
573 } |
1309
|
574 else if (bit_format) |
|
575 { |
|
576 r_fw = 8 * sizeof (double); |
|
577 i_fw = 8 * sizeof (double); |
|
578 rd = 0; |
|
579 } |
1658
|
580 else if (inf_or_nan || int_only) |
1
|
581 { |
|
582 int digits = x_max > x_min ? x_max : x_min; |
|
583 i_fw = r_fw = digits <= 0 ? 1 : digits; |
|
584 if (inf_or_nan && i_fw < 3) |
|
585 i_fw = r_fw = 3; |
|
586 r_fw += sign; |
3682
|
587 rd = r_fw; |
1
|
588 } |
|
589 else |
|
590 { |
|
591 int ld_max, rd_max; |
|
592 if (x_max > 0) |
|
593 { |
|
594 ld_max = x_max; |
1658
|
595 rd_max = prec > x_max ? prec - x_max : prec; |
1
|
596 x_max++; |
|
597 } |
|
598 else |
|
599 { |
|
600 ld_max = 1; |
1658
|
601 rd_max = prec > x_max ? prec - x_max : prec; |
1
|
602 x_max = -x_max + 1; |
|
603 } |
|
604 |
|
605 int ld_min, rd_min; |
|
606 if (x_min > 0) |
|
607 { |
|
608 ld_min = x_min; |
1658
|
609 rd_min = prec > x_min ? prec - x_min : prec; |
1
|
610 x_min++; |
|
611 } |
|
612 else |
|
613 { |
|
614 ld_min = 1; |
1658
|
615 rd_min = prec > x_min ? prec - x_min : prec; |
1
|
616 x_min = -x_min + 1; |
|
617 } |
|
618 |
|
619 ld = ld_max > ld_min ? ld_max : ld_min; |
|
620 rd = rd_max > rd_min ? rd_max : rd_min; |
|
621 |
|
622 i_fw = r_fw = ld + 1 + rd; |
|
623 if (inf_or_nan && i_fw < 3) |
|
624 i_fw = r_fw = 3; |
|
625 r_fw += sign; |
|
626 } |
|
627 |
1309
|
628 if (! (bank_format || hex_format || bit_format) |
4509
|
629 && (r_fw > Voutput_max_field_width || print_e || print_g)) |
1
|
630 { |
4509
|
631 if (print_g) |
|
632 { |
|
633 r_fmt = float_format (); |
|
634 i_fmt = float_format (); |
|
635 } |
|
636 else |
|
637 { |
|
638 int exp_field = 4; |
|
639 if (x_max > 100 || x_min > 100) |
|
640 exp_field++; |
1
|
641 |
4509
|
642 i_fw = r_fw = 1 + prec + exp_field; |
|
643 if (inf_or_nan && i_fw < 3) |
|
644 i_fw = r_fw = 3; |
|
645 r_fw += sign; |
1
|
646 |
4509
|
647 r_fmt = float_format (r_fw, prec - 1, std::ios::scientific); |
|
648 i_fmt = float_format (i_fw, prec - 1, std::ios::scientific); |
|
649 } |
3608
|
650 |
1
|
651 if (print_big_e) |
|
652 { |
3608
|
653 r_fmt.uppercase (); |
|
654 i_fmt.uppercase (); |
1
|
655 } |
|
656 } |
3611
|
657 else if (inf_or_nan || int_only) |
|
658 { |
|
659 r_fmt = float_format (r_fw, rd); |
|
660 i_fmt = float_format (i_fw, rd); |
|
661 } |
1
|
662 else |
|
663 { |
3608
|
664 r_fmt = float_format (r_fw, rd, std::ios::fixed); |
|
665 i_fmt = float_format (i_fw, rd, std::ios::fixed); |
1
|
666 } |
|
667 |
3608
|
668 curr_real_fmt = &r_fmt; |
|
669 curr_imag_fmt = &i_fmt; |
1
|
670 } |
|
671 |
1658
|
672 static void |
|
673 set_format (const Complex& c, int& r_fw, int& i_fw) |
|
674 { |
|
675 curr_real_fmt = 0; |
|
676 curr_imag_fmt = 0; |
|
677 |
|
678 if (free_format) |
|
679 return; |
|
680 |
|
681 double rp = c.real (); |
|
682 double ip = c.imag (); |
|
683 |
2387
|
684 bool sign = (rp < 0.0); |
1658
|
685 |
2387
|
686 bool inf_or_nan = (xisinf (c) || xisnan (c)); |
1658
|
687 |
2387
|
688 bool int_only = (D_NINT (rp) == rp && D_NINT (ip) == ip); |
1658
|
689 |
|
690 double r_abs = rp < 0.0 ? -rp : rp; |
|
691 double i_abs = ip < 0.0 ? -ip : ip; |
|
692 |
2800
|
693 int r_x = r_abs == 0.0 |
|
694 ? 0 : static_cast<int> (floor (log10 (r_abs) + 1.0)); |
|
695 |
|
696 int i_x = i_abs == 0.0 |
|
697 ? 0 : static_cast<int> (floor (log10 (i_abs) + 1.0)); |
1658
|
698 |
|
699 int x_max, x_min; |
|
700 |
|
701 if (r_x > i_x) |
|
702 { |
|
703 x_max = r_x; |
|
704 x_min = i_x; |
|
705 } |
|
706 else |
|
707 { |
|
708 x_max = i_x; |
|
709 x_min = r_x; |
|
710 } |
|
711 |
|
712 set_complex_format (sign, x_max, x_min, r_x, inf_or_nan, int_only, |
|
713 r_fw, i_fw); |
|
714 } |
|
715 |
1
|
716 static inline void |
164
|
717 set_format (const Complex& c) |
1
|
718 { |
|
719 int r_fw, i_fw; |
|
720 set_format (c, r_fw, i_fw); |
|
721 } |
|
722 |
|
723 static void |
2387
|
724 set_complex_matrix_format (bool sign, int x_max, int x_min, |
|
725 int r_x_max, int r_x_min, bool inf_or_nan, |
1715
|
726 int int_or_inf_or_nan, int& r_fw, int& i_fw) |
1
|
727 { |
3608
|
728 static float_format r_fmt; |
|
729 static float_format i_fmt; |
1
|
730 |
2165
|
731 int prec = Voutput_precision; |
1
|
732 |
|
733 int ld, rd; |
|
734 |
|
735 if (bank_format) |
|
736 { |
|
737 int digits = r_x_max > r_x_min ? r_x_max : r_x_min; |
|
738 i_fw = 0; |
|
739 r_fw = digits <= 0 ? 4 : digits + 3; |
|
740 if (inf_or_nan && i_fw < 3) |
|
741 i_fw = r_fw = 3; |
|
742 r_fw += sign; |
|
743 rd = 2; |
|
744 } |
1282
|
745 else if (hex_format) |
|
746 { |
|
747 r_fw = 2 * sizeof (double); |
|
748 i_fw = 2 * sizeof (double); |
|
749 rd = 0; |
|
750 } |
1309
|
751 else if (bit_format) |
|
752 { |
|
753 r_fw = 8 * sizeof (double); |
|
754 i_fw = 8 * sizeof (double); |
|
755 rd = 0; |
|
756 } |
4509
|
757 else if (Vfixed_point_format && ! print_g) |
3268
|
758 { |
|
759 rd = prec; |
|
760 i_fw = r_fw = rd + 2; |
|
761 if (inf_or_nan && i_fw < 3) |
|
762 i_fw = r_fw = 3; |
|
763 r_fw += sign; |
|
764 } |
1715
|
765 else if (int_or_inf_or_nan) |
1
|
766 { |
|
767 int digits = x_max > x_min ? x_max : x_min; |
|
768 i_fw = r_fw = digits <= 0 ? 1 : digits; |
|
769 if (inf_or_nan && i_fw < 3) |
|
770 i_fw = r_fw = 3; |
|
771 r_fw += sign; |
3682
|
772 rd = r_fw; |
1
|
773 } |
|
774 else |
|
775 { |
|
776 int ld_max, rd_max; |
|
777 if (x_max > 0) |
|
778 { |
|
779 ld_max = x_max; |
1658
|
780 rd_max = prec > x_max ? prec - x_max : prec; |
1
|
781 x_max++; |
|
782 } |
|
783 else |
|
784 { |
|
785 ld_max = 1; |
1658
|
786 rd_max = prec > x_max ? prec - x_max : prec; |
1
|
787 x_max = -x_max + 1; |
|
788 } |
|
789 |
|
790 int ld_min, rd_min; |
|
791 if (x_min > 0) |
|
792 { |
|
793 ld_min = x_min; |
1658
|
794 rd_min = prec > x_min ? prec - x_min : prec; |
1
|
795 x_min++; |
|
796 } |
|
797 else |
|
798 { |
|
799 ld_min = 1; |
1658
|
800 rd_min = prec > x_min ? prec - x_min : prec; |
1
|
801 x_min = -x_min + 1; |
|
802 } |
|
803 |
|
804 ld = ld_max > ld_min ? ld_max : ld_min; |
|
805 rd = rd_max > rd_min ? rd_max : rd_min; |
|
806 |
|
807 i_fw = r_fw = ld + 1 + rd; |
|
808 if (inf_or_nan && i_fw < 3) |
|
809 i_fw = r_fw = 3; |
|
810 r_fw += sign; |
|
811 } |
|
812 |
1309
|
813 if (! (bank_format || hex_format || bit_format) |
3105
|
814 && (print_e |
4509
|
815 || print_g |
3105
|
816 || (! Vfixed_point_format && r_fw > Voutput_max_field_width))) |
1
|
817 { |
4509
|
818 if (print_g) |
|
819 { |
|
820 r_fmt = float_format (); |
|
821 i_fmt = float_format (); |
|
822 } |
|
823 else |
|
824 { |
|
825 int exp_field = 4; |
|
826 if (x_max > 100 || x_min > 100) |
|
827 exp_field++; |
1
|
828 |
4509
|
829 i_fw = r_fw = 1 + prec + exp_field; |
|
830 if (inf_or_nan && i_fw < 3) |
|
831 i_fw = r_fw = 3; |
|
832 r_fw += sign; |
1
|
833 |
4509
|
834 r_fmt = float_format (r_fw, prec - 1, std::ios::scientific); |
|
835 i_fmt = float_format (i_fw, prec - 1, std::ios::scientific); |
|
836 } |
3608
|
837 |
1
|
838 if (print_big_e) |
|
839 { |
3608
|
840 r_fmt.uppercase (); |
|
841 i_fmt.uppercase (); |
1
|
842 } |
|
843 } |
3611
|
844 else if (int_or_inf_or_nan) |
|
845 { |
|
846 r_fmt = float_format (r_fw, rd); |
|
847 i_fmt = float_format (i_fw, rd); |
|
848 } |
1
|
849 else |
|
850 { |
3608
|
851 r_fmt = float_format (r_fw, rd, std::ios::fixed); |
|
852 i_fmt = float_format (i_fw, rd, std::ios::fixed); |
1
|
853 } |
|
854 |
3608
|
855 curr_real_fmt = &r_fmt; |
|
856 curr_imag_fmt = &i_fmt; |
1
|
857 } |
|
858 |
1658
|
859 static void |
3105
|
860 set_format (const ComplexMatrix& cm, int& r_fw, int& i_fw, double& scale) |
1658
|
861 { |
|
862 curr_real_fmt = 0; |
|
863 curr_imag_fmt = 0; |
|
864 |
|
865 if (free_format) |
|
866 return; |
|
867 |
|
868 Matrix rp = real (cm); |
|
869 Matrix ip = imag (cm); |
|
870 |
4431
|
871 bool sign = rp.any_element_is_negative (true); |
1658
|
872 |
2387
|
873 bool inf_or_nan = cm.any_element_is_inf_or_nan (); |
1658
|
874 |
2387
|
875 bool int_or_inf_or_nan = (rp.all_elements_are_int_or_inf_or_nan () |
|
876 && ip.all_elements_are_int_or_inf_or_nan ()); |
1658
|
877 |
2387
|
878 Matrix r_m_abs = rp.abs (); |
1658
|
879 double r_max_abs = pr_max_internal (r_m_abs); |
|
880 double r_min_abs = pr_min_internal (r_m_abs); |
|
881 |
2387
|
882 Matrix i_m_abs = ip.abs (); |
1658
|
883 double i_max_abs = pr_max_internal (i_m_abs); |
|
884 double i_min_abs = pr_min_internal (i_m_abs); |
|
885 |
2800
|
886 int r_x_max = r_max_abs == 0.0 |
|
887 ? 0 : static_cast<int> (floor (log10 (r_max_abs) + 1.0)); |
|
888 |
|
889 int r_x_min = r_min_abs == 0.0 |
|
890 ? 0 : static_cast<int> (floor (log10 (r_min_abs) + 1.0)); |
1658
|
891 |
2800
|
892 int i_x_max = i_max_abs == 0.0 |
|
893 ? 0 : static_cast<int> (floor (log10 (i_max_abs) + 1.0)); |
|
894 |
|
895 int i_x_min = i_min_abs == 0.0 |
|
896 ? 0 : static_cast<int> (floor (log10 (i_min_abs) + 1.0)); |
1658
|
897 |
|
898 int x_max = r_x_max > i_x_max ? r_x_max : i_x_max; |
|
899 int x_min = r_x_min > i_x_min ? r_x_min : i_x_min; |
|
900 |
4270
|
901 scale = (x_max == 0 || int_or_inf_or_nan) ? 1.0 : std::pow (10.0, x_max - 1); |
3105
|
902 |
1658
|
903 set_complex_matrix_format (sign, x_max, x_min, r_x_max, r_x_min, |
1715
|
904 inf_or_nan, int_or_inf_or_nan, r_fw, i_fw); |
1658
|
905 } |
|
906 |
1
|
907 static inline void |
164
|
908 set_format (const ComplexMatrix& cm) |
1
|
909 { |
|
910 int r_fw, i_fw; |
3105
|
911 double scale; |
|
912 set_format (cm, r_fw, i_fw, scale); |
1
|
913 } |
|
914 |
|
915 static void |
3608
|
916 set_range_format (bool sign, int x_max, int x_min, int all_ints, int& fw) |
1
|
917 { |
3608
|
918 static float_format fmt; |
1
|
919 |
2165
|
920 int prec = Voutput_precision; |
1
|
921 |
|
922 int ld, rd; |
|
923 |
|
924 if (bank_format) |
|
925 { |
|
926 int digits = x_max > x_min ? x_max : x_min; |
|
927 fw = sign + digits < 0 ? 4 : digits + 3; |
|
928 rd = 2; |
|
929 } |
1282
|
930 else if (hex_format) |
|
931 { |
|
932 fw = 2 * sizeof (double); |
|
933 rd = 0; |
|
934 } |
1309
|
935 else if (bit_format) |
|
936 { |
|
937 fw = 8 * sizeof (double); |
|
938 rd = 0; |
|
939 } |
1658
|
940 else if (all_ints) |
1
|
941 { |
|
942 int digits = x_max > x_min ? x_max : x_min; |
|
943 fw = sign + digits; |
3682
|
944 rd = fw; |
1
|
945 } |
4509
|
946 else if (Vfixed_point_format && ! print_g) |
3105
|
947 { |
|
948 rd = prec; |
|
949 fw = rd + 2 + sign; |
|
950 } |
1
|
951 else |
|
952 { |
|
953 int ld_max, rd_max; |
|
954 if (x_max > 0) |
|
955 { |
|
956 ld_max = x_max; |
1658
|
957 rd_max = prec > x_max ? prec - x_max : prec; |
1
|
958 x_max++; |
|
959 } |
|
960 else |
|
961 { |
|
962 ld_max = 1; |
1658
|
963 rd_max = prec > x_max ? prec - x_max : prec; |
1
|
964 x_max = -x_max + 1; |
|
965 } |
|
966 |
|
967 int ld_min, rd_min; |
|
968 if (x_min > 0) |
|
969 { |
|
970 ld_min = x_min; |
1658
|
971 rd_min = prec > x_min ? prec - x_min : prec; |
1
|
972 x_min++; |
|
973 } |
|
974 else |
|
975 { |
|
976 ld_min = 1; |
1658
|
977 rd_min = prec > x_min ? prec - x_min : prec; |
1
|
978 x_min = -x_min + 1; |
|
979 } |
|
980 |
|
981 ld = ld_max > ld_min ? ld_max : ld_min; |
|
982 rd = rd_max > rd_min ? rd_max : rd_min; |
|
983 |
|
984 fw = sign + ld + 1 + rd; |
|
985 } |
|
986 |
1309
|
987 if (! (bank_format || hex_format || bit_format) |
3105
|
988 && (print_e |
4509
|
989 || print_g |
3105
|
990 || (! Vfixed_point_format && fw > Voutput_max_field_width))) |
1
|
991 { |
4509
|
992 if (print_g) |
|
993 fmt = float_format (); |
|
994 else |
|
995 { |
|
996 int exp_field = 4; |
|
997 if (x_max > 100 || x_min > 100) |
|
998 exp_field++; |
1
|
999 |
4509
|
1000 fw = sign + 2 + prec + exp_field; |
1
|
1001 |
4509
|
1002 fmt = float_format (fw, prec - 1, std::ios::scientific); |
|
1003 } |
3608
|
1004 |
1
|
1005 if (print_big_e) |
3608
|
1006 fmt.uppercase (); |
1
|
1007 } |
3611
|
1008 else if (all_ints) |
|
1009 fmt = float_format (fw, rd); |
1
|
1010 else |
3608
|
1011 fmt = float_format (fw, rd, std::ios::fixed); |
1
|
1012 |
3608
|
1013 curr_real_fmt = &fmt; |
1
|
1014 } |
|
1015 |
1658
|
1016 static void |
3105
|
1017 set_format (const Range& r, int& fw, double& scale) |
1658
|
1018 { |
|
1019 curr_real_fmt = 0; |
|
1020 curr_imag_fmt = 0; |
|
1021 |
|
1022 if (free_format) |
|
1023 return; |
|
1024 |
|
1025 double r_min = r.base (); |
|
1026 double r_max = r.limit (); |
|
1027 |
|
1028 if (r_max < r_min) |
|
1029 { |
|
1030 double tmp = r_max; |
|
1031 r_max = r_min; |
|
1032 r_min = tmp; |
|
1033 } |
|
1034 |
2387
|
1035 bool sign = (r_min < 0.0); |
1658
|
1036 |
2387
|
1037 bool all_ints = r.all_elements_are_ints (); |
1658
|
1038 |
|
1039 double max_abs = r_max < 0.0 ? -r_max : r_max; |
|
1040 double min_abs = r_min < 0.0 ? -r_min : r_min; |
|
1041 |
2800
|
1042 int x_max = max_abs == 0.0 |
|
1043 ? 0 : static_cast<int> (floor (log10 (max_abs) + 1.0)); |
|
1044 |
|
1045 int x_min = min_abs == 0.0 |
|
1046 ? 0 : static_cast<int> (floor (log10 (min_abs) + 1.0)); |
1658
|
1047 |
4270
|
1048 scale = (x_max == 0 || all_ints) ? 1.0 : std::pow (10.0, x_max - 1); |
3105
|
1049 |
1658
|
1050 set_range_format (sign, x_max, x_min, all_ints, fw); |
|
1051 } |
|
1052 |
1
|
1053 static inline void |
164
|
1054 set_format (const Range& r) |
1
|
1055 { |
|
1056 int fw; |
3105
|
1057 double scale; |
|
1058 set_format (r, fw, scale); |
1
|
1059 } |
|
1060 |
1282
|
1061 union equiv |
|
1062 { |
|
1063 double d; |
|
1064 unsigned char i[sizeof (double)]; |
|
1065 }; |
|
1066 |
1309
|
1067 #define PRINT_CHAR_BITS(os, c) \ |
|
1068 do \ |
|
1069 { \ |
|
1070 unsigned char ctmp = c; \ |
|
1071 char stmp[9]; \ |
1488
|
1072 stmp[0] = (ctmp & 0x80) ? '1' : '0'; \ |
|
1073 stmp[1] = (ctmp & 0x40) ? '1' : '0'; \ |
|
1074 stmp[2] = (ctmp & 0x20) ? '1' : '0'; \ |
|
1075 stmp[3] = (ctmp & 0x10) ? '1' : '0'; \ |
|
1076 stmp[4] = (ctmp & 0x08) ? '1' : '0'; \ |
|
1077 stmp[5] = (ctmp & 0x04) ? '1' : '0'; \ |
|
1078 stmp[6] = (ctmp & 0x02) ? '1' : '0'; \ |
|
1079 stmp[7] = (ctmp & 0x01) ? '1' : '0'; \ |
1309
|
1080 stmp[8] = '\0'; \ |
3013
|
1081 os << stmp; \ |
1309
|
1082 } \ |
|
1083 while (0) |
|
1084 |
|
1085 #define PRINT_CHAR_BITS_SWAPPED(os, c) \ |
|
1086 do \ |
|
1087 { \ |
|
1088 unsigned char ctmp = c; \ |
|
1089 char stmp[9]; \ |
1488
|
1090 stmp[0] = (ctmp & 0x01) ? '1' : '0'; \ |
|
1091 stmp[1] = (ctmp & 0x02) ? '1' : '0'; \ |
|
1092 stmp[2] = (ctmp & 0x04) ? '1' : '0'; \ |
|
1093 stmp[3] = (ctmp & 0x08) ? '1' : '0'; \ |
|
1094 stmp[4] = (ctmp & 0x10) ? '1' : '0'; \ |
|
1095 stmp[5] = (ctmp & 0x20) ? '1' : '0'; \ |
|
1096 stmp[6] = (ctmp & 0x40) ? '1' : '0'; \ |
|
1097 stmp[7] = (ctmp & 0x80) ? '1' : '0'; \ |
1309
|
1098 stmp[8] = '\0'; \ |
3013
|
1099 os << stmp; \ |
1309
|
1100 } \ |
|
1101 while (0) |
|
1102 |
2522
|
1103 static void |
3608
|
1104 pr_any_float (const float_format *fmt, std::ostream& os, double d, int fw = 0) |
1
|
1105 { |
529
|
1106 if (fmt) |
1
|
1107 { |
1282
|
1108 if (hex_format) |
|
1109 { |
|
1110 equiv tmp; |
|
1111 tmp.d = d; |
|
1112 |
|
1113 // Unless explicitly asked for, always print in big-endian |
|
1114 // format. |
|
1115 |
|
1116 // XXX FIXME XXX -- is it correct to swap bytes for VAX |
|
1117 // formats and not for Cray? |
|
1118 |
3013
|
1119 // XXX FIXME XXX -- will bad things happen if we are |
|
1120 // interrupted before resetting the format flags and fill |
|
1121 // character? |
|
1122 |
2317
|
1123 oct_mach_info::float_format flt_fmt = |
|
1124 oct_mach_info::native_float_format (); |
|
1125 |
3013
|
1126 char ofill = os.fill ('0'); |
|
1127 |
3608
|
1128 std::ios::fmtflags oflags |
|
1129 = os.flags (std::ios::right | std::ios::hex); |
3013
|
1130 |
1282
|
1131 if (hex_format > 1 |
4574
|
1132 || flt_fmt == oct_mach_info::flt_fmt_ieee_big_endian |
|
1133 || flt_fmt == oct_mach_info::flt_fmt_cray |
|
1134 || flt_fmt == oct_mach_info::flt_fmt_unknown) |
1282
|
1135 { |
1322
|
1136 for (size_t i = 0; i < sizeof (double); i++) |
3548
|
1137 os << std::setw (2) << static_cast<int> (tmp.i[i]); |
1282
|
1138 } |
|
1139 else |
|
1140 { |
1328
|
1141 for (int i = sizeof (double) - 1; i >= 0; i--) |
3548
|
1142 os << std::setw (2) << static_cast<int> (tmp.i[i]); |
1282
|
1143 } |
3013
|
1144 |
|
1145 os.fill (ofill); |
|
1146 os.setf (oflags); |
1282
|
1147 } |
1309
|
1148 else if (bit_format) |
|
1149 { |
|
1150 equiv tmp; |
|
1151 tmp.d = d; |
|
1152 |
|
1153 // Unless explicitly asked for, always print in big-endian |
|
1154 // format. |
|
1155 |
|
1156 // XXX FIXME XXX -- is it correct to swap bytes for VAX |
|
1157 // formats and not for Cray? |
|
1158 |
2317
|
1159 oct_mach_info::float_format flt_fmt = |
|
1160 oct_mach_info::native_float_format (); |
|
1161 |
4574
|
1162 if (flt_fmt == oct_mach_info::flt_fmt_ieee_big_endian |
|
1163 || flt_fmt == oct_mach_info::flt_fmt_cray |
|
1164 || flt_fmt == oct_mach_info::flt_fmt_unknown) |
1309
|
1165 { |
1322
|
1166 for (size_t i = 0; i < sizeof (double); i++) |
1309
|
1167 PRINT_CHAR_BITS (os, tmp.i[i]); |
|
1168 } |
|
1169 else |
|
1170 { |
|
1171 if (bit_format > 1) |
|
1172 { |
1328
|
1173 for (size_t i = 0; i < sizeof (double); i++) |
1309
|
1174 PRINT_CHAR_BITS_SWAPPED (os, tmp.i[i]); |
|
1175 } |
|
1176 else |
|
1177 { |
|
1178 for (int i = sizeof (double) - 1; i >= 0; i--) |
|
1179 PRINT_CHAR_BITS (os, tmp.i[i]); |
|
1180 } |
|
1181 } |
|
1182 } |
1282
|
1183 else if (xisinf (d)) |
1
|
1184 { |
2804
|
1185 const char *s; |
1
|
1186 if (d < 0.0) |
|
1187 s = "-Inf"; |
|
1188 else |
|
1189 s = "Inf"; |
|
1190 |
|
1191 if (fw > 0) |
3548
|
1192 os << std::setw (fw) << s; |
1
|
1193 else |
|
1194 os << s; |
|
1195 } |
4025
|
1196 else if (octave_is_NA (d)) |
|
1197 { |
|
1198 if (fw > 0) |
|
1199 os << std::setw (fw) << "NA"; |
|
1200 else |
|
1201 os << "NA"; |
|
1202 } |
1
|
1203 else if (xisnan (d)) |
|
1204 { |
|
1205 if (fw > 0) |
3548
|
1206 os << std::setw (fw) << "NaN"; |
1
|
1207 else |
|
1208 os << "NaN"; |
|
1209 } |
|
1210 else |
3608
|
1211 os << pr_formatted_float (*fmt, d); |
1
|
1212 } |
529
|
1213 else |
|
1214 os << d; |
1
|
1215 } |
|
1216 |
|
1217 static inline void |
3608
|
1218 pr_float (std::ostream& os, double d, int fw = 0, double scale = 1.0) |
1
|
1219 { |
4509
|
1220 if (Vfixed_point_format && ! print_g && scale != 1.0) |
3608
|
1221 d /= scale; |
|
1222 |
1
|
1223 pr_any_float (curr_real_fmt, os, d, fw); |
|
1224 } |
|
1225 |
|
1226 static inline void |
3523
|
1227 pr_imag_float (std::ostream& os, double d, int fw = 0) |
1
|
1228 { |
|
1229 pr_any_float (curr_imag_fmt, os, d, fw); |
|
1230 } |
|
1231 |
2522
|
1232 static void |
3608
|
1233 pr_complex (std::ostream& os, const Complex& c, int r_fw = 0, |
|
1234 int i_fw = 0, double scale = 1.0) |
1
|
1235 { |
4509
|
1236 Complex tmp |
|
1237 = (Vfixed_point_format && ! print_g && scale != 1.0) ? c / scale : c; |
3608
|
1238 |
|
1239 double r = tmp.real (); |
|
1240 |
1
|
1241 pr_float (os, r, r_fw); |
3608
|
1242 |
1
|
1243 if (! bank_format) |
|
1244 { |
3608
|
1245 double i = tmp.imag (); |
4349
|
1246 if (! (hex_format || bit_format) && lo_ieee_signbit (i)) |
1
|
1247 { |
|
1248 os << " - "; |
|
1249 i = -i; |
|
1250 pr_imag_float (os, i, i_fw); |
|
1251 } |
|
1252 else |
|
1253 { |
1309
|
1254 if (hex_format || bit_format) |
1282
|
1255 os << " "; |
|
1256 else |
|
1257 os << " + "; |
|
1258 |
1
|
1259 pr_imag_float (os, i, i_fw); |
|
1260 } |
|
1261 os << "i"; |
|
1262 } |
|
1263 } |
|
1264 |
626
|
1265 static void |
3523
|
1266 print_empty_matrix (std::ostream& os, int nr, int nc, bool pr_as_read_syntax) |
626
|
1267 { |
|
1268 assert (nr == 0 || nc == 0); |
|
1269 |
|
1270 if (pr_as_read_syntax) |
|
1271 { |
|
1272 if (nr == 0 && nc == 0) |
|
1273 os << "[]"; |
|
1274 else |
|
1275 os << "zeros (" << nr << ", " << nc << ")"; |
|
1276 } |
|
1277 else |
|
1278 { |
|
1279 os << "[]"; |
4559
|
1280 |
2165
|
1281 if (Vprint_empty_dimensions) |
626
|
1282 os << "(" << nr << "x" << nc << ")"; |
|
1283 } |
|
1284 } |
|
1285 |
1186
|
1286 static void |
4559
|
1287 print_empty_nd_array (std::ostream& os, const dim_vector& dims, |
|
1288 bool pr_as_read_syntax) |
|
1289 { |
|
1290 assert (dims.any_zero ()); |
|
1291 |
|
1292 if (pr_as_read_syntax) |
|
1293 os << "zeros (" << dims.str (',') << ")"; |
|
1294 else |
|
1295 { |
|
1296 os << "[]"; |
|
1297 |
|
1298 if (Vprint_empty_dimensions) |
|
1299 os << "(" << dims.str () << ")"; |
|
1300 } |
|
1301 } |
|
1302 |
|
1303 static void |
3523
|
1304 pr_scale_header (std::ostream& os, double scale) |
3105
|
1305 { |
4509
|
1306 if (Vfixed_point_format && ! print_g && scale != 1.0) |
3105
|
1307 { |
3568
|
1308 os << " " |
|
1309 << std::setw (8) << std::setprecision (1) |
|
1310 << std::setiosflags (std::ios::scientific|std::ios::left) |
|
1311 << scale |
|
1312 << std::resetiosflags (std::ios::scientific|std::ios::left) |
|
1313 << " *\n"; |
3105
|
1314 |
|
1315 if (! compact_format) |
|
1316 os << "\n"; |
|
1317 } |
|
1318 } |
|
1319 |
|
1320 static void |
3523
|
1321 pr_col_num_header (std::ostream& os, int total_width, int max_width, |
1972
|
1322 int lim, int col, int extra_indent) |
1186
|
1323 { |
2165
|
1324 if (total_width > max_width && Vsplit_long_rows) |
1186
|
1325 { |
|
1326 if (col != 0 && ! compact_format) |
2915
|
1327 os << "\n\n"; |
1186
|
1328 |
|
1329 int num_cols = lim - col; |
|
1330 |
3548
|
1331 os << std::setw (extra_indent) << ""; |
1972
|
1332 |
1186
|
1333 if (num_cols == 1) |
|
1334 os << " Column " << col + 1 << ":\n"; |
|
1335 else if (num_cols == 2) |
|
1336 os << " Columns " << col + 1 << " and " << lim << ":\n"; |
|
1337 else |
|
1338 os << " Columns " << col + 1 << " through " << lim << ":\n"; |
2915
|
1339 |
|
1340 if (! compact_format) |
|
1341 os << "\n"; |
1186
|
1342 } |
|
1343 } |
|
1344 |
3248
|
1345 static inline void |
3608
|
1346 pr_plus_format (std::ostream& os, double d) |
3248
|
1347 { |
4632
|
1348 if (d > 0.0) |
|
1349 os << plus_format_chars[0]; |
3248
|
1350 else if (d < 0.0) |
4632
|
1351 os << plus_format_chars[1]; |
3248
|
1352 else |
4632
|
1353 os << plus_format_chars[2]; |
3248
|
1354 } |
|
1355 |
1
|
1356 void |
4661
|
1357 octave_print_internal (std::ostream& os, double d, |
|
1358 bool /* pr_as_read_syntax */) |
1
|
1359 { |
|
1360 if (plus_format) |
|
1361 { |
3608
|
1362 pr_plus_format (os, d); |
1
|
1363 } |
|
1364 else |
|
1365 { |
|
1366 set_format (d); |
|
1367 if (free_format) |
|
1368 os << d; |
|
1369 else |
|
1370 pr_float (os, d); |
|
1371 } |
|
1372 } |
|
1373 |
|
1374 void |
3608
|
1375 octave_print_internal (std::ostream& os, const Matrix& m, |
|
1376 bool pr_as_read_syntax, int extra_indent) |
1
|
1377 { |
|
1378 int nr = m.rows (); |
|
1379 int nc = m.columns (); |
|
1380 |
2408
|
1381 if (nr == 0 || nc == 0) |
626
|
1382 print_empty_matrix (os, nr, nc, pr_as_read_syntax); |
|
1383 else if (plus_format && ! pr_as_read_syntax) |
1
|
1384 { |
|
1385 for (int i = 0; i < nr; i++) |
|
1386 { |
|
1387 for (int j = 0; j < nc; j++) |
|
1388 { |
4153
|
1389 OCTAVE_QUIT; |
|
1390 |
3608
|
1391 pr_plus_format (os, m(i,j)); |
1
|
1392 } |
2907
|
1393 |
|
1394 if (i < nr - 1) |
|
1395 os << "\n"; |
1
|
1396 } |
|
1397 } |
|
1398 else |
|
1399 { |
|
1400 int fw; |
3105
|
1401 double scale = 1.0; |
|
1402 set_format (m, fw, scale); |
1
|
1403 int column_width = fw + 2; |
|
1404 int total_width = nc * column_width; |
2926
|
1405 int max_width = command_editor::terminal_cols (); |
1
|
1406 |
626
|
1407 if (pr_as_read_syntax) |
|
1408 max_width -= 4; |
1972
|
1409 else |
|
1410 max_width -= extra_indent; |
|
1411 |
|
1412 if (max_width < 0) |
|
1413 max_width = 0; |
626
|
1414 |
1
|
1415 if (free_format) |
|
1416 { |
626
|
1417 if (pr_as_read_syntax) |
|
1418 os << "[\n"; |
|
1419 |
1
|
1420 os << m; |
626
|
1421 |
|
1422 if (pr_as_read_syntax) |
|
1423 os << "]"; |
|
1424 |
1
|
1425 return; |
|
1426 } |
|
1427 |
|
1428 int inc = nc; |
2165
|
1429 if (total_width > max_width && Vsplit_long_rows) |
1
|
1430 { |
|
1431 inc = max_width / column_width; |
|
1432 if (inc == 0) |
|
1433 inc++; |
|
1434 } |
|
1435 |
626
|
1436 if (pr_as_read_syntax) |
1
|
1437 { |
|
1438 for (int i = 0; i < nr; i++) |
|
1439 { |
626
|
1440 int col = 0; |
|
1441 while (col < nc) |
1
|
1442 { |
626
|
1443 int lim = col + inc < nc ? col + inc : nc; |
|
1444 |
|
1445 for (int j = col; j < lim; j++) |
|
1446 { |
4153
|
1447 OCTAVE_QUIT; |
|
1448 |
626
|
1449 if (i == 0 && j == 0) |
|
1450 os << "[ "; |
|
1451 else |
|
1452 { |
|
1453 if (j > col && j < lim) |
|
1454 os << ", "; |
|
1455 else |
|
1456 os << " "; |
|
1457 } |
|
1458 |
3608
|
1459 pr_float (os, m(i,j)); |
626
|
1460 } |
|
1461 |
|
1462 col += inc; |
|
1463 |
|
1464 if (col >= nc) |
|
1465 { |
|
1466 if (i == nr - 1) |
|
1467 os << " ]"; |
|
1468 else |
|
1469 os << ";\n"; |
|
1470 } |
|
1471 else |
|
1472 os << " ...\n"; |
1
|
1473 } |
|
1474 } |
626
|
1475 } |
|
1476 else |
|
1477 { |
3105
|
1478 pr_scale_header (os, scale); |
|
1479 |
626
|
1480 for (int col = 0; col < nc; col += inc) |
|
1481 { |
|
1482 int lim = col + inc < nc ? col + inc : nc; |
|
1483 |
1972
|
1484 pr_col_num_header (os, total_width, max_width, lim, col, |
|
1485 extra_indent); |
626
|
1486 |
|
1487 for (int i = 0; i < nr; i++) |
|
1488 { |
3548
|
1489 os << std::setw (extra_indent) << ""; |
1972
|
1490 |
626
|
1491 for (int j = col; j < lim; j++) |
|
1492 { |
4153
|
1493 OCTAVE_QUIT; |
|
1494 |
626
|
1495 os << " "; |
|
1496 |
3608
|
1497 pr_float (os, m(i,j), fw, scale); |
626
|
1498 } |
|
1499 |
2907
|
1500 if (i < nr - 1) |
|
1501 os << "\n"; |
626
|
1502 } |
|
1503 } |
1
|
1504 } |
|
1505 } |
|
1506 } |
|
1507 |
4532
|
1508 #define PRINT_ND_ARRAY(os, nda, NDA_T, ELT_T, MAT_T) \ |
|
1509 do \ |
|
1510 { \ |
4559
|
1511 if (nda.is_empty ()) \ |
|
1512 print_empty_nd_array (os, nda.dims (), pr_as_read_syntax); \ |
|
1513 else \ |
|
1514 { \ |
4532
|
1515 \ |
4559
|
1516 int ndims = nda.ndims (); \ |
|
1517 \ |
|
1518 dim_vector dims = nda.dims (); \ |
4532
|
1519 \ |
4559
|
1520 Array<int> ra_idx (ndims, 0); \ |
4532
|
1521 \ |
4559
|
1522 int m = 1; \ |
4532
|
1523 \ |
4559
|
1524 for (int i = 2; i < ndims; i++) \ |
|
1525 m *= dims(i); \ |
|
1526 \ |
|
1527 int nr = dims(0); \ |
|
1528 int nc = dims(1); \ |
4532
|
1529 \ |
4559
|
1530 for (int i = 0; i < m; i++) \ |
|
1531 { \ |
4655
|
1532 OCTAVE_QUIT; \ |
|
1533 \ |
4559
|
1534 std::string nm = "ans"; \ |
4532
|
1535 \ |
4559
|
1536 if (m > 1) \ |
|
1537 { \ |
|
1538 nm += "(:,:,"; \ |
4532
|
1539 \ |
4559
|
1540 OSSTREAM buf; \ |
4532
|
1541 \ |
4559
|
1542 for (int k = 2; k < ndims; k++) \ |
|
1543 { \ |
|
1544 buf << ra_idx(k) + 1; \ |
4532
|
1545 \ |
4559
|
1546 if (k < ndims - 1) \ |
|
1547 buf << ","; \ |
|
1548 else \ |
|
1549 buf << ")"; \ |
|
1550 } \ |
4532
|
1551 \ |
4559
|
1552 buf << OSSTREAM_ENDS; \ |
4532
|
1553 \ |
4559
|
1554 nm += OSSTREAM_STR (buf); \ |
|
1555 \ |
|
1556 OSSTREAM_FREEZE (buf); \ |
|
1557 } \ |
4532
|
1558 \ |
4559
|
1559 Array<idx_vector> idx (ndims); \ |
4532
|
1560 \ |
4559
|
1561 idx(0) = idx_vector (':'); \ |
|
1562 idx(1) = idx_vector (':'); \ |
|
1563 \ |
|
1564 for (int k = 2; k < ndims; k++) \ |
|
1565 idx(k) = idx_vector (ra_idx(k) + 1); \ |
4532
|
1566 \ |
4559
|
1567 octave_value page \ |
|
1568 = MAT_T (Array2<ELT_T> (nda.index (idx), nr, nc)); \ |
|
1569 \ |
|
1570 page.print_with_name (os, nm); \ |
4532
|
1571 \ |
4559
|
1572 if (i < m) \ |
|
1573 NDA_T::increment_index (ra_idx, dims, 2); \ |
|
1574 } \ |
|
1575 } \ |
4532
|
1576 } \ |
|
1577 while (0) |
|
1578 |
4513
|
1579 void |
|
1580 octave_print_internal (std::ostream& os, const NDArray& nda, |
|
1581 bool pr_as_read_syntax, int extra_indent) |
|
1582 { |
|
1583 switch (nda.ndims ()) |
|
1584 { |
|
1585 case 1: |
|
1586 case 2: |
|
1587 octave_print_internal (os, nda.matrix_value (), |
|
1588 pr_as_read_syntax, extra_indent); |
|
1589 break; |
|
1590 |
|
1591 default: |
4532
|
1592 PRINT_ND_ARRAY (os, nda, NDArray, double, Matrix); |
4513
|
1593 break; |
|
1594 } |
|
1595 } |
|
1596 |
3248
|
1597 static inline void |
3608
|
1598 pr_plus_format (std::ostream& os, const Complex& c) |
3248
|
1599 { |
|
1600 double rp = c.real (); |
|
1601 double ip = c.imag (); |
|
1602 |
|
1603 if (rp == 0.0) |
|
1604 { |
|
1605 if (ip == 0.0) |
|
1606 os << " "; |
|
1607 else |
|
1608 os << "i"; |
|
1609 } |
|
1610 else if (ip == 0.0) |
3608
|
1611 pr_plus_format (os, rp); |
3248
|
1612 else |
|
1613 os << "c"; |
|
1614 } |
|
1615 |
1
|
1616 void |
3523
|
1617 octave_print_internal (std::ostream& os, const Complex& c, |
4661
|
1618 bool /* pr_as_read_syntax */) |
1
|
1619 { |
|
1620 if (plus_format) |
|
1621 { |
3608
|
1622 pr_plus_format (os, c); |
1
|
1623 } |
|
1624 else |
|
1625 { |
|
1626 set_format (c); |
|
1627 if (free_format) |
|
1628 os << c; |
|
1629 else |
|
1630 pr_complex (os, c); |
|
1631 } |
|
1632 } |
|
1633 |
|
1634 void |
3523
|
1635 octave_print_internal (std::ostream& os, const ComplexMatrix& cm, |
1972
|
1636 bool pr_as_read_syntax, int extra_indent) |
1
|
1637 { |
|
1638 int nr = cm.rows (); |
|
1639 int nc = cm.columns (); |
|
1640 |
2408
|
1641 if (nr == 0 || nc == 0) |
626
|
1642 print_empty_matrix (os, nr, nc, pr_as_read_syntax); |
|
1643 else if (plus_format && ! pr_as_read_syntax) |
1
|
1644 { |
|
1645 for (int i = 0; i < nr; i++) |
|
1646 { |
|
1647 for (int j = 0; j < nc; j++) |
|
1648 { |
4153
|
1649 OCTAVE_QUIT; |
|
1650 |
3608
|
1651 pr_plus_format (os, cm(i,j)); |
1
|
1652 } |
2907
|
1653 |
|
1654 if (i < nr - 1) |
|
1655 os << "\n"; |
1
|
1656 } |
|
1657 } |
|
1658 else |
|
1659 { |
|
1660 int r_fw, i_fw; |
3105
|
1661 double scale = 1.0; |
|
1662 set_format (cm, r_fw, i_fw, scale); |
1
|
1663 int column_width = i_fw + r_fw; |
1309
|
1664 column_width += (bank_format || hex_format|| bit_format) ? 2 : 7; |
1
|
1665 int total_width = nc * column_width; |
2926
|
1666 int max_width = command_editor::terminal_cols (); |
1
|
1667 |
626
|
1668 if (pr_as_read_syntax) |
|
1669 max_width -= 4; |
1972
|
1670 else |
|
1671 max_width -= extra_indent; |
|
1672 |
|
1673 if (max_width < 0) |
|
1674 max_width = 0; |
626
|
1675 |
1
|
1676 if (free_format) |
|
1677 { |
626
|
1678 if (pr_as_read_syntax) |
|
1679 os << "[\n"; |
|
1680 |
1
|
1681 os << cm; |
626
|
1682 |
|
1683 if (pr_as_read_syntax) |
|
1684 os << "]"; |
|
1685 |
1
|
1686 return; |
|
1687 } |
|
1688 |
|
1689 int inc = nc; |
2165
|
1690 if (total_width > max_width && Vsplit_long_rows) |
1
|
1691 { |
|
1692 inc = max_width / column_width; |
|
1693 if (inc == 0) |
|
1694 inc++; |
|
1695 } |
|
1696 |
626
|
1697 if (pr_as_read_syntax) |
1
|
1698 { |
|
1699 for (int i = 0; i < nr; i++) |
|
1700 { |
626
|
1701 int col = 0; |
|
1702 while (col < nc) |
1
|
1703 { |
626
|
1704 int lim = col + inc < nc ? col + inc : nc; |
|
1705 |
|
1706 for (int j = col; j < lim; j++) |
|
1707 { |
4153
|
1708 OCTAVE_QUIT; |
|
1709 |
626
|
1710 if (i == 0 && j == 0) |
|
1711 os << "[ "; |
|
1712 else |
|
1713 { |
|
1714 if (j > col && j < lim) |
|
1715 os << ", "; |
|
1716 else |
|
1717 os << " "; |
|
1718 } |
|
1719 |
3608
|
1720 pr_complex (os, cm(i,j)); |
626
|
1721 } |
|
1722 |
|
1723 col += inc; |
|
1724 |
|
1725 if (col >= nc) |
|
1726 { |
|
1727 if (i == nr - 1) |
|
1728 os << " ]"; |
|
1729 else |
|
1730 os << ";\n"; |
|
1731 } |
1
|
1732 else |
626
|
1733 os << " ...\n"; |
1
|
1734 } |
|
1735 } |
626
|
1736 } |
|
1737 else |
|
1738 { |
3105
|
1739 pr_scale_header (os, scale); |
|
1740 |
626
|
1741 for (int col = 0; col < nc; col += inc) |
|
1742 { |
|
1743 int lim = col + inc < nc ? col + inc : nc; |
|
1744 |
1972
|
1745 pr_col_num_header (os, total_width, max_width, lim, col, |
|
1746 extra_indent); |
626
|
1747 |
|
1748 for (int i = 0; i < nr; i++) |
|
1749 { |
3548
|
1750 os << std::setw (extra_indent) << ""; |
1972
|
1751 |
626
|
1752 for (int j = col; j < lim; j++) |
|
1753 { |
4153
|
1754 OCTAVE_QUIT; |
|
1755 |
626
|
1756 os << " "; |
|
1757 |
3608
|
1758 pr_complex (os, cm(i,j), r_fw, i_fw, scale); |
626
|
1759 } |
2907
|
1760 |
|
1761 if (i < nr - 1) |
|
1762 os << "\n"; |
626
|
1763 } |
|
1764 } |
1
|
1765 } |
|
1766 } |
|
1767 } |
|
1768 |
|
1769 void |
4513
|
1770 octave_print_internal (std::ostream& os, const ComplexNDArray& nda, |
|
1771 bool pr_as_read_syntax, int extra_indent) |
|
1772 { |
|
1773 switch (nda.ndims ()) |
|
1774 { |
|
1775 case 1: |
|
1776 case 2: |
|
1777 octave_print_internal (os, nda.matrix_value (), |
|
1778 pr_as_read_syntax, extra_indent); |
|
1779 break; |
|
1780 |
|
1781 default: |
4532
|
1782 PRINT_ND_ARRAY (os, nda, ComplexNDArray, Complex, ComplexMatrix); |
4513
|
1783 break; |
|
1784 } |
|
1785 } |
|
1786 |
|
1787 void |
3523
|
1788 octave_print_internal (std::ostream& os, const Range& r, |
1972
|
1789 bool pr_as_read_syntax, int extra_indent) |
1
|
1790 { |
626
|
1791 double base = r.base (); |
1
|
1792 double increment = r.inc (); |
626
|
1793 double limit = r.limit (); |
1
|
1794 int num_elem = r.nelem (); |
|
1795 |
626
|
1796 if (plus_format && ! pr_as_read_syntax) |
1
|
1797 { |
|
1798 for (int i = 0; i < num_elem; i++) |
|
1799 { |
4153
|
1800 OCTAVE_QUIT; |
|
1801 |
626
|
1802 double val = base + i * increment; |
4632
|
1803 |
|
1804 pr_plus_format (os, val); |
1
|
1805 } |
|
1806 } |
|
1807 else |
|
1808 { |
|
1809 int fw; |
3105
|
1810 double scale = 1.0; |
|
1811 set_format (r, fw, scale); |
1
|
1812 |
626
|
1813 if (pr_as_read_syntax) |
1
|
1814 { |
626
|
1815 if (free_format) |
|
1816 { |
|
1817 os << base << " : "; |
|
1818 if (increment != 1.0) |
|
1819 os << increment << " : "; |
|
1820 os << limit; |
|
1821 } |
|
1822 else |
|
1823 { |
|
1824 pr_float (os, base, fw); |
|
1825 os << " : "; |
|
1826 if (increment != 1.0) |
|
1827 { |
|
1828 pr_float (os, increment, fw); |
|
1829 os << " : "; |
|
1830 } |
|
1831 pr_float (os, limit, fw); |
|
1832 } |
1
|
1833 } |
626
|
1834 else |
|
1835 { |
|
1836 int column_width = fw + 2; |
|
1837 int total_width = num_elem * column_width; |
2926
|
1838 int max_width = command_editor::terminal_cols (); |
1
|
1839 |
626
|
1840 if (free_format) |
|
1841 { |
|
1842 os << r; |
|
1843 return; |
|
1844 } |
1
|
1845 |
626
|
1846 int inc = num_elem; |
2165
|
1847 if (total_width > max_width && Vsplit_long_rows) |
1
|
1848 { |
626
|
1849 inc = max_width / column_width; |
|
1850 if (inc == 0) |
|
1851 inc++; |
1
|
1852 } |
|
1853 |
1972
|
1854 max_width -= extra_indent; |
|
1855 |
|
1856 if (max_width < 0) |
|
1857 max_width = 0; |
|
1858 |
3105
|
1859 pr_scale_header (os, scale); |
|
1860 |
626
|
1861 int col = 0; |
|
1862 while (col < num_elem) |
1
|
1863 { |
626
|
1864 int lim = col + inc < num_elem ? col + inc : num_elem; |
|
1865 |
1972
|
1866 pr_col_num_header (os, total_width, max_width, lim, col, |
|
1867 extra_indent); |
|
1868 |
3548
|
1869 os << std::setw (extra_indent) << ""; |
626
|
1870 |
|
1871 for (int i = col; i < lim; i++) |
|
1872 { |
4153
|
1873 OCTAVE_QUIT; |
|
1874 |
626
|
1875 double val = base + i * increment; |
3105
|
1876 |
4791
|
1877 if (i == num_elem - 1) |
|
1878 { |
|
1879 // See the comments in Range::matrix_value. |
|
1880 |
|
1881 if ((increment > 0 && val > limit) |
|
1882 || (increment < 0 && val < limit)) |
|
1883 val = limit; |
|
1884 } |
|
1885 |
626
|
1886 os << " "; |
3105
|
1887 |
3608
|
1888 pr_float (os, val, fw, scale); |
626
|
1889 } |
|
1890 |
2907
|
1891 col += inc; |
626
|
1892 |
2907
|
1893 if (col < num_elem) |
|
1894 os << "\n"; |
1
|
1895 } |
|
1896 } |
|
1897 } |
|
1898 } |
|
1899 |
1343
|
1900 void |
3523
|
1901 octave_print_internal (std::ostream& os, const boolMatrix& bm, |
3215
|
1902 bool pr_as_read_syntax, |
|
1903 int extra_indent) |
|
1904 { |
|
1905 Matrix tmp (bm); |
|
1906 octave_print_internal (os, tmp, pr_as_read_syntax, extra_indent); |
|
1907 } |
|
1908 |
|
1909 void |
4513
|
1910 octave_print_internal (std::ostream& os, const boolNDArray& nda, |
|
1911 bool pr_as_read_syntax, |
|
1912 int extra_indent) |
|
1913 { |
|
1914 switch (nda.ndims ()) |
|
1915 { |
|
1916 case 1: |
|
1917 case 2: |
|
1918 octave_print_internal (os, nda.matrix_value (), |
|
1919 pr_as_read_syntax, extra_indent); |
|
1920 break; |
|
1921 |
|
1922 default: |
4532
|
1923 PRINT_ND_ARRAY (os, nda, boolNDArray, bool, boolMatrix); |
4513
|
1924 break; |
|
1925 } |
|
1926 } |
|
1927 |
|
1928 void |
3523
|
1929 octave_print_internal (std::ostream& os, const charMatrix& chm, |
3215
|
1930 bool pr_as_read_syntax, |
|
1931 int /* extra_indent XXX FIXME XXX */, |
|
1932 bool pr_as_string) |
1343
|
1933 { |
1572
|
1934 if (pr_as_string) |
|
1935 { |
|
1936 int nstr = chm.rows (); |
1343
|
1937 |
1572
|
1938 if (pr_as_read_syntax && nstr > 1) |
|
1939 os << "[ "; |
1343
|
1940 |
2907
|
1941 if (nstr != 0) |
1343
|
1942 { |
2664
|
1943 for (int i = 0; i < nstr; i++) |
1572
|
1944 { |
4153
|
1945 OCTAVE_QUIT; |
|
1946 |
3523
|
1947 std::string row = chm.row_as_string (i); |
2664
|
1948 |
|
1949 if (pr_as_read_syntax) |
|
1950 { |
|
1951 os << "\"" << undo_string_escapes (row) << "\""; |
1343
|
1952 |
2664
|
1953 if (i < nstr - 1) |
|
1954 os << "; "; |
|
1955 } |
|
1956 else |
2907
|
1957 { |
|
1958 os << row; |
|
1959 |
|
1960 if (i < nstr - 1) |
|
1961 os << "\n"; |
|
1962 } |
1572
|
1963 } |
1343
|
1964 } |
1572
|
1965 |
|
1966 if (pr_as_read_syntax && nstr > 1) |
|
1967 os << " ]"; |
1343
|
1968 } |
1572
|
1969 else |
|
1970 { |
|
1971 os << "sorry, printing char matrices not implemented yet\n"; |
|
1972 } |
1343
|
1973 } |
|
1974 |
4513
|
1975 void |
|
1976 octave_print_internal (std::ostream& os, const charNDArray& nda, |
4663
|
1977 bool pr_as_read_syntax, int extra_indent, |
4513
|
1978 bool pr_as_string) |
|
1979 { |
|
1980 switch (nda.ndims ()) |
|
1981 { |
|
1982 case 1: |
|
1983 case 2: |
|
1984 octave_print_internal (os, nda.matrix_value (), |
|
1985 pr_as_read_syntax, extra_indent, pr_as_string); |
|
1986 break; |
|
1987 |
|
1988 default: |
4532
|
1989 PRINT_ND_ARRAY (os, nda, charNDArray, char, charMatrix); |
4513
|
1990 break; |
|
1991 } |
|
1992 } |
|
1993 |
4655
|
1994 void |
|
1995 octave_print_internal (std::ostream& os, const ArrayN<std::string>& nda, |
4663
|
1996 bool pr_as_read_syntax, int /* extra_indent */) |
4655
|
1997 { |
|
1998 // XXX FIXME XXX -- this mostly duplicates the code in the |
|
1999 // PRINT_ND_ARRAY macro. |
|
2000 |
|
2001 if (nda.is_empty ()) |
|
2002 print_empty_nd_array (os, nda.dims (), pr_as_read_syntax); |
|
2003 else if (nda.length () == 1) |
|
2004 { |
|
2005 os << nda(0); |
|
2006 } |
|
2007 else |
|
2008 { |
|
2009 int ndims = nda.ndims (); |
|
2010 |
|
2011 dim_vector dims = nda.dims (); |
|
2012 |
|
2013 Array<int> ra_idx (ndims, 0); |
|
2014 |
|
2015 int m = 1; |
|
2016 |
|
2017 for (int i = 2; i < ndims; i++) |
|
2018 m *= dims(i); |
|
2019 |
|
2020 int nr = dims(0); |
|
2021 int nc = dims(1); |
|
2022 |
|
2023 for (int i = 0; i < m; i++) |
|
2024 { |
|
2025 std::string nm = "ans"; |
|
2026 |
|
2027 if (m > 1) |
|
2028 { |
|
2029 nm += "(:,:,"; |
|
2030 |
|
2031 OSSTREAM buf; |
|
2032 |
|
2033 for (int k = 2; k < ndims; k++) |
|
2034 { |
|
2035 buf << ra_idx(k) + 1; |
|
2036 |
|
2037 if (k < ndims - 1) |
|
2038 buf << ","; |
|
2039 else |
|
2040 buf << ")"; |
|
2041 } |
|
2042 |
|
2043 buf << OSSTREAM_ENDS; |
|
2044 |
|
2045 nm += OSSTREAM_STR (buf); |
|
2046 |
|
2047 OSSTREAM_FREEZE (buf); |
|
2048 } |
|
2049 |
|
2050 Array<idx_vector> idx (ndims); |
|
2051 |
|
2052 idx(0) = idx_vector (':'); |
|
2053 idx(1) = idx_vector (':'); |
|
2054 |
|
2055 for (int k = 2; k < ndims; k++) |
|
2056 idx(k) = idx_vector (ra_idx(k) + 1); |
|
2057 |
|
2058 Array2<std::string> page (nda.index (idx), nr, nc); |
|
2059 |
|
2060 // XXX FIXME XXX -- need to do some more work to put these |
|
2061 // in neatly aligned columns... |
|
2062 |
|
2063 int n_rows = page.rows (); |
|
2064 int n_cols = page.cols (); |
|
2065 |
|
2066 os << nm << " =\n\n"; |
|
2067 |
|
2068 for (int ii = 0; ii < n_rows; ii++) |
|
2069 { |
|
2070 for (int jj = 0; jj < n_cols; jj++) |
|
2071 os << " " << page(ii,jj); |
|
2072 |
|
2073 os << "\n"; |
|
2074 } |
|
2075 |
|
2076 if (i < m - 1) |
|
2077 os << "\n"; |
|
2078 |
|
2079 if (i < m) |
|
2080 increment_index (ra_idx, dims, 2); |
|
2081 } |
|
2082 } |
|
2083 } |
|
2084 |
3933
|
2085 extern void |
|
2086 octave_print_internal (std::ostream&, const Cell&, bool, int, bool) |
3928
|
2087 { |
3933
|
2088 panic_impossible (); |
3928
|
2089 } |
|
2090 |
3685
|
2091 DEFUN (disp, args, nargout, |
|
2092 "-*- texinfo -*-\n\ |
|
2093 @deftypefn {Built-in Function} {} disp (@var{x})\n\ |
|
2094 Display the value of @var{x}. For example,\n\ |
|
2095 \n\ |
|
2096 @example\n\ |
|
2097 disp (\"The value of pi is:\"), disp (pi)\n\ |
|
2098 \n\ |
|
2099 @print{} the value of pi is:\n\ |
|
2100 @print{} 3.1416\n\ |
|
2101 @end example\n\ |
|
2102 \n\ |
|
2103 @noindent\n\ |
|
2104 Note that the output from @code{disp} always ends with a newline.\n\ |
|
2105 \n\ |
|
2106 If an output value is requested, @code{disp} prints nothing and\n\ |
|
2107 returns the formatted output in a string.\n\ |
|
2108 @end deftypefn\n\ |
|
2109 @seealso{fdisp}") |
|
2110 { |
|
2111 octave_value retval; |
|
2112 |
|
2113 int nargin = args.length (); |
|
2114 |
|
2115 if (nargin == 1 && nargout < 2) |
|
2116 { |
|
2117 if (nargout == 0) |
|
2118 args(0).print (octave_stdout); |
|
2119 else |
|
2120 { |
4051
|
2121 OSSTREAM buf; |
3685
|
2122 args(0).print (buf); |
4051
|
2123 buf << OSSTREAM_ENDS; |
|
2124 retval = OSSTREAM_STR (buf); |
|
2125 OSSTREAM_FREEZE (buf); |
3685
|
2126 } |
|
2127 } |
|
2128 else |
|
2129 print_usage ("disp"); |
|
2130 |
|
2131 return retval; |
|
2132 } |
|
2133 |
|
2134 DEFUN (fdisp, args, , |
|
2135 "-*- texinfo -*-\n\ |
|
2136 @deftypefn {Built-in Function} {} fdisp (@var{fid}, @var{x})\n\ |
|
2137 Display the value of @var{x} on the stream @var{fid}. For example,\n\ |
|
2138 \n\ |
|
2139 @example\n\ |
|
2140 disp (stdout, \"The value of pi is:\"), disp (stdout, pi)\n\ |
|
2141 \n\ |
|
2142 @print{} the value of pi is:\n\ |
|
2143 @print{} 3.1416\n\ |
|
2144 @end example\n\ |
|
2145 \n\ |
|
2146 @noindent\n\ |
|
2147 Note that the output from @code{disp} always ends with a newline.\n\ |
|
2148 \n\ |
|
2149 If an output value is requested, @code{disp} prints nothing and\n\ |
|
2150 returns the formatted output in a string.\n\ |
|
2151 @end deftypefn\n\ |
|
2152 @seealso{disp}") |
|
2153 { |
|
2154 octave_value retval; |
|
2155 |
|
2156 int nargin = args.length (); |
|
2157 |
|
2158 if (nargin == 2) |
|
2159 { |
|
2160 int fid = octave_stream_list::get_file_number (args (0)); |
|
2161 |
|
2162 octave_stream os = octave_stream_list::lookup (fid, "fdisp"); |
|
2163 |
|
2164 if (! error_state) |
|
2165 { |
3769
|
2166 std::ostream *osp = os.output_stream (); |
3685
|
2167 |
|
2168 if (osp) |
|
2169 args(1).print (*osp); |
|
2170 else |
|
2171 error ("fdisp: stream not open for writing"); |
|
2172 } |
|
2173 } |
|
2174 else |
|
2175 print_usage ("fdisp"); |
|
2176 |
|
2177 return retval; |
|
2178 } |
|
2179 |
1
|
2180 static void |
|
2181 init_format_state (void) |
|
2182 { |
2387
|
2183 free_format = false; |
|
2184 plus_format = false; |
|
2185 bank_format = false; |
3608
|
2186 hex_format = 0; |
1309
|
2187 bit_format = 0; |
2387
|
2188 print_e = false; |
|
2189 print_big_e = false; |
4509
|
2190 print_g = false; |
1
|
2191 } |
|
2192 |
|
2193 static void |
|
2194 set_output_prec_and_fw (int prec, int fw) |
|
2195 { |
4233
|
2196 bind_builtin_variable ("output_precision", prec); |
|
2197 bind_builtin_variable ("output_max_field_width", fw); |
1
|
2198 } |
|
2199 |
1755
|
2200 static void |
|
2201 set_format_style (int argc, const string_vector& argv) |
1
|
2202 { |
1755
|
2203 int idx = 1; |
|
2204 |
1899
|
2205 if (--argc > 0) |
1
|
2206 { |
3523
|
2207 std::string arg = argv[idx++]; |
2584
|
2208 |
1755
|
2209 if (arg == "short") |
1
|
2210 { |
1755
|
2211 if (--argc > 0) |
1
|
2212 { |
1755
|
2213 arg = argv[idx++]; |
|
2214 |
|
2215 if (arg == "e") |
1
|
2216 { |
1755
|
2217 init_format_state (); |
2387
|
2218 print_e = true; |
1755
|
2219 } |
|
2220 else if (arg == "E") |
|
2221 { |
|
2222 init_format_state (); |
2387
|
2223 print_e = true; |
|
2224 print_big_e = true; |
1
|
2225 } |
4509
|
2226 else if (arg == "g") |
|
2227 { |
|
2228 init_format_state (); |
|
2229 print_g = true; |
|
2230 } |
|
2231 else if (arg == "G") |
|
2232 { |
|
2233 init_format_state (); |
|
2234 print_g = true; |
|
2235 print_big_e = true; |
|
2236 } |
1
|
2237 else |
|
2238 { |
1755
|
2239 error ("format: unrecognized option `short %s'", |
|
2240 arg.c_str ()); |
|
2241 return; |
|
2242 } |
|
2243 } |
|
2244 else |
|
2245 init_format_state (); |
|
2246 |
4509
|
2247 set_output_prec_and_fw (5, 10); |
1755
|
2248 } |
|
2249 else if (arg == "long") |
|
2250 { |
|
2251 if (--argc > 0) |
|
2252 { |
|
2253 arg = argv[idx++]; |
|
2254 |
|
2255 if (arg == "e") |
|
2256 { |
|
2257 init_format_state (); |
2387
|
2258 print_e = true; |
1755
|
2259 } |
|
2260 else if (arg == "E") |
|
2261 { |
|
2262 init_format_state (); |
2387
|
2263 print_e = true; |
|
2264 print_big_e = true; |
1
|
2265 } |
4509
|
2266 else if (arg == "g") |
|
2267 { |
|
2268 init_format_state (); |
|
2269 print_g = true; |
|
2270 } |
|
2271 else if (arg == "G") |
|
2272 { |
|
2273 init_format_state (); |
|
2274 print_g = true; |
|
2275 print_big_e = true; |
|
2276 } |
1
|
2277 else |
1755
|
2278 { |
|
2279 error ("format: unrecognized option `long %s'", |
|
2280 arg.c_str ()); |
|
2281 return; |
|
2282 } |
1186
|
2283 } |
1
|
2284 else |
1755
|
2285 init_format_state (); |
|
2286 |
4509
|
2287 set_output_prec_and_fw (15, 20); |
1755
|
2288 } |
|
2289 else if (arg == "hex") |
|
2290 { |
|
2291 init_format_state (); |
3608
|
2292 hex_format = 1; |
1755
|
2293 } |
|
2294 else if (arg == "native-hex") |
|
2295 { |
|
2296 init_format_state (); |
|
2297 hex_format = 2; |
|
2298 } |
|
2299 else if (arg == "bit") |
|
2300 { |
|
2301 init_format_state (); |
|
2302 bit_format = 1; |
|
2303 } |
|
2304 else if (arg == "native-bit") |
|
2305 { |
|
2306 init_format_state (); |
|
2307 bit_format = 2; |
|
2308 } |
|
2309 else if (arg == "+" || arg == "plus") |
|
2310 { |
4632
|
2311 if (--argc > 0) |
|
2312 { |
|
2313 arg = argv[idx++]; |
|
2314 |
|
2315 if (arg.length () == 3) |
|
2316 plus_format_chars = arg; |
|
2317 else |
|
2318 { |
|
2319 error ("format: invalid option for plus format"); |
|
2320 return; |
|
2321 } |
|
2322 } |
|
2323 else |
|
2324 plus_format_chars = "+ "; |
|
2325 |
1755
|
2326 init_format_state (); |
2387
|
2327 plus_format = true; |
1755
|
2328 } |
|
2329 else if (arg == "bank") |
|
2330 { |
|
2331 init_format_state (); |
2387
|
2332 bank_format = true; |
1755
|
2333 } |
|
2334 else if (arg == "free") |
|
2335 { |
|
2336 init_format_state (); |
2387
|
2337 free_format = true; |
1755
|
2338 } |
|
2339 else if (arg == "none") |
|
2340 { |
|
2341 init_format_state (); |
2387
|
2342 free_format = true; |
1755
|
2343 } |
|
2344 else if (arg == "compact") |
|
2345 { |
2387
|
2346 compact_format = true; |
1755
|
2347 } |
|
2348 else if (arg == "loose") |
|
2349 { |
2387
|
2350 compact_format = false; |
1
|
2351 } |
|
2352 else |
1755
|
2353 error ("format: unrecognized format state `%s'", arg.c_str ()); |
1
|
2354 } |
|
2355 else |
|
2356 { |
|
2357 init_format_state (); |
|
2358 set_output_prec_and_fw (5, 10); |
|
2359 } |
|
2360 } |
|
2361 |
4208
|
2362 DEFCMD (format, args, , |
3372
|
2363 "-*- texinfo -*-\n\ |
|
2364 @deffn {Command} format options\n\ |
|
2365 Control the format of the output produced by @code{disp} and Octave's\n\ |
|
2366 normal echoing mechanism. Valid options are listed in the following\n\ |
|
2367 table.\n\ |
|
2368 \n\ |
|
2369 @table @code\n\ |
|
2370 @item short\n\ |
|
2371 Octave will try to print numbers with at\n\ |
4509
|
2372 least 5 significant figures within a field that is a maximum of 10\n\ |
|
2373 characters wide (not counting additional spacing that is added between\n\ |
|
2374 columns of a matrix).\n\ |
3372
|
2375 \n\ |
|
2376 If Octave is unable to format a matrix so that columns line up on the\n\ |
|
2377 decimal point and all the numbers fit within the maximum field width,\n\ |
|
2378 it switches to an @samp{e} format.\n\ |
|
2379 \n\ |
|
2380 @item long\n\ |
|
2381 Octave will try to print numbers with at least 15 significant figures\n\ |
4509
|
2382 within a field that is a maximum of 20 characters wide (not counting\n\ |
|
2383 additional spacing that is added between columns of a matrix).\n\ |
3372
|
2384 \n\ |
|
2385 As will the @samp{short} format, Octave will switch to an @samp{e}\n\ |
|
2386 format if it is unable to format a matrix so that columns line up on the\n\ |
|
2387 decimal point and all the numbers fit within the maximum field width.\n\ |
|
2388 \n\ |
|
2389 @item long e\n\ |
|
2390 @itemx short e\n\ |
|
2391 The same as @samp{format long} or @samp{format short} but always display\n\ |
|
2392 output with an @samp{e} format. For example, with the @samp{short e}\n\ |
4509
|
2393 format, @code{pi} is displayed as @code{3.14e+00}.\n\ |
3372
|
2394 \n\ |
|
2395 @item long E\n\ |
|
2396 @itemx short E\n\ |
|
2397 The same as @samp{format long e} or @samp{format short e} but always\n\ |
|
2398 display output with an uppercase @samp{E} format. For example, with\n\ |
4509
|
2399 the @samp{long E} format, @code{pi} is displayed as\n\ |
3372
|
2400 @code{3.14159265358979E+00}.\n\ |
4509
|
2401 @item long g\n\ |
|
2402 @itemx short g\n\ |
|
2403 Choose between normal @samp{long} (or @samp{short}) and and\n\ |
|
2404 @samp{long e} (or @samp{short e}) formats based on the magnitude\n\ |
|
2405 of the number. For example, with the @samp{short g} format,\n\ |
|
2406 @code{pi .^ [2; 4; 8; 16; 32]} is displayed as\n\ |
|
2407 \n\ |
|
2408 @example\n\ |
|
2409 @group\n\ |
|
2410 ans =\n\ |
|
2411 \n\ |
|
2412 3.1416\n\ |
|
2413 9.8696\n\ |
|
2414 97.409\n\ |
|
2415 9488.5\n\ |
|
2416 9.0032e+07\n\ |
|
2417 8.1058e+15\n\ |
|
2418 @end group\n\ |
|
2419 @end example\n\ |
|
2420 \n\ |
|
2421 @item long G\n\ |
|
2422 @itemx short G\n\ |
|
2423 The same as @samp{format long g} or @samp{format short g} but use an\n\ |
|
2424 uppercase @samp{E} format. For example, with the @samp{short G} format,\n\ |
|
2425 @code{pi .^ [2; 4; 8; 16; 32]} is displayed as\n\ |
|
2426 \n\ |
|
2427 @example\n\ |
|
2428 @group\n\ |
|
2429 ans =\n\ |
|
2430 \n\ |
|
2431 3.1416\n\ |
|
2432 9.8696\n\ |
|
2433 97.409\n\ |
|
2434 9488.5\n\ |
|
2435 9.0032E+07\n\ |
|
2436 8.1058E+15\n\ |
|
2437 @end group\n\ |
|
2438 @end example\n\ |
3372
|
2439 \n\ |
|
2440 @item free\n\ |
|
2441 @itemx none\n\ |
|
2442 Print output in free format, without trying to line up columns of\n\ |
|
2443 matrices on the decimal point. This also causes complex numbers to be\n\ |
|
2444 formatted like this @samp{(0.604194, 0.607088)} instead of like this\n\ |
|
2445 @samp{0.60419 + 0.60709i}.\n\ |
529
|
2446 \n\ |
3372
|
2447 @item bank\n\ |
|
2448 Print in a fixed format with two places to the right of the decimal\n\ |
|
2449 point.\n\ |
|
2450 \n\ |
|
2451 @item +\n\ |
4632
|
2452 @itemx + @var{chars}\n\ |
|
2453 @itemx plus\n\ |
|
2454 @itemx plus @var{chars}\n\ |
3372
|
2455 Print a @samp{+} symbol for nonzero matrix elements and a space for zero\n\ |
|
2456 matrix elements. This format can be very useful for examining the\n\ |
|
2457 structure of a large matrix.\n\ |
|
2458 \n\ |
4632
|
2459 The optional argument @var{chars} specifies a list of 3 characters to use\n\ |
|
2460 for printing values greater than zero, less than zero and equal to zero.\n\ |
|
2461 For example, with the @samp{+ \"+-.\"} format, @code{[1, 0, -1; -1, 0, 1]}\n\ |
|
2462 is displayed as\n\ |
|
2463 \n\ |
|
2464 @example\n\ |
|
2465 @group\n\ |
|
2466 ans =\n\ |
|
2467 \n\ |
|
2468 +.-\n\ |
|
2469 -.+\n\ |
|
2470 @end group\n\ |
|
2471 @end example\n\ |
|
2472 \n\ |
3372
|
2473 @item hex\n\ |
|
2474 Print the hexadecimal representation numbers as they are stored in\n\ |
|
2475 memory. For example, on a workstation which stores 8 byte real values\n\ |
|
2476 in IEEE format with the least significant byte first, the value of\n\ |
|
2477 @code{pi} when printed in @code{hex} format is @code{400921fb54442d18}.\n\ |
|
2478 This format only works for numeric values.\n\ |
|
2479 \n\ |
|
2480 @item bit\n\ |
|
2481 Print the bit representation of numbers as stored in memory.\n\ |
|
2482 For example, the value of @code{pi} is\n\ |
|
2483 \n\ |
|
2484 @example\n\ |
|
2485 @group\n\ |
|
2486 01000000000010010010000111111011\n\ |
|
2487 01010100010001000010110100011000\n\ |
|
2488 @end group\n\ |
|
2489 @end example\n\ |
|
2490 \n\ |
|
2491 (shown here in two 32 bit sections for typesetting purposes) when\n\ |
|
2492 printed in bit format on a workstation which stores 8 byte real values\n\ |
|
2493 in IEEE format with the least significant byte first. This format only\n\ |
|
2494 works for numeric types.\n\ |
|
2495 @end table\n\ |
|
2496 \n\ |
|
2497 By default, Octave will try to print numbers with at least 5 significant\n\ |
|
2498 figures within a field that is a maximum of 10 characters wide.\n\ |
|
2499 \n\ |
|
2500 If Octave is unable to format a matrix so that columns line up on the\n\ |
|
2501 decimal point and all the numbers fit within the maximum field width,\n\ |
|
2502 it switches to an @samp{e} format.\n\ |
|
2503 \n\ |
|
2504 If @code{format} is invoked without any options, the default format\n\ |
|
2505 state is restored.\n\ |
|
2506 @end deffn") |
529
|
2507 { |
2086
|
2508 octave_value_list retval; |
529
|
2509 |
1755
|
2510 int argc = args.length () + 1; |
|
2511 |
1968
|
2512 string_vector argv = args.make_argv ("format"); |
1755
|
2513 |
|
2514 if (error_state) |
|
2515 return retval; |
529
|
2516 |
|
2517 set_format_style (argc, argv); |
|
2518 |
|
2519 return retval; |
|
2520 } |
|
2521 |
2165
|
2522 static int |
3105
|
2523 fixed_point_format (void) |
|
2524 { |
|
2525 Vfixed_point_format = check_preference ("fixed_point_format"); |
|
2526 |
|
2527 return 0; |
|
2528 } |
|
2529 |
|
2530 static int |
2165
|
2531 output_max_field_width (void) |
|
2532 { |
|
2533 double val; |
|
2534 if (builtin_real_scalar_variable ("output_max_field_width", val) |
4025
|
2535 && ! octave_is_NaN_or_NA (val)) |
2165
|
2536 { |
|
2537 int ival = NINT (val); |
2800
|
2538 if (ival > 0 && ival == val) |
2165
|
2539 { |
|
2540 Voutput_max_field_width = ival; |
|
2541 return 0; |
|
2542 } |
|
2543 } |
|
2544 gripe_invalid_value_specified ("output_max_field_width"); |
|
2545 return -1; |
|
2546 } |
|
2547 |
|
2548 static int |
|
2549 output_precision (void) |
|
2550 { |
|
2551 double val; |
|
2552 if (builtin_real_scalar_variable ("output_precision", val) |
4025
|
2553 && ! octave_is_NaN_or_NA (val)) |
2165
|
2554 { |
|
2555 int ival = NINT (val); |
2800
|
2556 if (ival >= 0 && ival == val) |
2165
|
2557 { |
|
2558 Voutput_precision = ival; |
|
2559 return 0; |
|
2560 } |
|
2561 } |
|
2562 gripe_invalid_value_specified ("output_precision"); |
|
2563 return -1; |
|
2564 } |
|
2565 |
|
2566 static int |
|
2567 print_empty_dimensions (void) |
|
2568 { |
|
2569 Vprint_empty_dimensions = check_preference ("print_empty_dimensions"); |
|
2570 |
|
2571 return 0; |
|
2572 } |
|
2573 |
|
2574 static int |
|
2575 split_long_rows (void) |
|
2576 { |
|
2577 Vsplit_long_rows = check_preference ("split_long_rows"); |
|
2578 |
|
2579 return 0; |
|
2580 } |
|
2581 |
|
2582 void |
|
2583 symbols_of_pr_output (void) |
|
2584 { |
4233
|
2585 DEFVAR (fixed_point_format, false, fixed_point_format, |
3321
|
2586 "-*- texinfo -*-\n\ |
|
2587 @defvr {Built-in Variable} fixed_point_format\n\ |
|
2588 If the value of this variable is nonzero, Octave will scale all values\n\ |
|
2589 in a matrix so that the largest may be written with one leading digit.\n\ |
|
2590 The scaling factor is printed on the first line of output. For example,\n\ |
|
2591 \n\ |
|
2592 @example\n\ |
|
2593 @group\n\ |
|
2594 octave:1> logspace (1, 7, 5)'\n\ |
|
2595 ans =\n\ |
|
2596 \n\ |
|
2597 1.0e+07 *\n\ |
|
2598 \n\ |
|
2599 0.00000\n\ |
|
2600 0.00003\n\ |
|
2601 0.00100\n\ |
|
2602 0.03162\n\ |
|
2603 1.00000\n\ |
|
2604 @end group\n\ |
|
2605 @end example\n\ |
|
2606 \n\ |
|
2607 @noindent\n\ |
|
2608 Notice that first value appears to be zero when it is actually 1. For\n\ |
|
2609 this reason, you should be careful when setting\n\ |
|
2610 @code{fixed_point_format} to a nonzero value.\n\ |
|
2611 \n\ |
|
2612 The default value of @code{fixed_point_format} is 0.\n\ |
3333
|
2613 @end defvr"); |
3105
|
2614 |
3258
|
2615 DEFVAR (output_max_field_width, 10.0, output_max_field_width, |
3321
|
2616 "-*- texinfo -*-\n\ |
|
2617 @defvr {Built-in Variable} output_max_field_width\n\ |
|
2618 This variable specifies the maximum width of a numeric output field.\n\ |
|
2619 The default value is 10.\n\ |
3333
|
2620 @end defvr"); |
2165
|
2621 |
3258
|
2622 DEFVAR (output_precision, 5.0, output_precision, |
3321
|
2623 "-*- texinfo -*-\n\ |
|
2624 @defvr {Built-in Variable} output_precision\n\ |
|
2625 This variable specifies the minimum number of significant figures to\n\ |
|
2626 display for numeric output. The default value is 5.\n\ |
3333
|
2627 @end defvr"); |
2165
|
2628 |
4233
|
2629 DEFVAR (print_empty_dimensions, true, print_empty_dimensions, |
3321
|
2630 "-*- texinfo -*-\n\ |
|
2631 @defvr {Built-in Variable} print_empty_dimensions\n\ |
|
2632 If the value of @code{print_empty_dimensions} is nonzero, the\n\ |
|
2633 dimensions of empty matrices are printed along with the empty matrix\n\ |
|
2634 symbol, @samp{[]}. For example, the expression\n\ |
|
2635 \n\ |
|
2636 @example\n\ |
|
2637 zeros (3, 0)\n\ |
|
2638 @end example\n\ |
|
2639 \n\ |
|
2640 @noindent\n\ |
|
2641 will print\n\ |
|
2642 \n\ |
|
2643 @example\n\ |
|
2644 ans = [](3x0)\n\ |
|
2645 @end example\n\ |
3333
|
2646 @end defvr"); |
2165
|
2647 |
4233
|
2648 DEFVAR (split_long_rows, true, split_long_rows, |
3321
|
2649 "-*- texinfo -*-\n\ |
|
2650 @defvr {Built-in Variable} split_long_rows\n\ |
|
2651 For large matrices, Octave may not be able to display all the columns of\n\ |
|
2652 a given row on one line of your screen. This can result in missing\n\ |
|
2653 information or output that is nearly impossible to decipher, depending\n\ |
|
2654 on whether your terminal truncates or wraps long lines.\n\ |
|
2655 \n\ |
|
2656 If the value of @code{split_long_rows} is nonzero, Octave will display\n\ |
|
2657 the matrix in a series of smaller pieces, each of which can fit within\n\ |
|
2658 the limits of your terminal width. Each set of rows is labeled so that\n\ |
|
2659 you can easily see which columns are currently being displayed.\n\ |
|
2660 For example:\n\ |
|
2661 \n\ |
|
2662 @smallexample\n\ |
|
2663 @group\n\ |
|
2664 octave:13> rand (2,10)\n\ |
|
2665 ans =\n\ |
|
2666 \n\ |
|
2667 Columns 1 through 6:\n\ |
|
2668 \n\ |
|
2669 0.75883 0.93290 0.40064 0.43818 0.94958 0.16467\n\ |
|
2670 0.75697 0.51942 0.40031 0.61784 0.92309 0.40201\n\ |
|
2671 \n\ |
|
2672 Columns 7 through 10:\n\ |
|
2673 \n\ |
|
2674 0.90174 0.11854 0.72313 0.73326\n\ |
|
2675 0.44672 0.94303 0.56564 0.82150\n\ |
|
2676 @end group\n\ |
|
2677 @end smallexample\n\ |
|
2678 \n\ |
|
2679 @noindent\n\ |
|
2680 The default value of @code{split_long_rows} is nonzero.\n\ |
3333
|
2681 @end defvr"); |
2165
|
2682 } |
|
2683 |
1
|
2684 /* |
|
2685 ;;; Local Variables: *** |
|
2686 ;;; mode: C++ *** |
|
2687 ;;; End: *** |
|
2688 */ |