source: trunk/src/series.m @ 1184

Last change on this file since 1184 was 1184, checked in by sommeria, 5 weeks ago

bed-scan updated and many updates

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