source: trunk/src/get_file_series.m @ 827

Last change on this file since 827 was 809, checked in by g7moreau, 10 years ago
  • Add license
File size: 7.4 KB
Line 
1%'get_file_series': determine the list of input file names and file indices for functions called by 'series'.
2%------------------------------------------------------------------------
3% [filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param)
4%
5% OUTPUT:
6% filecell{iview,fileindex}: cell array representing the list of file names
7%        iview: line in the table corresponding to a given file series
8%        fileindex: file index within  the file series,
9% i1_series{iview}(ref_j,ref_i)... are the corresponding arrays of indices i1,i2,j1,j2, depending on the input line iview and the two reference indices ref_i,ref_j
10% i1_series{iview}(fileindex) expresses the same indices as a 1D array in file indices
11%
12% INPUT:
13% Param: structure of input parameters as read from the GUI series (by the function read_GUI)
14
15%=======================================================================
16% Copyright 2008-2014, LEGI UMR 5519 / CNRS UJF G-INP, Grenoble, France
17%   http://www.legi.grenoble-inp.fr
18%   Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
19%
20%     This file is part of the toolbox UVMAT.
21%
22%     UVMAT is free software; you can redistribute it and/or modify
23%     it under the terms of the GNU General Public License as published
24%     by the Free Software Foundation; either version 2 of the license,
25%     or (at your option) any later version.
26%
27%     UVMAT is distributed in the hope that it will be useful,
28%     but WITHOUT ANY WARRANTY; without even the implied warranty of
29%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
30%     GNU General Public License (see LICENSE.txt) for more details.
31%=======================================================================
32
33function [filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param)
34
35filecell={};
36InputTable=Param.InputTable;
37first_i=Param.IndexRange.first_i;
38incr_i=Param.IndexRange.incr_i;
39last_i=Param.IndexRange.last_i;
40first_j=[];last_j=[];incr_j=1;%default
41if isfield(Param.IndexRange,'first_j')&& isfield(Param.IndexRange,'last_j')
42    first_j=Param.IndexRange.first_j;
43    last_j=Param.IndexRange.last_j;
44end
45if isfield(Param.IndexRange,'incr_j')
46    incr_j=Param.IndexRange.incr_j;
47end
48
49%% determine the list of input file names
50% nbmissing=0;
51NbView=size(InputTable,1);
52i1_series=cell(NbView,1);% initiate index series with empty cells
53i2_series=cell(NbView,1);
54j1_series=cell(NbView,1);
55j2_series=cell(NbView,1);
56for iview=1:NbView
57    r.mode='';
58    if isfield (Param.IndexRange,'PairString')
59        if ischar(Param.IndexRange.PairString)
60            Param.IndexRange.PairString={Param.IndexRange.PairString};
61        end
62        r=regexp(Param.IndexRange.PairString{iview,1},'(?<mode>(Di=)|(Dj=)) -*(?<num1>\d+)\|(?<num2>\d+)','names');%look for mode=Dj or Di
63        if isempty(r)
64            r=regexp(Param.IndexRange.PairString{iview,1},'(?<num1>\d+)(?<mode>-)(?<num2>\d+)','names');%look for burst pairs
65        end
66        % TODO case of free pairs:
67        %r=regexp(pair_string,'.*\D(?<num1>[\d+|*])(?<delim>[-||])(?<num2>[\d+|*])','names');
68    end
69    if isempty(r)||isempty(r.mode)
70        r(1).num1='';
71        r(1).num2='';
72        if isfield (Param.IndexRange,'PairString') && strcmp(Param.IndexRange.PairString{iview,1},'j=*-*')
73            r(1).mode='*-*';
74        else
75            r(1).mode='';
76        end
77    end
78   
79    if isempty(incr_i) || isempty(incr_j) || isequal(r(1).mode,'*-*')|| isequal(r(1).mode,'*|*')% free pairs or increment
80        FilePath=fullfile(InputTable{iview,1},InputTable{iview,2});
81        fileinput=[InputTable{iview,3} InputTable{iview,4} InputTable{iview,5}];
82        [tild,tild,tild,i1_series{iview},i2_series{iview},j1_series{iview},j2_series{iview},NomType,FileInfo,MovieObject,...
83            i1_input,i2_input,j1_input,j2_input]=find_file_series(FilePath,fileinput);
84        i1_series{iview}=squeeze(i1_series{iview}(1,:,:)); %select first  pair index as ordered by find_file_series
85        i2_series{iview}=squeeze(i2_series{iview}(1,:,:)); %select first  pair index as ordered by find_file_series
86        j1_series{iview}=squeeze(j1_series{iview}(1,:,:)); %first  pair index
87        j2_series{iview}=squeeze(j2_series{iview}(1,:,:)); %second  pair index
88        if isempty(incr_i)
89            if isempty(first_j) || isempty(incr_j) % no j index or no defined increment for j
90                ref_j=find(max(i1_series{iview},[],2));
91                ref_i=find(max(i1_series{iview},[],1));
92                ref_i=ref_i-1;
93                ref_j=ref_j-1;
94                ref_i=ref_i(ref_i>=first_i & ref_i<=last_i);
95                ref_j=ref_j(ref_j>=first_j & ref_j<=last_j);
96            else
97                ref_j=first_j:incr_j:last_j;
98                ref_i=find(max(i1_series{iview}(:,ref_j),[],1));
99                ref_i=ref_i-1;
100                ref_i=ref_i(ref_i>=first_i & ref_i<=last_i);
101            end
102        else
103            ref_i=first_i:incr_i:last_i;%default
104            if isempty(first_j) ||isempty(incr_j)% no j index or no defined increment for j
105                ref_j=find(max(i1_series{iview},[],2));
106                ref_j=ref_j-1;
107                ref_j=ref_j(ref_j>=first_j & ref_j<=last_j);
108            else
109                ref_j=first_j:incr_j:last_j;
110            end
111        end
112        if isempty(ref_j)
113            i1_series{iview}=i1_series{iview}(2,ref_i+1);
114            if ~isempty(i2_series{iview})
115                i2_series{iview}=i2_series{iview}(2,ref_i+1);
116            end
117        else
118            i1_series{iview}=i1_series{iview}(ref_j+1,ref_i+1);
119            if ~isempty(i2_series{iview})
120                i2_series{iview}=i2_series{iview}(ref_j+1,ref_i+1);
121            end
122        end
123        if ~isempty(j1_series{iview})
124            j1_series{iview}=j1_series{iview}(ref_j+1,ref_i+1);
125            if ~isempty(j2_series{iview})
126                j2_series{iview}=j2_series{iview}(ref_j+1,ref_i+1);
127            end
128        end
129    else
130        ref_i=first_i:incr_i:last_i;%default
131        ref_j=first_j:incr_j:last_j;%default
132        [i1_series{iview},i2_series{iview},j1_series{iview},j2_series{iview}]=find_file_indices(ref_i,ref_j,str2num(r.num1),str2num(r.num2),r.mode);
133    end
134    %     if ~isequal(r(1).mode,'*-*')% imposed pairs or single i and/or j index
135    %         [i1_series{iview},i2_series{iview},j1_series{iview},j2_series{iview}]=find_file_indices(ref_i,ref_j,str2num(r.num1),str2num(r.num2),r.mode);
136    %     end
137   
138    %list of files
139    i2=[];j1=[];j2=[];
140    for ifile=1:numel(i1_series{iview})
141        i1=i1_series{iview}(ifile);
142        if ~isempty(i2_series{iview})
143            i2=i2_series{iview}(ifile);
144        end
145        if ~isempty(j1_series{iview})
146            j1=j1_series{iview}(ifile);
147        end
148        if ~isempty(j2_series{iview})
149            j2=j2_series{iview}(ifile);
150        end
151        filecell{iview,ifile}=fullfile_uvmat(InputTable{iview,1},InputTable{iview,2},InputTable{iview,3},InputTable{iview,5},InputTable{iview,4},i1,i2,j1,j2);
152    end
153end
154
155
156function [i1_series,i2_series,j1_series,j2_series]=find_file_indices(ref_i,ref_j,num1,num2,mode)
157i1_series=ref_i;%default
158j1_series=[];
159if ~isempty(ref_j)
160    [i1_series,j1_series]=meshgrid(ref_i,ref_j);
161end
162i2_series=i1_series;
163j2_series=j1_series;
164
165switch mode
166    case 'Di='  %  case 'series(Di)')
167        i1_series=i1_series-num1;
168        i2_series=i2_series+num2;
169    case 'Dj='  %  case 'series(Dj)'
170        j1_series=j1_series-num1;
171        j2_series=j2_series+num2;
172    case '-'  % case 'bursts'
173        j1_series=num1*ones(size(i1_series));
174        j2_series=num2*ones(size(i1_series));
175end
Note: See TracBrowser for help on using the repository browser.