source: trunk/src/series.m @ 463

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

a few bug repairs and update in the series fcts

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