source: trunk/src/series.m @ 358

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

a few bug corrected in series (still work to do)

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