]> Creatis software - CreaPhase.git/blob - octave_packages/dataframe-0.9.1/@dataframe/size.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / dataframe-0.9.1 / @dataframe / size.m
1 function varargout = size(df, varargin)
2   %# function resu = size(df, varargin)
3   %# This is size operator for a dataframe object.
4
5   %% Copyright (C) 2009-2012 Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
6   %%
7   %% This file is part of Octave.
8   %%
9   %% Octave is free software; you can redistribute it and/or
10   %% modify it under the terms of the GNU General Public
11   %% License as published by the Free Software Foundation;
12   %% either version 2, or (at your option) any later version.
13   %%
14   %% Octave is distributed in the hope that it will be useful,
15   %% but WITHOUT ANY WARRANTY; without even the implied
16   %% warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
17   %% PURPOSE.  See the GNU General Public License for more
18   %% details.
19   %%
20   %% You should have received a copy of the GNU General Public
21   %% License along with Octave; see the file COPYING.  If not,
22   %% write to the Free Software Foundation, 51 Franklin Street -
23   %% Fifth Floor, Boston, MA 02110-1301, USA.
24   
25   %#
26   %# $Id: size.m 9585 2012-02-05 15:32:46Z cdemills $
27   %#
28
29   switch nargin
30     case 1
31       switch nargout
32         case {0, 1}
33           varargout{1} = df._cnt;
34         case {2}
35           varargout{1} = df._cnt(1);
36           if (1 == df._cnt(2) && length(df._cnt) > 2),
37             varargout{2} = df._cnt(3);
38           else
39             varargout{2} = df._cnt(2);
40           endif
41         case {3}
42           varargout{1:2} = df._cnt(1:2);
43           if 2==length(df._cnt),
44             varargout{3} = 1;
45           else
46             varargout{3} = df._cnt(3);
47           endif
48         otherwise
49           error(print_usage());
50       endswitch
51     case 2
52       switch nargout
53         case {0 1}
54           varargout{1} = df._cnt;
55           try
56             varargout{1} = varargout{1}(varargin{1});
57           catch
58             error(print_usage());
59           end_try_catch
60         otherwise
61           error(print_usage());
62       endswitch
63     case 3
64       switch nargout
65         case {0 1}
66           if (length(df._cnt) < 3),
67             varargout{1} = 1;
68           else
69             varargout{1} = df._cnt;
70           endif
71           try
72             varargout{1} = varargout{1}(varargin{1});
73           catch
74             error(print_usage());
75           end_try_catch
76         otherwise
77           error(print_usage());
78       endswitch
79     otherwise
80       error(print_usage());
81   endswitch
82
83 endfunction
84
85 function usage = print_usage()
86   usage = strcat('Invalid call to size.  Correct usage is: ', ' ', ...
87                   '-- Overloaded Function:  size (A, N)');
88 endfunction