]> Creatis software - CreaPhase.git/blob - octave_packages/dataframe-0.9.1/@dataframe/fold.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / dataframe-0.9.1 / @dataframe / fold.m
1 function resu = fold(df, dim, indr, indc)
2
3   %# function resu = subasgn(df, S, RHS)
4   %# The purpose is to fold a dataframe. Part from (1:indr-1) doesn't
5   %# move, then content starting at indr is moved into the second,
6   %# third, ... sheet. To be moved, there must be equality of rownames,
7   %# if any, and of fields contained in indc.
8
9
10   %% Copyright (C) 2009-2012 Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
11   %%
12   %% This file is part of Octave.
13   %%
14   %% Octave is free software; you can redistribute it and/or
15   %% modify it under the terms of the GNU General Public
16   %% License as published by the Free Software Foundation;
17   %% either version 2, or (at your option) any later version.
18   %%
19   %% Octave is distributed in the hope that it will be useful,
20   %% but WITHOUT ANY WARRANTY; without even the implied
21   %% warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
22   %% PURPOSE.  See the GNU General Public License for more
23   %% details.
24   %%
25   %% You should have received a copy of the GNU General Public
26   %% License along with Octave; see the file COPYING.  If not,
27   %% write to the Free Software Foundation, 51 Franklin Street -
28   %% Fifth Floor, Boston, MA 02110-1301, USA.
29   
30   %#
31   %# $Id: fold.m 9585 2012-02-05 15:32:46Z cdemills $
32   %#
33 switch dim
34   case 1
35     [indr, nrow] = df_name2idx(df._name{1}, indr, df._cnt(1), 'row');
36     [indc, ncol] = df_name2idx(df._name{2}, indc, df._cnt(2), 'column');
37     
38     if (indr(1) > 1),
39       slice_size = indr(1) - 1;
40       %# we can't use directly resu = df(1:slice_size, :, :)
41       S.type = '()';
42       S.subs = { 1:slice_size, ':', ':', 'dataframe'};
43       resu = subsref(df, S);
44       
45       %# how many columns for each slice
46       targets = cellfun(@length, df._rep);
47       %# a test function to determine if the location is free
48       for indj = 1:df._cnt(2),
49         if (any(indj == indc)),
50           continue;
51         endif
52         switch df._type{indj}
53           case { 'char' }
54             testfunc{indj} = @(x, indr, indc) ...
55                 !isna(x{indr, indc});
56           otherwise
57             testfunc{indj} = @(x, indr, indc) ...
58                 !isna(x(indr, indc));
59         endswitch
60       endfor
61
62       for indi = indr,
63         %# where does this line go ?
64         where = find(df._data{indc}(1:slice_size, 1) ...
65                      == df._data{indc}(indi, 1));
66         if (!isempty(where)),
67           %# transfering one line -- loop over columns
68           for indj = 1:df._cnt(2),
69             if any(indj == indc),
70               continue;
71             endif
72            
73             if (testfunc{indj}(resu._data{indj}, where, targets(indj))),
74               %# add one more sheet
75               resu = df_pad(resu, 3, 1, indj);
76               targets(indj) = targets(indj) + 1;
77             endif
78             %# transfer field
79             stop
80             resu._data{indj}(where, targets(indj)) = ...
81                 df._data{indj}(indi, 1);
82           endfor
83           %# update row index
84           resu._ridx(where, max(targets)) = df._ridx(indi);
85         else
86           disp('line 65: FIXME'); keyboard;
87         endif
88       endfor
89
90     else
91
92       disp('line 70: FIXME '); keyboard
93     endif
94
95
96 endswitch