source: trunk/src/series.m @ 1090

Last change on this file since 1090 was 1090, checked in by sommeria, 4 years ago

system of mirror output path introduced, and series/sliding_average added

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