source: trunk/src/series.m @ 595

Last change on this file since 595 was 595, checked in by sommeria, 11 years ago

steps further to use series with cluster. Some bsolete functions removed

File size: 105.4 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%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
17%  Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
18%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
19%     This file is part of the toolbox UVMAT.
20%
21%     UVMAT is free software; you can redistribute it and/or modify
22%     it under the terms of the GNU General Public License as published by
23%     the Free Software Foundation; either version 2 of the License, or
24%     (at your option) any later version.
25%
26%     UVMAT is distributed in the hope that it will be useful,
27%     but WITHOUT ANY WARRANTY; without even the implied warranty of
28%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29%     GNU General Public License (file UVMAT/COPYING.txt) for more details.
30%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
31
32%------------------------------------------------------------------------
33%------------------------------------------------------------------------
34%  I - MAIN FUNCTION series
35%------------------------------------------------------------------------
36%------------------------------------------------------------------------
37function varargout = series(varargin)
38
39% Begin initialization code - DO NOT EDIT
40gui_Singleton = 1;
41gui_State = struct('gui_Name',       mfilename, ...
42                   'gui_Singleton',  gui_Singleton, ...
43                   'gui_OpeningFcn', @series_OpeningFcn, ...
44                   'gui_OutputFcn',  @series_OutputFcn, ...
45                   'gui_LayoutFcn',  [] , ...
46                   'gui_Callback',   []);
47if nargin && ischar(varargin{1})
48    gui_State.gui_Callback = str2func(varargin{1});
49end
50
51if nargout
52    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
53else
54    gui_mainfcn(gui_State, varargin{:});
55end
56% End initialization code - DO NOT EDIT
57
58%--------------------------------------------------------------------------
59% --- Executes just before series is made visible.
60%--------------------------------------------------------------------------
61function series_OpeningFcn(hObject, eventdata, handles,Param)
62
63% Choose default command line output for series
64handles.output = hObject;
65% Update handles structure
66guidata(hObject, handles);
67
68%% initial settings
69drawnow
70set(hObject,'Units','pixels')
71set(handles.PairString,'ColumnName',{'pairs'})
72set(handles.PairString,'ColumnEditable',logical(0))
73set(handles.PairString,'ColumnFormat',{'char'})
74set(handles.PairString,'Data',{''})
75series_ResizeFcn(hObject, eventdata, handles)%resize table according to series GUI size
76set(hObject,'WindowButtonDownFcn',{'mouse_down'})%allows mouse action with right button (zoom for uicontrol display)
77% check default input data
78if ~exist('Param','var')
79    Param=[]; %default
80end
81
82%% default list of functions in the mebu ActionName
83ActionList={'check_data_files';'aver_stat';'time_series';'merge_proj'};% WARNING: fits with nb_builtin_ACTION=4 in ActionName_callback
84[path_series,name,ext]=fileparts(which('series'));% path to the GUI series
85path_series_fct=fullfile(path_series,'series');%path of the functions in subdirectroy 'series'
86path_bin=fullfile(path_series,'bin');%path of the binary functions (compiled)
87ActionPathList=regexprep(ActionList,'^.+$',path_series_fct);% set path=path_series to each function in the list ('^.+$'=any non empty nbre of char form beginning to end of char string)
88ActionPathList=[ActionPathList regexprep(ActionList,'^.+$',path_bin)];% set path to compiled functions
89ActionExtList={'.m';'.sh'};% default choice of extensions (Matlab fct .m or compiled version .sh)
90RunModeList={'local';'background'};% default choice of extensions (Matlab fct .m or compiled version .sh)
91[s,w]=system('oarstat');% look for cluster system 'oar'
92if isequal(s,0)
93    RunModeList=[RunModeList;{'cluster_oar'}];
94end
95[s,w]=system('qstat');% look for cluster system 'sge'
96if isequal(s,0)
97    RunModeList=[RunModeList;{'cluster_sge'}];
98end
99set(handles.RunMode,'String',RunModeList)
100
101%% default list of functions in the mebu TransformName
102TransformList={'';'sub_field';'phys';'phys_polar'};% WARNING: must fit with the corresponding menu in uvmat and nb_builtin_transform=4 in  TransformName_callback
103path_transform_fct=fullfile(path_series,'transform_field');
104TransformPathList=regexprep(TransformList,'^.+$',path_transform_fct);% set path=path_transform_fct to each function in the list ('^.+$'=any non empty nbre of char form beginning to end of char string)
105
106%% load the personal file uvmat_perso.mat
107dir_perso=prefdir;
108profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
109if exist(profil_perso,'file')
110    h=load (profil_perso);
111    %get the list of previous input files in the upper bar menu Open
112    if isfield(h,'MenuFile')
113        for ifile=1:min(length(h.MenuFile),5)
114            eval(['set(handles.MenuFile_' num2str(ifile) ',''Label'',h.MenuFile{ifile});'])
115        end
116    end
117    %get the menu of actions
118    if isfield(h,'ActionExtListUser') && iscell(h.ActionExtListUser)
119        ActionExtList=[ActionExtList; h.ActionExtListUser];
120    end
121    if isfield(h,'ActionListUser') && iscell(h.ActionListUser) && isfield(h,'ActionPathListUser') && iscell(h.ActionPathListUser)
122        ActionList=[ActionList;h.ActionListUser];
123        ActionPathList=[ActionPathList;h.ActionPathListUser];
124    end
125    %get the menu of transform fct
126    if isfield(h,'TransformListUser') && iscell(h.TransformListUser) && isfield(h,'TransformPathListUser') && iscell(h.TransformPathListUser)
127        TransformList=[TransformList;h.TransformListUser];
128        TransformPathList=[TransformPathList;h.TransformPathListUser];
129    end
130end
131
132%% selection of the input Action fct
133ActionCheckExist=false(size(ActionList));
134for ilist=1:numel(ActionList)
135    ActionCheckExist(ilist)=exist(fullfile(ActionPathList{ilist},[ActionList{ilist} '.m']),'file');
136end
137ActionPathList=ActionPathList(ActionCheckExist,:);
138ActionList=ActionList(ActionCheckExist);
139set(handles.ActionName,'String',[ActionList;{'more...'}])
140set(handles.ActionName,'UserData',ActionPathList)
141ActionIndex=[];
142if isfield(Param,'ActionName')% copy the selected menu index transferred in Param from uvmat
143    ActionIndex=find(strcmp(Param.ActionName,ActionList),1);
144end
145if isempty(ActionIndex)
146    ActionIndex=1;
147end
148set(handles.ActionName,'Value',ActionIndex)
149set(handles.ActionPath,'String',ActionPathList{ActionIndex})
150set(handles.ActionExt,'Value',1)
151set(handles.ActionExt,'String',ActionExtList)
152
153%% selection of the input transform fct
154TransformCheckExist=false(size(TransformList));
155TransformCheckExist(1)=1;%the first option is blank: no transform, always allowed
156for ilist=2:numel(TransformList)
157    TransformCheckExist(ilist)=exist(fullfile(TransformPathList{ilist},[TransformList{ilist} '.m']),'file');
158end
159TransformPathList=TransformPathList(TransformCheckExist);
160TransformList=TransformList(TransformCheckExist);
161set(handles.TransformName,'String',[TransformList;{'more...'}])
162set(handles.TransformName,'UserData',TransformPathList)
163TransformIndex=[];
164if isfield(Param,'TransformName')% copy the selected menu index transferred in Param from uvmat
165    TransformIndex=find(strcmp(Param.TransformName,TransformList),1);
166end
167if isempty(TransformIndex)
168    TransformIndex=1;
169end
170set(handles.TransformName,'Value',TransformIndex)
171set(handles.TransformPath,'String',TransformPathList{TransformIndex})
172   
173%% fields input initialisation
174if isfield(Param,'list_fields')&& isfield(Param,'index_fields') &&~isempty(Param.list_fields) &&~isempty(Param.index_fields)
175    set(handles.FieldName,'String',Param.list_fields);% list menu fields
176    set(handles.FieldName,'Value',Param.index_fields);% selected string index
177end
178if isfield(Param,'Coord_x_str')&& isfield(Param,'Coord_x_val')
179        set(handles.Coord_x,'String',Param.Coord_x_str);% list menu fields
180    set(handles.Coord_x,'Value',Param.Coord_x_val);% selected string index
181end
182if isfield(Param,'Coord_y_str')&& isfield(Param,'Coord_y_val')
183        set(handles.Coord_y,'String',Param.Coord_y_str);% list menu fields
184    set(handles.Coord_y,'Value',Param.Coord_y_val);% selected string index
185end
186
187%% Adjust the GUI according to the binaries available in PARAM.xml
188% path_uvmat=fileparts(which('uvmat')); %path to civ
189% addpath (path_uvmat) ; %add the path to civ, (useful in case of change of working directory after civ has been s opened in the working directory)
190% errormsg=[];%default error message
191% xmlfile='PARAM.xml';
192% if exist(xmlfile,'file')
193%     try
194%         t=xmltree(xmlfile);
195%         sparam=convert(t);
196%     catch ME
197%         errormsg={' Unable to read the file PARAM.xml defining the  binaries:';ME.message};
198%     end
199% else
200%     errormsg=[xmlfile ' not found: path to binaries undefined'];
201% end
202% if ~isempty(errormsg)
203%     msgbox_uvmat('WARNING',errormsg);
204% end
205% test_batch=0;%default: ,no batch mode available
206% if isfield(sparam,'BatchParam') && isfield(sparam.BatchParam,'BatchMode')
207%     test_batch=strcmp(sparam.BatchParam.BatchMode,'sge'); %sge is currently the only implemented batch mod
208% end
209% RUNVal=get(handles.RunMode,'Value');
210% if test_batch==0
211%    if RUNVal>2
212%        set(handles.RunMode,'Value',1)
213%    end
214%    set(handles.RunMode,'String',{'local';'background'})
215% else
216%     set(handles.RunMode,'String',{'local';'background';'cluster'})
217% end
218
219%% introduce the input file name(s) if defined from input Param
220if isfield(Param,'FileName')
221    InputTable={'','','','',''}; % refresh the file input table
222    set(handles.InputTable,'Data',InputTable)
223    if isfield(Param,'FileName_1')
224        display_file_name(handles,Param.FileName_1,0)
225        display_file_name(handles,Param.FileName,1)
226    else
227        display_file_name(handles,Param.FileName,0)
228    end
229end 
230if isfield(Param,'incr_i')
231    set(handles.num_incr_i,'String',num2str(Param.incr_i))
232end
233if isfield(Param,'incr_j')
234    set(handles.num_incr_j,'String',num2str(Param.incr_j))
235end
236
237
238%------------------------------------------------------------------------
239% --- Outputs from this function are returned to the command line.
240function varargout = series_OutputFcn(hObject, eventdata, handles)
241%------------------------------------------------------------------------
242% varargout  cell array for returning output args (see VARARGOUT);
243% hObject    handle to figure
244% eventdata  reserved - to be defined in a future version of MATLAB
245% handles    structure with handles and user data (see GUIDATA)
246% Get default command line output from handles structure
247varargout{1} = handles.output;
248
249%------------------------------------------------------------------------
250%------------------------------------------------------------------------
251%  II - FUNCTIONS FOR INTRODUCING THE INPUT FILES
252% automatically sets the global properties when the rootfile name is introduced
253% then activate the view-field actionname if selected
254% it is activated either by clicking on the RootPath window or by the
255% browser
256%------------------------------------------------------------------------
257%------------------------------------------------------------------------
258function MenuBrowse_Callback(hObject, eventdata, handles)
259%------------------------------------------------------------------------   
260InputTable=get(handles.InputTable,'Data');
261if isempty(InputTable)
262    RootPathCell={};
263else
264    RootPathCell=InputTable(:,1);
265end
266oldfile=''; %default
267if isempty(RootPathCell)||isequal(RootPathCell,{''})%loads the previously stored file name and set it as default in the file_input box
268     dir_perso=prefdir;
269     profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
270     if exist(profil_perso,'file')
271          h=load (profil_perso);
272         if isfield(h,'filebase')&&ischar(h.filebase)
273                 oldfile=h.filebase;
274         end
275         if isfield(h,'RootPath')&&ischar(h.RootPath)
276                 oldfile=h.RootPath;
277         end
278     end
279else
280     SubDirCell=InputTable(:,2);
281    RootFileCell=InputTable(:,3);
282     oldfile=fullfile(RootPathCell{1},SubDirCell{1},RootFileCell{1});
283 end
284[FileName, PathName, filterindex] = uigetfile( ...
285       {'*.xml;*.xls;*.png;*.tif;*.avi;*.AVI;*.nc', ' (*.xml,*.xls, *.png,*.tif, *.avi,*.nc)';
286       '*.xml',  '.xml files '; ...
287        '*.xls',  '.xls files '; ...
288        '*.png','.png image files'; ...
289        '*.tif','.tif image files'; ...
290        '*.avi;*.AVI','.avi movie files'; ...
291        '*.nc','.netcdf files'; ...
292        '*.*',  'All Files (*.*)'}, ...
293        'Pick a file',oldfile);
294fileinput=[PathName FileName];%complete file name
295if isempty(fileinput),return;end %abandon if no file is introduced by the browser
296[path,name,ext]=fileparts(fileinput);
297if isequal(ext,'.xml')
298    [Param,Heading]=xml2struct(fileinput);
299    if ~strcmp(Heading,'Series')
300        msg_box_uvmat('ERROR','xml file heading is not <Series>')
301    else
302        fill_GUI(Param,handles.series);%fill the GUI with the parameters retrieved from the xml file
303        if isfield(Param,'CheckObject')&& Param.CheckObject
304            set_object(Param.ProjObject)
305        end
306        set(handles.REFRESH,'UserData',[1:size(Param.InputTable,1)])
307        REFRESH_Callback([],[], handles)
308        return
309    end
310elseif isequal(ext,'.xls')
311    msg_box_uvmat('ERROR','input file type not implemented')%A Faire: ouvrir le fichier pour naviguer
312else
313    display_file_name(handles,fileinput,0)
314end
315
316% --------------------------------------------------------------------
317function MenuFile_1_Callback(hObject, eventdata, handles)
318fileinput=get(handles.MenuFile_1,'Label');
319display_file_name(handles,fileinput,0)
320
321% --------------------------------------------------------------------
322function MenuFile_2_Callback(hObject, eventdata, handles)
323fileinput=get(handles.MenuFile_2,'Label');
324display_file_name(handles,fileinput,0)
325
326% --------------------------------------------------------------------
327function MenuFile_3_Callback(hObject, eventdata, handles)
328fileinput=get(handles.MenuFile_3,'Label');
329display_file_name( handles,fileinput,0)
330
331% --------------------------------------------------------------------
332function MenuFile_4_Callback(hObject, eventdata, handles)
333fileinput=get(handles.MenuFile_4,'Label');
334display_file_name(handles,fileinput,0)
335
336% --------------------------------------------------------------------
337function MenuFile_5_Callback(hObject, eventdata, handles)
338fileinput=get(handles.MenuFile_5,'Label');
339display_file_name(handles,fileinput,0)
340
341% --------------------------------------------------------------------
342function MenuBrowse_insert_Callback(hObject, eventdata, handles)
343InputTable=get(handles.InputTable,'Data');
344RootPathCell=InputTable(:,1);
345SubDirCell=InputTable(:,3);
346RootFileCell=InputTable(:,2);
347oldfile=''; %default
348if isempty(RootPathCell)||isequal(RootPathCell,{''})%loads the previously stored file name and set it as default in the file_input box
349     dir_perso=prefdir;
350     profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
351     if exist(profil_perso,'file')
352          h=load (profil_perso);
353         if isfield(h,'filebase')&ischar(h.filebase)
354                 oldfile=h.filebase;
355         end
356         if isfield(h,'RootPath')&ischar(h.RootPath)
357                 oldfile=h.RootPath;
358         end
359     end
360 else
361     oldfile=fullfile(RootPathCell{1},RootFileCell{1});
362 end
363[FileName, PathName, filterindex] = uigetfile( ...
364       {'*.xml;*.xls;*.png;*.avi;*.AVI;*.nc', ' (*.xml,*.xls, *.png, *.avi,*.nc)';
365       '*.xml',  '.xml files '; ...
366        '*.xls',  '.xls files '; ...
367        '*.png','.png image files'; ...
368        '*.avi;*.AVI','.avi movie files'; ...
369        '*.nc','.netcdf files'; ...
370        '*.*',  'All Files (*.*)'}, ...
371        'Pick a file',oldfile);
372fileinput=[PathName FileName];%complete file name
373sizf=size(fileinput);
374if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end
375[path,name,ext]=fileparts(fileinput);
376if isequal(ext,'.xml')
377    msgbox_uvmat('ERROR','input file type not implemented')%A Faire: ouvrir le fichier pour naviguer
378elseif isequal(ext,'.xls')
379    msgbox_uvmat('ERROR','input file type not implemented')%A Faire: ouvrir le fichier pour naviguer
380else
381    display_file_name(handles,fileinput,'append')
382end
383
384% --------------------------------------------------------------------
385function MenuFile_insert_1_Callback(hObject, eventdata, handles)
386% --------------------------------------------------------------------   
387fileinput=get(handles.MenuFile_insert_1,'Label');
388display_file_name(handles,fileinput,'append')
389
390% --------------------------------------------------------------------
391function MenuFile_insert_2_Callback(hObject, eventdata, handles)
392% --------------------------------------------------------------------   
393fileinput=get(handles.MenuFile_insert_2,'Label');
394display_file_name(handles,fileinput,'append')
395
396% --------------------------------------------------------------------
397function MenuFile_insert_3_Callback(hObject, eventdata, handles)
398% --------------------------------------------------------------------   
399fileinput=get(handles.MenuFile_insert_3,'Label');
400display_file_name( handles,fileinput,'append')
401
402% --------------------------------------------------------------------
403function MenuFile_insert_4_Callback(hObject, eventdata, handles)
404% --------------------------------------------------------------------   
405fileinput=get(handles.MenuFile_insert_4,'Label');
406display_file_name( handles,fileinput,'append')
407
408% --------------------------------------------------------------------
409function MenuFile_insert_5_Callback(hObject, eventdata, handles)
410% --------------------------------------------------------------------   
411fileinput=get(handles.MenuFile_insert_5,'Label');
412display_file_name(handles,fileinput,'append')
413
414%------------------------------------------------------------------------
415% --- Executes when entered data in editable cell(s) in InputTable.
416function InputTable_CellEditCallback(hObject, eventdata, handles)
417%------------------------------------------------------------------------
418set(handles.REFRESH,'Visible','on')
419iview=eventdata.Indices(1);
420view_set=get(handles.REFRESH,'UserData');
421if isempty(find(view_set==iview))
422    set(handles.REFRESH,'UserData',[view_set iview])
423end
424%% enable other menus and uicontrols
425set(handles.MenuOpen_insert,'Enable','on')
426set(handles.MenuFile_insert_1,'Enable','on')
427set(handles.MenuFile_insert_2,'Enable','on')
428set(handles.MenuFile_insert_3,'Enable','on')
429set(handles.MenuFile_insert_4,'Enable','on')
430set(handles.MenuFile_insert_5,'Enable','on')
431set(handles.RUN, 'Enable','On')
432set(handles.RUN,'BackgroundColor',[1 0 0])% set RUN button to red
433
434%update the output dir
435% SubDir=sort(InputTable(:,2)); %set of subdirectories sorted in alphabetical order
436% SubDirOut=SubDir{1};
437% if numel(SubDir)>1
438%     for ilist=2:numel(SubDir)
439%         SubDirOut=[SubDirOut '-' SubDir{ilist}];
440%     end
441% end
442% set(handles.OutputSubDir,'String',SubDirOut)
443
444%------------------------------------------------------------------------
445% --- Executes on button press in REFRESH.
446function REFRESH_Callback(hObject, eventdata, handles)
447%------------------------------------------------------------------------
448InputTable=get(handles.InputTable,'Data');
449view_set=get(handles.REFRESH,'UserData');
450set(handles.REFRESH,'BackgroundColor',[0.7 0.7 0.7])% set REFRESH  button to grey color
451drawnow
452for iview=view_set
453    RootPath=fullfile(InputTable{iview,1},InputTable{iview,2});
454    if ~exist(RootPath,'dir')
455        i1_series=[];
456        RootPath=fileparts(RootPath); %will try the upped forldr
457    else
458        [RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,tild,FileType,MovieObject]=...
459            find_file_series(fullfile(InputTable{iview,1},InputTable{iview,2}),[InputTable{iview,3} InputTable{iview,4} InputTable{iview,5}]);
460    end
461    if isempty(i1_series)
462        [FileName, PathName, filterindex] = uigetfile( ...
463            {'*.xml;*.xls;*.png;*.tif;*.avi;*.AVI;*.nc', ' (*.xml,*.xls, *.png,*.tif, *.avi,*.nc)';
464            '*.xml',  '.xml files '; ...
465            '*.xls',  '.xls files '; ...
466            '*.png','.png image files'; ...
467            '*.tif','.tif image files'; ...
468            '*.avi;*.AVI','.avi movie files'; ...
469            '*.nc','.netcdf files'; ...
470            '*.*',  'All Files (*.*)'}, ...
471            ['unvalid entry at line ' num2str(iview) ', pick a file'],RootPath);
472        fileinput=[PathName FileName];%complete file name
473        if isempty(fileinput),return;end %abandon if the operation has been cancelled: no input from browser
474        [path,name,ext]=fileparts(fileinput);
475        display_file_name(handles,fileinput,iview)
476    else
477        update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileType,MovieObject,iview)
478    end
479end
480set(handles.REFRESH,'BackgroundColor',[1 0 0])% set REFRESH  button to grey color
481set(handles.REFRESH,'Visible','off')
482set(handles.REFRESH,'UserData',[])
483
484%------------------------------------------------------------------------
485% --- Function called when a new file is opened, either by series_OpeningFcn or by the browser
486function display_file_name(handles,fileinput,iview)
487%------------------------------------------------------------------------ 
488%
489% INPUT:
490% handles: handles of elements in the GUI
491% fielinput: input file name, including path
492% append =0 (refresh the Input table with the new file), ='append' append a new line in the table
493
494%% get the input root name, indices, file extension and nomenclature NomType
495if ~exist(fileinput,'file')
496    msgbox_uvmat('ERROR',['input file ' fileinput  ' does not exist'])
497    return
498end
499
500%% enable other menus and uicontrols
501set(handles.MenuOpen_insert,'Enable','on')
502set(handles.MenuFile_insert_1,'Enable','on')
503set(handles.MenuFile_insert_2,'Enable','on')
504set(handles.MenuFile_insert_3,'Enable','on')
505set(handles.MenuFile_insert_4,'Enable','on')
506set(handles.MenuFile_insert_5,'Enable','on')
507set(handles.RUN, 'Enable','On')
508set(handles.RUN,'BackgroundColor',[1 0 0])% set RUN button to red
509set(handles.InputTable,'BackgroundColor',[1 1 0]) % set RootPath edit box  to yellow
510drawnow
511
512%% detect root name, nomenclature and indices in the input file name:
513[FilePath,FileName,FileExt]=fileparts(fileinput);
514% detect the file type, get the movie object if relevant, and look for the corresponding file series:
515% the root name and indices may be corrected by including the first index i1 if a corresponding xml file exists
516[RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,NomType,FileType,MovieObject,i1,i2,j1,j2]=find_file_series(FilePath,[FileName FileExt]);
517if isempty(RootFile)&&isempty(i1_series)
518    errormsg='no input file in the series';
519    return
520end
521
522%% fill the list of file series
523InputTable=get(handles.InputTable,'Data');
524if strcmp(iview,'append') % display the input data as a new line in the table
525     iview=size(InputTable,1);
526     InputTable(iview+1,:)={'','','','',''};
527     InputTable(iview,:)=[{RootPath},{SubDir},{RootFile},{NomType},{FileExt}];
528elseif iview==0 % or re-initialise the list of  input  file series
529    iview=1;
530    InputTable=[{'','','','',''};{'','','','',''}];
531     InputTable(iview,:)=[{RootPath},{SubDir},{RootFile},{NomType},{FileExt}];
532    set(handles.TimeTable,'Data',[{[]},{[]},{[]},{[]}])
533    set(handles.MinIndex,'Data',[{[]},{[]}])
534    set(handles.MaxIndex,'Data',[{[]},{[]}])
535    set(handles.ListView,'Value',1)
536    set(handles.ListView,'String',{'1'})
537end
538nbview=size(InputTable,1);
539set(handles.ListView,'String',mat2cell((1:nbview)',ones(nbview,1)))
540set(handles.ListView,'Value',iview)
541set(handles.InputTable,'Data',InputTable)
542
543%% determine the selected reference field indices for pair display
544ref_i=1; %default ref_i is a reference frame index used to find existing pairs from PIV
545if ~isempty(i1)
546    ref_i=i1;
547    if ~isempty(i2)
548        ref_i=floor((ref_i+i2)/2);% reference image number corresponding to the file
549    end
550end
551set(handles.num_ref_i,'String',num2str(ref_i));
552ref_j=1; %default  ref_j is a reference frame index used to find existing pairs from PIV
553if ~isempty(j1)
554    ref_j=j1;
555    if ~isempty(j2)
556        ref_j=floor((j1+j2)/2);
557    end         
558end
559set(handles.num_ref_j,'String',num2str(ref_j));
560
561%% update the list of recent files in the menubar and save it for future opening
562MenuFile=[{get(handles.MenuFile_1,'Label')};{get(handles.MenuFile_2,'Label')};...
563    {get(handles.MenuFile_3,'Label')};{get(handles.MenuFile_4,'Label')};{get(handles.MenuFile_5,'Label')}];
564str_find=strcmp(fileinput,MenuFile);
565if isempty(find(str_find,1))
566    MenuFile=[{fileinput};MenuFile];%insert the current file if not already in the list
567end
568for ifile=1:min(length(MenuFile),5)
569    eval(['set(handles.MenuFile_' num2str(ifile) ',''Label'',MenuFile{ifile});'])
570    eval(['set(handles.MenuFile_insert_' num2str(ifile) ',''Label'',MenuFile{ifile});'])
571end
572dir_perso=prefdir;
573profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
574if exist(profil_perso,'file')
575    save (profil_perso,'MenuFile','-append'); %store the file names for future opening of uvmat
576else
577    save (profil_perso,'MenuFile','-V6'); %store the file names for future opening of uvmat
578end
579
580set(handles.InputTable,'BackgroundColor',[1 1 1])
581
582%% initiate input file series and refresh the current field view:     
583update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileType,MovieObject,iview);
584
585%------------------------------------------------------------------------
586% --- Update information about a new field series (indices to scan, timing,
587%     calibration from an xml file
588function update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileType,VideoObject,iview)
589%------------------------------------------------------------------------
590%% update the output dir
591InputTable=get(handles.InputTable,'Data');
592SubDir=sort(InputTable(1:end-1,2)); %set of subdirectories sorted in alphabetical order
593SubDirOut=SubDir{1};
594if numel(SubDir)>1
595    for ilist=2:numel(SubDir)
596        SubDirOut=[SubDirOut '-' SubDir{ilist}];
597    end
598end
599set(handles.OutputSubDir,'String',SubDirOut)
600
601%% display the min and max indices for the file series
602if size(i1_series,2)==2 && min(min(i1_series(:,1,:)))==0
603    MinIndex_j=1;
604    MaxIndex_j=1;
605    MinIndex_i=find(i1_series(:,2,:), 1 )-1;
606    MaxIndex_i=find(i1_series(:,2,:), 1, 'last' )-1;
607else
608    pair_max=squeeze(max(i1_series,[],1)); %max on pair index
609    j_max=max(pair_max,[],1);
610    %i_sum=sum(sum(i1_series,2),1);%sum of i1_series on the last index
611    MaxIndex_i=find(j_max, 1, 'last' )-1;% max ref index i
612    MinIndex_i=find(j_max, 1 )-1;% min ref index i
613    diff_i_max=diff(j_max);
614    if isequal (diff_i_max,diff_i_max(1)*ones(size(diff_i_max)))
615        set(handles.num_incr_i,'String',num2str(diff_i_max(1)))
616    end
617    i_max=max(pair_max,[],2);
618    MaxIndex_j=max(find(i_max))-1;% max ref index i
619    MinIndex_j=min(find(i_max))-1;% min ref index i
620    diff_j_max=diff(i_max);
621    if isequal (diff_j_max,diff_j_max(1)*ones(size(diff_j_max)))
622        set(handles.num_incr_j,'String',num2str(diff_j_max(1)))
623    end
624end
625MinIndex=get(handles.MinIndex,'Data');%retrieve the min indices in the table MinIndex
626MaxIndex=get(handles.MaxIndex,'Data');%retrieve the max indices in the table MaxIndex
627if isequal(MinIndex_i,-1)
628    MinIndex_i=0;
629end
630if isequal(MinIndex_j,-1)
631    MinIndex_j=0;
632end
633MinIndex{iview,1}=MinIndex_i;
634MinIndex{iview,2}=MinIndex_j;
635MaxIndex{iview,1}=MaxIndex_i;
636MaxIndex{iview,2}=MaxIndex_j;
637
638set(handles.MinIndex,'Data',MinIndex)%display the min indices in the table MinIndex
639set(handles.MaxIndex,'Data',MaxIndex)%display the max indices in the table MaxIndex
640
641%% adjust the first and last indices if requested by the bounds
642first_i=str2num(get(handles.num_first_i,'String'));
643ref_i=str2num(get(handles.num_ref_i,'String'));
644ref_j=str2num(get(handles.num_ref_j,'String'));
645if isempty(first_i)
646    first_i=ref_i;
647elseif first_i < MinIndex_i
648    first_i=MinIndex_i;
649elseif first_i >MaxIndex_i
650    first_i=MinIndex_i;
651end
652first_j=str2num(get(handles.num_first_j,'String'));
653if isempty(first_j)
654    first_j=ref_j;
655elseif first_j<MinIndex_j
656    first_j=MinIndex_j;
657elseif first_j >MaxIndex_j
658    first_j=MinIndex_j;
659end
660last_i=str2num(get(handles.num_last_i,'String'));
661if isempty(last_i)
662    last_i=ref_i;
663elseif last_i > MaxIndex_i
664    last_i=MaxIndex_i;
665elseif last_i<first_i
666    last_i=first_i;
667end
668last_j=str2num(get(handles.num_first_j,'String'));
669if isempty(last_j)
670    last_j=ref_j;
671elseif last_j>MaxIndex_j
672    last_j=MaxIndex_j;
673elseif last_i<first_i
674    last_i=first_i;
675end
676set(handles.num_first_i,'String',num2str(first_i));
677set(handles.num_first_j,'String',num2str(first_j));
678set(handles.num_last_i,'String',num2str(last_i));
679set(handles.num_last_j,'String',num2str(last_j));
680
681%% read timing and total frame number from the current file (movie files) may be overrid by xml file
682InputTable=get(handles.InputTable,'Data');
683FileBase=fullfile(InputTable{iview,1},InputTable{iview,3});
684time=[];%default
685% case of movies
686if strcmp(InputTable{iview,4},'*')
687    if ~isempty(VideoObject)
688        imainfo=get(VideoObject);
689        time=(0:1/imainfo.FrameRate:(imainfo.NumberOfFrames-1)/imainfo.FrameRate)';
690       % set(handles.Dt_txt,'String',['Dt=' num2str(1000/imainfo.FrameRate) 'ms']);%display the elementary time interval in millisec
691        ColorType='truecolor';
692    elseif ~isempty(imformats(regexprep(InputTable{iview,5},'^.',''))) || isequal(InputTable{iview,5},'.vol')%&& isequal(NomType,'*')% multi-frame image
693        if ~isempty(InputTable{iview,2})
694            imainfo=imfinfo(fullfile(InputTable{iview,1},InputTable{iview,2},[InputTable{iview,3} InputTable{iview,5}]));
695        else
696            imainfo=imfinfo([FileBase InputTable{iview,5}]);
697        end
698        ColorType=imainfo.ColorType;%='truecolor' for color images
699        if length(imainfo) >1 %case of image with multiple frames
700            nbfield=length(imainfo);
701            nbfield_j=1;
702        end
703    end
704end
705
706%%  read image documentation file  if found%%%%%%%%%%%%%%%%%%%%%%%%%%%
707XmlData=[];
708NbSlice_calib={};
709XmlFileName=find_imadoc(InputTable{iview,1},InputTable{iview,2},InputTable{iview,3},InputTable{iview,5});
710if ~isempty(XmlFileName)
711        [XmlData,warntext]=imadoc2struct(XmlFileName);
712        if isfield(XmlData,'Heading') && isfield(XmlData.Heading,'ImageName') && ischar(XmlData.Heading.ImageName)
713            [PP,FF,ext_ima_read]=fileparts(XmlData.Heading.ImageName);
714        end
715        if isfield(XmlData,'Time')
716            time=XmlData.Time;
717        end
718        if isfield(XmlData,'Camera')
719            if isfield(XmlData.Camera,'NbSlice')&& ~isempty(XmlData.Camera.NbSlice)
720                NbSlice_calib{iview}=XmlData.Camera.NbSlice;% Nbre of slices for Zindex in phys transform
721                if ~isequal(NbSlice_calib{iview},NbSlice_calib{1})
722                    msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
723                end
724            end
725            if isfield(XmlData.Camera,'TimeUnit')&& ~isempty(XmlData.Camera.TimeUnit)
726                TimeUnit=XmlData.Camera.TimeUnit;
727            end
728        end
729        if ~isempty(warntext)
730            msgbox_uvmat('WARNING',warntext)
731        end 
732end
733
734%% update time table
735if ~isempty(time)
736    TimeTable=get(handles.TimeTable,'Data');
737    first_i=str2num(get(handles.num_first_i,'String'));
738    last_i=str2num(get(handles.num_last_i,'String'));
739    first_j=str2num(get(handles.num_first_j,'String'));
740    last_j=str2num(get(handles.num_last_j,'String'));
741    MinIndexTable=get(handles.MinIndex,'Data');
742    MinIndex_i=MinIndexTable{iview,1};
743    MinIndex_j=MinIndexTable{iview,2};
744    MaxIndexTable=get(handles.MaxIndex,'Data');
745    MaxIndex_i=MaxIndexTable{iview,1};
746    MaxIndex_j=MaxIndexTable{iview,2};
747    if isempty(MinIndex_j)% only i index
748        if MinIndex_i>0
749            TimeTable{iview,1}=time(MinIndex_i);
750        end
751        TimeTable{iview,2}=time(first_i);
752        TimeTable{iview,3}=time(last_i);
753        TimeTable{iview,4}=time(MaxIndex_i);
754    elseif ~isempty(time)
755        if MinIndex_i>0
756            TimeTable{iview,1}=time(MinIndex_i,MinIndex_j);
757        end
758        if size(time)>=[last_i last_j]
759            TimeTable{iview,2}=time(first_i,first_j);
760            TimeTable{iview,3}=time(last_i,last_j);
761        end
762        if size(time)>=[MaxIndex_i MaxIndex_j];
763            TimeTable{iview,4}=time(MaxIndex_i,MaxIndex_j);
764        end
765    end
766    set(handles.TimeTable,'Data',TimeTable)
767end
768
769%% number of slices
770NbSlice=1;%default
771if isfield(XmlData,'GeometryCalib') && isfield(XmlData.GeometryCalib,'SliceCoord')
772    siz=size(XmlData.GeometryCalib.SliceCoord);
773    if siz(1)>1
774        NbSlice=siz(1);
775    end
776end
777set(handles.num_NbSlice,'String',num2str(NbSlice))
778   
779%% update pair menus
780set(handles.Pairs,'Visible','on')
781set(handles.PairString,'Visible','on')
782ListView=get(handles.ListView,'String');
783ListView{iview}=num2str(iview);
784set(handles.ListView,'String',ListView);
785set(handles.ListView,'Value',iview)
786update_mode(handles,i1_series,i2_series,j1_series,j2_series,time)
787
788%% update the series info in 'UserData'
789SeriesData=get(handles.series,'UserData');
790SeriesData.i1_series{iview}=i1_series;
791SeriesData.i2_series{iview}=i2_series;
792SeriesData.j1_series{iview}=j1_series;
793SeriesData.j2_series{iview}=j2_series;
794SeriesData.FileType{iview}=FileType;
795SeriesData.Time{iview}=time;
796set(handles.series,'UserData',SeriesData)
797
798%% enable j index visibilitycellfun(@isempty,regexp(PairString,'^j'))
799% state='off';
800check_jindex=~cellfun(@isempty,SeriesData.j1_series); %look for non empty j indices
801if isempty(find(check_jindex))
802    enable_j(handles,'off') % no j index needed
803else
804    PairString=get(handles.PairString,'Data');
805    if isempty(find(cellfun(@isempty,regexp(PairString,'^j'))))% if all pair string begins by j (burst)
806        enable_j(handles,'off') % no j index needed
807    else
808        enable_j(handles,'on')
809    end
810end
811
812%% display the set of existing files as an image
813set(handles.FileStatus,'Units','pixels')
814Position=get(handles.FileStatus,'Position');
815set(handles.FileStatus,'Units','normalized')
816xI=0.5:Position(3)-0.5;
817nbview=numel(SeriesData.i1_series);
818pair_max=cell(1,nbview);
819for iview=1:nbview
820    pair_max{iview}=squeeze(max(SeriesData.i1_series{iview},[],1)); %max on pair index
821    if (strcmp(get(handles.num_first_j,'Visible'),'off')&& size(pair_max{iview},2)~=1)
822        pair_max{iview}=squeeze(max(pair_max{iview},[],1)); % consider only the i index
823    end
824    index_min(iview)=find(pair_max{iview}>0, 1 );
825    index_max(iview)=find(pair_max{iview}>0, 1, 'last' );
826end
827index_min=min(index_min);
828index_max=max(index_max);
829range_index=index_max-index_min+1;
830scale_y=Position(4)/nbview;
831scale_x=Position(3)/range_index;
832x=(0.5:range_index-0.5)*Position(3)/range_index;
833% y=(0.5:nbview-0.5)*Position(4)/nbview;
834range_y=max(1,floor(Position(4)/nbview));
835CData=zeros(nbview*range_y,Position(3));
836for iview=1:nbview
837    ind_y=1+(iview-1)*range_y:iview*range_y;
838    LineData=zeros(1,range_index);
839    x_index=find(pair_max{iview}>0)-index_min+1;
840    LineData(x_index)=1;
841    if numel(x)>1
842    LineData=interp1(x,LineData,xI,'nearest');
843    CData(ind_y,:)=ones(size(ind_y'))*LineData;
844    end
845end
846CData=cat(3,zeros(size(CData)),CData,zeros(size(CData)));
847set(handles.FileStatus,'CData',CData);
848
849
850%% enable field and veltype menus, in accordance with the current action
851ActionName_Callback([],[], handles)
852
853%% check for pair display
854check_pairs=0;
855for iview=1:numel(SeriesData.i2_series)
856    if ~isempty(SeriesData.i2_series{iview})||~isempty(SeriesData.j2_series{iview})
857        check_pairs=1;
858    end
859end
860if check_pairs
861    set(handles.Pairs,'Visible','on')
862    set(handles.PairString,'Visible','on')
863else
864    set(handles.Pairs,'Visible','off')
865    set(handles.PairString,'Visible','off')
866end
867
868%% set length of waitbar
869displ_time(handles)
870
871
872%% set default options in menu 'Fields'
873switch FileType
874    case {'civx','civdata'}
875        [FieldList,ColorList]=calc_field;
876        set(handles.FieldName,'String',[{'image'};FieldList;{'get_field...'}]);%standard menu for civx data
877        set(handles.FieldName,'Value',2) % set menu to 'velocity
878        set(handles.Coord_x,'Value',1);
879        set(handles.Coord_x,'String',{'X'});
880        set(handles.Coord_y,'Value',1);
881        set(handles.Coord_y,'String',{'Y'});
882    case 'netcdf'
883        set(handles.FieldName,'Value',1)
884        set(handles.FieldName,'String',{'get_field...'})
885        if isempty(i2_series)
886            i2=[];
887        else
888            i2=i2_series(1,ref_j+1,ref_i+1);
889        end
890        if isempty(j1_series)
891            j1=[];j2=[];
892        else
893            j1=j1_series(1,ref_j+1,ref_i+1);
894            if isempty(j2_series)
895                j2=[];
896            else
897                j2=j2_series(1,ref_j+1,ref_i+1);
898            end
899        end
900        FileName=fullfile_uvmat(InputTable{iview,1},InputTable{iview,2},InputTable{iview,3},InputTable{iview,5},InputTable{iview,4},i1_series(1,ref_j+1,ref_i+1),i2,j1,j2);
901%         hget_field=get_field(FileName);
902%         hhget_field=guidata(hget_field);
903%         get_field('RUN_Callback',hhget_field.RUN,[],hhget_field);
904    otherwise
905        set(handles.FieldName,'Value',1) % set menu to 'image'
906        set(handles.FieldName,'String',{'image'})
907        set(handles.Coord_x,'Value',1);
908        set(handles.Coord_x,'String',{'AX'});
909        set(handles.Coord_y,'Value',1);
910        set(handles.Coord_y,'String',{'AY'});
911end
912
913%------------------------------------------------------------------------
914function num_first_i_Callback(hObject, eventdata, handles)
915%------------------------------------------------------------------------
916num_last_i_Callback(hObject, eventdata, handles)
917
918%------------------------------------------------------------------------
919function num_last_i_Callback(hObject, eventdata, handles)
920%------------------------------------------------------------------------
921SeriesData=get(handles.series,'UserData');
922if ~isfield(SeriesData,'Time')
923    SeriesData.Time{1}=[];
924end
925displ_time(handles);
926
927%------------------------------------------------------------------------
928function num_first_j_Callback(hObject, eventdata, handles)
929%------------------------------------------------------------------------
930 num_last_j_Callback(hObject, eventdata, handles)
931
932%------------------------------------------------------------------------
933function num_last_j_Callback(hObject, eventdata, handles)
934%------------------------------------------------------------------------
935first_j=str2num(get(handles.num_first_j,'String'));
936last_j=str2num(get(handles.num_last_j,'String'));
937ref_j=ceil((first_j+last_j)/2);
938set(handles.num_ref_j,'String', num2str(ref_j))
939num_ref_j_Callback(hObject, eventdata, handles)
940SeriesData=get(handles.series,'UserData');
941if ~isfield(SeriesData,'Time')
942    SeriesData.Time{1}=[];
943end
944displ_time(handles);
945
946
947%------------------------------------------------------------------------
948% ---- find the times corresponding to the first and last indices of a series
949function displ_time(handles)
950%------------------------------------------------------------------------
951SeriesData=get(handles.series,'UserData');%
952ref_i=[str2num(get(handles.num_first_i,'String')) str2num(get(handles.num_last_i,'String'))];
953ref_j=[str2num(get(handles.num_first_j,'String')) str2num(get(handles.num_last_j,'String'))];
954TimeTable=get(handles.TimeTable,'Data');
955Pairs=get(handles.PairString,'Data');
956for iview=1:size(TimeTable,1)
957    if size(SeriesData.Time,1)<iview
958        break
959    end
960    i1=ref_i;
961    j1=ref_j;
962    i2=ref_i;
963    j2=ref_j;
964    % case of pairs
965    if ~isempty(Pairs{iview,1})
966        r=regexp(Pairs{iview,1},'(?<mode>(Di=)|(Dj=)) -*(?<num1>\d+)\|(?<num2>\d+)','names');
967        if isempty(r)
968            r=regexp(Pairs{iview,1},'(?<num1>\d+)(?<mode>-)(?<num2>\d+)','names');
969        end
970        switch r.mode
971            case 'Di='  %  case 'series(Di)')
972                i1=ref_i-str2num(r.num1);
973                i2=ref_i+str2num(r.num2);
974            case 'Dj='  %  case 'series(Dj)'
975                j1=ref_j-str2num(r.num1);
976                j2=ref_j+str2num(r.num2);
977            case '-'  % case 'bursts'
978                j1=str2num(r.num1)*ones(size(ref_i));
979                j2=str2num(r.num2)*ones(size(ref_i));
980        end
981    end
982    TimeTable{iview,2}=[];
983    TimeTable{iview,3}=[];
984    if size(SeriesData.Time{iview},1)>=i2(2)&&size(SeriesData.Time{iview},1)>=j2(2)
985        if isempty(ref_j)
986            time_first=(SeriesData.Time{iview}(i1(1))+SeriesData.Time{iview}(i2(1)))/2;
987            time_last=(SeriesData.Time{iview}(i1(2))+SeriesData.Time{iview}(i2(2)))/2;
988        else
989            time_first=(SeriesData.Time{iview}(i1(1),j1(1))+SeriesData.Time{iview}(i2(1),j2(1)))/2;
990            time_last=(SeriesData.Time{iview}(i1(2),j1(2))+SeriesData.Time{iview}(i2(2),j2(2)))/2;
991        end
992        TimeTable{iview,2}=time_first; %TODO: take into account pairs
993        TimeTable{iview,3}=time_last; %TODO: take into account pairs
994    end
995end
996set(handles.TimeTable,'Data',TimeTable)
997
998%% set the waitbar position with respect to the min and max in the series
999for iview=1:numel(SeriesData.i1_series)
1000    pair_max{iview}=squeeze(max(SeriesData.i1_series{iview},[],1)); %max on pair index
1001    if (strcmp(get(handles.num_first_j,'Visible'),'off')&& size(pair_max{iview},2)~=1)
1002        pair_max{iview}=squeeze(max(pair_max{iview},[],1)); % consider only the i index
1003    end
1004    pair_max{iview}=reshape(pair_max{iview},1,[]);
1005    index_min(iview)=find(pair_max{iview}>0, 1 );
1006    index_max(iview)=find(pair_max{iview}>0, 1, 'last' );
1007end
1008[index_min,iview_min]=min(index_min);
1009[index_max,iview_max]=min(index_max);
1010if size(SeriesData.i1_series{iview_min},2)==1% movie
1011    index_first=ref_i(1);
1012    index_last=ref_i(2);
1013else
1014    index_first=(ref_i(1)-1)*(size(SeriesData.i1_series{iview_min},1))+ref_j(1)+1;
1015    index_last=(ref_i(2)-1)*(size(SeriesData.i1_series{iview_max},1))+ref_j(2)+1;
1016end
1017range=index_max-index_min+1;
1018coeff_min=(index_first-index_min)/range;
1019coeff_max=(index_last-index_min+1)/range;
1020Position=get(handles.Waitbar,'Position');% position of the waitbar:= [ x,y, width, height]
1021Position_status=get(handles.FileStatus,'Position');
1022Position(1)=coeff_min*Position_status(3)+Position_status(1);
1023Position(3)=Position_status(3)*(coeff_max-coeff_min);
1024set(handles.Waitbar,'Position',Position)
1025update_waitbar(handles.Waitbar,0)
1026
1027%------------------------------------------------------------------------
1028% --- Executes when selected cell(s) is changed in PairString.
1029function PairString_CellSelectionCallback(hObject, eventdata, handles)
1030%------------------------------------------------------------------------   
1031set(handles.ListView,'Value',eventdata.Indices(1))% detect the selected raw index
1032ListView_Callback ([],[],handles) % update the list of available pairs
1033
1034%------------------------------------------------------------------------
1035%------------------------------------------------------------------------
1036%  III - FUNCTIONS ASSOCIATED TO THE FRAME SET PAIRS
1037%------------------------------------------------------------------------
1038%------------------------------------------------------------------------
1039% --- Executes on selection change in ListView.
1040function ListView_Callback(hObject, eventdata, handles)
1041%------------------------------------------------------------------------   
1042SeriesData=get(handles.series,'UserData');
1043i2_series=[];
1044j2_series=[];
1045iview=get(handles.ListView,'Value');
1046if ~isempty(SeriesData.i2_series{iview})
1047    i2_series=SeriesData.i2_series{iview};
1048end
1049if ~isempty(SeriesData.j2_series{iview})
1050    j2_series=SeriesData.j2_series{iview};
1051end
1052update_mode(handles,SeriesData.i1_series{iview},SeriesData.i2_series{iview},...
1053    SeriesData.j1_series{iview},SeriesData.j2_series{iview},SeriesData.Time{iview})
1054
1055%------------------------------------------------------------------------
1056% --- Executes on button press in mode.
1057function mode_Callback(hObject, eventdata, handles)
1058%------------------------------------------------------------------------       
1059SeriesData=get(handles.series,'UserData');
1060iview=get(handles.ListView,'Value');
1061mode_list=get(handles.mode,'String');
1062mode=mode_list{get(handles.mode,'Value')};
1063if isequal(mode,'bursts')
1064    enable_i(handles,'On')
1065    enable_j(handles,'Off') %do not display j index scanning in burst mode (j is fixed by the burst choice)
1066else
1067    enable_i(handles,'On')
1068    enable_j(handles,'Off')
1069end
1070fill_ListPair(handles,SeriesData.i1_series{iview},SeriesData.i2_series{iview},...
1071    SeriesData.j1_series{iview},SeriesData.j2_series{iview},SeriesData.Time{iview})
1072ListPairs_Callback([],[],handles)
1073
1074%-------------------------------------------------------------
1075% --- Executes on selection in ListPairs.
1076function ListPairs_Callback(hObject,eventdata,handles)
1077%------------------------------------------------------------
1078list_pair=get(handles.ListPairs,'String');%get the menu of image pairs
1079if isempty(list_pair)
1080    string='';
1081else
1082    string=list_pair{get(handles.ListPairs,'Value')};
1083    string=regexprep(string,',.*','');%removes time indication (after ',')
1084end
1085PairString=get(handles.PairString,'Data');
1086iview=get(handles.ListView,'Value');
1087PairString{iview,1}=string;
1088% report the selected pair string to the table PairString
1089set(handles.PairString,'Data',PairString)
1090
1091%------------------------------------------------------------------------
1092function num_ref_i_Callback(hObject, eventdata, handles)
1093%------------------------------------------------------------------------
1094mode_list=get(handles.mode,'String');
1095mode=mode_list{get(handles.mode,'Value')};
1096SeriesData=get(handles.series,'UserData');
1097iview=get(handles.ListView,'Value');
1098fill_ListPair(handles,SeriesData.i1_series{iview},SeriesData.i2_series{iview},...
1099    SeriesData.j1_series{iview},SeriesData.j2_series{iview},SeriesData.Time{iview});% update the menu of pairs depending on the available netcdf files
1100ListPairs_Callback([],[],handles)
1101
1102%------------------------------------------------------------------------
1103function num_ref_j_Callback(hObject, eventdata, handles)
1104%------------------------------------------------------------------------
1105num_ref_i_Callback(hObject, eventdata, handles)
1106
1107%------------------------------------------------------------------------
1108function update_mode(handles,i1_series,i2_series,j1_series,j2_series,time)
1109%------------------------------------------------------------------------   
1110% check_burst=0;
1111if isempty(j2_series)% no j pair
1112    if isempty(i2_series)
1113        set(handles.mode,'Value',1)
1114        set(handles.mode,'String',{''})% no pair menu to display
1115    else   
1116        set(handles.mode,'Value',1)
1117        set(handles.mode,'String',{'series(Di)'}) % pair menu with only option Di
1118    end
1119else %existence of j pairs
1120    pair_max=squeeze(max(i1_series,[],1)); %max on pair index
1121    j_max=max(pair_max,[],1);
1122    MaxIndex_i=max(find(j_max))-1;% max ref index i
1123    MinIndex_i=min(find(j_max))-1;% min ref index i
1124    i_max=max(pair_max,[],2);
1125    MaxIndex_j=max(find(i_max))-1;% max ref index i
1126    MinIndex_j=min(find(i_max))-1;% min ref index i
1127    if MaxIndex_j==MinIndex_j
1128        set(handles.mode,'Value',1);
1129        set(handles.mode,'String',{'bursts'})
1130%         check_burst=1;
1131    elseif MaxIndex_i==MinIndex_i
1132        set(handles.mode,'Value',1);
1133        set(handles.mode,'String',{'series(Dj)'})
1134    else
1135        set(handles.mode,'String',{'bursts';'series(Dj)'})
1136        if (MaxIndex_j-MinIndex_j)>10
1137            set(handles.mode,'Value',2);%set mode to series(Dj) if more than 10 j values
1138        else
1139            set(handles.mode,'Value',1);
1140%             check_burst=1;
1141        end
1142    end
1143end
1144% if check_burst
1145%     enable_i(handles,'On')
1146%     enable_j(handles,'Off') %do not display j index scanning in burst mode (j is fixed by the burst choice)
1147% else
1148%     enable_i(handles,'On')
1149%     if isempty(j1_series)
1150%          enable_j(handles,'Off')
1151%     else
1152%         enable_j(handles,'On')
1153%     end
1154% end
1155fill_ListPair(handles,i1_series,i2_series,j1_series,j2_series,time)
1156ListPairs_Callback([],[],handles)
1157
1158%--------------------------------------------------------------
1159% determine the menu for civ1 pairstring depending on existing netcdf files
1160% with the reference indices num_ref_i and num_ref_j
1161%----------------------------------------------------------------
1162function fill_ListPair(handles,i1_series,i2_series,j1_series,j2_series,time)
1163
1164mode_list=get(handles.mode,'String');
1165mode=mode_list{get(handles.mode,'Value')};
1166ref_i=str2num(get(handles.num_ref_i,'String'));
1167if isempty(ref_i)
1168    ref_i=1;
1169end
1170if strcmp(get(handles.num_ref_j,'Visible'),'on')
1171    ref_j=str2num(get(handles.num_ref_j,'String'));
1172    if isempty(ref_j)
1173        ref_j=1;
1174    end
1175else
1176    ref_j=1;
1177end
1178TimeUnit=get(handles.TimeUnit,'String');
1179if length(TimeUnit)>=1
1180    dtunit=['m' TimeUnit];
1181else
1182    dtunit='e-03';
1183end
1184
1185displ_pair={};
1186if strcmp(mode,'series(Di)')
1187    if isempty(i2_series)
1188        msgbox_uvmat('ERROR','no i1-i2 pair available')
1189        return
1190    end
1191    diff_i=i2_series-i1_series;
1192    min_diff=min(diff_i(diff_i>0));
1193    max_diff=max(diff_i(diff_i>0));
1194    for ipair=min_diff:max_diff
1195        if numel(diff_i(diff_i==ipair))>0
1196            pair_string=['Di= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ];
1197            if ~isempty(time)
1198                if ref_i<=floor(ipair/2)
1199                    ref_i=floor(ipair/2)+1;% shift ref_i to get the first pair
1200                end
1201                Dt=time(ref_i+ceil(ipair/2),ref_j)-time(ref_i-floor(ipair/2),ref_j);
1202                pair_string=[pair_string ', Dt=' num2str(Dt) ' ' dtunit];
1203            end
1204            displ_pair=[displ_pair;{pair_string}];
1205        end
1206    end
1207    if ~isempty(displ_pair)
1208        displ_pair=[displ_pair;{'Di=*|*'}];
1209    end
1210elseif strcmp(mode,'series(Dj)')
1211    if isempty(j2_series)
1212        msgbox_uvmat('ERROR','no j1-j2 pair available')
1213        return
1214    end
1215    diff_j=j2_series-j1_series;
1216    min_diff=min(diff_j(diff_j>0));
1217    max_diff=max(diff_j(diff_j>0));
1218    for ipair=min_diff:max_diff
1219        if numel(diff_j(diff_j==ipair))>0
1220            pair_string=['Dj= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ];
1221            if ~isempty(time)
1222                if ref_j<=floor(ipair/2)
1223                    ref_j=floor(ipair/2)+1;% shift ref_i to get the first pair
1224                end
1225                Dt=time(ref_i,ref_j+ceil(ipair/2))-time(ref_i,ref_j-floor(ipair/2));
1226                pair_string=[pair_string ', Dt=' num2str(Dt) ' ' dtunit];
1227            end
1228            displ_pair=[displ_pair;{pair_string}];
1229        end
1230    end
1231    if ~isempty(displ_pair)
1232        displ_pair=[displ_pair;{'Dj=*|*'}];
1233    end
1234elseif strcmp(mode,'bursts')
1235    if isempty(j2_series)
1236        msgbox_uvmat('ERROR','no j1-j2 pair available')
1237        return
1238    end
1239    diff_j=j2_series-j1_series;
1240    min_j1=min(j1_series(j1_series>0));
1241    max_j1=max(j1_series(j1_series>0));
1242    min_j2=min(j2_series(j2_series>0));
1243    max_j2=max(j2_series(j2_series>0));
1244    for pair1=min_j1:min(max_j1,min_j1+20)
1245        for pair2=min_j2:min(max_j2,min_j2+20)
1246        if numel(j1_series(j1_series==pair1))>0 && numel(j2_series(j2_series==pair2))>0
1247            displ_pair=[displ_pair;{['j= ' num2str(pair1) '-' num2str(pair2)]}];
1248        end
1249        end
1250    end
1251    if ~isempty(displ_pair)
1252        displ_pair=[displ_pair;{'j=*-*'}];
1253    end
1254end
1255set(handles.num_ref_i,'String',num2str(ref_i)) % update ref_i and ref_j
1256set(handles.num_ref_j,'String',num2str(ref_j))
1257
1258%% display list of pairstring
1259displ_pair_list=get(handles.ListPairs,'String');
1260NewVal=[];
1261if ~isempty(displ_pair_list)
1262Val=get(handles.ListPairs,'Value');
1263NewVal=find(strcmp(displ_pair_list{Val},displ_pair),1);% look at the previous display in the new menu displ_pï¿œir
1264end
1265if ~isempty(NewVal)
1266    set(handles.ListPairs,'Value',NewVal)
1267else
1268    set(handles.ListPairs,'Value',1)
1269end
1270set(handles.ListPairs,'String',displ_pair)
1271
1272%-------------------------------------
1273function enable_i(handles,state)
1274set(handles.i_txt,'Visible',state)
1275set(handles.num_first_i,'Visible',state)
1276set(handles.num_last_i,'Visible',state)
1277set(handles.num_incr_i,'Visible',state)
1278% set(handles.num_MaxIndex_i,'Visible',state)
1279set(handles.num_ref_i,'Visible',state)
1280set(handles.ref_i_text,'Visible',state)
1281
1282%-----------------------------------
1283function enable_j(handles,state)
1284set(handles.j_txt,'Visible',state)
1285set(handles.num_first_j,'Visible',state)
1286set(handles.num_last_j,'Visible',state)
1287set(handles.num_incr_j,'Visible',state)
1288set(handles.num_ref_j,'Visible',state)
1289set(handles.ref_j_text,'Visible',state)
1290% if strcmp(state,'off')
1291%     set(handles.MinIndex,'ColumnName',{'imax'})
1292% set(handles.MinIndex,'ColumnEditable',logical(0))
1293% else
1294%         set(handles.MinIndex,'ColumnName',{'imax','jmax'})
1295% end
1296
1297
1298%%%%%%%%%%%%%%%%%%%%
1299%%  MAIN ActionName FUNCTIONS
1300%%%%%%%%%%%%%%%%%%%%
1301%------------------------------------------------------------------------
1302% --- Executes on button press in RUN.
1303function RUN_Callback(hObject, eventdata, handles)
1304%------------------------------------------------------------------------
1305
1306set(handles.RUN,'BusyAction','queue');
1307set(0,'CurrentFigure',handles.series)
1308set(handles.RUN, 'Enable','Off')
1309set(handles.RUN,'BackgroundColor',[0.831 0.816 0.784])
1310drawnow
1311
1312%% read the input parameters and set the output dir and nomenclature
1313[Series,OutputDir,errormsg]=prepare_jobs(handles);% get parameters form the GUI series
1314if ~isempty(errormsg)
1315    msgbox_uvmat('ERROR',errormsg)
1316    return
1317end
1318OutputNomType=nomtype2pair(Series.InputTable{1,4});% nomenclature for output files
1319DirXml=fullfile(OutputDir,'0_XML');
1320if ~exist(DirXml,'dir')
1321    [tild,msg1]=mkdir(DirXml);
1322    if ~strcmp(msg1,'')
1323        msgbox_uvmat('ERROR',['cannot create ' DirXml ': ' msg1]);%error message for directory creation
1324        return
1325    end
1326end
1327
1328%% select the Action modes
1329RunModeList=get(handles.RunMode,'String');
1330RunMode=RunModeList{get(handles.RunMode,'Value')};
1331ActionExt='.m';%default
1332if isfield(Series.Action,'ActionExt')
1333    ActionExt=Series.Action.ActionExt;% '.m' or '.sh' (compiled)
1334end
1335ActionName=Series.Action.ActionName;
1336ActionPath=Series.Action.ActionPath;
1337path_series=fileparts(which('series'));
1338
1339%% create the Action fct handle if RunMode option = 'local'
1340if strcmp(RunMode,'local')
1341    if ~isequal(ActionPath,path_series)
1342        eval(['spath=which(''' ActionName ''');']) %spath = current path of the selected function ACTION
1343        if ~exist(ActionPath,'dir')
1344            msgbox_uvmat('ERROR',['The prescribed function path ' ActionPath ' does not exist']);
1345            return
1346        end
1347        if ~isequal(spath,ActionPath)
1348            addpath(ActionPath)% add the prescribed path if not the current one
1349        end
1350    end
1351    eval(['h_fun=@' ActionName ';'])%create a function handle for ACTION
1352    if ~isequal(ActionPath,path_series)
1353        rmpath(ActionPath)% add the prescribed path if not the current one
1354    end
1355end
1356
1357%% Get RunTime code from the file PARAM.xml (needed to run compiled functions)
1358errormsg='';%default error message
1359xmlfile=fullfile(path_series,'PARAM.xml');
1360test_batch=0;%default: ,no batch mode available
1361if ~exist(xmlfile,'file')
1362    [success,message]=copyfile(fullfile(path_series,'PARAM.xml.default'),xmlfile);
1363end
1364RunTime='';
1365if strcmp(ActionExt,'.sh')
1366    if exist(xmlfile,'file')
1367        s=xml2struct(xmlfile);
1368        if strcmp(RunMode,'cluster') && isfield(s,'BatchParam')
1369            if isfield(s.BatchParam,'RunTime')
1370                RunTime=s.BatchParam.RunTime;
1371            end
1372            if isfield(s.BatchParam,'NbCore')
1373                NbCore=s.BatchParam.NbCore;
1374            end
1375        elseif (strcmp(RunMode,'background')||strcmp(RunMode,'local')) && isfield(s,'RunParam')
1376            if isfield(s.RunParam,'RunTime')
1377                RunTime=s.RunParam.RunTime;
1378            end
1379            if isfield(s.RunParam,'NbCore')
1380                NbCore=s.RunParam.NbCore;
1381            end
1382        end
1383    end
1384    if isempty(RunTime) && strcmp(RunMode,'cluster')
1385        msgbox_uvmat('ERROR','RunTime name not found in PARAM.xml, compiled version .sh cannot run on cluster')
1386        return
1387    end
1388    Series.RunTime=RunTime;
1389end
1390
1391%% set nbre of cluster cores and processes
1392switch RunMode
1393    case {'local','background'}
1394        NbCore=1;% no need to split the calculation
1395    case 'cluster_oar'
1396        if strcmp(Series.Action.ActionExt,'.m')% case of Matlab function (uncompiled)
1397            NbCore=1;% one core used only (limitation of Matlab licences)
1398            msgbox_uvmat('WARNING','Number of cores =1: select the compiled version civ_matlab.sh for multi-core processing');
1399            extra_oar='';
1400        else
1401            answer=inputdlg({'Number of cores (max 36)','extra oar options'},'oarsub parameter',1,{'12',''});
1402            NbCore=str2double(answer{1});
1403            extra_oar=answer{2};
1404        end
1405end
1406if ~isfield(Series.IndexRange,'NbSlice')
1407    Series.IndexRange.NbSlice=[];
1408end
1409if isempty(Series.IndexRange.NbSlice)
1410    NbProcess=NbCore;% choose one process per core
1411else
1412    NbProcess=Series.IndexRange.NbSlice;% the nbre of run processes is equal to the number of slices
1413    NbCore=min(NbCore,NbProcess);% at least one process per core
1414end
1415
1416%% read index ranges
1417first_i=1;
1418last_i=1;
1419incr_i=1;
1420first_j=1;
1421last_j=1;
1422if isfield(Series.IndexRange,'first_i')
1423    first_i=Series.IndexRange.first_i;
1424    incr_i=Series.IndexRange.incr_i;
1425    last_i=Series.IndexRange.last_i;
1426end
1427if isfield(Series.IndexRange,'first_j')
1428    first_j=Series.IndexRange.first_j;
1429    last_j=Series.IndexRange.last_j;
1430end
1431if last_i < first_i || last_j < first_j , msgbox_uvmat('ERROR','last field number must be larger than the first one'),...
1432        set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return
1433else
1434    BlockLength=ceil(numel(first_i:incr_i:last_i)/NbProcess);
1435end
1436
1437%% direct processing on the current Matlab session
1438if strcmp (RunMode,'local')
1439    Series.RUNHandle=handles.RUN;
1440    Series.WaitbarHandle=handles.Waitbar;
1441    for iprocess=1:NbProcess
1442        if isempty(Series.IndexRange.NbSlice)
1443            Series.IndexRange.first_i=first_i+(iprocess-1)*BlockLength;
1444            Series.IndexRange.last_i=first_i+(iprocess)*BlockLength-1;
1445        else
1446            Series.IndexRange.first_i= first_i+iprocess-1;
1447            Series.IndexRange.incr_i=incr_i*Series.IndexRange.NbSlice;
1448        end
1449        t=struct2xml(Series);
1450        t=set(t,1,'name','Series');
1451        filexml=fullfile_uvmat(DirXml,'',Series.InputTable{1,3},'.xml',OutputNomType,...
1452            Series.IndexRange.first_i,Series.IndexRange.last_i,first_j,last_j);
1453        save(t,filexml);
1454        switch ActionExt
1455            case '.m'
1456                h_fun(Series);
1457            case '.sh'
1458                switch computer
1459                    case {'PCWIN','PCWIN64'} %Windows system
1460                        filexml=regexprep(filexml,'\\','\\\\');% add '\' so that '\' are left as characters
1461                        system([fullfile(ActionPath,[ActionName '.sh']) ' ' Series.RunTime ' ' filexml]);% TODO: adapt to DOS system
1462                    case {'GLNX86','GLNXA64','MACI64'}%Linux  system
1463                        system([fullfile(ActionPath,[ActionName '.sh']) ' ' Series.RunTime ' ' filexml]);
1464                end
1465        end
1466    end
1467elseif strcmp(get(handles.OutputDirExt,'Visible'),'off')
1468    msgbox_uvmat('ERROR',['no output file for Action ' ActionName ', use run mode = local']);% a output dir is needed for background option
1469    return
1470else
1471    %% processing on a different session of the same computer (background) or cluster, create executable files
1472    batch_file_list=cell(NbProcess,1);% initiate the list of executable files
1473    DirBat=fullfile(OutputDir,'0_BAT');
1474    %create subdirectory for executable files
1475    if ~exist(DirBat,'dir')
1476        [tild,msg1]=mkdir(DirBat);
1477        if ~strcmp(msg1,'')
1478            msgbox_uvmat('ERROR',['cannot create ' DirBat ': ' msg1]);%error message for directory creation
1479            return
1480        end
1481    end
1482    %create subdirectory for log files
1483    DirLog=fullfile(OutputDir,'0_LOG');
1484    if ~exist(DirLog,'dir')
1485        [tild,msg1]=mkdir(DirLog);
1486        if ~strcmp(msg1,'')
1487            msgbox_uvmat('ERROR',['cannot create ' DirLog ': ' msg1]);%error message for directory creation
1488            return
1489        end
1490    end
1491    for iprocess=1:NbProcess
1492        if isempty(Series.IndexRange.NbSlice)% process by blocks of i index
1493            Series.IndexRange.first_i=first_i+(iprocess-1)*BlockLength;
1494            Series.IndexRange.last_i=first_i+(iprocess)*BlockLength-1;
1495        else% process by slices of i index if NbSlice is defined, computation in a single process if NbSlice =1
1496            Series.IndexRange.first_i= first_i+iprocess-1;
1497            Series.IndexRange.incr_i=incr_i*Series.IndexRange.NbSlice;
1498        end
1499       
1500        % create, fill and save the xml parameter file
1501        t=struct2xml(Series);
1502        t=set(t,1,'name','Series');
1503        filexml=fullfile_uvmat(DirXml,'',Series.InputTable{1,3},'.xml',OutputNomType,...
1504            Series.IndexRange.first_i,Series.IndexRange.last_i,first_j,last_j);
1505        save(t,filexml);% save the parameter file
1506       
1507        %create the executable file
1508        filebat=fullfile_uvmat(DirBat,'',Series.InputTable{1,3},'.bat',OutputNomType,...
1509            Series.IndexRange.first_i,Series.IndexRange.last_i,first_j,last_j);
1510        batch_file_list{iprocess}=filebat;
1511        [fid,message]=fopen(filebat,'w');% create the executable file
1512        if isequal(fid,-1)
1513            msgbox_uvmat('ERROR', ['creation of .bat file: ' message]);
1514            return
1515        end
1516       
1517        % set the log file name
1518        filelog=fullfile_uvmat(DirLog,'',Series.InputTable{1,3},'.log',OutputNomType,...
1519            Series.IndexRange.first_i,Series.IndexRange.last_i,first_j,last_j);
1520       
1521        % fill and save the executable file
1522        switch ActionExt
1523            case '.m'% Matlab function
1524                switch computer
1525                    case {'GLNX86','GLNXA64','MACI64'}
1526                        cmd=[...
1527                            '#!/bin/bash \n'...
1528                            '. /etc/sysprofile \n'...
1529                            'matlab -nodisplay -nosplash -nojvm -logfile ''' filelog ''' <<END_MATLAB \n'...
1530                            'addpath(''' path_series '''); \n'...
1531                            'addpath(''' Series.Action.ActionPath '''); \n'...
1532                            '' Series.Action.ActionName  '( ''' filexml '''); \n'...
1533                            'exit \n'...
1534                            'END_MATLAB \n'];
1535                        fprintf(fid,cmd);%fill the executable file with the  char string cmd
1536                        fclose(fid);% close the executable file
1537                        system(['chmod +x ' filebat]);% set the file to executable
1538                    case {'PCWIN','PCWIN64'}
1539                        text_matlabscript=['matlab -automation -logfile ' regexprep(filelog,'\\','\\\\')...
1540                            ' -r "addpath(''' regexprep(path_series,'\\','\\\\') ''');'...
1541                            'addpath(''' regexprep(Series.Action.ActionPath,'\\','\\\\') ''');'...
1542                            '' Series.Action.ActionName  '( ''' regexprep(filexml,'\\','\\\\') ''');exit"'];
1543                        fprintf(fid,text_matlabscript);%fill the executable file with the  char string cmd
1544                        fclose(fid);% close the executable file
1545                end
1546            case '.sh' % compiled Matlab function
1547                switch computer
1548                    case {'GLNX86','GLNXA64','MACI64'}
1549                        cmd=['#!/bin/bash \n '...
1550                            '#$ -cwd \n '...
1551                            'hostname && date \n '...
1552                            'umask 002 \n'...
1553                            fullfile(ActionPath,[ActionName '.sh']) ' ' Series.RunTime ' ' filexml];%allow writting access to created files for user group
1554                        fprintf(fid,cmd);%fill the executable file with the  char string cmd
1555                        fclose(fid);% close the executable file
1556                        system(['chmod +x ' filebat]);% set the file to executable
1557                       
1558                    case {'PCWIN','PCWIN64'}    %       TODO: adapt to Windows system
1559                        %                                 cmd=['matlab -automation -logfile ' regexprep(filelog,'\\','\\\\')...
1560                        %                                     ' -r "addpath(''' regexprep(path_series,'\\','\\\\') ''');'...
1561                        %                                     'addpath(''' regexprep(Series.Action.ActionPath,'\\','\\\\') ''');'...
1562                        %                                     '' Series.Action.ActionName  '( ''' regexprep(filexml,'\\','\\\\') ''');exit"'];
1563                        fprintf(fid,cmd);
1564                        fclose(fid);
1565                        %                               dos([filebat ' &']);
1566                end
1567        end
1568    end
1569end
1570
1571%% launch the executable files for background or cluster processing
1572switch RunMode
1573    case 'background'
1574        for iprocess=1:NbProcess
1575            system(batch_file_list{iprocess})% directly execute the command file for each process
1576        end
1577    case 'cluster_oar' % option 'oar-parexec' used
1578        %create subdirectory for oar command and log files
1579        DirOAR=fullfile(OutputDir,'0_OAR');
1580        if ~exist(DirOAR,'dir')
1581            [tild,msg1]=mkdir(DirOAR);
1582            if ~strcmp(msg1,'')
1583                msgbox_uvmat('ERROR',['cannot create ' DirOAR ': ' msg1]);%error message for directory creation
1584                return
1585            end
1586        end
1587        max_walltime=3600*12; % 12h max
1588        walltime_onejob=600;%seconds
1589        filename_joblist=fullfile(DirOAR,'job_list.txt');%create name of the global executable file
1590        fid=fopen(filename_joblist,'w');
1591        for p=1:length(batch_file_list)
1592            fprintf(fid,[batch_file_list{p} '\n']);% list of exe files (TODO: create them)
1593        end
1594        fclose(fid);
1595        system(['chmod +x ' filename_joblist]);% set the file to executable
1596        oar_command=['oarsub -n CIVX '...
1597            '-t idempotent --checkpoint ' num2str(walltime_onejob+60) ' '...
1598            '-l /core=' num2str(NbCore) ','...
1599            'walltime=' datestr(min(1.05*walltime_onejob/86400*max(length(batch_file_list),NbCore)/NbCore,max_walltime/86400),13) ' '...
1600            '-E ' regexprep(filename_joblist,'\.txt\>','.stderr') ' '...
1601            '-O ' regexprep(filename_joblist,'\.txt\>','.stdout') ' '...
1602            extra_oar ' '...
1603            '"oar-parexec -s -f ' filename_joblist ' '...
1604            '-l ' filename_joblist '.log"\n'];
1605        filename_oarcommand=fullfile(DirOAR,'oar_command');
1606        fid=fopen(filename_oarcommand,'w');
1607        fprintf(fid,oar_command);
1608        fclose(fid);
1609        fprintf(oar_command);% display in command line
1610        %system(['chmod +x ' oar_command]);% set the file to executable
1611        system(oar_command);     
1612end
1613
1614%% reset the GUI series
1615update_waitbar(handles.Waitbar,1); % put the waitbar to end position to indicate launching is finished
1616set(handles.RUN, 'Enable','On')
1617set(handles.RUN,'BackgroundColor',[1 0 0])
1618set(handles.RUN, 'Value',0)
1619
1620%------------------------------------------------------------------------
1621function STOP_Callback(hObject, eventdata, handles)
1622%------------------------------------------------------------------------
1623set(handles.RUN, 'BusyAction','cancel')
1624set(handles.RUN,'BackgroundColor',[1 0 0])
1625set(handles.RUN,'enable','on')
1626set(handles.RUN, 'Value',0)
1627
1628% %------------------------------------------------------------------------
1629% % --- Executes on button press in BIN.
1630% function BIN_Callback(hObject, eventdata, handles)
1631% %------------------------------------------------------------------------
1632%     cmd=['#!/bin/bash \n '...
1633%         '#$ -cwd \n '...
1634%         'hostname && date \n '...
1635%         'umask 002 \n'...
1636%         Param.xml.CivmBin ' ' Param.xml.RunTime ' ' filename_xml ' ' OutputFile '.nc'];
1637%     
1638%------------------------------------------------------------------------
1639% --- Main launch command, called by RUN and BATCH
1640
1641function [Series,OutputDir,errormsg]=prepare_jobs(handles)
1642%INPUT:
1643% handles: handles of graphic objects on the GUI series
1644
1645%------------------------------------------------------------------------
1646OutputDir='';
1647errormsg='';
1648
1649%% Read parameters from series
1650Series=read_GUI(handles.series);
1651
1652%% get_field GUI
1653% if isfield(Series,'InputFields')&&isfield(Series.InputFields,'Field')
1654%     if strcmp(Series.InputFields.Field,'get_field...')
1655%         hget_field=findobj(allchild(0),'name','get_field');
1656%         Series.GetField=read_GUI(hget_field);
1657%     end
1658% end
1659
1660%% create the output data directory
1661%determine the root file corresponding to the first sub dir
1662if get(handles.RUN,'value') && isfield(Series,'OutputSubDir')
1663    SubDirOut=[get(handles.OutputSubDir,'String') Series.OutputDirExt];
1664    SubDirOutNew=SubDirOut;
1665    SeriesData=get(handles.series,'UserData');
1666    if size(Series.InputTable,1)>1 && isfield(SeriesData,'AllowInputSort') && SeriesData.AllowInputSort
1667        [tild,iview]=sort(Series.InputTable(:,2)); %subdirectories sorted in alphabetical order
1668        Series.InputTable=Series.InputTable(iview,:);
1669    end
1670    detect=exist(fullfile(Series.InputTable{1,1},SubDirOutNew),'dir');% test if  the dir  already exist
1671    check_create=1; %need to create the result directory by default
1672    while detect
1673        answer=msgbox_uvmat('INPUT_Y-N',['use existing ouput directory: ' fullfile(Series.InputTable{1,1},SubDirOutNew) ', possibly delete previous data']);
1674        if isequal(answer,'Yes')
1675            detect=0;
1676            check_create=0;
1677        else
1678            r=regexp(SubDirOutNew,'(?<root>.*\D)(?<num1>\d+)$','names');%detect whether name ends by a number
1679            if isempty(r)
1680                r(1).root=[SubDirOutNew '_'];
1681                r(1).num1='0';
1682            end
1683            SubDirOutNew=[r(1).root num2str(str2num(r(1).num1)+1)];%increment the index by 1 or put 1
1684            detect=exist(fullfile(Series.InputTable{1,1},SubDirOutNew),'dir');% test if  the dir  already exists   
1685            check_create=1;
1686        end
1687    end
1688    Series.OutputDirExt=regexprep(SubDirOutNew,Series.OutputSubDir,'');
1689    Series.OutputRootFile=Series.InputTable{1,3};% the first sorted RootFile taken for output
1690    set(handles.OutputDirExt,'String',Series.OutputDirExt)
1691    OutputDir=fullfile(Series.InputTable{1,1},[Series.OutputSubDir Series.OutputDirExt]);% full name (with path) of output directory
1692    if check_create    % create output directory if it does not exist
1693        [tild,msg1]=mkdir(OutputDir);
1694        if ~strcmp(msg1,'')
1695            errormsg=['cannot create ' OutputDir ': ' msg1];%error message for directory creation
1696            return
1697        end
1698    end
1699   % RootOut=fullfile(OutputDir,Series.InputTable{1,3});% name of the parameter xml file set in this directory
1700end
1701
1702%% removes unused information on Series
1703if isfield(Series,'Pairs')
1704    Series=rmfield(Series,'Pairs'); %info Pairs not needed for output
1705end
1706Series.IndexRange=rmfield(Series.IndexRange,'TimeTable');
1707Series.IndexRange=rmfield(Series.IndexRange,'MinIndex');
1708Series.IndexRange=rmfield(Series.IndexRange,'MaxIndex');
1709empty_line=false(size(Series.InputTable,1),1);
1710for iline=1:size(Series.InputTable,1)
1711    empty_line(iline)=isequal(Series.InputTable(iline,1:3),{'','',''});
1712end
1713Series.InputTable(empty_line,:)=[];
1714
1715%------------------------------------------------------------------------
1716% --- Executes on selection change in ActionName.
1717function ActionName_Callback(hObject, eventdata, handles)
1718%------------------------------------------------------------------------
1719%% stop any ongoing series processing
1720if isequal(get(handles.RUN,'Value'),1)
1721    answer= msgbox_uvmat('INPUT_Y-N','stop current Action process?');
1722    if strcmp(answer,'Yes')
1723        STOP_Callback(hObject, eventdata, handles)
1724    else
1725        return
1726    end
1727end
1728
1729%% get Action name and path
1730nb_builtin_ACTION=4; %nbre of functions initially proposed in the menu ActionName (as defined in the Opening fct of series)
1731ActionList=get(handles.ActionName,'String');% list menu fields
1732ActionIndex=get(handles.ActionName,'Value');
1733if ~isequal(ActionIndex,1)
1734    InputTable=get(handles.InputTable,'Data');
1735    if isempty(InputTable{1,4})
1736        msgbox_uvmat('ERROR','no input file available: use Open in the menu bar')
1737        return
1738    end
1739end
1740ActionName= ActionList{get(handles.ActionName,'Value')}; % selected function name
1741ActionPathList=get(handles.ActionName,'UserData');%list of recorded paths to functions of the list ActionName
1742
1743%% add a new function to the menu if 'more...' has been selected in the menu ActionName
1744if isequal(ActionName,'more...')
1745    [FileName, PathName] = uigetfile( ...
1746        {'*.m', ' (*.m)';
1747        '*.m',  '.m files '; ...
1748        '*.*', 'All Files (*.*)'}, ...
1749        'Pick a series processing function ',get(handles.ActionPath,'String'));
1750    if length(FileName)<2
1751        return
1752    end
1753    [ActionPath,ActionName,ActionExt]=fileparts(FileName);
1754    % insert the choice in the menu
1755    ActionIndex=find(strcmp(ActionName,ActionList),1);% look for the selected function in the menu Action
1756    if isempty(ActionIndex)%the input string does not exist in the menu
1757        ActionIndex= length(ActionList);
1758        ActionList=[ActionList(1:end-1);{ActionName};ActionList(end)];% the selected function is appended in the menu, before the last item 'more...'
1759        set(handles.ActionName,'String',ActionList)
1760    end
1761    %set(handles.ActionName,'Value',ActionIndex)
1762    %list_path{ActionIndex}=PathName;
1763    % remove old Action options in the menu (keeping a menu length <nb_builtin_ACTION+5)
1764    if length(ActionList)>nb_builtin_ACTION+5; %nb_builtin=nbre of functions always remaining in the initial menu
1765        nbremove=length(ActionList)-nb_builtin_ACTION-5;
1766        ActionList(nb_builtin_ACTION+1:end-5)=[];
1767        ActionPathList(nb_builtin_ACTION+1:end-4)=[];
1768        ActionIndex=ActionIndex-nbremove;
1769    end
1770    set(handles.ActionName,'Value',ActionIndex)
1771    set(handles.ActionName,'String',ActionList)
1772    ActionPathList{ActionIndex}=PathName;
1773    set(handles.ActionPath,'enable','inactive')% indicate that the current path is accessible (not 'off')
1774   
1775    % record the file extension and update the paths in userdata
1776    ActionExtList=get(handles.ActionExt,'String');
1777    ActionExtIndex=find(strcmp(ActionExt,ActionExtList), 1);
1778    if isempty(ActionExtIndex)
1779        set(handles.ActionExt,'String',[ActionExtList;{ActionExt}])
1780        set(handles.ActionExt,'Value',numel(ActionExtList)+1)
1781        ActionPathNew=cell(size(ActionPathList,1),1);%new column of ActionPath
1782        ActionPathNew{ActionIndex}=ActionPath;
1783        ActionPathList=[ActionPathList ActionPathNew];
1784    end
1785    set(handles.ActionName,'UserData',ActionPathList);
1786   
1787    %record the current menu in personal file profil_perso
1788    dir_perso=prefdir;
1789    profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
1790    if nb_builtin_ACTION+1<=length(ActionList)-1
1791        ActionListUser=ActionList(nb_builtin_ACTION+1:numel(ActionList)-1);
1792        ActionPathListUser=ActionPathList(nb_builtin_ACTION+1:numel(ActionList)-1,:);
1793        ActionExtListUser={};
1794        if numel(ActionExtList)>2
1795            ActionExtListUser=ActionExtList(3:end);
1796        end
1797        if exist(profil_perso,'file')
1798            save(profil_perso,'ActionListUser','ActionPathListUser','ActionExtListUser','-append')
1799        else
1800            save(profil_perso,'ActionListUser','ActionPathListUser','ActionExtListUser','-V6')
1801        end
1802    end
1803end
1804
1805%% check the current ActionPath to the selected function
1806ActionPath=ActionPathList{ActionIndex};%current recorded path
1807set(handles.ActionPath,'String',ActionPath); %show the path to the senlected function
1808
1809%% reinitialise the waitbar
1810update_waitbar(handles.Waitbar,0)
1811
1812%% default setting for the visibility of the GUI elements
1813set(handles.FieldTransform,'Visible','off')
1814set(handles.CheckObject,'Visible','off');
1815set(handles.ProjObject,'Visible','off');
1816set(handles.CheckMask,'Visible','off')
1817set(handles.Mask,'Visible','off')
1818
1819%% create the function handle for Action
1820path_series=which('series');
1821if ~isequal(ActionPath,path_series)
1822    eval(['spath=which(''' ActionName ''');']) %spath = current path of the selected function ACTION
1823    if ~exist(ActionPath,'dir')
1824        errormsg=['The prescribed function path ' ActionPath ' does not exist'];
1825        return
1826    end
1827    if ~isequal(spath,ActionPath)
1828        addpath(ActionPath)% add the prescribed path if not the current one
1829    end
1830end
1831eval(['h_fun=@' ActionName ';'])%create a function handle for ACTION
1832if ~isequal(ActionPath,path_series)
1833        rmpath(ActionPath)% add the prescribed path if not the current one   
1834end
1835
1836%% prepare the input param
1837[Series,tild,errormsg]=prepare_jobs(handles);
1838if ~isempty(errormsg)
1839    msgbox_uvmat('ERROR',errormsg)
1840    return
1841end
1842ParamOut=h_fun(Series);
1843
1844%% Put the first line of the selected Action fct as tootip help
1845try
1846    [fid,errormsg] =fopen([ActionName '.m']);
1847    InputText=textscan(fid,'%s',1,'delimiter','\n');
1848    fclose(fid);
1849    set(handles.ActionName,'ToolTipString',InputText{1}{1})% put the first line of the selected function as tooltip help
1850end
1851% if ~isequal(path_series,PathName)
1852%     rmpath(PathName)
1853% end
1854Param_list={};
1855
1856%% Detect the types of input files
1857SeriesData=get(handles.series,'UserData');
1858nb_civ=0;nb_netcdf=0;
1859if ~isempty(SeriesData)
1860    nb_civ=numel(find(strcmp('civx',SeriesData.FileType)|strcmp('civdata',SeriesData.FileType)));
1861    nb_netcdf=numel(find(strcmp('netcdf',SeriesData.FileType)));
1862end
1863
1864%% Check whether alphabetical sorting of input Subdir is alowed by the Action fct  (for multiples series entries)
1865SeriesData.AllowInputSort=0;%default
1866if isfield(ParamOut,'AllowInputSort')&&isequal(ParamOut.AllowInputSort,'on')
1867    SeriesData.AllowInputSort=1;
1868end
1869
1870%% Impose the whole input file index range if requested
1871if isfield(ParamOut,'WholeIndexRange')&&isequal(ParamOut.WholeIndexRange,'on')
1872    MinIndex=get(handles.MinIndex,'Data');
1873    MaxIndex=get(handles.MaxIndex,'Data');
1874    if ~isempty(MinIndex)
1875        set(handles.num_first_i,'String',num2str(MinIndex{1}))
1876        set(handles.num_last_i,'String',num2str(MaxIndex{1}))
1877        set(handles.num_incr_i,'String','1')
1878        if size(MinIndex,2)>=2
1879            set(handles.num_first_j,'String',num2str(MinIndex{1,2}))
1880            set(handles.num_last_j,'String',num2str(MaxIndex{1,2}))
1881            set(handles.num_incr_j,'String','1')
1882        end
1883    end
1884else
1885% check index ranges
1886first_i=1;last_i=1;first_j=1;last_j=1;
1887if isfield(Series.IndexRange,'first_i')
1888    first_i=Series.IndexRange.first_i;
1889    last_i=Series.IndexRange.last_i;
1890end
1891if isfield(Series.IndexRange,'first_j')
1892    first_j=Series.IndexRange.first_j;
1893    last_j=Series.IndexRange.last_j;
1894end
1895if last_i < first_i || last_j < first_j , msgbox_uvmat('ERROR','last field number must be larger than the first one'),...
1896    set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
1897end
1898
1899%% NbSlice visibility
1900NbSliceVisible='off';%default
1901if isfield(ParamOut,'NbSlice') && isequal(ParamOut.NbSlice,'on')
1902    NbSliceVisible='on';
1903    set(handles.num_NbProcess,'String',get(handles.num_NbSlice,'String'))% the nbre of processes is imposed as the nbre of slices
1904else
1905    set(handles.num_NbProcess,'String','')% free nbre of processes
1906end
1907set(handles.num_NbSlice,'Visible',NbSliceVisible)
1908set(handles.NbSlice_title,'Visible',NbSliceVisible)
1909
1910%% Visibility of VelType and VelType_1 menus
1911VelTypeVisible='off';  %hidden by default
1912VelType_1Visible='off';
1913InputFieldsVisible='off';%visibility of the frame Fields
1914if isfield(ParamOut,'VelType')
1915    if strcmp( ParamOut.VelType,'one')||strcmp( ParamOut.VelType,'two')
1916        if nb_civ>=1
1917            VelTypeVisible='on';
1918            InputFieldsVisible='on';
1919        end
1920    end
1921    if strcmp( ParamOut.VelType,'two')
1922        if nb_civ>=2
1923            VelType_1Visible='on';
1924        end
1925    end
1926end
1927set(handles.VelType,'Visible',VelTypeVisible)
1928set(handles.VelType_text,'Visible',VelTypeVisible);
1929set(handles.VelType_1,'Visible',VelType_1Visible)
1930set(handles.VelType_text_1,'Visible',VelType_1Visible);
1931
1932%% Visibility of FieldName and FieldName_1 menus
1933FieldNameVisible='off';  %hidden by default
1934FieldName_1Visible='off';  %hidden by default
1935if isfield(ParamOut,'FieldName')
1936    if strcmp( ParamOut.FieldName,'one')||strcmp( ParamOut.FieldName,'two')
1937        if (nb_civ+nb_netcdf)>=1
1938            InputFieldsVisible='on';
1939            FieldNameVisible='on';
1940        end
1941    end
1942    if strcmp( ParamOut.FieldName,'two')
1943        if (nb_civ+nb_netcdf)>=1
1944            FieldName_1Visible='on';
1945        end
1946    end
1947end
1948set(handles.InputFields,'Visible',InputFieldsVisible)
1949set(handles.FieldName,'Visible',FieldNameVisible) % test for MenuBorser
1950set(handles.FieldName_1,'Visible',FieldName_1Visible)
1951
1952%% Visibility of FieldTransform menu
1953FieldTransformVisible='off';  %hidden by default
1954if isfield(ParamOut,'FieldTransform')
1955    FieldTransformVisible=ParamOut.FieldTransform; 
1956    TransformName_Callback([],[], handles)
1957end
1958set(handles.FieldTransform,'Visible',FieldTransformVisible)
1959
1960%% Visibility of projection object
1961ProjObjectVisible='off';  %hidden by default
1962if isfield(ParamOut,'ProjObject')
1963    ProjObjectVisible=ParamOut.ProjObject;
1964end
1965set(handles.CheckObject,'Visible',ProjObjectVisible)
1966if ~get(handles.CheckObject,'Value')
1967    ProjObjectVisible='off';
1968end
1969set(handles.ProjObject,'Visible',ProjObjectVisible)
1970set(handles.DeleteObject,'Visible',ProjObjectVisible)
1971set(handles.ViewObject,'Visible',ProjObjectVisible)
1972
1973
1974%% Visibility of mask input
1975MaskVisible='off';  %hidden by default
1976if isfield(ParamOut,'Mask')
1977    MaskVisible=ParamOut.Mask;
1978end
1979set(handles.Mask,'Visible',MaskVisible)
1980set(handles.CheckMask,'Visible',MaskVisible);
1981
1982%% definition of the directory containing the output files
1983OutputDirVisible='off';
1984if isfield(ParamOut,'OutputDirExt')&&~isempty(ParamOut.OutputDirExt)
1985    set(handles.OutputDirExt,'String',ParamOut.OutputDirExt)
1986    OutputDirVisible='on';
1987end
1988set(handles.OutputDirExt,'Visible',OutputDirVisible)
1989set(handles.OutputSubDir,'Visible',OutputDirVisible)
1990set(handles.OutputDir_title,'Visible',OutputDirVisible)
1991set(handles.RunMode,'Visible',OutputDirVisible)
1992set(handles.ActionExt,'Visible',OutputDirVisible)
1993set(handles.RunMode_title,'Visible',OutputDirVisible)
1994set(handles.ActionExt_title,'Visible',OutputDirVisible)
1995
1996%% definition of an additional parameter set, determined by an ancillary GUI
1997if isfield(ParamOut,'ActionInput')
1998    set(handles.ActionInput,'Visible','on')
1999    set(handles.ActionInput_title,'Visible','on')
2000    set(handles.ActionInput,'String',ActionName)
2001    SeriesData.ActionInput=ParamOut.ActionInput;
2002else
2003    set(handles.ActionInput,'Visible','off')
2004    set(handles.ActionInput_title,'Visible','off')
2005    if isfield(SeriesData,'ActionInput')
2006    SeriesData=rmfield(SeriesData,'ActionInput');
2007    end
2008end   
2009set(handles.series,'UserData',SeriesData)
2010
2011%------------------------------------------------------------------------
2012% --- Executes on selection change in FieldName.
2013function FieldName_Callback(hObject, eventdata, handles)
2014%------------------------------------------------------------------------
2015field_str=get(handles.FieldName,'String');
2016field_index=get(handles.FieldName,'Value');
2017field=field_str{field_index(1)};
2018if isequal(field,'get_field...')
2019    hget_field=findobj(allchild(0),'name','get_field');
2020    if ~isempty(hget_field)
2021        delete(hget_field)%delete opened versions of get_field
2022    end
2023    Series=read_GUI(handles.series);
2024    Series.InputTable=Series.InputTable(1,:);
2025    filecell=get_file_series(Series);
2026    if exist(filecell{1,1},'file')
2027        GetFieldData=get_field(filecell{1,1});
2028        FieldList={};
2029        XName=GetFieldData.XVarName;
2030        if GetFieldData.CheckVector
2031            UName=GetFieldData.PanelVectors.vector_x;
2032            VName=GetFieldData.PanelVectors.vector_y;
2033            XName=GetFieldData.XVarName;
2034            YName=GetFieldData.YVarName;
2035            CName=GetFieldData.PanelVectors.vec_color;
2036            [FieldList,VecColorList]=set_field_list(UName,VName,CName);
2037        elseif GetFieldData.CheckScalar
2038            AName=GetFieldData.PanelScalar.scalar;
2039            XName=GetFieldData.XVarName;
2040            YName=GetFieldData.YVarName;
2041            FieldList={AName};
2042        elseif GetFieldData.CheckPlot1D;
2043            YName=GetFieldData.CheckPlot1D.ordinate;
2044        end
2045        set(handles.Coord_x,'String',{XName})
2046        set(handles.Coord_y,'String',{YName})
2047        set(handles.FieldName,'Value',1)
2048        set(handles.FieldName,'String',[FieldList; {'get_field...'}]);
2049        %         set(handles.ColorScalar,'Value',1)
2050        %         set(handles.ColorScalar,'String',VecColorList);
2051        %         UvData.FileType{1}='netcdf';
2052        %         set(handles.uvmat,'UserData',UvData)
2053    end
2054    % elseif isequal(field,'more...')
2055    %     str=calc_field;
2056    %     [ind_answer,v] = listdlg('PromptString','Select a file:',...
2057    %                 'SelectionMode','single',...
2058    %                 'ListString',str);
2059    %        % edit the choice in the fields and actionname menu
2060    %      scalar=cell2mat(str(ind_answer));
2061    %      update_menu(handles.FieldName,scalar)
2062end
2063
2064%------------------------------------------------------------------------
2065% --- Executes on selection change in FieldName_1.
2066function FieldName_1_Callback(hObject, eventdata, handles)
2067%------------------------------------------------------------------------
2068field_str=get(handles.FieldName_1,'String');
2069field_index=get(handles.FieldName_1,'Value');
2070field=field_str{field_index};
2071if isequal(field,'get_field...')   
2072     hget_field=findobj(allchild(0),'name','get_field_1');
2073     if ~isempty(hget_field)
2074         delete(hget_field)
2075     end
2076     SeriesData=get(handles.series,'UserData');
2077     filename=SeriesData.CurrentInputFile_1;
2078     if exist(filename,'file')
2079        hget_field=get_field(filename);
2080        set(hget_field,'name','get_field_1')
2081     end
2082% elseif isequal(field,'more...')
2083%     str=calc_field;
2084%     [ind_answer,v] = listdlg('PromptString','Select a file:',...
2085%                 'SelectionMode','single',...
2086%                 'ListString',str);
2087%        % edit the choice in the fields and actionname menu
2088%      scalar=cell2mat(str(ind_answer));
2089%      update_menu(handles.FieldName_1,scalar)
2090end   
2091
2092
2093%%%%%%%%%%%%%
2094function [ind_remove]=find_pairs(dirpair,ind_i,last_i)
2095indsel=ind_i;
2096indiff=diff(ind_i); %test index increment to detect multiplets (several pairs with the same index ind_i) and holes in the series
2097indiff=[1 indiff last_i-ind_i(end)+1];%for testing gaps with the imposed bounds
2098if ~isempty(indiff)
2099    indiff2=diff(indiff);
2100    indiffp=[indiff2 1];
2101    indiffm=[1 indiff2];
2102    ind_multi_m=find((indiff==0)&(indiffm<0))-1;%indices of first members of multiplets
2103    ind_multi_p=find((indiff==0)&(indiffp>0));%indices of last members of multiplets
2104    %for each multiplet, select the most recent file
2105    ind_remove=[];
2106    for i=1:length(ind_multi_m)
2107        ind_pairs=ind_multi_m(i):ind_multi_p(i);
2108        for imulti=1:length(ind_pairs)
2109            datepair(imulti)=datenum(dirpair(ind_pairs(imulti)).date);%dates of creation
2110        end
2111        [datenew,indsort2]=sort(datepair); %sort the multiplet by creation date
2112        ind_s=indsort2(1:end-1);%
2113        ind_remove=[ind_remove ind_pairs(ind_s)];%remove these indices, leave the last one
2114    end
2115end
2116
2117%------------------------------------------------------------------------
2118% --- determine the list of index pairstring of processing file
2119function [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)
2120%------------------------------------------------------------------------
2121num_i1=num_i;% set of first image numbers by default
2122num_i2=num_i;
2123num_j1=num_j;
2124num_j2=num_j;
2125num_i_out=num_i;
2126num_j_out=num_j;
2127% if isequal (NomType,'_1-2_1') || isequal (NomType,'_1-2')
2128if isequal(mode,'series(Di)')
2129    num_i1_line=num_i+ind_shift(3);% set of first image numbers
2130    num_i2_line=num_i+ind_shift(4);
2131    % adjust the first and last field number
2132        indsel=find(num_i1_line >= 1);
2133    num_i_out=num_i(indsel);
2134    num_i1_line=num_i1_line(indsel);
2135    num_i2_line=num_i2_line(indsel);
2136    num_j1=meshgrid(num_j,ones(size(num_i1_line)));
2137    num_j2=meshgrid(num_j,ones(size(num_i1_line)));
2138    [xx,num_i1]=meshgrid(num_j,num_i1_line);
2139    [xx,num_i2]=meshgrid(num_j,num_i2_line);
2140elseif isequal (mode,'series(Dj)')||isequal (mode,'bursts')
2141    if isequal(mode,'bursts') %case of bursts (png_old or png_2D)
2142        num_j1=ind_shift(1)*ones(size(num_i));
2143        num_j2=ind_shift(2)*ones(size(num_i));
2144    else
2145        num_j1_col=num_j+ind_shift(1);% set of first image numbers
2146        num_j2_col=num_j+ind_shift(2);
2147        % adjust the first field number
2148        indsel=find((num_j1_col >= 1));   
2149        num_j_out=num_j(indsel);
2150        num_j1_col=num_j1_col(indsel);
2151        num_j2_col=num_j2_col(indsel);
2152        [num_i1,num_j1]=meshgrid(num_i,num_j1_col);
2153        [num_i2,num_j2]=meshgrid(num_i,num_j2_col);
2154    end   
2155end
2156
2157%------------------------------------------------------------------------
2158% --- Executes on button press in CheckObject.
2159function CheckObject_Callback(hObject, eventdata, handles)
2160%------------------------------------------------------------------------
2161value=get(handles.CheckObject,'Value');
2162if value
2163%      set(handles.CheckObject,'BackgroundColor',[1 1 0])%put unactivated buttons to yellow
2164     hset_object=findobj(allchild(0),'tag','set_object');%find the set_object interface handle
2165     if ishandle(hset_object)
2166         uistack(hset_object,'top')% show the GUI set_object if opened
2167     else
2168         %get the object file
2169         InputTable=get(handles.InputTable,'Data');
2170         defaultname=InputTable{1,1};
2171         if isempty(defaultname)
2172            defaultname={''};
2173         end
2174        [FileName, PathName] = uigetfile( ...
2175       {'*.xml;*.mat', ' (*.xml,*.mat)';
2176       '*.xml',  '.xml files '; ...
2177        '*.mat',  '.mat matlab files '}, ...
2178        'Pick an xml object file (or use uvmat to create it)',defaultname);
2179        fileinput=[PathName FileName];%complete file name
2180        sizf=size(fileinput);
2181        if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end
2182        %read the file
2183        data=xml2struct(fileinput);
2184        if ~isfield(data,'Type')
2185             msgbox_uvmat('ERROR',[fileinput ' is not an object xml file'])
2186             return
2187        end
2188        if ~isfield(data,'ProjMode')
2189             data.ProjMode='none';
2190        end
2191        hset_object=set_object(data);% call the set_object interface
2192     end
2193     ProjObject=read_GUI(hset_object);
2194     set(handles.ProjObject,'String',ProjObject.Name);%display the object name
2195     SeriesData=get(handles.series,'UserData');
2196     SeriesData.ProjObject=ProjObject;
2197     set(handles.series,'UserData',SeriesData);
2198     set(handles.DeleteObject,'Visible','on');
2199     set(handles.ViewObject,'Visible','on');
2200     set(handles.ProjObject,'Visible','on');
2201else
2202         set(handles.DeleteObject,'Visible','off');
2203     set(handles.ViewObject,'Visible','off');
2204     set(handles.ProjObject,'Visible','off');
2205%     set(handles.CheckObject,'BackgroundColor',[0.7 0.7 0.7])%put activated buttons to green
2206end
2207%set(handles.series,'UserData',SeriesData)
2208
2209%--------------------------------------------------------------
2210function CheckMask_Callback(hObject, eventdata, handles)
2211value=get(handles.CheckMask,'Value');
2212if value
2213    msgbox_uvmat('ERROR','not implemented yet')
2214end
2215%--------------------------------------------------------------
2216
2217%-------------------------------------------------------------------
2218%'uv_ncbrowser': interactively calls the netcdf file browser 'get_field.m'
2219function ncbrowser_uvmat(hObject, eventdata)
2220%-------------------------------------------------------------------
2221     bla=get(gcbo,'String');
2222     ind=get(gcbo,'Value');
2223     filename=cell2mat(bla(ind));
2224      blank=find(filename==' ');
2225      filename=filename(1:blank-1);
2226     get_field(filename)
2227
2228% ------------------------------------------------------------------
2229function MenuHelp_Callback(hObject, eventdata, handles)
2230%-------------------------------------------------------------------
2231path_to_uvmat=which ('uvmat');% check the path of uvmat
2232pathelp=fileparts(path_to_uvmat);
2233helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html');
2234if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package')
2235else
2236    addpath (fullfile(pathelp,'uvmat_doc'))
2237    web([helpfile '#series'])
2238end
2239
2240%-------------------------------------------------------------------
2241% --- Executes on selection change in TransformName.
2242function TransformName_Callback(hObject, eventdata, handles)
2243%----------------------------------------------------------------------
2244TransformList=get(handles.TransformName,'String');
2245TransformIndex=get(handles.TransformName,'Value');
2246TransformName=TransformList{TransformIndex};
2247TransformPathList=get(handles.TransformName,'UserData');
2248nb_builtin_transform=4;
2249% ff=functions(list_transform{end});
2250if isequal(TransformName,'more...');
2251%     coord_fct='';
2252%     prompt = {'Enter the name of the transform function'};
2253%     dlg_title = 'user defined transform';
2254%     num_lines= 1;
2255    [FileName, PathName] = uigetfile( ...
2256       {'*.m', ' (*.m)';
2257        '*.m',  '.m files '; ...
2258        '*.*', 'All Files (*.*)'}, ...
2259        'Pick a transform function',get(handles.TransformPath,'String'));
2260    if isequal(FileName,0)
2261        return     %browser closed without choice
2262    end
2263    if isequal(PathName(end),'/')||isequal(PathName(end),'\')
2264        PathName(end)=[];
2265    end
2266    [TransformPath,TransformName,TransformExt]=fileparts(FileName);% removes extension .m
2267    if ~strcmp(TransformExt,'.m')
2268        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
2269        return
2270    end
2271     % insert the choice in the menu
2272    TransformIndex=find(strcmp(TransformName,TransformList),1);% look for the selected function in the menu Action
2273    if isempty(TransformIndex)%the input string does not exist in the menu
2274        TransformIndex= length(TransformList);
2275        TransformList=[TransformList(1:end-1);{TransformnName};TransformList(end)];% the selected function is appended in the menu, before the last item 'more...'
2276        set(handles.TransformName,'String',TransformList)
2277        TransformPathList=[TransformPathList;{TransformPath}];
2278    end
2279   % save the new menu in the personal file 'uvmat_perso.mat'
2280   dir_perso=prefdir;%personal Matalb directory
2281   profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
2282   if exist(profil_perso,'file')
2283       for ilist=nb_builtin_transform+1:numel(TransformPathList)
2284           TransformListUser{ilist-nb_builtin_transform}=TransformList{ilist};
2285           TransformPathListUser{ilist-nb_builtin_transform}=TransformPathList{ilist};
2286       end
2287       save (profil_perso,'TransformPathListUser','TransformListUser','-append'); %store the root name for future opening of uvmat
2288   end
2289end
2290
2291%display the current function path
2292set(handles.TransformPath,'String',TransformPathList{TransformIndex}); %show the path to the senlected function
2293set(handles.TransformName,'UserData',TransformPathList);
2294
2295
2296% --------------------------------------------------------------------
2297function MenuExportConfig_Callback(hObject, eventdata, handles)
2298global Series
2299[tild,Series,errormsg]=prepare_jobs(handles);
2300% Series=read_GUI(handles.series);
2301
2302evalin('base','global Series')%make CurData global in the workspace
2303display('current series config :')
2304evalin('base','Series') %display CurData in the workspace
2305commandwindow; %brings the Matlab command window to the front
2306
2307
2308% --- Executes on selection change in RunMode.
2309function RunMode_Callback(hObject, eventdata, handles)
2310
2311% --- Executes on selection change in Coord_x.
2312function Coord_x_Callback(hObject, eventdata, handles)
2313
2314
2315% --- Executes on selection change in Coord_y.
2316function Coord_y_Callback(hObject, eventdata, handles)
2317
2318
2319
2320% --- Executes when series is resized.
2321function series_ResizeFcn(hObject, eventdata, handles)
2322%% input table
2323set(handles.InputTable,'Unit','pixel')
2324Pos=get(handles.InputTable,'Position');
2325set(handles.InputTable,'Unit','normalized')
2326ColumnWidth=round([0.5 0.14 0.14 0.14 0.08]*(Pos(3)-52));
2327ColumnWidth=num2cell(ColumnWidth);
2328set(handles.InputTable,'ColumnWidth',ColumnWidth)
2329
2330%% MinIndex and MaxIndex
2331set(handles.MinIndex,'Unit','pixel')
2332Pos=get(handles.MinIndex,'Position');
2333set(handles.MinIndex,'Unit','normalized')
2334ColumnWidth=get(handles.MinIndex,'ColumnWidth');
2335if numel(ColumnWidth)==2
2336    ColumnWidth=num2cell(floor([0.5 0.5]*(Pos(3)-20)));
2337else
2338    ColumnWidth={Pos(3)-5};
2339end   
2340set(handles.MinIndex,'ColumnWidth',ColumnWidth)
2341set(handles.MaxIndex,'ColumnWidth',ColumnWidth)
2342
2343%% TimeTable
2344set(handles.TimeTable,'Unit','pixel')
2345Pos=get(handles.TimeTable,'Position');
2346set(handles.TimeTable,'Unit','normalized')
2347ColumnWidth=get(handles.TimeTable,'ColumnWidth');
2348ColumnWidth=num2cell(floor([0.25 0.25 0.25 0.25]*(Pos(3)-20)));
2349set(handles.TimeTable,'ColumnWidth',ColumnWidth)
2350
2351
2352%% PairString
2353set(handles.PairString,'Unit','pixel')
2354Pos=get(handles.PairString,'Position');
2355set(handles.PairString,'Unit','normalized')
2356set(handles.PairString,'ColumnWidth',{Pos(3)-5})
2357
2358
2359% --- Executes on button press in status.
2360function status_Callback(hObject, eventdata, handles)
2361
2362if get(handles.status,'Value')
2363    set(handles.status,'BackgroundColor',[1 1 0])
2364    drawnow
2365    StatusData.time_ref=get(handles.RUN,'UserData');% get the time of launch
2366    Param=read_GUI(handles.series);
2367    RootPath=Param.InputTable{1,1};
2368    OutputSubDir=[Param.OutputSubDir Param.OutputDirExt];% subdirectory for output files
2369    OutputDir=fullfile(RootPath,OutputSubDir);
2370    hfig=findobj(allchild(0),'name','series_status');
2371    if isempty(hfig)
2372        hfig=figure('DeleteFcn',@stop_status);
2373        set(hfig,'MenuBar','none')% suppress the menu bar
2374        set(hfig,'NumberTitle','off')%suppress the fig number in the title
2375        set(hfig,'name','series_status')
2376        set(hfig,'tag','series_status')
2377        uicontrol('Style','listbox','Units','normalized', 'Position',[0.05 0.09 0.9 0.71], 'Callback', @view_file,'tag','list','UserData',OutputDir);
2378        uicontrol('Style','edit','Units','normalized', 'Position', [0.05 0.87 0.9 0.1],'tag','titlebox','Max',2,'String',OutputDir);
2379        uicontrol('Style','frame','Units','normalized', 'Position', [0.05 0.81 0.9 0.05]);
2380        uicontrol('Style','pushbutton','Units','normalized', 'Position', [0.7 0.01 0.2 0.07],'String','Close','FontWeight','bold','FontUnits','points','FontSize',11,'Callback',@stop_status);
2381        hrefresh=uicontrol('Style','pushbutton','Units','normalized', 'Position', [0.1 0.01 0.2 0.07],'String','Refresh','FontWeight','bold','FontUnits','points','FontSize',11,'Callback',@refresh_GUI);
2382        set(hrefresh,'UserData',StatusData)
2383        BarPosition=[0.05 0.81 0.01 0.05];
2384        uicontrol('Style','frame','Units','normalized', 'Position',BarPosition ,'BackgroundColor',[1 0 0],'tag','waitbar');
2385        drawnow
2386    end
2387    refresh_GUI(hrefresh,[])
2388else
2389    %% delete current display fig if selection is off
2390    set(handles.status,'BackgroundColor',[0 1 0])
2391    hfig=findobj(allchild(0),'name','series_status');
2392    if ~isempty(hfig)
2393        delete(hfig)
2394    end
2395    return
2396end
2397
2398
2399%------------------------------------------------------------------------   
2400% launched by selecting a file on the list
2401function view_file(hObject, eventdata)
2402list=get(hObject,'String');
2403index=get(hObject,'Value');
2404rootroot=get(hObject,'UserData');
2405selectname=list{index};
2406ind_dot=regexp(selectname,'\.\.\.');
2407if ~isempty(ind_dot)
2408    selectname=selectname(1:ind_dot-1);
2409end
2410FullSelectName=fullfile(rootroot,selectname);
2411if exist(FullSelectName,'dir')% a directory has been selected
2412    ListFiles=dir(FullSelectName);
2413    ListDisplay=cell(numel(ListFiles),1);
2414    for ilist=2:numel(ListDisplay)% suppress the first line '.'
2415        ListDisplay{ilist-1}=ListFiles(ilist).name;
2416    end
2417    set(hObject,'Value',1)
2418    set(hObject,'String',ListDisplay)
2419    if strcmp(selectname,'..')
2420        FullSelectName=fileparts(fileparts(FullSelectName));
2421    end
2422    set(hObject,'UserData',FullSelectName)
2423    hfig=get(hObject,'parent');
2424    htitlebox=findobj(hfig,'tag','titlebox');   
2425    set(htitlebox,'String',FullSelectName)
2426elseif exist(FullSelectName,'file')%visualise the vel field if it exists
2427    FileType=get_file_type(FullSelectName);
2428    if strcmp(FileType,'txt')
2429        edit(FullSelectName)
2430    else
2431        uvmat(FullSelectName)
2432    end
2433    set(gcbo,'Value',1)
2434end
2435
2436
2437%------------------------------------------------------------------------
2438
2439%------------------------------------------------------------------------   
2440% launched by refreshing the status figure
2441function refresh_GUI(hObject, eventdata)
2442%------------------------------------------------------------------------
2443hfig=get(hObject,'parent');
2444htitlebox=findobj(hfig,'tag','titlebox');
2445hlist=findobj(hfig,'tag','list');
2446OutputDir=get(htitlebox,'String');
2447ListFiles=dir(OutputDir);
2448ListDisplay=cell(numel(ListFiles),1);
2449for ilist=2:numel(ListDisplay)
2450    ListDisplay{ilist-1}=ListFiles(ilist).name;
2451end
2452set(hlist,'String',ListDisplay)
2453% civ_files=get(hfig,'UserData');
2454
2455% [filepath,filename,ext]=fileparts(civ_files{1});
2456% [tild,SubDir,extdir]=fileparts(filepath);
2457% SubDir=[SubDir extdir];
2458% option_civ=StatusData.option_civ;
2459% nbfiles=numel(civ_files);
2460% testrecent=0;
2461% count=0;
2462% datnum=zeros(1,nbfiles);
2463% filefound=cell(1,nbfiles);
2464% for ifile=1:nbfiles
2465%     detect=exist(civ_files{ifile},'file'); % check the existence of the file
2466%     option=0;
2467%     if detect==0
2468%         option_str='not created';
2469%     else
2470%         datfile=dir(civ_files{ifile});
2471%         if isfield(datfile,'datenum')
2472%             datnum(ifile)=datfile.datenum;%only available in recent matlab versions
2473%             testrecent=1;
2474%         end
2475%         filefound(ifile)={datfile.name};
2476%         
2477%         % check the content  netcdf file
2478%         Data=nc2struct(civ_files{ifile},'ListGlobalAttribute','CivStage','patch2','fix2','civ2','patch','fix');
2479%         option_list={'civ1','fix1','patch1','civ2','fix2','patch2'};
2480%         if ~isempty(Data.CivStage)
2481%             option=Data.CivStage;%case of Matlab civ
2482%         else
2483%             if ~isempty(Data.patch2) && isequal(Data.patch2,1)
2484%                 option=6;
2485%             elseif ~isempty(Data.fix2) && isequal(Data.fix2,1)
2486%                 option=5;
2487%             elseif ~isempty(Data.civ2) && isequal(Data.civ2,1);
2488%                 option=4;
2489%             elseif ~isempty(Data.patch) && isequal(Data.patch,1);
2490%                 option=3;
2491%             elseif ~isempty(Data.fix) && isequal(Data.fix,1);
2492%                 option=2;
2493%             else
2494%                 option=1;
2495%             end
2496%         end
2497%         option_str=option_list{option};
2498%         if datnum(ifile)<StatusData.time_ref
2499%             option_str=[option_str '  --OLD--'];
2500%         end
2501%     end
2502%     if option >= option_civ
2503%         count=count+1;
2504%     end
2505%     [filepath,filename,ext]=fileparts(civ_files{ifile});
2506%     Tabchar{ifile,1}=[fullfile(SubDir,filename) ext  '...' option_str];
2507% end
2508% datnum=datnum(datnum~=0);%keep the non zero values corresponding to existing files
2509% if isempty(datnum)
2510%     if testrecent
2511%         message='no civ result created yet';
2512%     else
2513%         message='';
2514%     end
2515% else
2516%     datnum=datnum(datnum~=0);%keep the non zero values corresponding to existing files
2517%     [first,ind]=min(datnum);
2518%     [last,indlast]=max(datnum);
2519%     message={[num2str(count) ' file(s) done over ' num2str(nbfiles)] ;['oldest modification:  ' cell2mat(filefound(ind)) ' : ' datestr(first)];...
2520%         ['latest modification:  ' cell2mat(filefound(indlast)) ' : ' datestr(last)]};
2521% end
2522% hlist=findobj(hfig,'tag','list');
2523% htitlebox=findobj(hfig,'tag','titlebox');
2524% hwaitbar=findobj(hfig,'tag','waitbar');
2525% set(hlist,'String',Tabchar)
2526% set(htitlebox,'String', message)
2527% if count>0 %&& ~test_new
2528%     BarPosition(3)=0.9*count/nbfiles;
2529%     set(hwaitbar,'Position',BarPosition)
2530% end
2531%------------------------------------------------------------------------   
2532% launched by deleting the status figure
2533function stop_status(hObject, eventdata)
2534%------------------------------------------------------------------------
2535hciv=findobj(allchild(0),'tag','series');
2536hhciv=guidata(hciv);
2537set(hhciv.status,'value',0) %reset the status uicontrol in the GUI civ
2538set(hhciv.status,'BackgroundColor',[0 1 0])
2539delete(gcbf)
2540
2541% --- Executes on selection change in ActionExt.
2542function ActionExt_Callback(hObject, eventdata, handles)
2543ActionExtList=get(handles.ActionExt,'String');
2544ActionExt=ActionExtList{get(handles.ActionExt,'Value')};
2545ActionList=get(handles.ActionName,'String');
2546ActionName=ActionList{get(handles.ActionName,'Value')};
2547if strcmp(ActionExt,'.sh')
2548    ActionFullName=fullfile(get(handles.ActionPath,'String'),[ActionName '.sh']);
2549    if ~exist(ActionFullName,'file')
2550        answer=msgbox_uvmat('INPUT_Y-N','compiled version has not been created: compile now?');
2551        if strcmp(answer,'Yes')
2552            currentdir=pwd;
2553            cd(get(handles.ActionPath,'String'))
2554            compile(ActionName)
2555            cd(currentdir)
2556        end
2557    end
2558    currentdir=pwd;
2559    cd(get(handles.ActionPath,'String'))
2560    sh_file=dir([ActionName '.sh']);
2561    m_file=dir([ActionName '.m']);
2562    if isfield(m_file,'datenum') && m_file.datenum>sh_file.datenum
2563        set(handles.ActionExt,'BackgroundColor',[1 1 0])
2564        drawnow
2565        answer=msgbox_uvmat('INPUT_Y-N',[ActionName '.sh needs to be updated: recompile now?']);
2566        if strcmp(answer,'Yes')
2567            compile(ActionName)
2568        end
2569        set(handles.ActionExt,'BackgroundColor',[1 1 1])
2570    end
2571    cd(currentdir)
2572end
2573
2574
2575function ActionInput_Callback(hObject, eventdata, handles)
2576
2577
2578% --- Executes on button press in DeleteObject.
2579function DeleteObject_Callback(hObject, eventdata, handles)
2580if get(handles.DeleteObject,'Value')
2581        SeriesData=get(handles.series,'UserData');
2582    SeriesData.ProjObject=[];
2583    set(handles.series,'UserData',SeriesData)
2584    set(handles.ProjObject,'String','')
2585    set(handles.CheckObject,'Value',0)
2586    set(handles.DeleteObject,'Visible','off')
2587    set(handles.ViewObject,'Visible','off')
2588end
2589
2590% --- Executes on button press in ViewObject.
2591function ViewObject_Callback(hObject, eventdata, handles)
2592if get(handles.ViewObject,'Value')
2593        UserData=get(handles.series,'UserData');
2594    set_object(UserData.ProjObject)
2595else
2596    hset_object=findobj(allchild(0),'Tag','set_object');
2597    if ~isempty(hset_object)
2598        delete(hset_object)
2599    end
2600end
2601
2602
2603function num_NbProcess_Callback(hObject, eventdata, handles)
2604
2605
2606function num_NbSlice_Callback(hObject, eventdata, handles)
2607NbSlice=str2num(get(handles.num_NbSlice,'String'));
2608set(handles.num_NbProcess,'String',num2str(NbSlice))
Note: See TracBrowser for help on using the repository browser.