1 | %'get_file_series': determine the list of 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 | function [filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param) |
---|
16 | |
---|
17 | filecell={};i1_series={};i2_series={};j1_series={};j2_series={}; |
---|
18 | InputTable=Param.InputTable; |
---|
19 | first_i=Param.IndexRange.first_i; |
---|
20 | incr_i=Param.IndexRange.incr_i; |
---|
21 | last_i=Param.IndexRange.last_i; |
---|
22 | % ref_i=first_i:incr_i:last_i; |
---|
23 | %ref_j=[]; |
---|
24 | first_j=[];last_j=[];incr_j=1;%default |
---|
25 | if isfield(Param.IndexRange,'first_j')&& isfield(Param.IndexRange,'last_j') |
---|
26 | first_j=Param.IndexRange.first_j; |
---|
27 | last_j=Param.IndexRange.last_j; |
---|
28 | end |
---|
29 | if isfield(Param.IndexRange,'incr_j') |
---|
30 | incr_j=Param.IndexRange.incr_j; |
---|
31 | end |
---|
32 | |
---|
33 | %% determine the list of input file names |
---|
34 | nbmissing=0; |
---|
35 | NbView=size(InputTable,1); |
---|
36 | i1_series=cell(NbView,1);% initiate index series with empty cells |
---|
37 | i2_series=cell(NbView,1); |
---|
38 | j1_series=cell(NbView,1); |
---|
39 | j2_series=cell(NbView,1); |
---|
40 | for iview=1:NbView |
---|
41 | r.mode=''; |
---|
42 | if isfield (Param.IndexRange,'PairString') |
---|
43 | if ischar(Param.IndexRange.PairString) |
---|
44 | Param.IndexRange.PairString={Param.IndexRange.PairString}; |
---|
45 | end |
---|
46 | r=regexp(Param.IndexRange.PairString{iview,1},'(?<mode>(Di=)|(Dj=)) -*(?<num1>\d+)\|(?<num2>\d+)','names');%look for mode=Dj or Di |
---|
47 | if isempty(r) |
---|
48 | r=regexp(Param.IndexRange.PairString{iview,1},'(?<num1>\d+)(?<mode>-)(?<num2>\d+)','names');%look for burst pairs |
---|
49 | end |
---|
50 | % TODO case of free pairs: |
---|
51 | %r=regexp(pair_string,'.*\D(?<num1>[\d+|*])(?<delim>[-||])(?<num2>[\d+|*])','names'); |
---|
52 | end |
---|
53 | if isempty(r)||isempty(r.mode) |
---|
54 | r(1).num1=''; |
---|
55 | r(1).num2=''; |
---|
56 | if isfield (Param.IndexRange,'PairString') && strcmp(Param.IndexRange.PairString{iview,1},'j=*-*') |
---|
57 | r(1).mode='*-*'; |
---|
58 | else |
---|
59 | r(1).mode=''; |
---|
60 | end |
---|
61 | end |
---|
62 | |
---|
63 | if isempty(incr_i) || isempty(incr_j) || isequal(r(1).mode,'*-*')|| isequal(r(1).mode,'*|*')% free pairs or increment |
---|
64 | FilePath=fullfile(InputTable{iview,1},InputTable{iview,2}); |
---|
65 | fileinput=[InputTable{iview,3} InputTable{iview,4} InputTable{iview,5}]; |
---|
66 | [tild,tild,tild,i1_series{iview},i2_series{iview},j1_series{iview},j2_series{iview},NomType,FileType,FileInfo,MovieObject,... |
---|
67 | i1_input,i2_input,j1_input,j2_input]=find_file_series(FilePath,fileinput); |
---|
68 | i1_series{iview}=squeeze(i1_series{iview}(1,:,:)); %select first pair index as ordered by find_file_series |
---|
69 | i2_series{iview}=squeeze(i2_series{iview}(1,:,:)); %select first pair index as ordered by find_file_series |
---|
70 | j1_series{iview}=squeeze(j1_series{iview}(1,:,:)); %first pair index |
---|
71 | j2_series{iview}=squeeze(j2_series{iview}(1,:,:)); %second pair index |
---|
72 | if isempty(incr_i) |
---|
73 | if isempty(first_j) || isempty(incr_j) % no j index or no defined increment for j |
---|
74 | ref_j=find(max(i1_series{iview},[],2)); |
---|
75 | ref_i=find(max(i1_series{iview},[],1)); |
---|
76 | ref_i=ref_i-1; |
---|
77 | ref_j=ref_j-1; |
---|
78 | ref_i=ref_i(ref_i>=first_i & ref_i<=last_i); |
---|
79 | ref_j=ref_j(ref_j>=first_j & ref_j<=last_j); |
---|
80 | else |
---|
81 | ref_j=first_j:incr_j:last_j; |
---|
82 | ref_i=find(max(i1_series{iview}(:,ref_j),[],1)); |
---|
83 | ref_i=ref_i-1; |
---|
84 | ref_i=ref_i(ref_i>=first_i & ref_i<=last_i); |
---|
85 | end |
---|
86 | else |
---|
87 | ref_i=first_i:incr_i:last_i;%default |
---|
88 | if isempty(first_j) ||isempty(incr_j)% no j index or no defined increment for j |
---|
89 | ref_j=find(max(i1_series{iview},[],2)); |
---|
90 | ref_j=ref_j-1; |
---|
91 | ref_j=ref_j(ref_j>=first_j & ref_j<=last_j); |
---|
92 | else |
---|
93 | ref_j=first_j:incr_j:last_j; |
---|
94 | end |
---|
95 | end |
---|
96 | if isempty(ref_j) |
---|
97 | i1_series{iview}=i1_series{iview}(2,ref_i+1); |
---|
98 | if ~isempty(i2_series{iview}) |
---|
99 | i2_series{iview}=i2_series{iview}(2,ref_i+1); |
---|
100 | end |
---|
101 | else |
---|
102 | i1_series{iview}=i1_series{iview}(ref_j+1,ref_i+1); |
---|
103 | if ~isempty(i2_series{iview}) |
---|
104 | i2_series{iview}=i2_series{iview}(ref_j+1,ref_i+1); |
---|
105 | end |
---|
106 | end |
---|
107 | if ~isempty(j1_series{iview}) |
---|
108 | j1_series{iview}=j1_series{iview}(ref_j+1,ref_i+1); |
---|
109 | if ~isempty(j2_series{iview}) |
---|
110 | j2_series{iview}=j2_series{iview}(ref_j+1,ref_i+1); |
---|
111 | end |
---|
112 | end |
---|
113 | else |
---|
114 | ref_i=first_i:incr_i:last_i;%default |
---|
115 | ref_j=first_j:incr_j:last_j;%default |
---|
116 | [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); |
---|
117 | end |
---|
118 | % if ~isequal(r(1).mode,'*-*')% imposed pairs or single i and/or j index |
---|
119 | % [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); |
---|
120 | % end |
---|
121 | |
---|
122 | %list of files |
---|
123 | i2=[];j1=[];j2=[]; |
---|
124 | for ifile=1:numel(i1_series{iview}) |
---|
125 | i1=i1_series{iview}(ifile); |
---|
126 | if ~isempty(i2_series{iview}) |
---|
127 | i2=i2_series{iview}(ifile); |
---|
128 | end |
---|
129 | if ~isempty(j1_series{iview}) |
---|
130 | j1=j1_series{iview}(ifile); |
---|
131 | end |
---|
132 | if ~isempty(j2_series{iview}) |
---|
133 | j2=j2_series{iview}(ifile); |
---|
134 | end |
---|
135 | filecell{iview,ifile}=fullfile_uvmat(InputTable{iview,1},InputTable{iview,2},InputTable{iview,3},InputTable{iview,5},InputTable{iview,4},i1,i2,j1,j2); |
---|
136 | end |
---|
137 | end |
---|
138 | |
---|
139 | |
---|
140 | function [i1_series,i2_series,j1_series,j2_series]=find_file_indices(ref_i,ref_j,num1,num2,mode) |
---|
141 | i1_series=ref_i;%default |
---|
142 | j1_series=[]; |
---|
143 | if ~isempty(ref_j) |
---|
144 | [i1_series,j1_series]=meshgrid(ref_i,ref_j); |
---|
145 | end |
---|
146 | i2_series=i1_series; |
---|
147 | j2_series=j1_series; |
---|
148 | |
---|
149 | switch mode |
---|
150 | case 'Di=' % case 'series(Di)') |
---|
151 | i1_series=i1_series-num1; |
---|
152 | i2_series=i2_series+num2; |
---|
153 | case 'Dj=' % case 'series(Dj)' |
---|
154 | j1_series=j1_series-num1; |
---|
155 | j2_series=j2_series+num2; |
---|
156 | case '-' % case 'bursts' |
---|
157 | j1_series=num1*ones(size(i1_series)); |
---|
158 | j2_series=num2*ones(size(i1_series)); |
---|
159 | end |
---|