source: trunk/src/series.m @ 1157

Last change on this file since 1157 was 1156, checked in by sommeria, 4 months ago

bugs repaired

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