source: trunk/src/series.m @ 1189

Last change on this file since 1189 was 1189, checked in by sommeria, 2 days ago

introduced creator of xml for PCO multitif

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