source: trunk/src/series.m @ 472

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

many bugs repaired. series set to work in mode background

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