source: trunk/src/series.m

Last change on this file was 1161, checked in by sommeria, 8 days ago

filter_tps modified to avoid possible bugs in case of few vectors, subpixel interpolation slightly modified in civ

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