source: trunk/src/series.m @ 1096

Last change on this file since 1096 was 1096, checked in by sommeria, 3 years ago

bugs fixed

File size: 177.1 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
17%=======================================================================
18% Copyright 2008-2021, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
19%   http://www.legi.grenoble-inp.fr
20%   Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
21%
22%     This file is part of the toolbox UVMAT.
23%
24%     UVMAT is free software; you can redistribute it and/or modify
25%     it under the terms of the GNU General Public License as published
26%     by the Free Software Foundation; either version 2 of the license,
27%     or (at your option) any later version.
28%
29%     UVMAT is distributed in the hope that it will be useful,
30%     but WITHOUT ANY WARRANTY; without even the implied warranty of
31%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
32%     GNU General Public License (see LICENSE.txt) for more details.
33%=======================================================================
34
35%------------------------------------------------------------------------
36%------------------------------------------------------------------------
37%  I - MAIN FUNCTION series
38%------------------------------------------------------------------------
39%------------------------------------------------------------------------
40function varargout = series(varargin)
41
42% Begin initialization code - DO NOT EDIT
43gui_Singleton = 1;
44gui_State = struct('gui_Name',       mfilename, ...
45                   'gui_Singleton',  gui_Singleton, ...
46                   'gui_OpeningFcn', @series_OpeningFcn, ...
47                   'gui_OutputFcn',  @series_OutputFcn, ...
48                   'gui_LayoutFcn',  [] , ...
49                   'gui_Callback',   []);
50if nargin && ischar(varargin{1})
51    gui_State.gui_Callback = str2func(varargin{1});
52end
53
54if nargout
55    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
56else
57    gui_mainfcn(gui_State, varargin{:});
58end
59% End initialization code - DO NOT EDIT
60
61%--------------------------------------------------------------------------
62% --- Executes just before series is made visible.
63%--------------------------------------------------------------------------
64function series_OpeningFcn(hObject, eventdata, handles,Param)
65
66% Choose default command line output for series
67handles.output = hObject;
68% Update handles structure
69guidata(hObject, handles);
70
71%% initial settings
72% position and  size of the GUI at opening
73set(0,'Unit','points')
74ScreenSize=get(0,'ScreenSize'); % size of the current screen, in points (1/72 inch)
75Width=900; % prefered width of the GUI in points (1/72 inch)
76Height=624; % prefered height of the GUI in points (1/72 inch)
77%adjust to screen size (reduced by a min margin)
78RescaleFactor=min((ScreenSize(3)-80)/Width,(ScreenSize(4)-80)/Height);
79if RescaleFactor>1
80    RescaleFactor=min(RescaleFactor,1);
81end
82Width=Width*RescaleFactor;
83Height=Height*RescaleFactor;
84LeftX=80*RescaleFactor; % position of the left fig side, in pixels (put to the left side, with some margin)
85LowY=round(ScreenSize(4)/2-Height/2); % put at the middle height on the screen
86set(hObject,'Units','points')
87set(hObject,'Position',[LeftX LowY Width Height])% position and size of the GUI at opening
88
89% settings of table MinIndex_j
90set(handles.MinIndex_i,'ColumnFormat',{'numeric'})
91set(handles.MinIndex_i,'ColumnEditable',false)
92set(handles.MinIndex_i,'ColumnName',{'i min'})
93set(handles.MinIndex_i,'Data',[])% initiate Data to double (not cell)
94
95% settings of table MinIndex_j
96set(handles.MinIndex_j,'ColumnFormat',{'numeric'})
97set(handles.MinIndex_j,'ColumnEditable',false)
98set(handles.MinIndex_j,'ColumnName',{'j min'})
99set(handles.MinIndex_j,'Data',[])% initiate Data to double (not cell)
100
101% settings of table MaxIndex_i
102set(handles.MaxIndex_i,'ColumnFormat',{'numeric'})
103set(handles.MaxIndex_i,'ColumnEditable',false)
104set(handles.MaxIndex_i,'ColumnName',{'i max'})
105set(handles.MaxIndex_i,'Data',[])% initiate Data to double (not cell)
106
107% settings of table MaxIndex_j
108set(handles.MaxIndex_j,'ColumnFormat',{'numeric'})
109set(handles.MaxIndex_j,'ColumnEditable',false)
110set(handles.MaxIndex_j,'ColumnName',{'j max'})
111set(handles.MaxIndex_j,'Data',[])% initiate Data to double (not cell)
112
113% settings of table PairString
114set(handles.PairString,'ColumnName',{'pairs'})
115set(handles.PairString,'ColumnEditable',false)
116set(handles.PairString,'ColumnFormat',{'char'})
117set(handles.PairString,'Data',{''})
118
119% settings of table MaskTable
120set(handles.MaskTable,'ColumnName',{'mask name'})
121set(handles.PairString,'ColumnEditable',false)
122set(handles.PairString,'ColumnFormat',{'char'})
123set(handles.PairString,'Data',{''})
124
125series_ResizeFcn(hObject, eventdata, handles)%resize table according to series GUI size
126set(hObject,'WindowButtonDownFcn',{'mouse_down'})%allows mouse action with right button (zoom for uicontrol display)
127set(hObject,'DeleteFcn',{@closefcn})%
128
129% check default input data
130if ~exist('Param','var')
131    Param=[]; % default
132end
133
134%% Read the parameter file series.xml, or created from series.xml.default if it does not exist
135SeriesData=[];
136[path_series,name,ext]=fileparts(which('series'));% path to the GUI series
137xmlfile=fullfile(path_series,'series.xml');
138if ~exist(xmlfile,'file')
139    [success,message]=copyfile(fullfile(path_series,'series.xml.default'),xmlfile);
140end
141if exist(xmlfile,'file')
142    SeriesData.SeriesParam=xml2struct(xmlfile);
143    if ~(isfield(SeriesData.SeriesParam,'ClusterParam')&& isfield(SeriesData.SeriesParam.ClusterParam,'LaunchCmdFcn'))
144        [success,message]=copyfile(xmlfile,fullfile(path_series,'series_old.xml'));% update the file series.xml inot correctly documented
145        delete(xmlfile);
146        [success,message]=copyfile(fullfile(path_series,'series.xml.default'),xmlfile);
147    end 
148    SeriesData.SeriesParam=xml2struct(xmlfile);
149end
150
151%% list of builtin functions in the menu ActionName
152ActionList={'check_data_files';'aver_stat';'time_series';'civ_series';'merge_proj'}; % WARNING: fits with nb_builtin_ACTION=4 in ActionName_callback
153NbBuiltinAction=numel(ActionList);
154set(handles.Action,'UserData',NbBuiltinAction)
155path_series_fct=fullfile(path_series,'series');%path of the functions in subdirectroy 'series'
156[path_series,name,ext]=fileparts(which('series')); % path to the GUI series
157path_series_fct=fullfile(path_series,'series'); % path of the functions in subdirectroy 'series'
158command = ['LD_LIBRARY_PATH=$(echo $LD_LIBRARY_PATH | pyp "l = x.split('':''); l = [s for s in l if ''matlab'' not in s]; print('':''.join(l))") ' ...
159            'python -c "import fluidimage"'];
160[code, ~] = system(command);
161if code==0
162    ActionExtList={'.m';'.sh';'.py (in dev.)'}; % default choice of extensions (Matlab fct .m or compiled version .sh
163else
164    ActionExtList={'.m';'.sh'};  % python options not installed
165end
166ActionPathList=cell(NbBuiltinAction,1); % initiate the cell matrix of Action fct paths
167ActionPathList(:)={path_series_fct}; % set the default path to series fcts to all list members
168RunModeList={'local';'background'}; % default choice of extensions (Matlab fct .m or compiled version .sh)
169[s,w]=system(SeriesData.SeriesParam.ClusterParam.ExistenceTest); % look for cluster system presence
170% [s,w]=system('oarstat'); % look for cluster system 'oar'
171if isequal(s,0)
172    RunModeList=[RunModeList;{'cluster'}];
173    set(handles.MonitorCluster,'Visible','on'); % make visible button for access to Monika
174    set(handles.num_CPUTime,'Visible','on'); % make visible button for CPU time estimate for one ref index
175    set(handles.num_CPUTime,'String','1')% defqult CPU time estimate 1 minute
176    set(handles.CPUTime_txt,'Visible','on'); % make visible button for CPU time title
177end
178% [s,w]=system('qstat -help'); % look for cluster system 'sge'
179% if isequal(s,0)
180%     if regexp(w,'^pbs')
181%         RunModeList=[RunModeList;{'cluster_pbs'}];
182%     elseif regexp(w,'^SGE')
183%         RunModeList=[RunModeList;{'cluster_sge'}];
184%     else
185%         RunModeList=[RunModeList;{'cluster_qstat_unknown'}];
186%     end
187% end
188set(handles.RunMode,'String',RunModeList)% display the menu of available run modes, local, background or cluster manager
189
190%% list of builtin transform functions in the menu TransformName
191TransformList={'';'sub_field';'phys';'phys_polar'}; % WARNING: must fit with the corresponding menu in uvmat and nb_builtin_transform=4 in  TransformName_callback
192NbBuiltinTransform=numel(TransformList);
193path_transform_fct=fullfile(path_series,'transform_field');
194TransformPathList=cell(NbBuiltinTransform,1); % initiate the cell matrix of Action fct paths
195TransformPathList(:)={path_transform_fct}; % set the default path to series fcts to all list members
196SeriesData.TransformPath=path_transform_fct;% store the standard path for trqnsform functions (needed for compilation)
197
198%% get the user defined functions stored in the personal file uvmat_perso.mat
199dir_perso=prefdir;
200profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
201if exist(profil_perso,'file')
202    h=load (profil_perso);
203    %get the list of previous input files in the upper bar menu Open
204    if isfield(h,'MenuFile')
205        for ifile=1:min(length(h.MenuFile),5)
206            set(handles.(['MenuFile_' num2str(ifile)]),'Label',h.MenuFile{ifile});
207            set(handles.(['MenuFile_' num2str(ifile+5)]),'Label',h.MenuFile{ifile});
208        end
209    end
210    %get the list of previous campaigns in the upper bar menu Open campaign
211%     if isfield(h,'MenuCampaign')
212%         for ifile=1:min(length(h.MenuCampaign),5)
213%             set(handles.(['MenuCampaign_' num2str(ifile)]),'Label',h.MenuCampaign{ifile});
214%         end
215%     end
216    %get the menu of actions
217    if isfield(h,'ActionListUser') && iscell(h.ActionListUser) && isfield(h,'ActionPathListUser') && iscell(h.ActionPathListUser)
218        ActionList=[ActionList;h.ActionListUser];
219        ActionPathList=[ActionPathList;h.ActionPathListUser(:,1)];
220    end
221    %get the menu of transform fct
222    if isfield(h,'TransformListUser') && iscell(h.TransformListUser) && isfield(h,'TransformPathListUser') && iscell(h.TransformPathListUser)
223        TransformList=[TransformList;h.TransformListUser];
224        TransformPathList=[TransformPathList;h.TransformPathListUser];
225    end
226end
227
228%% selection of the input Action fct
229ActionCheckExist=true(size(ActionList)); % initiate the check of the path to the listed action fct
230for ilist=NbBuiltinAction+1:numel(ActionList)%check  the validity of the path of the user defined Action fct
231    ActionCheckExist(ilist)=exist(fullfile(ActionPathList{ilist},[ActionList{ilist} '.m']),'file');
232end
233ActionPathList=ActionPathList(ActionCheckExist,:); % suppress the menu options which are not valid anymore
234ActionList=ActionList(ActionCheckExist);
235set(handles.ActionName,'String',[ActionList;{'more...'}])
236set(handles.ActionName,'UserData',ActionPathList)
237ActionIndex=[];
238if isfield(Param,'ActionName')% copy the selected menu index transferred in Param from uvmat
239    ActionIndex=find(strcmp(Param.ActionName,ActionList),1);
240end
241if isempty(ActionIndex)
242    ActionIndex=1;
243end
244set(handles.ActionName,'Value',ActionIndex)
245set(handles.ActionPath,'String',ActionPathList{ActionIndex})
246set(handles.ActionExt,'Value',1)
247set(handles.ActionExt,'String',ActionExtList)
248
249%% selection of the input transform fct
250TransformCheckExist=true(size(TransformList));
251for ilist=NbBuiltinTransform+1:numel(TransformList)
252    TransformCheckExist(ilist)=exist(fullfile(TransformPathList{ilist},[TransformList{ilist} '.m']),'file');
253end
254TransformPathList=TransformPathList(TransformCheckExist);
255TransformList=TransformList(TransformCheckExist);
256set(handles.TransformName,'String',[TransformList;{'more...'}])
257set(handles.TransformName,'UserData',TransformPathList)
258TransformIndex=[];
259if isfield(Param,'TransformName')% copy the selected menu index transferred in Param from uvmat
260    TransformIndex=find(strcmp(Param.TransformName,TransformList),1);
261end
262if isempty(TransformIndex)
263    TransformIndex=1;
264end
265set(handles.TransformName,'Value',TransformIndex)
266set(handles.TransformPath,'String',TransformPathList{TransformIndex})
267   
268%% fields input initialisation
269if isfield(Param,'list_fields')&& isfield(Param,'index_fields') &&~isempty(Param.list_fields) &&~isempty(Param.index_fields)
270    set(handles.FieldName,'String',Param.list_fields); % list menu fields
271    set(handles.FieldName,'Value',Param.index_fields); % selected string index
272end
273if isfield(Param,'Coordinates')
274    if isfield(Param.Coordinates,'Coord_x')
275        set(handles.Coord_x,'String',Param.Coordinates.Coord_x)
276    end
277    if isfield(Param.Coordinates,'Coord_y')
278        set(handles.Coord_y,'String',Param.Coordinates.Coord_y)
279    end
280    if isfield(Param.Coordinates,'Coord_z')
281        set(handles.Coord_z,'String',Param.Coordinates.Coord_z)
282    end
283end
284
285%% introduce the input file name(s) if defined from input Param,
286set(handles.series,'UserData',SeriesData)% initiate Userdata
287if isfield(Param,'InputFile')
288   
289    %% fill the list of file series
290    InputTable=[{Param.InputFile.RootPath},{Param.InputFile.SubDir},{Param.InputFile.RootFile},{Param.InputFile.NomType},{Param.InputFile.FileExt}];
291    if isempty(find(cellfun('isempty',InputTable)==0)); % if there is no input file, do not introduce input info
292        set(handles.REFRESH,'BackgroundColor',[1 0 1])% set REFRESH button to magenta color to indicate that input refresh is needed
293        return
294    end
295    TimeTable=[{Param.InputFile.TimeName},{[]},{[]},{[]},{[]}];
296    if isfield(Param.InputFile,'RootPath_1')
297        InputTable=[InputTable;[{Param.InputFile.RootPath_1},{Param.InputFile.SubDir_1},{Param.InputFile.RootFile_1},{Param.InputFile.NomType_1},{Param.InputFile.FileExt_1}]];
298        TimeTable=[TimeTable; [{Param.InputFile.TimeName_1},{[]},{[]},{[]},{[]}]];
299    end
300    set(handles.InputTable,'Data',InputTable)
301    %% determine the selected reference field indices for pair display
302   
303    [tild,tild,tild,i1,i2,j1,j2]=fileparts_uvmat(Param.InputFile.FileIndex);
304    if isempty(i1)
305        i1=1;
306    end
307    if isempty(i2)
308        i2=i1;
309    end
310    ref_i=floor((i1+i2)/2); % reference image number corresponding to the file
311    % set(handles.num_ref_i,'String',num2str(ref_i));
312    if isempty(j1)
313        j1=1;
314    end
315    if isempty(j2)
316        j2=j1;
317    end
318    ref_j=floor((j1+j2)/2); % reference image number corresponding to the file
319    SeriesData.ref_i=ref_i;
320    SeriesData.ref_j=ref_j;
321    set(handles.series,'UserData',SeriesData)
322    update_rootinfo(handles,Param.HiddenData.i1_series{1},Param.HiddenData.i2_series{1},Param.HiddenData.j1_series{1},Param.HiddenData.j2_series{1},...
323        Param.HiddenData.FileInfo{1},Param.HiddenData.MovieObject{1},1)
324    if isfield(Param,'FileName_1')
325        %         display_file_name(handles,Param,2)
326        update_rootinfo(handles,Param.HiddenData.i1_series{2},Param.HiddenData.i2_series{2},Param.HiddenData.j1_series{2},Param.HiddenData.j2_series{2},...
327            Param.HiddenData.FileInfo{2},Param.HiddenData.MovieObject{2},2)
328    end
329    %% enable field and veltype menus, in accordance with the current action
330    ActionName_Callback([],[], handles)
331   
332    %% set length of waitbar
333    displ_time(handles)
334   
335else
336    set(handles.REFRESH,'BackgroundColor',[1 0 1])% set REFRESH button to magenta color to indicate that input refresh is needed
337end
338if isfield(Param,'incr_i')
339    set(handles.num_incr_i,'String',num2str(Param.incr_i))
340else
341    set(handles.num_incr_i,'String','1')
342end
343if isfield(Param,'incr_j')
344    set(handles.num_incr_j,'String',num2str(Param.incr_j))
345else
346    set(handles.num_incr_j,'String','1')
347end
348
349%------------------------------------------------------------------------
350% --- Outputs from this function are returned to the command line.
351function varargout = series_OutputFcn(hObject, eventdata, handles)
352%------------------------------------------------------------------------
353varargout{1} = handles.output;
354
355%------------------------------------------------------------------------
356% --- executed when closing uvmat: delete or desactivate the associated figures if exist
357function closefcn(gcbo,eventdata)
358%------------------------------------------------------------------------
359
360% delete set_object_series if detected
361hh=findobj(allchild(0),'name','view_object_series');
362if ~isempty(hh)
363    delete(hh)
364end
365hh=findobj(allchild(0),'name','edit_object_series');
366if ~isempty(hh)
367    delete(hh)
368end
369
370%delete the bowser if detected
371hh=findobj(allchild(0),'tag','browser');
372if ~isempty(hh)
373    delete(hh)
374end
375
376
377%------------------------------------------------------------------------
378%------------------------------------------------------------------------
379%  II - FUNCTIONS FOR INTRODUCING THE INPUT FILES
380% automatically sets the global properties when the rootfile name is introduced
381% then activate the view-field actionname if selected
382% it is activated either by clicking on the RootPath window or by the
383% browser
384%------------------------------------------------------------------------
385%------------------------------------------------------------------------
386% --- fct activated by the browser under 'Open'
387%------------------------------------------------------------------------ 
388function MenuBrowse_Callback(hObject, eventdata, handles)
389%% look for the previously opened file 'oldfile'
390InputTable=get(handles.InputTable,'Data');
391oldfile=InputTable{1,1};
392if isempty(oldfile)
393    % use a file name stored in prefdir
394    dir_perso=prefdir;
395    profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
396    if exist(profil_perso,'file')
397        h=load (profil_perso);
398        if isfield(h,'RootPath') && ischar(h.RootPath)
399            oldfile=h.RootPath;
400        end
401    end
402end
403%% launch the browser
404fileinput=uigetfile_uvmat('pick an input file in the series',oldfile);
405hh=dir(fileinput);
406if numel(hh)>1
407    msgbox_uvmat('ERROR','invalid input, probably a broken link');
408else
409    if ~isempty(fileinput)
410        display_file_name(handles,fileinput,'one')
411    end
412end
413
414% --------------------------------------------------------------------
415function MenuBrowseAppend_Callback(hObject, eventdata, handles)
416
417%% look for the previously opened file 'oldfile'
418InputTable=get(handles.InputTable,'Data');
419RootPathCell=InputTable(:,1);
420if isempty(RootPathCell{1})% no input file in the table
421     MenuBrowse_Callback(hObject, eventdata, handles)%refresh the input table, not append
422     return
423end
424SubDirCell=InputTable(:,2);
425oldfile=fullfile(RootPathCell{1},SubDirCell{1});
426
427%% use a file name stored in prefdir
428dir_perso=prefdir;
429profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
430if exist(profil_perso,'file')
431    h=load (profil_perso);
432    if isfield(h,'RootPath') && ischar(h.RootPath)
433        oldfile=h.RootPath;
434    end
435end
436
437%% launch the browser
438fileinput=uigetfile_uvmat('pick a file to append in the input table',oldfile);
439hh=dir(fileinput);
440if numel(hh)>1
441    msgbox_uvmat('ERROR','invalid input, probably a broken link');
442else
443    if ~isempty(fileinput)
444        display_file_name(handles,fileinput,'append')
445    end
446end
447
448%------------------------------------------------------------------------
449% --- fct activated by selecting a previous file under the menu Open
450%------------------------------------------------------------------------
451function MenuFile_Callback(hObject, eventdata, handles)
452
453errormsg=display_file_name(handles,get(hObject,'Label'),'one');
454if ~isempty(errormsg)
455    set(hObject,'Label','')
456    MenuFile=[{get(handles.MenuFile_1,'Label')};{get(handles.MenuFile_2,'Label')};...
457        {get(handles.MenuFile_3,'Label')};{get(handles.MenuFile_4,'Label')};{get(handles.MenuFile_5,'Label')}];
458    str_find=strcmp(get(hObject,'Label'),MenuFile);
459    MenuFile(str_find)=[]; % suppress the input file to the list
460    for ifile=1:numel(MenuFile)
461        set(handles.(['MenuFile_' num2str(ifile)]),'Label',MenuFile{ifile});
462    end
463end
464
465%------------------------------------------------------------------------
466% --- fct activated by selecting a previous file under the menu Open/append
467%------------------------------------------------------------------------
468function MenuFile_append_Callback(hObject, eventdata, handles)
469
470InputTable=get(handles.InputTable,'Data');
471if isempty(InputTable{1,1})% no input file in the table
472    display_file_name(handles,get(hObject,'Label'),'one') %refresh the input table, not append
473else
474    display_file_name(handles,get(hObject,'Label'),'append')% append the selected file to the current list of InputTable
475end
476
477%------------------------------------------------------------------------
478% --- fct activated by the browser under 'Open campaign/Browse...'
479%------------------------------------------------------------------------
480function MenuBrowseCampaign_Callback(hObject, eventdata, handles)
481
482%% look for the previously opened file 'oldfile'
483InputTable=get(handles.InputTable,'Data');
484if ~isempty(InputTable)
485oldfile=[InputTable{1,1} InputTable{1,2}];
486else
487    % use a file name stored in prefdir
488    dir_perso=prefdir;
489    profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
490    if exist(profil_perso,'file')
491        h=load (profil_perso);
492        if isfield(h,'MenuCampaign') && ~isempty(h.MenuCampaign)&& ischar(h.MenuCampaign{1})
493            oldfile=h.MenuCampaign{1};
494        end
495    end
496end
497InputTable{1,1}='...';
498set(handles.InputTable,'Data',InputTable)
499browse_data(oldfile,'on','on'); % open the GUI browse_data to get select a campaign dir, experiment and device
500% NbLines=numel(OutPut.Experiment)*numel(OutPut.DataSeries);
501% icount=0;
502% for iexp=1:numel(OutPut.Experiment)
503%     for idevice=1:numel(OutPut.DataSeries)
504%         icount=icount+1;
505%         InputTable{icount,1}=fullfile(OutPut.Campaign,OutPut.Experiment{iexp});
506%         InputTable{icount,2}=OutPut.DataSeries{idevice};
507%         if isempty(InputTable{icount,3})
508%             if icount>1
509%             InputTable{icount,3}=InputTable{icount-1,3};
510%             else
511%                 InputTable{icount,3}='';
512%             end
513%         end
514%         if isempty(InputTable{icount,4})
515%             if icount>1
516%             InputTable{icount,4}=InputTable{icount-1,4};
517%             else
518%                 InputTable{icount,4}='';
519%             end
520%         end
521%                 if isempty(InputTable{icount,5})
522%             if icount>1
523%             InputTable{icount,5}=InputTable{icount-1,5};
524%             else
525%                 InputTable{icount,5}='';
526%             end
527%         end
528%     end
529% end
530% if size(InputTable,1)>icount
531%     InputTable(icount+1:size(InputTable,1),:)=[];
532% end
533%REFRESH_Callback(hObject, eventdata, handles)
534
535% --------------------------------------------------------------------
536% function MenuCampaign_Callback(hObject, eventdata, handles)
537% % --------------------------------------------------------------------
538%
539% OutPut=browse_data(get(hObject,'Label'),'on','on'); % open the GUI browse_data to get select a campaign dir, experiment and device
540% if ~isfield(OutPut,'Campaign')
541%     return
542% end
543% NbLines=numel(OutPut.Experiment)*numel(OutPut.DataSeries);
544% icount=0;
545% InputTable=get(handles.InputTable,'Data');
546% for iexp=1:numel(OutPut.Experiment)
547%     for idevice=1:numel(OutPut.DataSeries)
548%         icount=icount+1;
549%         InputTable{icount,1}=fullfile(OutPut.Campaign,OutPut.Experiment{iexp});
550%         InputTable{icount,2}=OutPut.DataSeries{idevice};
551%         if isempty(InputTable{icount,3})
552%             if icount>1
553%                 InputTable{icount,3}=InputTable{icount-1,3};
554%             else
555%                 InputTable{icount,3}='';
556%             end
557%         end
558%         if isempty(InputTable{icount,4})
559%             if icount>1
560%                 InputTable{icount,4}=InputTable{icount-1,4};
561%             else
562%                 InputTable{icount,4}='';
563%             end
564%         end
565%         if isempty(InputTable{icount,5})
566%             if icount>1
567%                 InputTable{icount,5}=InputTable{icount-1,5};
568%             else
569%                 InputTable{icount,5}='';
570%             end
571%         end
572%     end
573% end
574% if size(InputTable,1)>icount
575%     InputTable(icount+1:size(InputTable,1),:)=[];
576% end
577% set(handles.InputTable,'Data',InputTable)
578% REFRESH_Callback(hObject, eventdata, handles)
579
580
581% --- Executes when selected cell(s) is changed in InputTable.
582function InputTable_CellSelectionCallback(hObject, eventdata, handles)
583iline=[];
584if ~isempty(eventdata.Indices)
585    iline=eventdata.Indices(1);
586end
587set(handles.InputLine,'String',num2str(iline));
588
589%------------------------------------------------------------------------
590% --- 'key_press_fcn:' function activated when a key is pressed on the keyboard
591%------------------------------------------------------------------------
592function InputTable_KeyPressFcn(hObject, eventdata, handles)
593set(handles.REFRESH,'BackgroundColor',[1 0 1])% set REFRESH button to magenta color to indicate that input refresh is needed
594set(handles.OutputSubDir,'BackgroundColor',[1 0 1])% set edit box OutputSubDir to magenta color to indicate that refresh may be needed
595xx=double(get(handles.series,'CurrentCharacter')); % get the keyboard character
596if ~isempty(xx)
597    switch xx
598        case 31 %downward arrow
599            InputTable=get(handles.InputTable,'Data');
600            iline=str2double(get(handles.InputLine,'String'));
601            if isequal(iline,size(InputTable,1))% arrow downward
602                InputTable=[InputTable;InputTable(iline,:)]; % create a new line as a copy of the last one
603                set(handles.InputTable,'Data',InputTable);
604            end
605        case 127  %key 'Suppress'
606            ClearLine_Callback(hObject, eventdata, handles)
607    end
608end
609
610%------------------------------------------------------------------------
611% --- Executes on button press in REFRESH.
612function REFRESH_Callback(hObject, eventdata, handles)
613%------------------------------------------------------------------------
614check_input_file_series(handles)
615
616%% enable field and veltype menus, in accordance with the current action
617ActionInput_Callback([],[], handles)
618
619
620function check_input_file_series(handles)
621InputTable=get(handles.InputTable,'Data');
622set(handles.series,'Pointer','watch') % set the mouse pointer to 'watch'
623set(handles.REFRESH,'BackgroundColor',[1 1 0])% set REFRESH  button to yellow color (indicate activation)
624drawnow
625empty_line=false(size(InputTable,1),1);
626for iline=1:size(InputTable,1)
627    empty_line(iline)= isempty(cell2mat(InputTable(iline,1:3)));
628end
629if ~isempty(find(empty_line,1))
630    InputTable(empty_line,:)=[]; % remove empty lines
631    set(handles.InputTable,'Data',InputTable)
632    ListTable={'MinIndex_i','MaxIndex_i','MinIndex_j','MaxIndex_j','PairString','TimeTable'};
633    for ilist=1:numel(ListTable)
634        Table=get(handles.(ListTable{ilist}),'Data');
635        Table(empty_line,:)=[]; % remove empty lines
636        set(handles.(ListTable{ilist}),'Data',Table);
637    end
638    set(handles.series,'UserData',[])%refresh the stored info
639end
640nbview=size(InputTable,1);
641for iview=1:nbview
642    RootPath=fullfile(InputTable{iview,1},InputTable{iview,2});
643    if ~exist(RootPath,'dir')
644        i1_series=[];
645        RootFile='';
646    else %scan the input folder
647        InputTable{iview,3}=regexprep(InputTable{iview,3},'^/','');
648            [RootPath,~,RootFile,i1_series,i2_series,j1_series,j2_series,tild,FileInfo,MovieObject]=...
649                find_file_series(fullfile(InputTable{iview,1},InputTable{iview,2}),[InputTable{iview,3} InputTable{iview,4} InputTable{iview,5}]);
650    end
651    % if no file is found, open a browser
652    if isempty(RootFile)&& isempty(i1_series)
653        fileinput=uigetfile_uvmat(['wrong input at line ' num2str(iview) ':pick a new input file'],RootPath);
654        if isempty(fileinput)
655            set(handles.REFRESH,'BackgroundColor',[1 0 0])% set REFRESH  back to red color
656            return
657        else
658            display_file_name(handles,fileinput,iview)
659        end
660    else
661       update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileInfo,MovieObject,iview)
662    end
663end
664
665%% update MinIndex_i and MaxIndex_i if the input table content has been reduced in line nbre
666MinIndex_i_table=get(handles.MinIndex_i,'Data'); % retrieve the min indices in the table MinIndex
667set(handles.MinIndex_i,'Data',MinIndex_i_table(1:nbview,:));
668MinIndex_j_table=get(handles.MinIndex_j,'Data'); % retrieve the min indices in the table MinIndex
669set(handles.MinIndex_j,'Data',MinIndex_j_table(1:nbview,:));
670MaxIndex_i_table=get(handles.MaxIndex_i,'Data'); % retrieve the min indices in the table MinIndex
671
672set(handles.MaxIndex_i,'Data',MaxIndex_i_table(1:nbview,:));
673MaxIndex_j_table=get(handles.MaxIndex_j,'Data'); % retrieve the min indices in the table MinIndex
674set(handles.MaxIndex_j,'Data',MaxIndex_j_table(1:nbview,:));
675PairString=get(handles.PairString,'Data'); % retrieve the min indices in the table MinIndex
676set(handles.PairString,'Data',PairString(1:nbview,:));
677TimeTable=get(handles.TimeTable,'Data'); % retrieve the min indices in the table MinIndex
678set(handles.TimeTable,'Data',TimeTable(1:nbview,:));
679
680%% set length of waitbar
681displ_time(handles)
682set(handles.REFRESH,'BackgroundColor',[1 0 0])% set REFRESH  button to red color (indicate activation finished)
683set(handles.series,'Pointer','arrow') % set the mouse pointer to 'watch'
684
685
686
687%------------------------------------------------------------------------
688% --- Function called when a new file is opened, either by series_OpeningFcn or by the browser
689%------------------------------------------------------------------------
690% INPUT:
691% handles: handles of elements in the GUI
692% Param: structure of input parameters, including  input file name and path
693% iview: line index in the input table
694%       or 'one': refresh the list
695%         'append': add a new line to the input table
696function errormsg=display_file_name(handles,Param,iview)
697 
698set(handles.REFRESH,'BackgroundColor',[1 1 0])% set REFRESH  button to yellow color (indicate activation)
699drawnow
700errormsg=''; % default
701if ischar(Param)
702    fileinput=Param;
703else% input set when series is opened (called by the GUI uvmat)
704    fileinput=Param.FileName;
705end
706   
707%% get the input root name, indices, file extension and nomenclature NomType
708if isempty(regexp(fileinput,'^http')) && ~exist(fileinput,'file')
709    errormsg=['input file ' fileinput  ' does not exist'];
710    msgbox_uvmat('ERROR',errormsg)
711    set(handles.REFRESH,'BackgroundColor',[1 0 1])% set REFRESH  button to magenta color (refresh still needed)
712    return
713end
714
715%% detect root name, nomenclature and indices in the input file name:
716[FilePath,FileName,FileExt]=fileparts(fileinput);
717%%%%%%%%%%%%%%%%%%
718%TODO: case of input by uvmat: do not check agai the input seies %%%%%%%
719%%%%%%%%%%%%%%%%%%%
720% detect the file type, get the movie object if relevant, and look for the corresponding file series:
721% the root name and indices may be corrected by including the first index i1 if a corresponding xml file exists
722[RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,NomType,FileInfo,MovieObject,i1,i2,j1,j2]=find_file_series(FilePath,[FileName FileExt]);
723FileType=FileInfo.FileType;
724if isempty(RootFile)&&isempty(i1_series)
725    errormsg='no input file in the series';
726    msgbox_uvmat('ERROR',errormsg)
727    set(handles.REFRESH,'BackgroundColor',[1 0 1])% set REFRESH  button to magenta color (end of activation)
728    return
729end
730if strcmp(FileType,'txt')
731    edit(fileinput)
732    set(handles.REFRESH,'BackgroundColor',[1 0 1])% set REFRESH  button to  magenta color (end of activation)
733    return
734elseif strcmp(FileType,'xml')
735    editxml(fileinput)
736    set(handles.REFRESH,'BackgroundColor',[1 0 1])% set REFRESH  button to magenta  color (end of activation)
737     return
738elseif strcmp(FileType,'figure')
739    open(fileinput)
740    set(handles.REFRESH,'BackgroundColor',[1 0 1])% set REFRESH  button to magenta  color (end of activation)
741     return
742end
743
744%% enable other menus and uicontrols
745set(handles.RUN, 'Enable','On')
746set(handles.RUN,'BackgroundColor',[1 0 0])% set RUN button to red
747set(handles.InputTable,'BackgroundColor',[1 1 0]) % set RootPath edit box  to yellow
748drawnow
749
750
751%% fill the list of file series
752InputTable=get(handles.InputTable,'Data');
753SeriesData=get(handles.series,'UserData');
754
755if strcmp(iview,'append') % display the input data as a new line in the table
756    iview=size(InputTable,1)+1; % the next line in InputTable becomes the current line
757elseif strcmp(iview,'one') % refresh the list of  input  file series
758    iview=1; % the first line in InputTable becomes the current line
759    InputTable={'','','','',''};
760    set(handles.TimeTable,'Data',[{''},{[]},{[]},{[]},{[]}])
761    set(handles.MinIndex_i,'Data',[])
762    set(handles.MaxIndex_i,'Data',[])
763    set(handles.MinIndex_j,'Data',[])
764    set(handles.MaxIndex_j,'Data',[])
765    set(handles.PairString,'Data',{''})
766    SeriesData.CheckPair=0; % reset the list of input lines with pairs
767    SeriesData.i1_series={};
768    SeriesData.i2_series={};
769    SeriesData.j1_series={};
770    SeriesData.j2_series={};
771    SeriesData.FileType={};
772    SeriesData.FileInfo={};
773    SeriesData.Time={};
774end
775if isfield(SeriesData,'i1_series')
776    SeriesData.i1_series(iview+1:end)=[];
777    SeriesData.i2_series(iview+1:end)=[];
778    SeriesData.j1_series(iview+1:end)=[];
779    SeriesData.j2_series(iview+1:end)=[];
780    SeriesData.FileType(iview+1:end)=[];
781    SeriesData.FileInfo(iview+1:end)=[];
782    SeriesData.Time(iview+1:end)=[];
783end
784InputTable(iview,:)=[{RootPath},{SubDir},{RootFile},{NomType},{FileExt}];
785if iview >1
786    set(handles.InputLine,'String',num2str(iview))
787end
788set(handles.InputTable,'Data',InputTable)
789
790%% determine the selected reference field indices for pair display
791if isempty(i1)
792    i1=1;
793end
794if isempty(i2)
795    i2=i1;
796end
797ref_i=floor((i1+i2)/2); % reference image number corresponding to the file
798% set(handles.num_ref_i,'String',num2str(ref_i));
799if isempty(j1)
800    j1=1;
801end
802if isempty(j2)
803    j2=j1;
804end
805ref_j=floor((j1+j2)/2); % reference image number corresponding to the file
806SeriesData.ref_i=ref_i;
807SeriesData.ref_j=ref_j;
808
809%% update first and last indices if they do not exist
810Param=read_GUI(handles.series);
811first_j=[];
812if isfield(Param.IndexRange,'first_j'); first_j=Param.IndexRange.first_j; end
813last_j=[];
814if isfield(Param.IndexRange,'last_j'); last_j=Param.IndexRange.last_j; end
815PairString='';
816if isfield(Param.IndexRange,'PairString'); PairString=Param.IndexRange.PairString; end
817[i1,i2,j1,j2] = get_file_index(Param.IndexRange.first_i,first_j,PairString);
818FirstFileName=fullfile_uvmat(Param.InputTable{1,1},Param.InputTable{1,2},Param.InputTable{1,3},...
819    Param.InputTable{1,5},Param.InputTable{1,4},i1,i2,j1,j2);
820if ~exist(FirstFileName,'file')
821    set(handles.num_first_i,'String',num2str(ref_i))
822    set(handles.num_first_j,'String',num2str(ref_j))
823end
824[i1,i2,j1,j2] = get_file_index(Param.IndexRange.last_i,last_j,PairString);
825LastFileName=fullfile_uvmat(Param.InputTable{1,1},Param.InputTable{1,2},Param.InputTable{1,3},...
826    Param.InputTable{1,5},Param.InputTable{1,4},i1,i2,j1,j2);
827if ~exist(LastFileName,'file')
828    set(handles.num_last_i,'String',num2str(ref_i))
829    set(handles.num_last_j,'String',num2str(ref_j))
830end
831
832%% update the list of recent files in the menubar and save it for future opening
833MenuFile=[{get(handles.MenuFile_1,'Label')};{get(handles.MenuFile_2,'Label')};...
834    {get(handles.MenuFile_3,'Label')};{get(handles.MenuFile_4,'Label')};{get(handles.MenuFile_5,'Label')}];
835str_find=strcmp(fileinput,MenuFile);
836if isempty(find(str_find,1))
837    MenuFile=[{fileinput};MenuFile]; % insert the current file if not already in the list
838end
839for ifile=1:min(length(MenuFile),5)
840    eval(['set(handles.MenuFile_' num2str(ifile) ',''Label'',MenuFile{ifile});'])
841end
842dir_perso=prefdir;
843profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
844if exist(profil_perso,'file')
845    save (profil_perso,'MenuFile','-append'); % store the file names for future opening of uvmat
846else
847    save (profil_perso,'MenuFile','-V6'); % store the file names for future opening of uvmat
848end
849% save the opened file to initiate future opening
850SeriesData.RefFile{iview}=fileinput; % reference opening file for line iview
851SeriesData.Ref_i1=i1;
852SeriesData.Ref_i2=i2;
853SeriesData.Ref_j1=j1;
854SeriesData.Ref_j2=j2;
855
856%% define the path for the output files
857[InputPath,Device,DeviceExt]=fileparts(InputTable{1,1});
858[InputPath,Experiment,ExperimentExt]=fileparts(InputPath);
859[~,InputPath,InputPathExt]=fileparts(InputPath);
860set(handles.Device,'String',[Device DeviceExt])
861set(handles.Experiment,'String',[Experiment ExperimentExt])
862if ~isempty(regexp(InputTable{1,1},'(^http://)|(^https://)'))
863    set(handles.OutputPathBrowse,'Value',1)% an output folder needs to be specified for OpenDAP data
864end
865
866%update the output path if needed
867if ~(isfield(SeriesData,'InputPath') && strcmp(SeriesData.InputPath,InputPath))
868    if get(handles.OutputPathBrowse,'Value')==1  % fix the output path in manual mode
869        OutputPathOld=get(handles.OutputPath,'String');
870        OutputPath=uigetdir(OutputPathOld,'pick a root folder for output data');
871        set(handles.OutputPath,'String',OutputPath)
872    else %reproduce the input path for output
873        set(handles.OutputPath,'String',InputPath)
874    end
875    SeriesData.InputPath=InputPath;
876end
877
878set(handles.series,'UserData',SeriesData)
879
880set(handles.InputTable,'BackgroundColor',[1 1 1])
881
882%% initiate input file series and refresh the current field view:     
883update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileInfo,MovieObject,iview);
884%% enable field and veltype menus, in accordance with the current action
885ActionName_Callback([],[], handles)
886
887%% set length of waitbar
888displ_time(handles)
889
890set(handles.REFRESH,'BackgroundColor',[1 0 0])% set REFRESH  button to red color (end of activation)
891
892%------------------------------------------------------------------------
893% --- Update information about a new field series (indices to scan, timing,
894%     calibration from an xml file
895function update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileInfo,VideoObject,iview)
896%------------------------------------------------------------------------
897InputTable=get(handles.InputTable,'Data');
898
899%% display the min and max indices for the whole file series
900if size(i1_series,2)==2 && min(min(i1_series(:,1,:)))==0
901    MinIndex_j=1; % index j set to 1 by default
902    MaxIndex_j=1;
903    MinIndex_i=find(i1_series(1,2,:), 1 )-1; % min ref index i detected in the series (corresponding to the first non-zero value of i1_series, except for zero index)
904    MaxIndex_i=find(i1_series(1,2,:),1,'last' )-1; % max ref index i detected in the series (corresponding to the last non-zero value of i1_series)
905else
906    ref_i=squeeze(max(i1_series(1,:,:),[],2)); % select ref_j index for each ref_i
907    ref_j=squeeze(max(j1_series(1,:,:),[],3)); % select ref_i index for each ref_j
908     MinIndex_i=min(find(ref_i))-1;
909     MaxIndex_i=max(find(ref_i))-1;
910     MaxIndex_j=max(find(ref_j))-1;
911     MinIndex_j=min(find(ref_j))-1;
912    diff_j_max=diff(ref_j);
913    diff_i_max=diff(ref_i);
914    if ~isempty(diff_i_max) && isequal (diff_i_max,diff_i_max(1)*ones(size(diff_i_max)))
915        set(handles.num_incr_i,'String',num2str(diff_i_max(1)))% detect an increment to dispaly by default
916    end
917    if ~isempty(diff_j_max) && isequal (diff_j_max,diff_j_max(1)*ones(size(diff_j_max)))
918        set(handles.num_incr_j,'String',num2str(diff_j_max(1)))
919    end
920end
921if isequal(MinIndex_i,-1)
922    MinIndex_i=0;
923end
924if isequal(MinIndex_j,-1)
925    MinIndex_j=0;
926end
927MinIndex_i_table=get(handles.MinIndex_i,'Data'); % retrieve the min indices in the table MinIndex
928MinIndex_j_table=get(handles.MinIndex_j,'Data'); % retrieve the min indices in the table MinIndex
929MaxIndex_i_table=get(handles.MaxIndex_i,'Data'); % retrieve the min indices in the table MinIndex
930MaxIndex_j_table=get(handles.MaxIndex_j,'Data'); % retrieve the min indices in the table MinIndex
931if ~isempty(MinIndex_i)&&~isempty(MaxIndex_i)
932    MinIndex_i_table(iview,1)=MinIndex_i;
933    MaxIndex_i_table(iview,1)=MaxIndex_i;
934end
935if ~isempty(MinIndex_j)&&~isempty(MaxIndex_j)
936    MinIndex_j_table(iview,1)=MinIndex_j;
937    MaxIndex_j_table(iview,1)=MaxIndex_j;
938end
939set(handles.MinIndex_i,'Data',MinIndex_i_table)%display the min indices in the table MinIndex
940set(handles.MinIndex_j,'Data',MinIndex_j_table)%display the max indices in the table MaxIndex
941set(handles.MaxIndex_i,'Data',MaxIndex_i_table)%display the min indices in the table MinIndex
942set(handles.MaxIndex_j,'Data',MaxIndex_j_table)%display the max indices in the table MaxIndex
943SeriesData=get(handles.series,'UserData');
944
945%% adjust the first and last indices for the selected series, only if requested by the bounds
946% i index, compare input to min index i
947first_i=str2num(get(handles.num_first_i,'String')); % retrieve previous first i
948% ref_i=str2num(get(handles.num_ref_i,'String')); % index i given by the input field
949ref_i=1;
950if isfield(SeriesData,'ref_i')
951    ref_i=SeriesData.ref_i;
952end
953if isempty(first_i)
954    first_i=ref_i; % first_i updated by the input value
955elseif first_i < MinIndex_i
956    first_i=MinIndex_i; % first_i set to the min i index (restricted by oter input lines)
957elseif first_i >MaxIndex_i
958    first_i=MaxIndex_i; % first_i set to the max i index (restricted by oter input lines)
959end
960% j index,  compare input to min index j
961first_j=str2num(get(handles.num_first_j,'String'));
962ref_j=1;
963if isfield(SeriesData,'ref_j')
964    ref_j=SeriesData.ref_j;
965end
966if isempty(first_j)
967    first_j=ref_j; % first_j updated by the input value
968elseif first_j<MinIndex_j
969    first_j=MinIndex_j; % first_j set to the min j index (restricted by oter input lines)
970elseif first_j >MaxIndex_j
971    first_j=MaxIndex_j; % first_j set to the max j index (restricted by oter input lines)
972end
973% i index, compare input to max index i
974last_i=str2num(get(handles.num_last_i,'String'));
975if isempty(last_i)
976    last_i=ref_i;
977elseif last_i > MaxIndex_i
978    last_i=MaxIndex_i;
979elseif last_i<first_i
980    last_i=first_i;
981end
982% j index, compare input to max index j
983last_j=str2num(get(handles.num_last_j,'String'));
984if isempty(last_j)
985    last_j=ref_j;
986elseif last_j>MaxIndex_j
987    last_j=MaxIndex_j;
988elseif last_j<first_j
989    last_j=first_j;
990end
991set(handles.num_first_i,'String',num2str(first_i));
992set(handles.num_first_j,'String',num2str(first_j));
993set(handles.num_last_i,'String',num2str(last_i));
994set(handles.num_last_j,'String',num2str(last_j));
995
996%% number of slices set by default
997NbSlice=[]; % default
998% read  value set by the first series for the append mode (iwiew >1)
999if iview>1 && strcmp(get(handles.num_NbSlice,'Visible'),'on')
1000    NbSlice=str2double(get(handles.num_NbSlice,'String'));
1001end
1002
1003%% default time settings
1004TimeUnit='';
1005% read  value set by the first series for the append mode (iwiew >1)
1006if iview>1
1007    TimeUnit=get(handles.TimeUnit,'String');
1008end
1009TimeName='';
1010Time=[]; % default
1011TimeMin=[];
1012TimeFirst=[];
1013TimeLast=[];
1014TimeMax=[];
1015
1016%%  read image documentation file if found
1017XmlData=[];
1018check_calib=0;
1019XmlFileName=find_imadoc(InputTable{iview,1},InputTable{iview,2},InputTable{iview,3},InputTable{iview,5});
1020if ~isempty(XmlFileName)
1021    [XmlData,errormsg]=imadoc2struct(XmlFileName);
1022    if ~isempty(errormsg)
1023        msgbox_uvmat('WARNING',['error in reading ' XmlFileName ': ' errormsg]);
1024    end
1025    % read time if available
1026    if isfield(XmlData,'Time')
1027        Time=XmlData.Time;
1028        TimeName='xml';
1029    end
1030    if isfield(XmlData,'Camera')
1031        if isfield(XmlData.Camera,'TimeUnit')&& ~isempty(XmlData.Camera.TimeUnit)
1032            if iview>1 && ~isempty(TimeUnit) && ~strcmp(TimeUnit,XmlData.Camera.TimeUnit)
1033                msgbox_uvmat('WARNING','inconsistent time unit with the first field series');
1034            end
1035            TimeUnit=XmlData.Camera.TimeUnit;
1036        end
1037    end
1038    % number of slices
1039    if isfield(XmlData,'TranslationMotor')&& isfield(XmlData.TranslationMotor,'NbSlice')
1040        NbSlice_motor=XmlData.TranslationMotor.NbSlice;
1041        if ~isempty(NbSlice) && ~isequal(NbSlice_motor,NbSlice)
1042                msgbox_uvmat('WARNING','inconsistent Z numbers of Z indices');
1043        else
1044            NbSlice=NbSlice_motor;
1045        end
1046    end
1047end
1048if ~isempty(NbSlice)
1049set(handles.num_NbSlice,'String',num2str(NbSlice))
1050set(handles.num_NbSlice,'Visible','on')
1051end
1052
1053%% read timing  from the current file (prioritary)
1054if ~isempty(VideoObject)% case of movies
1055    imainfo=get(VideoObject);
1056    if isempty(j1_series) % frame index along i
1057        Time=zeros(imainfo.NumberOfFrames+1,2);
1058        Time(:,2)=(0:1/imainfo.FrameRate:(imainfo.NumberOfFrames)/imainfo.FrameRate)';
1059    else
1060        Time=[0;ones(size(i1_series,3)-1,1)]*(0:1/imainfo.FrameRate:(imainfo.NumberOfFrames)/imainfo.FrameRate);
1061    end
1062    TimeName='video';
1063end
1064
1065
1066%% determine the min and max times: case of Netcdf files will be treated later in FieldName_Callback
1067if ~isempty(TimeName)
1068    TimeMin=Time(MinIndex_i+1,MinIndex_j+1);
1069    if size(Time)>=[first_i+1 first_j+1]
1070        TimeFirst=Time(first_i+1,first_j+1);
1071    end
1072    if size(Time)>=[last_i+1 last_j+1]
1073        TimeLast=Time(last_i+1,last_j+1);
1074    end
1075    if size(Time)>=[MaxIndex_i+1 MaxIndex_j+1]
1076        TimeMax=Time(MaxIndex_i+1,MaxIndex_j+1);
1077    end
1078end
1079
1080%% update the time table
1081TimeTable=get(handles.TimeTable,'Data');
1082TimeTable{iview,1}=TimeName;
1083TimeTable{iview,2}=TimeMin;
1084TimeTable{iview,3}=TimeFirst;
1085TimeTable{iview,4}=TimeLast;
1086TimeTable{iview,5}=TimeMax;
1087set(handles.TimeTable,'Data',TimeTable)
1088
1089%% update the series info in 'UserData'
1090SeriesData.i1_series{iview}=i1_series;
1091SeriesData.i2_series{iview}=i2_series;
1092SeriesData.j1_series{iview}=j1_series;
1093SeriesData.j2_series{iview}=j2_series;
1094SeriesData.FileType{iview}=FileInfo.FileType;
1095SeriesData.FileInfo{iview}=FileInfo;
1096SeriesData.Time{iview}=Time;
1097
1098SeriesData.TimeName=TimeName;
1099
1100if check_calib
1101    SeriesData.GeometryCalib{iview}=XmlData.GeometryCalib;
1102end
1103set(handles.series,'UserData',SeriesData)
1104
1105%% update pair menus
1106hset_pair=findobj(allchild(0),'Tag','set_pairs');
1107if ~isempty(hset_pair), delete(hset_pair); end % delete the GUI set_pair if opened
1108CheckPair= ~isempty(i2_series)||~isempty(j2_series); % check whether index pairs need to be defined
1109PairString=get(handles.PairString,'Data');
1110if CheckPair% if pairs need to be display for line iview
1111    [ModeMenu,ModeValue]=update_mode(i1_series,i2_series,j2_series);
1112    Menu=update_listpair(i1_series,i2_series,j1_series,j2_series,ModeMenu{ModeValue},Time,TimeUnit,ref_i,ref_j,TimeName,InputTable(iview,:),FileInfo);
1113    PairString{iview,1}=Menu{1};
1114else
1115    PairString{iview,1}=''; % no pair for #iview
1116end
1117set(handles.PairString,'Data',PairString)
1118if isempty(find(cellfun('isempty',get(handles.PairString,'Data'))==0, 1))% if all lines of pairs are empty
1119    set(handles.PairString,'Visible','off')
1120    set(handles.SetPairs,'Visible','off')
1121else
1122    set(handles.PairString,'Visible','on')
1123    set(handles.SetPairs,'Visible','on')
1124end
1125
1126
1127%% display the set of existing files as an image
1128set(handles.FileStatus,'Units','pixels')
1129Position=get(handles.FileStatus,'Position');
1130set(handles.FileStatus,'Units','normalized')
1131%xI=0.5:Position(3)-0.5;
1132nbview=numel(SeriesData.i1_series);
1133j_max=cell(1,nbview);
1134MaxIndex_i=ones(1,nbview); % default
1135MinIndex_i=ones(1,nbview); % default
1136for iline=1:nbview
1137    pair_max=squeeze(max(SeriesData.i1_series{iline},[],1)); % max on pair index
1138    j_max{iline}=max(pair_max,[],1); % max on j index
1139    if ~isempty(j_max{iline})
1140    MaxIndex_i(iline)=find(j_max{iline}, 1, 'last' )-1; % max ref index i
1141    MinIndex_i(iline)=find(j_max{iline}, 1 )-1; % min ref index i
1142    end
1143end
1144MinIndex_i=min(MinIndex_i);
1145MaxIndex_i=max(MaxIndex_i);
1146range_index=MaxIndex_i-MinIndex_i+1;
1147range_y=max(1,floor(Position(4)/nbview));
1148npx=floor(Position(3));
1149file_indices=MinIndex_i+floor(((0.5:npx-0.5)/npx)*range_index)+1;
1150CData=zeros(nbview*range_y,npx); % initiate the image representing the existing files
1151for iline=1:nbview
1152    ind_y=1+(iline-1)*range_y:iline*range_y;
1153    LineData=zeros(size(file_indices));
1154    file_select=file_indices(file_indices<=numel(j_max{iline}));
1155    ind_select=file_indices<=numel(j_max{iline});
1156    LineData(ind_select)=j_max{iline}(file_select)~=0;
1157    CData(ind_y,:)=ones(size(ind_y'))*LineData;
1158end
1159CData=cat(3,zeros(size(CData)),CData,zeros(size(CData))); % make color images r=0,g,b=0
1160set(handles.FileStatus,'CData',CData);
1161
1162%-----------------------------------------------------------guide -------------
1163%------------------------------------------------------------------------
1164%  III - FUNCTIONS ASSOCIATED TO THE FRAME IndexRange
1165%------------------------------------------------------------------------
1166
1167
1168% ---- determine the menu to put in mode and advice a default choice
1169%------------------------------------------------------------------------
1170function [ModeMenu,ModeValue]=update_mode(i1_series,i2_series,j2_series)
1171%------------------------------------------------------------------------   
1172ModeMenu={''};
1173if isempty(j2_series)% no j pair
1174    ModeValue=1;
1175    if ~isempty(i2_series)
1176        ModeMenu={'series(Di)'}; % pair menu with only option Di
1177    end
1178else %existence of j pairs
1179    pair_max=squeeze(max(i1_series,[],1)); % max on pair index
1180    j_max=max(pair_max,[],1);
1181    MaxIndex_i=find(j_max, 1, 'last' )-1; % max ref index i
1182    MinIndex_i=find(j_max, 1 )-1; % min ref index i
1183    i_max=max(pair_max,[],2);
1184    MaxIndex_j=find(i_max, 1, 'last' )-1; % max ref index i
1185    MinIndex_j=find(i_max, 1 )-1; % min ref index i
1186    if MaxIndex_j==MinIndex_j
1187        ModeValue=1;
1188        ModeMenu={'bursts'};
1189    elseif MaxIndex_i==MinIndex_i
1190        ModeValue=1;
1191        ModeMenu={'series(Dj)'};
1192    else
1193        ModeMenu={'bursts';'series(Dj)'};
1194        if (MaxIndex_j-MinIndex_j)>10
1195            ModeValue=2; % set mode to series(Dj) if more than 10 j values
1196        else
1197            ModeValue=1;
1198        end
1199    end
1200end
1201
1202
1203%------------------------------------------------------------------------
1204%fill the menu of possible pairs as input
1205function displ_pair=update_listpair(i1_series,i2_series,j1_series,j2_series,mode,time,TimeUnit,ref_i,ref_j,TimeName,InputTable,FileInfo)
1206%------------------------------------------------------------------------
1207displ_pair={};
1208if isempty(TimeUnit)
1209    dtunit='e-03';
1210else
1211    dtunit=['m' TimeUnit];
1212end
1213switch mode
1214    case 'series(Di)'
1215        diff_i=i2_series-i1_series;
1216        min_diff=min(diff_i(diff_i>0));
1217        max_diff=max(diff_i(diff_i>0));
1218        for ipair=min_diff:max_diff
1219            if ~isempty(find(diff_i==ipair,1))% if the considered difference exists as input
1220                pair_string=['Di= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ];
1221                if size(time,1)>=ref_i+ceil(ipair/2)
1222                    if ref_i<=floor(ipair/2)
1223                        ref_i=floor(ipair/2)+1; % shift ref_i to get the first pair
1224                    end
1225                    Dt=time(ref_i+ceil(ipair/2),ref_j)-time(ref_i-floor(ipair/2),ref_j);
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;{'Di=*|*'}];
1233        end
1234    case 'series(Dj)'
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_diff=min(diff_j(diff_j>0));
1241        max_diff=max(diff_j(diff_j>0));
1242        for ipair=min_diff:max_diff
1243            if numel(diff_j(diff_j==ipair))>0
1244                pair_string=['Dj= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ];
1245                if ~isempty(time)
1246                    if ref_j<=floor(ipair/2)
1247                        ref_j=floor(ipair/2)+1; % shift ref_i to get the first pair
1248                    end
1249                    Dt=time(ref_i,ref_j+ceil(ipair/2))-time(ref_i,ref_j-floor(ipair/2));
1250                    pair_string=[pair_string ', Dt=' num2str(Dt) ' ' dtunit];
1251                end
1252                displ_pair=[displ_pair;{pair_string}];
1253            end
1254        end
1255        if ~isempty(displ_pair)
1256            displ_pair=[displ_pair;{'Dj=*|*'}];
1257        end
1258    case 'bursts'
1259        if isempty(j2_series)
1260            msgbox_uvmat('ERROR','no j1-j2 pair available')
1261            return
1262        end
1263        %diff_j=j2_series-j1_series;
1264        min_j1=min(j1_series(j1_series>0));
1265        max_j1=max(j1_series(j1_series>0));
1266        min_j2=min(j2_series(j2_series>0));
1267        max_j2=max(j2_series(j2_series>0));
1268        for pair1=min_j1:min(max_j1,min_j1+20)
1269            for pair2=min_j2:min(max_j2,min_j2+20)
1270                if numel(j1_series(j1_series==pair1))>0 && numel(j2_series(j2_series==pair2))>0
1271                    pair_string=['j= ' num2str(pair1) '-' num2str(pair2)];
1272                    [TimeValue,DtValue]=get_time(ref_i,[],pair_string,InputTable,FileInfo,TimeName,'Dt');
1273                    %Dt=time(ref_i,pair2+1)-time(ref_i,pair1+1);
1274                    pair_string=[pair_string ', Dt=' num2str(DtValue) ' ' dtunit];
1275                    displ_pair=[displ_pair;{pair_string}];
1276                end
1277            end
1278        end
1279        if ~isempty(displ_pair)
1280            displ_pair=[displ_pair;{'j=*-*'}];
1281        end
1282end
1283
1284%------------------------------------------------------------------------
1285function num_first_i_Callback(hObject, eventdata, handles)
1286%------------------------------------------------------------------------
1287num_last_i_Callback(hObject, eventdata, handles)
1288
1289%------------------------------------------------------------------------
1290function num_last_i_Callback(hObject, eventdata, handles)
1291%------------------------------------------------------------------------
1292SeriesData=get(handles.series,'UserData');
1293if ~isfield(SeriesData,'Time')
1294    SeriesData.Time{1}=[];
1295end
1296displ_time(handles);
1297
1298%------------------------------------------------------------------------
1299function num_first_j_Callback(hObject, eventdata, handles)
1300%------------------------------------------------------------------------
1301 num_last_j_Callback(hObject, eventdata, handles)
1302
1303%------------------------------------------------------------------------
1304function num_last_j_Callback(hObject, eventdata, handles)
1305%------------------------------------------------------------------------
1306% first_j=str2num(get(handles.num_first_j,'String'));
1307% last_j=str2num(get(handles.num_last_j,'String'));
1308% ref_j=ceil((first_j+last_j)/2);
1309% set(handles.num_ref_j,'String', num2str(ref_j))
1310% num_ref_j_Callback(hObject, eventdata, handles)
1311SeriesData=get(handles.series,'UserData');
1312if ~isfield(SeriesData,'Time')
1313    SeriesData.Time{1}=[];
1314end
1315displ_time(handles);
1316
1317%------------------------------------------------------------------------
1318% ---- find the times corresponding to the first and last indices of a series
1319function displ_time(handles)
1320%------------------------------------------------------------------------
1321SeriesData=get(handles.series,'UserData'); %
1322if ~isfield(SeriesData,'Time')
1323    return
1324end
1325PairString=get(handles.PairString,'Data');
1326ref_i_1=str2num(get(handles.num_first_i,'String')); % first reference index
1327ref_i_2=str2num(get(handles.num_last_i,'String')); % last reference index
1328ref_j_1=[];ref_j_2=[];
1329if strcmp(get(handles.num_first_j,'Visible'),'on')
1330ref_j_1=str2num(get(handles.num_first_j,'String'));
1331ref_j_2=str2num(get(handles.num_last_j,'String'));
1332end
1333[i1_1,i2_1,j1_1,j2_1] = get_file_index(ref_i_1,ref_j_1,PairString);
1334[i1_2,i2_2,j1_2,j2_2] = get_file_index(ref_i_2,ref_j_2,PairString);
1335TimeTable=get(handles.TimeTable,'Data');
1336%%%%%%
1337%TODO: read time in netcdf file, see ActionName_Callback
1338%%%%%%%
1339%Pairs=get(handles.PairString,'Data');
1340for iview=1:size(TimeTable,1)
1341    if size(SeriesData.Time,1)<iview
1342        break
1343    end
1344    TimeTable{iview,3}=[];
1345    TimeTable{iview,4}=[];
1346    if size(SeriesData.Time{iview},1)>=i2_2+1 && (isempty(ref_j_1)||size(SeriesData.Time{iview},2)>=j2_2+1)
1347        if isempty(ref_j_1)
1348            time_first=(SeriesData.Time{iview}(i1_1+1,2)+SeriesData.Time{iview}(i2_1+1,2))/2;
1349            time_last=(SeriesData.Time{iview}(i1_2+1,2)+SeriesData.Time{iview}(i2_2+1,2))/2;
1350        else
1351            time_first=(SeriesData.Time{iview}(i1_1+1,j1_1+1)+SeriesData.Time{iview}(i2_1+1,j2_1+1))/2;
1352            time_last=(SeriesData.Time{iview}(i1_2+1,j1_2+1)+SeriesData.Time{iview}(i2_2+1,j2_1+1))/2;
1353        end
1354        TimeTable{iview,3}=time_first; % TODO: take into account pairs
1355        TimeTable{iview,4}=time_last; % TODO: take into account pairs
1356    end
1357end
1358set(handles.TimeTable,'Data',TimeTable)
1359
1360%% set the waitbar position with respect to the min and max in the series
1361MinIndex_i=min(get(handles.MinIndex_i,'Data'));
1362MaxIndex_i=max(get(handles.MaxIndex_i,'Data'));
1363pos_first=(ref_i_1-MinIndex_i)/(MaxIndex_i-MinIndex_i+1);
1364pos_last=(ref_i_2-MinIndex_i+1)/(MaxIndex_i-MinIndex_i+1);
1365if isempty(pos_first), pos_first=0; end
1366if isempty(pos_last), pos_last=1; end
1367Position=get(handles.Waitbar,'Position'); % position of the waitbar:= [ x,y, width, height]
1368Position_status=get(handles.FileStatus,'Position');
1369Position(1)=Position_status(1)+Position_status(3)*pos_first;
1370Position(3)=max(Position_status(3)*(pos_last-pos_first),0.001); % width must remain positive
1371set(handles.Waitbar,'Position',Position)
1372update_waitbar(handles.Waitbar,0)
1373
1374%------------------------------------------------------------------------
1375% --- Executes when selected cell(s) is changed in PairString.
1376function PairString_CellSelectionCallback(hObject, eventdata, handles)
1377%------------------------------------------------------------------------   
1378if numel(eventdata.Indices)>=1
1379    PairString=get(hObject,'Data');
1380    if ~isempty(PairString{eventdata.Indices(1)})
1381        SetPairs_Callback(hObject, eventdata.Indices(1), handles)
1382    end
1383end
1384
1385%-------------------------------------
1386function enable_i(handles,state)
1387set(handles.i_txt,'Visible',state)
1388set(handles.num_first_i,'Visible',state)
1389set(handles.num_last_i,'Visible',state)
1390set(handles.num_incr_i,'Visible',state)
1391
1392%-----------------------------------
1393function enable_j(handles,state)
1394set(handles.j_txt,'Visible',state)
1395set(handles.num_first_j,'Visible',state)
1396set(handles.num_last_j,'Visible',state)
1397set(handles.num_incr_j,'Visible',state)
1398set(handles.MinIndex_j,'Visible',state)
1399set(handles.MaxIndex_j,'Visible',state)
1400
1401
1402%%%%%%%%%%%%%%%%%%%%
1403%%  MAIN ActionName FUNCTIONS
1404%%%%%%%%%%%%%%%%%%%%
1405%------------------------------------------------------------------------
1406% --- Executes on button press in RUN.
1407%------------------------------------------------------------------------
1408function RUN_Callback(hObject, eventdata, handles)
1409
1410%% settings of the button RUN
1411if ~isequal(get(handles.ActionInput,'BackgroundColor'),[1 0 0])
1412    msgbox_uvmat('ERROR','first activate the button ActionInput')
1413    return
1414end
1415set(handles.RUN,'BusyAction','queue'); % activation of STOP button will set BusyAction to 'cancel'
1416set(handles.RUN, 'Enable','Off')% avoid further RUN action until the current one is finished
1417set(handles.RUN,'BackgroundColor',[1 1 0])%show activation of RUN by yellow color
1418drawnow
1419set(handles.status,'Value',0)% desable status display if relevant
1420status_Callback([], eventdata, handles)
1421
1422%% launch action
1423errormsg=launch_action(handles);
1424if ~isempty(errormsg)
1425     msgbox_uvmat('ERROR',errormsg)
1426end
1427
1428%% reset the GUI series
1429update_waitbar(handles.Waitbar,1); % put the waitbar to end position to indicate launching is finished
1430set(handles.RUN, 'Enable','On')
1431set(handles.RUN,'BackgroundColor',[1 0 0])
1432set(handles.RUN, 'Value',0)
1433
1434%------------------------------------------------------------------------
1435% --- called by RUN_Callback
1436%------------------------------------------------------------------------
1437% The calculations are launched in three different ways:
1438% RunMode='local': calculation on the local Matlab session, will prevent other actions during that time.
1439% RunMode='background': calculation on the local computer, but in a new Matlab session (with no graphic output).
1440% RunMode='cluster': calculations dispatched in a cluster, using a managing system, 'oar, 'sge, or 'sgb'.
1441% In the latter case, the calculation is split in 'packets' of i index (all j indices are contained in a single packet).
1442% This splitting is possible only if the different calculations in the series are independent. Otherwise the action
1443% function imposes a number of processes NbSlice in input, for instance NbSlice=1 for a time series.
1444% If NbSlice is not imposed, the splitting in packets (jobs) is determined
1445% so that a job is optimum length AdvisedJobCPUTime), and the total job number in any case smaller
1446% than MaxJobNumber (these parameters are defined in the file series.xml in
1447% accordance with the management strategy for the cluster). The jobs are
1448% dispatched in parallel into NbCore processors by the cluster managing system.
1449
1450function errormsg=launch_action(handles)
1451errormsg=''; % default
1452
1453%% read the data on the GUI series
1454Param=read_GUI_series(handles); % displayed parameters
1455SeriesData=get(handles.series,'UserData'); % hidden parameters
1456if isfield(SeriesData,'TransformInput')
1457    Param.TransformInput=SeriesData.TransformInput;
1458end
1459if isfield(SeriesData,'ProjObject')
1460    Param.ProjObject=SeriesData.ProjObject;
1461end
1462if ~isfield(SeriesData,'i1_series')
1463    errormsg='The input field series needs to be refreshed: press REFRESH';
1464    return
1465end
1466if isfield(Param,'InputFields')&& isfield(Param.InputFields,'FieldName')&& isequal(Param.InputFields.FieldName,'add_field...')
1467    errormsg='input field name(s) not defined, select add_field...';
1468    return
1469end
1470
1471%% select the Action mode, 'local', 'background' or 'cluster' (if available)
1472RunMode='local'; % default (needed for first opening of the GUI series)
1473if isfield(Param.Action,'RunMode')
1474    RunMode=Param.Action.RunMode;
1475    Param.Action=rmfield(Param.Action,'RunMode'); % remove from the recorded xml file to avoid interference during ImportConfig
1476    Param.RunMode=RunMode; % keep track of the mode
1477end
1478ActionExt='.m'; % default
1479if isfield(Param.Action,'ActionExt')
1480    ActionExt=Param.Action.ActionExt; % '.m', '.sh' (compiled)  or '.py' (Python)
1481    Param.Action=rmfield(Param.Action,'ActionExt'); % remove from the recorded xml file to avoid interference during ImportConfig
1482end
1483ActionName=Param.Action.ActionName;
1484ActionPath=Param.Action.ActionPath;
1485path_series=fileparts(which('series'));
1486
1487%% create the Action fct handle if RunMode option = 'local'
1488if strcmp(RunMode,'local')
1489    if ~isequal(ActionPath,path_series)
1490        eval(['spath=which(''' ActionName ''');']) %spath = current path of the selected function ACTION
1491        if ~exist(ActionPath,'dir')
1492            errormsg=['The prescribed function path ' ActionPath ' does not exist'];
1493            return
1494        end
1495        if ~isequal(spath,ActionPath)
1496            addpath(ActionPath)% add the prescribed path if not the current one
1497        end
1498    end
1499    eval(['h_fun=@' ActionName ';'])%create a function handle for ACTION
1500    if ~isequal(ActionPath,path_series)
1501        rmpath(ActionPath)% add the prescribed path if not the current one
1502    end
1503end
1504
1505%% Get  parameters from series.xml
1506errormsg=''; % default error message
1507ActionFullName=fullfile(get(handles.ActionPath,'String'),ActionName);
1508
1509%% If a compiled version has been selected (ext .sh) check wether it needs to be recompiled
1510if strcmp(ActionExt,'.sh')
1511    TransformPath='';
1512    if isfield(SeriesData,'TransformPath')
1513        TransformPath=SeriesData.TransformPath;
1514        if isfield(SeriesData,'TransformList')
1515            TransformList=get(handles.TransformName,'String');
1516            TransformIndex=get(handles.TransformName,'Value');
1517            TransformName=TransformList{TransformIndex};
1518            if ~ismember(TransformName,SeriesData.TransformList)
1519                TransformPath='';
1520            end
1521        end
1522    end
1523    if ~isempty(TransformPath)&&...
1524          ~strcmp(TransformPath,get(handles.TransformPath,'String'))% if the transform is not in paths set for compilation
1525        msgbox_uvmat('ERROR', 'compilation not available for this transform function, select .m')
1526        return
1527    end
1528    set(handles.series,'Pointer','watch') % set the mouse pointer to 'watch'
1529    set(handles.ActionExt,'BackgroundColor',[1 1 0])
1530    [mcrmajor, mcrminor] = mcrversion;   
1531    MCRROOT = ['MCRROOT',int2str(mcrmajor),int2str(mcrminor)];
1532    RunTime = getenv('MCRROOT'); % Just variable MCRROOT with no version in it's name
1533    if strcmp(RunTime,'')
1534        RunTime = getenv(MCRROOT); % Use specialize MCRROOT with version
1535    end
1536    ActionNameVersion=[ActionName '_' MCRROOT];
1537    ActionFullName=fullfile(get(handles.ActionPath,'String'),[ActionNameVersion '.sh']);
1538    % compile the .m file if the .sh file does not exist yet
1539    if ~exist(ActionFullName,'file')
1540        answer=msgbox_uvmat('INPUT_Y-N','compiled version has not been created: compile now?');
1541        if strcmp(answer,'Yes')
1542            set(handles.ActionExt,'BackgroundColor',[1 1 0])
1543            path_uvmat=fileparts(which('series'));
1544            currentdir=pwd;
1545            cd(get(handles.ActionPath,'String'))% go to the directory of Action
1546            addpath(path_uvmat)% add the path to uvmat to run the fct 'compile'
1547            compile(ActionName,TransformPath)
1548            cd(currentdir)
1549        else
1550            errormsg='Action launch interrupted';
1551            return
1552        end       
1553    else
1554        sh_file_info=dir(fullfile(get(handles.ActionPath,'String'),[ActionNameVersion '.sh']));
1555        m_file_info=dir(fullfile(get(handles.ActionPath,'String'),[ActionName '.m']));
1556        if isfield(m_file_info,'datenum') && m_file_info.datenum>sh_file_info.datenum
1557            set(handles.ActionExt,'BackgroundColor',[1 1 0])
1558            drawnow
1559            answer=msgbox_uvmat('INPUT_Y-N',[ActionNameVersion '.sh needs to be updated: recompile now?']);
1560            if strcmp(answer,'Yes')
1561                path_uvmat=fileparts(which('series'));
1562                currentdir=pwd;
1563                cd(get(handles.ActionPath,'String'))% go to the directory of Action
1564                addpath(path_uvmat)% add the path to uvmat to run the fct 'compile'
1565                addpath(fullfile(path_uvmat,'transform_field'))% add the path to transform functions to run the fct 'compile'
1566                compile(ActionName,TransformPath)
1567                cd(currentdir)
1568            end
1569        end
1570    end
1571
1572    set(handles.ActionExt,'BackgroundColor',[1 1 1])
1573     set(handles.series,'Pointer','arrow') % set the mouse pointer to 'watch
1574end
1575
1576%% set nbre of cluster cores and processes:
1577% NbCore is the number of computer processors used
1578% NbProcess is the number of independent processes in which the required calculation is split.
1579switch RunMode
1580    case {'local','background'}
1581        NbCore=1; % no need to split the calculation
1582    case 'cluster'
1583        %proposed number of cores to reserve in the cluster
1584        NbCoreAdvised=SeriesData.SeriesParam.ClusterParam.NbCoreAdvised;
1585        NbCoreMax=SeriesData.SeriesParam.ClusterParam.NbCoreMax;
1586        if NbCoreMax~=1
1587            if strcmp(ActionExt,'.m')% case of Matlab function (uncompiled)
1588                warning_string=', preferably use .sh option to save Matlab licences';
1589            else
1590                warning_string=')';
1591            end
1592            answer=msgbox_uvmat('INPUT_TXT',['Number of cores (max ' num2str(NbCoreMax) ', ' warning_string],num2str(NbCoreAdvised));
1593            if isempty(answer)
1594                errormsg='Action launch interrupted by user';
1595                return
1596            end
1597            NbCore=str2double(answer);
1598            if NbCore > NbCoreMax
1599                NbCore=NbCoreMax;
1600            end
1601        else
1602            NbCore=1;
1603        end
1604end
1605if ~isfield(Param.IndexRange,'NbSlice')
1606    Param.IndexRange.NbSlice=[];
1607end
1608OutputPath=get(handles.OutputPath,'String');
1609
1610%% Look for processing on multiple experiments set by the GUI browse_data
1611NbExp=1;% initiate the number of experiments set by the GUI browse_data, =1 otherwise
1612if get(handles.Replicate,'Value')
1613    hh=findobj(allchild(0),'Tag','browse_data');
1614    if isempty(hh)
1615        set(handles.Replicate,'Value',0)
1616    else
1617        set(handles.Replicate,'BackgroundColor',[1 1 0])%paint Relicate button in yellow
1618        BrowseData=guidata(hh);
1619        SourceDir=get(BrowseData.SourceDir,'String');
1620        ListExp=get(BrowseData.ListExperiments,'String');
1621        ExpIndices=get(BrowseData.ListExperiments,'Value');
1622        ListExp=ListExp(ExpIndices);
1623        ListDevices=get(BrowseData.ListDevices,'String');
1624        DeviceIndices=get(BrowseData.ListDevices,'Value');
1625        ListDevices=ListDevices(DeviceIndices);
1626        ListDataSeries=get(BrowseData.DataSeries,'String');
1627        DataSeriesIndices=get(BrowseData.DataSeries,'Value');
1628        ListDataSeries=ListDataSeries(DataSeriesIndices);
1629        NbExp=0; % counter of the number of experiments set by the GUI browse_data
1630        for iexp=1:numel(ListExp)
1631            if ~isempty(regexp(ListExp{iexp},'^\+/'))% if it is a folder
1632                if strcmp(get(BrowseData.DataSeries,'enable'),'off') %case of a multiple input line for series
1633                    NbExp=NbExp+1;
1634                    ExpIndex{NbExp}=iexp;
1635                    for idevice=1:numel(ListDevices)
1636                        lpath= fullfile(SourceDir,regexprep(ListExp{iexp},'^\+/',''),...
1637                            regexprep(ListDevices{idevice},'^\+/',''));
1638                        lpathout=fullfile(OutputPath,regexprep(ListExp{iexp},'^\+/',''),...
1639                            regexprep(ListDevices{idevice},'^\+/',''));
1640                        ldir=regexprep(ListDataSeries{idevice},'^\+/','');
1641                        ListPath{idevice,NbExp}=lpath;
1642                        ListPathOut{idevice,NbExp}=lpathout;
1643                        ListSubdir{idevice,NbExp}=ldir;
1644                    end
1645                else
1646                    for idevice=1:numel(ListDevices)
1647                        if ~isempty(regexp(ListDevices{idevice},'^\+/'))% if it is a folder
1648                            for isubdir=1:numel(ListDataSeries)
1649                                if ~isempty(regexp(ListDataSeries{isubdir},'^\+/'))% if it is a folder
1650                                    lpath= fullfile(SourceDir,regexprep(ListExp{iexp},'^\+/',''),...
1651                                        regexprep(ListDevices{idevice},'^\+/',''));
1652                                    lpathout= fullfile(OutputPath,regexprep(ListExp{iexp},'^\+/',''),...
1653                                        regexprep(ListDevices{idevice},'^\+/',''));
1654                                    ldir= regexprep(ListDataSeries{isubdir},'^\+/','');
1655                                    if exist(fullfile(lpath,ldir),'dir')
1656                                        NbExp=NbExp+1;
1657                                        ExpIndex{NbExp}=iexp;
1658                                        ListPath{NbExp}=lpath;
1659                                        ListPathOut{NbExp}=lpathout;
1660                                        ListSubdir{NbExp}=ldir;
1661                                    end
1662                                end
1663                            end
1664                        end
1665                    end
1666                end
1667            end
1668        end
1669        answer=msgbox_uvmat('INPUT_Y-N-Cancel',['replicate the processing on ' num2str(NbExp) ' data series']);
1670        if strcmp(answer,'Cancel')||strcmp(answer,'No')
1671            return
1672        end
1673    end
1674end
1675
1676%%%%%%%%%%%%%%%%%%% LOOP ON EXPERIMENTS POSSIBLY SET BY THE GUI browse_data, NbExp=1 otherwise %%%%%%%%%
1677
1678for iexp=1:NbExp
1679    if get(handles.Replicate,'Value')
1680        if ~strcmp(get(handles.RUN,'BusyAction'),'queue')% allow for STOP action
1681            disp('program stopped by user')
1682            return
1683        end
1684        set(BrowseData.ListExperiments,'Value',ExpIndex{iexp})
1685        Param.InputTable(:,1)=ListPath(:,iexp);
1686        Param.InputTable(:,2)=ListSubdir(:,iexp);
1687        OutputSubDir=unique(ListSubdir(:,iexp));
1688        Param.OutputSubDir=OutputSubDir{1};
1689        if numel(OutputSubDir)>1% case
1690            for iout=2:numel(OutputSubDir)
1691                Param.OutputSubDir=[Param.OutputSubDir '-' OutputSubDir{iout}];
1692            end               
1693        end       
1694    end
1695    [xx,ExpName]=fileparts(Param.InputTable{1,1});
1696    Param.IndexRange.first_i=str2num(get(handles.num_first_i,'String'));%reset the firrst_i and last_i for multiple experiments, modified by the splitting into NbProcess
1697    Param.IndexRange.last_i=str2num(get(handles.num_last_i,'String'));
1698   
1699    %% create the output data directory if needed, after checking its existence
1700    OutputDir='';
1701    answer='';
1702    if isfield(Param,'OutputSubDir')% possibly update the output dir if it already exists
1703        PathOut=get(handles.OutputPath,'String');
1704        if ~exist(PathOut,'dir') % test if  the dir  already exist
1705        PathOut=uigetdir(PathOut,'pick the output root path')
1706        set(handles.OutputPath,'String',PathOut);
1707        end
1708        PathExpOut=fullfile(PathOut,get(handles.Experiment,'String'));
1709        if ~exist(PathExpOut,'dir')
1710            [tild,msg1]=mkdir(PathExpOut);
1711            if ~strcmp(msg1,'')
1712                errormsg=['cannot create ' PathExpOut ': ' msg1]; % error message for directory creation
1713                return
1714            end
1715        end
1716        PathExpDeviceOut=fullfile(PathExpOut,get(handles.Device,'String'));
1717        if ~exist(PathExpDeviceOut,'dir')
1718            [tild,msg1]=mkdir(PathExpDeviceOut);
1719            if ~strcmp(msg1,'')
1720                errormsg=['cannot create ' PathExpDeviceOut ': ' msg1]; % error message for directory creation
1721                return
1722            end
1723        end
1724        SubDirOut=[Param.OutputSubDir Param.OutputDirExt];
1725        SubDirOutNew=SubDirOut;
1726        detect=exist(fullfile(PathExpDeviceOut,SubDirOutNew),'dir'); % test if  the dir  already exist
1727        check_create=1; % need to create the result directory by default
1728        CheckOverwrite=1;
1729        if isfield(Param,'CheckOverwrite')
1730            CheckOverwrite=Param.CheckOverwrite;% will overwrite previous data if it is equal to 1
1731        end
1732        while detect
1733            if CheckOverwrite
1734                comment=', possibly overwrite previous data';
1735            else
1736                comment=', will complement existing result files (no overwriting)';
1737            end
1738            answer=msgbox_uvmat('INPUT_Y-N-Cancel',['use existing ouput directory: ' fullfile(PathExpDeviceOut,SubDirOutNew) comment]);
1739            if strcmp(answer,'Cancel')
1740                break
1741            elseif strcmp(answer,'Yes')
1742                detect=0;
1743                check_create=0;
1744            else
1745                r=regexp(SubDirOutNew,'(?<root>.*\D)(?<num1>\d+)$','names'); % detect whether name ends by a number
1746                if isempty(r)
1747                    r(1).root=[SubDirOutNew '_'];
1748                    r(1).num1='0';
1749                end
1750                SubDirOutNew=[r(1).root num2str(str2num(r(1).num1)+1)]; % increment the index by 1 or put 1
1751                detect=exist(fullfile(PathExpDeviceOut,SubDirOutNew),'dir'); % test if  the dir  already exists
1752                check_create=1;
1753            end
1754        end
1755        if strcmp(answer,'Cancel')
1756            continue
1757        end
1758        Param.OutputDirExt=regexprep(SubDirOutNew,['^' Param.OutputSubDir],'');
1759        Param.OutputRootFile=Param.InputTable{1,3}; % the first sorted RootFile taken for output
1760        OutputDir=fullfile(PathExpDeviceOut,[Param.OutputSubDir Param.OutputDirExt]); % full name (with path) of output directory
1761        if check_create    % create output directory if it does not exist
1762            [tild,msg1]=mkdir(OutputDir);
1763            if ~strcmp(msg1,'')
1764                errormsg=['cannot create ' OutputDir ': ' msg1]; % error message for directory creation
1765                return
1766            end
1767        end
1768       
1769    elseif isfield(Param,'ActionInput')&&isfield(Param.ActionInput,'LogPath')% custom definition of the output dir
1770        OutputDir=Param.ActionInput.LogPath;
1771    end
1772   
1773    set(handles.OutputSubDir,'String',Param.OutputSubDir)
1774    set(handles.OutputDirExt,'String',Param.OutputDirExt)
1775    drawnow
1776    if get(handles.Replicate,'Value')
1777        set(handles.InputTable,'Data',Param.InputTable)
1778        check_input_file_series(handles)
1779    end
1780    DirXml=fullfile(OutputDir,'0_XML');
1781    if ~exist(DirXml,'dir')
1782        [~,msg1]=mkdir(DirXml);
1783        if ~strcmp(msg1,'')
1784            errormsg=['cannot create ' DirXml ': ' msg1]; % error message for directory creation
1785            return
1786        end
1787        [success,msg] = fileattrib(DirXml,'+w','g','s'); % allow writing access for the group of users, recursively in the folder
1788        if success==0
1789            msgbox_uvmat('WARNING',{['unable to set group write access to ' DirXml ':']; msg}); % error message for directory creation
1790        end
1791    end
1792    OutputNomType=nomtype2pair(Param.InputTable{1,4}); % nomenclature for output files
1793   
1794    %% get the set of reference input field indices
1795    first_i=1; % first i index to process
1796    last_i=1; % last i index to process
1797    incr_i=1; % increment step in i index
1798    first_j=1; % first j index to process
1799    last_j=1; % last j index to process
1800    incr_j=1; % increment step in j index
1801    if isfield(Param.IndexRange,'first_i')
1802        first_i=Param.IndexRange.first_i;
1803        incr_i=Param.IndexRange.incr_i;
1804        last_i=Param.IndexRange.last_i;
1805    end
1806    if isfield(Param.IndexRange,'incr_j')
1807        first_j=Param.IndexRange.first_j;
1808        last_j=Param.IndexRange.last_j;
1809        incr_j=Param.IndexRange.incr_j;
1810    end
1811    if last_i < first_i || last_j < first_j
1812        errormsg= 'series/Run_Callback:last field index must be larger or equal to the first one';
1813        return
1814    end
1815    %incr_i must be defined, =1 by default, if NbSlice is active
1816    if isempty(incr_i)&& ~isempty(Param.IndexRange.NbSlice)
1817        incr_i=1;
1818        set(handles.num_incr_i,'String','1')
1819    end
1820    % case of no increment i defined: processing is done on the available files found in i1_series
1821    if isempty(incr_i)
1822        if isempty(incr_j)
1823            [ref_j,ref_i]=find(squeeze(SeriesData.i1_series{1}(1,:,:)));
1824            ref_j=ref_j(ref_j>=first_j & ref_j<=last_j);
1825            ref_i=ref_i(ref_i>=first_i & ref_i<=last_i);
1826            ref_j=ref_j-1;
1827            ref_i=ref_i-1;
1828        else
1829            ref_j=first_j:incr_j:last_j;
1830            [tild,ref_i]=find(squeeze(SeriesData.i1_series{1}(1,:,:)));
1831            ref_i=ref_i-1;
1832            ref_i=ref_i(ref_i>=first_i & ref_i<=last_i);
1833        end
1834        % increment i is defined: processing is done on first_i:incr_i:last_i;
1835    else
1836        ref_i=first_i:incr_i:last_i;
1837        if isempty(incr_j)% automatic finding of the existing j indices
1838            [ref_j,tild]=find(squeeze(SeriesData.i1_series{1}(1,:,:)));
1839            ref_j=ref_j-1;
1840            ref_j=ref_j(ref_j>=first_j & ref_j<=last_j);
1841        else
1842            ref_j=first_j:incr_j:last_j;
1843        end
1844    end
1845    CPUTime=1; % job time estimated at 1 min per iteration (on index i and j) by default
1846    if isfield(Param.Action, 'CPUTime') && ~isempty(Param.Action.CPUTime)
1847        CPUTime=Param.Action.CPUTime; % Note: CpUTime for one iteration ref_i has to be multiplied by the number of j indices nbfield_j
1848    end
1849    nbfield_j=numel(ref_j); % number of j indices
1850    BlockLength=numel(ref_i); % by default, job involves the full set of i field indices
1851    NbProcess=1;
1852    switch RunMode
1853        case 'cluster'
1854            JobNumberMax=SeriesData.SeriesParam.ClusterParam.JobNumberMax;
1855            JobCPUTimeAdvised=SeriesData.SeriesParam.ClusterParam.JobCPUTimeAdvised;
1856            if isempty(Param.IndexRange.NbSlice)% if NbSlice is not defined
1857                BlockLength= ceil(JobCPUTimeAdvised/(CPUTime*nbfield_j)); % iterations are grouped in sets with length BlockLength  such that the typical CPU time of a job is JobCPUTimeAdvised.
1858                BlockLength=max(BlockLength,ceil(numel(ref_i)*NbExp/JobNumberMax)); % possibly increase the BlockLength to have less than MaxJobNumber jobs
1859                NbProcess=ceil(numel(ref_i)/BlockLength) ; % nbre of processes sent to oar
1860            else
1861                NbProcess=Param.IndexRange.NbSlice; % the parameter NbSlice sets the nbre of run processes
1862            end
1863            NbCore=min(NbCore,NbProcess); % reduces the number of cores if it exceeds the number of processes
1864        otherwise
1865            if ~isempty(Param.IndexRange.NbSlice)
1866                NbProcess=Param.IndexRange.NbSlice; % the parameter NbSlice sets the nbre of run processes
1867            end
1868    end
1869   
1870    %% record nbre of output files and starting time for computation for status
1871    StatusData=get(handles.status,'UserData');
1872    if isfield(StatusData,'OutputFileMode')
1873        switch StatusData.OutputFileMode
1874            case 'NbInput'
1875                StatusData.NbOutputFile=numel(ref_i)*nbfield_j;
1876            case 'NbInput_i'
1877                StatusData.NbOutputFile=numel(ref_i);
1878            case 'NbSlice'
1879                StatusData.NbOutputFile=str2num(get(handles.num_NbSlice,'String'));
1880        end
1881    end
1882    StatusData.TimeStart=now;
1883    set(handles.status,'UserData',StatusData)
1884   
1885    %% case of a function in Python
1886    if strcmp(ActionExt, '.py (in dev.)')
1887        fprintf([
1888            '\n' ...
1889            '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n' ...
1890            'The option .py is used. It is still in development.\n' ...
1891            'To try it, first install pyper and the most recent version of fluidimage\n' ...
1892            '(see https://bitbucket.org/fluiddyn/fluidimage).\n' ...
1893            'Warning: there is no direct correspondance between UVMAT and fluidimage parameters\n' ...
1894            '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n'])
1895        RunMode = 'python';
1896    end
1897   
1898   
1899    %% direct processing on the current Matlab session or creation of command files
1900    filexml=cell(1,NbProcess); % initialisation of the names of the files containing the processing parameters
1901    extxml=cell(1,NbProcess); % initialisation of the set of labels used for the files documenting each process
1902    for iprocess=1:NbProcess
1903        extxml{iprocess}='.xml';
1904    end
1905    for iprocess=1:NbProcess
1906        if ~strcmp(get(handles.RUN,'BusyAction'),'queue')% allow for STOP action
1907            disp('program stopped by user')
1908            return
1909        end
1910        Param.IndexRange.incr_slice=incr_i;
1911        if isempty(Param.IndexRange.NbSlice)
1912            Param.IndexRange.first_i=first_i+(iprocess-1)*BlockLength*incr_i;
1913            if Param.IndexRange.first_i>last_i
1914                NbProcess=iprocess-1; % leave the loop, we are at the end of the calculation
1915                break
1916            end
1917            Param.IndexRange.last_i=min(last_i,first_i+(iprocess)*BlockLength*incr_i-1);
1918        else %multislices (then incr_i is not empty)
1919            Param.IndexRange.first_i= first_i+iprocess-1;
1920            Param.IndexRange.incr_slice=incr_i*Param.IndexRange.NbSlice;
1921        end
1922        for ilist=1:size(Param.InputTable,1)
1923            Param.InputTable{ilist,1}=regexprep(Param.InputTable{ilist,1},'\','/'); % correct path name for PCWIN system
1924        end
1925       
1926        if isfield(Param,'OutputSubDir')
1927            t=struct2xml(Param);
1928            t=set(t,1,'name','Series');
1929            extxml{iprocess}=fullfile_uvmat('','',Param.InputTable{1,3},'.xml',OutputNomType,...
1930                Param.IndexRange.first_i,Param.IndexRange.last_i,first_j,last_j);
1931            filexml{iprocess}=fullfile(OutputDir,'0_XML',extxml{iprocess});
1932            try
1933                save(t, filexml{iprocess}); % save the xml file containing the processing parameters
1934            catch ME
1935                if ~strcmp (RunMode,'local')
1936                    errormsg=['error writting ' filexml{iprocess} ': ' ME.message];
1937                    return
1938                end
1939            end
1940        end
1941        if strcmp (RunMode,'local')
1942            switch ActionExt
1943                case '.m'
1944                    h_fun(Param); % direct launching
1945                   
1946                case '.sh'
1947                    switch computer
1948                        case {'PCWIN','PCWIN64'} %Windows system
1949                            filexml=regexprep(filexml,'\\','\\\\'); % add '\' so that '\' are left as characters
1950                            system([ActionFullName ' ' RunTime ' ' filexml{iprocess}]); % TODO: adapt to DOS system
1951                        case {'GLNX86','GLNXA64','MACI64'}%Linux  system
1952                            system([ActionFullName ' ' RunTime ' ' filexml{iprocess}]);
1953                    end
1954            end
1955        end
1956    end
1957   
1958    if ~strcmp (RunMode,'local') && ~strcmp(RunMode,'python')
1959        %% processing on a different session of the same computer (background) or cluster, create executable files
1960        batch_file_list=cell(NbProcess,1); % initiate the list of executable files
1961        DirExe=fullfile(OutputDir,'0_EXE'); % directory name for executable files
1962        switch computer
1963            case {'PCWIN','PCWIN64'} %Windows system
1964                ExeExt='.bat';
1965            case {'GLNX86','GLNXA64','MACI64'}%Linux  system
1966                ExeExt='.sh';
1967        end
1968        %create subdirectory for executable files
1969        if ~exist(DirExe,'dir')
1970            [tild,msg1]=mkdir(DirExe);
1971            if ~strcmp(msg1,'')
1972                errormsg=['cannot create ' DirExe ': ' msg1]; % error message for directory creation
1973                return
1974            end
1975            [success,msg] = fileattrib(DirExe,'+w','g','s'); % allow writing access for the group of users, recursively in the folder
1976            if success==0
1977                msgbox_uvmat('WARNING',{['unable to set group write access to ' DirExe ':']; msg}); % error message for directory creation
1978            end
1979        end
1980        %create subdirectory for log files
1981        DirLog=fullfile(OutputDir,'0_LOG');
1982        if ~exist(DirLog,'dir')
1983            [tild,msg1]=mkdir(DirLog);
1984            if ~strcmp(msg1,'')
1985                errormsg=['cannot create ' DirLog ': ' msg1]; % error message for directory creation
1986                return
1987            end
1988            [success,msg] = fileattrib(DirLog,'+w','g','s'); % allow writing access for the group of users, recursively in the folder
1989            if success==0
1990                msgbox_uvmat('WARNING',{['unable to set group write access to ' DirLog ':']; msg}); % error message for directory creation
1991            end
1992        end
1993       
1994        %create the executable file
1995        file_exe_global=fullfile_uvmat('','',Param.InputTable{1,3},ExeExt,OutputNomType,...
1996            first_i,last_i,first_j,last_j);
1997        file_exe_global=fullfile(OutputDir,'0_EXE',file_exe_global);
1998        filelog_global=fullfile_uvmat('','',Param.InputTable{1,3},'.log',OutputNomType,...
1999            first_i,last_i,first_j,last_j);
2000        filelog_global=fullfile(OutputDir,'0_LOG',filelog_global);
2001       
2002        for iprocess=1:NbProcess
2003            %create the executable file
2004            batch_file_list{iprocess}=fullfile(OutputDir,'0_EXE',regexprep(extxml{iprocess},'.xml$',ExeExt));
2005           
2006            % set the log file name
2007            filelog{iprocess}=fullfile(OutputDir,'0_LOG',regexprep(extxml{iprocess},'.xml$','.log'));
2008        end
2009    end
2010   
2011    %% launch the executable files for background or cluster processing
2012   
2013    switch RunMode
2014       
2015        case 'background'
2016            [fid,message]=fopen(file_exe_global,'w');
2017            if isequal(fid,-1)
2018                errormsg=['creation of ' file_exe_global ':' message];
2019                return
2020            end
2021            switch ActionExt
2022                case '.m'% Matlab function
2023                    switch computer
2024                        case {'GLNX86','GLNXA64','MACI64'}
2025                            matlab_ver = ver('MATLAB');
2026                            matlab_version = matlab_ver.Version;
2027                            cmd=[...
2028                                '#!/bin/bash\n'...
2029                                'source /etc/profile\n'...
2030                                'module load matlab/' matlab_version '\n'...% CHOICE OF MATLAB VERSION
2031                                'time_start=$(date +%%s)\n'...
2032                                'matlab -nodisplay -nosplash -nojvm -logfile ''' filelog_global ''' <<END_MATLAB\n'...
2033                                'addpath(''' path_series ''');\n'...
2034                                'addpath(''' Param.Action.ActionPath ''');\n'];
2035                            for iprocess=1:NbProcess
2036                                cmd=[cmd '' Param.Action.ActionName  '(''' filexml{iprocess} ''');\n'];
2037                            end
2038                            cmd=[cmd  'exit\n' 'END_MATLAB\n'...
2039                                'time_end=$(date +%%s)\n'...
2040                                'echo "global time = " $(($time_end - $time_start)) >> ''' filelog_global '''\n'];
2041                            fprintf(fid,cmd); % fill the executable file with the  char string cmd
2042                            fclose(fid); % close the executable filefilelog_global
2043                            system(['chmod +x ' file_exe_global]); % set the file to executable
2044                        case {'PCWIN','PCWIN64'}
2045                            cmd=['matlab -automation -logfile ' regexprep(filelog{iprocess},'\\','\\\\')...
2046                                ' -r "addpath(''' regexprep(path_series,'\\','\\\\') ''');'...
2047                                'addpath(''' regexprep(Param.Action.ActionPath,'\\','\\\\') ''');'];
2048                            for iprocess=1:NbProcess
2049                                cmd=[cmd '' Param.Action.ActionName  '( ''' regexprep(filexml{iprocess},'\\','\\\\') ''');']
2050                            end
2051                            cmd=[cmd ';exit"'];
2052                            fprintf(fid,cmd); % fill the executable file with the  char string cmd
2053                            fclose(fid); % close the executable file
2054                    end
2055                    system([file_exe_global ' &'])% directly execute the command file
2056                case '.sh' % compiled Matlab function
2057                    for iprocess=1:NbProcess
2058                        switch computer
2059                            case {'GLNX86','GLNXA64','MACI64'}
2060                                [fid,message]=fopen(batch_file_list{iprocess},'w'); % create the executable file
2061                                if isequal(fid,-1)
2062                                    errormsg=['creation of .bat file: ' message];
2063                                    return
2064                                end
2065                                cmd=['#!/bin/bash \n '...
2066                                    '#$ -cwd \n '...
2067                                    'hostname && date \n '...
2068                                    'umask 002 \n'...
2069                                    ActionFullName ' ' RunTime ' ' filexml{iprocess}]; % allow writting access to created files for user group
2070                                fprintf(fid,cmd); % fill the executable file with the  char string cmd
2071                                fclose(fid); % close the executable file
2072                                system(['chmod +x ' batch_file_list{iprocess}]); % set the file to executable
2073                                system([batch_file_list{iprocess} ' &'])% directly execute the command file
2074                            case {'PCWIN','PCWIN64'}
2075                                msgbox_uvmat('ERROR','option for compiled Matlab functions not implemented for Windows system')
2076                                return
2077                        end
2078                    end
2079                    msgbox_uvmat('CONFIRMATION',[ActionFullName ' launched in background for ' ExpName ': press STATUS to see results'])
2080            end
2081           
2082        case 'cluster' % option 'oar-parexec' used
2083            %create subdirectory for oar commands
2084            for iprocess=1:NbProcess
2085                [fid,message]=fopen(batch_file_list{iprocess},'w'); % create the executable file
2086                if isequal(fid,-1)
2087                    errormsg=['creation of .bat file: ' message];
2088                    return
2089                end
2090                if  strcmp(ActionExt,'.sh')
2091                    cmd=['#!/bin/bash \n '...
2092                        '#$ -cwd \n '...
2093                        'hostname && date \n '...
2094                        'umask 002 \n'...
2095                        ActionFullName ' ' RunTime ' ' filexml{iprocess}]; % allow writting access to created files for user group
2096                else
2097                    matlab_ver = ver('MATLAB');
2098                    matlab_version = matlab_ver.Version;
2099                    cmd=[...
2100                        '#!/bin/bash\n'...
2101                        'source /etc/profile\n'...
2102                        'module load matlab/' matlab_version '\n'...% CHOICE OF MATLAB VERSION
2103                        'matlab -nodisplay -nosplash -nojvm -singleCompThread -logfile ''' filelog{iprocess} ''' <<END_MATLAB\n'...
2104                        'addpath(''' path_series ''');\n'...
2105                        'addpath(''' Param.Action.ActionPath ''');\n'...
2106                        '' Param.Action.ActionName  '(''' filexml{iprocess} ''');\n'...
2107                        'exit\n'...
2108                        'END_MATLAB\n'];
2109                end
2110                fprintf(fid,cmd); % fill the executable file with the  char string cmd
2111                fclose(fid); % close the executable file
2112                system(['chmod +x ' batch_file_list{iprocess}]); % set the file to executable
2113            end
2114            DIR_CLUSTER=fullfile(OutputDir,'0_CLUSTER');
2115            if exist(DIR_CLUSTER,'dir')% delete the content of the dir 0_LOG to allow new input
2116                curdir=pwd;
2117                cd(DIR_CLUSTER)
2118                delete('*')
2119                cd(curdir)
2120            else
2121                [tild,msg1]=mkdir(DIR_CLUSTER);
2122                if ~strcmp(msg1,'')
2123                    errormsg=['cannot create ' DIR_CLUSTER ': ' msg1]; % error message for directory creation
2124                    return
2125                end
2126            end
2127            % create file containing the list of jobs
2128            ListProcess=fullfile(DIR_CLUSTER,'job_list.txt'); % name of the file containing the list of executables
2129            [fid,errormsg]=fopen(ListProcess,'w'); % open it for writting
2130            if isempty(errormsg)
2131            for iprocess=1:length(batch_file_list)
2132                fprintf(fid,[batch_file_list{iprocess} '\n']); % write list of exe files
2133            end
2134            fclose(fid);
2135            system(['chmod +x ' ListProcess]); % set the file to executable
2136            else
2137                errormsg=['error for writting the executable file:' errormsg];
2138            end       
2139            CPUTimeProcess=CPUTime*BlockLength*nbfield_j; % estimated CPU time for one individual process (in minutes)
2140            LaunchCmdFcn=SeriesData.SeriesParam.ClusterParam.LaunchCmdFcn;
2141            oar_command=feval(LaunchCmdFcn,ListProcess,ActionFullName,DirLog,NbProcess, NbCore,CPUTimeProcess)
2142            [status,result]=system(oar_command)% execute system command and show the result (ID number of the launched job) on the Matlab command window
2143            filename_oarcommand=fullfile(DIR_CLUSTER,'0_cluster_command'); % keep track of the command in file '0-OAR/0_cluster_command'
2144            [fid,errormsg]=fopen(filename_oarcommand,'w');
2145            if ~isempty(errormsg)
2146                msgbox_uvmat('ERROR',['cannot create ' filename_oarcommand ': ' errormsg])
2147                return
2148            end
2149            fprintf(fid,oar_command); % store the command
2150            fprintf(fid,result); % store the result (job ID number)
2151            fclose(fid);
2152            if status==0
2153                msgbox_uvmat('CONFIRMATION',[ActionFullName ' launched for ' ExpName ' as ' num2str(NbProcess) ' processes in cluster: press STATUS to see results'])
2154            else
2155                msgbox_uvmat('ERROR',result)
2156            end
2157            %     case 'cluster_pbs' % for LMFA Kepler machine:  trqnsferred to fct
2158           
2159            %         %create subdirectory for pbs command and log files
2160            %         DirPBS=fullfile(OutputDir,'0_PBS'); % todo : common name OAR/PBS
2161            %         if exist(DirPBS,'dir')% delete the content of the dir 0_LOG to allow new input
2162            %             curdir=pwd;
2163            %             cd(DirPBS)
2164            %             delete('*')
2165            %             cd(curdir)
2166            %         else
2167            %             [tild,msg1]=mkdir(DirPBS);
2168            %             if ~strcmp(msg1,'')
2169            %                 errormsg=['cannot create ' DirPBS ': ' msg1]; % error message for directory creation
2170            %                 return
2171            %             end
2172            %         end
2173            %         max_walltime=3600*20; % 20h max total calculation (cannot exceed 24 h)
2174            %         walltime_onejob=1800; % seconds, max estimated time for asingle file index value
2175            %         ListProcess=fullfile(DirPBS,'job_list.txt'); % create name of the global executable file
2176            %         fid=fopen(ListProcess,'w');
2177            %         for iprocess=1:length(batch_file_list)
2178            %             fprintf(fid,[batch_file_list{iprocess} '\n']); % list of exe files
2179            %         end
2180            %         fclose(fid);
2181            %         system(['chmod +x ' ListProcess]); % set the file to executable
2182            %         pbs_command=['qsub -n CIVX '...
2183            %             '-t idempotent --checkpoint ' num2str(walltime_onejob+60) ' '...
2184            %             '-l /core=' num2str(NbCore) ','...
2185            %             'walltime=' datestr(min(1.05*walltime_onejob/86400*max(NbProcess*BlockLength*nbfield_j,NbCore)/NbCore,max_walltime/86400),13) ' '...
2186            %             '-E ' regexprep(ListProcess,'\.txt\>','.stderr') ' '...
2187            %             '-O ' regexprep(ListProcess,'\.txt\>','.log') ' '...
2188            %             extra_qstat ' '...
2189            %             '"oar-parexec -s -f ' ListProcess ' '...
2190            %             '-l ' ListProcess '.log"'];
2191            %         filename_oarcommand=fullfile(DirPBS,'pbs_command');
2192            %         fid=fopen(filename_oarcommand,'w');
2193            %         fprintf(fid,pbs_command);
2194            %         fclose(fid);
2195            %         fprintf(pbs_command); % display in command line
2196            %         %system(pbs_command);
2197            %         msgbox_uvmat('CONFIRMATION',[ActionFullName ' command ready to be launched in cluster'])
2198           
2199        case 'cluster_sge' % for PSMN % TODO: use the standard 'cluster' config with an external fct
2200            % Au PSMN, on ne cr??e pas 1 job avec plusieurs c??urs, mais N jobs de 1 c??urs
2201            % o?? N < 1000.
2202            %create subdirectory for pbs command and log files
2203           
2204            DirSGE=fullfile(OutputDir,'0_SGE');
2205            if exist(DirSGE,'dir')% delete the content of the dir 0_LOG to allow new input
2206                curdir=pwd;
2207                cd(DirSGE)
2208                delete('*')
2209                cd(curdir)
2210            else
2211                [tild,msg1]=mkdir(DirSGE);
2212                if ~strcmp(msg1,'')
2213                    errormsg=['cannot create ' DirSGE ': ' msg1]; % error message for directory creation
2214                    return
2215                end
2216            end
2217            maxImgsPerJob = ceil(length(batch_file_list)/NbCore);
2218            disp(['Max number of jobs: ' num2str(NbCore)])
2219            disp(['Images per job: ' num2str(maxImgsPerJob)])
2220           
2221            iprocess = 1;
2222            imgsInJob = [];
2223            currJobIndex = 1;
2224            done = 0;
2225            while(~done)
2226                if(iprocess <= length(batch_file_list))
2227                    imgsInJob = [imgsInJob, iprocess];
2228                end
2229                if((numel(imgsInJob) >= maxImgsPerJob) || (iprocess == length(batch_file_list)))
2230                    cmd=['#!/bin/sh \n'...
2231                        '#$ -cwd \n'...
2232                        'hostname && date\n']
2233                    for ii=1:numel(imgsInJob)
2234                        cmd=[cmd ActionFullName ' /softs/matlab ' filexml{imgsInJob(ii)} '\n'];
2235                    end
2236                    [fid, message] = fopen([DirSGE '/job' num2str(currJobIndex) '.sh'], 'w');
2237                    fprintf(fid, cmd);
2238                    fclose(fid);
2239                    system(['chmod +x ' DirSGE '/job' num2str(currJobIndex) '.sh'])
2240                    sge_command=['qsub -N civ_' num2str(currJobIndex) ' '...
2241                        '-q ' qstat_Queue ' '...
2242                        '-e ' fullfile([DirSGE '/job' num2str(currJobIndex) '.out']) ' '...
2243                        '-o ' fullfile([DirSGE '/job' num2str(currJobIndex) '.out']) ' '...
2244                        fullfile([DirSGE '/job' num2str(currJobIndex) '.sh'])];
2245                    fprintf(sge_command); % display in command line
2246                    [status, result] = system(sge_command);
2247                    fprintf(result);
2248                    currJobIndex = currJobIndex + 1;
2249                    imgsInJob = [];
2250                end
2251                if(iprocess == length(batch_file_list))
2252                    done = 1;
2253                end
2254                iprocess = iprocess + 1;
2255            end
2256            msgbox_uvmat('CONFIRMATION',[num2str(currJobIndex-1) ' jobs launched on queue ' qstat_Queue '.'])
2257        case 'python'
2258            command = ['LD_LIBRARY_PATH=$(echo $LD_LIBRARY_PATH | pyp "l = x.split('':''); l = [s for s in l if ''matlab'' not in s]; print('':''.join(l))") ' ...
2259                'python -m fluidimage.run_from_xml ' filexml{iprocess}];
2260            fprintf(['command:\n' command '\n\n'])
2261            system(command, '-echo');
2262    end
2263    if exist(OutputDir,'dir')
2264        [SUCCESS,MESSAGE,MESSAGEID] = fileattrib (OutputDir);
2265        if MESSAGE.GroupWrite~=1
2266            [success,msg] = fileattrib(OutputDir,'+w','g','s'); % allow writing access for the group of users, recursively in the folder
2267            if success==0
2268                msgbox_uvmat('WARNING',{['unable to set group write access to ' OutputDir ':']; msg}); % error message for directory creation
2269            end
2270        end
2271    end
2272end
2273set(handles.Replicate,'BackgroundColor',[0 1 0])
2274
2275%------------------------------------------------------------------------
2276function STOP_Callback(hObject, eventdata, handles)
2277%------------------------------------------------------------------------
2278set(handles.RUN, 'BusyAction','cancel')
2279set(handles.RUN,'BackgroundColor',[1 0 0])
2280set(handles.RUN,'enable','on')
2281set(handles.RUN, 'Value',0)
2282
2283%------------------------------------------------------------------------
2284% --- read parameters from the GUI series
2285%------------------------------------------------------------------------
2286function Param=read_GUI_series(handles)
2287
2288%% read raw parameters from the GUI series
2289Param=read_GUI(handles.series);
2290
2291%% clean the output structure by removing unused information
2292if isfield(Param,'Pairs')
2293    Param=rmfield(Param,'Pairs'); % info Pairs not needed for output
2294end
2295if isfield(Param,'InputLine')
2296    Param=rmfield(Param,'InputLine');
2297end
2298if isfield(Param,'EditObject')
2299    Param=rmfield(Param,'EditObject');
2300end
2301Param.IndexRange.TimeSource=Param.IndexRange.TimeTable{end,1};
2302Param.IndexRange=rmfield(Param.IndexRange,'TimeTable');
2303empty_line=false(size(Param.InputTable,1),1);
2304for iline=1:size(Param.InputTable,1)
2305    empty_line(iline)=isempty(cell2mat(Param.InputTable(iline,1:3)));
2306end
2307Param.InputTable(empty_line,:)=[];
2308
2309%------------------------------------------------------------------------
2310% --- Executes on selection change in ActionName.
2311function ActionName_Callback(hObject, ActionPath, handles)
2312%------------------------------------------------------------------------
2313
2314%% stop any ongoing series processing
2315if isequal(get(handles.RUN,'Value'),1)
2316    answer= msgbox_uvmat('INPUT_Y-N','stop current Action process?');
2317    if strcmp(answer,'Yes')
2318        STOP_Callback(hObject, [], handles)
2319    else
2320        return
2321    end
2322end
2323set(handles.ActionName,'BackgroundColor',[1 1 0])
2324huigetfile=findobj(allchild(0),'tag','status_display');
2325if ~isempty(huigetfile)
2326    delete(huigetfile)
2327end
2328drawnow
2329
2330%% get Action name and path
2331NbBuiltinAction=get(handles.Action,'UserData'); % nbre of functions initially proposed in the menu ActionName (as defined in the Opening fct of series)
2332ActionList=get(handles.ActionName,'String'); % list menu fields
2333ActionIndex=get(handles.ActionName,'Value');
2334if ~isequal(ActionIndex,1)% if we are not just opening series
2335    InputTable=get(handles.InputTable,'Data');
2336    if isempty(InputTable{1,4})
2337        msgbox_uvmat('ERROR','no input file available: use Open in the menu bar')
2338        return
2339    end
2340end
2341ActionName= ActionList{get(handles.ActionName,'Value')}; % selected function name
2342ActionPathList=get(handles.ActionName,'UserData'); % list of recorded paths to functions of the list ActionName
2343
2344%% add a new function to the menu if 'more...' has been selected in the menu ActionName
2345if isequal(ActionName,'more...')
2346    if ~ischar(ActionPath)
2347        ActionPath=get(handles.ActionPath,'String');
2348    end
2349    [FileName, PathName] = uigetfile( ...
2350        {'*.m', ' (*.m)';
2351        '*.m',  '.m files '; ...
2352        '*.*', 'All Files (*.*)'}, ...
2353        'Pick a series processing function ',ActionPath);
2354    if length(FileName)<2
2355        return
2356    end
2357    [tild,ActionName,ActionExt]=fileparts(FileName);
2358   
2359    % insert the choice in the menu ActionName
2360    ActionIndex=find(strcmp(ActionName,ActionList),1); % look for the selected function in the menu Action
2361    PathName=regexprep(PathName,'/$','');
2362    if ~isempty(ActionIndex) && ~strcmp(ActionPathList{ActionIndex},PathName)%compare the path to the existing fct
2363        ActionIndex=[]; % the selected path is different than the recorded one
2364    end
2365    if isempty(ActionIndex)%the qselected fct (with selected path) does not exist in the menu
2366        ActionIndex= length(ActionList);
2367        ActionList=[ActionList(1:end-1);{ActionName};ActionList(end)]; % the selected function is appended in the menu, before the last item 'more...'
2368         ActionPathList=[ActionPathList; PathName];
2369    end
2370   
2371    % record the file extension and extend the path list if it is a new extension
2372    ActionExtList=get(handles.ActionExt,'String');
2373    ActionExtIndex=find(strcmp(ActionExt,ActionExtList), 1);
2374    if isempty(ActionExtIndex)
2375        set(handles.ActionExt,'String',[ActionExtList;{ActionExt}])
2376    end
2377
2378    % remove old Action options in the menu (keeping a menu length <nb_builtin_ACTION+5)
2379    if length(ActionList)>NbBuiltinAction+5; % nb_builtin_ACTION=nbre of functions always remaining in the initial menu
2380        nbremove=length(ActionList)-NbBuiltinAction-5;
2381        ActionList(NbBuiltinAction+1:end-5)=[];
2382        ActionPathList(NbBuiltinAction+1:end-4,:)=[];
2383        ActionIndex=ActionIndex-nbremove;
2384    end
2385   
2386    % record action menu, choice and path
2387    set(handles.ActionName,'Value',ActionIndex)
2388    set(handles.ActionName,'String',ActionList)
2389       set(handles.ActionName,'UserData',ActionPathList);
2390    set(handles.ActionExt,'Value',ActionExtIndex)
2391       
2392    %record the user defined menu additions in personal file profil_perso
2393    dir_perso=prefdir;
2394    profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
2395    if NbBuiltinAction+1<=numel(ActionList)-1
2396        ActionListUser=ActionList(NbBuiltinAction+1:numel(ActionList)-1);
2397        ActionPathListUser=ActionPathList(NbBuiltinAction+1:numel(ActionList)-1);
2398        ActionExtListUser={};
2399        if numel(ActionExtList)>2
2400            ActionExtListUser=ActionExtList(3:end);
2401        end
2402        if exist(profil_perso,'file')
2403            save(profil_perso,'ActionListUser','ActionPathListUser','ActionExtListUser','-append')
2404        else
2405            save(profil_perso,'ActionListUser','ActionPathListUser','ActionExtListUser','-V6')
2406        end
2407    end
2408end
2409
2410%% check the current ActionPath to the selected function
2411ActionPath=ActionPathList{ActionIndex}; % current recorded path
2412set(handles.ActionPath,'String',ActionPath); % show the path to the senlected function
2413
2414%% reinitialise the waitbar
2415update_waitbar(handles.Waitbar,0)
2416
2417%% Put the first line of the selected Action fct as tooltip help
2418try
2419    [fid,errormsg] =fopen([ActionName '.m']);
2420    InputText=textscan(fid,'%s',1,'delimiter','\n');
2421    fclose(fid);
2422    set(handles.ActionName,'ToolTipString',InputText{1}{1})% put the first line of the selected function as tooltip help
2423end
2424set(handles.ActionName,'BackgroundColor',[1 1 1])
2425set(handles.ActionInput,'BackgroundColor',[1 0 1])% set ActionInput button to magenta color to indicate that input refr
2426
2427
2428% --- Executes on button press in ActionInput.
2429function ActionInput_Callback(hObject, eventdata, handles)
2430
2431set(handles.ActionInput,'BackgroundColor',[1 1 0])
2432SeriesData=get(handles.series,'UserData'); % info on the input file series
2433
2434%% create the function handle for Action
2435ActionPath=get(handles.ActionPath,'String');
2436ActionList=get(handles.ActionName,'String');
2437ActionName= ActionList{get(handles.ActionName,'Value')}; % selected function name
2438if ~exist(ActionPath,'dir')
2439    ActionName_Callback(handles.ActionName, ActionPath, handles)% update the function
2440    return
2441end
2442current_dir=pwd; % current working dir
2443cd(ActionPath)
2444h_fun=str2func(ActionName);
2445cd(current_dir)
2446
2447%% Activate the Action fct to adapt the configuration of the GUI series and bring specific parameters in SeriesData
2448Param=read_GUI_series(handles); % read the parameters from the GUI series
2449Param.Action.RUN=0;
2450Param.SeriesData=SeriesData;
2451ParamOut=h_fun(Param); % run the selected Action function to get the relevant input
2452
2453
2454%% Visibility of VelType and VelType_1 menus asked by ActionName
2455VelTypeRequest=1; % VelType requested by default
2456VelTypeRequest_1=1; % VelType requested by default
2457if isfield(ParamOut,'VelType')
2458    VelTypeRequest=ismember(ParamOut.VelType,{'on','one','two'});
2459    VelTypeRequest_1=strcmp( ParamOut.VelType,'two');
2460end
2461FieldNameRequest=0;  %hidden by default
2462FieldNameRequest_1=0;  %hidden by default
2463if isfield(ParamOut,'FieldName')
2464    FieldNameRequest=ismember(ParamOut.FieldName,{'on','one','two'});
2465    FieldNameRequest_1=strcmp( ParamOut.FieldName,'two');
2466end
2467
2468%% Detect the types of input files and set menus and default options in 'VelType'
2469iview_civ=find(strcmp('civx',SeriesData.FileType)|strcmp('civdata',SeriesData.FileType));
2470iview_netcdf=find(strcmp('netcdf',SeriesData.FileType)|strcmp('civx',SeriesData.FileType)|strcmp('civdata',SeriesData.FileType)); % all nc files, icluding civ
2471FieldList=get(handles.FieldName,'String'); % previous list as default
2472if ~iscell(FieldList),FieldList={FieldList};end
2473FieldList_1=get(handles.FieldName_1,'String'); % previous list as default
2474if ~iscell(FieldList_1),FieldList_1={FieldList_1};end
2475CheckList_1=1; % indicate whether FieldName_1 has been updated
2476handles_coord=[handles.Coord_x handles.Coord_y handles.Coord_z handles.Coord_x_title handles.Coord_y_title handles.Coord_z_title];
2477if VelTypeRequest && numel(iview_civ)>=1
2478    menu=set_veltype_display(SeriesData.FileInfo{iview_civ(1)}.CivStage,SeriesData.FileType{iview_civ(1)});
2479    set(handles.VelType,'Value',1)% set first choice by default
2480    set(handles.VelType,'String',[{'*'};menu])
2481    set(handles.VelType,'Visible','on')
2482    set(handles.VelType_title,'Visible','on')
2483    FieldList=set_field_list('U','V'); % standard menu for civx data
2484    if max(get(handles.FieldName,'Value'))>numel(FieldList)
2485        set(handles.FieldName,'Value',1); % velocity vector choice by default
2486    end
2487    if  VelTypeRequest_1 && numel(iview_civ)>=2
2488        menu=set_veltype_display(SeriesData.FileInfo{iview_civ(2)}.CivStage,SeriesData.FileType{iview_civ(2)});
2489        set(handles.VelType_1,'Value',1)% set first choice by default
2490        set(handles.VelType_1,'String',[{'*'};menu])
2491        set(handles.VelType_1,'Visible','on')
2492        set(handles.VelType_title_1,'Visible','on')
2493        FieldList_1=[set_field_list('U','V');{'C'};{'add_field...'}]; % standard menu for civx data
2494        CheckList_1=1;
2495        set(handles.FieldName_1,'Value',1); % velocity vector choice by default
2496    else
2497        set(handles.VelType_1,'Visible','off')
2498        set(handles.VelType_title_1,'Visible','off')
2499    end
2500else
2501    set(handles.VelType,'Visible','off')
2502    set(handles.VelType_title,'Visible','off')
2503end
2504
2505%% Detect the types of input files and set menus and default options in 'FieldName'
2506if (FieldNameRequest || VelTypeRequest) && numel(iview_netcdf)>=1
2507    set(handles.InputFields,'Visible','on')% set the frame InputFields visible
2508    if FieldNameRequest && isfield(SeriesData.FileInfo{iview_netcdf(1)},'ListVarName')
2509        set(handles.FieldName,'Visible','on')
2510        set(handles.Field_text,'Visible','on')
2511        ListVarName=SeriesData.FileInfo{iview_netcdf(1)}.ListVarName;
2512        ind_var=get(handles.FieldName,'Value'); % indices of previously selected variables
2513        for ilist=1:numel(ind_var)
2514            if isempty(find(strcmp(FieldList{ind_var(ilist)},ListVarName)))
2515                FieldList={}; % previous choice not consistent with new input field
2516                set(handles.FieldName,'Value',1)
2517                break
2518            end
2519        end
2520        if ~isempty(FieldList)
2521            if isempty(find(strcmp(get(handles.Coord_x,'String'),ListVarName)))||...
2522                    isempty(find(strcmp(get(handles.Coord_y,'String'),ListVarName)))
2523                FieldList={};
2524                set(handles.Coord_x,'String','')
2525                set(handles.Coord_y,'String','')
2526            end
2527            Coord_z=get(handles.Coord_z,'String');
2528            if ~isempty(Coord_z) && isempty(find(strcmp(Coord_z,ListVarName)))
2529                FieldList={};
2530                set(handles.Coord_z,'String','')
2531            end
2532        end
2533    else
2534        set(handles.FieldName,'Visible','off')
2535        set(handles.Field_text,'Visible','off')
2536    end
2537   
2538    set(handles_coord,'Visible','on')
2539    if isempty(find(strcmp('add_field...',FieldList)))
2540        FieldList=[FieldList;{'add_field...'}];%add 'add_field...' to the menu FieldName if it is not already
2541    end
2542    if FieldNameRequest_1 && numel(iview_netcdf)>=2
2543        set(handles.FieldName_1,'Visible','on')
2544        if CheckList_1==0        % not civ input made
2545            ListVarName=SeriesData.FileInfo{iview_netcdf(2)}.ListVarName;
2546            ind_var=get(handles.FieldName,'Value'); % indices of previously selected variables
2547            for ilist=1:numel(ind_var)
2548                if isempty(find(strcmp(FieldList{ind_var(ilist)},ListVarName)))
2549                    FieldList_1={}; % previous choice not consistent with new input field
2550                    set(handles.FieldName_1,'Value',1)
2551                    break
2552                end
2553            end
2554            warn_coord=0;
2555            if isempty(find(strcmp(get(handles.Coord_x,'String'),ListVarName)))||...
2556                    isempty(find(strcmp(get(handles.Coord_y,'String'),ListVarName)))
2557                warn_coord=1;
2558            end
2559            if ~isempty(Coord_z) && isempty(find(strcmp(Coord_z,ListVarName)))
2560                FieldList_1={};
2561                warn_coord=1;
2562            end
2563            if warn_coord
2564                msgbox_uvmat('WARNING','coordinate names do not exist in the second netcdf input file')
2565            end
2566           
2567            set(handles.FieldName_1,'Visible','on')
2568            set(handles.FieldName_1,'Value',1)
2569            set(handles.FieldName_1,'String',FieldList_1)
2570        end
2571    else
2572        set(handles.FieldName_1,'Visible','off')
2573    end
2574    if isempty(FieldList)
2575        set(handles.Field_text,'Visible','off')
2576        set(handles.FieldName,'Visible','off')
2577    else
2578        set(handles.Field_text,'Visible','on')
2579        set(handles.FieldName,'Visible','on')
2580        set(handles.FieldName,'String',FieldList)
2581    end
2582else
2583    set(handles.InputFields,'Visible','off')
2584end
2585
2586%% Introduce visibility of file overwrite option
2587if isfield(ParamOut,'CheckOverwriteVisible')&& strcmp(ParamOut.CheckOverwriteVisible,'on')
2588    set(handles.CheckOverwrite,'Visible','on')
2589else
2590    set(handles.CheckOverwrite,'Visible','off')
2591end
2592
2593%% Check whether alphabetical sorting of input Subdir is allowed by the Action fct  (for multiples series entries)
2594if isfield(ParamOut,'AllowInputSort')&&isequal(ParamOut.AllowInputSort,'on')&& size(Param.InputTable,1)>1
2595    [tild,iview]=sort(Param.InputTable(:,2)); % subdirectories sorted in alphabetical order
2596    set(handles.InputTable,'Data',Param.InputTable(iview,:));
2597    MinIndex_i=get(handles.MinIndex_i,'Data');
2598    MinIndex_j=get(handles.MinIndex_j,'Data');
2599    MaxIndex_i=get(handles.MaxIndex_i,'Data');
2600    MaxIndex_j=get(handles.MaxIndex_j,'Data');
2601    set(handles.MinIndex_i,'Data',MinIndex_i(iview,:));
2602    set(handles.MinIndex_j,'Data',MinIndex_j(iview,:));
2603    set(handles.MaxIndex_i,'Data',MaxIndex_i(iview,:));
2604    set(handles.MaxIndex_j,'Data',MaxIndex_j(iview,:));
2605    TimeTable=get(handles.TimeTable,'Data');
2606    if size(TimeTable,1)<size(Param.InputTable,1)%if the time table is not complete, copy the missing lines from the previous ones
2607        for iline=size(TimeTable,1)+1:size(Param.InputTable,1)
2608            TimeTable(iline,:)=TimeTable(iline-1,:);
2609        end
2610    end
2611    set(handles.TimeTable,'Data',TimeTable(iview,:));% sort the time tables
2612    PairString=get(handles.PairString,'Data');
2613    set(handles.PairString,'Data',PairString(iview,:));
2614end
2615
2616%% Impose the whole input file index range if requested
2617if isfield(ParamOut,'WholeIndexRange')&&isequal(ParamOut.WholeIndexRange,'on')
2618    MinIndex_i=get(handles.MinIndex_i,'Data');
2619    MinIndex_j=get(handles.MinIndex_j,'Data');
2620    MaxIndex_i=get(handles.MaxIndex_i,'Data');
2621    MaxIndex_j=get(handles.MaxIndex_j,'Data');
2622    set(handles.num_first_i,'String',num2str(MinIndex_i(1)))% set first as the min index (for the first line)
2623    set(handles.num_last_i,'String',num2str(MaxIndex_i(1)))% set last as the max index (for the first line)
2624    set(handles.num_incr_i,'String','1')
2625    set(handles.num_first_j,'String',num2str(MinIndex_j(1)))% set first as the min index (for the first line)
2626    set(handles.num_last_j,'String',num2str(MaxIndex_j(1)))% set last as the max index (for the first line)
2627    set(handles.num_incr_j,'String','1')
2628else  % check index ranges
2629    first_i=1;last_i=1;first_j=1;last_j=1;
2630    if isfield(Param.IndexRange,'first_i')
2631        first_i=Param.IndexRange.first_i;
2632        last_i=Param.IndexRange.last_i;
2633    end
2634    if isfield(Param.IndexRange,'first_j')
2635        first_j=Param.IndexRange.first_j;
2636        last_j=Param.IndexRange.last_j;
2637    end
2638    if last_i < first_i || last_j < first_j , msgbox_uvmat('ERROR','last field number must be larger than the first one'),...
2639            set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
2640end
2641
2642%% enable or desable j index visibility
2643status_j='on'; % default
2644if isempty(find(~cellfun(@isempty,SeriesData.j1_series), 1)); % case of empty j indices
2645    status_j='off'; % no j index needed
2646elseif strcmp(get(handles.PairString,'Visible'),'on')
2647    check_burst=cellfun(@isempty,regexp(get(handles.PairString,'Data'),'^j')); % =0 for burst case, 1 otherwise
2648    if isempty(find(check_burst, 1))% if all pair string begins by j (burst)
2649        status_j='off'; % no j index needed for bust case
2650    end
2651end
2652enable_j(handles,status_j) % no j index needed
2653if isfield(ParamOut,'j_index_1')&& isfield(ParamOut,'j_index_2')%strcmp(ParamOut.Desable_j_index,'on')
2654    %status_j='off';
2655    set(handles.num_first_j,'String',num2str(ParamOut.j_index_1))
2656    set(handles.num_last_j,'String',num2str(ParamOut.j_index_2))
2657    set(handles.num_first_j,'enable','off')
2658    set(handles.num_last_j,'enable','off')
2659    set(handles.num_incr_j,'visible','off')
2660else
2661    set(handles.num_first_j,'enable','on')
2662    set(handles.num_last_j,'enable','on')
2663    set(handles.num_incr_j,'visible',status_j)
2664end
2665
2666%% NbSlice visibility
2667if isfield(ParamOut,'NbSlice') && (strcmp(ParamOut.NbSlice,'on')||isnumeric(ParamOut.NbSlice))
2668    set(handles.num_NbSlice,'Visible','on')
2669    set(handles.NbSlice_title,'Visible','on')
2670else
2671    set(handles.num_NbSlice,'Visible','off')
2672    set(handles.NbSlice_title,'Visible','off')
2673end
2674if isfield(ParamOut,'NbSlice') && isnumeric(ParamOut.NbSlice)
2675    set(handles.num_NbSlice,'String',num2str(ParamOut.NbSlice))
2676    set(handles.num_NbSlice,'Enable','off'); % NbSlice set by the activation of the Action function
2677else
2678    set(handles.num_NbSlice,'Enable','on'); % NbSlice can be modified on the GUI series
2679end
2680
2681%% Visibility of FieldTransform menu
2682FieldTransformVisible='off';  %hidden by default
2683if isfield(ParamOut,'FieldTransform')
2684    if ~strcmp(ParamOut.FieldTransform,'off')
2685    FieldTransformVisible='on'; 
2686    end
2687    if iscell(ParamOut.FieldTransform)
2688        SeriesData.TransformList=ParamOut.FieldTransform;
2689    end
2690    TransformName_Callback([],[], handles)
2691end
2692set(handles.FieldTransform,'Visible',FieldTransformVisible)
2693if isfield(ParamOut,'TransformPath')% record the path of transform function requested for compilation
2694    set(handles.TransformPath,'UserData',ParamOut.TransformPath)
2695else
2696    set(handles.TransformPath,'UserData',[])
2697end
2698
2699%% Visibility of projection object
2700ProjObjectVisible='off';  %hidden by default
2701if isfield(ParamOut,'ProjObject')
2702    ProjObjectVisible=ParamOut.ProjObject;
2703end
2704set(handles.CheckObject,'Visible',ProjObjectVisible)
2705if ~get(handles.CheckObject,'Value')
2706    ProjObjectVisible='off';
2707end
2708set(handles.ProjObjectName,'Visible',ProjObjectVisible)
2709set(handles.DeleteObject,'Visible',ProjObjectVisible)
2710set(handles.ViewObject,'Visible',ProjObjectVisible)
2711set(handles.EditObject,'Visible',ProjObjectVisible)
2712
2713%% Visibility of mask input
2714MaskVisible='off';  %hidden by default
2715if isfield(ParamOut,'Mask')
2716    MaskVisible=ParamOut.Mask;
2717end
2718set(handles.CheckMask,'Visible',MaskVisible);
2719%% Setting of expected iteration time
2720if isfield(ParamOut,'CPUTime')
2721    set(handles.num_CPUTime,'String',num2str(ParamOut.CPUTime));
2722end
2723
2724%% definition of the path for the output files
2725InputTable=get(handles.InputTable,'Data');
2726[OutputPath,Device,DeviceExt]=fileparts(InputTable{1,1});
2727[OutputPath,Experiment,ExperimentExt]=fileparts(OutputPath);
2728set(handles.Device,'String',[Device DeviceExt])
2729set(handles.Device,'Visible','on')
2730set(handles.Device_title,'Visible','on')
2731set(handles.Experiment,'String',[Experiment ExperimentExt])
2732set(handles.Experiment,'Visible','on')
2733set(handles.Experiment_title,'Visible','on')
2734set(handles.Experiment_title,'Visible','on')
2735set(handles.OutputPath,'Visible','on')
2736set(handles.OutputPathBrowse,'Visible','on')
2737   
2738%% definition of the subdirectory containing the output files
2739
2740if  ~(isfield(SeriesData,'ActionName') && strcmp(ActionName,SeriesData.ActionName))
2741    OutputDirExt='.series'; % default
2742    if isfield(ParamOut,'OutputDirExt')&&~isempty(ParamOut.OutputDirExt)
2743        OutputDirExt=ParamOut.OutputDirExt;
2744    end
2745    set(handles.OutputDirExt,'String',OutputDirExt)
2746end
2747OutputDirVisible='off';
2748OutputSubDirMode='auto'; % default
2749SubDirOut='';
2750if isfield(ParamOut,'OutputSubDirMode')
2751    OutputSubDirMode=ParamOut.OutputSubDirMode;
2752end
2753switch OutputSubDirMode
2754    case 'auto' % default
2755        OutputDirVisible='on';
2756        SubDir=InputTable(1:end,2); % set of subdirectories
2757        SubDirOut=SubDir{1};
2758        if numel(SubDir)>1
2759            for ilist=2:numel(SubDir)
2760                SubDirOut=[SubDirOut '-' regexprep(SubDir{ilist},'^/','')];
2761            end
2762        end
2763    case 'one'
2764        OutputDirVisible='on';
2765        SubDirOut=InputTable{1,2}; % use the first subdir name (+OutputDirExt) as output  subdirectory
2766    case 'two'
2767        OutputDirVisible='on';   
2768        SubDir=InputTable(1:2,2); % set of subdirectories
2769        SubDirOut=SubDir{1};
2770        if numel(SubDir)>1
2771                SubDirOut=[SubDirOut '-' regexprep(SubDir{2},'^/','')];
2772        end
2773    case 'last'
2774        OutputDirVisible='on';
2775        SubDirOut=InputTable{end,2}; % use the last subdir name (+OutputDirExt) as output  subdirectory
2776end
2777set(handles.OutputSubDir,'String',SubDirOut)
2778set(handles.OutputSubDir,'BackgroundColor',[1 1 1])% set edit box to white color to indicate refreshment
2779set(handles.OutputDirExt,'Visible',OutputDirVisible)
2780set(handles.OutputSubDir,'Visible',OutputDirVisible)
2781% set(handles.OutputDir_title,'Visible',OutputDirVisible)
2782SeriesData.ActionName=ActionName; % record ActionName for next use
2783
2784
2785%% visibility of the run mode (local or background or cluster)
2786if strcmp(OutputSubDirMode,'none')
2787    RunModeVisible='off'; % only local mode available if no output file is produced
2788else
2789    RunModeVisible='on';
2790end
2791set(handles.RunMode,'Visible',RunModeVisible)
2792set(handles.ActionExt,'Visible',RunModeVisible)
2793set(handles.RunMode_title,'Visible',RunModeVisible)
2794set(handles.ActionExt_title,'Visible',RunModeVisible)
2795
2796
2797%% Expected nbre of output files
2798if isfield(ParamOut,'OutputFileMode')
2799    StatusData.OutputFileMode=ParamOut.OutputFileMode;
2800    set(handles.status,'UserData',StatusData)
2801end
2802
2803%% definition of an additional parameter set, determined by an ancillary GUI
2804if isfield(ParamOut,'ActionInput')
2805%     set(handles.ActionInput,'Visible','on')
2806    ParamOut.ActionInput.Program=ActionName; % record the program in ActionInput
2807    SeriesData.ActionInput=ParamOut.ActionInput;
2808else
2809%     set(handles.ActionInput,'Visible','off')
2810    if isfield(SeriesData,'ActionInput')
2811        SeriesData=rmfield(SeriesData,'ActionInput');
2812    end
2813end
2814set(handles.series,'UserData',SeriesData)
2815set(handles.ActionInput,'BackgroundColor',[1 0 0])
2816
2817
2818%------------------------------------------------------------------------
2819% --- Executes on button press in RefreshField.
2820function RefreshField_Callback(hObject, eventdata, handles)
2821%------------------------------------------------------------------------
2822set(handles.FieldName,'String',{'add_field...'});
2823set(handles.FieldName,'Value',1);
2824FieldName_Callback(hObject, eventdata, handles)
2825
2826
2827%------------------------------------------------------------------------
2828% --- Executes on selection change in FieldName.
2829function FieldName_Callback(hObject, eventdata, handles)
2830%------------------------------------------------------------------------
2831FieldListInit=get(handles.FieldName,'String');
2832field_index=get(handles.FieldName,'Value');
2833field=FieldListInit{field_index(1)};
2834if isequal(field,'add_field...')
2835    FieldListInit(field_index(1))=[];
2836    SeriesData=get(handles.series,'UserData');
2837    % input line for which the field choice is relevant
2838    iview=find(ismember(SeriesData.FileType,{'netcdf','civx','civdata'})); % all nc files, icluding civ
2839    hget_field=findobj(allchild(0),'name','get_field');
2840    if ~isempty(hget_field)
2841        delete(hget_field)%delete opened versions of get_field
2842    end
2843    Param=read_GUI(handles.series);
2844    InputTable=Param.InputTable(iview,:);
2845    % check the existence of the first file in the series
2846    first_j=[];last_j=[];MinIndex_j=1;MaxIndex_j=1; % default setting for index j
2847    if isfield(Param.IndexRange,'first_j') % if index j is used     
2848        first_j=Param.IndexRange.first_j;
2849        last_j=Param.IndexRange.last_j;
2850        MinIndex_j=Param.IndexRange.MinIndex_j(iview);
2851        MaxIndex_j=Param.IndexRange.MaxIndex_j(iview);
2852    end
2853    PairString='';
2854    if isfield(Param.IndexRange,'PairString'); PairString=Param.IndexRange.PairString{iview}; end
2855    [i1,i2,j1,j2] = get_file_index(Param.IndexRange.first_i,first_j,PairString);
2856    LineIndex=iview(1);
2857    if numel(iview)>1     
2858        answer=msgbox_uvmat('INPUT_TXT',['select the line of the input table:' num2str(iview)] ,num2str(iview(1)));
2859        LineIndex=str2num(answer);
2860    end
2861    FirstFileName=fullfile_uvmat(InputTable{LineIndex,1},InputTable{LineIndex,2},InputTable{LineIndex,3},...
2862        InputTable{LineIndex,5},InputTable{LineIndex,4},i1,i2,j1,j2);
2863    if exist(FirstFileName,'file') || ~isempty(regexp(InputTable{LineIndex,1},'^http'))
2864        ParamIn.Title='get_field: pick input variables and coordinates for series processing';
2865        ParamIn.SeriesInput=1;
2866        GetFieldData=get_field(FirstFileName,ParamIn);
2867        FieldList={};
2868        if isfield(GetFieldData,'FieldOption')% if a field has been selected
2869        switch GetFieldData.FieldOption
2870            case 'vectors'
2871                UName=GetFieldData.PanelVectors.vector_x;
2872                VName=GetFieldData.PanelVectors.vector_y;
2873                YName={GetFieldData.Coordinates.Coord_y};
2874                FieldList={['vec(' UName ',' VName ')'];...
2875                    ['norm(' UName ',' VName ')'];...
2876                    UName;VName};
2877                set(handles.VelType,'Visible','off')
2878            case {'scalar'}
2879                FieldList=GetFieldData.PanelScalar.scalar;
2880                YName={GetFieldData.Coordinates.Coord_y};
2881                if ischar(FieldList)
2882                    FieldList={FieldList};
2883                end
2884                set(handles.VelType,'Visible','off')
2885            case 'civdata...'
2886                FieldList=[set_field_list('U','V') ;{'C'}];
2887                set(handles.FieldName,'Value',1) % set menu to 'velocity
2888                XName='X';
2889                YName='y';
2890                set(handles.VelType,'Visible','on')
2891        end
2892        set(handles.FieldName,'Value',1)
2893        set(handles.FieldName,'String',[FieldListInit; FieldList; {'add_field...'}]);
2894        if ~strcmp(GetFieldData.FieldOption,'civdata...')
2895           if ~isempty(regexp(FieldList{1},'^vec'))
2896                set(handles.FieldName,'Value',1)
2897           else
2898                set(handles.FieldName,'Value',1:numel(FieldList))%select all input fields by default
2899           end
2900            XName=GetFieldData.Coordinates.Coord_x;
2901            YName=GetFieldData.Coordinates.Coord_y;
2902            TimeNameStr=GetFieldData.Time.SwitchVarIndexTime;
2903            % get the time info                     
2904            TimeTable=get(handles.TimeTable,'Data');
2905            switch TimeNameStr
2906                case 'file index'
2907                    TimeName='';
2908                case 'attribute'
2909                    TimeName=['att:' GetFieldData.Time.TimeName];
2910                    % update the time table
2911                    TimeTable{LineIndex,2}=get_time(Param.IndexRange.MinIndex_i(LineIndex),MinIndex_j,PairString,InputTable,SeriesData.FileInfo{LineIndex},GetFieldData.Time.TimeName);  % Min time     
2912                    TimeTable{LineIndex,3}=get_time(Param.IndexRange.first_i,first_j,PairString,InputTable,SeriesData.FileInfo{LineIndex},GetFieldData.Time.TimeName);  % first time             
2913                    TimeTable{LineIndex,4}=get_time(Param.IndexRange.last_i,last_j,PairString,InputTable,SeriesData.FileInfo{LineIndex},GetFieldData.Time.TimeName);  % last time                     
2914                    TimeTable{LineIndex,5}=get_time(Param.IndexRange.MaxIndex_i(LineIndex),MaxIndex_j,PairString,InputTable,SeriesData.FileInfo{LineIndex},GetFieldData.Time.TimeName);  % Max time
2915                case 'variable'
2916                    set(handles.TimeName,'String',['var:' GetFieldData.Time.TimeName])
2917                    set(handles.NomType,'String','*')
2918                    set(handles.RootFile,'String',[get(handles.RootFile,'String') get(handles.FileIndex,'String')])% A VERIFIER !!!!!!
2919                    set(handles.FileIndex,'String','')
2920                    ParamIn.TimeVarName=GetFieldData.Time.TimeName;
2921                case 'matrix_index'
2922                    TimeName=['dim:' GetFieldData.Time.TimeName];
2923                    set(handles.NomType,'String','*')
2924                    set(handles.RootFile,'String',[get(handles.RootFile,'String') get(handles.FileIndex,'String')])
2925                    set(handles.FileIndex,'String','')
2926                    ParamIn.TimeDimName=GetFieldData.Time.TimeName;
2927            end
2928            TimeTable{LineIndex,1}=TimeName;
2929            set(handles.TimeTable,'Data',TimeTable);
2930        end
2931        set(handles.Coord_x,'String',XName)
2932        set(handles.Coord_y,'String',YName)
2933        set(handles.Coord_x,'Visible','on')
2934        set(handles.Coord_y,'Visible','on')
2935        end
2936    else
2937        msgbox_uvmat('ERROR',[FirstFileName ' does not exist'])
2938    end
2939end
2940
2941
2942function [TimeValue,DtValue]=get_time(ref_i,ref_j,PairString,InputTable,FileInfo,TimeName,DtName)
2943[i1,i2,j1,j2] = get_file_index(ref_i,ref_j,PairString);
2944FileName=fullfile_uvmat(InputTable{1},InputTable{2},InputTable{3},InputTable{5},InputTable{4},i1,i2,j1,j2);
2945Data=nc2struct(FileName,[]);
2946TimeValue=[];
2947DtValue=[];
2948if isequal(FileInfo.FileType,'civdata')
2949    if ismember(TimeName,{'civ1','filter1'})
2950        if isfield(Data,'Civ1_Time')
2951        TimeValue=Data.Civ1_Time;
2952        end
2953        if isfield(Data,'Civ1_Dt')
2954        DtValue=Data.Civ1_Dt;
2955        end
2956    else
2957        if isfield(Data,'Civ2_Time')
2958        TimeValue=Data.Civ2_Time;
2959        end
2960        if isfield(Data,'Civ2_Dt')
2961        DtValue=Data.Civ2_Dt;
2962        end
2963    end
2964else
2965    if ~isempty(TimeName)&& isfield(Data,TimeName)
2966        TimeValue=Data.(TimeName);
2967    end
2968    if exist('DtName','var') && isfield(Data,DtName)
2969        DtValue=Data.(DtName);
2970    end
2971end
2972
2973%------------------------------------------------------------------------
2974% --- Executes on selection change in FieldName_1.
2975function FieldName_1_Callback(hObject, eventdata, handles)
2976%------------------------------------------------------------------------
2977field_str=get(handles.FieldName_1,'String');
2978field_index=get(handles.FieldName_1,'Value');
2979field=field_str{field_index(1)};
2980if isequal(field,'add_field...')
2981    hget_field=findobj(allchild(0),'name','get_field');
2982    if ~isempty(hget_field)
2983        delete(hget_field)%delete opened versions of get_field
2984    end
2985    Param=read_GUI(handles.series);
2986    Param.InputTable=Param.InputTable(1,:);
2987    % check the existence of the first file in the series
2988    first_j=[];
2989    if isfield(Param.IndexRange,'first_j'); first_j=Param.IndexRange.first_j; end
2990    if isfield(Param.IndexRange,'last_j'); last_j=Param.IndexRange.last_j; end
2991    PairString='';
2992    if isfield(Param.IndexRange,'PairString'); PairString=Param.IndexRange.PairString; end
2993    [i1,i2,j1,j2] = get_file_index(Param.IndexRange.first_i,first_j,PairString);
2994    FirstFileName=fullfile_uvmat(Param.InputTable{1,1},Param.InputTable{1,2},Param.InputTable{1,3},...
2995        Param.InputTable{1,5},Param.InputTable{1,4},i1,i2,j1,j2);
2996    if exist(FirstFileName,'file')
2997        ParamIn.SeriesInput=1;
2998        GetFieldData=get_field(FirstFileName,ParamIn);
2999        FieldList={};
3000        switch GetFieldData.FieldOption
3001            case 'vectors'
3002                UName=GetFieldData.PanelVectors.vector_x;
3003                VName=GetFieldData.PanelVectors.vector_y;
3004                FieldList={['vec(' UName ',' VName ')'];...
3005                    ['norm(' UName ',' VName ')'];...
3006                    UName;VName};
3007            case {'scalar','pick variables'}
3008                FieldList=GetFieldData.PanelScalar.scalar;
3009                if ischar(FieldList)
3010                    FieldList={FieldList};
3011                end
3012            case '1D plot'
3013
3014            case 'civdata...'
3015                FieldList=set_field_list('U','V','C');
3016                set(handles.FieldName,'Value',2) % set menu to 'velocity
3017        end
3018        if ~strcmp(GetFieldData.FieldOption,'civdata...')
3019            TimeNameStr=GetFieldData.Time.SwitchVarIndexTime;
3020            switch TimeNameStr
3021                case 'file index'
3022                    set(handles.TimeName,'String','');
3023                case 'attribute'
3024                    set(handles.TimeName,'String',['att:' GetFieldData.Time.TimeName]);
3025                case 'variable'
3026                    set(handles.TimeName,'String',['var:' GetFieldData.Time.TimeName])
3027                    set(handles.NomType,'String','*')
3028                    set(handles.RootFile,'String',[get(handles.RootFile,'String') get(handles.FileIndex,'String')])% A VERIFIER !!!!!!
3029                    set(handles.FileIndex,'String','')
3030                    ParamIn.TimeVarName=GetFieldData.Time.TimeName;
3031                case 'matrix_index'
3032                    set(handles.TimeName,'String',['dim:' GetFieldData.Time.TimeName]);
3033                    set(handles.NomType,'String','*')
3034                    set(handles.RootFile,'String',[get(handles.RootFile,'String') get(handles.FileIndex,'String')])
3035                    set(handles.FileIndex,'String','')
3036                    ParamIn.TimeDimName=GetFieldData.Time.TimeName;
3037            end
3038        end
3039        set(handles.FieldName_1,'Value',1)
3040        set(handles.FieldName_1,'String',[FieldList; {'add_field...'}]);
3041    end
3042end   
3043
3044
3045%%%%%%%%%%%%%
3046function [ind_remove]=find_pairs(dirpair,ind_i,last_i)
3047indsel=ind_i;
3048indiff=diff(ind_i); % test index increment to detect multiplets (several pairs with the same index ind_i) and holes in the series
3049indiff=[1 indiff last_i-ind_i(end)+1]; % for testing gaps with the imposed bounds
3050if ~isempty(indiff)
3051    indiff2=diff(indiff);
3052    indiffp=[indiff2 1];
3053    indiffm=[1 indiff2];
3054    ind_multi_m=find((indiff==0)&(indiffm<0))-1; % indices of first members of multiplets
3055    ind_multi_p=find((indiff==0)&(indiffp>0)); % indices of last members of multiplets
3056    %for each multiplet, select the most recent file
3057    ind_remove=[];
3058    for i=1:length(ind_multi_m)
3059        ind_pairs=ind_multi_m(i):ind_multi_p(i);
3060        for imulti=1:length(ind_pairs)
3061            datepair(imulti)=datenum(dirpair(ind_pairs(imulti)).date); % dates of creation
3062        end
3063        [datenew,indsort2]=sort(datepair); % sort the multiplet by creation date
3064        ind_s=indsort2(1:end-1); %
3065        ind_remove=[ind_remove ind_pairs(ind_s)]; % remove these indices, leave the last one
3066    end
3067end
3068
3069%------------------------------------------------------------------------
3070% --- determine the list of index pairstring of processing file
3071function [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)
3072%------------------------------------------------------------------------
3073num_i1=num_i; % set of first image numbers by default
3074num_i2=num_i;
3075num_j1=num_j;
3076num_j2=num_j;
3077num_i_out=num_i;
3078num_j_out=num_j;
3079% if isequal (NomType,'_1-2_1') || isequal (NomType,'_1-2')
3080if isequal(mode,'series(Di)')
3081    num_i1_line=num_i+ind_shift(3); % set of first image numbers
3082    num_i2_line=num_i+ind_shift(4);
3083    % adjust the first and last field number
3084        indsel=find(num_i1_line >= 1);
3085    num_i_out=num_i(indsel);
3086    num_i1_line=num_i1_line(indsel);
3087    num_i2_line=num_i2_line(indsel);
3088    num_j1=meshgrid(num_j,ones(size(num_i1_line)));
3089    num_j2=meshgrid(num_j,ones(size(num_i1_line)));
3090    [xx,num_i1]=meshgrid(num_j,num_i1_line);
3091    [xx,num_i2]=meshgrid(num_j,num_i2_line);
3092elseif isequal (mode,'series(Dj)')||isequal (mode,'bursts')
3093    if isequal(mode,'bursts') %case of bursts (png_old or png_2D)
3094        num_j1=ind_shift(1)*ones(size(num_i));
3095        num_j2=ind_shift(2)*ones(size(num_i));
3096    else
3097        num_j1_col=num_j+ind_shift(1); % set of first image numbers
3098        num_j2_col=num_j+ind_shift(2);
3099        % adjust the first field number
3100        indsel=find((num_j1_col >= 1));   
3101        num_j_out=num_j(indsel);
3102        num_j1_col=num_j1_col(indsel);
3103        num_j2_col=num_j2_col(indsel);
3104        [num_i1,num_j1]=meshgrid(num_i,num_j1_col);
3105        [num_i2,num_j2]=meshgrid(num_i,num_j2_col);
3106    end   
3107end
3108
3109%------------------------------------------------------------------------
3110% --- Executes on button press in CheckObject.
3111function CheckObject_Callback(hObject, eventdata, handles)
3112%------------------------------------------------------------------------
3113hset_object=findobj(allchild(0),'tag','set_object'); % find the set_object interface handle
3114if get(handles.CheckObject,'Value')
3115    SeriesData=get(handles.series,'UserData');
3116    if isfield(SeriesData,'ProjObject') && ~isempty(SeriesData.ProjObject)
3117        set(handles.ViewObject,'Value',1)
3118        ViewObject_Callback(hObject, eventdata, handles)
3119    else
3120        if ishandle(hset_object)
3121            uistack(hset_object,'top')% show the GUI set_object if opened
3122        else
3123            %get the object file
3124            InputTable=get(handles.InputTable,'Data');
3125            defaultname=InputTable{1,1};
3126            if isempty(defaultname)
3127                defaultname={''};
3128            end
3129            fileinput=uigetfile_uvmat('pick a xml object file (or use uvmat to create it)',defaultname,'.xml');
3130            if isempty(fileinput)% exit if no object file is selected
3131                set(handles.CheckObject,'Value',0)
3132                return
3133            end
3134            %read the file
3135            data=xml2struct(fileinput);
3136            if ~isfield(data,'Type')
3137                msgbox_uvmat('ERROR',[fileinput ' is not an object xml file'])
3138                set(handles.CheckObject,'Value',0)
3139                return
3140            end
3141            if ~isfield(data,'ProjMode')
3142                data.ProjMode='none';
3143            end
3144            hset_object=set_object(data); % call the set_object interface
3145            set(hset_object,'Name','set_object_series')% name to distinguish from set_object used with uvmat
3146        end
3147        ProjObject=read_GUI(hset_object);
3148        set(handles.ProjObjectName,'String',ProjObject.Name); % display the object name
3149        SeriesData=get(handles.series,'UserData');
3150        SeriesData.ProjObject=ProjObject;
3151        set(handles.series,'UserData',SeriesData);
3152    end
3153    set(handles.EditObject,'Visible','on');
3154    set(handles.DeleteObject,'Visible','on');
3155    set(handles.ViewObject,'Visible','on');
3156    set(handles.ProjObjectName,'Visible','on');
3157else
3158    set(handles.EditObject,'Visible','off');
3159    set(handles.DeleteObject,'Visible','off');
3160    set(handles.ViewObject,'Visible','off');
3161    if ~ishandle(hset_object)
3162        set(handles.ViewObject,'Value',0);
3163    end
3164    set(handles.ProjObjectName,'Visible','off');
3165end
3166
3167%------------------------------------------------------------------------
3168% --- Executes on button press in ViewObject.
3169%------------------------------------------------------------------------
3170function ViewObject_Callback(hObject, eventdata, handles)
3171
3172UserData=get(handles.series,'UserData');
3173hset_object=findobj(allchild(0),'Tag','set_object');
3174if ~isempty(hset_object)
3175    delete(hset_object)% refresh set_object if already opened
3176end
3177hset_object=set_object(UserData.ProjObject);
3178set(hset_object,'Name','view_object_series')
3179
3180
3181%------------------------------------------------------------------------
3182% --- Executes on button press in EditObject.
3183function EditObject_Callback(hObject, eventdata, handles)
3184%------------------------------------------------------------------------
3185if get(handles.EditObject,'Value')
3186    set(handles.ViewObject,'Value',0)
3187    UserData=get(handles.series,'UserData');
3188    hset_object=set_object(UserData.ProjObject);
3189    set(hset_object,'Name','edit_object_series')
3190    set(get(hset_object,'Children'),'Enable','on')
3191else
3192    hset_object=findobj(allchild(0),'Tag','set_object');
3193    if ~isempty(hset_object)
3194        set(get(hset_object,'Children'),'Enable','off')
3195    end
3196end
3197
3198%------------------------------------------------------------------------
3199% --- Executes on button press in DeleteObject.
3200function DeleteObject_Callback(hObject, eventdata, handles)
3201%------------------------------------------------------------------------
3202SeriesData=get(handles.series,'UserData');
3203SeriesData.ProjObject=[];
3204set(handles.series,'UserData',SeriesData)
3205set(handles.ProjObjectName,'String','')
3206set(handles.ProjObjectName,'Visible','off')
3207set(handles.CheckObject,'Value',0)
3208set(handles.ViewObject,'Visible','off')
3209set(handles.EditObject,'Visible','off')
3210hset_object=findobj(allchild(0),'name','set_object_series');
3211if ~isempty(hset_object)
3212    delete(hset_object)
3213end
3214set(handles.DeleteObject,'Visible','off')
3215
3216%------------------------------------------------------------------------
3217% --- Executed when CheckMask is activated
3218%------------------------------------------------------------------------
3219function CheckMask_Callback(hObject, eventdata, handles)
3220
3221if get(handles.CheckMask,'Value')
3222    InputTable=get(handles.InputTable,'Data');
3223    nbview=size(InputTable,1);
3224    MaskTable=cell(nbview,1); % default
3225    ListMask=cell(nbview,1); % default
3226    MaskData=get(handles.MaskTable,'Data');
3227    MaskData(size(MaskData,1):nbview,1)=cell(size(MaskData,1):nbview,1); % complement if undefined lines
3228    for iview=1:nbview
3229        ListMask{iview,1}=num2str(iview);
3230        RootPath=InputTable{iview,1};
3231        if ~isempty(RootPath)
3232            if isempty(MaskData{iview})
3233                SubDir=InputTable{iview,2};
3234                MaskPath=fullfile(RootPath,[regexprep(SubDir,'\..*','') '.mask']); % take the root part of SubDir, before the first dot '.'
3235                if exist(MaskPath,'dir')
3236                    ListStruct=dir(MaskPath); % look for a mask file
3237                    ListCells=struct2cell(ListStruct); % transform dir struct to a cell arrray
3238                    check_dir=cell2mat(ListCells(4,:)); % =1 for directories, =0 for files
3239                    ListFiles=ListCells(1,:); % list of file and dri names
3240                    ListFiles=ListFiles(~check_dir); % list of file names (excluding dir)
3241                    mdetect=0;
3242                    if ~isempty(ListFiles)
3243                        for ifile=1:numel(ListFiles)
3244                            [tild,tild,MaskFile{ifile},i1_series,i2_series,j1_series,j2_series,MaskNomType,MaskFileType]=find_file_series(MaskPath,ListFiles{ifile},0);
3245                            if strcmp(MaskFileType,'image') && isempty(i2_series) && isempty(j2_series)
3246                                mdetect=1;
3247                                MaskName=ListFiles{ifile};
3248                            end
3249                            if ~strcmp(MaskFile{ifile},MaskFile{1})
3250                                mdetect=0; % cancel detection test in case of multiple masks, use the brower for selection
3251                                break
3252                            end
3253                        end
3254                    end
3255                    if mdetect==1
3256                        MaskName=fullfile(MaskPath,'mask_1.png');
3257                    else
3258                        MaskName=uigetfile_uvmat('select a mask file:',MaskPath,'image');
3259                    end
3260                else
3261                    MaskName=uigetfile_uvmat('select a mask file:',RootPath,'image');
3262                end
3263                MaskTable{iview,1}=MaskName ;
3264                ListMask{iview,1}=num2str(iview);
3265            end
3266        end
3267    end
3268    set(handles.MaskTable,'Data',MaskTable)
3269    set(handles.MaskTable,'Visible','on')
3270    set(handles.MaskBrowse,'Visible','on')
3271    set(handles.ListMask,'Visible','on')
3272    set(handles.ListMask,'String',ListMask)
3273    set(handles.ListMask,'Value',1)
3274else
3275    set(handles.MaskTable,'Visible','off')
3276    set(handles.MaskBrowse,'Visible','off')
3277    set(handles.ListMask,'Visible','off')
3278end
3279
3280%------------------------------------------------------------------------
3281% --- Executes on button press in MaskBrowse.
3282%------------------------------------------------------------------------
3283function MaskBrowse_Callback(hObject, eventdata, handles)
3284
3285InputTable=get(handles.InputTable,'Data');
3286iview=get(handles.ListMask,'Value');
3287RootPath=InputTable{iview,1};
3288MaskName=uigetfile_uvmat('select a mask file:',RootPath,'image');
3289if ~isempty(MaskName)
3290    MaskTable=get(handles.MaskTable,'Data');
3291    MaskTable{iview,1}=MaskName ;
3292    set(handles.MaskTable,'Data',MaskTable)
3293end
3294
3295%------------------------------------------------------------------------
3296% --- Executes when selected cell(s) is changed in MaskTable.
3297%------------------------------------------------------------------------
3298function MaskTable_CellSelectionCallback(hObject, eventdata, handles)
3299
3300if numel(eventdata.Indices)>=1
3301set(handles.ListMask,'Value',eventdata.Indices(1))
3302end
3303
3304%-------------------------------------------------------------------
3305function MenuHelp_Callback(hObject, eventdata, handles)
3306%-------------------------------------------------------------------
3307
3308
3309% path_to_uvmat=which ('uvmat'); % check the path of uvmat
3310% pathelp=fileparts(path_to_uvmat);
3311% helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html');
3312% if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package')
3313% else
3314%     addpath (fullfile(pathelp,'uvmat_doc'))
3315%     web([helpfile '#series'])
3316% end
3317
3318%-------------------------------------------------------------------
3319% --- Executes on selection change in TransformName.
3320function TransformName_Callback(hObject, eventdata, handles)
3321%----------------------------------------------------------------------
3322TransformList=get(handles.TransformName,'String');
3323TransformIndex=get(handles.TransformName,'Value');
3324TransformName=TransformList{TransformIndex};
3325TransformPathList=get(handles.TransformName,'UserData');
3326nb_builtin_transform=4;
3327if isequal(TransformName,'more...');     
3328    FileName=uigetfile_uvmat('Pick a transform function',get(handles.TransformPath,'String'),'.m');
3329    if isempty(FileName)
3330        return     %browser closed without choice
3331    end
3332    [TransformPath,TransformName,TransformExt]=fileparts(FileName); % removes extension .m
3333    if ~strcmp(TransformExt,'.m')
3334        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
3335        return
3336    end
3337     % insert the choice in the menu
3338    TransformIndex=find(strcmp(TransformName,TransformList),1); % look for the selected function in the menu Action
3339    if isempty(TransformIndex)%the input string does not exist in the menu
3340        TransformIndex= length(TransformList);
3341        TransformList=[TransformList(1:end-1);{TransformName};TransformList(end)]; % the selected function is appended in the menu, before the last item 'more...'
3342        set(handles.TransformName,'String',TransformList)
3343        TransformPathList=[TransformPathList;{TransformPath}];
3344    else% the input function already exist, we update its path (possibly new)
3345        TransformPathList{TransformIndex}=TransformPath; %
3346        set(handles.TransformName,'Value',TransformIndex)
3347    end
3348   % save the new menu in the personal file 'uvmat_perso.mat'
3349   dir_perso=prefdir; % personal Matalb directory
3350   profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
3351   if exist(profil_perso,'file')
3352       for ilist=nb_builtin_transform+1:numel(TransformPathList)
3353           TransformListUser{ilist-nb_builtin_transform}=TransformList{ilist};
3354           TransformPathListUser{ilist-nb_builtin_transform}=TransformPathList{ilist};
3355       end
3356       TransformPathListUser=TransformPathListUser';
3357       TransformListUser=TransformListUser';
3358       save (profil_perso,'TransformPathListUser','TransformListUser','-append'); % store the root name for future opening of uvmat
3359   end
3360end
3361
3362%display the current function path
3363set(handles.TransformPath,'String',TransformPathList{TransformIndex}); % show the path to the senlected function
3364set(handles.TransformName,'UserData',TransformPathList);
3365
3366%% create the function handle of the selected fct
3367if ~isempty(TransformName)
3368    if ~exist(TransformPathList{TransformIndex},'dir')
3369        msgbox_uvmat('ERROR',['The prescribed transform function path ' TransformPathList{TransformIndex} ' does not exist']);
3370        return
3371    end
3372    current_dir=pwd; % current working dir
3373    cd(TransformPathList{TransformIndex})
3374    transform_handle=str2func(TransformName);
3375    cd(current_dir)
3376    Field.Action.RUN=0;% indicate that the transform fct is called only to get input param
3377    SeriesData=get(handles.series,'UserData');
3378    ParamIn=[];
3379    if isfield(SeriesData,'TransformInput')
3380        ParamIn.TransformInput=SeriesData.TransformInput;
3381    end
3382    DataOut=feval(transform_handle,Field,ParamIn);% execute the transform fct to get the required conditions
3383    Field.Action.RUN=0; % indicate that the transform fct is called only to get input param
3384    %DataOut=feval(transform_handle,Field,[]); % execute the transform fct to get the required conditions
3385    if isfield(DataOut,'TransformInput')%  used to add transform parameters at selection of the transform fct
3386        SeriesData.TransformInput=DataOut.TransformInput;
3387        set(handles.series,'UserData',SeriesData)
3388    end
3389end
3390
3391%------------------------------------------------------------------------
3392% --- fct activated by the upper bar menu ExportConfig
3393%------------------------------------------------------------------------
3394function MenuDisplayConfig_Callback(hObject, eventdata, handles)
3395
3396global Param
3397Param=read_GUI_series(handles);
3398evalin('base','global Param')%make CurData global in the workspace
3399display('current series config :')
3400evalin('base','Param') %display CurData in the workspace
3401commandwindow; % brings the Matlab command window to the front
3402
3403%------------------------------------------------------------------------
3404% --- fct activated by the upper bar menu InportConfig: import
3405%     menu settings from an xml file (stored in /0_XML for each run)
3406%------------------------------------------------------------------------
3407function MenuImportConfig_Callback(hObject, eventdata, handles)
3408
3409%% use a browser to choose the xml file containing the processing config
3410InputTable=get(handles.InputTable,'Data');
3411oldfile=InputTable{1,1}; % current path in InputTable
3412if isempty(oldfile)
3413    % use a file name stored in prefdir
3414    dir_perso=prefdir;
3415    profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
3416    if exist(profil_perso,'file')
3417        h=load (profil_perso);
3418        if isfield(h,'RootPath') && ischar(h.RootPath)
3419            oldfile=h.RootPath;
3420        end
3421    end
3422end
3423filexml=uigetfile_uvmat('pick a xml parameter file',oldfile,'.xml'); % get the xml file containing processing parameters
3424if isempty(filexml), return, end % quit function if an xml file has not been opened
3425
3426%% fill the GUI series with the content of the xml file
3427[Param,RootTag,errormsg]=xml2struct(filexml); % read the input xml file as a Matlab structure
3428if ~isempty(errormsg)
3429    msgbox_uvmat('ERROR',errormsg);
3430    return
3431end
3432% ask to stop current Action if button RUN is in action (another process is already running)
3433if isequal(get(handles.RUN,'Value'),1)
3434    answer= msgbox_uvmat('INPUT_Y-N','stop current Action process?');
3435    if strcmp(answer,'Yes')
3436        STOP_Callback(hObject, eventdata, handles)
3437    else
3438        return
3439    end
3440end
3441Param.Action.RUN=0; % desactivate the input RUN=1
3442
3443fill_GUI(Param,handles.series)% fill the elements of the GUI series with the input parameters
3444SeriesData=get(handles.series,'UserData');
3445if isfield(Param,'InputFields')
3446    ListField=Param.InputFields.FieldName;
3447    if ischar(ListField),ListField={ListField}; end
3448    set(handles.FieldName,'String',[ListField;{'add_field...'}])
3449     set(handles.FieldName,'Value',1:numel(ListField))
3450     set(handles.FieldName,'Visible','on')
3451end       
3452if isfield(Param,'ActionInput')%  introduce  parameters specific to an Action fct, for instance PIV parameters
3453%     set(handles.ActionInput,'Visible','on')
3454%     set(handles.ActionInput,'Value',0)
3455    Param.ActionInput.ConfigSource=filexml; % record the source of config for future info
3456    SeriesData.ActionInput=Param.ActionInput;
3457end
3458if isfield(Param,'TransformInput')%  introduce  parameters specific to a transform fct
3459    SeriesData.TransformInput=Param.TransformInput;
3460end
3461if isfield(Param,'ProjObject') %introduce projection object if relevant
3462    SeriesData.ProjObject=Param.ProjObject;
3463end
3464set(handles.series,'UserData',SeriesData)
3465if isfield(Param,'CheckObject') && isequal(Param.CheckObject,1)
3466    set(handles.ProjObjectName,'String',Param.ProjObject.Name)
3467    set(handles.ViewObject,'Visible','on')
3468    set(handles.EditObject,'Visible','on')
3469    set(handles.DeleteObject,'Visible','on')
3470else     
3471    set(handles.ProjObjectName,'String','')
3472    set(handles.ProjObjectName,'Visible','off')
3473    set(handles.ViewObject,'Visible','off')
3474    set(handles.EditObject,'Visible','off')
3475    set(handles.DeleteObject,'Visible','off')     
3476end     
3477set(handles.REFRESH,'BackgroundColor',[1 0 1]); % paint REFRESH button in magenta to indicate that it should be activated
3478
3479
3480%------------------------------------------------------------------------
3481% --- Executes when the GUI series is resized.
3482%------------------------------------------------------------------------
3483function series_ResizeFcn(hObject, eventdata, handles)
3484
3485%% input table
3486set(handles.InputTable,'Unit','pixel')
3487Pos=get(handles.InputTable,'Position');
3488set(handles.InputTable,'Unit','normalized')
3489ColumnWidth=round([0.5 0.14 0.14 0.14 0.08]*(Pos(3)-52));
3490ColumnWidth=num2cell(ColumnWidth);
3491set(handles.InputTable,'ColumnWidth',ColumnWidth)
3492
3493%% MinIndex_j and MaxIndex_i
3494unit=get(handles.MinIndex_i,'Unit');
3495set(handles.MinIndex_i,'Unit','pixel')
3496Pos=get(handles.MinIndex_i,'Position');
3497set(handles.MinIndex_i,'Unit',unit)
3498set(handles.MinIndex_i,'ColumnWidth',{Pos(3)-18})
3499set(handles.MaxIndex_i,'ColumnWidth',{Pos(3)-18})
3500set(handles.MinIndex_j,'ColumnWidth',{Pos(3)-18})
3501set(handles.MaxIndex_j,'ColumnWidth',{Pos(3)-18})
3502
3503%% TimeTable
3504set(handles.TimeTable,'Unit','pixel')
3505Pos=get(handles.TimeTable,'Position');
3506set(handles.TimeTable,'Unit','normalized')
3507% ColumnWidth=get(handles.TimeTable,'ColumnWidth');
3508ColumnWidth=num2cell(floor([0.2 0.2 0.2 0.2 0.2]*(Pos(3)-20)));
3509set(handles.TimeTable,'ColumnWidth',ColumnWidth)
3510
3511
3512%% PairString
3513set(handles.PairString,'Unit','pixel')
3514Pos=get(handles.PairString,'Position');
3515set(handles.PairString,'Unit','normalized')
3516set(handles.PairString,'ColumnWidth',{Pos(3)-5})
3517
3518%% MaskTable
3519set(handles.MaskTable,'Unit','pixel')
3520Pos=get(handles.MaskTable,'Position');
3521set(handles.MaskTable,'Unit','normalized')
3522set(handles.MaskTable,'ColumnWidth',{Pos(3)-5})
3523
3524%------------------------------------------------------------------------
3525% --- Executes on button press in status.
3526%------------------------------------------------------------------------
3527function status_Callback(hObject, eventdata, handles)
3528
3529if get(handles.status,'Value')
3530    set(handles.status,'BackgroundColor',[1 1 0])
3531    drawnow
3532    Param=read_GUI(handles.series);
3533    RootPath=fullfile(Param.OutputPath,Param.Experiment,Param.Device);
3534    if ~isfield(Param,'OutputSubDir')   
3535        msgbox_uvmat('ERROR','no standard sub-directory definition for output files, use a browser to check the output')
3536        set(handles.status,'BackgroundColor',[0 1 0])
3537        return
3538    end
3539    OutputSubDir=[Param.OutputSubDir Param.OutputDirExt]; % subdirectory for output files
3540    OutputDir=fullfile(RootPath,OutputSubDir);
3541    if exist(OutputDir,'dir')
3542        uigetfile_uvmat('status_display',OutputDir)
3543    else
3544        msgbox_uvmat('ERROR','output folder not created yet: calculation did not start')
3545        set(handles.status,'BackgroundColor',[0 1 0])
3546    end
3547else
3548    %% delete current display fig if selection is off
3549    set(handles.status,'BackgroundColor',[0 1 0])
3550    hfig=findobj(allchild(0),'name','status_display');
3551    if ~isempty(hfig)
3552        delete(hfig)
3553    end
3554    return
3555end
3556
3557
3558%------------------------------------------------------------------------   
3559% launched by selecting a file on the list
3560%------------------------------------------------------------------------
3561function view_file(hObject, eventdata)
3562
3563list=get(hObject,'String');
3564index=get(hObject,'Value');
3565rootroot=get(hObject,'UserData');
3566selectname=list{index};
3567ind_dot=regexp(selectname,'\.\.\.');
3568if ~isempty(ind_dot)
3569    selectname=selectname(1:ind_dot-1);
3570end
3571FullSelectName=fullfile(rootroot,selectname);
3572if exist(FullSelectName,'dir')% a directory has been selected
3573    ListFiles=dir(FullSelectName);
3574    ListDisplay=cell(numel(ListFiles),1);
3575    for ilist=2:numel(ListDisplay)% suppress the first line '.'
3576        ListDisplay{ilist-1}=ListFiles(ilist).name;
3577    end
3578    set(hObject,'Value',1)
3579    set(hObject,'String',ListDisplay)
3580    if strcmp(selectname,'..')
3581        FullSelectName=fileparts(fileparts(FullSelectName));
3582    end
3583    set(hObject,'UserData',FullSelectName)
3584    hfig=get(hObject,'parent');
3585    htitlebox=findobj(hfig,'tag','titlebox');   
3586    set(htitlebox,'String',FullSelectName)
3587elseif exist(FullSelectName,'file')%visualise the vel field if it exists
3588    FileInfo=get_file_info(FullSelectName);   
3589    if strcmp(FileInfo.FileType,'txt')
3590        edit(FullSelectName)
3591    elseif strcmp(FileInfo.FileType,'xml')
3592        editxml(FullSelectName)
3593    else
3594        uvmat(FullSelectName)
3595    end
3596    set(gcbo,'Value',1)
3597end
3598
3599
3600%------------------------------------------------------------------------   
3601% launched by refreshing the status figure
3602%------------------------------------------------------------------------
3603function refresh_GUI(hfig)
3604
3605htitlebox=findobj(hfig,'tag','titlebox');
3606hlist=findobj(hfig,'tag','list');
3607hseries=findobj(allchild(0),'tag','series');
3608hstatus=findobj(hseries,'tag','status');
3609StatusData=get(hstatus,'UserData');
3610OutputDir=get(htitlebox,'String');
3611if ischar(OutputDir),OutputDir={OutputDir};end
3612ListFiles=dir(OutputDir{1});
3613if numel(ListFiles)<1
3614    return
3615end
3616ListFiles(1)=[]; % removes the first line ='.'
3617ListDisplay=cell(numel(ListFiles),1);
3618testrecent=0;
3619datnum=zeros(numel(ListDisplay),1);
3620for ilist=1:numel(ListDisplay)
3621    ListDisplay{ilist}=ListFiles(ilist).name;
3622      if ~ListFiles(ilist).isdir && isfield(ListFiles(ilist),'datenum')
3623            datnum(ilist)=ListFiles(ilist).datenum; % only available in recent matlab versions
3624            testrecent=1;
3625       end
3626end
3627set(hlist,'String',ListDisplay)
3628
3629%% Look at date of creation
3630ListDisplay=ListDisplay(datnum~=0);
3631datnum=datnum(datnum~=0); % keep the non zero values corresponding to existing files
3632NbOutputFile=[];
3633if isempty(datnum)
3634    if testrecent
3635        message='no civ result created yet';
3636    else
3637        message='';
3638    end
3639else
3640    [first,indfirst]=min(datnum);
3641    [last,indlast]=max(datnum);
3642    NbOutputFile_str='?';
3643    NbOutputFile=[];
3644    if isfield(StatusData,'NbOutputFile')
3645        NbOutputFile=StatusData.NbOutputFile;
3646        NbOutputFile_str=num2str(NbOutputFile);
3647    end
3648    message={[num2str(numel(datnum)) ' file(s) done over ' NbOutputFile_str] ;['oldest modification:  ' ListDisplay{indfirst} ' : ' datestr(first)];...
3649        ['latest modification:  ' ListDisplay{indlast} ' : ' datestr(last)]};
3650end
3651set(htitlebox,'String', [OutputDir{1};message])
3652
3653%% update the waitbar
3654hwaitbar=findobj(hfig,'tag','waitbar');
3655if ~isempty(NbOutputFile)
3656    BarPosition=get(hwaitbar,'Position');
3657    BarPosition(3)=0.9*numel(datnum)/NbOutputFile;
3658    set(hwaitbar,'Position',BarPosition)
3659end
3660
3661%------------------------------------------------------------------------
3662% --- Executes on selection change in ActionExt.
3663%------------------------------------------------------------------------
3664function ActionExt_Callback(hObject, eventdata, handles)
3665
3666ActionExtList=get(handles.ActionExt,'String');
3667ActionExt=ActionExtList{get(handles.ActionExt,'Value')};
3668if strcmp(ActionExt,'.py (in dev.)')
3669    set(handles.RunMode,'Value',2)
3670end
3671
3672
3673function num_NbSlice_Callback(hObject, eventdata, handles)
3674NbSlice=str2num(get(handles.num_NbSlice,'String'));
3675
3676%------------------------------------------------------------------------
3677% --- set the visibility of relevant velocity type menus:
3678function menu=set_veltype_display(Civ,FileType)
3679%------------------------------------------------------------------------
3680if ~exist('FileType','var')
3681    FileType='civx';
3682end
3683switch FileType
3684    case 'civx'
3685        menu={'civ1';'interp1';'filter1';'civ2';'interp2';'filter2'};
3686        if isequal(Civ,0)
3687            imax=0;
3688        elseif isequal(Civ,1) || isequal(Civ,2)
3689            imax=1;
3690        elseif isequal(Civ,3)
3691            imax=3;
3692        elseif isequal(Civ,4) || isequal(Civ,5)
3693            imax=4;
3694        elseif isequal(Civ,6) %patch2
3695            imax=6;
3696        end
3697    case 'civdata'
3698        menu={'civ1';'filter1';'civ2';'filter2'};
3699        if isequal(Civ,0)
3700            imax=0;
3701        elseif isequal(Civ,1) || isequal(Civ,2)
3702            imax=1;
3703        elseif isequal(Civ,3)
3704            imax=2;
3705        elseif isequal(Civ,4) || isequal(Civ,5)
3706            imax=3;
3707        else%if isequal(Civ,6) %patch2
3708            imax=4;
3709        end
3710end
3711menu=menu(1:imax);
3712
3713
3714% --- Executes on mouse motion over figure - except title and menu.
3715% function series_WindowButtonMotionFcn(hObject, eventdata, handles)
3716% set(hObject,'Pointer','arrow');
3717
3718
3719% --- Executes on button press in SetPairs.
3720function SetPairs_Callback(hObject, eventdata, handles)
3721
3722%% delete previous occurrence of 'set_pairs'
3723hfig=findobj(allchild(0),'Tag','set_pairs');
3724if ~isempty(hfig)
3725delete(hfig)
3726end
3727
3728%% create the GUI set_pairs
3729set(0,'Unit','points')
3730ScreenSize=get(0,'ScreenSize'); % get the size of the screen, to put the fig on the upper right
3731Width=220; % fig width in points (1/72 inch)
3732Height=min(0.8*ScreenSize(4),300);
3733Left=ScreenSize(3)- Width-40; % right edge close to the right, with margin=40
3734Bottom=ScreenSize(4)-Height-40; % put fig at top right
3735hfig=findobj(allchild(0),'Tag','set_slice');
3736if ~isempty(hfig),delete(hfig), end; % delete existing version of the GUI
3737hfig=figure('name','set_pairs','tag','set_pairs','MenuBar','none','NumberTitle','off','Unit','points','Position',[Left,Bottom,Width,Height]);
3738BackgroundColor=get(hfig,'Color');
3739SeriesData=get(handles.series,'UserData');
3740TimeUnit=get(handles.TimeUnit,'String');
3741PairString=get(handles.PairString,'Data');
3742ListViewLines=find(cellfun('isempty',PairString)==0); % find list of non empty pairs
3743ListViewMenu=cell(numel(ListViewLines),1);
3744%iview=get(handles.PairString,'Value');
3745iview=[];
3746for ilist=1:numel(ListViewLines)
3747    ListViewMenu{ilist}=num2str(ListViewLines(ilist));
3748end
3749if isempty(iview)
3750    ListViewValue=numel(ListViewLines); % we work by default on the pair option for the last line which requires pairs
3751    iview=ListViewLines(end);
3752else
3753    ListViewValue=find(ListViewLines==iview);
3754end
3755ref_i=str2num(get(handles.num_first_i,'String'));
3756ref_j=1; % default
3757if strcmp(get(handles.num_first_j,'String'),'Visible')
3758    ref_j=str2num(get(handles.num_first_j,'String'));
3759end
3760[ModeMenu,ModeValue]=update_mode(SeriesData.i1_series{1},SeriesData.i2_series{1},SeriesData.j2_series{1});
3761InputTable=get(handles.InputTable,'Data');
3762displ_pair=update_listpair(SeriesData.i1_series{1},SeriesData.i2_series{1},SeriesData.j1_series{1},SeriesData.j2_series{1},ModeMenu{ModeValue},...
3763                                                 SeriesData.Time{1},TimeUnit,ref_i,ref_j,SeriesData.TimeName,InputTable,SeriesData.FileInfo{1});
3764for iline=1:size(InputTable,1)
3765    viewcell{iline}=num2str(iline);
3766end
3767viewcell=viewcell';
3768ModeMenu={'bursts';'series(Dj)'};
3769ModeValue=1;                                               
3770                   %i1_series,i2_series,j1_series,j2_series,mode,time,TimeUnit,ref_i,ref_j,TimeName,InputTable,FileInfo                             
3771% first raw of the GUI
3772uicontrol('Style','text','Units','normalized', 'Position', [0.05 0.88 0.5 0.1],'BackgroundColor',BackgroundColor,...
3773    'String','row to edit #','FontUnits','points','FontSize',12,'FontWeight','bold','ForegroundColor','blue','HorizontalAlignment','right'); % title
3774uicontrol('Style','popupmenu','Units','normalized', 'Position', [0.54 0.8 0.3 0.2],'BackgroundColor',[1 1 1],...
3775    'Callback',@(hObject,eventdata)ListView_Callback(hObject,eventdata),'String',viewcell,'Value',1,'FontUnits','points','FontSize',12,'FontWeight','bold',...
3776    'Tag','ListView','TooltipString','''ListView'':choice of the file series w for pair display');
3777% second raw of the GUI
3778uicontrol('Style','text','Units','normalized', 'Position', [0.05 0.79 0.7 0.1],'BackgroundColor',BackgroundColor,...
3779    'String','mode of index pairing:','FontUnits','points','FontSize',12,'FontWeight','bold','ForegroundColor','blue','HorizontalAlignment','left'); % title
3780uicontrol('Style','popupmenu','Units','normalized', 'Position', [0.05 0.62 0.9 0.2],'BackgroundColor',[1 1 1],...
3781    'Callback',@(hObject,eventdata)Mode_Callback(hObject,eventdata),'String',ModeMenu,'Value',ModeValue,'FontUnits','points','FontSize',12,'FontWeight','bold',...
3782    'Tag','Mode','TooltipString','''Mode'': choice of the image pair mode');
3783% third raw
3784uicontrol('Style','text','Units','normalized', 'Position', [0.05 0.6 0.7 0.1],'BackgroundColor',BackgroundColor,...
3785    'String','pair choice:','FontUnits','points','FontSize',12,'FontWeight','bold','ForegroundColor','blue','HorizontalAlignment','left'); % title
3786uicontrol('Style','listbox','Units','normalized', 'Position', [0.05 0.42 0.9 0.2],'BackgroundColor',[1 1 1],...
3787    'Callback',@(hObject,eventdata)ListPair_Callback(hObject,eventdata),'String',displ_pair,'Value',1,'FontUnits','points','FontSize',12,'FontWeight','bold',...
3788    'Tag','ListPair','TooltipString','''ListPair'': menu for selecting the image pair');
3789uicontrol('Style','text','Units','normalized', 'Position', [0.1 0.22 0.8 0.1],'BackgroundColor',BackgroundColor,...
3790    'String','ref_i           ref_j','FontUnits','points','FontSize',12,'FontWeight','bold','ForegroundColor','blue','HorizontalAlignment','center'); % title
3791uicontrol('Style','edit','Units','normalized', 'Position', [0.15 0.17 0.3 0.08],'BackgroundColor',[1 1 1],...
3792    'Callback',@(hObject,eventdata)num_ref_i_Callback(hObject,eventdata),'String',num2str(ref_i),'FontUnits','points','FontSize',12,'FontWeight','bold',...
3793    'Tag','num_ref_i','TooltipString','''num_ref_i'': reference field index i used to display dt in ''list_pair_civ''');
3794uicontrol('Style','edit','Units','normalized', 'Position', [0.55 0.17 0.3 0.08],'BackgroundColor',[1 1 1],...
3795    'Callback',@(hObject,eventdata)num_ref_j_Callback(hObject,eventdata),'String',num2str(ref_j),'FontUnits','points','FontSize',12,'FontWeight','bold',...
3796    'Tag','num_ref_j','TooltipString','''num_ref_j'': reference field index i used to display dt in ''list_pair_civ''');
3797uicontrol('Style','pushbutton','Units','normalized', 'Position', [0.01 0.01 0.3 0.12],'BackgroundColor',[0 1 0],...
3798    'Callback',@(hObject,eventdata)OK_Callback(hObject,eventdata),'String','OK','FontUnits','points','FontSize',12,'FontWeight','bold',...
3799    'Tag','OK','TooltipString','''OK'': validate the choice');
3800%  last raw  of the GUI: pushbuttons
3801% uicontrol('Style','pushbutton','Units','normalized', 'Position', [0.35 0.01 0.3 0.15],'BackgroundColor',[0 1 0],'String','OK','Callback',@(hObject,eventdata)OK_Callback(hObject,eventdata),...
3802%     'FontWeight','bold','FontUnits','points','FontSize',12,'TooltipString','''OK'': apply the output to the current field series in uvmat');
3803drawnow
3804
3805%------------------------------------------------------------------------
3806function ListView_Callback(hObject,eventdata)
3807Mode_Callback(hObject,eventdata)
3808
3809%------------------------------------------------------------------------   
3810function Mode_Callback(hObject,eventdata)
3811%% get input info
3812hseries=findobj(allchild(0),'tag','series'); % handles of the GUI series
3813hhseries=guidata(hseries); % handles of the elements in the GUI series
3814TimeUnit=get(hhseries.TimeUnit,'String');
3815SeriesData=get(hseries,'UserData');
3816mode_list=get(hObject,'String');
3817mode=mode_list{get(hObject,'Value')};
3818hListView=findobj(get(hObject,'parent'),'Tag','ListView');
3819iview=get(hListView,'Value');
3820i1_series=SeriesData.i1_series{iview};
3821i2_series=SeriesData.i2_series{iview};
3822j1_series=SeriesData.j1_series{iview};
3823j2_series=SeriesData.j2_series{iview};
3824
3825%% enable j index visibility after the new choice
3826
3827if strcmp(mode,'series(Dj)')
3828   status_j='on'; % default
3829else
3830       status_j='off'; % no j index needed for bust case
3831end
3832enable_j(hhseries,status_j) % no j index needed
3833
3834%% get the reference indices for the time interval Dt
3835href_i=findobj(get(hObject,'parent'),'Tag','ref_i');
3836ref_i=[];ref_j=[];
3837if strcmp(get(href_i,'Visible'),'on')
3838    ref_i=str2num(get(href_i,'String'));
3839end
3840if isempty(ref_i)
3841    ref_i=1;
3842end
3843if isempty(ref_j)
3844    ref_j=1;
3845end
3846
3847%% update the menu ListPair
3848Menu=update_listpair(i1_series,i2_series,j1_series,j2_series,mode,SeriesData.Time{iview},TimeUnit,ref_i,ref_j,SeriesData.FileInfo);
3849hlist_pairs=findobj(get(hObject,'parent'),'Tag','ListPair');
3850set(hlist_pairs,'Value',1)% set the first choice by default in ListPair
3851set(hlist_pairs,'String',Menu)% set the menu in ListPair
3852ListPair_Callback(hlist_pairs,[])% apply the default choice in ListPair
3853
3854%-------------------------------------------------------------
3855% --- Executes on selection in ListPair.
3856function ListPair_Callback(hObject,eventdata)
3857%------------------------------------------------------------
3858list_pair=get(hObject,'String'); % get the menu of image pairs
3859if isempty(list_pair)
3860    string='';
3861else
3862    string=list_pair{get(hObject,'Value')};
3863   % string=regexprep(string,',.*',''); % removes time indication (after ',')
3864end
3865hseries=findobj(allchild(0),'tag','series');
3866hPairString=findobj(hseries,'tag','PairString');
3867PairString=get(hPairString,'Data');
3868hListView=findobj(get(hObject,'parent'),'Tag','ListView');
3869iview=get(hListView,'Value');
3870PairString{iview,1}=string;
3871% report the selected pair string to the table PairString
3872set(hPairString,'Data',PairString)
3873
3874
3875%------------------------------------------------------------------------
3876function num_ref_i_Callback(hObject, eventdata)
3877%------------------------------------------------------------------------
3878Mode_Callback([],[])
3879
3880%------------------------------------------------------------------------
3881function num_ref_j_Callback(hObject, eventdata)
3882%------------------------------------------------------------------------
3883Mode_Callback([],[])
3884
3885%------------------------------------------------------------------------
3886function OK_Callback(hObject, eventdata)
3887%------------------------------------------------------------------------
3888delete(get(hObject,'parent'))
3889
3890
3891%------------------------------------------------------------------------
3892% --- Executes on button press in ClearLine.
3893%------------------------------------------------------------------------
3894function ClearLine_Callback(hObject, eventdata, handles)
3895InputTable=get(handles.InputTable,'Data');
3896iline=str2double(get(handles.InputLine,'String'));
3897if size(InputTable,1)>1
3898    InputTable(iline,:)=[]; % suppress the current line if not the first
3899    set(handles.InputTable,'Data',InputTable);
3900end
3901set(handles.REFRESH,'BackgroundColor',[1 0 1])% set REFRESH button to magenta color to indicate that input refr
3902
3903
3904% --- Executes on button press in MonitorCluster.
3905function MonitorCluster_Callback(hObject, eventdata, handles)
3906
3907[rr,ss]=system('oarstat |grep N=UVmat');% check the list of jobs launched with uvmat
3908if isempty(ss)
3909   disp( 'no job presently submitted with uvmat')
3910else
3911    disp('format: R/W=run/wait, time lapsed, R=nbre of cores,W=walltime')
3912    disp(ss)
3913end
3914
3915
3916function OutputSubDir_Callback(hObject, eventdata, handles)
3917set(handles.OutputSubDir,'BackgroundColor',[1 1 1])
3918
3919
3920% --- Executes on button press in CheckOverwrite.
3921function CheckOverwrite_Callback(hObject, eventdata, handles)
3922
3923% --- Executes on button press in TestCPUTime.
3924function TestCPUTime_Callback(hObject, eventdata, handles)
3925% hObject    handle to TestCPUTime (see GCBO)
3926% eventdata  reserved - to be defined in a future version of MATLAB
3927% handles    structure with handles and user data (see GUIDATA)
3928
3929
3930% --- Executes on button press in DiskQuota.
3931function DiskQuota_Callback(hObject, eventdata, handles)
3932SeriesData=get(handles.series,'UserData');
3933system(SeriesData.SeriesParam.DiskQuotaCmd)
3934
3935
3936% --- Executes on button press in Replicate.
3937function Replicate_Callback(hObject, eventdata, handles)
3938if get(handles.Replicate,'Value')
3939    InputTable=get(handles.InputTable,'Data');
3940    for ilist=1:size(InputTable,1)
3941        InputDir{ilist}=fullfile(InputTable{ilist,1},InputTable{ilist,2});
3942    end
3943    browse_data(InputDir)
3944else
3945    hh=findobj(allchild(0),'Tag','browse_data');
3946    if ~isempty(hh)
3947        delete(hh)
3948    end
3949end
3950
3951
3952
3953
3954function OutputPath_Callback(hObject, eventdata, handles)
3955
3956
3957function Experiment_Callback(hObject, eventdata, handles)
3958
3959
3960function Device_Callback(hObject, eventdata, handles)
3961
3962
3963% --- Executes on button press in OutputPathBrowse.
3964function OutputPathBrowse_Callback(hObject, eventdata, handles)
3965CheckValue=get(handles.OutputPathBrowse,'Value');
3966if CheckValue
3967OutputPath=uigetdir(get(handles.OutputPath,'String'));
3968set(handles.OutputPath,'String',OutputPath)
3969else
3970    InputTable=get(handles.InputTable,'Data');
3971    set(handles.OutputPath,'String',InputTable{1,1})
3972end
Note: See TracBrowser for help on using the repository browser.