1 ## Copyright (C) 2008, Thomas Treichl <thomas.treichl@gmx.net>
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
17 ## @deftypefn {Function} {[@var{string}] =} asci ([@var{columns}])
20 ## If this function is called without any input argument and without any output
21 ## argument then print a nice ASCI-table (excluding special characters with
22 ## hexcode 0x00 to 0x20) on screen with four columns per default. If this
23 ## function is called with one output argument then return an ASCI-table string
24 ## and don't print anything on screen. Finally, if this function is called with
25 ## one input argument of type scalar then either print (no output argument) or
26 ## return (one output argument) an ASCI-table with a number of columns given in
36 function [varargout] = asci (varargin)
38 %# Check number and types of input arguments
41 elseif (isnumeric (varargin{1}) && \
42 isequal (size (varargin{1}), [1, 1]))
43 vcol = floor (varargin{1});
48 %# First char is #32 (0x20) and last char is #128 (0x80)
50 voff = floor ((128 - 32) / vcol);
52 %# Print a first row for the and underline that row
54 vtab = sprintf ("%s Dec Hex Chr ", vtab);
56 vtab = sprintf ("%s\n", vtab);
59 vtab = sprintf ("%s-------------", vtab);
61 vtab = sprintf ("%s\n", vtab);
63 %# Create the lines and columns of the asci table
64 for vpos = 32:(32+voff)
66 vact = (vcnt-1)*voff+vpos;
67 vstr = {num2str(vact), dec2hex(vact), char(vact)};
68 for vctn = 1:length (vstr)
69 vtab = sprintf ("%s %3s", vtab, vstr{vctn});
71 vtab = sprintf ("%s ", vtab);
73 vtab = sprintf ("%s\n", vtab);
75 vtab = sprintf ("%s\n", vtab);
77 %# Print table to screen or return it to output argument