source: trunk/src/series.m @ 1155

Last change on this file since 1155 was 1154, checked in by sommeria, 4 months ago

various improvements

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