comparison src/pr-output.cc @ 5794:1138ced03f14

[project @ 2006-05-08 20:23:04 by jwe]
author jwe
date Mon, 08 May 2006 20:23:07 +0000
parents ace8d8d26933
children 080c08b192d8
comparison
equal deleted inserted replaced
5793:395382df0d8a 5794:1138ced03f14
58 #include "utils.h" 58 #include "utils.h"
59 #include "variables.h" 59 #include "variables.h"
60 60
61 // TRUE means use a scaled fixed point format for `format long' and 61 // TRUE means use a scaled fixed point format for `format long' and
62 // `format short'. 62 // `format short'.
63 static bool Vfixed_point_format; 63 static bool Vfixed_point_format = false;
64 64
65 // The maximum field width for a number printed by the default output 65 // The maximum field width for a number printed by the default output
66 // routines. 66 // routines.
67 static int Voutput_max_field_width; 67 static int Voutput_max_field_width = 10;
68 68
69 // The precision of the numbers printed by the default output 69 // The precision of the numbers printed by the default output
70 // routines. 70 // routines.
71 static int Voutput_precision; 71 static int Voutput_precision = 5;
72 72
73 // TRUE means that the dimensions of empty objects should be printed 73 // TRUE means that the dimensions of empty objects should be printed
74 // like this: x = [](2x0). 74 // like this: x = [](2x0).
75 bool Vprint_empty_dimensions; 75 bool Vprint_empty_dimensions = true;
76 76
77 // TRUE means that the rows of big matrices should be split into 77 // TRUE means that the rows of big matrices should be split into
78 // smaller slices that fit on the screen. 78 // smaller slices that fit on the screen.
79 static bool Vsplit_long_rows; 79 static bool Vsplit_long_rows = true;
80 80
81 // How many levels of structure elements should we print? 81 // How many levels of structure elements should we print?
82 int Vstruct_levels_to_print; 82 int Vstruct_levels_to_print = 2;
83 83
84 // TRUE means don't do any fancy formatting. 84 // TRUE means don't do any fancy formatting.
85 static bool free_format = false; 85 static bool free_format = false;
86 86
87 // TRUE means print plus sign for nonzero, blank for zero. 87 // TRUE means print plus sign for nonzero, blank for zero.
2605 } 2605 }
2606 2606
2607 static void 2607 static void
2608 set_output_prec_and_fw (int prec, int fw) 2608 set_output_prec_and_fw (int prec, int fw)
2609 { 2609 {
2610 bind_builtin_variable ("output_precision", prec); 2610 Voutput_precision = prec;
2611 bind_builtin_variable ("output_max_field_width", fw); 2611 Voutput_max_field_width = fw;
2612 } 2612 }
2613 2613
2614 static void 2614 static void
2615 set_format_style (int argc, const string_vector& argv) 2615 set_format_style (int argc, const string_vector& argv)
2616 { 2616 {
2942 set_format_style (argc, argv); 2942 set_format_style (argc, argv);
2943 2943
2944 return retval; 2944 return retval;
2945 } 2945 }
2946 2946
2947 static int 2947 DEFUN (fixed_point_format, args, nargout,
2948 fixed_point_format (void) 2948 "-*- texinfo -*-\n\
2949 { 2949 @deftypefn {Built-in Function} {@var{val} =} fixed_point_format ()\n\
2950 Vfixed_point_format = check_preference ("fixed_point_format"); 2950 @deftypefnx {Built-in Function} {@var{old_val} =} fixed_point_format (@var{new_val})\n\
2951 2951 Query or set the internal variable that controls whether Octave will\n\
2952 return 0; 2952 use a scaled format to print matrix values such that the largest\n\
2953 } 2953 element may be written with a single leading digit with the scaling\n\
2954 2954 factor is printed on the first line of output. For example,\n\
2955 static int
2956 output_max_field_width (void)
2957 {
2958 double val;
2959 if (builtin_real_scalar_variable ("output_max_field_width", val)
2960 && ! xisnan (val))
2961 {
2962 int ival = NINT (val);
2963 if (ival > 0 && ival == val)
2964 {
2965 Voutput_max_field_width = ival;
2966 return 0;
2967 }
2968 }
2969 gripe_invalid_value_specified ("output_max_field_width");
2970 return -1;
2971 }
2972
2973 static int
2974 output_precision (void)
2975 {
2976 double val;
2977 if (builtin_real_scalar_variable ("output_precision", val)
2978 && ! xisnan (val))
2979 {
2980 int ival = NINT (val);
2981 if (ival >= 0 && ival == val)
2982 {
2983 Voutput_precision = ival;
2984 return 0;
2985 }
2986 }
2987 gripe_invalid_value_specified ("output_precision");
2988 return -1;
2989 }
2990
2991 static int
2992 print_empty_dimensions (void)
2993 {
2994 Vprint_empty_dimensions = check_preference ("print_empty_dimensions");
2995
2996 return 0;
2997 }
2998
2999 static int
3000 split_long_rows (void)
3001 {
3002 Vsplit_long_rows = check_preference ("split_long_rows");
3003
3004 return 0;
3005 }
3006
3007 static int
3008 struct_levels_to_print (void)
3009 {
3010 double val;
3011 if (builtin_real_scalar_variable ("struct_levels_to_print", val)
3012 && ! xisnan (val))
3013 {
3014 int ival = NINT (val);
3015 if (ival == val)
3016 {
3017 Vstruct_levels_to_print = ival;
3018 return 0;
3019 }
3020 }
3021 gripe_invalid_value_specified ("struct_levels_to_print");
3022 return -1;
3023 }
3024
3025 void
3026 symbols_of_pr_output (void)
3027 {
3028 DEFVAR (fixed_point_format, false, fixed_point_format,
3029 "-*- texinfo -*-\n\
3030 @defvr {Built-in Variable} fixed_point_format\n\
3031 If the value of this variable is nonzero, Octave will scale all values\n\
3032 in a matrix so that the largest may be written with one leading digit.\n\
3033 The scaling factor is printed on the first line of output. For example,\n\
3034 \n\ 2955 \n\
3035 @example\n\ 2956 @example\n\
3036 @group\n\ 2957 @group\n\
3037 octave:1> logspace (1, 7, 5)'\n\ 2958 octave:1> logspace (1, 7, 5)'\n\
3038 ans =\n\ 2959 ans =\n\
3049 \n\ 2970 \n\
3050 @noindent\n\ 2971 @noindent\n\
3051 Notice that first value appears to be zero when it is actually 1. For\n\ 2972 Notice that first value appears to be zero when it is actually 1. For\n\
3052 this reason, you should be careful when setting\n\ 2973 this reason, you should be careful when setting\n\
3053 @code{fixed_point_format} to a nonzero value.\n\ 2974 @code{fixed_point_format} to a nonzero value.\n\
3054 \n\ 2975 @end deftypefn")
3055 The default value of @code{fixed_point_format} is 0.\n\ 2976 {
3056 @end defvr"); 2977 return SET_INTERNAL_VARIABLE (fixed_point_format);
3057 2978 }
3058 DEFVAR (output_max_field_width, 10.0, output_max_field_width, 2979
3059 "-*- texinfo -*-\n\ 2980 DEFUN (print_empty_dimensions, args, nargout,
3060 @defvr {Built-in Variable} output_max_field_width\n\ 2981 "-*- texinfo -*-\n\
3061 This variable specifies the maximum width of a numeric output field.\n\ 2982 @deftypefn {Built-in Function} {@var{val} =} print_empty_dimensions ()\n\
3062 The default value is 10.\n\ 2983 @deftypefnx {Built-in Function} {@var{old_val} =} print_empty_dimensions (@var{new_val})\n\
3063 @end defvr"); 2984 Query or set the internal varaible that controls whether the\n\
3064
3065 DEFVAR (output_precision, 5.0, output_precision,
3066 "-*- texinfo -*-\n\
3067 @defvr {Built-in Variable} output_precision\n\
3068 This variable specifies the minimum number of significant figures to\n\
3069 display for numeric output. The default value is 5.\n\
3070 @end defvr");
3071
3072 DEFVAR (print_empty_dimensions, true, print_empty_dimensions,
3073 "-*- texinfo -*-\n\
3074 @defvr {Built-in Variable} print_empty_dimensions\n\
3075 If the value of @code{print_empty_dimensions} is nonzero, the\n\
3076 dimensions of empty matrices are printed along with the empty matrix\n\ 2985 dimensions of empty matrices are printed along with the empty matrix\n\
3077 symbol, @samp{[]}. For example, the expression\n\ 2986 symbol, @samp{[]}. For example, the expression\n\
3078 \n\ 2987 \n\
3079 @example\n\ 2988 @example\n\
3080 zeros (3, 0)\n\ 2989 zeros (3, 0)\n\
3084 will print\n\ 2993 will print\n\
3085 \n\ 2994 \n\
3086 @example\n\ 2995 @example\n\
3087 ans = [](3x0)\n\ 2996 ans = [](3x0)\n\
3088 @end example\n\ 2997 @end example\n\
3089 @end defvr"); 2998 @end deftypefn")
3090 2999 {
3091 DEFVAR (split_long_rows, true, split_long_rows, 3000 return SET_INTERNAL_VARIABLE (print_empty_dimensions);
3092 "-*- texinfo -*-\n\ 3001 }
3093 @defvr {Built-in Variable} split_long_rows\n\ 3002
3094 For large matrices, Octave may not be able to display all the columns of\n\ 3003 DEFUN (split_long_rows, args, nargout,
3095 a given row on one line of your screen. This can result in missing\n\ 3004 "-*- texinfo -*-\n\
3096 information or output that is nearly impossible to decipher, depending\n\ 3005 @deftypefn {Built-in Function} {@var{val} =} split_long_rows ()\n\
3097 on whether your terminal truncates or wraps long lines.\n\ 3006 @deftypefnx {Built-in Function} {@var{old_val} =} split_long_rows (@var{new_val})\n\
3098 \n\ 3007 Query or set the internal variable that controls whether rows of a matrix\n\
3099 If the value of @code{split_long_rows} is nonzero, Octave will display\n\ 3008 may be split when displayed to a terminal window. If the rows are split,\n\
3100 the matrix in a series of smaller pieces, each of which can fit within\n\ 3009 Octave will display the matrix in a series of smaller pieces, each of\n\
3101 the limits of your terminal width. Each set of rows is labeled so that\n\ 3010 which can fit within the limits of your terminal width and each set of\n\
3102 you can easily see which columns are currently being displayed.\n\ 3011 rows is labeled so that you can easily see which columns are currently\n\
3103 For example:\n\ 3012 being displayed. For example:\n\
3104 \n\ 3013 \n\
3105 @smallexample\n\ 3014 @smallexample\n\
3106 @group\n\ 3015 @group\n\
3107 octave:13> rand (2,10)\n\ 3016 octave:13> rand (2,10)\n\
3108 ans =\n\ 3017 ans =\n\
3116 \n\ 3025 \n\
3117 0.90174 0.11854 0.72313 0.73326\n\ 3026 0.90174 0.11854 0.72313 0.73326\n\
3118 0.44672 0.94303 0.56564 0.82150\n\ 3027 0.44672 0.94303 0.56564 0.82150\n\
3119 @end group\n\ 3028 @end group\n\
3120 @end smallexample\n\ 3029 @end smallexample\n\
3121 \n\ 3030 @end deftypefn")
3122 @noindent\n\ 3031 {
3123 The default value of @code{split_long_rows} is nonzero.\n\ 3032 return SET_INTERNAL_VARIABLE (split_long_rows);
3124 @end defvr"); 3033 }
3125 3034
3126 DEFVAR (struct_levels_to_print, 2.0, struct_levels_to_print, 3035 DEFUN (output_max_field_width, args, nargout,
3127 "-*- texinfo -*-\n\ 3036 "-*- texinfo -*-\n\
3128 @defvr {Built-in Variable} struct_levels_to_print\n\ 3037 @deftypefn {Built-in Function} {@var{val} =} output_max_field_width ()\n\
3129 You can tell Octave how many structure levels to display by setting the\n\ 3038 @deftypefnx {Built-in Function} {@var{old_val} =} output_max_field_width (@var{new_val})\n\
3130 built-in variable @code{struct_levels_to_print}. The default value is 2.\n\ 3039 Query or set the internal variable that specifies the maximum width\n\
3131 @end defvr"); 3040 of a numeric output field.\n\
3041 @seealso{format, output_precision}\n\
3042 @end deftypefn")
3043 {
3044 return SET_INTERNAL_VARIABLE_WITH_LIMITS (output_precision, 0, INT_MAX);
3045 }
3046
3047 DEFUN (output_precision, args, nargout,
3048 "-*- texinfo -*-\n\
3049 @deftypefn {Built-in Function} {@var{val} =} output_precision ()\n\
3050 @deftypefnx {Built-in Function} {@var{old_val} =} output_precision (@var{new_val})\n\
3051 Query or set the internal variable that specifies the minimum number of\n\
3052 significant figures to display for numeric output.\n\
3053 @seealso{format, output_max_field_width}\n\
3054 @end deftypefn")
3055 {
3056 return SET_INTERNAL_VARIABLE_WITH_LIMITS (output_precision, -1, INT_MAX);
3057 }
3058
3059 DEFUN (struct_levels_to_print, args, nargout,
3060 "-*- texinfo -*-\n\
3061 @deftypefn {Built-in Function} {@var{val} =} struct_levels_to_print ()\n\
3062 @deftypefnx {Built-in Function} {@var{old_val} =} struct_levels_to_print (@var{new_val})\n\
3063 Query or set the internal variable that specifies the number of\n\
3064 structure levels to display.\n\
3065 @end deftypefn")
3066 {
3067 return SET_INTERNAL_VARIABLE_WITH_LIMITS (struct_levels_to_print,
3068 -1, INT_MAX);
3132 } 3069 }
3133 3070
3134 /* 3071 /*
3135 ;;; Local Variables: *** 3072 ;;; Local Variables: ***
3136 ;;; mode: C++ *** 3073 ;;; mode: C++ ***