source: trunk/src/series.m @ 461

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

a few bug repairs

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