source: trunk/src/series.m @ 1100

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

turb_stat updated for multi slices

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