source: trunk/src/series.m @ 353

Last change on this file since 353 was 353, checked in by sommeria, 9 years ago

functions adapted to Matlab version 2009 (~ replaced by 'tild' in function output)
svn test put under 'try' (error observed)
fullfile_uvmat introduced, aimed at replacing name_generator

File size: 102.8 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_rootfile(handles,param.FileName_1,0)
116        update_rootfile(handles,param.FileName,1)
117    else
118        update_rootfile(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
128% NomType_Callback(hObject, eventdata, handles)
129REFRESH_INDICES_Callback(hObject, eventdata, handles)
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)
213InputTable=get(handles.InputTable,'Data');
214RootPathCell=InputTable(:,1);
215SubDirCell=InputTable(:,1);
216RootFileCell=InputTable(:,1);
217%RootPathCell=get(handles.RootPath,'String');
218%SubDirCell=get(handles.SubDir,'String'); 
219%RootFileCell=get(handles.RootFile,'String');
220oldfile=''; %default
221if isempty(RootPathCell)||isequal(RootPathCell,{''})%loads the previously stored file name and set it as default in the file_input box
222     dir_perso=prefdir;
223     profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
224     if exist(profil_perso,'file')
225          h=load (profil_perso);
226         if isfield(h,'filebase')&&ischar(h.filebase)
227                 oldfile=h.filebase;
228         end
229         if isfield(h,'RootPath')&&ischar(h.RootPath)
230                 oldfile=h.RootPath;
231         end
232     end
233 else
234     oldfile=fullfile(RootPathCell{1},SubDirCell{1},RootFileCell{1});
235 end
236[FileName, PathName, filterindex] = uigetfile( ...
237       {'*.xml;*.xls;*.png;*.tif;*.avi;*.AVI;*.nc', ' (*.xml,*.xls, *.png,*.tif, *.avi,*.nc)';
238       '*.xml',  '.xml files '; ...
239        '*.xls',  '.xls files '; ...
240        '*.png','.png image files'; ...
241        '*.tif','.tif image files'; ...
242        '*.avi;*.AVI','.avi movie files'; ...
243        '*.nc','.netcdf files'; ...
244        '*.*',  'All Files (*.*)'}, ...
245        'Pick a file',oldfile);
246fileinput=[PathName FileName];%complete file name
247%testblank=findstr(fileinput,' ');%look for blanks
248% if ~isempty(testblank)
249%     errordlg('forbidden input file name: contain blanks')
250%     return
251% end
252sizf=size(fileinput);
253if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end
254[path,name,ext]=fileparts(fileinput);
255SeriesData=[];%dfault
256if isequal(ext,'.xml')
257    warndlg_uvmat('ERROR','input file type not implemented')%A Faire: ouvrir le fichier pour naviguer
258elseif isequal(ext,'.xls')
259    warndlg_uvmat('ERROR','input file type not implemented')%A Faire: ouvrir le fichier pour naviguer
260else
261    update_rootfile(handles,fileinput,0)
262     %update list of recent files in the menubar
263    MenuFile_1=fileinput;
264    MenuFile_2=get(handles.MenuFile_1,'Label');
265    MenuFile_3=get(handles.MenuFile_2,'Label');
266    MenuFile_4=get(handles.MenuFile_3,'Label');
267    MenuFile_5=get(handles.MenuFile_4,'Label');
268    set(handles.MenuFile_1,'Label',MenuFile_1)
269    set(handles.MenuFile_2,'Label',MenuFile_2)
270    set(handles.MenuFile_3,'Label',MenuFile_3)
271    set(handles.MenuFile_4,'Label',MenuFile_4)
272    set(handles.MenuFile_5,'Label',MenuFile_5)
273    set(handles.MenuFile_insert_1,'Label',MenuFile_1)
274    set(handles.MenuFile_insert_2,'Label',MenuFile_2)
275    set(handles.MenuFile_insert_3,'Label',MenuFile_3)
276    set(handles.MenuFile_insert_4,'Label',MenuFile_4)
277    set(handles.MenuFile_insert_5,'Label',MenuFile_5)
278    dir_perso=prefdir;
279    profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
280    if exist(profil_perso,'file')
281        save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-append'); %store the file names for future opening of uvmat
282    else
283    txt=ver('MATLAB');
284    Release=txt.Release;
285        relnumb=str2num(Release(3:4));
286        if relnumb >= 14
287            save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-V6'); %store the file names for future opening of uvmat
288        else
289            save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5'); %store the file names for future opening of uvmat
290        end
291    end
292end
293
294
295% --------------------------------------------------------------------
296function MenuFile_1_Callback(hObject, eventdata, handles)
297fileinput=get(handles.MenuFile_1,'Label');
298update_rootfile(handles,fileinput,0)
299
300% --------------------------------------------------------------------
301function MenuFile_2_Callback(hObject, eventdata, handles)
302fileinput=get(handles.MenuFile_2,'Label');
303update_rootfile(handles,fileinput,0)
304
305% --------------------------------------------------------------------
306function MenuFile_3_Callback(hObject, eventdata, handles)
307fileinput=get(handles.MenuFile_3,'Label');
308update_rootfile( handles,fileinput,0)
309
310% --------------------------------------------------------------------
311function MenuFile_4_Callback(hObject, eventdata, handles)
312fileinput=get(handles.MenuFile_4,'Label');
313update_rootfile(handles,fileinput,0)
314
315% --------------------------------------------------------------------
316function MenuFile_5_Callback(hObject, eventdata, handles)
317fileinput=get(handles.MenuFile_5,'Label');
318update_rootfile(handles,fileinput,0)
319
320% --------------------------------------------------------------------
321function MenuBrowse_insert_Callback(hObject, eventdata, handles)
322InputTable=get(handles.InputTable,'Data');
323RootPathCell=InputTable(:,1);
324SubDirCell=InputTable(:,3);
325RootFileCell=InputTable(:,2);
326% RootPathCell=get(handles.RootPath,'String');
327% RootFileCell=get(handles.RootFile,'String');
328oldfile=''; %default
329if isempty(RootPathCell)||isequal(RootPathCell,{''})%loads the previously stored file name and set it as default in the file_input box
330     dir_perso=prefdir;
331     profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
332     if exist(profil_perso,'file')
333          h=load (profil_perso);
334         if isfield(h,'filebase')&ischar(h.filebase)
335                 oldfile=h.filebase;
336         end
337         if isfield(h,'RootPath')&ischar(h.RootPath)
338                 oldfile=h.RootPath;
339         end
340     end
341 else
342     oldfile=fullfile(RootPathCell{1},RootFileCell{1});
343 end
344[FileName, PathName, filterindex] = uigetfile( ...
345       {'*.xml;*.xls;*.png;*.avi;*.AVI;*.nc', ' (*.xml,*.xls, *.png, *.avi,*.nc)';
346       '*.xml',  '.xml files '; ...
347        '*.xls',  '.xls files '; ...
348        '*.png','.png image files'; ...
349        '*.avi;*.AVI','.avi movie files'; ...
350        '*.nc','.netcdf files'; ...
351        '*.*',  'All Files (*.*)'}, ...
352        'Pick a file',oldfile);
353fileinput=[PathName FileName];%complete file name
354% testblank=findstr(fileinput,' ');%look for blanks
355% if ~isempty(testblank)
356%     errordlg('forbidden input file name: contain blanks')
357%     return
358% end
359sizf=size(fileinput);
360if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end
361[path,name,ext]=fileparts(fileinput);
362SeriesData=[];%dfault
363if isequal(ext,'.xml')
364    msgbox_uvmat('ERROR','input file type not implemented')%A Faire: ouvrir le fichier pour naviguer
365elseif isequal(ext,'.xls')
366    msgbox_uvmat('ERROR','input file type not implemented')%A Faire: ouvrir le fichier pour naviguer
367else
368    update_rootfile(handles,fileinput,1)
369    %update list of recent files in the menubar
370    MenuFile_1=fileinput;
371    MenuFile_2=get(handles.MenuFile_1,'Label');
372    MenuFile_3=get(handles.MenuFile_2,'Label');
373    MenuFile_4=get(handles.MenuFile_3,'Label');
374    MenuFile_5=get(handles.MenuFile_4,'Label');
375    set(handles.MenuFile_1,'Label',MenuFile_1)
376    set(handles.MenuFile_2,'Label',MenuFile_2)
377    set(handles.MenuFile_3,'Label',MenuFile_3)
378    set(handles.MenuFile_4,'Label',MenuFile_4)
379    set(handles.MenuFile_5,'Label',MenuFile_5)
380    set(handles.MenuFile_insert_1,'Label',MenuFile_1)
381    set(handles.MenuFile_insert_2,'Label',MenuFile_2)
382    set(handles.MenuFile_insert_3,'Label',MenuFile_3)
383    set(handles.MenuFile_insert_4,'Label',MenuFile_4)
384    set(handles.MenuFile_insert_5,'Label',MenuFile_5)
385    dir_perso=prefdir;
386    profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
387    if exist(profil_perso,'file')
388        save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-append'); %store the file names for future opening of uvmat
389    else
390    txt=ver('MATLAB');
391    Release=txt.Release;
392        relnumb=str2num(Release(3:4));
393        if relnumb >= 14
394            save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-V6'); %store the file names for future opening of uvmat
395        else
396            save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5'); %store the file names for future opening of uvmat
397        end
398    end
399end
400%------------------------------------------------
401
402% --------------------------------------------------------------------
403function MenuFile_insert_1_Callback(hObject, eventdata, handles)
404fileinput=get(handles.MenuFile_insert_1,'Label');
405update_rootfile(handles,fileinput,1)
406
407% --------------------------------------------------------------------
408function MenuFile_insert_2_Callback(hObject, eventdata, handles)
409fileinput=get(handles.MenuFile_insert_2,'Label');
410update_rootfile(handles,fileinput,1)
411
412% --------------------------------------------------------------------
413function MenuFile_insert_3_Callback(hObject, eventdata, handles)
414fileinput=get(handles.MenuFile_insert_3,'Label');
415update_rootfile( handles,fileinput,1)
416
417% --------------------------------------------------------------------
418function MenuFile_insert_4_Callback(hObject, eventdata, handles)
419fileinput=get(handles.MenuFile_insert_4,'Label');
420update_rootfile( handles,fileinput,1)
421
422% --------------------------------------------------------------------
423function MenuFile_insert_5_Callback(hObject, eventdata, handles)
424fileinput=get(handles.MenuFile_insert_5,'Label');
425update_rootfile(handles,fileinput,1)
426
427%------------------------------------------------------------------------
428% ---  refresh the GUI data after introduction of a new file series
429% INPUT:
430% handles:
431% fileinput: name of the input file
432% 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')
433function update_rootfile(handles,fileinput,addtest)
434%------------------------------------------------------------------------ 
435
436%% enable other menus and uicontrols
437set(handles.MenuOpen_insert,'Enable','on')
438set(handles.MenuFile_insert_1,'Enable','on')
439set(handles.MenuFile_insert_2,'Enable','on')
440set(handles.MenuFile_insert_3,'Enable','on')
441set(handles.MenuFile_insert_4,'Enable','on')
442set(handles.MenuFile_insert_5,'Enable','on')
443set(handles.RUN, 'Enable','On')
444set(handles.RUN,'BackgroundColor',[1 0 0])% set RUN button to red
445% set(handles.RootPath,'BackgroundColor',[1 1 0]) % set RootPath edit box  to yellow
446set(handles.InputTable,'BackgroundColor',[1 1 0]) % set RootPath edit box  to yellow
447drawnow
448
449%% get the input root name, indices, file extension and nomenclature NomType
450if ~exist(fileinput,'file')
451    msgbox_uvmat('ERROR',['input file ' fileinput  ' does not exist'])
452    return
453end
454[RootPath,SubDir,RootFile,i1,i2,j1,j2,FileExt,NomType]=fileparts_uvmat(fileinput);
455
456%% determine reference field indices
457ref_i=1; %default ref_i is a reference frame index used to find existing pairs from PIV
458if ~isempty(i1)
459    ref_i=i1;
460    if ~isempty(i2)
461        ref_i=floor((ref_i+i2)/2);% reference image number corresponding to the file
462%         SeriesData.browse_Di=i2-i1;
463    end
464end
465set(handles.ref_i,'String',num2str(ref_i));
466set(handles.num_first_i,'String',num2str(ref_i));
467set(handles.num_last_i,'String',num2str(ref_i));
468ref_j=1; %default  ref_j is a reference frame index used to find existing pairs from PIV
469if ~isempty(j1)
470    ref_j=j1;
471    if ~isempty(j2)
472        ref_j=floor((j1+j2)/2);
473%         SeriesData.browse_Dj=j2-j1;
474    end         
475end
476set(handles.ref_j,'String',num2str(ref_j));
477set(handles.num_first_j,'String',num2str(ref_j))
478set(handles.num_last_j,'String',num2str(ref_j));
479TimeUnit=''; %default
480time=[];%default
481
482% read timing and total frame number from the current file (movie files) !! may be overrid by xml file
483FileBase=fullfile(RootPath,RootFile);
484
485testima=0; %test for image input
486if isequal(lower(FileExt),'.avi') %.avi file
487    testima=1;
488%     info=aviinfo([FileBase FileExt]);
489%     time=(0:1/info.FramesPerSecond:(info.NumFrames-1)/info.FramesPerSecond)';
490%     num_MaxIndex_i=info.NumFrames;
491%     num_MaxIndex_j=1;
492elseif ~isempty(imformats(FileExt(2:end)))
493    testima=1;
494%     if isequal(NomType,'*')% multi-frame image
495%         imainfo=imfinfo([FileBase FileExt]);     
496%         if length(imainfo) >1 %case of image with multiple frames
497%             num_MaxIndex_i=length(imainfo);
498%             num_MaxIndex_j=1;
499%         end
500%     end
501elseif isequal(FileExt,'.vol')
502     testima=1;
503end
504
505%% fill the list of file series
506
507% insert the current file series at the head of the list
508InputTable=get(handles.InputTable,'Data');
509if addtest
510%     SeriesData=get(handles.series,'UserData');
511%   %  SeriesData.displ_num=[0 0 0 0;SeriesData.displ_num];
512%     SeriesData.CurrentInputFile_1=SeriesData.CurrentInputFile;
513%     SeriesData.i1_series=[SeriesData.i1_series;{i1_series}];
514%     SeriesData.i2_series=[SeriesData.i2_series;{i2_series}];
515%     SeriesData.j1_series=[SeriesData.j1_series;{j1_series}];
516%     SeriesData.j2_series=[SeriesData.j2_series;{j2_series}];
517InputTable=get(handles.InputTable,'Data');
518 InputTable=[{RootPath},{SubDir},{RootFile},{NomType},{FileExt};InputTable];
519%     RootPathCell=[{RootPath}; InputTable{] ;
520%     SubDirCell=[{SubDir}; get(handles.SubDir,'String')];
521%     RootFileCell=[{RootFile}; get(handles.RootFile,'String')];
522%     NomTypeCell=[{NomType}; SeriesData.NomType];
523%     FileExtCell=[{FileExt}; get(handles.FileExt,'String')];
524%     FileTypeCell=[{FileType};SeriesData.FileType];
525%     set(handles.NomType,'String',[{};get(handles.NomType,'String')])
526   
527% or re-initialise the list of  input  file series   
528else
529    InputTable=[{RootPath},{SubDir},{RootFile},{NomType},{FileExt}];
530end
531set(handles.InputTable,'Data',InputTable)
532%     SeriesData=[];%re-initialisation
533%  %   SeriesData.displ_num=[0 0 0 0];
534% %     SeriesData.i1_series={i1_series};
535% %     SeriesData.i2_series={i2_series};
536% %     SeriesData.j1_series={j1_series};
537% %     SeriesData.j2_series={j2_series};
538%     RootPathCell={RootPath};
539%     SubDirCell={SubDir};
540%     RootFileCell={RootFile};   
541%     NomTypeCell={NomType};
542%     FileExtCell={FileExt};   
543% %    FileTypeCell={FileType};
544% end
545% SeriesData.NomType=NomTypeCell;
546%SeriesData.FileType=FileTypeCell;
547SeriesData.CurrentInputFile=fileinput;
548% set(handles.RootPath,'String',RootPathCell);
549% set(handles.SubDir,'String',SubDirCell);
550% set(handles.RootFile,'String',RootFileCell);
551% set(handles.NomType,'String',NomTypeCell);
552% set(handles.FileExt,'String',FileExtCell);
553%set(handles.InputTable,'Data',[RootPathCell SubDirCell RootFileCell NomTypeCell FileExtCell]) ;
554update_indices(handles,fileinput,1)
555
556
557% %% display times
558% if addtest
559%     SeriesData.Time=[{time} SeriesData.Time];
560% else
561%    SeriesData.Time={time};
562% end
563% set(handles.TimeUnit,'String',TimeUnit)
564% set(handles.series,'UserData',SeriesData);
565% time_display=[time(MinIndex_i,MinIndex_j) time(ref_i,ref_j) time(ref_i,ref_j) time(MaxIndex_i,MaxIndex_j);...
566%     time(MinIndex_i,MinIndex_j) time(ref_i,ref_j) time(ref_i,ref_j) time(MaxIndex_i,MaxIndex_j)];
567% set(handles.time_table,'Data',time_display)
568
569
570
571%store the root name for future opening of uvmat
572dir_perso=prefdir;
573profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
574if exist(profil_perso,'file')
575    save (profil_perso,'RootPath','SubDir','RootFile','NomType', '-append'); %store the root name for future opening of uvmat
576else
577    txt=ver('MATLAB');
578    Release=txt.Release;
579    relnumb=str2num(Release(3:4));
580    if relnumb >= 14
581        save (profil_perso,'RootPath','SubDir','RootFile','NomType','-V6') %store the root name for future opening of uvmat
582    else
583        save(profil_perso,'RootPath','SubDir','RootFile','NomType')
584    end         
585end
586set(handles.InputTable,'BackgroundColor',[1 1 1])
587% set(handles.PathCampaign,'String',SeriesData.PathCampaign)
588%num_last_j_Callback([], [], handles)% TODO:update
589%num_last_i_Callback([], [], handles)
590
591% %------------------------------------------------------------------------
592% function RootPath_Callback(hObject, eventdata, handles)
593% %------------------------------------------------------------------------
594% Val=get(handles.RootPath,'Value');
595% synchronise_view(handles,Val)
596% NomType_Callback(hObject, eventdata, handles)
597
598% %------------------------------------------------------------------------
599% function synchronise_view(handles,Val)
600% %------------------------------------------------------------------------
601% set(handles.RootPath,'Value',Val)
602% set(handles.SubDir,'Value',Val)
603% set(handles.RootFile,'Value',Val)
604% set(handles.NomType,'Value',Val)
605% set(handles.FileExt,'Value',Val)
606% set(handles.num_MaxIndex_i,'Value',Val)
607% set(handles.num_MaxIndex_j,'Value',Val)
608% % set(handles.time_first,'Value',Val)
609% % set(handles.time_last,'Value',Val)
610
611
612% %------------------------------------------------------------------------
613% % Executes on carriage return on the subdir civ1 edit window
614% function SubDir_Callback(hObject, eventdata, handles)
615% %------------------------------------------------------------------------
616% Val=get(handles.SubDir,'Value');
617% synchronise_view(handles,Val)
618% NomType_Callback(hObject, eventdata, handles)
619
620% %------------------------------------------------------------------------
621% % --- function activated when a new filebase (image series) is introduced
622% function RootFile_Callback(hObject, eventdata, handles)
623% %------------------------------------------------------------------------
624% Val=get(handles.RootFile,'Value');
625% synchronise_view(handles,Val)
626% NomType_Callback(hObject, eventdata, handles)
627
628%--------------------------------------------------------------
629% %function activated when a new filebase (image series) is introduced
630% %------------------------------------------------------------
631% function FileExt_Callback(hObject, eventdata, handles)
632% Val=get(handles.FileExt,'Value');
633% synchronise_view(handles,Val)
634
635% %--------------------------------------------------------------
636% %function activated when a new filebase (image series) is introduced
637% %------------------------------------------------------------
638% function num_MaxIndex_i_Callback(hObject, eventdata, handles)
639% Val=get(handles.num_MaxIndex_i,'Value');
640% synchronise_view(handles,Val)
641
642% %--------------------------------------------------------------
643% %function activated when a new filebase (image series) is introduced
644% %------------------------------------------------------------
645% function num_MaxIndex_j_Callback(hObject, eventdata, handles)
646% Val=get(handles.num_MaxIndex_j,'Value');
647% synchronise_view(handles,Val)
648%
649% %--------------------------------------------------------------
650% %function activated when a new filebase (image series) is introduced
651% %------------------------------------------------------------
652% function time_first_Callback(hObject, eventdata, handles)
653% Val=get(handles.time_first,'Value');
654% synchronise_view(handles,Val)
655%
656% %--------------------------------------------------------------
657% %function activated when a new filebase (image series) is introduced
658% %------------------------------------------------------------
659% function time_last_Callback(hObject, eventdata, handles)
660% Val=get(handles.time_last,'Value');
661% synchronise_view(handles,Val)
662% NomType_Callback(hObject, eventdata, handles)
663
664% %------------------------------------------------------------------------
665% function NomType_Callback(hObject, eventdata, handles)
666% %------------------------------------------------------------------------
667
668% --- Executes when entered data in editable cell(s) in InputTable.
669function InputTable_CellEditCallback(hObject, eventdata, handles)
670% hObject    handle to InputTable (see GCBO)
671% eventdata  structure with the following fields (see UITABLE)
672%       Indices: row and column indices of the cell(s) edited
673%       PreviousData: previous data for the cell(s) edited
674%       EditData: string(s) entered by the user
675%       NewData: EditData or its converted form set on the Data property. Empty if Data was not changed
676%       Error: error string when failed to convert EditData to appropriate value for Data
677% handles    structure with handles and user data (see GUIDATA)
678eventdata
679list_lines=get(handles.REFRESH_INDICES,'UserData');
680list_lines(eventdata.Indices(1))=1; %select the edited line for refresh
681set(handles.REFRESH_INDICES,'UserData',list_lines);
682set(handles.REFRESH_INDICES,'Visible','on')
683
684
685%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%????????????
686% --- Executes on button press in mode.
687%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
688    function mode_Callback(hObject, eventdata, handles)
689       
690        SeriesData=get(handles.series,'UserData');
691        mode_list=get(handles.mode,'String');
692        mode_value=get(handles.mode,'Value');
693        mode=mode_list{mode_value};
694        NomType=[];
695        % test_find_pair=0;
696        % if isfield(SeriesData,'NomType')
697        NomTypeCell=SeriesData.NomType;
698        Val=get(handles.NomType,'Value');
699        NomType=NomTypeCell{Val};
700        check_pairs=~isempty(SeriesData.i2_series{Val})||~isempty(SeriesData.j2_series{Val});
701       
702        time=[];
703        if isfield(SeriesData,'Time')
704            time=SeriesData.Time{1}; %get the set of times
705        end
706        siztime=size(time);
707        nbfield=siztime(1);
708        nbfield2=siztime(2);
709        % indchosen=1;  %%first pair selected by default
710        if isequal(mode,'bursts')
711            enable_i(handles,'On')
712            enable_j(handles,'Off') %do not display j index scanning in burst mode (j is fixed by the burst choice)
713        elseif  ~isempty(SeriesData.j2_series{Val})
714            enable_i(handles,'On')
715            enable_j(handles,'On') % allow both i and j index scanning
716        else
717            enable_i(handles,'On')
718            enable_j(handles,'Off')
719        end
720        % set(handles.list_pair_civ,'Value',indchosen);%set the default choice of image pairs for civ1
721        set(handles.series,'UserData',SeriesData)
722       
723        %list pairs if relevant
724        if check_pairs
725            find_netcpair_civ(handles,Val)
726        end
727
728%-------------------------------------
729function enable_i(handles,state)
730set(handles.i_txt,'Visible',state)
731set(handles.num_first_i,'Visible',state)
732set(handles.num_last_i,'Visible',state)
733set(handles.num_incr_i,'Visible',state)
734set(handles.num_MaxIndex_i,'Visible',state)
735set(handles.ref_i,'Visible',state)
736set(handles.ref_i_text,'Visible',state)
737
738%-----------------------------------
739function enable_j(handles,state)
740set(handles.j_txt,'Visible',state)
741set(handles.num_MinIndex_j,'Visible',state)
742set(handles.num_first_j,'Visible',state)
743set(handles.num_last_j,'Visible',state)
744set(handles.num_incr_j,'Visible',state)
745set(handles.num_MaxIndex_j,'Visible',state)
746set(handles.ref_j,'Visible',state)
747set(handles.ref_j_text,'Visible',state)
748
749%-----------------------------------
750function view_FieldMenu(handles,state)
751% set(handles.FieldMenu,'Visible',state)
752% set(handles.Field_text,'Visible',state)
753set(handles.InputFields,'Visible',state)
754
755%-----------------------------------
756function view_FieldMenu_1(handles,state)
757set(handles.FieldMenu_1,'Visible',state)
758set(handles.Field_text_1,'Visible',state)
759
760% %-----------------------------------
761% function view_TRANSFORM(handles,state)
762% set(handles.TRANSFORM_frame,'Visible',state)
763% set(handles.transform_fct,'Visible',state);
764% set(handles.TRANSFORM_title,'Visible',state)
765
766%--------------------------------------------------------------
767% determine the menu for civ1 pairs depending on existing netcdf files
768% with the reference indices ref_i and ref_j
769%----------------------------------------------------------------
770function find_netcpair_civ(handles,Val)
771SeriesData=get(handles.series,'UserData');
772% NomTypeCell=get(handles.NomType,'String');
773NomTypeCell=SeriesData.NomType;
774NomType=NomTypeCell{Val};
775
776set(handles.Pairs,'Visible','on')% makes the panel "Pairs' visible
777%nomenclature types
778RootPathCell=get(handles.RootPath,'String');
779filepath=RootPathCell{Val};
780RootFileCell=get(handles.RootFile,'String');
781filename=RootFileCell{Val};
782filebase=fullfile(filepath,filename);
783SubDirCell=get(handles.SubDir,'String');
784subdir=SubDirCell{Val};
785if ~exist(fullfile(filepath,subdir),'dir')
786         msgbox_uvmat('ERROR',['no civ file available: subdirectory ' subdir ' does not exist'])
787         set(handles.list_pair_civ,'String',{''});
788         return
789end
790mode_list=get(handles.mode,'String');
791mode_value=get(handles.mode,'Value');
792mode=mode_list{mode_value};
793
794%reads image numbers from the interface
795% ref_i=str2num(get(handles.ref_i,'String'));
796% ref_j=str2num(get(handles.ref_j,'String'));
797% ref_time=0;
798% nbfield=50;
799% nbfield2=50;%default max number of pairs
800
801%look for existing processed pairs involving the field at the middle of the series if civ1 will not
802% be performed, while the result is needed for next steps.
803
804% ind_exist=0;
805TimeUnit=get(handles.TimeUnit,'String');
806if length(TimeUnit)>=1
807    dtunit=['m' TimeUnit];
808else
809    dtunit='e-03';
810end
811
812%% NEW
813i1_series=SeriesData.i1_series{Val};
814i2_series=SeriesData.i2_series{Val};
815j1_series=SeriesData.j1_series{Val};
816j2_series=SeriesData.j2_series{Val};
817displ_pair={};
818if strcmp(mode,'series(Di)')
819    if isempty(i2_series)
820        msgbox_uvmat('ERROR','no i1-i2 pair available')
821        return
822    end
823    diff_i=i2_series-i1_series;
824    min_diff=min(diff_i(diff_i>0));
825    max_diff=max(diff_i(diff_i>0));
826    for ipair=min_diff:max_diff
827        if numel(diff_i(diff_i==ipair))>0
828            displ_pair=[displ_pair;{['Di= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ]}];
829        end
830    end
831    if ~isempty(displ_pair)
832        displ_pair=[displ_pair;{'Di=*|*'}];
833    end
834elseif strcmp(mode,'series(Dj)')
835    if isempty(j2_series)
836        msgbox_uvmat('ERROR','no j1-j2 pair available')
837        return
838    end
839    diff_j=j2_series-j1_series;
840    min_diff=min(diff_j(diff_j>0));
841    max_diff=max(diff_j(diff_j>0));
842    for ipair=min_diff:max_diff
843        if numel(diff_j(diff_j==ipair))>0
844            displ_pair=[displ_pair;{['Dj= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ]}];
845        end
846    end
847    if ~isempty(displ_pair)
848        displ_pair=[displ_pair;{'Dj=*|*'}];
849    end
850elseif strcmp(mode,'bursts')
851    if isempty(j2_series)
852        msgbox_uvmat('ERROR','no j1-j2 pair available')
853        return
854    end
855    diff_j=j2_series-j1_series;
856    min_j1=min(j1_series(j1_series>0));
857    max_j1=max(j1_series(j1_series>0));
858    min_j2=min(j2_series(j2_series>0));
859    max_j2=max(j2_series(j2_series>0));
860    for pair1=min_j1:min(max_j1,min_j1+20)
861        for pair2=min_j2:min(max_j2,min_j2+20)
862        if numel(j1_series(j1_series==pair1))>0 && numel(j2_series(j2_series==pair2))>0
863            displ_pair=[displ_pair;{['j= ' num2str(pair1) '-' num2str(pair2)]}];
864        end
865        end
866    end
867    if ~isempty(displ_pair)
868        displ_pair=[displ_pair;{'j=*-*'}];
869    end
870end
871
872%% display list of pairs
873displ_pair_list=get(handles.list_pair_civ,'String');
874NewVal=[];
875if ~isempty(displ_pair_list)
876Val=get(handles.list_pair_civ,'Value');
877NewVal=find(strcmp(displ_pair_list{Val},displ_pair),1);% look at the previous display in the new menu displ_pâir
878end
879if ~isempty(NewVal)
880    set(handles.list_pair_civ,'Value',NewVal)
881else
882    set(handles.list_pair_civ,'Value',1)
883end
884set(handles.list_pair_civ,'String',displ_pair)
885displ_pair
886
887 %   displ_pair{ind_exist}=['Di= ' num2str(-floor(index/2)) '|' num2str(ceil(index/2)) ' :dt= ' num2str(dt*1000) dtunit];
888% if strcmp(mode,'series(Di)')
889%      for index=1:min(nbfield-1,50)
890%          filename=name_generator(filebase,ref_i-floor(index/2),ref_j,'.nc',NomType,1,ref_i+ceil(index/2),ref_j,subdir);
891%          select=(exist(filename,'file')==2);
892%          if select==1
893%                ind_exist=ind_exist+1;
894%                 displ_num(1,ind_exist)=0;
895%                 displ_num(2,ind_exist)=0;
896%                 displ_num(3,ind_exist)=-floor(index/2);
897%                 displ_num(4,ind_exist)=ceil(index/2);
898%                 %[cte_detect,vdt,cte_read]=read_netcdf(filename,{'dt','dt2','absolut_time_T0','absolute_time_TO_2'});
899%                 [Cte,var_detect,ichoice]=nc2struct(filename,{});
900%                 if isfield(Cte,'dt2')
901%                     dt=Cte.dt2;
902%                 elseif isfield(Cte,'dt')
903%                     dt=Cte.dt;
904%                 end
905%                 if isfield(Cte,'absolut_time_TO_2')
906%                     ref_time(ind_exist)=Cte.absolut_time_TO_2;%civ2 data used in priority
907%                 elseif isfield(Cte,'absolut_time_TO')
908%                     ref_time(ind_exist)=Cte.absolut_time_TO;%civ2 data used in priorit
909%                 elseif isfield(Cte,'Time')
910%                     ref_time(ind_exist)=Cte.Time;
911%                 end
912%                 displ_pair{ind_exist}=['Di= ' num2str(-floor(index/2)) '|' num2str(ceil(index/2)) ' :dt= ' num2str(dt*1000) dtunit];
913%          end
914%      end
915%      set(handles.list_pair_civ,'String',[displ_pair';{'Di=*|*'}]);   
916% elseif isequal(mode,'series(Dj)')% series on the j index
917%        for index=1:min(nbfield2-1,50)
918%            filename=name_generator(filebase,ref_i,ref_j-floor(index/2),'.nc',NomType,1,ref_i,ref_j+ceil(index/2),subdir);
919%            select=(exist(filename,'file')==2);
920%            if select==1
921%                ind_exist=ind_exist+1;
922%                 displ_num(1,ind_exist)=-floor(index/2);
923%                 displ_num(2,ind_exist)=ceil(index/2);
924%                 displ_num(3,ind_exist)=0;
925%                 displ_num(4,ind_exist)=0;
926%                 [Cte,var_detect,ichoice]=nc2struct(filename,{});
927%                 if isfield(Cte,'dt2')
928%                     dt=Cte.dt2;
929%                 elseif isfield(Cte,'dt')
930%                     dt=Cte.dt;
931%                 end
932%                 if isfield(Cte,'absolut_time_TO_2')
933%                     ref_time(ind_exist)=Cte.absolut_time_TO_2;%civ2 data used in priority
934%                 elseif isfield(Cte,'absolut_time_TO')
935%                     ref_time(ind_exist)=Cte.absolut_time_TO;%civ2 data used in priorit
936%                 elseif isfield(Cte,'Time')
937%                     ref_time(ind_exist)=Cte.Time;
938%                 end
939%                 displ_pair{ind_exist}=['Dj= ' num2str(-floor(index/2)) '|' num2str(ceil(index/2)) ' :dt= ' num2str(dt*1000) dtunit];
940%            end
941%        end
942%        set(handles.list_pair_civ,'String',[displ_pair';{'Dj=*|*'}]);
943% elseif isequal(mode,'bursts') %case of bursts
944%     for numod_a=1:nbfield2-1 %nbfield2 always >=2 for 'bursts' mode
945%         for numod_b=(numod_a+1):nbfield2
946%             [filename]=name_generator(filebase,ref_i,numod_a,'.nc',NomType,1,ref_i,numod_b,subdir)
947%             select=(exist(filename,'file')==2)
948%             if select==1
949%                 ind_exist=ind_exist+1;
950%                 numlist_a(ind_exist)=numod_a;
951%                 numlist_b(ind_exist)=numod_b;
952%                 Attr=nc2struct(filename,[]);
953%                 isfield(Attr,'absolut_time_T0_2')
954%                 if isfield(Attr,'dt2')
955%                    dt(ind_exist)=Attr.dt2;
956%                    ref_time(ind_exist)=Attr.absolut_time_T0_2;
957%                 elseif isfield(Attr,'dt')& isfield(Attr,'absolut_time_T0')
958%                    dt(ind_exist)=Attr.dt;
959%                    ref_time(ind_exist)=Attr.absolut_time_T0;
960%                 else
961%                    dt(ind_exist)=NaN;%no information on dt
962%                 end
963%                 %determine nom_type_ima for pair display (used in num2stra.m)
964%                 switch NomType
965%                     case {'#ab'}
966%                         nom_type_ima='#a';
967%                     case {'#AB'}
968%                         nom_type_ima='#A';
969%                     otherwise
970%                          nom_type_ima='_1_1';
971%                 end
972%                displ_pair{ind_exist}=['j= ' num2stra(numod_a,nom_type_ima,2) '-' num2stra(numod_b,nom_type_ima,2) ...
973%                         ' :dt= ' num2str(dt(ind_exist)*1000)];
974%             end
975%          end
976%          set(handles.list_pair_civ,'String',[displ_pair';{'j=*-*'}]);
977%      end
978%      if exist('dt','var') & ~isempty(dt)
979%          [dtsort,indsort]=sort(dt);
980%          displ_num(1,:)=numlist_a(indsort);
981%          displ_num(2,:)=numlist_b(indsort);
982%          displ_num(3,:)=0;
983%          displ_num(4,:)=0;
984%          displ_pair=displ_pair(indsort);
985%          ref_time=ref_time(indsort);
986%      end
987% end
988if isempty(displ_pair)
989    msgbox_uvmat('ERROR',['no file available for the selected subdirectory ' subdir])
990end
991return
992%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%END FUNCTION
993
994
995if ind_exist==0
996         if  isequal(mode,'series(Dj)') | isequal(mode,'st_series(Dj)')
997            msgbox_uvmat('ERROR',['no .nc file available for the selected reference index j=' num2str(ref_j) ' and subdirectory ' subdir])
998        else
999            msgbox_uvmat('ERROR',['no .nc file available for the selected reference index i=' num2str(ref_i) ' and subdirectory ' subdir])
1000        end
1001        if isequal(mode,'bursts') %case of bursts
1002            set(handles.list_pair_civ,'String',{'j=*-*'});
1003        elseif isequal(mode,'series(Di)') %case of bursts
1004            set(handles.list_pair_civ,'String',{'Di=*|*'});
1005        elseif isequal(mode,'series(Dj)') %case of bursts
1006            set(handles.list_pair_civ,'String',{'Dj=*|*'});
1007        end
1008end
1009return
1010%TO update
1011val=get(handles.list_pair_civ,'Value');
1012if val > length(displ_pair)
1013    set(handles.list_pair_civ,'Value',1);% first pair proposed by default in the menu
1014    val=1;
1015end
1016iview=get(handles.NomType,'Value');
1017SeriesData.displ_num(iview,:)=(displ_num(:,val))';
1018SeriesData.ref_time=ref_time;
1019set(handles.series,'UserData',SeriesData)
1020list_pair_civ_Callback([],[],handles)
1021
1022%-------------------------------------------------------------
1023% --- Executes on selection in list_pair_civ.
1024function list_pair_civ_Callback(hObject,eventdata,handles)
1025%------------------------------------------------------------
1026return
1027%%%%%%%%
1028%update num_first_i and num_last_i according to the chosen image pairs
1029testupdate=0;
1030Val=get(handles.RootPath,'Value');
1031IndexCell=get(handles.NomType,'String');
1032SeriesData=get(handles.series,'UserData');
1033NomType=SeriesData.NomType{Val};
1034list_pair=get(handles.list_pair_civ,'String');%get the menu of image pairs
1035index_pair=get(handles.list_pair_civ,'Value');
1036str_pair=list_pair{index_pair};
1037ind_equ=strfind(str_pair,'=');%find '='
1038ind_sep=strfind(str_pair,'|');%find pair separator '|'
1039ind_com=strfind(str_pair,':');%find ':'
1040test_bursts=0;
1041if isempty(ind_sep)
1042    ind_sep=strfind(str_pair,'-');%find pair separator if it is not '|'
1043    test_bursts=1;% we are in the case of bursts
1044end
1045displ_num=[0 0 0 0]; %default
1046if ~isempty(ind_sep)&& ~strcmp(str_pair(ind_sep-1),'*')% if there is a pair separator ('|' or '-')
1047    num1_str=str_pair(ind_equ(1)+1:ind_sep-1);
1048    num2_str=str_pair(ind_sep+1:ind_com-1);
1049    num1=str2double(num1_str);
1050    num2=str2double(num2_str);
1051    if isequal(num1_str(1),' ')
1052        num1_str(1)=[];
1053    end   
1054    if isequal(num2_str(end),' ')
1055        num2_str(end)=[];
1056    end
1057    switch NomType
1058       case {'_1-2_1'}
1059           if isequal(num1_str(1),'0')
1060               IndexCell{Val}=['_(i-(i+' num2_str ')_j'];
1061           else
1062               IndexCell{Val}=['_(i' num1_str ')-(i+' num2_str ')_j'];
1063           end
1064           displ_num(3)=num1;
1065           displ_num(4)=num2;
1066       case {'_1-2'}
1067           if isequal(num1_str(1),'0')
1068               IndexCell{Val}=['_(i' num1_str ')-(i+' num2_str ')'];
1069           else
1070               IndexCell{Val}=['_(i' num1_str ')-(i+' num2_str ')'];
1071           end
1072           displ_num(3)=num1;
1073           displ_num(4)=num2;
1074       case '_1_1-2'
1075          if test_bursts
1076              IndexCell{Val}=['_i_' num1_str '-' num2_str ];
1077          else
1078              if isequal(num1_str(1),'0')
1079                 IndexCell{Val}=['_i_j-(j+' num2_str ')'];
1080              else
1081                 IndexCell{Val}=['_i_(j' num1_str ')-(j+' num2_str ')'];
1082              end
1083          end
1084          displ_num(1)=num1;
1085          displ_num(2)=num2;
1086       case {'#_ab'} %TO COMPLETE
1087           IndexCell{Val}=['_i_' num1_str '-' num2_str ];
1088
1089    end
1090end
1091set(handles.NomType,'String',IndexCell)
1092SeriesData.displ_num(Val,:)=displ_num;
1093set(handles.series,'UserData',SeriesData)
1094% set(handles.NomType,'Value',Val)
1095
1096if ~isequal(str_pair,'Dj=*|*')&~isequal(str_pair,'Di=*|*')
1097        mode_list=get(handles.mode,'String');
1098    mode_value=get(handles.mode,'Value');
1099    mode=mode_list{mode_value};
1100        if isequal(mode,'series(Di)')
1101        first_i=str2num(get(handles.num_first_i,'String'));
1102        last_i=str2num(get(handles.num_last_i,'String'));
1103        incr_i=str2num(get(handles.num_incr_i,'String'));
1104        num1=first_i:incr_i:last_i;
1105        lastfieldCell=get(handles.num_MaxIndex_i,'String');
1106        lastfield=str2num(lastfieldCell{1});
1107        if ~isempty(lastfield)
1108            ind=find((num1-floor(index_pair/2)*ones(size(num1))>0)& (num1+ceil(index_pair/2)*ones(size(num1))<=lastfield));
1109            num1=num1(ind);       
1110        end
1111        if ~isempty(num1)
1112            set(handles.num_first_i,'String',num2str(num1(1)));
1113            set(handles.num_last_i,'String',num2str(num1(end)));
1114        end
1115        testupdate=1;
1116        elseif isequal(mode,'series(Dj)')
1117        first_j=str2num(get(handles.num_first_j,'String'));
1118        last_j=str2num(get(handles.num_last_j,'String'));
1119        incr_j=str2num(get(handles.num_incr_j,'String'));
1120        num_j=first_j:incr_j:last_j;
1121        lastfieldCell=get(handles.num_MaxIndex_j,'String');
1122        if ~isempty(lastfieldCell)
1123            lastfield2=lastfieldCell{1};
1124            ind=find((num_j-floor(index_pair/2)*ones(size(num_j))>0)& ...
1125                 (num_j+ceil(index_pair/2)*ones(size(num_j))<=lastfield2));
1126        end
1127        testupdate=1;
1128        end
1129       
1130        %update the first and last times of the series
1131        if testupdate && isfield(SeriesData,'Time')
1132        if ~isempty(SeriesData.Time{1})
1133            displ_time(handles);
1134        end
1135        end
1136end
1137
1138%------------------------------------------------------------------------
1139% --- Executes on button press in RUN.
1140function RUN_Callback(hObject, eventdata, handles)
1141%------------------------------------------------------------------------
1142%% read root name and field type
1143set(handles.RUN,'BusyAction','queue');
1144set(0,'CurrentFigure',handles.series)
1145if isequal(get(handles.GetObject,'Visible'),'on') && isequal(get(handles.GetObject,'Value'),1)
1146    Series.GetObject=1;
1147    GetObject_Callback(hObject, eventdata, handles)
1148else
1149    Series.GetObject=0;
1150end
1151SeriesData=get(handles.series,'UserData');
1152
1153% Series.hseries=handles.series; % handles to the series GUI
1154
1155%% Read parameters from series
1156Series=read_GUI(handles.series);%TODO: extend to all input param
1157Series.hseries=handles.series; % handles to the series GUI
1158
1159   first_i=1;
1160   last_i=1;
1161   incr_i=1;
1162       first_j=1;
1163    last_j=1;
1164    incr_j=1;
1165if isfield(Series.IndexRange,'first_i')
1166    first_i=Series.IndexRange.first_i;
1167    incr_i=Series.IndexRange.incr_i;
1168    last_i=Series.IndexRange.last_i;
1169end
1170if isfield(Series.IndexRange,'first_j')
1171    first_j=Series.IndexRange.first_j;
1172    incr_j=Series.IndexRange.incr_j;
1173    last_j=Series.IndexRange.last_j;
1174end
1175
1176%% read input file parameters and set menus
1177Series.PathProject=get(handles.PathCampaign,'String');
1178% InputTable=get(handles.InputTable,'Data');
1179RootPath=Series.InputTable(:,1);
1180SubDir=Series.InputTable(:,2);
1181RootFile=Series.InputTable(:,3);
1182NomType=Series.InputTable(:,4);
1183FileExt=Series.InputTable(:,5);
1184% RootPath=get(handles.RootPath,'String');% path of the root name of the first field series
1185% RootFile=get(handles.RootFile,'String');% root name of the first field series
1186% SubDir=get(handles.SubDir,'String');% subdirectory for netcdf files
1187% FileExt=get(handles.FileExt,'String');%file extension
1188if isempty(SeriesData)
1189    msgbox_uvmat('ERROR','no input file series')
1190    return
1191end
1192% NomType=SeriesData.NomType;
1193if length(RootPath)==1 %string character input for user fct
1194    Series.RootPath=RootPath{1};
1195    Series.RootFile=RootFile{1};
1196    Series.SubDir=SubDir{1};
1197    Series.FileExt=FileExt{1};
1198    Series.NomType=NomType{1};
1199else %cell input for user fct
1200    Series.RootPath=RootPath;
1201    Series.RootFile=RootFile;
1202    Series.SubDir=SubDir;
1203    Series.FileExt=FileExt;
1204    Series.NomType=NomType;
1205end
1206if isequal(get(handles.FieldMenu,'Visible'),'on')
1207    FieldMenu=get(handles.FieldMenu,'String');
1208    FieldValue=get(handles.FieldMenu,'Value');
1209    Series.Field=FieldMenu(FieldValue);
1210end
1211menu_coord_state=get(handles.transform_fct,'Visible');
1212Series.CoordType='';%default
1213if isequal(menu_coord_state,'on')
1214%     menu_coord=get(handles.transform_fct,'String');
1215    menu_index=get(handles.transform_fct,'Value');
1216    transform_list=get(handles.transform_fct,'UserData');
1217    Series.transform_fct=transform_list{menu_index};% transform function handles
1218end
1219   
1220%     
1221% first_i=str2num(get(handles.num_first_i,'String'));
1222% last_i=str2num(get(handles.num_last_i,'String'));
1223% incr_i=str2num(get(handles.num_incr_i,'String'));
1224% first_j=str2num(get(handles.num_first_j,'String'));
1225% last_j=str2num(get(handles.num_last_j,'String'));
1226% incr_j=str2num(get(handles.num_incr_j,'String'));
1227% if ~isequal(get(handles.num_first_i,'Visible'),'on')
1228%    first_i=1;
1229%    last_i=1;
1230%    incr_i=1;
1231% end
1232% if ~isequal(get(handles.num_first_j,'Visible'),'on')
1233%     first_j=1;
1234%     last_j=1;
1235%     incr_j=1;
1236% end
1237
1238%reinitiate waitbar position
1239Series.WaitbarPos=get(handles.waitbar_frame,'Position');%TO SUPPRESS
1240waitbarpos=Series.WaitbarPos;
1241waitbarpos(4)=0.005;%reinitialize waitbar to zero height
1242waitbarpos(2)=Series.WaitbarPos(2)+Series.WaitbarPos(4)-0.005;
1243% set(handles.waitbar,'Position',waitbarpos)
1244
1245if isfield(Series.IndexRange,'NbSlice')
1246Series.NbSlice=Series.IndexRange.NbSlice;
1247end
1248if last_i < first_i | last_j < first_j , msgbox_uvmat('ERROR','last field number must be larger than the first one'),...
1249    set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
1250num_i=first_i:incr_i:last_i;
1251num_j=first_j:incr_j:last_j;
1252% nbfield_cell=get(handles.num_MaxIndex_i,'String');
1253nbfield=cell2mat(Series.IndexRange.MaxIndex);
1254nb=min(nbfield,1);
1255nbfield=nb(1);
1256nbfield2=nb(2);
1257% nbfield2=cell2mat(Series.IndexRange.MaxIndex);
1258% nbfield=min(nbfield);
1259% % nbfield=[]; %default
1260% % for iview=1:length(nbfield_cell)
1261% %     nb=nbfield_cell{iview};
1262% %     if ~isempty(nb)
1263% %         nbfield=[nbfield nb];
1264% %     end
1265% % end
1266% % nbfield=min(nbfield);
1267% nbfield2_cell=get(handles.num_MaxIndex_j,'String');
1268% nbfield2=[]; %default
1269% for iview=1:length(nbfield2_cell)
1270%     nb=str2num(nbfield2_cell{iview});
1271%     if ~isempty(nb)
1272%         nbfield2=[nbfield2 nb];
1273%     end
1274% end
1275% nbfield2=min(nbfield2);
1276
1277%get complementary information from the 'series' interface
1278list_action=get(handles.ACTION,'String');% list menu action
1279index_action=get(handles.ACTION,'Value');% selected string index
1280action= list_action{index_action}; % selected string
1281mode_list=get(handles.mode,'String');
1282index_mode=get(handles.mode,'Value');
1283mode=mode_list{index_mode};
1284ind_shift=0;%default
1285
1286%determine the list of input file names
1287nbmissing=0;
1288for iview=1:length(RootPath)
1289    %case of pairs (.nc files)
1290    fileinput=name_generator(fullfile(RootPath{iview},RootFile{iview}),first_i,first_j,FileExt{iview},NomType{iview},1,first_i+1,first_j+1,SubDir{iview});
1291    if strcmp(get(handles.Pairs,'Visible'),'on')
1292       pair_list=get(handles.list_pair_civ,'String');
1293       val=get(handles.list_pair_civ,'Value');
1294       pair_string=pair_list{val};
1295       r=regexp(pair_string,'.*\D(?<num1>[\d+|*])(?<delim>[-||])(?<num2>[\d+|*])','names');
1296       if ~isempty(r)
1297           if strcmp(r.num1,'*')%free pairs
1298               [tild,RootFile,i1_series,i2_series,j1_series,j2_series,tild,tild,Object]=find_file_series(fileinput)% TODO: choice pair when multiple choice
1299 
1300               if isempty(i2_series) %j pairs
1301                   ind_sel=i1_series>=i1_series>=first_i & i1_series<=last_i & j1_series>first_j & j2_series<last_j;
1302                   j2_series=j2_series(ind_sel);
1303               else%i pairs
1304                   if isempty(j1_series) %j pairs
1305                        ind_sel=i1_series>=first_i & i2_series<=last_i ;
1306                   else
1307                       ind_sel=i1_series>=first_i & i2_series<=last_i& j1_series>first_j & j1_series<last_j;
1308                       j1_series=j1_series(ind_sel);
1309                       i2_series=i2_series(ind_sel);
1310                   end
1311               end
1312               i1_series=i1_series(ind_sel);             
1313           else
1314               if strcmp(r.delim,'-')
1315                   ind_shift(1)=str2num(r.num1);
1316                   ind_shift(2)=str2num(r.num2);
1317               else
1318                   ind_shift(1)=-str2num(r.num1);
1319                   ind_shift(2)=str2num(r.num2);
1320               end
1321               [i1_series,i2_series,j1_series,j2_series,nbmissing]=find_file_indices(num_i,num_j,ind_shift,NomType{iview},mode);
1322           end
1323       end
1324       if isempty(i1_series)
1325           msgbox_uvmat('ERROR','no file in the considered range')
1326           return
1327       end
1328       if isempty(i2_series)
1329           i2_series=i1_series;
1330       end
1331       if isempty(j2_series)
1332           j2_series=j1_series;
1333       end
1334%     if isequal(NomType{iview},'_1_1-2')|| isequal(NomType{iview},'_1-2_1')|| isequal(NomType{iview},'_1-2')|| isequal(NomType{iview},'#_ab')
1335%         ind_shift=SeriesData.displ_num(iview,:);
1336%         if isequal(ind_shift,[0 0 0 0]) % undefined pairs
1337%             if isequal(NomType{iview},'#_ab')
1338%                 mode='#_ab';
1339%             end
1340%             [num_i1,i2_series,j1_series,num_j2,nbmissing]=netseries_generator(fullfile(RootPath{iview},RootFile{iview}),SubDir{iview},mode,num_first_i,num_incr_i,num_last_i,num_first_j,num_incr_j,num_last_j);
1341%         else   
1342%             [num_i1,num_i2,num_j1,num_j2,num_i,num_j]=find_file_indices(num_i,num_j,ind_shift,NomType{iview},mode);
1343%             if isempty(num_i)
1344%                 msgbox_uvmat('ERROR','ERROR: empty set of input files chosen')
1345%                 return
1346%             end
1347%             if num_i(1)>num_first_i
1348%                set(handles.num_first_i,'String',num2str(num_i(1)))%update the display of first field
1349%                last_i_Callback(hObject, eventdata, handles)
1350%             end
1351%             if num_i(end)<num_last_i
1352%                set(handles.num_last_i,'String',num2str(num_i(end)))%update the display of last field
1353%                last_i_Callback(hObject, eventdata, handles)
1354%             end
1355%             if num_j(1)>num_first_j
1356%                set(handles.num_first_j,'String',num2str(num_j(1)))%update the display of first field
1357%                last_j_Callback(hObject, eventdata, handles)
1358%             end
1359%             if num_j(end)<num_last_j
1360%                set(handles.num_last_j,'String',num2str(num_j(end)))%update the display of last field
1361%                last_j_Callback(hObject, eventdata, handles)
1362%             end
1363%         end
1364    else%case of images
1365        [i1_series,j1_series]=meshgrid(num_i,num_j);
1366        i2_series=i1_series;
1367        j2_series=j1_series;
1368    end
1369    if length(RootPath)>1
1370        i1_series_cell{iview}=i1_series;
1371        i2_series_cell{iview}=i2_series;
1372        j1_series_cell{iview}=j1_series;
1373        j2_series_cell{iview}=j2_series;
1374    end
1375end
1376
1377%% defining the ACTION function handle
1378path_series=which('series');
1379list_path=get(handles.ACTION,'UserData');
1380index=get(handles.ACTION,'Value');
1381fct_path=list_path{index}; %path stored for the function ACTION
1382if ~isequal(fct_path,path_series)
1383    eval(['spath=which(''' action ''');']) %spath = current path of the selected function ACTION
1384    if ~exist(fct_path,'dir')
1385        msgbox_uvmat('ERROR',['The prescibed function path ' fct_path ' does not exist'])
1386        return
1387    end
1388    if ~isequal(spath,fct_path)
1389        addpath(fct_path)% add the prescribed path if not the current one
1390    end
1391end
1392eval(['h_fun=@' action ';'])%create a function handle for ACTION
1393if ~isequal(fct_path,path_series)
1394        rmpath(fct_path)% add the prescribed path if not the current one   
1395end
1396
1397%% RUN ACTION
1398Series.Action=action;%name of the processing programme
1399set(handles.RUN,'BackgroundColor',[0.831 0.816 0.784])
1400if length(RootPath)>1
1401    h_fun(i1_series_cell,i2_series_cell,j1_series_cell,j2_series_cell,Series);
1402else
1403    h_fun(i1_series,i2_series,j1_series,j2_series,Series);
1404end
1405set(handles.RUN,'BackgroundColor',[1 0 0])
1406
1407% %save the current interface setting as figure namefig, append .0 to the name if it already exists
1408% detect=1;
1409% while detect==1
1410%     namefigfull=[namedoc '.fig'];
1411%     hh=dir(namefigfull);
1412%     if ~isempty(hh)
1413%         detect=1;
1414%         namedoc=[namedoc '.0'];
1415%     else
1416%         detect=0;
1417%     end
1418% end
1419% saveas(gcbf,namefigfull);%save the interface with name namefigfull (A CHANGER EN FICHIER  .xml)
1420
1421%------------------------------------------------------------------------
1422function STOP_Callback(hObject, eventdata, handles)
1423%------------------------------------------------------------------------
1424set(handles.RUN, 'BusyAction','cancel')
1425set(handles.RUN,'BackgroundColor',[1 0 0])
1426
1427
1428%------------------------------------------------------------------------
1429function num_first_i_Callback(hObject, eventdata, handles)
1430%------------------------------------------------------------------------
1431num_last_i_Callback(hObject, eventdata, handles)
1432
1433%------------------------------------------------------------------------
1434function num_last_i_Callback(hObject, eventdata, handles)
1435%------------------------------------------------------------------------
1436SeriesData=get(handles.series,'UserData');
1437if ~isfield(SeriesData,'Time')
1438    SeriesData.Time{1}=[];
1439end
1440displ_time(handles);
1441
1442%------------------------------------------------------------------------
1443function num_first_j_Callback(hObject, eventdata, handles)
1444%------------------------------------------------------------------------
1445 num_last_j_Callback(hObject, eventdata, handles)
1446
1447%------------------------------------------------------------------------
1448function num_last_j_Callback(hObject, eventdata, handles)
1449%------------------------------------------------------------------------
1450first_j=str2num(get(handles.num_first_j,'String'));
1451last_j=str2num(get(handles.num_last_j,'String'));
1452ref_j=ceil((first_j+last_j)/2);
1453set(handles.ref_j,'String', num2str(ref_j))
1454ref_j_Callback(hObject, eventdata, handles)
1455SeriesData=get(handles.series,'UserData');
1456if ~isfield(SeriesData,'Time')
1457    SeriesData.Time{1}=[];
1458end
1459displ_time(handles);
1460
1461
1462%------------------------------------------------------------------------
1463function ref_i_Callback(hObject, eventdata, handles)
1464%------------------------------------------------------------------------
1465mode_list=get(handles.mode,'String');
1466mode_value=get(handles.mode,'Value');
1467mode=mode_list{mode_value};
1468SeriesData=get(handles.series,'UserData');
1469%NomTypeCell=get(handles.NomType,'String');
1470NomTypeCell=SeriesData.NomType;
1471if ~isempty(NomTypeCell)
1472Val=get(handles.NomType,'Value');
1473NomType=NomTypeCell{Val};
1474% for ilist=1:length(NomType)
1475    if isequal(NomType,'_1_1-2')|| isequal(NomType,'_1-2_1')|| isequal(NomType,'_1-2')
1476        if isequal(mode,'series(Di)')
1477            find_netcpair_civ(handles,Val);% update the menu of pairs depending on the available netcdf files
1478%             break
1479        end
1480    end
1481end
1482
1483%------------------------------------------------------------------------
1484function ref_j_Callback(hObject, eventdata, handles)
1485%------------------------------------------------------------------------
1486mode_list=get(handles.mode,'String');
1487mode_value=get(handles.mode,'Value');
1488mode=mode_list{mode_value};
1489SeriesData=get(handles.series,'UserData');
1490NomTypeCell=SeriesData.NomType;
1491if ~isempty(NomTypeCell)
1492    Val=get(handles.NomType,'Value');
1493    NomType=NomTypeCell{Val};
1494    if isequal(NomType,'_1_1-2')|| isequal(NomType,'_1-2_1')|| isequal(NomType,'_1-2')
1495        if isequal(mode,'series(Dj)')
1496            find_netcpair_civ(handles,Val);% update the menu of pairs depending on the available netcdf files
1497        end
1498    end
1499end
1500
1501%------------------------------------------------------------------------
1502% --- Executes on selection change in ACTION.
1503function ACTION_Callback(hObject, eventdata, handles)
1504%------------------------------------------------------------------------
1505global nb_builtin_ACTION
1506list_ACTION=get(handles.ACTION,'String');% list menu fields
1507index_ACTION=get(handles.ACTION,'Value');% selected string index
1508ACTION= list_ACTION{index_ACTION}; % selected function name
1509path_series=which('series');%path to series.m
1510list_path=get(handles.ACTION,'UserData');%list of recorded paths to functions of the list ACTION
1511default_file=fullfile(list_path{end},ACTION);
1512% add a new function to the menu if the selected item is 'more...'
1513if isequal(ACTION,'more...')
1514    pathfct=fileparts(path_series);
1515    [FileName, PathName, filterindex] = uigetfile( ...
1516       {'*.m', ' (*.m)';
1517        '*.m',  '.m files '; ...
1518        '*.*', 'All Files (*.*)'}, ...
1519        'Pick a file',default_file);
1520    if length(FileName)<2
1521        return
1522    end
1523    [pp,ACTION,ext_fct]=fileparts(FileName);%(end-1:end);
1524    if ~isequal(ext_fct,'.m')
1525        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
1526        return
1527    end
1528   
1529   % insert the choice in the action menu
1530   menu_str=update_menu(handles.ACTION,ACTION);%new action menu in which the new item has been appended if needed
1531   index_ACTION=get(handles.ACTION,'Value');% currently selected index in the list
1532   list_path{index_ACTION}=PathName;
1533   if length(menu_str)>nb_builtin_ACTION+5; %nb_builtin=nbre of functions always remaining in the initial menu
1534       nbremove=length(menu_str)-nb_builtin_ACTION-5;
1535       menu_str(nb_builtin_ACTION+1:end-5)=[];
1536       list_path(nb_builtin_ACTION+1:end-4)=[];
1537       index_ACTION=index_ACTION-nbremove;
1538       set(handles.ACTION,'Value',index_ACTION)
1539       set(handles.ACTION,'String',menu_str)
1540   end
1541   list_path{index_ACTION}=PathName;
1542   set(handles.ACTION,'UserData',list_path);
1543   set(handles.path,'enable','inactive')% indicate that the current path is accessible (not 'off')
1544   
1545   %record the current menu in personal file profil_perso
1546   dir_perso=prefdir;
1547   profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
1548   for ilist=nb_builtin_ACTION+1:length(menu_str)-1
1549       series_fct{ilist-nb_builtin_ACTION}=fullfile(list_path{ilist},[menu_str{ilist} '.m']);     
1550   end
1551   if nb_builtin_ACTION+1<=length(menu_str)-1
1552       if exist(profil_perso,'file')% && nb_builtin_ACTION+1>=length(menu_str)-1
1553           save(profil_perso,'series_fct','-append')
1554       else
1555           txt=ver('MATLAB');
1556           Release=txt.Release;
1557           relnumb=str2num(Release(3:4));
1558           if relnumb >= 14%recent relaese of Matlab
1559               save(profil_perso,'series_fct','-V6')
1560           else
1561               save(profil_perso, 'series_fct')
1562           end
1563       end
1564   end
1565end
1566
1567%check the current path to the selected function
1568PathName=list_path{index_ACTION};%current recorded path
1569set(handles.path,'String',PathName); %show the path to the senlected function
1570
1571%default setting for the visibility of the GUI elements
1572% set(handles.RootPath,'UserData','many')
1573% set(handles.SubDir,'Visible','on')
1574% set(handles.RootFile,'Visible','on')
1575% set(handles.NomType,'Visible','on')
1576% set(handles.FileExt,'Visible','on')
1577set(handles.num_NbSlice,'Visible','off')
1578set(handles.NbSlice_title,'Visible','off')
1579set(handles.VelTypeMenu,'Visible','off');
1580set(handles.VelType_text,'Visible','off');
1581set(handles.VelTypeMenu_1,'Visible','off');
1582set(handles.VelType_text_1,'Visible','off');
1583view_FieldMenu(handles,'off')
1584view_FieldMenu_1(handles,'off')
1585set(handles.FieldTransform,'Visible','off')
1586% view_TRANSFORM(handles,'off')Visible','off')
1587set(handles.Objects,'Visible','off');
1588set(handles.GetMask,'Visible','off')
1589set(handles.Mask,'Visible','off')
1590% set(handles.GetObject,'Visible','off');
1591set(handles.OutputDir,'Visible','off');
1592% set(handles.PARAMETERS_frame,'Visible','off');
1593% set(handles.PARAMETERS_title,'Visible','off');
1594set(handles.ParamKey,'Visible','off')
1595set(handles.ParamVal,'Visible','off')
1596ParamKey={};
1597set(handles.FieldMenu,'Enable','off')
1598set(handles.VelTypeMenu,'Enable','off')
1599set(handles.FieldMenu_1,'Enable','off')
1600set(handles.VelTypeMenu_1,'Enable','off')
1601set(handles.transform_fct,'Enable','off')
1602%set the displayed GUI item needed for input parameters
1603if ~isequal(path_series,PathName)
1604    addpath(PathName)
1605end
1606eval(['h_function=@' ACTION ';']);
1607try
1608    [fid,errormsg] =fopen([ACTION '.m']);
1609    InputText=textscan(fid,'%s',1,'delimiter','\n');
1610    fclose(fid)
1611    set(handles.ACTION,'ToolTipString',InputText{1}{1})
1612end
1613if ~isequal(path_series,PathName)
1614    rmpath(PathName)
1615end
1616varargout=h_function();
1617Param_list={};
1618
1619%nb_series=length(RootFile);
1620% FileExt=get(handles.FileExt,'String');
1621% nb_series=length(FileExt);
1622InputFiles=get(handles.InputTable,'Data')
1623FileExt=InputFiles(:,5);
1624checkcell=find(cellfun('isempty',FileExt)~=0);
1625nb_series=0;
1626if ~isempty(checkcell)
1627nb_series=checkcell(end);
1628end
1629% nb_series=size(InputFiles,1)
1630testima_series=1; %test for a list of images only
1631testima=1;
1632testima_1=1;
1633testciv_series=1;
1634for iview=1:nb_series
1635     ext=FileExt{iview};
1636    if length(ext)<2
1637        ext='.none';
1638    end
1639    testimaview=~isempty(imformats(ext(2:end))) || isequal(lower(ext),'.avi');
1640    if ~testimaview
1641        if iview==1
1642            testima=0;
1643        end
1644        if iview==2
1645            testima_1=0;
1646        end
1647        testima_series=0;
1648    end
1649end
1650for ilist=1:length(varargout)-1
1651    switch varargout{ilist}
1652                       %RootFile always visible
1653%          case 'RootPath'   %visible by default
1654%             value=lower(varargout{ilist+1});
1655%             if isequal(value,'one')||isequal(value,'two')||isequal(value,'many')
1656%                 set(handles.RootFile,'UserData',value)% for use in menu Open_insert
1657%             end
1658%         case 'SubDir' %visible by default
1659%             if isequal(lower(varargout{ilist+1}),'off')
1660%                 set(handles.SubDir,'Visible','off')
1661%             end
1662%         case 'RootFile'   %visible by default
1663%             value=lower(varargout{ilist+1});
1664%             if isequal(value,'off')
1665%                 set(handles.RootFile,'Visible','off')
1666%             elseif isequal(value,'one')||isequal(value,'two')||isequal(value,'many')
1667%                 set(handles.RootFile,'Visible','on')
1668%                 set(handles.RootFile,'UserData',value)% for use in menu Open_insert
1669%             end
1670%         case 'NomType'   %visible by default
1671%             if isequal(lower(varargout{ilist+1}),'off')
1672%                 set(handles.NomType,'Visible','off')
1673%             end
1674%         case 'FileExt'   %visible by default
1675%             if isequal(lower(varargout{ilist+1}),'off')
1676%                 set(handles.FileExt,'Visible','off')
1677%             end
1678        case 'NbSlice'   %hidden by default
1679            if isequal(lower(varargout{ilist+1}),'on')
1680                set(handles.num_NbSlice,'Visible','on')
1681                set(handles.NbSlice_title,'Visible','on')
1682            end
1683        case 'VelTypeMenu'   %hidden by default
1684            if isequal(lower(varargout{ilist+1}),'one') || isequal(lower(varargout{ilist+1}),'two')
1685                set(handles.VelTypeMenu,'Enable','on')
1686                if nb_series >=1 && ~testima_series
1687                    set(handles.VelTypeMenu,'Visible','on')
1688                    set(handles.VelType_text,'Visible','on');
1689                    set(handles.Field_frame,'Visible','on')
1690                end
1691            end
1692            if isequal(lower(varargout{ilist+1}),'two')
1693                set(handles.VelTypeMenu_1,'Enable','on')
1694                if nb_series >=2 && ~testima_series
1695                    set(handles.VelTypeMenu_1,'Visible','on')
1696                    set(handles.VelType_text_1,'Visible','on');
1697                end
1698            end
1699        case 'FieldMenu'   %hidden by default
1700            if isequal(lower(varargout{ilist+1}),'one')||isequal(lower(varargout{ilist+1}),'two')
1701                set(handles.FieldMenu,'Enable','on') % test for MenuBorser
1702                if nb_series >=1 && ~testima_series
1703                    view_FieldMenu(handles,'on')
1704                end
1705            end
1706            if isequal(lower(varargout{ilist+1}),'two')
1707                set(handles.FieldMenu_1,'Enable','on')
1708                if nb_series >=2 && ~testima_1
1709                    view_FieldMenu_1(handles,'on')
1710                end
1711            end
1712        case 'CoordType'   %hidden by default
1713            if isequal(lower(varargout{ilist+1}),'on')
1714                set(handles.transform_fct,'Enable','on')
1715                set(handles.FieldTransform,'Visible','on')
1716%                 view_TRANSFORM(handles,'on')
1717            end
1718        case 'GetObject'   %hidden by default
1719            if isequal(lower(varargout{ilist+1}),'on')   
1720                set(handles.Objects,'Visible','on')
1721%                 set(handles.GetObject,'Visible','on');
1722            end
1723        case 'Mask'   %hidden by default
1724            if isequal(lower(varargout{ilist+1}),'on')   
1725                set(handles.Objects,'Visible','on')
1726%                 set(handles.GetMask,'Visible','on');
1727            end
1728        case 'PARAMETER' 
1729            set(handles.PARAMETERS_frame,'Visible','on')
1730            set(handles.PARAMETERS_title,'Visible','on')
1731            set(handles.ParamKey,'Visible','on')
1732            %set(handles.ParamVal,'Visible','on')
1733            Param_str=varargout{ilist+1};
1734            Param_list=[Param_list; {Param_str}];         
1735    end
1736end
1737if ~isempty(Param_list)
1738    set(handles.ParamKey,'String',Param_list)
1739    set(handles.ParamVal,'Visible','on')
1740end
1741
1742%------------------------------------------------------------------------
1743% --- Executes on selection change in FieldMenu.
1744function FieldMenu_Callback(hObject, eventdata, handles)
1745%------------------------------------------------------------------------
1746field_str=get(handles.FieldMenu,'String');
1747field_index=get(handles.FieldMenu,'Value');
1748field=field_str{field_index(1)};
1749if isequal(field,'get_field...')   
1750     hget_field=findobj(allchild(0),'name','get_field');
1751     if ~isempty(hget_field)
1752         delete(hget_field)%delete opened versions of get_field
1753     end
1754     SeriesData=get(handles.series,'UserData');
1755     filename=SeriesData.CurrentInputFile;
1756     if exist(filename,'file')
1757        get_field(filename)
1758     end
1759elseif isequal(field,'more...')
1760    str=calc_field;
1761    [ind_answer,v] = listdlg('PromptString','Select a file:',...
1762                'SelectionMode','single',...
1763                'ListString',str);
1764       % edit the choice in the fields and action menu
1765     scalar=cell2mat(str(ind_answer));
1766     update_menu(handles.FieldMenu,scalar)
1767end
1768
1769%------------------------------------------------------------------------
1770% --- Executes on selection change in FieldMenu_1.
1771function FieldMenu_1_Callback(hObject, eventdata, handles)
1772%------------------------------------------------------------------------
1773field_str=get(handles.FieldMenu_1,'String');
1774field_index=get(handles.FieldMenu_1,'Value');
1775field=field_str{field_index};
1776if isequal(field,'get_field...')   
1777     hget_field=findobj(allchild(0),'name','get_field_1');
1778     if ~isempty(hget_field)
1779         delete(hget_field)
1780     end
1781     SeriesData=get(handles.series,'UserData');
1782     filename=SeriesData.CurrentInputFile_1;
1783     if exist(filename,'file')
1784        hget_field=get_field(filename);
1785        set(hget_field,'name','get_field_1')
1786     end
1787elseif isequal(field,'more...')
1788    str=calc_field;
1789    [ind_answer,v] = listdlg('PromptString','Select a file:',...
1790                'SelectionMode','single',...
1791                'ListString',str);
1792       % edit the choice in the fields and action menu
1793     scalar=cell2mat(str(ind_answer));
1794     update_menu(handles.FieldMenu_1,scalar)
1795end   
1796
1797
1798%%%%%%%%%%%%%
1799function [ind_remove]=find_pairs(dirpair,ind_i,last_i)
1800indsel=ind_i;
1801indiff=diff(ind_i); %test index increment to detect multiplets (several pairs with the same index ind_i) and holes in the series
1802indiff=[1 indiff last_i-ind_i(end)+1];%for testing gaps with the imposed bounds
1803if ~isempty(indiff)
1804    indiff2=diff(indiff);
1805    indiffp=[indiff2 1];
1806    indiffm=[1 indiff2];
1807    ind_multi_m=find((indiff==0)&(indiffm<0))-1;%indices of first members of multiplets
1808    ind_multi_p=find((indiff==0)&(indiffp>0));%indices of last members of multiplets
1809    %for each multiplet, select the most recent file
1810    ind_remove=[];
1811    for i=1:length(ind_multi_m)
1812        ind_pairs=ind_multi_m(i):ind_multi_p(i);
1813        for imulti=1:length(ind_pairs)
1814            datepair(imulti)=datenum(dirpair(ind_pairs(imulti)).date);%dates of creation
1815        end
1816        [datenew,indsort2]=sort(datepair); %sort the multiplet by creation date
1817        ind_s=indsort2(1:end-1);%
1818        ind_remove=[ind_remove ind_pairs(ind_s)];%remove these indices, leave the last one
1819    end
1820end
1821
1822%------------------------------------------------------------------------
1823% --- determine the list of index pairs of processing file
1824function [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)
1825%------------------------------------------------------------------------
1826num_i1=num_i;% set of first image numbers by default
1827num_i2=num_i;
1828num_j1=num_j;
1829num_j2=num_j;
1830num_i_out=num_i;
1831num_j_out=num_j;
1832% if isequal (NomType,'_1-2_1') || isequal (NomType,'_1-2')
1833if isequal(mode,'series(Di)')
1834    num_i1_line=num_i+ind_shift(3);% set of first image numbers
1835    num_i2_line=num_i+ind_shift(4);
1836    % adjust the first and last field number
1837        indsel=find(num_i1_line >= 1);
1838    num_i_out=num_i(indsel);
1839    num_i1_line=num_i1_line(indsel);
1840    num_i2_line=num_i2_line(indsel);
1841    num_j1=meshgrid(num_j,ones(size(num_i1_line)));
1842    num_j2=meshgrid(num_j,ones(size(num_i1_line)));
1843    [xx,num_i1]=meshgrid(num_j,num_i1_line);
1844    [xx,num_i2]=meshgrid(num_j,num_i2_line);
1845elseif isequal (mode,'series(Dj)')||isequal (mode,'bursts')
1846    if isequal(mode,'bursts') %case of bursts (png_old or png_2D)
1847        num_j1=ind_shift(1)*ones(size(num_i));
1848        num_j2=ind_shift(2)*ones(size(num_i));
1849    else
1850        num_j1_col=num_j+ind_shift(1);% set of first image numbers
1851        num_j2_col=num_j+ind_shift(2);
1852        % adjust the first field number
1853        indsel=find((num_j1_col >= 1));   
1854        num_j_out=num_j(indsel);
1855        num_j1_col=num_j1_col(indsel);
1856        num_j2_col=num_j2_col(indsel);
1857        [num_i1,num_j1]=meshgrid(num_i,num_j1_col);
1858        [num_i2,num_j2]=meshgrid(num_i,num_j2_col);
1859    end   
1860end
1861
1862%------------------------------------------------------------------------
1863% ---- find the times corresponding to the first and last indices of a series
1864function displ_time(handles)
1865%------------------------------------------------------------------------
1866SeriesData=get(handles.series,'UserData');%
1867first_i=str2num(get(handles.num_first_i,'String'));
1868first_j=str2num(get(handles.num_first_j,'String'));
1869last_i=str2num(get(handles.num_last_i,'String'));
1870last_j=str2num(get(handles.num_last_j,'String'));
1871NomType=SeriesData.NomType;
1872mode_list=get(handles.mode,'String');
1873index_mode=get(handles.mode,'Value');
1874mode=mode_list{index_mode};
1875
1876time_first=[];
1877time_last=[];
1878if ~isfield(SeriesData,'Time')
1879    SeriesData.Time{1}=[];
1880end
1881for iview=1:length(NomType)
1882    time_first_cell{iview}='?';
1883    time_last_cell{iview}='?';%default
1884    time=SeriesData.Time{iview};
1885    if isequal(NomType{iview},'_1-2_1')|isequal(NomType{iview},'_1_1-2')|isequal(NomType{iview},'#_ab')|isequal(NomType{iview},'_1-2')
1886        if isfield(SeriesData,'displ_num')& ~isempty(SeriesData.displ_num)
1887            ind_shift=SeriesData.displ_num(iview,:);
1888            if isequal(mode,'bursts')
1889                first_j=0;
1890                last_j=0;
1891            end
1892            first_i1=first_i +ind_shift(3);
1893            first_i2 =first_i +ind_shift(4);
1894            first_j1 =first_j +ind_shift(1);
1895            first_j2 =first_j +ind_shift(2);
1896            last_i1=last_i +ind_shift(3);
1897            last_i2 =last_i +ind_shift(4);   
1898            last_j1 =last_j +ind_shift(1);
1899            last_j2 =last_j +ind_shift(2);
1900            siz=size(SeriesData.Time{1});
1901            if first_i1>=1 && first_j1>=1 && siz(1)>=last_i2 && siz(2)>=last_j2
1902                time_first=(time(first_i1,first_j1)+time(first_i2,first_j2))/2;
1903                time_last=(time(last_i1,last_j1)+time(last_i2,last_j2))/2;
1904            else%read the time in the nc files
1905                RootPath=get(handles.RootPath,'String');
1906                RootFile=get(handles.RootFile,'String');
1907                SubDir=get(handles.SubDir,'String');
1908                %VelType=get(handles.VelType,'String');
1909                VelType_str=get(handles.VelTypeMenu,'String');
1910                VelType_val=get(handles.VelTypeMenu,'Value');
1911                VelType=VelType_str{VelType_val};
1912                filebase=fullfile(RootPath{1},RootFile{1});
1913                [filefirst]=name_generator(filebase,first_i1,first_j1,'.nc',NomType{iview},1,first_i2,first_j2,SubDir{iview});
1914                if  exist(filefirst,'file')
1915                    Attrib=nc2struct(filefirst,[]);
1916                    if isfield(Attrib,'Time')
1917                        time_first=Attrib.Time;
1918                    else
1919                        if isfield(Attrib,'absolut_time_T0')
1920                            time_first=Attrib.absolut_time_T0;
1921                        end
1922                        if isfield(Attrib,'absolut_time_T0_2')&&~(isequal(VelType,'civ1')||isequal(VelType,'interp1')||isequal(VelType,'filter1'))
1923                            time_first=Attrib.absolut_time_T0_2;
1924                        end
1925                    end
1926                end
1927                [filelast]=name_generator(filebase,last_i1,last_j1,'.nc',NomType{iview},1,last_i2,last_j2,SubDir{iview});
1928                if exist(filelast,'file')
1929                   Attrib=nc2struct(filelast,[]);
1930                    if isfield(Attrib,'Time')
1931                        time_last=Attrib.Time;
1932                    else
1933                        if isfield(Attrib,'absolut_time_T0')
1934                            time_last=Attrib.absolut_time_T0;
1935                        end
1936                        if isfield(Attrib,'absolut_time_T0_2')&&~(isequal(VelType,'civ1')||isequal(VelType,'interp1')||isequal(VelType,'filter1'))
1937                            time_last=Attrib.absolut_time_T0_2;
1938                        end
1939                    end
1940                end
1941            end
1942        end
1943    else
1944        siz=size(time);
1945        if siz(1)>=last_i && siz(2)>=last_j && first_i>=1 && first_j>=1
1946            time_first=times(first_i,first_j);
1947            time_last=times(last_i,last_j);
1948        end
1949    end
1950    time_first_cell{iview}=num2str(time_first,4);
1951    time_last_cell{iview}=num2str(time_last,4);
1952end
1953% set(handles.time_first,'Value',1)
1954% set(handles.time_last,'Value',1)
1955% set(handles.time_first,'String',time_first_cell);
1956% set(handles.time_last,'String',time_last_cell);
1957
1958%------------------------------------------------------------------------
1959% --- Executes on button press in GetObject.
1960function GetObject_Callback(hObject, eventdata, handles)
1961%------------------------------------------------------------------------
1962SeriesData=get(handles.series,'UserData');
1963value=get(handles.GetObject,'Value');
1964if value
1965     set(handles.GetObject,'BackgroundColor',[1 1 0])%put unactivated buttons to yellow
1966%      DataInit.ParentButton=handles.GetObject;
1967     hset_object=findobj(allchild(0),'tag','set_object');%find the set_object interface handle
1968     if ishandle(hset_object)
1969         uistack(hset_object,'top')
1970        %[SeriesData.hset_object,SeriesData.sethandles]=set_object(DataInit); %open the set_object interface
1971     else
1972         %get the object file
1973         defaultname=get(handles.RootPath,'String');
1974         if isempty(defaultname)
1975            defaultname={''};
1976         end
1977        [FileName, PathName, filterindex] = uigetfile( ...
1978       {'*.xml;*.mat', ' (*.xml,*.mat)';
1979       '*.xml',  '.xml files '; ...
1980        '*.mat',  '.mat matlab files '}, ...
1981        'Pick an xml object file (or use uvmat to create it)',defaultname{1});
1982        fileinput=[PathName FileName];%complete file name
1983        testblank=findstr(fileinput,' ');%look for blanks
1984        if ~isempty(testblank)
1985            msgbox_uvmat('ERROR','forbidden input file name: contain blanks')
1986            return
1987        end
1988        sizf=size(fileinput);
1989        if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end
1990        %read the file
1991        t=xmltree(fileinput);
1992        data=convert(t);
1993        if ~isfield(data,'Style')
1994             data.Style='points';
1995        end
1996        if ~isfield(data,'ProjMode')
1997             data.ProjMode='projection';
1998        end
1999        transform_menu=get(handles.transform_fct,'String');
2000        ichoice=get(handles.transform_fct,'Value');
2001%         if isequal(transform_menu{ichoice},'px');
2002%             data.CoordType='px';
2003%         else
2004%             data.CoordType='phys';
2005%         end
2006        data.desable_plot=1;
2007        [SeriesData.hset_object,SeriesData.sethandles]=set_object(data);% call the set_object interface
2008     end
2009else
2010    set(handles.GetObject,'BackgroundColor',[0.7 0.7 0.7])%put activated buttons to green
2011%     if isfield(SeriesData,'hset_object')&& ishandle(SeriesData.hset_object)
2012%         close(SeriesData.hset_object)
2013%     end
2014end
2015set(handles.series,'UserData',SeriesData)
2016
2017%--------------------------------------------------------------
2018function GetMask_Callback(hObject, eventdata, handles)
2019value=get(handles.GetMask,'Value');
2020if value
2021    msgbox_uvmat('ERROR','not implemented yet')
2022end
2023%--------------------------------------------------------------
2024
2025%-------------------------------------------------------------------
2026%'uv_ncbrowser': interactively calls the netcdf file browser 'get_field.m'
2027function ncbrowser_uvmat(hObject, eventdata)
2028%-------------------------------------------------------------------
2029     bla=get(gcbo,'String');
2030     ind=get(gcbo,'Value');
2031     filename=cell2mat(bla(ind));
2032      blank=find(filename==' ');
2033      filename=filename(1:blank-1);
2034     get_field(filename)
2035
2036% ------------------------------------------------------------------
2037function MenuHelp_Callback(hObject, eventdata, handles)
2038%-------------------------------------------------------------------
2039path_to_uvmat=which ('uvmat');% check the path of uvmat
2040pathelp=fileparts(path_to_uvmat);
2041helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html');
2042if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package')
2043else
2044    addpath (fullfile(pathelp,'uvmat_doc'))
2045    web([helpfile '#series'])
2046end
2047
2048%-------------------------------------------------------------------
2049% --- Executes on selection change in transform_fct.
2050function transform_fct_Callback(hObject, eventdata, handles)
2051%-------------------------------------------------------------------
2052global nb_transform
2053
2054menu=get(handles.transform_fct,'String');
2055ind_coord=get(handles.transform_fct,'Value');
2056coord_option=menu{ind_coord};
2057list_transform=get(handles.transform_fct,'UserData');
2058ff=functions(list_transform{end});
2059if isequal(coord_option,'more...');
2060    coord_fct='';
2061    prompt = {'Enter the name of the transform function'};
2062    dlg_title = 'user defined transform';
2063    num_lines= 1;
2064    [FileName, PathName, filterindex] = uigetfile( ...
2065       {'*.m', ' (*.m)';
2066        '*.m',  '.m files '; ...
2067        '*.*', 'All Files (*.*)'}, ...
2068        'Pick a file', ff.file);
2069    if isequal(PathName(end),'/')||isequal(PathName(end),'\')
2070        PathName(end)=[];
2071    end
2072    transform_selected =fullfile(PathName,FileName);
2073    if ~exist(transform_selected,'file')
2074          return
2075    end
2076    [ppp,transform,xt_fct]=fileparts(FileName);% removes extension .m
2077    if ~isequal(ext_fct,'.m')
2078        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
2079        return
2080    end
2081   menu=update_menu(handles.transform_fct,transform);%add the selected fct to the menu
2082   ind_coord=get(handles.transform_fct,'Value');
2083   addpath(PathName)
2084   list_transform{ind_coord}=str2func(transform);% create the function handle corresponding to the newly seleced function
2085   set(handles.transform_fct,'UserData',list_transform)
2086   rmpath(PathName)
2087   % save the new menu in the personal file 'uvmat_perso.mat'
2088   dir_perso=prefdir;%personal Matalb directory
2089   profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
2090   if exist(profil_perso,'file')
2091       for ilist=nb_transform+1:numel(list_transform)
2092           ff=functions(list_transform{ilist});
2093           transform_fct{ilist-nb_transform}=ff.file;
2094       end
2095        save (profil_perso,'transform_fct','-append'); %store the root name for future opening of uvmat
2096   end
2097end
2098
2099%check the current path to the selected function
2100if ~isempty(list_transform{ind_coord})
2101func=functions(list_transform{ind_coord});
2102set(handles.path_transform,'String',fileparts(func.file)); %show the path to the senlected function
2103else
2104   set(handles.path_transform,'String',''); %show the path to the senlected function
2105end
2106%------------------------------------------------------------------------
2107% --- generates a series of file names with reference numbers between range1 and
2108% --- range2 with increment incr. The reference number num_ref is the image number at the middle of the
2109% --- image pair. The set of first numbers num1 of the image pairs is also
2110% --- given as output
2111% function [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)
2112% %------------------------------------------------------------------------
2113% [Path,Name]=fileparts(filebase);
2114% filebasesub=fullfile(Path,subdir,Name);
2115% filecell={};%default
2116% num_i1=[];
2117% num_i2=[];
2118% num_j1=[];
2119% num_j2=[];
2120% ind0_i=first_i:incr_i:last_i;
2121% nbcolumn=length(ind0_i);
2122% ind0_j=first_j:incr_j:last_j;
2123% nbline=length(ind0_j);
2124% if isequal(mode,'#_ab')
2125%     dirpair=dir([filebasesub '*_*.nc']);
2126% elseif isequal(mode,'bursts')||isequal(mode,'series(Dj)') 
2127%     dirpair=dir([filebasesub '_*_*-*.nc']);
2128% elseif isequal(mode,'series(Di)')
2129%     dirpair=dir([filebasesub '_*-*_*.nc']);
2130% else
2131%     msgbox_uvmat('ERROR','option *|* not yet implemented')
2132%     return
2133% end
2134% if isempty(dirpair)
2135%         msgbox_uvmat('ERROR','no pair detected in the selected range')
2136%         return
2137% end
2138%
2139% if isequal(mode,'bursts')||isequal(mode,'#_ab')
2140%     icount=0;
2141%     for ifile=1:length(dirpair)
2142%         [RootPath,RootFile,str_1,str_2,str_a,str_b,ext,nom_type]=name2display(dirpair(ifile).name);
2143%         num1_r=str2num(str_1);
2144%         if isequal(RootFile,Name) & ~isempty(num1_r)   
2145%             num_i1(ifile)=num1_r;
2146%             num_a(ifile)=stra2num(str_a);
2147%             num_b(ifile)=stra2num(str_b);
2148%         end     
2149%     end
2150%     test_range= (num_i1 >=first_i)&(num_i1<= last_i);% =1 when both numbers are in the range
2151%     ind_i=((num_i1-first_i)/incr_i)+1;%indices i in the list of prescribed file indices
2152%     select=find(test_range &(floor(ind_i)==ind_i));%selected indices of num_i1 in the file directory
2153%     ind_i=ind_i(select);%set of selected indices ind_i
2154%     [ind_i,indsort]=sort(ind_i);%sorted list of ind_i
2155%     select=select(indsort);
2156%     num_i1=num_i1(select);
2157%     num_a=num_a(select);
2158%     num_b=num_b(select);
2159%     dirpair=dirpair(select);
2160%     [ind_remove]=find_pairs(dirpair,ind_i,nbcolumn);
2161%     ind_i(ind_remove)=[];
2162%     num_a(ind_remove)=[];
2163%     num_b(ind_remove)=[];
2164%     num_j1=zeros(1,nbcolumn);%default
2165%     num_j2=num_j1;
2166%     num_j1(ind_i)=num_a;
2167%     num_j2(ind_i)=num_b;
2168%     num_i1=first_i:incr_i:last_i;
2169%     num_i2=num_i1;
2170%     nbmissing=nbcolumn-length(ind_i);
2171%
2172% elseif isequal(mode,'series(Di)')
2173%     %ind0_i=num_first_i:num_incr_i:num_last_i;
2174%     %nbcolumn=length(ind0_i);
2175%     %ind0_j=num_first_j:num_incr_j:num_last_j;
2176%     %nbline=length(ind0_j);
2177%     %dirpair=dir([filebasesub '_*-*_*.nc']);
2178%     for ifile=1:length(dirpair)
2179%         [RootPath,RootFile,str_1,str_2,str_a,str_b,ext,nom_type]=name2display(dirpair(ifile).name);
2180%         num_i1_r(ifile)=str2num(str_1);
2181%         num_i2_r(ifile)=str2num(str_2);
2182%         num_j(ifile)=str2num(str_a);
2183%     end
2184%     num_i=floor((num_i1_r+num_i2_r)/2); %list of reference indices of the detected files
2185%     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
2186%     ind_i=((num_i-first_i)/incr_i)+1;%indices i and j in the list of prescribed file indices
2187%     ind_j=((num_j-first_j)/incr_j)+1;
2188%     ind_ij=ind_j+nbline*(ind_i-1);%indices in the reshhaped series of prescribed file indices
2189%     select=find(test_range &(floor(ind_i)==ind_i)&(floor(ind_j)==ind_j));%selected indices in the file directory
2190%     ind_ij=ind_ij(select);%set of selected indices ind_ij
2191%     [ind_ij,indsort]=sort(ind_ij);%sorted list of ind_ij
2192%     select=select(indsort);
2193%     num_i1_r=num_i1_r(select);
2194%     num_i2_r=num_i2_r(select);
2195%     dirpair=dirpair(select);
2196%     [ind_remove]=find_pairs(dirpair,ind_ij,nbcolumn*nbline) ;
2197%     ind_ij(ind_remove)=[];
2198%     num_i1_r(ind_remove)=[];
2199%     num_i2_r(ind_remove)=[];
2200%     num_i1=zeros(1,nbline*nbcolumn);%default
2201%     num_i2=num_i1;
2202%     num_i1(ind_ij)=num_i1_r;
2203%     num_j2(ind_ij)=num_i2_r;
2204%     num_i1=reshape(num_i1,nbline,nbcolumn);
2205%     num_i2=reshape(num_i2,nbline,nbcolumn);
2206%     num_j1=meshgrid(ind0_i,ind0_j);
2207%     num_j2=num_j1;
2208%     nbmissing=nbline*nbcolumn-length(ind_ij);
2209% elseif isequal(mode,'series(Dj)')
2210%     for ifile=1:length(dirpair)
2211%         [RootPath,RootFile,str_1,str_2,str_a,str_b,ext,nom_type]=name2display(dirpair(ifile).name);
2212%         num_i(ifile)=str2num(str_1);
2213%         num_a(ifile)=str2num(str_a);
2214%         num_b(ifile)=str2num(str_b);
2215%     end
2216%     num_j=floor((num_a+num_b)/2); %list of reference indices of the detected files
2217%     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
2218%     ind_i=((num_i-first_i)/incr_i)+1;%indices i and j in the list of prescribed file indices
2219%     ind_j=((num_j-first_j)/incr_j)+1;
2220%     ind_ij=ind_j+nbline*(ind_i-1);%indices in the reshhaped series of prescribed file indices
2221%     select=find(test_range &(floor(ind_i)==ind_i)&(floor(ind_j)==ind_j));%selected indices in the file directory
2222%     ind_ij=ind_ij(select);%set of selected indices ind_ij
2223%     [ind_ij,indsort]=sort(ind_ij);%sorted list of ind_ij
2224%     select=select(indsort);
2225%     num_i=num_i(select);
2226%     num_a=num_a(select);
2227%     num_b=num_b(select);
2228%     dirpair=dirpair(select);
2229%     [ind_remove]=find_pairs(dirpair,ind_ij,nbcolumn*nbline) ;
2230%     ind_ij(ind_remove)=[];
2231%     num_a(ind_remove)=[];
2232%     num_b(ind_remove)=[];
2233%     num_j1=zeros(1,nbline*nbcolumn);%default
2234%     num_j2=num_j1;
2235%     num_j1(ind_ij)=num_a;
2236%     num_j2(ind_ij)=num_b;
2237%     num_j1=reshape(num_j1,nbline,nbcolumn);
2238%     num_j2=reshape(num_j2,nbline,nbcolumn);
2239%     num_i1=meshgrid(ind0_i,ind0_j);
2240%     num_i2=num_i1;
2241%     nbmissing=nbline*nbcolumn-length(ind_ij);
2242% end
2243
2244
2245% --- Executes on button press in REFRESH_INDICES.
2246function REFRESH_INDICES_Callback(hObject, eventdata, handles)
2247% hObject    handle to REFRESH_INDICES (see GCBO)
2248% eventdata  reserved - to be defined in a future version of MATLAB
2249% handles    structure with handles and user data (see GUIDATA)
2250set(handles.REFRESH_INDICES,'BackgroundColor',[0.7 0.7 0.7])
2251InputTable=get(handles.InputTable,'Data');
2252list_lines=get(handles.REFRESH_INDICES,'UserData');
2253
2254%% check the indices and FileTypes for each series (limited to the new ones to save time)
2255for ind_list=1:length(list_lines)
2256    if list_lines(ind_list)
2257        InputLine=InputTable(list_lines(ind_list),:);
2258        detect_idem=strcmp('"',InputLine);% look for '" (repeat of previous data)
2259        if ~isempty(detect_idem)&& list_lines(ind_list)>1
2260            InputLine{detect_idem}=InputTable(list_lines(ind_list)-1,detect_idem);
2261            set(handles.InputTable,'Data',InputTable)
2262        end
2263        fileinput=name_generator(fullfile(InputLine{1},InputLine{3}),1,1,InputLine{5},InputLine{4},1,2,2,InputLine{2});
2264        %update file series defined by the selected line
2265        [InputTable{list_lines(ind_list),1},InputTable{list_lines(ind_list),2},InputTable{list_lines(ind_list),4},errormsg]=update_indices(handles,fileinput,list_lines(ind_list));
2266        if ~isempty(errormsg)
2267                msgbox_uvmat('ERROR',errormsg)
2268                return
2269        end
2270    end
2271end
2272set(handles.InputTable,'Data',InputTable)
2273SeriesData=get(handles.series,'UserData');
2274
2275state_j='off';
2276state_Pairs='off';
2277state_InputFields='off';
2278if ~isempty(SeriesData)
2279for ilist=1:size(InputTable,1)
2280    SeriesData.j1_series{ilist}
2281    if ~isempty(SeriesData.j1_series{ilist})
2282        state_j='on';
2283    end
2284    if ~isempty(SeriesData.i2_series{ilist})||~isempty(SeriesData.j2_series{ilist})
2285         state_Pairs='on';
2286    end
2287    if strcmp(SeriesData.FileType,'civx')||strcmp(SeriesData.FileType,'civdata')
2288        state_InputFields='on';
2289    end
2290end
2291end
2292set(handles.num_first_j,'Visible',state_j)
2293set(handles.num_last_j,'Visible',state_j)
2294set(handles.num_incr_j,'Visible',state_j)
2295set(handles.Pairs,'Visible',state_InputFields)
2296
2297set(handles.REFRESH_INDICES,'BackgroundColor',[1 0 0])
2298set(handles.REFRESH_INDICES,'visible','off')
2299
2300% update min and max indices for a series
2301function [RootPath,RootFile,NomType,errormsg]=update_indices(handles,fileinput,index)
2302
2303%% look for min and max indices existing in the file series and update SeriesData
2304errormsg='';
2305[RootPath,RootFile,i1_series,i2_series,j1_series,j2_series,NomType,FileType,Object]=find_file_series(fileinput);
2306if isempty(RootFile)&&isempty(i1_series)
2307    errormsg='not input file in the series';
2308    return
2309end
2310[tild,tild,FileExt]=fileparts(fileinput);
2311
2312MinIndex=get(handles.MinIndex,'Data');
2313MaxIndex=get(handles.MaxIndex,'Data');
2314MinIndex_i=min(i1_series(i1_series>0));
2315if ~isempty(i2_series)
2316    MaxIndex_i=max(i2_series(i2_series>0));
2317else
2318    MaxIndex_i=max(i1_series(i1_series>0));
2319end
2320MinIndex_j=min(j1_series(j1_series>0));
2321if ~isempty(j2_series)
2322    MaxIndex_j=max(j2_series(j2_series>0));
2323else
2324    MaxIndex_j=max(j1_series(j1_series>0));
2325end
2326MinIndex{index,1}=MinIndex_i;
2327MinIndex{index,2}=MinIndex_j;
2328MaxIndex{index,1}=MaxIndex_i;
2329MaxIndex{index,2}=MaxIndex_j;
2330set(handles.MinIndex,'Data',MinIndex)
2331set(handles.MaxIndex,'Data',MaxIndex)
2332SeriesData=get(handles.series,'UserData');
2333SeriesData.i1_series{index}=i1_series;
2334SeriesData.i2_series{index}=i2_series;
2335SeriesData.j1_series{index}=j1_series;
2336SeriesData.j2_series{index}=j2_series;
2337SeriesData.FileType{index}=FileType;
2338
2339%% represents the set of existing files as an image
2340set(handles.waitbar_frame,'Units','pixels')
2341pos=get(handles.waitbar_frame,'Position');
2342xima=0.5:pos(3)-0.5;% pixel positions on the image representing the existing file indices
2343yima=0.5:pos(4)-0.5;
2344[XIma,YIma]=meshgrid(xima,yima);
2345nb_i=size(i1_series,1);
2346nb_j=size(i1_series,2);
2347ind_i=(0.5:nb_i-0.5)*pos(3)/nb_i;
2348ind_j=(0.5:nb_j-0.5)*pos(4)/nb_j;
2349[Ind_i,Ind_j]=meshgrid(ind_i,ind_j);
2350CData=zeros([size(XIma) 3]);
2351file_ima=double((i1_series(:,:,1)>0)');
2352if numel(file_ima)>=2
2353if size(file_ima,1)==1
2354    CLine=interp1(ind_i,file_ima,xima,'nearest');
2355    CData(:,:,2)=ones(size(yima'))*CLine;
2356else
2357    CData(:,:,2)=interp2(Ind_i,Ind_j,file_ima,XIma,YIma,'nearest');
2358end
2359set(handles.waitbar_frame,'CData',CData)
2360end
2361set(handles.waitbar_frame,'Units','normalized')
2362
2363%% enable field and veltype menus
2364testfield=isequal(get(handles.FieldMenu,'enable'),'on');
2365testfield_1=isequal(get(handles.FieldMenu_1,'enable'),'on');
2366testveltype=isequal(get(handles.VelTypeMenu,'enable'),'on');
2367testveltype_1=isequal(get(handles.VelTypeMenu_1,'enable'),'on');
2368testtransform=isequal(get(handles.transform_fct,'Enable'),'on');
2369testnc=0;
2370testnc_1=0;
2371testcivx=0;
2372testcivx_1=0;
2373%TODO: update
2374% if length(FileExtCell)==1 || length(FileExtCell)>2
2375%     for iview=1:length(FileExtCell)
2376%         if isequal(FileExtCell{iview},'.nc')
2377%             testnc=1;
2378%         end
2379%         if isequal(FileTypeCell{iview},'civx')
2380%             testcivx=1;
2381%         end
2382%     end
2383% elseif length(FileExtCell)==2
2384%     testnc=isequal(FileExtCell{1},'.nc');
2385%     testnc_1=isequal(FileExtCell{2},'.nc');
2386%     testcivx=isequal(FileTypeCell{1},'civx');
2387%     testcivx_1=isequal(FileTypeCell{2},'civx');
2388% end
2389if testfield && testnc
2390    view_FieldMenu(handles,'on')
2391    if testcivx
2392        menustr=get(handles.FieldMenu,'String');
2393        if isequal(menustr,{'get_field...'})
2394            set(handles.FieldMenu,'String',{'get_field...';'velocity';'vort';'div';'more...'})
2395        end
2396    else
2397        set(handles.FieldMenu,'Value',1)
2398        set(handles.FieldMenu,'String',{'get_field...'})
2399    end
2400else
2401    view_FieldMenu(handles,'off')
2402end
2403if testfield_1 && testnc_1
2404    view_FieldMenu_1(handles,'on')
2405    if testcivx_1
2406        menustr=get(handles.FieldMenu_1,'String');
2407        if isequal(menustr,{'get_field...'})
2408            set(handles.FieldMenu_1,'String',{'get_field...';'velocity';'vort';'div';'more...'})
2409        end
2410    else
2411        set(handles.FieldMenu_1,'Value',1)
2412        set(handles.FieldMenu_1,'String',{'get_field...'})
2413    end
2414else
2415    view_FieldMenu_1(handles,'off')
2416end
2417if testveltype && testcivx
2418    set(handles.VelTypeMenu,'Visible','on')
2419    set(handles.VelType_text,'Visible','on');
2420else
2421    set(handles.VelTypeMenu,'Visible','off')
2422    set(handles.VelType_text,'Visible','off');
2423end
2424if testveltype_1 && testcivx_1
2425    set(handles.VelTypeMenu_1,'Visible','on')
2426    set(handles.VelType_text_1,'Visible','on');
2427else
2428    set(handles.VelTypeMenu_1,'Visible','off')
2429    set(handles.VelType_text_1,'Visible','off');
2430end
2431if testtransform && (testcivx || testima)
2432    set(handles.FieldTransform,'Visible','on')
2433%      view_TRANSFORM(handles,'on')
2434else
2435    set(handles.FieldTransform,'Visible','off')
2436%     view_TRANSFORM(handles,'off')
2437end
2438%TODO:update
2439% if ~isequal(FileExt,'.nc') && ~isequal(FileExt,'.cdf') && ~testima
2440%     msgbox_uvmat('ERROR',['invalid input file extension ' FileExt])
2441%     return
2442% end 
2443
2444%%  read image documentation file  if found%%%%%%%%%%%%%%%%%%%%%%%%%%%
2445ext_imadoc='';
2446FileBase=fullfile(RootPath,RootFile);
2447if isequal(FileExt,'.xml')||isequal(FileExt,'.civ')
2448    ext_imadoc=FileExt;
2449elseif exist([FileBase '.xml'],'file')
2450    ext_imadoc='.xml';
2451elseif exist([FileBase '.civ'],'file')
2452    ext_imadoc='.civ';
2453end
2454%read the ImaDoc file
2455XmlData=[];
2456NbSlice_calib={};
2457if isequal(ext_imadoc,'.xml')
2458        [XmlData,warntext]=imadoc2struct([FileBase '.xml']);
2459        if isfield(XmlData,'Heading') && isfield(XmlData.Heading,'ImageName') && ischar(XmlData.Heading.ImageName)
2460            [PP,FF,ext_ima_read]=fileparts(XmlData.Heading.ImageName);
2461        end
2462        if isfield(XmlData,'Time')
2463            time=XmlData.Time;
2464        end
2465        if isfield(XmlData,'Camera')
2466            if isfield(XmlData.Camera,'NbSlice')&& ~isempty(XmlData.Camera.NbSlice)
2467                NbSlice_calib{iview}=XmlData.Camera.NbSlice;% Nbre of slices for Zindex in phys transform
2468                if ~isequal(NbSlice_calib{iview},NbSlice_calib{1})
2469                    msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
2470                end
2471            end
2472            if isfield(XmlData.Camera,'TimeUnit')&& ~isempty(XmlData.Camera.TimeUnit)
2473                TimeUnit=XmlData.Camera.TimeUnit;
2474            end
2475        end
2476        if ~isempty(warntext)
2477            msgbox_uvmat('WARNING',warntext)
2478        end 
2479elseif isequal(ext_imadoc,'.civ')
2480    [error,XmlData.Time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([FileBase '.civ']);
2481    time=XmlData.Time;
2482    if error==2, warntext=['no file ' FileBase '.civ'];
2483    elseif error==1, warntext='inconsistent number of fields in the .civ file';
2484    end 
2485end 
2486
2487
2488%% number of slices
2489if isfield(XmlData,'GeometryCalib') && isfield(XmlData.GeometryCalib,'SliceCoord')
2490       siz=size(XmlData.GeometryCalib.SliceCoord);
2491       if siz(1)>1
2492           NbSlice=siz(1);
2493       else
2494           NbSlice=1;
2495       end
2496       set(handles.num_NbSlice,'String',num2str(NbSlice))
2497end
2498% set(handles.mode,'Visible','off') % do not show index pairs by default
2499set(handles.Pairs,'Visible','off')
2500% set(handles.ref_i,'Visible','off')
2501% set(handles.ref_i_text,'Visible','off')
2502testpair=0;
2503%set the menus of image pairs and default selection for series
2504%list pairs if relevant
2505% Val=get(handles.NomType,'Value');
2506% synchronise_view(handles,Val)
2507
2508% if ~isfield(SeriesData,'j1_series')||isempty(SeriesData.j1_series{index})
2509%     state_j='off'; %no need for j index
2510% else
2511%     state_j='on'; %case of j index
2512% end
2513% show index pairs if files exist
2514if isfield(SeriesData,'j1_series')&&(~isempty(SeriesData.i2_series{index})||~isempty(SeriesData.j2_series{index}))
2515    testpair=1;
2516    if ~isempty(SeriesData.i2_series{index}) %pairs with i index
2517        set(handles.mode,'Value',1)
2518        set(handles.mode,'String',{'series(Di)'})
2519    else  %pairs with j index
2520        set(handles.mode,'Value',1)
2521        set(handles.mode,'String',{'bursts';'series(Dj)'})
2522        if nbfield2>10 || nbfield==1
2523            set(handles.mode,'Value',2);
2524        else
2525            set(handles.mode,'Value',1);
2526        end
2527    end
2528    set(handles.mode,'Visible','on')
2529else
2530    set(handles.mode,'Visible','off')
2531end
2532% if ~isempty(NomTypeCell)
2533%     NomType=NomTypeCell{Val};
2534%     switch NomType 
2535%             case {'_1-2_1', '_1-2'}
2536%                 set(handles.mode,'String',{'series(Di)'})
2537%                 set(handles.mode,'Value',1);
2538%                 set(handles.mode,'Visible','on')
2539%                 testpair=1;
2540%             case {'#_ab'}
2541%                 set(handles.mode,'String',{'bursts'})
2542%                 set(handles.mode,'Value',1);
2543%                 testpair=1;
2544%             case '_1_1-2'
2545%                 set(handles.mode,'String',{'bursts';'series(Dj)'})%multiple choice
2546%                 if ~isempty(nbfield) && ~isempty(nbfield2) && ((nbfield2>10) || (nbfield==1))
2547%                     set(handles.mode,'Value',2);
2548%                 else
2549%                     set(handles.mode,'Value',1);% advice 'bursts' for small bursts
2550%                 end
2551%                 set(handles.mode,'Visible','on')
2552%                 testpair=1;
2553%     end
2554%     switch NomType   
2555%             case {'_1_1','_1_1-2','_1-2_1','1_ab','01_ab'},% two navigation indices
2556%                 state_j='on';
2557%     end
2558% end
2559set(handles.series,'UserData',SeriesData)
2560if testpair
2561    mode_Callback([],[], handles) 
2562else
2563%     set(handles.NomType,'String',NomTypeCell)
2564%     set(handles.j_txt,'Visible',state_j)
2565%     set(handles.num_MinIndex_j,'Visible',state_j)
2566%     set(handles.num_first_j,'Visible',state_j)
2567%     set(handles.num_incr_j,'Visible',state_j)
2568%     set(handles.num_last_j,'Visible',state_j)
2569%     set(handles.num_MaxIndex_j,'Visible',state_j)
2570end
2571
2572
2573% --- Executes on button press in BATCH.
2574function BATCH_Callback(hObject, eventdata, handles)
2575% hObject    handle to BATCH (see GCBO)
2576% eventdata  reserved - to be defined in a future version of MATLAB
2577% handles    structure with handles and user data (see GUIDATA)
2578Series=read_GUI(handles.series);
2579t=struct2xml(Series);
2580save(t); %TODO: determine a xml file name
2581
2582% list_action=get(handles.ACTION,'String');% list menu action
2583% index_action=get(handles.ACTION,'Value');% selected string index
2584% action= list_action{index_action}; % selected string
2585
2586%% defining the ACTION function handle
2587path_series=which('series');
2588list_path=get(handles.ACTION,'UserData');
2589index=get(handles.ACTION,'Value');
2590fct_path=list_path{index}; %path stored for the function ACTION
2591if ~isequal(fct_path,path_series)
2592    eval(['spath=which(''' action ''');']) %spath = current path of the selected function ACTION
2593    if ~exist(fct_path,'dir')
2594        msgbox_uvmat('ERROR',['The prescibed function path ' fct_path ' does not exist'])
2595        return
2596    end
2597    if ~isequal(spath,fct_path)
2598        addpath(fct_path)% add the prescribed path if not the current one
2599    end
2600end
2601eval(['h_fun=@' action ';'])%create a function handle for ACTION
2602if ~isequal(fct_path,path_series)
2603        rmpath(fct_path)% add the prescribed path if not the current one   
2604end
2605
2606h_fun('BATCH');% TODO modify the called function to read the xml file as input parameter
2607
2608
Note: See TracBrowser for help on using the repository browser.