source: trunk/src/series.m @ 1183

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

bed_scan added + bug repairs

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