source: trunk/src/series.m

Last change on this file was 1141, checked in by sommeria, 27 hours ago

smoothig parameter renormalised in filter_tps

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