source: trunk/src/series.m @ 1202

Last change on this file since 1202 was 1202, checked in by sommeria, 22 hours ago

parciv added and erasing bad file in complement series

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