1
|
1 // pr-output.cc -*- C++ -*- |
|
2 /* |
|
3 |
1009
|
4 Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton |
1
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
|
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 */ |
|
23 |
240
|
24 #ifdef HAVE_CONFIG_H |
1192
|
25 #include <config.h> |
1
|
26 #endif |
|
27 |
|
28 #include <iostream.h> |
|
29 #include <strstream.h> |
|
30 #include <string.h> |
|
31 #include <math.h> |
|
32 #include <float.h> |
|
33 #include <Complex.h> |
|
34 |
453
|
35 #include "dMatrix.h" |
|
36 #include "CMatrix.h" |
1
|
37 #include "Range.h" |
|
38 |
|
39 #include "tree-const.h" |
|
40 #include "variables.h" |
|
41 #include "user-prefs.h" |
|
42 #include "pr-output.h" |
|
43 #include "mappers.h" |
1282
|
44 #include "sysdep.h" |
1
|
45 #include "pager.h" |
542
|
46 #include "help.h" |
1
|
47 #include "error.h" |
|
48 #include "utils.h" |
529
|
49 #include "defun.h" |
1
|
50 |
|
51 // Current format string for real numbers and the real part of complex |
|
52 // numbers. |
529
|
53 static char *curr_real_fmt = 0; |
1
|
54 |
|
55 // Current format string for the imaginary part of complex numbers. |
529
|
56 static char *curr_imag_fmt = 0; |
1
|
57 |
1186
|
58 // Nonzero means don't do any fancy formatting. |
1
|
59 static int free_format = 0; |
|
60 |
|
61 // Nonzero means print plus sign for nonzero, blank for zero. |
|
62 static int plus_format = 0; |
|
63 |
1282
|
64 // Nonzero means always print like dollars and cents. |
|
65 static int bank_format = 0; |
|
66 |
|
67 // Nonzero means print data in hexadecimal format. |
|
68 static int hex_format = 0; |
|
69 |
1186
|
70 // Nonzero means don't put newlines around the column number headers. |
|
71 static int compact_format = 0; |
|
72 |
1
|
73 // Nonzero means use an e format. |
|
74 static int print_e = 0; |
|
75 |
|
76 // Nonzero means print E instead of e for exponent field. |
|
77 static int print_big_e = 0; |
|
78 |
|
79 static int |
|
80 any_element_is_negative (const Matrix& a) |
|
81 { |
|
82 int nr = a.rows (); |
|
83 int nc = a.columns (); |
|
84 for (int j = 0; j < nc; j++) |
|
85 for (int i = 0; i < nr; i++) |
|
86 if (a.elem (i, j) < 0.0) |
|
87 return 1; |
|
88 return 0; |
|
89 } |
|
90 |
|
91 static int |
|
92 any_element_is_inf_or_nan (const Matrix& a) |
|
93 { |
|
94 int nr = a.rows (); |
|
95 int nc = a.columns (); |
|
96 for (int j = 0; j < nc; j++) |
|
97 for (int i = 0; i < nr; i++) |
|
98 { |
|
99 double val = a.elem (i, j); |
|
100 if (xisinf (val) || xisnan (val)) |
|
101 return 1; |
|
102 } |
|
103 return 0; |
|
104 } |
|
105 |
|
106 static int |
|
107 any_element_is_inf_or_nan (const ComplexMatrix& a) |
|
108 { |
|
109 int nr = a.rows (); |
|
110 int nc = a.columns (); |
|
111 for (int j = 0; j < nc; j++) |
|
112 for (int i = 0; i < nr; i++) |
|
113 { |
|
114 Complex val = a.elem (i, j); |
|
115 if (xisinf (val) || xisnan (val)) |
|
116 return 1; |
|
117 } |
|
118 return 0; |
|
119 } |
|
120 |
|
121 static int |
|
122 all_elements_are_int_or_inf_or_nan (const Matrix& a) |
|
123 { |
|
124 int nr = a.rows (); |
|
125 int nc = a.columns (); |
|
126 for (int j = 0; j < nc; j++) |
|
127 for (int i = 0; i < nr; i++) |
|
128 { |
|
129 double val = a.elem (i, j); |
|
130 if (xisnan (val) || D_NINT (val) == val) |
|
131 continue; |
|
132 else |
|
133 return 0; |
|
134 } |
|
135 return 1; |
|
136 } |
|
137 |
|
138 static Matrix |
|
139 abs (const Matrix& a) |
|
140 { |
|
141 int nr = a.rows (); |
|
142 int nc = a.columns (); |
|
143 Matrix retval (nr, nc); |
|
144 for (int j = 0; j < nc; j++) |
|
145 for (int i = 0; i < nr; i++) |
|
146 retval.elem (i, j) = fabs (a.elem (i, j)); |
|
147 return retval; |
|
148 } |
|
149 |
|
150 static double |
164
|
151 pr_max_internal (const Matrix& m) |
1
|
152 { |
|
153 int nr = m.rows (); |
|
154 int nc = m.columns (); |
|
155 |
|
156 double result = DBL_MIN; |
|
157 |
|
158 for (int j = 0; j < nc; j++) |
|
159 for (int i = 0; i < nr; i++) |
|
160 { |
|
161 double val = m.elem (i, j); |
|
162 if (xisinf (val) || xisnan (val)) |
|
163 continue; |
|
164 |
|
165 if (val > result) |
|
166 result = val; |
|
167 } |
|
168 return result; |
|
169 } |
|
170 |
|
171 static double |
164
|
172 pr_min_internal (const Matrix& m) |
1
|
173 { |
|
174 int nr = m.rows (); |
|
175 int nc = m.columns (); |
|
176 |
|
177 double result = DBL_MAX; |
|
178 |
|
179 for (int j = 0; j < nc; j++) |
|
180 for (int i = 0; i < nr; i++) |
|
181 { |
|
182 double val = m.elem (i, j); |
|
183 if (xisinf (val) || xisnan (val)) |
|
184 continue; |
|
185 |
|
186 if (val < result) |
|
187 result = val; |
|
188 } |
|
189 return result; |
|
190 } |
|
191 |
|
192 static void |
|
193 set_format (double d, int& fw) |
|
194 { |
529
|
195 curr_real_fmt = 0; |
|
196 curr_imag_fmt = 0; |
1
|
197 |
|
198 if (free_format) |
|
199 return; |
|
200 |
278
|
201 static char fmt_buf[128]; |
1
|
202 |
|
203 int sign = (d < 0.0); |
|
204 |
|
205 int inf_or_nan = (xisinf (d) || xisnan (d)); |
|
206 |
|
207 double d_abs = d < 0.0 ? -d : d; |
|
208 |
575
|
209 int digits = (inf_or_nan || d_abs == 0.0) ? 0 |
|
210 : (int) floor (log10 (d_abs) + 1.0); |
1
|
211 |
|
212 int prec = user_pref.output_precision; |
|
213 |
|
214 int ld, rd; |
|
215 |
|
216 if (bank_format) |
|
217 { |
|
218 fw = digits < 0 ? 4 : digits + 3; |
|
219 if (inf_or_nan && fw < 3) |
|
220 fw = 3; |
|
221 fw += sign; |
|
222 rd = 2; |
|
223 } |
1282
|
224 else if (hex_format) |
|
225 { |
|
226 fw = 2 * sizeof (double); |
|
227 rd = 0; |
|
228 } |
1
|
229 else if (xisnan (d) || D_NINT (d) == d) |
|
230 { |
|
231 fw = digits; |
|
232 if (inf_or_nan && fw < 3) |
|
233 fw = 3; |
|
234 fw += sign; |
|
235 rd = 0; |
|
236 } |
|
237 else |
|
238 { |
|
239 if (digits > 0) |
|
240 { |
|
241 ld = digits; |
|
242 rd = prec - digits; |
|
243 digits++; |
|
244 } |
|
245 else |
|
246 { |
|
247 ld = 1; |
|
248 rd = prec - digits; |
|
249 digits = -digits + 1; |
|
250 } |
|
251 |
|
252 fw = ld + 1 + rd; |
|
253 if (inf_or_nan && fw < 3) |
|
254 fw = 3; |
|
255 fw += sign; |
|
256 } |
|
257 |
1282
|
258 if (! (bank_format || hex_format) |
|
259 && (fw > user_pref.output_max_field_width || print_e)) |
1
|
260 { |
|
261 int exp_field = 4; |
|
262 if (digits > 100) |
|
263 exp_field++; |
|
264 |
|
265 fw = 2 + prec + exp_field; |
|
266 if (inf_or_nan && fw < 3) |
|
267 fw = 3; |
|
268 fw += sign; |
|
269 |
|
270 if (print_big_e) |
|
271 sprintf (fmt_buf, "%%%d.%dE", fw, prec - 1); |
|
272 else |
|
273 sprintf (fmt_buf, "%%%d.%de", fw, prec - 1); |
|
274 } |
|
275 else |
|
276 { |
|
277 sprintf (fmt_buf, "%%%d.%df", fw, rd); |
|
278 } |
|
279 |
|
280 curr_real_fmt = &fmt_buf[0]; |
|
281 } |
|
282 |
|
283 static inline void |
|
284 set_format (double d) |
|
285 { |
|
286 int fw; |
|
287 set_format (d, fw); |
|
288 } |
|
289 |
|
290 static void |
164
|
291 set_format (const Matrix& m, int& fw) |
1
|
292 { |
529
|
293 curr_real_fmt = 0; |
|
294 curr_imag_fmt = 0; |
1
|
295 |
|
296 if (free_format) |
|
297 return; |
|
298 |
278
|
299 static char fmt_buf[128]; |
1
|
300 |
|
301 int sign = any_element_is_negative (m); |
|
302 |
|
303 int inf_or_nan = any_element_is_inf_or_nan (m); |
|
304 |
|
305 Matrix m_abs = abs (m); |
|
306 double max_abs = pr_max_internal (m_abs); |
|
307 double min_abs = pr_min_internal (m_abs); |
|
308 |
|
309 int x_max = max_abs == 0.0 ? 0 : (int) floor (log10 (max_abs) + 1.0); |
|
310 int x_min = min_abs == 0.0 ? 0 : (int) floor (log10 (min_abs) + 1.0); |
|
311 |
|
312 int prec = user_pref.output_precision; |
|
313 |
|
314 int ld, rd; |
|
315 |
|
316 if (bank_format) |
|
317 { |
|
318 int digits = x_max > x_min ? x_max : x_min; |
|
319 fw = digits <= 0 ? 4 : digits + 3; |
|
320 if (inf_or_nan && fw < 3) |
|
321 fw = 3; |
|
322 fw += sign; |
|
323 rd = 2; |
|
324 } |
1282
|
325 else if (hex_format) |
|
326 { |
|
327 fw = 2 * sizeof (double); |
|
328 rd = 0; |
|
329 } |
1
|
330 else if (all_elements_are_int_or_inf_or_nan (m)) |
|
331 { |
|
332 int digits = x_max > x_min ? x_max : x_min; |
|
333 fw = digits <= 0 ? 1 : digits; |
|
334 if (inf_or_nan && fw < 3) |
|
335 fw = 3; |
|
336 fw += sign; |
|
337 rd = 0; |
|
338 } |
|
339 else |
|
340 { |
|
341 int ld_max, rd_max; |
|
342 if (x_max > 0) |
|
343 { |
|
344 ld_max = x_max; |
|
345 rd_max = prec - x_max; |
|
346 x_max++; |
|
347 } |
|
348 else |
|
349 { |
|
350 ld_max = 1; |
|
351 rd_max = prec - x_max; |
|
352 x_max = -x_max + 1; |
|
353 } |
|
354 |
|
355 int ld_min, rd_min; |
|
356 if (x_min > 0) |
|
357 { |
|
358 ld_min = x_min; |
|
359 rd_min = prec - x_min; |
|
360 x_min++; |
|
361 } |
|
362 else |
|
363 { |
|
364 ld_min = 1; |
|
365 rd_min = prec - x_min; |
|
366 x_min = -x_min + 1; |
|
367 } |
|
368 |
|
369 ld = ld_max > ld_min ? ld_max : ld_min; |
|
370 rd = rd_max > rd_min ? rd_max : rd_min; |
|
371 |
|
372 fw = ld + 1 + rd; |
|
373 if (inf_or_nan && fw < 3) |
|
374 fw = 3; |
|
375 fw += sign; |
|
376 } |
|
377 |
1282
|
378 if (! (bank_format ||hex_format) |
|
379 && (fw > user_pref.output_max_field_width || print_e)) |
1
|
380 { |
|
381 int exp_field = 4; |
|
382 if (x_max > 100 || x_min > 100) |
|
383 exp_field++; |
|
384 |
|
385 fw = 2 + prec + exp_field; |
|
386 if (inf_or_nan && fw < 3) |
|
387 fw = 3; |
|
388 fw += sign; |
|
389 |
|
390 if (print_big_e) |
|
391 sprintf (fmt_buf, "%%%d.%dE", fw, prec - 1); |
|
392 else |
|
393 sprintf (fmt_buf, "%%%d.%de", fw, prec - 1); |
|
394 } |
|
395 else |
|
396 { |
|
397 sprintf (fmt_buf, "%%%d.%df", fw, rd); |
|
398 } |
|
399 |
|
400 curr_real_fmt = &fmt_buf[0]; |
|
401 } |
|
402 |
|
403 static inline void |
164
|
404 set_format (const Matrix& m) |
1
|
405 { |
|
406 int fw; |
|
407 set_format (m, fw); |
|
408 } |
|
409 |
|
410 static void |
164
|
411 set_format (const Complex& c, int& r_fw, int& i_fw) |
1
|
412 { |
529
|
413 curr_real_fmt = 0; |
|
414 curr_imag_fmt = 0; |
1
|
415 |
|
416 if (free_format) |
|
417 return; |
|
418 |
278
|
419 static char r_fmt_buf[128]; |
|
420 static char i_fmt_buf[128]; |
1
|
421 |
|
422 double rp = c.real (); |
|
423 double ip = c.imag (); |
|
424 |
|
425 int sign = (rp < 0.0); |
|
426 |
|
427 int inf_or_nan = (xisinf (c) || xisnan (c)); |
|
428 |
|
429 double r_abs = rp < 0.0 ? -rp : rp; |
|
430 double i_abs = ip < 0.0 ? -ip : ip; |
|
431 |
|
432 int r_x = r_abs == 0.0 ? 0 : (int) floor (log10 (r_abs) + 1.0); |
|
433 int i_x = i_abs == 0.0 ? 0 : (int) floor (log10 (i_abs) + 1.0); |
|
434 |
|
435 int x_max, x_min; |
|
436 |
|
437 if (r_x > i_x) |
|
438 { |
|
439 x_max = r_x; |
|
440 x_min = i_x; |
|
441 } |
|
442 else |
|
443 { |
|
444 x_max = i_x; |
|
445 x_min = r_x; |
|
446 } |
|
447 |
|
448 int prec = user_pref.output_precision; |
|
449 |
|
450 int ld, rd; |
|
451 |
|
452 if (bank_format) |
|
453 { |
|
454 int digits = r_x; |
|
455 i_fw = 0; |
|
456 r_fw = digits <= 0 ? 4 : digits + 3; |
|
457 if (inf_or_nan && r_fw < 3) |
|
458 r_fw = 3; |
|
459 r_fw += sign; |
|
460 rd = 2; |
|
461 } |
1282
|
462 else if (hex_format) |
|
463 { |
|
464 r_fw = 2 * sizeof (double); |
|
465 i_fw = 2 * sizeof (double); |
|
466 rd = 0; |
|
467 } |
1
|
468 else if (inf_or_nan || (D_NINT (rp) == rp && D_NINT (ip) == ip)) |
|
469 { |
|
470 int digits = x_max > x_min ? x_max : x_min; |
|
471 i_fw = r_fw = digits <= 0 ? 1 : digits; |
|
472 if (inf_or_nan && i_fw < 3) |
|
473 i_fw = r_fw = 3; |
|
474 r_fw += sign; |
|
475 rd = 0; |
|
476 } |
|
477 else |
|
478 { |
|
479 int ld_max, rd_max; |
|
480 if (x_max > 0) |
|
481 { |
|
482 ld_max = x_max; |
|
483 rd_max = prec - x_max; |
|
484 x_max++; |
|
485 } |
|
486 else |
|
487 { |
|
488 ld_max = 1; |
|
489 rd_max = prec - x_max; |
|
490 x_max = -x_max + 1; |
|
491 } |
|
492 |
|
493 int ld_min, rd_min; |
|
494 if (x_min > 0) |
|
495 { |
|
496 ld_min = x_min; |
|
497 rd_min = prec - x_min; |
|
498 x_min++; |
|
499 } |
|
500 else |
|
501 { |
|
502 ld_min = 1; |
|
503 rd_min = prec - x_min; |
|
504 x_min = -x_min + 1; |
|
505 } |
|
506 |
|
507 ld = ld_max > ld_min ? ld_max : ld_min; |
|
508 rd = rd_max > rd_min ? rd_max : rd_min; |
|
509 |
|
510 i_fw = r_fw = ld + 1 + rd; |
|
511 if (inf_or_nan && i_fw < 3) |
|
512 i_fw = r_fw = 3; |
|
513 r_fw += sign; |
|
514 } |
|
515 |
1282
|
516 if (! (bank_format || hex_format) |
|
517 && (r_fw > user_pref.output_max_field_width || print_e)) |
1
|
518 { |
|
519 int exp_field = 4; |
|
520 if (x_max > 100 || x_min > 100) |
|
521 exp_field++; |
|
522 |
|
523 i_fw = r_fw = 1 + prec + exp_field; |
|
524 if (inf_or_nan && i_fw < 3) |
|
525 i_fw = r_fw = 3; |
|
526 r_fw += sign; |
|
527 |
|
528 if (print_big_e) |
|
529 { |
|
530 sprintf (r_fmt_buf, "%%%d.%dE", r_fw, prec - 1); |
|
531 sprintf (i_fmt_buf, "%%%d.%dE", i_fw, prec - 1); |
|
532 } |
|
533 else |
|
534 { |
|
535 sprintf (r_fmt_buf, "%%%d.%de", r_fw, prec - 1); |
|
536 sprintf (i_fmt_buf, "%%%d.%de", i_fw, prec - 1); |
|
537 } |
|
538 } |
|
539 else |
|
540 { |
|
541 sprintf (r_fmt_buf, "%%%d.%df", r_fw, rd); |
|
542 sprintf (i_fmt_buf, "%%%d.%df", i_fw, rd); |
|
543 } |
|
544 |
|
545 curr_real_fmt = &r_fmt_buf[0]; |
|
546 curr_imag_fmt = &i_fmt_buf[0]; |
|
547 } |
|
548 |
|
549 static inline void |
164
|
550 set_format (const Complex& c) |
1
|
551 { |
|
552 int r_fw, i_fw; |
|
553 set_format (c, r_fw, i_fw); |
|
554 } |
|
555 |
|
556 static void |
164
|
557 set_format (const ComplexMatrix& cm, int& r_fw, int& i_fw) |
1
|
558 { |
529
|
559 curr_real_fmt = 0; |
|
560 curr_imag_fmt = 0; |
1
|
561 |
|
562 if (free_format) |
|
563 return; |
|
564 |
278
|
565 static char r_fmt_buf[128]; |
|
566 static char i_fmt_buf[128]; |
1
|
567 |
|
568 Matrix rp = real (cm); |
|
569 Matrix ip = imag (cm); |
|
570 |
|
571 int sign = any_element_is_negative (rp); |
|
572 |
|
573 int inf_or_nan = any_element_is_inf_or_nan (cm); |
|
574 |
|
575 Matrix r_m_abs = abs (rp); |
|
576 double r_max_abs = pr_max_internal (r_m_abs); |
|
577 double r_min_abs = pr_min_internal (r_m_abs); |
|
578 |
|
579 Matrix i_m_abs = abs (ip); |
|
580 double i_max_abs = pr_max_internal (i_m_abs); |
|
581 double i_min_abs = pr_min_internal (i_m_abs); |
|
582 |
|
583 int r_x_max = r_max_abs == 0.0 ? 0 : (int) floor (log10 (r_max_abs) + 1.0); |
|
584 int r_x_min = r_min_abs == 0.0 ? 0 : (int) floor (log10 (r_min_abs) + 1.0); |
|
585 |
|
586 int i_x_max = i_max_abs == 0.0 ? 0 : (int) floor (log10 (i_max_abs) + 1.0); |
|
587 int i_x_min = i_min_abs == 0.0 ? 0 : (int) floor (log10 (i_min_abs) + 1.0); |
|
588 |
|
589 int x_max = r_x_max > i_x_max ? r_x_max : i_x_max; |
|
590 int x_min = r_x_min > i_x_min ? r_x_min : i_x_min; |
|
591 |
|
592 int prec = user_pref.output_precision; |
|
593 |
|
594 int ld, rd; |
|
595 |
|
596 if (bank_format) |
|
597 { |
|
598 int digits = r_x_max > r_x_min ? r_x_max : r_x_min; |
|
599 i_fw = 0; |
|
600 r_fw = digits <= 0 ? 4 : digits + 3; |
|
601 if (inf_or_nan && i_fw < 3) |
|
602 i_fw = r_fw = 3; |
|
603 r_fw += sign; |
|
604 rd = 2; |
|
605 } |
1282
|
606 else if (hex_format) |
|
607 { |
|
608 r_fw = 2 * sizeof (double); |
|
609 i_fw = 2 * sizeof (double); |
|
610 rd = 0; |
|
611 } |
1
|
612 else if (all_elements_are_int_or_inf_or_nan (rp) |
|
613 && all_elements_are_int_or_inf_or_nan (ip)) |
|
614 { |
|
615 int digits = x_max > x_min ? x_max : x_min; |
|
616 i_fw = r_fw = digits <= 0 ? 1 : digits; |
|
617 if (inf_or_nan && i_fw < 3) |
|
618 i_fw = r_fw = 3; |
|
619 r_fw += sign; |
|
620 rd = 0; |
|
621 } |
|
622 else |
|
623 { |
|
624 int ld_max, rd_max; |
|
625 if (x_max > 0) |
|
626 { |
|
627 ld_max = x_max; |
|
628 rd_max = prec - x_max; |
|
629 x_max++; |
|
630 } |
|
631 else |
|
632 { |
|
633 ld_max = 1; |
|
634 rd_max = prec - x_max; |
|
635 x_max = -x_max + 1; |
|
636 } |
|
637 |
|
638 int ld_min, rd_min; |
|
639 if (x_min > 0) |
|
640 { |
|
641 ld_min = x_min; |
|
642 rd_min = prec - x_min; |
|
643 x_min++; |
|
644 } |
|
645 else |
|
646 { |
|
647 ld_min = 1; |
|
648 rd_min = prec - x_min; |
|
649 x_min = -x_min + 1; |
|
650 } |
|
651 |
|
652 ld = ld_max > ld_min ? ld_max : ld_min; |
|
653 rd = rd_max > rd_min ? rd_max : rd_min; |
|
654 |
|
655 i_fw = r_fw = ld + 1 + rd; |
|
656 if (inf_or_nan && i_fw < 3) |
|
657 i_fw = r_fw = 3; |
|
658 r_fw += sign; |
|
659 } |
|
660 |
1282
|
661 if (! (bank_format || hex_format) |
|
662 && (r_fw > user_pref.output_max_field_width || print_e)) |
1
|
663 { |
|
664 int exp_field = 4; |
|
665 if (x_max > 100 || x_min > 100) |
|
666 exp_field++; |
|
667 |
|
668 i_fw = r_fw = 1 + prec + exp_field; |
|
669 if (inf_or_nan && i_fw < 3) |
|
670 i_fw = r_fw = 3; |
|
671 r_fw += sign; |
|
672 |
|
673 if (print_big_e) |
|
674 { |
|
675 sprintf (r_fmt_buf, "%%%d.%dE", r_fw, prec - 1); |
|
676 sprintf (i_fmt_buf, "%%%d.%dE", i_fw, prec - 1); |
|
677 } |
|
678 else |
|
679 { |
|
680 sprintf (r_fmt_buf, "%%%d.%de", r_fw, prec - 1); |
|
681 sprintf (i_fmt_buf, "%%%d.%de", i_fw, prec - 1); |
|
682 } |
|
683 } |
|
684 else |
|
685 { |
|
686 sprintf (r_fmt_buf, "%%%d.%df", r_fw, rd); |
|
687 sprintf (i_fmt_buf, "%%%d.%df", i_fw, rd); |
|
688 } |
|
689 |
|
690 curr_real_fmt = &r_fmt_buf[0]; |
|
691 curr_imag_fmt = &i_fmt_buf[0]; |
|
692 } |
|
693 |
|
694 static int |
164
|
695 all_elements_are_ints (const Range& r) |
1
|
696 { |
1282
|
697 // If the base and increment are ints, the final value in the range |
|
698 // will also be an integer, even if the limit is not. |
1
|
699 |
|
700 double b = r.base (); |
|
701 double i = r.inc (); |
|
702 |
1086
|
703 return (! (xisnan (b) || xisnan (i)) |
|
704 && (double) NINT (b) == b && (double) NINT (i) == i); |
1
|
705 } |
|
706 |
|
707 static inline void |
164
|
708 set_format (const ComplexMatrix& cm) |
1
|
709 { |
|
710 int r_fw, i_fw; |
|
711 set_format (cm, r_fw, i_fw); |
|
712 } |
|
713 |
|
714 static void |
164
|
715 set_format (const Range& r, int& fw) |
1
|
716 { |
529
|
717 curr_real_fmt = 0; |
|
718 curr_imag_fmt = 0; |
1
|
719 |
|
720 if (free_format) |
|
721 return; |
|
722 |
278
|
723 static char fmt_buf[128]; |
1
|
724 |
|
725 double r_min = r.base (); |
|
726 double r_max = r.limit (); |
|
727 |
|
728 if (r_max < r_min) |
|
729 { |
|
730 double tmp = r_max; |
|
731 r_max = r_min; |
|
732 r_min = tmp; |
|
733 } |
|
734 |
|
735 int sign = (r_min < 0.0); |
|
736 |
|
737 double max_abs = r_max < 0.0 ? -r_max : r_max; |
|
738 double min_abs = r_min < 0.0 ? -r_min : r_min; |
|
739 |
|
740 int x_max = max_abs == 0.0 ? 0 : (int) floor (log10 (max_abs) + 1.0); |
|
741 int x_min = min_abs == 0.0 ? 0 : (int) floor (log10 (min_abs) + 1.0); |
|
742 |
|
743 int prec = user_pref.output_precision; |
|
744 |
|
745 int ld, rd; |
|
746 |
|
747 if (bank_format) |
|
748 { |
|
749 int digits = x_max > x_min ? x_max : x_min; |
|
750 fw = sign + digits < 0 ? 4 : digits + 3; |
|
751 rd = 2; |
|
752 } |
1282
|
753 else if (hex_format) |
|
754 { |
|
755 fw = 2 * sizeof (double); |
|
756 rd = 0; |
|
757 } |
1
|
758 else if (all_elements_are_ints (r)) |
|
759 { |
|
760 int digits = x_max > x_min ? x_max : x_min; |
|
761 fw = sign + digits; |
|
762 rd = 0; |
|
763 } |
|
764 else |
|
765 { |
|
766 int ld_max, rd_max; |
|
767 if (x_max > 0) |
|
768 { |
|
769 ld_max = x_max; |
|
770 rd_max = prec - x_max; |
|
771 x_max++; |
|
772 } |
|
773 else |
|
774 { |
|
775 ld_max = 1; |
|
776 rd_max = prec - x_max; |
|
777 x_max = -x_max + 1; |
|
778 } |
|
779 |
|
780 int ld_min, rd_min; |
|
781 if (x_min > 0) |
|
782 { |
|
783 ld_min = x_min; |
|
784 rd_min = prec - x_min; |
|
785 x_min++; |
|
786 } |
|
787 else |
|
788 { |
|
789 ld_min = 1; |
|
790 rd_min = prec - x_min; |
|
791 x_min = -x_min + 1; |
|
792 } |
|
793 |
|
794 ld = ld_max > ld_min ? ld_max : ld_min; |
|
795 rd = rd_max > rd_min ? rd_max : rd_min; |
|
796 |
|
797 fw = sign + ld + 1 + rd; |
|
798 } |
|
799 |
1282
|
800 if (! (bank_format || hex_format) |
|
801 && (fw > user_pref.output_max_field_width || print_e)) |
1
|
802 { |
|
803 int exp_field = 4; |
|
804 if (x_max > 100 || x_min > 100) |
|
805 exp_field++; |
|
806 |
|
807 fw = sign + 2 + prec + exp_field; |
|
808 |
|
809 if (print_big_e) |
|
810 sprintf (fmt_buf, "%%%d.%dE", fw, prec - 1); |
|
811 else |
|
812 sprintf (fmt_buf, "%%%d.%de", fw, prec - 1); |
|
813 } |
|
814 else |
|
815 { |
|
816 sprintf (fmt_buf, "%%%d.%df", fw, rd); |
|
817 } |
|
818 |
|
819 curr_real_fmt = &fmt_buf[0]; |
|
820 } |
|
821 |
|
822 static inline void |
164
|
823 set_format (const Range& r) |
1
|
824 { |
|
825 int fw; |
|
826 set_format (r, fw); |
|
827 } |
|
828 |
1282
|
829 union equiv |
|
830 { |
|
831 double d; |
|
832 unsigned char i[sizeof (double)]; |
|
833 }; |
|
834 |
1
|
835 static inline void |
626
|
836 pr_any_float (const char *fmt, ostream& os, double d, int fw = 0) |
1
|
837 { |
|
838 if (d == -0.0) |
|
839 d = 0.0; |
|
840 |
529
|
841 if (fmt) |
1
|
842 { |
1282
|
843 if (hex_format) |
|
844 { |
|
845 equiv tmp; |
|
846 tmp.d = d; |
|
847 |
|
848 // Unless explicitly asked for, always print in big-endian |
|
849 // format. |
|
850 |
|
851 // XXX FIXME XXX -- is it correct to swap bytes for VAX |
|
852 // formats and not for Cray? |
|
853 |
|
854 if (hex_format > 1 |
|
855 || native_float_format == OCTAVE_IEEE_BIG |
|
856 || native_float_format == OCTAVE_CRAY |
|
857 || native_float_format == OCTAVE_UNKNOWN_FLT_FMT) |
|
858 { |
|
859 for (int i = 0; i < sizeof (double); i++) |
|
860 os.form ("%02x", (int) tmp.i[i]); |
|
861 } |
|
862 else |
|
863 { |
|
864 for (int i = sizeof (double) - 1; i >= 0; i--) |
|
865 os.form ("%02x", (int) tmp.i[i]); |
|
866 } |
|
867 } |
|
868 else if (xisinf (d)) |
1
|
869 { |
|
870 char *s; |
|
871 if (d < 0.0) |
|
872 s = "-Inf"; |
|
873 else |
|
874 s = "Inf"; |
|
875 |
|
876 if (fw > 0) |
|
877 os.form ("%*s", fw, s); |
|
878 else |
|
879 os << s; |
|
880 } |
|
881 else if (xisnan (d)) |
|
882 { |
|
883 if (fw > 0) |
|
884 os.form ("%*s", fw, "NaN"); |
|
885 else |
|
886 os << "NaN"; |
|
887 } |
|
888 else |
|
889 os.form (fmt, d); |
|
890 } |
529
|
891 else |
|
892 os << d; |
1
|
893 } |
|
894 |
|
895 static inline void |
626
|
896 pr_float (ostream& os, double d, int fw = 0) |
1
|
897 { |
|
898 pr_any_float (curr_real_fmt, os, d, fw); |
|
899 } |
|
900 |
|
901 static inline void |
626
|
902 pr_imag_float (ostream& os, double d, int fw = 0) |
1
|
903 { |
|
904 pr_any_float (curr_imag_fmt, os, d, fw); |
|
905 } |
|
906 |
|
907 static inline void |
626
|
908 pr_complex (ostream& os, const Complex& c, int r_fw = 0, int i_fw = 0) |
1
|
909 { |
|
910 double r = c.real (); |
|
911 pr_float (os, r, r_fw); |
|
912 if (! bank_format) |
|
913 { |
|
914 double i = c.imag (); |
1282
|
915 if (! hex_format && i < 0) |
1
|
916 { |
|
917 os << " - "; |
|
918 i = -i; |
|
919 pr_imag_float (os, i, i_fw); |
|
920 } |
|
921 else |
|
922 { |
1282
|
923 if (hex_format) |
|
924 os << " "; |
|
925 else |
|
926 os << " + "; |
|
927 |
1
|
928 pr_imag_float (os, i, i_fw); |
|
929 } |
|
930 os << "i"; |
|
931 } |
|
932 } |
|
933 |
626
|
934 static void |
|
935 print_empty_matrix (ostream& os, int nr, int nc, int pr_as_read_syntax) |
|
936 { |
|
937 assert (nr == 0 || nc == 0); |
|
938 |
|
939 if (pr_as_read_syntax) |
|
940 { |
|
941 if (nr == 0 && nc == 0) |
|
942 os << "[]"; |
|
943 else |
|
944 os << "zeros (" << nr << ", " << nc << ")"; |
|
945 } |
|
946 else |
|
947 { |
|
948 os << "[]"; |
|
949 if (user_pref.print_empty_dimensions) |
|
950 os << "(" << nr << "x" << nc << ")"; |
|
951 os << "\n"; |
|
952 } |
|
953 } |
|
954 |
1186
|
955 static void |
|
956 pr_col_num_header (ostream& os, int total_width, int max_width, |
|
957 int lim, int col) |
|
958 { |
|
959 if (total_width > max_width && user_pref.split_long_rows) |
|
960 { |
|
961 if (col != 0 && ! compact_format) |
|
962 os << "\n"; |
|
963 |
|
964 int num_cols = lim - col; |
|
965 |
|
966 if (num_cols == 1) |
|
967 os << " Column " << col + 1 << ":\n"; |
|
968 else if (num_cols == 2) |
|
969 os << " Columns " << col + 1 << " and " << lim << ":\n"; |
|
970 else |
|
971 os << " Columns " << col + 1 << " through " << lim << ":\n"; |
|
972 |
|
973 if (! compact_format) |
|
974 os << "\n"; |
|
975 } |
|
976 } |
|
977 |
1
|
978 void |
719
|
979 octave_print_internal (ostream& os, double d, int pr_as_read_syntax) |
1
|
980 { |
|
981 if (plus_format) |
|
982 { |
|
983 if (d == 0.0) |
|
984 os << " "; |
|
985 else |
|
986 os << "+"; |
|
987 } |
|
988 else |
|
989 { |
|
990 set_format (d); |
|
991 if (free_format) |
|
992 os << d; |
|
993 else |
|
994 pr_float (os, d); |
|
995 } |
626
|
996 |
|
997 if (! pr_as_read_syntax) |
|
998 os << "\n"; |
1
|
999 } |
|
1000 |
|
1001 void |
719
|
1002 octave_print_internal (ostream& os, const Matrix& m, int pr_as_read_syntax) |
1
|
1003 { |
|
1004 int nr = m.rows (); |
|
1005 int nc = m.columns (); |
|
1006 |
626
|
1007 if (nr == 0 || nc == 0) |
|
1008 print_empty_matrix (os, nr, nc, pr_as_read_syntax); |
|
1009 else if (plus_format && ! pr_as_read_syntax) |
1
|
1010 { |
|
1011 for (int i = 0; i < nr; i++) |
|
1012 { |
|
1013 for (int j = 0; j < nc; j++) |
|
1014 { |
|
1015 if (j == 0) |
|
1016 os << " "; |
|
1017 |
|
1018 if (m.elem (i, j) == 0.0) |
|
1019 os << " "; |
|
1020 else |
|
1021 os << "+"; |
|
1022 } |
|
1023 os << "\n"; |
|
1024 } |
|
1025 } |
|
1026 else |
|
1027 { |
|
1028 int fw; |
|
1029 set_format (m, fw); |
|
1030 int column_width = fw + 2; |
|
1031 int total_width = nc * column_width; |
|
1032 int max_width = terminal_columns (); |
|
1033 |
626
|
1034 if (pr_as_read_syntax) |
|
1035 max_width -= 4; |
|
1036 |
1
|
1037 if (free_format) |
|
1038 { |
626
|
1039 if (pr_as_read_syntax) |
|
1040 os << "[\n"; |
|
1041 |
1
|
1042 os << m; |
626
|
1043 |
|
1044 if (pr_as_read_syntax) |
|
1045 os << "]"; |
|
1046 |
1
|
1047 return; |
|
1048 } |
|
1049 |
|
1050 int inc = nc; |
|
1051 if (total_width > max_width && user_pref.split_long_rows) |
|
1052 { |
|
1053 inc = max_width / column_width; |
|
1054 if (inc == 0) |
|
1055 inc++; |
|
1056 } |
|
1057 |
626
|
1058 if (pr_as_read_syntax) |
1
|
1059 { |
|
1060 for (int i = 0; i < nr; i++) |
|
1061 { |
626
|
1062 int col = 0; |
|
1063 while (col < nc) |
1
|
1064 { |
626
|
1065 int lim = col + inc < nc ? col + inc : nc; |
|
1066 |
|
1067 for (int j = col; j < lim; j++) |
|
1068 { |
|
1069 if (i == 0 && j == 0) |
|
1070 os << "[ "; |
|
1071 else |
|
1072 { |
|
1073 if (j > col && j < lim) |
|
1074 os << ", "; |
|
1075 else |
|
1076 os << " "; |
|
1077 } |
|
1078 |
|
1079 pr_float (os, m.elem (i, j)); |
|
1080 } |
|
1081 |
|
1082 col += inc; |
|
1083 |
|
1084 if (col >= nc) |
|
1085 { |
|
1086 if (i == nr - 1) |
|
1087 os << " ]"; |
|
1088 else |
|
1089 os << ";\n"; |
|
1090 } |
|
1091 else |
|
1092 os << " ...\n"; |
1
|
1093 } |
|
1094 } |
626
|
1095 } |
|
1096 else |
|
1097 { |
|
1098 for (int col = 0; col < nc; col += inc) |
|
1099 { |
|
1100 int lim = col + inc < nc ? col + inc : nc; |
|
1101 |
1186
|
1102 pr_col_num_header (os, total_width, max_width, lim, col); |
626
|
1103 |
|
1104 for (int i = 0; i < nr; i++) |
|
1105 { |
|
1106 for (int j = col; j < lim; j++) |
|
1107 { |
|
1108 os << " "; |
|
1109 |
|
1110 pr_float (os, m.elem (i, j), fw); |
|
1111 } |
|
1112 |
|
1113 os << "\n"; |
|
1114 } |
|
1115 } |
1
|
1116 } |
|
1117 } |
|
1118 } |
|
1119 |
|
1120 void |
626
|
1121 octave_print_internal (ostream& os, const Complex& c, |
|
1122 int pr_as_read_syntax) |
1
|
1123 { |
|
1124 if (plus_format) |
|
1125 { |
|
1126 if (c == 0.0) |
|
1127 os << " "; |
|
1128 else |
|
1129 os << "+"; |
|
1130 } |
|
1131 else |
|
1132 { |
|
1133 set_format (c); |
|
1134 if (free_format) |
|
1135 os << c; |
|
1136 else |
|
1137 pr_complex (os, c); |
|
1138 } |
626
|
1139 |
|
1140 if (! pr_as_read_syntax) |
|
1141 os << "\n"; |
1
|
1142 } |
|
1143 |
|
1144 void |
626
|
1145 octave_print_internal (ostream& os, const ComplexMatrix& cm, |
|
1146 int pr_as_read_syntax) |
1
|
1147 { |
|
1148 int nr = cm.rows (); |
|
1149 int nc = cm.columns (); |
|
1150 |
626
|
1151 if (nr == 0 || nc == 0) |
|
1152 print_empty_matrix (os, nr, nc, pr_as_read_syntax); |
|
1153 else if (plus_format && ! pr_as_read_syntax) |
1
|
1154 { |
|
1155 for (int i = 0; i < nr; i++) |
|
1156 { |
|
1157 for (int j = 0; j < nc; j++) |
|
1158 { |
|
1159 if (j == 0) |
|
1160 os << " "; |
|
1161 |
|
1162 if (cm.elem (i, j) == 0.0) |
|
1163 os << " "; |
|
1164 else |
|
1165 os << "+"; |
|
1166 } |
|
1167 os << "\n"; |
|
1168 } |
|
1169 } |
|
1170 else |
|
1171 { |
|
1172 int r_fw, i_fw; |
|
1173 set_format (cm, r_fw, i_fw); |
|
1174 int column_width = i_fw + r_fw; |
1282
|
1175 column_width += (bank_format || hex_format) ? 2 : 7; |
1
|
1176 int total_width = nc * column_width; |
|
1177 int max_width = terminal_columns (); |
|
1178 |
626
|
1179 if (pr_as_read_syntax) |
|
1180 max_width -= 4; |
|
1181 |
1
|
1182 if (free_format) |
|
1183 { |
626
|
1184 if (pr_as_read_syntax) |
|
1185 os << "[\n"; |
|
1186 |
1
|
1187 os << cm; |
626
|
1188 |
|
1189 if (pr_as_read_syntax) |
|
1190 os << "]"; |
|
1191 |
1
|
1192 return; |
|
1193 } |
|
1194 |
|
1195 int inc = nc; |
|
1196 if (total_width > max_width && user_pref.split_long_rows) |
|
1197 { |
|
1198 inc = max_width / column_width; |
|
1199 if (inc == 0) |
|
1200 inc++; |
|
1201 } |
|
1202 |
626
|
1203 if (pr_as_read_syntax) |
1
|
1204 { |
|
1205 for (int i = 0; i < nr; i++) |
|
1206 { |
626
|
1207 int col = 0; |
|
1208 while (col < nc) |
1
|
1209 { |
626
|
1210 int lim = col + inc < nc ? col + inc : nc; |
|
1211 |
|
1212 for (int j = col; j < lim; j++) |
|
1213 { |
|
1214 if (i == 0 && j == 0) |
|
1215 os << "[ "; |
|
1216 else |
|
1217 { |
|
1218 if (j > col && j < lim) |
|
1219 os << ", "; |
|
1220 else |
|
1221 os << " "; |
|
1222 } |
|
1223 |
|
1224 pr_complex (os, cm.elem (i, j)); |
|
1225 } |
|
1226 |
|
1227 col += inc; |
|
1228 |
|
1229 if (col >= nc) |
|
1230 { |
|
1231 if (i == nr - 1) |
|
1232 os << " ]"; |
|
1233 else |
|
1234 os << ";\n"; |
|
1235 } |
1
|
1236 else |
626
|
1237 os << " ...\n"; |
1
|
1238 } |
|
1239 } |
626
|
1240 } |
|
1241 else |
|
1242 { |
|
1243 for (int col = 0; col < nc; col += inc) |
|
1244 { |
|
1245 int lim = col + inc < nc ? col + inc : nc; |
|
1246 |
1186
|
1247 pr_col_num_header (os, total_width, max_width, lim, col); |
626
|
1248 |
|
1249 for (int i = 0; i < nr; i++) |
|
1250 { |
|
1251 for (int j = col; j < lim; j++) |
|
1252 { |
|
1253 os << " "; |
|
1254 |
|
1255 pr_complex (os, cm.elem (i, j)); |
|
1256 } |
|
1257 os << "\n"; |
|
1258 } |
|
1259 } |
1
|
1260 } |
|
1261 } |
|
1262 } |
|
1263 |
|
1264 void |
626
|
1265 octave_print_internal (ostream& os, const Range& r, |
|
1266 int pr_as_read_syntax) |
1
|
1267 { |
626
|
1268 double base = r.base (); |
1
|
1269 double increment = r.inc (); |
626
|
1270 double limit = r.limit (); |
1
|
1271 int num_elem = r.nelem (); |
|
1272 |
626
|
1273 if (plus_format && ! pr_as_read_syntax) |
1
|
1274 { |
|
1275 os << " "; |
|
1276 for (int i = 0; i < num_elem; i++) |
|
1277 { |
626
|
1278 double val = base + i * increment; |
1
|
1279 if (val == 0.0) |
|
1280 os << " "; |
|
1281 else |
|
1282 os << "+"; |
|
1283 } |
|
1284 } |
|
1285 else |
|
1286 { |
|
1287 int fw; |
|
1288 set_format (r, fw); |
|
1289 |
626
|
1290 if (pr_as_read_syntax) |
1
|
1291 { |
626
|
1292 |
|
1293 if (free_format) |
|
1294 { |
|
1295 os << base << " : "; |
|
1296 if (increment != 1.0) |
|
1297 os << increment << " : "; |
|
1298 os << limit; |
|
1299 } |
|
1300 else |
|
1301 { |
|
1302 pr_float (os, base, fw); |
|
1303 os << " : "; |
|
1304 if (increment != 1.0) |
|
1305 { |
|
1306 pr_float (os, increment, fw); |
|
1307 os << " : "; |
|
1308 } |
|
1309 pr_float (os, limit, fw); |
|
1310 } |
1
|
1311 } |
626
|
1312 else |
|
1313 { |
|
1314 int column_width = fw + 2; |
|
1315 int total_width = num_elem * column_width; |
|
1316 int max_width = terminal_columns (); |
1
|
1317 |
626
|
1318 if (free_format) |
|
1319 { |
|
1320 os << r; |
|
1321 return; |
|
1322 } |
1
|
1323 |
626
|
1324 int inc = num_elem; |
1
|
1325 if (total_width > max_width && user_pref.split_long_rows) |
|
1326 { |
626
|
1327 inc = max_width / column_width; |
|
1328 if (inc == 0) |
|
1329 inc++; |
1
|
1330 } |
|
1331 |
626
|
1332 int col = 0; |
|
1333 while (col < num_elem) |
1
|
1334 { |
626
|
1335 int lim = col + inc < num_elem ? col + inc : num_elem; |
|
1336 |
1186
|
1337 pr_col_num_header (os, total_width, max_width, lim, col); |
626
|
1338 |
|
1339 for (int i = col; i < lim; i++) |
|
1340 { |
|
1341 double val = base + i * increment; |
|
1342 os << " "; |
|
1343 pr_float (os, val, fw); |
|
1344 } |
|
1345 |
|
1346 os << "\n"; |
|
1347 |
|
1348 col += inc; |
1
|
1349 } |
|
1350 } |
|
1351 } |
|
1352 } |
|
1353 |
712
|
1354 DEFUN ("disp", Fdisp, Sdisp, 1, 1, |
529
|
1355 "disp (X): display value without name tag") |
|
1356 { |
|
1357 Octave_object retval; |
|
1358 |
|
1359 int nargin = args.length (); |
|
1360 |
712
|
1361 if (nargin == 1) |
|
1362 args(0).eval (1); |
529
|
1363 else |
|
1364 print_usage ("disp"); |
|
1365 |
|
1366 return retval; |
|
1367 } |
|
1368 |
1
|
1369 static void |
|
1370 init_format_state (void) |
|
1371 { |
|
1372 free_format = 0; |
|
1373 plus_format = 0; |
|
1374 bank_format = 0; |
1282
|
1375 hex_format = 0; |
1
|
1376 print_e = 0; |
|
1377 print_big_e = 0; |
|
1378 } |
|
1379 |
|
1380 static void |
|
1381 set_output_prec_and_fw (int prec, int fw) |
|
1382 { |
529
|
1383 tree_constant *tmp = 0; |
1
|
1384 |
|
1385 tmp = new tree_constant ((double) prec); |
195
|
1386 bind_builtin_variable ("output_precision", tmp); |
1
|
1387 |
|
1388 tmp = new tree_constant ((double) fw); |
195
|
1389 bind_builtin_variable ("output_max_field_width", tmp); |
1
|
1390 } |
|
1391 |
|
1392 void |
|
1393 set_format_style (int argc, char **argv) |
|
1394 { |
|
1395 if (--argc > 0) |
|
1396 { |
|
1397 argv++; |
|
1398 if (*argv[0]) |
|
1399 { |
|
1400 if (strcmp (*argv, "short") == 0) |
|
1401 { |
|
1402 if (--argc > 0) |
|
1403 { |
|
1404 argv++; |
|
1405 if (strcmp (*argv, "e") == 0) |
|
1406 { |
|
1407 init_format_state (); |
|
1408 print_e = 1; |
|
1409 } |
|
1410 else if (strcmp (*argv, "E") == 0) |
|
1411 { |
|
1412 init_format_state (); |
|
1413 print_e = 1; |
|
1414 print_big_e = 1; |
|
1415 } |
|
1416 else |
|
1417 { |
217
|
1418 error ("format: unrecognized option `short %s'", *argv); |
1
|
1419 return; |
|
1420 } |
|
1421 } |
|
1422 else |
|
1423 init_format_state (); |
|
1424 |
|
1425 set_output_prec_and_fw (3, 8); |
|
1426 } |
|
1427 else if (strcmp (*argv, "long") == 0) |
|
1428 { |
|
1429 if (--argc > 0) |
|
1430 { |
|
1431 argv++; |
|
1432 if (strcmp (*argv, "e") == 0) |
|
1433 { |
|
1434 init_format_state (); |
|
1435 print_e = 1; |
|
1436 } |
|
1437 else if (strcmp (*argv, "E") == 0) |
|
1438 { |
|
1439 init_format_state (); |
|
1440 print_e = 1; |
|
1441 print_big_e = 1; |
|
1442 } |
|
1443 else |
|
1444 { |
217
|
1445 error ("format: unrecognized option `long %s'", *argv); |
1
|
1446 return; |
|
1447 } |
|
1448 } |
|
1449 else |
|
1450 init_format_state (); |
|
1451 |
|
1452 set_output_prec_and_fw (15, 24); |
|
1453 } |
|
1454 else if (strcmp (*argv, "hex") == 0) |
1282
|
1455 { |
|
1456 init_format_state (); |
|
1457 hex_format = 1; |
|
1458 } |
|
1459 else if (strcmp (*argv, "native-hex") == 0) |
|
1460 { |
|
1461 init_format_state (); |
|
1462 hex_format = 2; |
|
1463 } |
|
1464 else if (strcmp (*argv, "+") == 0 || strcmp (*argv, "plus") == 0) |
1
|
1465 { |
|
1466 init_format_state (); |
|
1467 plus_format = 1; |
|
1468 } |
|
1469 else if (strcmp (*argv, "bank") == 0) |
|
1470 { |
|
1471 init_format_state (); |
|
1472 bank_format = 1; |
|
1473 } |
|
1474 else if (strcmp (*argv, "free") == 0) |
|
1475 { |
|
1476 init_format_state (); |
|
1477 free_format = 1; |
|
1478 } |
|
1479 else if (strcmp (*argv, "none") == 0) |
|
1480 { |
|
1481 init_format_state (); |
|
1482 free_format = 1; |
|
1483 } |
|
1484 else if (strcmp (*argv, "compact") == 0) |
1186
|
1485 { |
|
1486 compact_format = 1; |
|
1487 } |
1
|
1488 else if (strcmp (*argv, "loose") == 0) |
1186
|
1489 { |
|
1490 compact_format = 0; |
|
1491 } |
1
|
1492 else |
217
|
1493 error ("format: unrecognized format state `%s'", *argv); |
1
|
1494 } |
|
1495 else |
|
1496 usage ("format [format_state]"); |
|
1497 } |
|
1498 else |
|
1499 { |
|
1500 init_format_state (); |
|
1501 set_output_prec_and_fw (5, 10); |
|
1502 } |
|
1503 } |
|
1504 |
529
|
1505 DEFUN_TEXT ("format", Fformat, Sformat, -1, 1, |
|
1506 "format [style]\n\ |
|
1507 \n\ |
|
1508 set output formatting style") |
|
1509 { |
|
1510 Octave_object retval; |
|
1511 |
|
1512 DEFINE_ARGV("format"); |
|
1513 |
|
1514 set_format_style (argc, argv); |
|
1515 |
|
1516 DELETE_ARGV; |
|
1517 |
|
1518 return retval; |
|
1519 } |
|
1520 |
1
|
1521 /* |
|
1522 ;;; Local Variables: *** |
|
1523 ;;; mode: C++ *** |
|
1524 ;;; page-delimiter: "^/\\*" *** |
|
1525 ;;; End: *** |
|
1526 */ |