source: trunk/src/series.m @ 332

Last change on this file since 332 was 332, checked in by sommeria, 12 years ago

NomType? changed from _i1-i2 ... to _1-2 ... (bugs to be expected!)
bug corrected in geometry_calib
series changed by introducing a from FileIndices?, introduction of find_file_series to detect the file series corresponding to an input file

File size: 89.9 KB
Line 
1%'series': master function associated to the GUI series.m for analysis field series 
2%------------------------------------------------------------------------
3% function varargout = series(varargin)
4% associated with the GUI series.fig
5%
6%INPUT
7% param: structure with input parameters (link with the GUI uvmat)
8%      .menu_coord_str: string for the transform_fct (menu for coordinate transforms)
9%      .menu_coord_val: value for transform_fct (menu for coordinate transforms)
10%      .FileName: input file name
11%      .FileName_1: second input file name
12%      .list_field: menu of input fields
13%      .index_fields: chosen index
14%      .civ1=0 or 1, .interp1,  ... : input civ field type
15%
16%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
17%  Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
18%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
19%     This file is part of the toolbox UVMAT.
20%
21%     UVMAT is free software; you can redistribute it and/or modify
22%     it under the terms of the GNU General Public License as published by
23%     the Free Software Foundation; either version 2 of the License, or
24%     (at your option) any later version.
25%
26%     UVMAT is distributed in the hope that it will be useful,
27%     but WITHOUT ANY WARRANTY; without even the implied warranty of
28%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29%     GNU General Public License (file UVMAT/COPYING.txt) for more details.
30%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
31
32function varargout = series(varargin)
33
34% Begin initialization code - DO NOT EDIT
35gui_Singleton = 1;
36gui_State = struct('gui_Name',       mfilename, ...
37                   'gui_Singleton',  gui_Singleton, ...
38                   'gui_OpeningFcn', @series_OpeningFcn, ...
39                   'gui_OutputFcn',  @series_OutputFcn, ...
40                   'gui_LayoutFcn',  [] , ...
41                   'gui_Callback',   []);
42if nargin && ischar(varargin{1})
43    gui_State.gui_Callback = str2func(varargin{1});
44end
45
46if nargout
47    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
48else
49    gui_mainfcn(gui_State, varargin{:});
50end
51% End initialization code - DO NOT EDIT
52
53%--------------------------------------------------------------------------
54% --- Executes just before series is made visible.
55%--------------------------------------------------------------------------
56function series_OpeningFcn(hObject, eventdata, handles,param)
57global nb_builtin_ACTION nb_builtin_transform
58% Choose default command line output for series
59handles.output = hObject;
60% Update handles structure
61guidata(hObject, handles);
62%default initial parameters
63drawnow
64set(hObject,'Units','pixels')
65% set(0,'Units','pixels')
66% screensize=get(0,'ScreenSize'); %screen size in pixels
67set(hObject,'WindowButtonDownFcn',{'mouse_down'})%allows mouse action with right button (zoom for uicontrol display)
68%set(hObject,'Position',[150 100 1000 600] );%position and size in pixels (get adjusted to the screen size in case of excess)
69%load the list of previously browsed files in menus Open and Open_1
70dir_perso=prefdir;
71test_profil_perso=0;
72profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
73if exist(profil_perso,'file')
74     h=load (profil_perso);
75     test_profil_perso=1;
76     if isfield(h,'MenuFile_1')
77          set(handles.MenuFile_1,'Label',h.MenuFile_1);
78          set(handles.MenuFile_insert_1,'Label',h.MenuFile_1);
79     end
80     if isfield(h,'MenuFile_1')
81          set(handles.MenuFile_2,'Label',h.MenuFile_2);
82          set(handles.MenuFile_insert_2,'Label',h.MenuFile_2);
83     end
84     if isfield(h,'MenuFile_1')
85          set(handles.MenuFile_3,'Label',h.MenuFile_3);
86          set(handles.MenuFile_insert_3,'Label',h.MenuFile_3);
87     end
88     if isfield(h,'MenuFile_1')
89          set(handles.MenuFile_4,'Label',h.MenuFile_4);
90          set(handles.MenuFile_insert_4,'Label',h.MenuFile_4);
91     end
92     if isfield(h,'MenuFile_1')
93          set(handles.MenuFile_5,'Label',h.MenuFile_5);
94          set(handles.MenuFile_insert_5,'Label',h.MenuFile_5);
95     end
96end
97
98%check default input data
99if ~exist('param','var')
100    param=[]; %default
101end
102
103%file name and browser initialisation
104if isfield(param,'menu_coord_str')
105    set(handles.transform_fct,'String',param.menu_coord_str)
106end
107if isfield(param,'menu_coord_val')
108    set(handles.transform_fct,'Value',param.menu_coord_val);
109else
110     set(handles.transform_fct,'Value',1);%default
111end
112
113if isfield(param,'FileName')
114    if isfield(param,'FileName_1')
115        update_file(handles,param.FileName_1,0)
116        update_file(handles,param.FileName,1)
117    else
118        update_file(handles,param.FileName,0)
119    end
120end 
121
122%fields input initialisation
123if isfield(param,'list_fields')&& isfield(param,'index_fields') &&~isempty(param.list_fields) &&~isempty(param.index_fields)
124    set(handles.FieldMenu,'String',param.list_fields);% list menu fields
125    set(handles.FieldMenu,'Value',param.index_fields);% selected string index
126    FieldCell{1}=param.list_fields{param.index_fields};
127end
128NomType_Callback(hObject, eventdata, handles)
129
130%loads the information stored in prefdir to initiate  the list of ACTION functions
131fct_menu={'check_data_files';'aver_stat';'time_series';'merge_proj';'clean_civ_cmx'};
132transform_menu={'';'phys';'px';'phys_polar'};
133nb_builtin_ACTION=numel(fct_menu); %number of functions
134nb_transform=numel(transform_menu);
135[path_series,name,ext]=fileparts(which('series'));
136path_series=fullfile(path_series,'series');%path of the function 'series'
137addpath (path_series) ; %add the path to UVMAT, (useful in case of change of working directory after civ has been s opened in the working directory)
138path_transform=fullfile(path_series,'transform_field');%path to the field transform functions
139for ilist=1:length(fct_menu)
140    fct_path{ilist,1}=path_series;%paths of the fuctions buil-in in 'series.m'
141end
142
143%TRANSFORM menu: loads the information stored in prefdir to initiate  the list of field transform functions
144menu_str={'';'phys';'px';'phys_polar'};
145nb_builtin_transform=numel(menu_str); %number of functions
146[path_uvmat,name,ext]=fileparts(which('uvmat'));
147addpath(fullfile(path_uvmat,'transform_field'))
148fct_handle{1,1}=[];
149testexist(1)=1;
150for ilist=2:length(menu_str)
151    if exist(menu_str{ilist},'file')
152        fct_handle{ilist,1}=str2func(menu_str{ilist});
153        testexist(ilist)=1;
154    else
155        testexist(ilist)=0;
156    end
157end
158rmpath(fullfile(path_uvmat,'transform_field'))
159
160% read the list of functions stored in the personal file 'uvmat_perso.mat' in prefdir
161if test_profil_perso
162    if isfield(h,'series_fct') && iscell(h.series_fct)
163         for ilist=1:length(h.series_fct)
164             [path,file]=fileparts(h.series_fct{ilist});
165             fct_path=[fct_path; {path}];%concatene the list of paths
166             fct_menu=[fct_menu; {file}];
167         end
168    end
169    if isfield(h,'transform_fct') && iscell(h.transform_fct)
170        for ilist=1:length(h.transform_fct);
171             [path,file]=fileparts(h.transform_fct{ilist});
172             addpath(path)
173             if exist(file,'file')
174                h_func=str2func(file);
175                testexist=[testexist 1];
176             else
177                h_func=[];
178                testexist=[testexist 0];
179             end
180             fct_handle=[fct_handle; {h_func}];%concatene the list of paths
181             rmpath(path)
182             menu_str=[menu_str; {file}];
183        end
184    end
185end
186fct_menu=[fct_menu;{'more...'}];
187set(handles.ACTION,'String',fct_menu)
188set(handles.ACTION,'UserData',fct_path)% store the list of path in UserData of ACTION
189
190menu_str=menu_str(find(testexist));
191fct_handle=fct_handle(find(testexist));
192menu_str=[menu_str;{'more...'}];
193set(handles.transform_fct,'String',menu_str)
194set(handles.transform_fct,'UserData',fct_handle)% store the list of path in UserData of ACTION
195
196% display the GUI for the default action 'check_data_files'
197ACTION_Callback(hObject, eventdata, handles)
198
199%--------------------------------------------------------------
200% --- Outputs from this function are returned to the command line.
201%-----------------------------------------------------------------
202function varargout = series_OutputFcn(hObject, eventdata, handles)
203% varargout  cell array for returning output args (see VARARGOUT);
204% hObject    handle to figure
205% eventdata  reserved - to be defined in a future version of MATLAB
206% handles    structure with handles and user data (see GUIDATA)
207% Get default command line output from handles structure
208varargout{1} = handles.output;
209
210
211% --------------------------------------------------------------------
212function MenuBrowse_Callback(hObject, eventdata, handles)
213
214RootPathCell=get(handles.RootPath,'String');
215SubDirCell=get(handles.SubDir,'String'); 
216RootFileCell=get(handles.RootFile,'String');
217oldfile=''; %default
218if isempty(RootPathCell)||isequal(RootPathCell,{''})%loads the previously stored file name and set it as default in the file_input box
219     dir_perso=prefdir;
220     profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
221     if exist(profil_perso,'file')
222          h=load (profil_perso);
223         if isfield(h,'filebase')&&ischar(h.filebase)
224                 oldfile=h.filebase;
225         end
226         if isfield(h,'RootPath')&&ischar(h.RootPath)
227                 oldfile=h.RootPath;
228         end
229     end
230 else
231     oldfile=fullfile(RootPathCell{1},SubDirCell{1},RootFileCell{1});
232 end
233[FileName, PathName, filterindex] = uigetfile( ...
234       {'*.xml;*.xls;*.png;*.tif;*.avi;*.AVI;*.nc', ' (*.xml,*.xls, *.png,*.tif, *.avi,*.nc)';
235       '*.xml',  '.xml files '; ...
236        '*.xls',  '.xls files '; ...
237        '*.png','.png image files'; ...
238        '*.tif','.tif image files'; ...
239        '*.avi;*.AVI','.avi movie files'; ...
240        '*.nc','.netcdf files'; ...
241        '*.*',  'All Files (*.*)'}, ...
242        'Pick a file',oldfile);
243fileinput=[PathName FileName];%complete file name
244%testblank=findstr(fileinput,' ');%look for blanks
245% if ~isempty(testblank)
246%     errordlg('forbidden input file name: contain blanks')
247%     return
248% end
249sizf=size(fileinput);
250if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end
251[path,name,ext]=fileparts(fileinput);
252SeriesData=[];%dfault
253if isequal(ext,'.xml')
254    warndlg_uvmat('ERROR','input file type not implemented')%A Faire: ouvrir le fichier pour naviguer
255elseif isequal(ext,'.xls')
256    warndlg_uvmat('ERROR','input file type not implemented')%A Faire: ouvrir le fichier pour naviguer
257else
258    update_file(handles,fileinput,0)
259     %update list of recent files in the menubar
260    MenuFile_1=fileinput;
261    MenuFile_2=get(handles.MenuFile_1,'Label');
262    MenuFile_3=get(handles.MenuFile_2,'Label');
263    MenuFile_4=get(handles.MenuFile_3,'Label');
264    MenuFile_5=get(handles.MenuFile_4,'Label');
265    set(handles.MenuFile_1,'Label',MenuFile_1)
266    set(handles.MenuFile_2,'Label',MenuFile_2)
267    set(handles.MenuFile_3,'Label',MenuFile_3)
268    set(handles.MenuFile_4,'Label',MenuFile_4)
269    set(handles.MenuFile_5,'Label',MenuFile_5)
270    set(handles.MenuFile_insert_1,'Label',MenuFile_1)
271    set(handles.MenuFile_insert_2,'Label',MenuFile_2)
272    set(handles.MenuFile_insert_3,'Label',MenuFile_3)
273    set(handles.MenuFile_insert_4,'Label',MenuFile_4)
274    set(handles.MenuFile_insert_5,'Label',MenuFile_5)
275    dir_perso=prefdir;
276    profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
277    if exist(profil_perso,'file')
278        save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-append'); %store the file names for future opening of uvmat
279    else
280    txt=ver('MATLAB');
281    Release=txt.Release;
282        relnumb=str2num(Release(3:4));
283        if relnumb >= 14
284            save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-V6'); %store the file names for future opening of uvmat
285        else
286            save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5'); %store the file names for future opening of uvmat
287        end
288    end
289end
290
291
292% --------------------------------------------------------------------
293function MenuFile_1_Callback(hObject, eventdata, handles)
294fileinput=get(handles.MenuFile_1,'Label');
295update_file(handles,fileinput,0)
296
297% --------------------------------------------------------------------
298function MenuFile_2_Callback(hObject, eventdata, handles)
299fileinput=get(handles.MenuFile_2,'Label');
300update_file(handles,fileinput,0)
301
302% --------------------------------------------------------------------
303function MenuFile_3_Callback(hObject, eventdata, handles)
304fileinput=get(handles.MenuFile_3,'Label');
305update_file( handles,fileinput,0)
306
307% --------------------------------------------------------------------
308function MenuFile_4_Callback(hObject, eventdata, handles)
309fileinput=get(handles.MenuFile_4,'Label');
310update_file(handles,fileinput,0)
311
312% --------------------------------------------------------------------
313function MenuFile_5_Callback(hObject, eventdata, handles)
314fileinput=get(handles.MenuFile_5,'Label');
315update_file(handles,fileinput,0)
316
317% --------------------------------------------------------------------
318function MenuBrowse_insert_Callback(hObject, eventdata, handles)
319
320RootPathCell=get(handles.RootPath,'String');
321RootFileCell=get(handles.RootFile,'String');
322oldfile=''; %default
323if isempty(RootPathCell)||isequal(RootPathCell,{''})%loads the previously stored file name and set it as default in the file_input box
324     dir_perso=prefdir;
325     profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
326     if exist(profil_perso,'file')
327          h=load (profil_perso);
328         if isfield(h,'filebase')&ischar(h.filebase)
329                 oldfile=h.filebase;
330         end
331         if isfield(h,'RootPath')&ischar(h.RootPath)
332                 oldfile=h.RootPath;
333         end
334     end
335 else
336     oldfile=fullfile(RootPathCell{1},RootFileCell{1});
337 end
338[FileName, PathName, filterindex] = uigetfile( ...
339       {'*.xml;*.xls;*.png;*.avi;*.AVI;*.nc', ' (*.xml,*.xls, *.png, *.avi,*.nc)';
340       '*.xml',  '.xml files '; ...
341        '*.xls',  '.xls files '; ...
342        '*.png','.png image files'; ...
343        '*.avi;*.AVI','.avi movie files'; ...
344        '*.nc','.netcdf files'; ...
345        '*.*',  'All Files (*.*)'}, ...
346        'Pick a file',oldfile);
347fileinput=[PathName FileName];%complete file name
348% testblank=findstr(fileinput,' ');%look for blanks
349% if ~isempty(testblank)
350%     errordlg('forbidden input file name: contain blanks')
351%     return
352% end
353sizf=size(fileinput);
354if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end
355[path,name,ext]=fileparts(fileinput);
356SeriesData=[];%dfault
357if isequal(ext,'.xml')
358    msgbox_uvmat('ERROR','input file type not implemented')%A Faire: ouvrir le fichier pour naviguer
359elseif isequal(ext,'.xls')
360    msgbox_uvmat('ERROR','input file type not implemented')%A Faire: ouvrir le fichier pour naviguer
361else
362    update_file(handles,fileinput,1)
363    %update list of recent files in the menubar
364    MenuFile_1=fileinput;
365    MenuFile_2=get(handles.MenuFile_1,'Label');
366    MenuFile_3=get(handles.MenuFile_2,'Label');
367    MenuFile_4=get(handles.MenuFile_3,'Label');
368    MenuFile_5=get(handles.MenuFile_4,'Label');
369    set(handles.MenuFile_1,'Label',MenuFile_1)
370    set(handles.MenuFile_2,'Label',MenuFile_2)
371    set(handles.MenuFile_3,'Label',MenuFile_3)
372    set(handles.MenuFile_4,'Label',MenuFile_4)
373    set(handles.MenuFile_5,'Label',MenuFile_5)
374    set(handles.MenuFile_insert_1,'Label',MenuFile_1)
375    set(handles.MenuFile_insert_2,'Label',MenuFile_2)
376    set(handles.MenuFile_insert_3,'Label',MenuFile_3)
377    set(handles.MenuFile_insert_4,'Label',MenuFile_4)
378    set(handles.MenuFile_insert_5,'Label',MenuFile_5)
379    dir_perso=prefdir;
380    profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
381    if exist(profil_perso,'file')
382        save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-append'); %store the file names for future opening of uvmat
383    else
384    txt=ver('MATLAB');
385    Release=txt.Release;
386        relnumb=str2num(Release(3:4));
387        if relnumb >= 14
388            save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-V6'); %store the file names for future opening of uvmat
389        else
390            save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5'); %store the file names for future opening of uvmat
391        end
392    end
393end
394%------------------------------------------------
395
396% --------------------------------------------------------------------
397function MenuFile_insert_1_Callback(hObject, eventdata, handles)
398fileinput=get(handles.MenuFile_insert_1,'Label');
399update_file(handles,fileinput,1)
400
401% --------------------------------------------------------------------
402function MenuFile_insert_2_Callback(hObject, eventdata, handles)
403fileinput=get(handles.MenuFile_insert_2,'Label');
404update_file(handles,fileinput,1)
405
406% --------------------------------------------------------------------
407function MenuFile_insert_3_Callback(hObject, eventdata, handles)
408fileinput=get(handles.MenuFile_insert_3,'Label');
409update_file( handles,fileinput,1)
410
411% --------------------------------------------------------------------
412function MenuFile_insert_4_Callback(hObject, eventdata, handles)
413fileinput=get(handles.MenuFile_insert_4,'Label');
414update_file( handles,fileinput,1)
415
416% --------------------------------------------------------------------
417function MenuFile_insert_5_Callback(hObject, eventdata, handles)
418fileinput=get(handles.MenuFile_insert_5,'Label');
419update_file(handles,fileinput,1)
420
421%------------------------------------------------------------------------
422% ---  refresh the GUI data after introduction of a new file series
423% INPUT:
424% handles:
425% fileinput: name of the input file
426% addtest: =0 to refresh the list of file series, =1 to append a new series to the list (from the menu bar option 'Open_insert')
427function update_file(handles,fileinput,addtest)
428%------------------------------------------------------------------------ 
429
430%% enable other menus and uicontrols
431set(handles.MenuOpen_insert,'Enable','on')
432set(handles.MenuFile_insert_1,'Enable','on')
433set(handles.MenuFile_insert_2,'Enable','on')
434set(handles.MenuFile_insert_3,'Enable','on')
435set(handles.MenuFile_insert_4,'Enable','on')
436set(handles.MenuFile_insert_5,'Enable','on')
437set(handles.RUN, 'Enable','On')
438set(handles.RUN,'BackgroundColor',[1 0 0])% set RUN button to red
439set(handles.RootPath,'BackgroundColor',[1 1 0]) % set RootPath edit box  to yellow
440drawnow
441
442%% get the input root name, indices, file extension and nomenclature NomType
443if ~exist(fileinput,'file')
444    msgbox_uvmat('ERROR',['input file ' fileinput  ' does not exist'])
445    return
446end
447[RootPath,RootFile,i1,str2,str_a,str_b,FileExt,NomType,SubDir]=name2display(fileinput);
448
449%% look for min and max indices existing in the file series and update NomType
450[num_i1,num_i2,num_j1,num_j2,NomType,FileType,Object]=find_file_series(fileinput);
451 if strcmp(NomType,'*')
452     MinIndex_i=1;
453     MinIndex_j=1;
454     nb_field=num_i2;
455     nb_field2=1;
456 else
457    MinIndex_i=min(floor((min(num_i1)+min(num_i2))/2));
458    MinIndex_j=min(floor((min(num_j1)+min(num_j2))/2));
459    nb_field=max(floor((max(num_i1)+max(num_i2))/2));
460    nb_field2=max(floor((max(num_j1)+max(num_j2))/2));
461 end
462if isnan(nb_field)
463    nb_field_str='?';
464    nb_field_str2='?';
465else
466    MinIndex_i_str=num2str(MinIndex_i);
467    MinIndex_j_str=num2str(MinIndex_j);
468    nb_field_str=num2str(nb_field);
469    nb_field_str2=num2str(nb_field2); 
470end
471if addtest% case of insertion of a new series (menu bar option Open_insert)
472    MinIndex_i_cell=[{MinIndex_i_str} ;get(handles.MinIndex_i,'String')];
473    MinIndex_j_cell=[{MinIndex_j_str} ;get(handles.MinIndex_j,'String')];
474    nb_field_cell=[{nb_field_str} ;get(handles.nb_field,'String')];
475    nb_field2_cell=[{nb_field_str2} ;get(handles.nb_field2,'String')];
476else % refresh the list (menu bar option Open)
477    MinIndex_i_cell={MinIndex_i_str};
478    MinIndex_j_cell={MinIndex_j_str};
479    nb_field_cell={nb_field_str};
480    nb_field2_cell={nb_field_str2};
481end
482set(handles.MinIndex_i,'String',MinIndex_i_cell);
483set(handles.MinIndex_j,'String',MinIndex_j_cell);
484set(handles.nb_field,'String',nb_field_cell);
485set(handles.nb_field2,'String',nb_field2_cell);
486
487
488%% determine reference field indices
489ref_i=1; %default ref_i is a reference frame index used to find existing pairs from PIV
490if ~isempty(str2num(i1))
491    ref_i=str2num(i1);
492    if ~isempty(str2num(str2))
493        ref_i=floor((ref_i+str2num(str2))/2);% reference image number corresponding to the file
494        SeriesData.browse_Di=str2num(str2)-str2num(i1);
495    end
496end
497set(handles.ref_i,'String',num2str(ref_i));
498set(handles.first_i,'String',num2str(ref_i));
499set(handles.last_i,'String',num2str(ref_i));
500ref_j=1; %default  ref_j is a reference frame index used to find existing pairs from PIV
501if ~isempty(str2num(str_a))
502    ref_j=str2num(str_a);
503    if ~isempty(str2num(str_b))
504        ref_j=floor((str2num(str_a)+str2num(str_b))/2);
505        SeriesData.browse_Dj=str2num(str_b)-str2num(str_a);
506    end         
507end
508set(handles.ref_j,'String',num2str(ref_j));
509set(handles.first_j,'String',num2str(ref_j))
510set(handles.last_j,'String',num2str(ref_j));
511
512TimeUnit=''; %default
513time=[];%default
514GeometryCalib=[];%default
515nb_field=NaN;%default
516nb_field2=NaN;%default
517SeriesData.PathCampaign=get(handles.PathCampaign,'String');
518
519% read timing and total frame number from the current file (movie files) !! may be overrid by xml file
520FileBase=fullfile(RootPath,RootFile);
521
522testima=0; %test for image input
523if isequal(lower(FileExt),'.avi') %.avi file
524    testima=1;
525%     info=aviinfo([FileBase FileExt]);
526%     time=(0:1/info.FramesPerSecond:(info.NumFrames-1)/info.FramesPerSecond)';
527%     nb_field=info.NumFrames;
528%     nb_field2=1;
529elseif ~isempty(imformats(FileExt(2:end)))
530    testima=1;
531%     if isequal(NomType,'*')% multi-frame image
532%         imainfo=imfinfo([FileBase FileExt]);     
533%         if length(imainfo) >1 %case of image with multiple frames
534%             nb_field=length(imainfo);
535%             nb_field2=1;
536%         end
537%     end
538elseif isequal(FileExt,'.vol')
539     testima=1;
540end
541
542
543%% fill the list of file series
544% select the first line in the list
545set(handles.RootPath,'Value',1)
546set(handles.SubDir,'Value',1)
547set(handles.RootFile,'Value',1)
548set(handles.NomType,'Value',1)
549set(handles.FileExt,'Value',1)
550set(handles.nb_field,'Value',1)
551set(handles.nb_field2,'Value',1)
552% append the current file series to the list
553if addtest
554    SeriesData=get(handles.series,'UserData');
555    SeriesData.displ_num=[0 0 0 0;SeriesData.displ_num];
556    SeriesData.CurrentInputFile_1=SeriesData.CurrentInputFile;
557    RootPathCell=[{RootPath}; get(handles.RootPath,'String')] ;
558    SubDirCell=[{SubDir}; get(handles.SubDir,'String')];
559    RootFileCell=[{RootFile}; get(handles.RootFile,'String')];
560    NomTypeCell=[{NomType}; SeriesData.NomType];
561    FileExtCell=[{FileExt}; get(handles.FileExt,'String')];
562    FileTypeCell=[{FileType};SeriesData.FileType];
563    set(handles.NomType,'String',[{};get(handles.NomType,'String')])
564% or re-initialise the list of  input  file series   
565else
566    SeriesData=[];%re-initialisation
567    SeriesData.displ_num=[0 0 0 0];
568    RootPathCell={RootPath};
569    SubDirCell={SubDir};
570    RootFileCell={RootFile};   
571    NomTypeCell={NomType};
572    FileExtCell={FileExt};   
573    FileTypeCell={FileType};
574end
575SeriesData.NomType=NomTypeCell;
576SeriesData.FileType=FileTypeCell;
577SeriesData.CurrentInputFile=fileinput;
578set(handles.RootPath,'String',RootPathCell);
579set(handles.SubDir,'String',SubDirCell);
580set(handles.RootFile,'String',RootFileCell);
581set(handles.NomType,'String',NomTypeCell);
582set(handles.FileExt,'String',FileExtCell);
583
584%% enable field and veltype menus
585testfield=isequal(get(handles.FieldMenu,'enable'),'on');
586testfield_1=isequal(get(handles.FieldMenu_1,'enable'),'on');
587testveltype=isequal(get(handles.VelTypeMenu,'enable'),'on');
588testveltype_1=isequal(get(handles.VelTypeMenu_1,'enable'),'on');
589testtransform=isequal(get(handles.transform_fct,'Enable'),'on');
590testnc=0;
591testnc_1=0;
592testcivx=0;
593testcivx_1=0;
594if length(FileExtCell)==1 || length(FileExtCell)>2
595    for iview=1:length(FileExtCell)
596        if isequal(FileExtCell{iview},'.nc')
597            testnc=1;
598        end
599        if isequal(FileTypeCell{iview},'civx')
600            testcivx=1;
601        end
602    end
603elseif length(FileExtCell)==2
604    testnc=isequal(FileExtCell{1},'.nc');
605    testnc_1=isequal(FileExtCell{2},'.nc');
606    testcivx=isequal(FileTypeCell{1},'civx');
607    testcivx_1=isequal(FileTypeCell{2},'civx');
608end
609if testfield && testnc
610    view_FieldMenu(handles,'on')
611    if testcivx
612        menustr=get(handles.FieldMenu,'String');
613        if isequal(menustr,{'get_field...'})
614            set(handles.FieldMenu,'String',{'get_field...';'velocity';'vort';'div';'more...'})
615        end
616    else
617        set(handles.FieldMenu,'Value',1)
618        set(handles.FieldMenu,'String',{'get_field...'})
619    end
620else
621    view_FieldMenu(handles,'off')
622end
623if testfield_1 && testnc_1
624    view_FieldMenu_1(handles,'on')
625    if testcivx_1
626        menustr=get(handles.FieldMenu_1,'String');
627        if isequal(menustr,{'get_field...'})
628            set(handles.FieldMenu_1,'String',{'get_field...';'velocity';'vort';'div';'more...'})
629        end
630    else
631        set(handles.FieldMenu_1,'Value',1)
632        set(handles.FieldMenu_1,'String',{'get_field...'})
633    end
634else
635    view_FieldMenu_1(handles,'off')
636end
637if testveltype && testcivx
638    set(handles.VelTypeMenu,'Visible','on')
639    set(handles.VelType_text,'Visible','on');
640else
641    set(handles.VelTypeMenu,'Visible','off')
642    set(handles.VelType_text,'Visible','off');
643end
644if testveltype_1 && testcivx_1
645    set(handles.VelTypeMenu_1,'Visible','on')
646    set(handles.VelType_text_1,'Visible','on');
647else
648    set(handles.VelTypeMenu_1,'Visible','off')
649    set(handles.VelType_text_1,'Visible','off');
650end
651if testtransform && (testcivx || testima)
652     view_TRANSFORM(handles,'on')
653else
654    view_TRANSFORM(handles,'off')
655end
656if ~isequal(FileExt,'.nc') && ~isequal(FileExt,'.cdf') && ~testima
657    msgbox_uvmat('ERROR',['invalid input file extension ' FileExt])
658    return
659end 
660
661%%  read image documentation file  if found%%%%%%%%%%%%%%%%%%%%%%%%%%%
662ext_imadoc='';
663if isequal(FileExt,'.xml')||isequal(FileExt,'.civ')
664    ext_imadoc=FileExt;
665elseif exist([FileBase '.xml'],'file')
666    ext_imadoc='.xml';
667elseif exist([FileBase '.civ'],'file')
668    ext_imadoc='.civ';
669end
670%read the ImaDoc file
671XmlData=[];
672NbSlice_calib={};
673if isequal(ext_imadoc,'.xml')
674        [XmlData,warntext]=imadoc2struct([FileBase '.xml']);
675        if isfield(XmlData,'Heading') && isfield(XmlData.Heading,'ImageName') && ischar(XmlData.Heading.ImageName)
676            [PP,FF,ext_ima_read]=fileparts(XmlData.Heading.ImageName);
677        end
678        if isfield(XmlData,'Time')
679            time=XmlData.Time;
680        end
681        if isfield(XmlData,'Camera')
682            if isfield(XmlData.Camera,'NbSlice')&& ~isempty(XmlData.Camera.NbSlice)
683                NbSlice_calib{iview}=XmlData.Camera.NbSlice;% Nbre of slices for Zindex in phys transform
684                if ~isequal(NbSlice_calib{iview},NbSlice_calib{1})
685                    msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
686                end
687            end
688            if isfield(XmlData.Camera,'TimeUnit')&& ~isempty(XmlData.Camera.TimeUnit)
689                TimeUnit=XmlData.Camera.TimeUnit;
690            end
691        end
692        if ~isempty(warntext)
693            msgbox_uvmat('WARNING',warntext)
694        end 
695elseif isequal(ext_imadoc,'.civ')
696    [error,XmlData.Time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([FileBase '.civ']);
697    time=XmlData.Time;
698    if error==2, warntext=['no file ' FileBase '.civ'];
699    elseif error==1, warntext='inconsistent number of fields in the .civ file';
700    end 
701end 
702
703
704
705%% display times
706if addtest
707    SeriesData.Time=[{time} SeriesData.Time];
708else
709   SeriesData.Time={time};
710end
711set(handles.TimeUnit,'String',TimeUnit)
712set(handles.series,'UserData',SeriesData);
713
714%% number of slices
715if isfield(XmlData,'GeometryCalib') && isfield(XmlData.GeometryCalib,'SliceCoord')
716       siz=size(XmlData.GeometryCalib.SliceCoord);
717       if siz(1)>1
718           NbSlice=siz(1);
719       else
720           NbSlice=1;
721       end
722       set(handles.NbSlice,'String',num2str(NbSlice))
723end
724
725% set menus of index pairs
726NomType_Callback([], [], handles)
727
728%store the root name for future opening of uvmat
729dir_perso=prefdir;
730profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
731if exist(profil_perso,'file')
732    save (profil_perso,'RootPath','SubDir','RootFile','NomType', '-append'); %store the root name for future opening of uvmat
733else
734    txt=ver('MATLAB');
735    Release=txt.Release;
736    relnumb=str2num(Release(3:4));
737    if relnumb >= 14
738        save (profil_perso,'RootPath','SubDir','RootFile','NomType','-V6') %store the root name for future opening of uvmat
739    else
740        save(profil_perso,'RootPath','SubDir','RootFile','NomType')
741    end         
742end
743set(handles.RootPath,'BackgroundColor',[1 1 1])
744% set(handles.PathCampaign,'String',SeriesData.PathCampaign)
745last_j_Callback([], [], handles)
746last_i_Callback([], [], handles)
747
748%------------------------------------------------------------------------
749function RootPath_Callback(hObject, eventdata, handles)
750%------------------------------------------------------------------------
751Val=get(handles.RootPath,'Value');
752synchronise_view(handles,Val)
753NomType_Callback(hObject, eventdata, handles)
754
755%------------------------------------------------------------------------
756function synchronise_view(handles,Val)
757%------------------------------------------------------------------------
758set(handles.RootPath,'Value',Val)
759set(handles.SubDir,'Value',Val)
760set(handles.RootFile,'Value',Val)
761set(handles.NomType,'Value',Val)
762set(handles.FileExt,'Value',Val)
763set(handles.nb_field,'Value',Val)
764set(handles.nb_field2,'Value',Val)
765set(handles.time_first,'Value',Val)
766set(handles.time_last,'Value',Val)
767
768
769%------------------------------------------------------------------------
770% Executes on carriage return on the subdir civ1 edit window
771function SubDir_Callback(hObject, eventdata, handles)
772%------------------------------------------------------------------------
773Val=get(handles.SubDir,'Value');
774synchronise_view(handles,Val)
775NomType_Callback(hObject, eventdata, handles)
776
777%------------------------------------------------------------------------
778% --- function activated when a new filebase (image series) is introduced
779function RootFile_Callback(hObject, eventdata, handles)
780%------------------------------------------------------------------------
781Val=get(handles.RootFile,'Value');
782synchronise_view(handles,Val)
783NomType_Callback(hObject, eventdata, handles)
784
785%--------------------------------------------------------------
786%function activated when a new filebase (image series) is introduced
787%------------------------------------------------------------
788function FileExt_Callback(hObject, eventdata, handles)
789Val=get(handles.FileExt,'Value');
790synchronise_view(handles,Val)
791
792%--------------------------------------------------------------
793%function activated when a new filebase (image series) is introduced
794%------------------------------------------------------------
795function nb_field_Callback(hObject, eventdata, handles)
796Val=get(handles.nb_field,'Value');
797synchronise_view(handles,Val)
798
799%--------------------------------------------------------------
800%function activated when a new filebase (image series) is introduced
801%------------------------------------------------------------
802function nb_field2_Callback(hObject, eventdata, handles)
803Val=get(handles.nb_field2,'Value');
804synchronise_view(handles,Val)
805
806%--------------------------------------------------------------
807%function activated when a new filebase (image series) is introduced
808%------------------------------------------------------------
809function time_first_Callback(hObject, eventdata, handles)
810Val=get(handles.time_first,'Value');
811synchronise_view(handles,Val)
812
813%--------------------------------------------------------------
814%function activated when a new filebase (image series) is introduced
815%------------------------------------------------------------
816function time_last_Callback(hObject, eventdata, handles)
817Val=get(handles.time_last,'Value');
818synchronise_view(handles,Val)
819NomType_Callback(hObject, eventdata, handles)
820
821%------------------------------------------------------------------------
822function NomType_Callback(hObject, eventdata, handles)
823%------------------------------------------------------------------------
824SeriesData=get(handles.series,'UserData');
825if isfield(SeriesData,'NomType')
826    NomTypeCell=SeriesData.NomType;
827else
828    NomTypeCell={};
829end
830nbfield2_cell=get(handles.nb_field2,'String');
831val=get(handles.nb_field2,'Value');
832if iscell(nbfield2_cell)
833    nbfield2=str2num(nbfield2_cell{val});
834else
835    nbfield2=str2num(nbfield2_cell);
836end
837nbfield_cell=get(handles.nb_field,'String');
838if iscell(nbfield_cell)
839    nbfield=str2num(nbfield_cell{val});
840else
841   nbfield=str2num(nbfield_cell);
842end
843
844set(handles.mode,'Visible','off') % do not show index pairs by default
845set(handles.list_pair_civ,'Visible','off')
846set(handles.ref_i,'Visible','off')
847set(handles.ref_i_text,'Visible','off')
848testpair=0;
849state_j='off';
850%set the menus of image pairs and default selection for series
851%list pairs if relevant
852Val=get(handles.NomType,'Value');
853synchronise_view(handles,Val)
854if ~isempty(NomTypeCell)
855    NomType=NomTypeCell{Val};
856    switch NomType 
857            case {'_1-2_1', '_1-2'}
858                set(handles.mode,'String',{'series(Di)'})
859                set(handles.mode,'Value',1);
860                set(handles.mode,'Visible','on')
861                testpair=1;
862            case {'#_ab'}
863                set(handles.mode,'String',{'bursts'})
864                set(handles.mode,'Value',1);
865                testpair=1;
866            case '_1_1-2'
867                set(handles.mode,'String',{'bursts';'series(Dj)'})%multiple choice
868                if ~isempty(nbfield) && ~isempty(nbfield2) && ((nbfield2>10) || (nbfield==1))
869                    set(handles.mode,'Value',2);
870                else
871                    set(handles.mode,'Value',1);% advice 'bursts' for small bursts
872                end
873                set(handles.mode,'Visible','on')
874                testpair=1;
875    end
876    switch NomType   
877            case {'_1_1','_1_1-2','_1-2_1','1_ab','01_ab'},% two navigation indices
878                state_j='on';
879    end
880end
881if testpair
882    mode_Callback(hObject, eventdata, handles) 
883else
884    set(handles.NomType,'String',NomTypeCell)
885    set(handles.j_txt,'Visible',state_j)
886    set(handles.MinIndex_j,'Visible',state_j)
887    set(handles.first_j,'Visible',state_j)
888    set(handles.incr_j,'Visible',state_j)
889    set(handles.last_j,'Visible',state_j)
890    set(handles.nb_field2,'Visible',state_j)
891end
892
893
894%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%????????????
895% --- Executes on button press in mode.
896%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
897function mode_Callback(hObject, eventdata, handles)
898SeriesData=get(handles.series,'UserData');
899mode_list=get(handles.mode,'String');
900mode_value=get(handles.mode,'Value');
901mode=mode_list{mode_value};
902NomType=[];
903test_find_pair=0;
904if isfield(SeriesData,'NomType')
905    NomTypeCell=SeriesData.NomType;
906    Val=get(handles.NomType,'Value');
907    NomType=NomTypeCell{Val};
908    test_find_pair=isequal(NomType,'_1_1-2')|| isequal(NomType,'_1-2_1')|| isequal(NomType,'_1-2')|| isequal(NomType,'#_ab');
909end
910time=[];
911if isfield(SeriesData,'Time')
912time=SeriesData.Time{1}; %get the set of times
913end
914siztime=size(time);
915nbfield=siztime(1);
916nbfield2=siztime(2);
917indchosen=1;  %%first pair selected by default
918if isequal(mode,'bursts')
919    enable_i(handles,'On')
920    enable_j(handles,'Off') %do not display j index scanning in burst mode (j is fixed by the burst choice) 
921elseif  isequal(NomType,'_1_1-2')|| isequal(NomType,'_1-2_1')
922    enable_i(handles,'On')
923    enable_j(handles,'On') % allow both i and j index scanning
924else
925    enable_i(handles,'On')
926    enable_j(handles,'Off')
927end   
928set(handles.list_pair_civ,'Value',indchosen);%set the default choice of image pairs for civ1
929set(handles.series,'UserData',SeriesData)
930
931%list pairs if relevant
932if test_find_pair
933     find_netcpair_civ(hObject, eventdata, handles,Val)
934end
935
936%-------------------------------------
937function enable_i(handles,state)
938set(handles.i_txt,'Visible',state)
939set(handles.first_i,'Visible',state)
940set(handles.last_i,'Visible',state)
941set(handles.incr_i,'Visible',state)
942set(handles.nb_field,'Visible',state)
943set(handles.ref_i,'Visible',state)
944set(handles.ref_i_text,'Visible',state)
945
946%-----------------------------------
947function enable_j(handles,state)
948set(handles.j_txt,'Visible',state)
949set(handles.MinIndex_j,'Visible',state)
950set(handles.first_j,'Visible',state)
951set(handles.last_j,'Visible',state)
952set(handles.incr_j,'Visible',state)
953set(handles.nb_field2,'Visible',state)
954set(handles.ref_j,'Visible',state)
955set(handles.ref_j_text,'Visible',state)
956
957%-----------------------------------
958function view_FieldMenu(handles,state)
959set(handles.FieldMenu,'Visible',state)
960set(handles.Field_text,'Visible',state)
961set(handles.Field_frame,'Visible',state)
962
963%-----------------------------------
964function view_FieldMenu_1(handles,state)
965set(handles.FieldMenu_1,'Visible',state)
966set(handles.Field_text_1,'Visible',state)
967
968%-----------------------------------
969function view_TRANSFORM(handles,state)
970set(handles.TRANSFORM_frame,'Visible',state)
971set(handles.transform_fct,'Visible',state);
972set(handles.TRANSFORM_title,'Visible',state)
973
974%--------------------------------------------------------------
975% determine the menu for civ1 pairs depending on existing netcdf files
976% with the reference indices ref_i and ref_j
977%----------------------------------------------------------------
978function find_netcpair_civ(hObject, eventdata, handles,Val)
979SeriesData=get(handles.series,'UserData');
980% NomTypeCell=get(handles.NomType,'String');
981NomTypeCell=SeriesData.NomType;
982NomType=NomTypeCell{Val};
983  set(handles.list_pair_civ,'Visible','on')
984%nomenclature types
985RootPathCell=get(handles.RootPath,'String');
986filepath=RootPathCell{Val};
987RootFileCell=get(handles.RootFile,'String');
988filename=RootFileCell{Val};
989filebase=fullfile(filepath,filename);
990SubDirCell=get(handles.SubDir,'String');
991subdir=SubDirCell{Val};
992if ~exist(fullfile(filepath,subdir),'dir')
993         msgbox_uvmat('ERROR',['no civ file available: subdirectory ' subdir ' does not exist'])
994         set(handles.list_pair_civ,'String',{''});
995         return
996end
997mode_list=get(handles.mode,'String');
998mode_value=get(handles.mode,'Value');
999mode=mode_list{mode_value};
1000
1001%reads image numbers from the interface
1002ref_i=str2num(get(handles.ref_i,'String'));
1003ref_j=str2num(get(handles.ref_j,'String'));
1004ref_time=0;
1005nbfield=50;
1006nbfield2=50;%default max number of pairs
1007
1008%look for existing processed pairs involving the field at the middle of the series if civ1 will not
1009% be performed, while the result is needed for next steps.
1010displ_pair={''};
1011displ_num=[];
1012ind_exist=0;
1013TimeUnit=get(handles.TimeUnit,'String');
1014if length(TimeUnit)>=1
1015    dtunit=['m' TimeUnit];
1016else
1017    dtunit='e-03';
1018end
1019if strcmp(mode,'series(Di)')
1020     for index=1:min(nbfield-1,50)
1021         filename=name_generator(filebase,ref_i-floor(index/2),ref_j,'.nc',NomType,1,ref_i+ceil(index/2),ref_j,subdir);
1022         select=(exist(filename,'file')==2);
1023         if select==1
1024               ind_exist=ind_exist+1;
1025                displ_num(1,ind_exist)=0;
1026                displ_num(2,ind_exist)=0;
1027                displ_num(3,ind_exist)=-floor(index/2);
1028                displ_num(4,ind_exist)=ceil(index/2);
1029                %[cte_detect,vdt,cte_read]=read_netcdf(filename,{'dt','dt2','absolut_time_T0','absolute_time_TO_2'});
1030                [Cte,var_detect,ichoice]=nc2struct(filename,{});
1031                if isfield(Cte,'dt2')
1032                    dt=Cte.dt2;
1033                elseif isfield(Cte,'dt')
1034                    dt=Cte.dt;
1035                end
1036                if isfield(Cte,'absolut_time_TO_2')
1037                    ref_time(ind_exist)=Cte.absolut_time_TO_2;%civ2 data used in priority
1038                elseif isfield(Cte,'absolut_time_TO')
1039                    ref_time(ind_exist)=Cte.absolut_time_TO;%civ2 data used in priorit
1040                elseif isfield(Cte,'Time')
1041                    ref_time(ind_exist)=Cte.Time;
1042                end
1043                displ_pair{ind_exist}=['Di= ' num2str(-floor(index/2)) '|' num2str(ceil(index/2)) ' :dt= ' num2str(dt*1000) dtunit];
1044         end
1045     end
1046     set(handles.list_pair_civ,'String',[displ_pair';{'Di=*|*'}]);   
1047elseif isequal(mode,'series(Dj)')% series on the j index
1048       for index=1:min(nbfield2-1,50)
1049           filename=name_generator(filebase,ref_i,ref_j-floor(index/2),'.nc',NomType,1,ref_i,ref_j+ceil(index/2),subdir);
1050           select=(exist(filename,'file')==2);
1051           if select==1
1052               ind_exist=ind_exist+1;
1053                displ_num(1,ind_exist)=-floor(index/2);
1054                displ_num(2,ind_exist)=ceil(index/2);
1055                displ_num(3,ind_exist)=0;
1056                displ_num(4,ind_exist)=0;
1057                [Cte,var_detect,ichoice]=nc2struct(filename,{});
1058                if isfield(Cte,'dt2')
1059                    dt=Cte.dt2;
1060                elseif isfield(Cte,'dt')
1061                    dt=Cte.dt;
1062                end
1063                if isfield(Cte,'absolut_time_TO_2')
1064                    ref_time(ind_exist)=Cte.absolut_time_TO_2;%civ2 data used in priority
1065                elseif isfield(Cte,'absolut_time_TO')
1066                    ref_time(ind_exist)=Cte.absolut_time_TO;%civ2 data used in priorit
1067                elseif isfield(Cte,'Time')
1068                    ref_time(ind_exist)=Cte.Time;
1069                end
1070%                 if cte_detect(2)==1;
1071%                     dt=cte_read(2);
1072%                     ref_time(ind_exist)=cte_read(4);%civ2 data used in priority
1073%                 else
1074%                     dt=cte_read(1);
1075%                     ref_time(ind_exist)=cte_read(3);
1076%                 end
1077                displ_pair{ind_exist}=['Dj= ' num2str(-floor(index/2)) '|' num2str(ceil(index/2)) ' :dt= ' num2str(dt*1000) dtunit];
1078           end
1079       end
1080       set(handles.list_pair_civ,'String',[displ_pair';{'Dj=*|*'}]);
1081elseif isequal(mode,'bursts') %case of bursts
1082    for numod_a=1:nbfield2-1 %nbfield2 always >=2 for 'bursts' mode
1083        for numod_b=(numod_a+1):nbfield2
1084            [filename]=name_generator(filebase,ref_i,numod_a,'.nc',NomType,1,ref_i,numod_b,subdir)
1085            select=(exist(filename,'file')==2)
1086            if select==1
1087                ind_exist=ind_exist+1;
1088                numlist_a(ind_exist)=numod_a;
1089                numlist_b(ind_exist)=numod_b;
1090                Attr=nc2struct(filename,[]);
1091                isfield(Attr,'absolut_time_T0_2')
1092                if isfield(Attr,'dt2')
1093                   dt(ind_exist)=Attr.dt2;
1094                   ref_time(ind_exist)=Attr.absolut_time_T0_2;
1095                elseif isfield(Attr,'dt')& isfield(Attr,'absolut_time_T0')
1096                   dt(ind_exist)=Attr.dt;
1097                   ref_time(ind_exist)=Attr.absolut_time_T0;
1098                else
1099                   dt(ind_exist)=NaN;%no information on dt
1100                end
1101                %determine nom_type_ima for pair display (used in num2stra.m)
1102                switch NomType
1103                    case {'#ab'}
1104                        nom_type_ima='#a';
1105                    case {'#AB'}
1106                        nom_type_ima='#A';
1107                    otherwise
1108                         nom_type_ima='_1_1';
1109                end
1110               displ_pair{ind_exist}=['j= ' num2stra(numod_a,nom_type_ima,2) '-' num2stra(numod_b,nom_type_ima,2) ...
1111                        ' :dt= ' num2str(dt(ind_exist)*1000)];
1112            end
1113         end
1114         set(handles.list_pair_civ,'String',[displ_pair';{'j=*-*'}]);
1115     end
1116     if exist('dt','var') & ~isempty(dt)
1117         [dtsort,indsort]=sort(dt);
1118         displ_num(1,:)=numlist_a(indsort);
1119         displ_num(2,:)=numlist_b(indsort);
1120         displ_num(3,:)=0;
1121         displ_num(4,:)=0;
1122         displ_pair=displ_pair(indsort);
1123         ref_time=ref_time(indsort);
1124     end
1125end
1126if ind_exist==0
1127         if  isequal(mode,'series(Dj)') | isequal(mode,'st_series(Dj)')
1128            msgbox_uvmat('ERROR',['no .nc file available for the selected reference index j=' num2str(ref_j) ' and subdirectory ' subdir])
1129        else
1130            msgbox_uvmat('ERROR',['no .nc file available for the selected reference index i=' num2str(ref_i) ' and subdirectory ' subdir])
1131        end
1132        if isequal(mode,'bursts') %case of bursts
1133            set(handles.list_pair_civ,'String',{'j=*-*'});
1134        elseif isequal(mode,'series(Di)') %case of bursts
1135            set(handles.list_pair_civ,'String',{'Di=*|*'});
1136        elseif isequal(mode,'series(Dj)') %case of bursts
1137            set(handles.list_pair_civ,'String',{'Dj=*|*'});
1138        end
1139end
1140
1141val=get(handles.list_pair_civ,'Value');
1142if val > length(displ_pair)
1143    set(handles.list_pair_civ,'Value',1);% first pair proposed by default in the menu
1144    val=1;
1145end
1146iview=get(handles.NomType,'Value');
1147SeriesData.displ_num(iview,:)=(displ_num(:,val))';
1148SeriesData.ref_time=ref_time;
1149set(handles.series,'UserData',SeriesData)
1150list_pair_civ_Callback(hObject, eventdata, handles)
1151
1152%-------------------------------------------------------------
1153% --- Executes on selection in list_pair_civ.
1154function list_pair_civ_Callback(hObject, eventdata, handles)
1155%------------------------------------------------------------
1156
1157%update first_i and last_i according to the chosen image pairs
1158testupdate=0;
1159Val=get(handles.RootPath,'Value');
1160IndexCell=get(handles.NomType,'String');
1161SeriesData=get(handles.series,'UserData');
1162NomType=SeriesData.NomType{Val};
1163list_pair=get(handles.list_pair_civ,'String');%get the menu of image pairs
1164index_pair=get(handles.list_pair_civ,'Value');
1165str_pair=list_pair{index_pair};
1166ind_equ=strfind(str_pair,'=');%find '='
1167ind_sep=strfind(str_pair,'|');%find pair separator '|'
1168ind_com=strfind(str_pair,':');%find ':'
1169test_bursts=0;
1170if isempty(ind_sep)
1171    ind_sep=strfind(str_pair,'-');%find pair separator if it is not '|'
1172    test_bursts=1;% we are in the case of bursts
1173end
1174displ_num=[0 0 0 0]; %default
1175if ~isempty(ind_sep)&& ~strcmp(str_pair(ind_sep-1),'*')% if there is a pair separator ('|' or '-')
1176    num1_str=str_pair(ind_equ(1)+1:ind_sep-1);
1177    num2_str=str_pair(ind_sep+1:ind_com-1);
1178    num1=str2double(num1_str);
1179    num2=str2double(num2_str);
1180    if isequal(num1_str(1),' ')
1181        num1_str(1)=[];
1182    end   
1183    if isequal(num2_str(end),' ')
1184        num2_str(end)=[];
1185    end
1186    switch NomType
1187       case {'_1-2_1'}
1188           if isequal(num1_str(1),'0')
1189               IndexCell{Val}=['_(i-(i+' num2_str ')_j'];
1190           else
1191               IndexCell{Val}=['_(i' num1_str ')-(i+' num2_str ')_j'];
1192           end
1193           displ_num(3)=num1;
1194           displ_num(4)=num2;
1195       case {'_1-2'}
1196           if isequal(num1_str(1),'0')
1197               IndexCell{Val}=['_(i' num1_str ')-(i+' num2_str ')'];
1198           else
1199               IndexCell{Val}=['_(i' num1_str ')-(i+' num2_str ')'];
1200           end
1201           displ_num(3)=num1;
1202           displ_num(4)=num2;
1203       case '_1_1-2'
1204          if test_bursts
1205              IndexCell{Val}=['_i_' num1_str '-' num2_str ];
1206          else
1207              if isequal(num1_str(1),'0')
1208                 IndexCell{Val}=['_i_j-(j+' num2_str ')'];
1209              else
1210                 IndexCell{Val}=['_i_(j' num1_str ')-(j+' num2_str ')'];
1211              end
1212          end
1213          displ_num(1)=num1;
1214          displ_num(2)=num2;
1215       case {'#_ab'} %TO COMPLETE
1216           IndexCell{Val}=['_i_' num1_str '-' num2_str ];
1217
1218    end
1219end
1220set(handles.NomType,'String',IndexCell)
1221SeriesData.displ_num(Val,:)=displ_num;
1222set(handles.series,'UserData',SeriesData)
1223% set(handles.NomType,'Value',Val)
1224
1225if ~isequal(str_pair,'Dj=*|*')&~isequal(str_pair,'Di=*|*')
1226        mode_list=get(handles.mode,'String');
1227    mode_value=get(handles.mode,'Value');
1228    mode=mode_list{mode_value};
1229        if isequal(mode,'series(Di)')
1230        first_i=str2num(get(handles.first_i,'String'));
1231        last_i=str2num(get(handles.last_i,'String'));
1232        incr_i=str2num(get(handles.incr_i,'String'));
1233        num1=first_i:incr_i:last_i;
1234        lastfieldCell=get(handles.nb_field,'String');
1235        lastfield=str2num(lastfieldCell{1});
1236        if ~isempty(lastfield)
1237            ind=find((num1-floor(index_pair/2)*ones(size(num1))>0)& (num1+ceil(index_pair/2)*ones(size(num1))<=lastfield));
1238            num1=num1(ind);       
1239        end
1240        if ~isempty(num1)
1241            set(handles.first_i,'String',num2str(num1(1)));
1242            set(handles.last_i,'String',num2str(num1(end)));
1243        end
1244        testupdate=1;
1245        elseif isequal(mode,'series(Dj)')
1246        first_j=str2num(get(handles.first_j,'String'));
1247        last_j=str2num(get(handles.last_j,'String'));
1248        incr_j=str2num(get(handles.incr_j,'String'));
1249        num_j=first_j:incr_j:last_j;
1250        lastfieldCell=get(handles.nb_field2,'String');
1251        if ~isempty(lastfieldCell)
1252            lastfield2=lastfieldCell{1};
1253            ind=find((num_j-floor(index_pair/2)*ones(size(num_j))>0)& ...
1254                 (num_j+ceil(index_pair/2)*ones(size(num_j))<=lastfield2));
1255        end
1256        testupdate=1;
1257        end
1258       
1259        %update the first and last times of the series
1260        if testupdate && isfield(SeriesData,'Time')
1261        if ~isempty(SeriesData.Time{1})
1262            displ_time(handles,SeriesData.Time{1});
1263        end
1264        end
1265end
1266
1267%------------------------------------------------------------------------
1268% --- Executes on button press in RUN.
1269function RUN_Callback(hObject, eventdata, handles)
1270%------------------------------------------------------------------------
1271%read root name and field type
1272set(handles.RUN,'BusyAction','queue');
1273set(0,'CurrentFigure',handles.series)
1274if isequal(get(handles.GetObject,'Visible'),'on') && isequal(get(handles.GetObject,'Value'),1)
1275    Series.GetObject=1;
1276    GetObject_Callback(hObject, eventdata, handles)
1277else
1278    Series.GetObject=0;
1279end
1280SeriesData=get(handles.series,'UserData');
1281
1282%reinitiate waitbar position
1283Series.WaitbarPos=get(handles.waitbar_frame,'Position');%TO SUPPRESS
1284waitbarpos=Series.WaitbarPos;
1285waitbarpos(4)=0.005;%reinitialize waitbar to zero height
1286waitbarpos(2)=Series.WaitbarPos(2)+Series.WaitbarPos(4)-0.005;
1287set(handles.waitbar,'Position',waitbarpos)
1288
1289% read input file parameters and set menus
1290Series.PathProject=get(handles.PathCampaign,'String');
1291RootPath=get(handles.RootPath,'String');% path of the root name of the first field series
1292RootFile=get(handles.RootFile,'String');% root name of the first field series
1293SubDir=get(handles.SubDir,'String');% subdirectory for netcdf files
1294FileExt=get(handles.FileExt,'String');%file extension
1295if isempty(SeriesData)
1296    msgbox_uvmat('ERROR','no input file series')
1297    return
1298end
1299NomType=SeriesData.NomType;
1300if length(RootPath)==1 %string character input for user fct
1301    Series.RootPath=RootPath{1};
1302    Series.RootFile=RootFile{1};
1303    Series.SubDir=SubDir{1};
1304    Series.FileExt=FileExt{1};
1305    Series.NomType=NomType{1};
1306else %cell input for user fct
1307    Series.RootPath=RootPath;
1308    Series.RootFile=RootFile;
1309    Series.SubDir=SubDir;
1310    Series.FileExt=FileExt;
1311    Series.NomType=NomType;
1312end
1313if isequal(get(handles.FieldMenu,'Visible'),'on')
1314    FieldMenu=get(handles.FieldMenu,'String');
1315    FieldValue=get(handles.FieldMenu,'Value');
1316    Series.Field=FieldMenu(FieldValue);
1317end
1318menu_coord_state=get(handles.transform_fct,'Visible');
1319Series.CoordType='';%default
1320if isequal(menu_coord_state,'on')
1321%     menu_coord=get(handles.transform_fct,'String');
1322    menu_index=get(handles.transform_fct,'Value');
1323    transform_list=get(handles.transform_fct,'UserData');
1324    Series.transform_fct=transform_list{menu_index};% transform function handles
1325end
1326Series.hseries=handles.series; % handles to the series GUI
1327
1328%read the set of field numbers
1329first_i=str2num(get(handles.first_i,'String'));
1330last_i=str2num(get(handles.last_i,'String'));
1331incr_i=str2num(get(handles.incr_i,'String'));
1332first_j=str2num(get(handles.first_j,'String'));
1333last_j=str2num(get(handles.last_j,'String'));
1334incr_j=str2num(get(handles.incr_j,'String'));
1335if ~isequal(get(handles.first_i,'Visible'),'on')
1336   first_i=1;
1337   last_i=1;
1338   incr_i=1;
1339end
1340if ~isequal(get(handles.first_j,'Visible'),'on')
1341    first_j=1;
1342    last_j=1;
1343    incr_j=1;
1344end
1345Series.NbSlice=str2num(get(handles.NbSlice,'String'));
1346if isequal(first_i,[])|isequal(first_j,[]), msgbox_uvmat('ERROR','first field number not defined'),...
1347    set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
1348if isequal(last_i,[])| isequal(last_j,[]),msgbox_uvmat('ERROR','last field number not defined'),...
1349    set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
1350if isequal(incr_i,[])| isequal(incr_j,[]),msgbox_uvmat('ERROR','increment in field number not defined'),...
1351    set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
1352if last_i < first_i | last_j < first_j , msgbox_uvmat('ERROR','last field number must be larger than the first one'),...
1353    set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
1354num_i=first_i:incr_i:last_i;
1355num_j=first_j:incr_j:last_j;
1356nbfield_cell=get(handles.nb_field,'String');
1357nbfield=[]; %default
1358for iview=1:length(nbfield_cell)
1359    nb=str2num(nbfield_cell{iview});
1360    if ~isempty(nb)
1361        nbfield=[nbfield nb];
1362    end
1363end
1364nbfield=min(nbfield);
1365nbfield2_cell=get(handles.nb_field2,'String');
1366nbfield2=[]; %default
1367for iview=1:length(nbfield2_cell)
1368    nb=str2num(nbfield2_cell{iview});
1369    if ~isempty(nb)
1370        nbfield2=[nbfield2 nb];
1371    end
1372end
1373nbfield2=min(nbfield2);
1374
1375%get complementary information from the 'series' interface
1376list_action=get(handles.ACTION,'String');% list menu action
1377index_action=get(handles.ACTION,'Value');% selected string index
1378action= list_action{index_action}; % selected string
1379mode_list=get(handles.mode,'String');
1380index_mode=get(handles.mode,'Value');
1381mode=mode_list{index_mode};
1382ind_shift=0;%default
1383
1384%determine the list of input file names
1385nbmissing=0;
1386for iview=1:length(RootPath)
1387    %case of pairs (.nc files)
1388   
1389    if isequal(NomType{iview},'_1_1-2')|| isequal(NomType{iview},'_1-2_1')|| isequal(NomType{iview},'_1-2')|| isequal(NomType{iview},'#_ab')
1390        ind_shift=SeriesData.displ_num(iview,:);
1391        if isequal(ind_shift,[0 0 0 0]) % undefined pairs
1392            if isequal(NomType{iview},'#_ab')
1393                mode='#_ab';
1394            end
1395            [num_i1,num_i2,num_j1,num_j2,nbmissing]=netseries_generator(fullfile(RootPath{iview},RootFile{iview}),SubDir{iview},mode,first_i,incr_i,last_i,first_j,incr_j,last_j);
1396        else   
1397            [num_i1,num_i2,num_j1,num_j2,num_i,num_j]=find_file_indices(num_i,num_j,ind_shift,NomType{iview},mode);
1398            if isempty(num_i)
1399                msgbox_uvmat('ERROR','ERROR: empty set of input files chosen')
1400                return
1401            end
1402            if num_i(1)>first_i
1403               set(handles.first_i,'String',num2str(num_i(1)))%update the display of first field
1404               last_i_Callback(hObject, eventdata, handles)
1405            end
1406            if num_i(end)<last_i
1407               set(handles.last_i,'String',num2str(num_i(end)))%update the display of last field
1408               last_i_Callback(hObject, eventdata, handles)
1409            end
1410            if num_j(1)>first_j
1411               set(handles.first_j,'String',num2str(num_j(1)))%update the display of first field
1412               last_j_Callback(hObject, eventdata, handles)
1413            end
1414            if num_j(end)<last_j
1415               set(handles.last_j,'String',num2str(num_j(end)))%update the display of last field
1416               last_j_Callback(hObject, eventdata, handles)
1417            end
1418        end
1419    else%case of images
1420        [num_i1,num_j1]=meshgrid(num_i,num_j);
1421        num_i2=num_i1;
1422        num_j2=num_j1;
1423    end
1424    if length(RootPath)>1
1425        num_i1_cell{iview}=num_i1;
1426        num_i2_cell{iview}=num_i2;
1427        num_j1_cell{iview}=num_j1;
1428        num_j2_cell{iview}=num_j2;
1429    end
1430end
1431
1432% defining the ACTION function handle
1433path_series=which('series');
1434list_path=get(handles.ACTION,'UserData');
1435index=get(handles.ACTION,'Value');
1436fct_path=list_path{index}; %path stored for the function ACTION
1437if ~isequal(fct_path,path_series)
1438    eval(['spath=which(''' action ''');']) %spath = current path of the selected function ACTION
1439    if ~exist(fct_path,'dir')
1440        msgbox_uvmat('ERROR',['The prescibed function path ' fct_path ' does not exist'])
1441        return
1442    end
1443    if ~isequal(spath,fct_path)
1444        addpath(fct_path)% add the prescribed path if not the current one
1445    end
1446end
1447eval(['h_fun=@' action ';'])%create a function handle for ACTION
1448if ~isequal(fct_path,path_series)
1449        rmpath(fct_path)% add the prescribed path if not the current one   
1450end
1451
1452% RUN ACTION
1453Series.Action=action;%name of the processing programme
1454set(handles.RUN,'BackgroundColor',[0.831 0.816 0.784])
1455
1456if length(RootPath)>1
1457    h_fun(num_i1_cell,num_i2_cell,num_j1_cell,num_j2_cell,Series);
1458else
1459    h_fun(num_i1,num_i2,num_j1,num_j2,Series);
1460end
1461set(handles.RUN,'BackgroundColor',[1 0 0])
1462
1463% %save the current interface setting as figure namefig, append .0 to the name if it already exists
1464% detect=1;
1465% while detect==1
1466%     namefigfull=[namedoc '.fig'];
1467%     hh=dir(namefigfull);
1468%     if ~isempty(hh)
1469%         detect=1;
1470%         namedoc=[namedoc '.0'];
1471%     else
1472%         detect=0;
1473%     end
1474% end
1475% saveas(gcbf,namefigfull);%save the interface with name namefigfull (A CHANGER EN FICHIER  .xml)
1476
1477%------------------------------------------------------------------------
1478function STOP_Callback(hObject, eventdata, handles)
1479%------------------------------------------------------------------------
1480set(handles.RUN, 'BusyAction','cancel')
1481set(handles.RUN,'BackgroundColor',[1 0 0])
1482
1483
1484%------------------------------------------------------------------------
1485function first_i_Callback(hObject, eventdata, handles)
1486%------------------------------------------------------------------------
1487last_i_Callback(hObject, eventdata, handles)
1488
1489%------------------------------------------------------------------------
1490function last_i_Callback(hObject, eventdata, handles)
1491%------------------------------------------------------------------------
1492SeriesData=get(handles.series,'UserData');
1493if ~isfield(SeriesData,'Time')
1494    SeriesData.Time{1}=[];
1495end
1496displ_time(handles,SeriesData.Time{1});
1497
1498%------------------------------------------------------------------------
1499function first_j_Callback(hObject, eventdata, handles)
1500%------------------------------------------------------------------------
1501 last_j_Callback(hObject, eventdata, handles)
1502
1503%------------------------------------------------------------------------
1504function last_j_Callback(hObject, eventdata, handles)
1505%------------------------------------------------------------------------
1506first_j=str2num(get(handles.first_j,'String'));
1507last_j=str2num(get(handles.last_j,'String'));
1508ref_j=ceil((first_j+last_j)/2);
1509set(handles.ref_j,'String', num2str(ref_j))
1510ref_j_Callback(hObject, eventdata, handles)
1511SeriesData=get(handles.series,'UserData');
1512if ~isfield(SeriesData,'Time')
1513    SeriesData.Time{1}=[];
1514end
1515displ_time(handles,SeriesData.Time{1});
1516
1517
1518%------------------------------------------------------------------------
1519function ref_i_Callback(hObject, eventdata, handles)
1520%------------------------------------------------------------------------
1521mode_list=get(handles.mode,'String');
1522mode_value=get(handles.mode,'Value');
1523mode=mode_list{mode_value};
1524SeriesData=get(handles.series,'UserData');
1525%NomTypeCell=get(handles.NomType,'String');
1526NomTypeCell=SeriesData.NomType;
1527if ~isempty(NomTypeCell)
1528Val=get(handles.NomType,'Value');
1529NomType=NomTypeCell{Val};
1530% for ilist=1:length(NomType)
1531    if isequal(NomType,'_1_1-2')|| isequal(NomType,'_1-2_1')|| isequal(NomType,'_1-2')
1532        if isequal(mode,'series(Di)')
1533            find_netcpair_civ(hObject, eventdata, handles,Val);% update the menu of pairs depending on the available netcdf files
1534%             break
1535        end
1536    end
1537end
1538
1539%------------------------------------------------------------------------
1540function ref_j_Callback(hObject, eventdata, handles)
1541%------------------------------------------------------------------------
1542mode_list=get(handles.mode,'String');
1543mode_value=get(handles.mode,'Value');
1544mode=mode_list{mode_value};
1545SeriesData=get(handles.series,'UserData');
1546NomTypeCell=SeriesData.NomType;
1547if ~isempty(NomTypeCell)
1548    Val=get(handles.NomType,'Value');
1549    NomType=NomTypeCell{Val};
1550    if isequal(NomType,'_1_1-2')|| isequal(NomType,'_1-2_1')|| isequal(NomType,'_1-2')
1551        if isequal(mode,'series(Dj)')
1552            find_netcpair_civ(hObject, eventdata, handles,Val);% update the menu of pairs depending on the available netcdf files
1553        end
1554    end
1555end
1556
1557%------------------------------------------------------------------------
1558% --- Executes on selection change in ACTION.
1559function ACTION_Callback(hObject, eventdata, handles)
1560%------------------------------------------------------------------------
1561global nb_builtin_ACTION
1562list_ACTION=get(handles.ACTION,'String');% list menu fields
1563index_ACTION=get(handles.ACTION,'Value');% selected string index
1564ACTION= list_ACTION{index_ACTION}; % selected function name
1565path_series=which('series');%path to series.m
1566list_path=get(handles.ACTION,'UserData');%list of recorded paths to functions of the list ACTION
1567default_file=fullfile(list_path{end},ACTION);
1568% add a new function to the menu if the selected item is 'more...'
1569if isequal(ACTION,'more...')
1570    pathfct=fileparts(path_series);
1571    [FileName, PathName, filterindex] = uigetfile( ...
1572       {'*.m', ' (*.m)';
1573        '*.m',  '.m files '; ...
1574        '*.*', 'All Files (*.*)'}, ...
1575        'Pick a file',default_file);
1576    if length(FileName)<2
1577        return
1578    end
1579    [pp,ACTION,ext_fct]=fileparts(FileName);%(end-1:end);
1580    if ~isequal(ext_fct,'.m')
1581        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
1582        return
1583    end
1584   
1585   % insert the choice in the action menu
1586   menu_str=update_menu(handles.ACTION,ACTION);%new action menu in which the new item has been appended if needed
1587   index_ACTION=get(handles.ACTION,'Value');% currently selected index in the list
1588   list_path{index_ACTION}=PathName;
1589   if length(menu_str)>nb_builtin_ACTION+5; %nb_builtin=nbre of functions always remaining in the initial menu
1590       nbremove=length(menu_str)-nb_builtin_ACTION-5;
1591       menu_str(nb_builtin_ACTION+1:end-5)=[];
1592       list_path(nb_builtin_ACTION+1:end-4)=[];
1593       index_ACTION=index_ACTION-nbremove;
1594       set(handles.ACTION,'Value',index_ACTION)
1595       set(handles.ACTION,'String',menu_str)
1596   end
1597   list_path{index_ACTION}=PathName;
1598   set(handles.ACTION,'UserData',list_path);
1599   set(handles.path,'enable','inactive')% indicate that the current path is accessible (not 'off')
1600   
1601   %record the current menu in personal file profil_perso
1602   dir_perso=prefdir;
1603   profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
1604   for ilist=nb_builtin_ACTION+1:length(menu_str)-1
1605       series_fct{ilist-nb_builtin_ACTION}=fullfile(list_path{ilist},[menu_str{ilist} '.m']);     
1606   end
1607   if nb_builtin_ACTION+1<=length(menu_str)-1
1608       if exist(profil_perso,'file')% && nb_builtin_ACTION+1>=length(menu_str)-1
1609           save(profil_perso,'series_fct','-append')
1610       else
1611           txt=ver('MATLAB');
1612           Release=txt.Release;
1613           relnumb=str2num(Release(3:4));
1614           if relnumb >= 14%recent relaese of Matlab
1615               save(profil_perso,'series_fct','-V6')
1616           else
1617               save(profil_perso, 'series_fct')
1618           end
1619       end
1620   end
1621end
1622
1623%check the current path to the selected function
1624PathName=list_path{index_ACTION};%current recorded path
1625set(handles.path,'String',PathName); %show the path to the senlected function
1626
1627%default setting for the visibility of the GUI elements
1628set(handles.RootPath,'UserData','many')
1629set(handles.SubDir,'Visible','on')
1630set(handles.RootFile,'Visible','on')
1631set(handles.NomType,'Visible','on')
1632set(handles.FileExt,'Visible','on')
1633set(handles.NbSlice,'Visible','off')
1634set(handles.NbSlice_title,'Visible','off')
1635set(handles.VelTypeMenu,'Visible','off');
1636set(handles.VelType_text,'Visible','off');
1637set(handles.VelTypeMenu_1,'Visible','off');
1638set(handles.VelType_text_1,'Visible','off');
1639view_FieldMenu(handles,'off')
1640view_FieldMenu_1(handles,'off')
1641view_TRANSFORM(handles,'off')
1642set(handles.ProjObject_frame,'Visible','off');
1643set(handles.GetMask,'Visible','off')
1644set(handles.Mask,'Visible','off')
1645set(handles.GetObject,'Visible','off');
1646set(handles.ProjObject,'Visible','off');
1647set(handles.OutputDir,'Visible','off');
1648set(handles.PARAMETERS_frame,'Visible','off');
1649set(handles.PARAMETERS_title,'Visible','off');
1650set(handles.ParamKey,'Visible','off')
1651set(handles.ParamVal,'Visible','off')
1652ParamKey={};
1653set(handles.FieldMenu,'Enable','off')
1654set(handles.VelTypeMenu,'Enable','off')
1655set(handles.FieldMenu_1,'Enable','off')
1656set(handles.VelTypeMenu_1,'Enable','off')
1657set(handles.transform_fct,'Enable','off')
1658%set the displayed GUI item needed for input parameters
1659if ~isequal(path_series,PathName)
1660    addpath(PathName)
1661end
1662eval(['h_function=@' ACTION ';']);
1663try
1664    [fid,errormsg] =fopen([ACTION '.m']);
1665    InputText=textscan(fid,'%s',1,'delimiter','\n');
1666    fclose(fid)
1667    set(handles.ACTION,'ToolTipString',InputText{1}{1})
1668end
1669if ~isequal(path_series,PathName)
1670    rmpath(PathName)
1671end
1672varargout=h_function();
1673Param_list={};
1674
1675%nb_series=length(RootFile);
1676FileExt=get(handles.FileExt,'String');
1677nb_series=length(FileExt);
1678testima_series=1; %test for a list of images only
1679testima=1;
1680testima_1=1;
1681testciv_series=1;
1682for iview=1:nb_series
1683    ext=FileExt{iview};
1684    if length(ext)<2
1685        ext='.none';
1686    end
1687    testimaview=~isempty(imformats(ext(2:end))) || isequal(lower(ext),'.avi');
1688    if ~testimaview
1689        if iview==1
1690            testima=0;
1691        end
1692        if iview==2
1693            testima_1=0;
1694        end
1695        testima_series=0;
1696    end
1697end
1698for ilist=1:length(varargout)-1
1699    switch varargout{ilist}
1700                       %RootFile always visible
1701         case 'RootPath'   %visible by default
1702            value=lower(varargout{ilist+1});
1703            if isequal(value,'one')||isequal(value,'two')||isequal(value,'many')
1704                set(handles.RootFile,'UserData',value)% for use in menu Open_insert
1705            end
1706        case 'SubDir' %visible by default
1707            if isequal(lower(varargout{ilist+1}),'off')
1708                set(handles.SubDir,'Visible','off')
1709            end
1710        case 'RootFile'   %visible by default
1711            value=lower(varargout{ilist+1});
1712            if isequal(value,'off')
1713                set(handles.RootFile,'Visible','off')
1714            elseif isequal(value,'one')||isequal(value,'two')||isequal(value,'many')
1715                set(handles.RootFile,'Visible','on')
1716                set(handles.RootFile,'UserData',value)% for use in menu Open_insert
1717            end
1718        case 'NomType'   %visible by default
1719            if isequal(lower(varargout{ilist+1}),'off')
1720                set(handles.NomType,'Visible','off')
1721            end
1722        case 'FileExt'   %visible by default
1723            if isequal(lower(varargout{ilist+1}),'off')
1724                set(handles.FileExt,'Visible','off')
1725            end
1726        case 'NbSlice'   %hidden by default
1727            if isequal(lower(varargout{ilist+1}),'on')
1728                set(handles.NbSlice,'Visible','on')
1729                set(handles.NbSlice_title,'Visible','on')
1730            end
1731        case 'VelTypeMenu'   %hidden by default
1732            if isequal(lower(varargout{ilist+1}),'one') || isequal(lower(varargout{ilist+1}),'two')
1733                set(handles.VelTypeMenu,'Enable','on')
1734                if nb_series >=1 && ~testima_series
1735                    set(handles.VelTypeMenu,'Visible','on')
1736                    set(handles.VelType_text,'Visible','on');
1737                    set(handles.Field_frame,'Visible','on')
1738                end
1739            end
1740            if isequal(lower(varargout{ilist+1}),'two')
1741                set(handles.VelTypeMenu_1,'Enable','on')
1742                if nb_series >=2 && ~testima_series
1743                    set(handles.VelTypeMenu_1,'Visible','on')
1744                    set(handles.VelType_text_1,'Visible','on');
1745                end
1746            end
1747        case 'FieldMenu'   %hidden by default
1748            if isequal(lower(varargout{ilist+1}),'one')||isequal(lower(varargout{ilist+1}),'two')
1749                set(handles.FieldMenu,'Enable','on') % test for MenuBorser
1750                if nb_series >=1 && ~testima_series
1751                    view_FieldMenu(handles,'on')
1752                end
1753            end
1754            if isequal(lower(varargout{ilist+1}),'two')
1755                set(handles.FieldMenu_1,'Enable','on')
1756                if nb_series >=2 && ~testima_1
1757                    view_FieldMenu_1(handles,'on')
1758                end
1759            end
1760        case 'CoordType'   %hidden by default
1761            if isequal(lower(varargout{ilist+1}),'on')
1762                set(handles.transform_fct,'Enable','on')
1763                view_TRANSFORM(handles,'on')
1764            end
1765        case 'GetObject'   %hidden by default
1766            if isequal(lower(varargout{ilist+1}),'on')   
1767                set(handles.ProjObject_frame,'Visible','on')
1768                set(handles.GetObject,'Visible','on');
1769            end
1770        case 'Mask'   %hidden by default
1771            if isequal(lower(varargout{ilist+1}),'on')   
1772                set(handles.ProjObject_frame,'Visible','on')
1773                set(handles.GetMask,'Visible','on');
1774            end
1775        case 'PARAMETER' 
1776            set(handles.PARAMETERS_frame,'Visible','on')
1777            set(handles.PARAMETERS_title,'Visible','on')
1778            set(handles.ParamKey,'Visible','on')
1779            %set(handles.ParamVal,'Visible','on')
1780            Param_str=varargout{ilist+1};
1781            Param_list=[Param_list; {Param_str}];         
1782    end
1783end
1784if ~isempty(Param_list)
1785    set(handles.ParamKey,'String',Param_list)
1786    set(handles.ParamVal,'Visible','on')
1787end
1788
1789%------------------------------------------------------------------------
1790% --- Executes on selection change in FieldMenu.
1791function FieldMenu_Callback(hObject, eventdata, handles)
1792%------------------------------------------------------------------------
1793field_str=get(handles.FieldMenu,'String');
1794field_index=get(handles.FieldMenu,'Value');
1795field=field_str{field_index(1)};
1796if isequal(field,'get_field...')   
1797     hget_field=findobj(allchild(0),'name','get_field');
1798     if ~isempty(hget_field)
1799         delete(hget_field)%delete opened versions of get_field
1800     end
1801     SeriesData=get(handles.series,'UserData');
1802     filename=SeriesData.CurrentInputFile;
1803     if exist(filename,'file')
1804        get_field(filename)
1805     end
1806elseif isequal(field,'more...')
1807    str=calc_field;
1808    [ind_answer,v] = listdlg('PromptString','Select a file:',...
1809                'SelectionMode','single',...
1810                'ListString',str);
1811       % edit the choice in the fields and action menu
1812     scalar=cell2mat(str(ind_answer));
1813     update_menu(handles.FieldMenu,scalar)
1814end
1815
1816%------------------------------------------------------------------------
1817% --- Executes on selection change in FieldMenu_1.
1818function FieldMenu_1_Callback(hObject, eventdata, handles)
1819%------------------------------------------------------------------------
1820field_str=get(handles.FieldMenu_1,'String');
1821field_index=get(handles.FieldMenu_1,'Value');
1822field=field_str{field_index};
1823if isequal(field,'get_field...')   
1824     hget_field=findobj(allchild(0),'name','get_field_1');
1825     if ~isempty(hget_field)
1826         delete(hget_field)
1827     end
1828     SeriesData=get(handles.series,'UserData');
1829     filename=SeriesData.CurrentInputFile_1;
1830     if exist(filename,'file')
1831        hget_field=get_field(filename);
1832        set(hget_field,'name','get_field_1')
1833     end
1834elseif isequal(field,'more...')
1835    str=calc_field;
1836    [ind_answer,v] = listdlg('PromptString','Select a file:',...
1837                'SelectionMode','single',...
1838                'ListString',str);
1839       % edit the choice in the fields and action menu
1840     scalar=cell2mat(str(ind_answer));
1841     update_menu(handles.FieldMenu_1,scalar)
1842end   
1843
1844
1845%%%%%%%%%%%%%
1846function [ind_remove]=find_pairs(dirpair,ind_i,last_i)
1847
1848        indsel=ind_i;
1849        indiff=diff(ind_i); %test index increment to detect multiplets (several pairs with the same index ind_i) and holes in the series
1850        indiff=[1 indiff last_i-ind_i(end)+1];%for testing gaps with the imposed bounds
1851        if ~isempty(indiff)
1852            indiff2=diff(indiff);
1853            indiffp=[indiff2 1];
1854            indiffm=[1 indiff2];
1855            ind_multi_m=find((indiff==0)&(indiffm<0))-1;%indices of first members of multiplets
1856            ind_multi_p=find((indiff==0)&(indiffp>0));%indices of last members of multiplets
1857                %for each multiplet, select the most recent file
1858            ind_remove=[];
1859            for i=1:length(ind_multi_m)
1860                ind_pairs=ind_multi_m(i):ind_multi_p(i);
1861                for imulti=1:length(ind_pairs)
1862                    datepair(imulti)=datenum(dirpair(ind_pairs(imulti)).date);%dates of creation
1863                end
1864                [datenew,indsort2]=sort(datepair); %sort the multiplet by creation date
1865                ind_s=indsort2(1:end-1);%
1866                ind_remove=[ind_remove ind_pairs(ind_s)];%remove these indices, leave the last one
1867            end
1868        end
1869
1870%------------------------------------------------------------------------
1871% --- determine the list of index pairs of processing file
1872function [num_i1,num_i2,num_j1,num_j2,num_i_out,num_j_out]=find_file_indices(num_i,num_j,ind_shift,NomType,mode)
1873%------------------------------------------------------------------------
1874num_i1=num_i;% set of first image numbers by default
1875num_i2=num_i;
1876num_j1=num_j;
1877num_j2=num_j;
1878num_i_out=num_i;
1879num_j_out=num_j;
1880if isequal (NomType,'_1-2_1') || isequal (NomType,'_1-2')
1881    num_i1_line=num_i+ind_shift(3);% set of first image numbers
1882    num_i2_line=num_i+ind_shift(4);
1883    % adjust the first and last field number
1884        indsel=find(num_i1_line >= 1);
1885    num_i_out=num_i(indsel);
1886    num_i1_line=num_i1_line(indsel);
1887    num_i2_line=num_i2_line(indsel);
1888    num_j1=meshgrid(num_j,ones(size(num_i1_line)));
1889    num_j2=meshgrid(num_j,ones(size(num_i1_line)));
1890    [xx,num_i1]=meshgrid(num_j,num_i1_line);
1891    [xx,num_i2]=meshgrid(num_j,num_i2_line);
1892elseif isequal (NomType,'_1_1-2') || isequal (NomType,'#_ab')
1893    if isequal(mode,'bursts') %case of bursts (png_old or png_2D)
1894        num_j1=ind_shift(1)*ones(size(num_i));
1895        num_j2=ind_shift(2)*ones(size(num_i));
1896    else
1897        num_j1_col=num_j+ind_shift(1);% set of first image numbers
1898        num_j2_col=num_j+ind_shift(2);
1899        % adjust the first field number
1900        indsel=find((num_j1_col >= 1));   
1901        num_j_out=num_j(indsel);
1902        num_j1_col=num_j1_col(indsel);
1903        num_j2_col=num_j2_col(indsel);
1904        [num_i1,num_j1]=meshgrid(num_i,num_j1_col);
1905        [num_i2,num_j2]=meshgrid(num_i,num_j2_col);
1906    end   
1907end
1908
1909%------------------------------------------------------------------------
1910% ---- find the times corresponding to the first and last indices of a series
1911function displ_time(handles,times)
1912%------------------------------------------------------------------------
1913SeriesData=get(handles.series,'UserData');%
1914first_i=str2num(get(handles.first_i,'String'));
1915first_j=str2num(get(handles.first_j,'String'));
1916last_i=str2num(get(handles.last_i,'String'));
1917last_j=str2num(get(handles.last_j,'String'));
1918NomType=SeriesData.NomType;
1919mode_list=get(handles.mode,'String');
1920index_mode=get(handles.mode,'Value');
1921mode=mode_list{index_mode};
1922
1923time_first=[];
1924time_last=[];
1925if ~isfield(SeriesData,'Time')
1926    SeriesData.Time{1}=[];
1927end
1928for iview=1:length(NomType)
1929    time_first_cell{iview}='?';
1930    time_last_cell{iview}='?';%default
1931    time=SeriesData.Time{iview};
1932    if isequal(NomType{iview},'_1-2_1')|isequal(NomType{iview},'_1_1-2')|isequal(NomType{iview},'#_ab')|isequal(NomType{iview},'_1-2')
1933        if isfield(SeriesData,'displ_num')& ~isempty(SeriesData.displ_num)
1934            ind_shift=SeriesData.displ_num(iview,:);
1935            if isequal(mode,'bursts')
1936                first_j=0;
1937                last_j=0;
1938            end
1939            first_i1=first_i +ind_shift(3);
1940            first_i2 =first_i +ind_shift(4);
1941            first_j1 =first_j +ind_shift(1);
1942            first_j2 =first_j +ind_shift(2);
1943            last_i1=last_i +ind_shift(3);
1944            last_i2 =last_i +ind_shift(4);   
1945            last_j1 =last_j +ind_shift(1);
1946            last_j2 =last_j +ind_shift(2);
1947            siz=size(SeriesData.Time{1});
1948            if first_i1>=1 && first_j1>=1 && siz(1)>=last_i2 && siz(2)>=last_j2
1949                time_first=(time(first_i1,first_j1)+time(first_i2,first_j2))/2;
1950                time_last=(time(last_i1,last_j1)+time(last_i2,last_j2))/2;
1951            else%read the time in the nc files
1952                RootPath=get(handles.RootPath,'String');
1953                RootFile=get(handles.RootFile,'String');
1954                SubDir=get(handles.SubDir,'String');
1955                %VelType=get(handles.VelType,'String');
1956                VelType_str=get(handles.VelTypeMenu,'String');
1957                VelType_val=get(handles.VelTypeMenu,'Value');
1958                VelType=VelType_str{VelType_val};
1959                filebase=fullfile(RootPath{1},RootFile{1});
1960                [filefirst]=name_generator(filebase,first_i1,first_j1,'.nc',NomType{iview},1,first_i2,first_j2,SubDir{iview});
1961                if  exist(filefirst,'file')
1962                    Attrib=nc2struct(filefirst,[]);
1963                    if isfield(Attrib,'Time')
1964                        time_first=Attrib.Time;
1965                    else
1966                        if isfield(Attrib,'absolut_time_T0')
1967                            time_first=Attrib.absolut_time_T0;
1968                        end
1969                        if isfield(Attrib,'absolut_time_T0_2')&&~(isequal(VelType,'civ1')||isequal(VelType,'interp1')||isequal(VelType,'filter1'))
1970                            time_first=Attrib.absolut_time_T0_2;
1971                        end
1972                    end
1973                end
1974                [filelast]=name_generator(filebase,last_i1,last_j1,'.nc',NomType{iview},1,last_i2,last_j2,SubDir{iview});
1975                if exist(filelast,'file')
1976                   Attrib=nc2struct(filelast,[]);
1977                    if isfield(Attrib,'Time')
1978                        time_last=Attrib.Time;
1979                    else
1980                        if isfield(Attrib,'absolut_time_T0')
1981                            time_last=Attrib.absolut_time_T0;
1982                        end
1983                        if isfield(Attrib,'absolut_time_T0_2')&&~(isequal(VelType,'civ1')||isequal(VelType,'interp1')||isequal(VelType,'filter1'))
1984                            time_last=Attrib.absolut_time_T0_2;
1985                        end
1986                    end
1987                end
1988            end
1989        end
1990    else
1991        siz=size(times);
1992        if siz(1)>=last_i && siz(2)>=last_j && first_i>=1 && first_j>=1
1993            time_first=times(first_i,first_j);
1994            time_last=times(last_i,last_j);
1995        end
1996    end
1997    time_first_cell{iview}=num2str(time_first,4);
1998    time_last_cell{iview}=num2str(time_last,4);
1999end
2000set(handles.time_first,'Value',1)
2001set(handles.time_last,'Value',1)
2002set(handles.time_first,'String',time_first_cell);
2003set(handles.time_last,'String',time_last_cell);
2004
2005%------------------------------------------------------------------------
2006% --- Executes on button press in GetObject.
2007function GetObject_Callback(hObject, eventdata, handles)
2008%------------------------------------------------------------------------
2009SeriesData=get(handles.series,'UserData');
2010value=get(handles.GetObject,'Value');
2011if value
2012     set(handles.GetObject,'BackgroundColor',[1 1 0])%put unactivated buttons to yellow
2013%      DataInit.ParentButton=handles.GetObject;
2014     hset_object=findobj(allchild(0),'tag','set_object');%find the set_object interface handle
2015     if ishandle(hset_object)
2016         uistack(hset_object,'top')
2017        %[SeriesData.hset_object,SeriesData.sethandles]=set_object(DataInit); %open the set_object interface
2018     else
2019         %get the object file
2020         defaultname=get(handles.RootPath,'String');
2021         if isempty(defaultname)
2022            defaultname={''};
2023         end
2024        [FileName, PathName, filterindex] = uigetfile( ...
2025       {'*.xml;*.mat', ' (*.xml,*.mat)';
2026       '*.xml',  '.xml files '; ...
2027        '*.mat',  '.mat matlab files '}, ...
2028        'Pick an xml object file (or use uvmat to create it)',defaultname{1});
2029        fileinput=[PathName FileName];%complete file name
2030        testblank=findstr(fileinput,' ');%look for blanks
2031        if ~isempty(testblank)
2032            msgbox_uvmat('ERROR','forbidden input file name: contain blanks')
2033            return
2034        end
2035        sizf=size(fileinput);
2036        if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end
2037        %read the file
2038        t=xmltree(fileinput);
2039        data=convert(t);
2040        if ~isfield(data,'Style')
2041             data.Style='points';
2042        end
2043        if ~isfield(data,'ProjMode')
2044             data.ProjMode='projection';
2045        end
2046        transform_menu=get(handles.transform_fct,'String');
2047        ichoice=get(handles.transform_fct,'Value');
2048%         if isequal(transform_menu{ichoice},'px');
2049%             data.CoordType='px';
2050%         else
2051%             data.CoordType='phys';
2052%         end
2053        data.desable_plot=1;
2054        [SeriesData.hset_object,SeriesData.sethandles]=set_object(data);% call the set_object interface
2055     end
2056else
2057    set(handles.GetObject,'BackgroundColor',[0.7 0.7 0.7])%put activated buttons to green
2058%     if isfield(SeriesData,'hset_object')&& ishandle(SeriesData.hset_object)
2059%         close(SeriesData.hset_object)
2060%     end
2061end
2062set(handles.series,'UserData',SeriesData)
2063
2064%--------------------------------------------------------------
2065function GetMask_Callback(hObject, eventdata, handles)
2066value=get(handles.GetMask,'Value');
2067if value
2068    msgbox_uvmat('ERROR','not implemented yet')
2069end
2070%--------------------------------------------------------------
2071
2072%-------------------------------------------------------------------
2073%'uv_ncbrowser': interactively calls the netcdf file browser 'get_field.m'
2074function ncbrowser_uvmat(hObject, eventdata)
2075%-------------------------------------------------------------------
2076     bla=get(gcbo,'String');
2077     ind=get(gcbo,'Value');
2078     filename=cell2mat(bla(ind));
2079      blank=find(filename==' ');
2080      filename=filename(1:blank-1);
2081     get_field(filename)
2082
2083% ------------------------------------------------------------------
2084function MenuHelp_Callback(hObject, eventdata, handles)
2085%-------------------------------------------------------------------
2086path_to_uvmat=which ('uvmat');% check the path of uvmat
2087pathelp=fileparts(path_to_uvmat);
2088helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html');
2089if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package')
2090else
2091    addpath (fullfile(pathelp,'uvmat_doc'))
2092    web([helpfile '#series'])
2093end
2094
2095%-------------------------------------------------------------------
2096% --- Executes on selection change in transform_fct.
2097function transform_fct_Callback(hObject, eventdata, handles)
2098%-------------------------------------------------------------------
2099global nb_transform
2100
2101menu=get(handles.transform_fct,'String');
2102ind_coord=get(handles.transform_fct,'Value');
2103coord_option=menu{ind_coord};
2104list_transform=get(handles.transform_fct,'UserData');
2105ff=functions(list_transform{end});
2106if isequal(coord_option,'more...');
2107    coord_fct='';
2108    prompt = {'Enter the name of the transform function'};
2109    dlg_title = 'user defined transform';
2110    num_lines= 1;
2111    [FileName, PathName, filterindex] = uigetfile( ...
2112       {'*.m', ' (*.m)';
2113        '*.m',  '.m files '; ...
2114        '*.*', 'All Files (*.*)'}, ...
2115        'Pick a file', ff.file);
2116    if isequal(PathName(end),'/')||isequal(PathName(end),'\')
2117        PathName(end)=[];
2118    end
2119    transform_selected =fullfile(PathName,FileName);
2120    if ~exist(transform_selected,'file')
2121          return
2122    end
2123    [ppp,transform,xt_fct]=fileparts(FileName);% removes extension .m
2124    if ~isequal(ext_fct,'.m')
2125        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
2126        return
2127    end
2128   menu=update_menu(handles.transform_fct,transform);%add the selected fct to the menu
2129   ind_coord=get(handles.transform_fct,'Value');
2130   addpath(PathName)
2131   list_transform{ind_coord}=str2func(transform);% create the function handle corresponding to the newly seleced function
2132   set(handles.transform_fct,'UserData',list_transform)
2133   rmpath(PathName)
2134   % save the new menu in the personal file 'uvmat_perso.mat'
2135   dir_perso=prefdir;%personal Matalb directory
2136   profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
2137   if exist(profil_perso,'file')
2138       for ilist=nb_transform+1:numel(list_transform)
2139           ff=functions(list_transform{ilist});
2140           transform_fct{ilist-nb_transform}=ff.file;
2141       end
2142        save (profil_perso,'transform_fct','-append'); %store the root name for future opening of uvmat
2143   end
2144end
2145
2146%check the current path to the selected function
2147if ~isempty(list_transform{ind_coord})
2148func=functions(list_transform{ind_coord});
2149set(handles.path_transform,'String',fileparts(func.file)); %show the path to the senlected function
2150else
2151   set(handles.path_transform,'String',''); %show the path to the senlected function
2152end
2153%------------------------------------------------------------------------
2154% --- generates a series of file names with reference numbers between range1 and
2155% --- range2 with increment incr. The reference number num_ref is the image number at the middle of the
2156% --- image pair. The set of first numbers num1 of the image pairs is also
2157% --- given as output
2158function [num_i1,num_i2,num_j1,num_j2,nbmissing]=netseries_generator(filebase,subdir,mode,first_i,incr_i,last_i,first_j,incr_j,last_j)
2159%------------------------------------------------------------------------
2160[Path,Name]=fileparts(filebase);
2161filebasesub=fullfile(Path,subdir,Name);
2162filecell={};%default
2163num_i1=[];
2164num_i2=[];
2165num_j1=[];
2166num_j2=[];
2167ind0_i=first_i:incr_i:last_i;
2168nbcolumn=length(ind0_i);
2169ind0_j=first_j:incr_j:last_j;
2170nbline=length(ind0_j);
2171if isequal(mode,'#_ab')
2172    dirpair=dir([filebasesub '*_*.nc']);
2173elseif isequal(mode,'bursts')||isequal(mode,'series(Dj)') 
2174    dirpair=dir([filebasesub '_*_*-*.nc']);
2175elseif isequal(mode,'series(Di)')
2176    dirpair=dir([filebasesub '_*-*_*.nc']);
2177else
2178    msgbox_uvmat('ERROR','option *|* not yet implemented')
2179    return
2180end
2181if isempty(dirpair)
2182        msgbox_uvmat('ERROR','no pair detected in the selected range')
2183        return
2184end
2185
2186if isequal(mode,'bursts')||isequal(mode,'#_ab')
2187    icount=0;
2188    for ifile=1:length(dirpair)
2189        [RootPath,RootFile,str_1,str_2,str_a,str_b,ext,nom_type]=name2display(dirpair(ifile).name);
2190        num1_r=str2num(str_1);
2191        if isequal(RootFile,Name) & ~isempty(num1_r)   
2192            num_i1(ifile)=num1_r;
2193            num_a(ifile)=stra2num(str_a);
2194            num_b(ifile)=stra2num(str_b);
2195        end     
2196    end
2197    test_range= (num_i1 >=first_i)&(num_i1<= last_i);% =1 when both numbers are in the range
2198    ind_i=((num_i1-first_i)/incr_i)+1;%indices i in the list of prescribed file indices
2199    select=find(test_range &(floor(ind_i)==ind_i));%selected indices of num_i1 in the file directory
2200    ind_i=ind_i(select);%set of selected indices ind_i
2201    [ind_i,indsort]=sort(ind_i);%sorted list of ind_i
2202    select=select(indsort);
2203    num_i1=num_i1(select);
2204    num_a=num_a(select);
2205    num_b=num_b(select);
2206    dirpair=dirpair(select);
2207    [ind_remove]=find_pairs(dirpair,ind_i,nbcolumn);
2208    ind_i(ind_remove)=[];
2209    num_a(ind_remove)=[];
2210    num_b(ind_remove)=[];
2211    num_j1=zeros(1,nbcolumn);%default
2212    num_j2=num_j1;
2213    num_j1(ind_i)=num_a;
2214    num_j2(ind_i)=num_b;
2215    num_i1=first_i:incr_i:last_i;
2216    num_i2=num_i1;
2217    nbmissing=nbcolumn-length(ind_i);
2218
2219elseif isequal(mode,'series(Di)')
2220    %ind0_i=first_i:incr_i:last_i;
2221    %nbcolumn=length(ind0_i);
2222    %ind0_j=first_j:incr_j:last_j;
2223    %nbline=length(ind0_j);
2224    %dirpair=dir([filebasesub '_*-*_*.nc']);
2225    for ifile=1:length(dirpair)
2226        [RootPath,RootFile,str_1,str_2,str_a,str_b,ext,nom_type]=name2display(dirpair(ifile).name);
2227        num_i1_r(ifile)=str2num(str_1);
2228        num_i2_r(ifile)=str2num(str_2);
2229        num_j(ifile)=str2num(str_a);
2230    end
2231    num_i=floor((num_i1_r+num_i2_r)/2); %list of reference indices of the detected files
2232    test_range= (num_i >=first_i)&(num_i<= last_i)&(num_j >=first_j)&(num_j<= last_j);% =1 when both numbers are in the range
2233    ind_i=((num_i-first_i)/incr_i)+1;%indices i and j in the list of prescribed file indices
2234    ind_j=((num_j-first_j)/incr_j)+1;
2235    ind_ij=ind_j+nbline*(ind_i-1);%indices in the reshhaped series of prescribed file indices
2236    select=find(test_range &(floor(ind_i)==ind_i)&(floor(ind_j)==ind_j));%selected indices in the file directory
2237    ind_ij=ind_ij(select);%set of selected indices ind_ij
2238    [ind_ij,indsort]=sort(ind_ij);%sorted list of ind_ij
2239    select=select(indsort);
2240    num_i1_r=num_i1_r(select);
2241    num_i2_r=num_i2_r(select);
2242    dirpair=dirpair(select);
2243    [ind_remove]=find_pairs(dirpair,ind_ij,nbcolumn*nbline) ;
2244    ind_ij(ind_remove)=[];
2245    num_i1_r(ind_remove)=[];
2246    num_i2_r(ind_remove)=[];
2247    num_i1=zeros(1,nbline*nbcolumn);%default
2248    num_i2=num_i1;
2249    num_i1(ind_ij)=num_i1_r;
2250    num_j2(ind_ij)=num_i2_r;
2251    num_i1=reshape(num_i1,nbline,nbcolumn);
2252    num_i2=reshape(num_i2,nbline,nbcolumn);
2253    num_j1=meshgrid(ind0_i,ind0_j);
2254    num_j2=num_j1;
2255    nbmissing=nbline*nbcolumn-length(ind_ij);
2256elseif isequal(mode,'series(Dj)')
2257    for ifile=1:length(dirpair)
2258        [RootPath,RootFile,str_1,str_2,str_a,str_b,ext,nom_type]=name2display(dirpair(ifile).name);
2259        num_i(ifile)=str2num(str_1);
2260        num_a(ifile)=str2num(str_a);
2261        num_b(ifile)=str2num(str_b);
2262    end
2263    num_j=floor((num_a+num_b)/2); %list of reference indices of the detected files
2264    test_range= (num_i >=first_i)&(num_i<= last_i)&(num_j >=first_j)&(num_j<= last_j);% =1 when both numbers are in the range
2265    ind_i=((num_i-first_i)/incr_i)+1;%indices i and j in the list of prescribed file indices
2266    ind_j=((num_j-first_j)/incr_j)+1;
2267    ind_ij=ind_j+nbline*(ind_i-1);%indices in the reshhaped series of prescribed file indices
2268    select=find(test_range &(floor(ind_i)==ind_i)&(floor(ind_j)==ind_j));%selected indices in the file directory
2269    ind_ij=ind_ij(select);%set of selected indices ind_ij
2270    [ind_ij,indsort]=sort(ind_ij);%sorted list of ind_ij
2271    select=select(indsort);
2272    num_i=num_i(select);
2273    num_a=num_a(select);
2274    num_b=num_b(select);
2275    dirpair=dirpair(select);
2276    [ind_remove]=find_pairs(dirpair,ind_ij,nbcolumn*nbline) ;
2277    ind_ij(ind_remove)=[];
2278    num_a(ind_remove)=[];
2279    num_b(ind_remove)=[];
2280    num_j1=zeros(1,nbline*nbcolumn);%default
2281    num_j2=num_j1;
2282    num_j1(ind_ij)=num_a;
2283    num_j2(ind_ij)=num_b;
2284    num_j1=reshape(num_j1,nbline,nbcolumn);
2285    num_j2=reshape(num_j2,nbline,nbcolumn);
2286    num_i1=meshgrid(ind0_i,ind0_j);
2287    num_i2=num_i1;
2288    nbmissing=nbline*nbcolumn-length(ind_ij);
2289end
2290
2291
2292
Note: See TracBrowser for help on using the repository browser.