source: trunk/src/series.m @ 601

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

a few bugs corrected

File size: 107.1 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',false)
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'
86%path_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 ActionPathList];% set path to .sh commands for 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] = 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,FileInfo,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,FileInfo,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,FileInfo,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,FileInfo,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,FileInfo,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});
710TimeUnit='';
711if ~isempty(XmlFileName)
712        [XmlData,warntext]=imadoc2struct(XmlFileName);
713        if isfield(XmlData,'Heading') && isfield(XmlData.Heading,'ImageName') && ischar(XmlData.Heading.ImageName)
714            [PP,FF,ext_ima_read]=fileparts(XmlData.Heading.ImageName);
715        end
716        if isfield(XmlData,'Time')
717            time=XmlData.Time;
718        end
719        if isfield(XmlData,'Camera')
720            if isfield(XmlData.Camera,'NbSlice')&& ~isempty(XmlData.Camera.NbSlice)
721                NbSlice_calib{iview}=XmlData.Camera.NbSlice;% Nbre of slices for Zindex in phys transform
722                if ~isequal(NbSlice_calib{iview},NbSlice_calib{1})
723                    msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
724                end
725            end
726            if isfield(XmlData.Camera,'TimeUnit')&& ~isempty(XmlData.Camera.TimeUnit)
727                TimeUnit=XmlData.Camera.TimeUnit;
728            end
729        end
730        if ~isempty(warntext)
731            msgbox_uvmat('WARNING',warntext)
732        end 
733end
734
735%% update time table
736if ~isempty(time)
737    TimeTable=get(handles.TimeTable,'Data');
738    first_i=str2num(get(handles.num_first_i,'String'));
739    last_i=str2num(get(handles.num_last_i,'String'));
740    first_j=str2num(get(handles.num_first_j,'String'));
741    last_j=str2num(get(handles.num_last_j,'String'));
742    MinIndexTable=get(handles.MinIndex,'Data');
743    MinIndex_i=MinIndexTable{iview,1};
744    MinIndex_j=MinIndexTable{iview,2};
745    MaxIndexTable=get(handles.MaxIndex,'Data');
746    MaxIndex_i=MaxIndexTable{iview,1};
747    MaxIndex_j=MaxIndexTable{iview,2};
748    if isempty(MinIndex_j)% only i index
749        if MinIndex_i>0
750            TimeTable{iview,1}=time(MinIndex_i);
751        end
752        TimeTable{iview,2}=time(first_i);
753        TimeTable{iview,3}=time(last_i);
754        TimeTable{iview,4}=time(MaxIndex_i);
755    elseif ~isempty(time)
756        if MinIndex_i>0
757            TimeTable{iview,1}=time(MinIndex_i,MinIndex_j);
758        end
759        if size(time)>=[last_i last_j]
760            TimeTable{iview,2}=time(first_i,first_j);
761            TimeTable{iview,3}=time(last_i,last_j);
762        end
763        if size(time)>=[MaxIndex_i MaxIndex_j];
764            TimeTable{iview,4}=time(MaxIndex_i,MaxIndex_j);
765        end
766    end
767    set(handles.TimeTable,'Data',TimeTable)
768end
769
770%% number of slices
771NbSlice=1;%default
772check_calib=0;
773if isfield(XmlData,'GeometryCalib')
774    check_calib=1;
775    if isfield(XmlData.GeometryCalib,'SliceCoord')
776    siz=size(XmlData.GeometryCalib.SliceCoord);
777    if siz(1)>1
778        NbSlice=siz(1);
779    end
780    end
781end
782set(handles.num_NbSlice,'String',num2str(NbSlice))
783   
784%% update pair menus
785set(handles.Pairs,'Visible','on')
786set(handles.PairString,'Visible','on')
787ListView=get(handles.ListView,'String');
788ListView{iview}=num2str(iview);
789set(handles.ListView,'String',ListView);
790set(handles.ListView,'Value',iview)
791update_mode(handles,i1_series,i2_series,j1_series,j2_series,time)
792
793%% update the series info in 'UserData'
794SeriesData=get(handles.series,'UserData');
795SeriesData.i1_series{iview}=i1_series;
796SeriesData.i2_series{iview}=i2_series;
797SeriesData.j1_series{iview}=j1_series;
798SeriesData.j2_series{iview}=j2_series;
799SeriesData.FileType{iview}=FileType;
800SeriesData.FileInfo{iview}=FileInfo;
801SeriesData.Time{iview}=time;
802if ~isempty(TimeUnit)
803    SeriesData.TimeUnit=TimeUnit;
804end
805if check_calib
806SeriesData.GeometryCalib{iview}=XmlData.GeometryCalib;
807end
808set(handles.series,'UserData',SeriesData)
809
810%% enable j index visibilitycellfun(@isempty,regexp(PairString,'^j'))
811% state='off';
812check_jindex=~cellfun(@isempty,SeriesData.j1_series); %look for non empty j indices
813if isempty(find(check_jindex))
814    enable_j(handles,'off') % no j index needed
815else
816    PairString=get(handles.PairString,'Data');
817    if isempty(find(cellfun(@isempty,regexp(PairString,'^j'))))% if all pair string begins by j (burst)
818        enable_j(handles,'off') % no j index needed
819    else
820        enable_j(handles,'on')
821    end
822end
823
824%% display the set of existing files as an image
825set(handles.FileStatus,'Units','pixels')
826Position=get(handles.FileStatus,'Position');
827set(handles.FileStatus,'Units','normalized')
828xI=0.5:Position(3)-0.5;
829nbview=numel(SeriesData.i1_series);
830pair_max=cell(1,nbview);
831for iview=1:nbview
832    pair_max{iview}=squeeze(max(SeriesData.i1_series{iview},[],1)); %max on pair index
833    if (strcmp(get(handles.num_first_j,'Visible'),'off')&& size(pair_max{iview},2)~=1)
834        pair_max{iview}=squeeze(max(pair_max{iview},[],1)); % consider only the i index
835    end
836    index_min(iview)=find(pair_max{iview}>0, 1 );
837    index_max(iview)=find(pair_max{iview}>0, 1, 'last' );
838end
839index_min=min(index_min);
840index_max=max(index_max);
841range_index=index_max-index_min+1;
842scale_y=Position(4)/nbview;
843scale_x=Position(3)/range_index;
844x=(0.5:range_index-0.5)*Position(3)/range_index;
845% y=(0.5:nbview-0.5)*Position(4)/nbview;
846range_y=max(1,floor(Position(4)/nbview));
847CData=zeros(nbview*range_y,Position(3));
848for iview=1:nbview
849    ind_y=1+(iview-1)*range_y:iview*range_y;
850    LineData=zeros(1,range_index);
851    x_index=find(pair_max{iview}>0)-index_min+1;
852    LineData(x_index)=1;
853    if numel(x)>1
854    LineData=interp1(x,LineData,xI,'nearest');
855    CData(ind_y,:)=ones(size(ind_y'))*LineData;
856    end
857end
858CData=cat(3,zeros(size(CData)),CData,zeros(size(CData)));
859set(handles.FileStatus,'CData',CData);
860
861
862%% enable field and veltype menus, in accordance with the current action
863ActionName_Callback([],[], handles)
864
865%% check for pair display
866check_pairs=0;
867for iview=1:numel(SeriesData.i2_series)
868    if ~isempty(SeriesData.i2_series{iview})||~isempty(SeriesData.j2_series{iview})
869        check_pairs=1;
870    end
871end
872if check_pairs
873    set(handles.Pairs,'Visible','on')
874    set(handles.PairString,'Visible','on')
875else
876    set(handles.Pairs,'Visible','off')
877    set(handles.PairString,'Visible','off')
878end
879
880%% set length of waitbar
881displ_time(handles)
882
883
884%% set default options in menu 'Fields'
885switch FileType
886    case {'civx','civdata'}
887        [FieldList,ColorList]=set_field_list('U','V','C');
888        set(handles.FieldName,'String',[{'image'};FieldList;{'get_field...'}]);%standard menu for civx data
889        set(handles.FieldName,'Value',2) % set menu to 'velocity
890        set(handles.Coord_x,'Value',1);
891        set(handles.Coord_x,'String',{'X'});
892        set(handles.Coord_y,'Value',1);
893        set(handles.Coord_y,'String',{'Y'});
894    case 'netcdf'
895        set(handles.FieldName,'Value',1)
896        set(handles.FieldName,'String',{'get_field...'})
897        if isempty(i2_series)
898            i2=[];
899        else
900            i2=i2_series(1,ref_j+1,ref_i+1);
901        end
902        if isempty(j1_series)
903            j1=[];j2=[];
904        else
905            j1=j1_series(1,ref_j+1,ref_i+1);
906            if isempty(j2_series)
907                j2=[];
908            else
909                j2=j2_series(1,ref_j+1,ref_i+1);
910            end
911        end
912        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);
913%         hget_field=get_field(FileName);
914%         hhget_field=guidata(hget_field);
915%         get_field('RUN_Callback',hhget_field.RUN,[],hhget_field);
916    otherwise
917        set(handles.FieldName,'Value',1) % set menu to 'image'
918        set(handles.FieldName,'String',{'image'})
919        set(handles.Coord_x,'Value',1);
920        set(handles.Coord_x,'String',{'AX'});
921        set(handles.Coord_y,'Value',1);
922        set(handles.Coord_y,'String',{'AY'});
923end
924
925%------------------------------------------------------------------------
926function num_first_i_Callback(hObject, eventdata, handles)
927%------------------------------------------------------------------------
928num_last_i_Callback(hObject, eventdata, handles)
929
930%------------------------------------------------------------------------
931function num_last_i_Callback(hObject, eventdata, handles)
932%------------------------------------------------------------------------
933SeriesData=get(handles.series,'UserData');
934if ~isfield(SeriesData,'Time')
935    SeriesData.Time{1}=[];
936end
937displ_time(handles);
938
939%------------------------------------------------------------------------
940function num_first_j_Callback(hObject, eventdata, handles)
941%------------------------------------------------------------------------
942 num_last_j_Callback(hObject, eventdata, handles)
943
944%------------------------------------------------------------------------
945function num_last_j_Callback(hObject, eventdata, handles)
946%------------------------------------------------------------------------
947first_j=str2num(get(handles.num_first_j,'String'));
948last_j=str2num(get(handles.num_last_j,'String'));
949ref_j=ceil((first_j+last_j)/2);
950set(handles.num_ref_j,'String', num2str(ref_j))
951num_ref_j_Callback(hObject, eventdata, handles)
952SeriesData=get(handles.series,'UserData');
953if ~isfield(SeriesData,'Time')
954    SeriesData.Time{1}=[];
955end
956displ_time(handles);
957
958
959%------------------------------------------------------------------------
960% ---- find the times corresponding to the first and last indices of a series
961function displ_time(handles)
962%------------------------------------------------------------------------
963SeriesData=get(handles.series,'UserData');%
964ref_i=[str2num(get(handles.num_first_i,'String')) str2num(get(handles.num_last_i,'String'))];
965ref_j=[str2num(get(handles.num_first_j,'String')) str2num(get(handles.num_last_j,'String'))];
966TimeTable=get(handles.TimeTable,'Data');
967Pairs=get(handles.PairString,'Data');
968for iview=1:size(TimeTable,1)
969    if size(SeriesData.Time,1)<iview
970        break
971    end
972    i1=ref_i;
973    j1=ref_j;
974    i2=ref_i;
975    j2=ref_j;
976    % case of pairs
977    if ~isempty(Pairs{iview,1})
978        r=regexp(Pairs{iview,1},'(?<mode>(Di=)|(Dj=)) -*(?<num1>\d+)\|(?<num2>\d+)','names');
979        if isempty(r)
980            r=regexp(Pairs{iview,1},'(?<num1>\d+)(?<mode>-)(?<num2>\d+)','names');
981        end
982        switch r.mode
983            case 'Di='  %  case 'series(Di)')
984                i1=ref_i-str2num(r.num1);
985                i2=ref_i+str2num(r.num2);
986            case 'Dj='  %  case 'series(Dj)'
987                j1=ref_j-str2num(r.num1);
988                j2=ref_j+str2num(r.num2);
989            case '-'  % case 'bursts'
990                j1=str2num(r.num1)*ones(size(ref_i));
991                j2=str2num(r.num2)*ones(size(ref_i));
992        end
993    end
994    TimeTable{iview,2}=[];
995    TimeTable{iview,3}=[];
996    if size(SeriesData.Time{iview},1)>=i2(2)&&size(SeriesData.Time{iview},1)>=j2(2)
997        if isempty(ref_j)
998            time_first=(SeriesData.Time{iview}(i1(1))+SeriesData.Time{iview}(i2(1)))/2;
999            time_last=(SeriesData.Time{iview}(i1(2))+SeriesData.Time{iview}(i2(2)))/2;
1000        else
1001            time_first=(SeriesData.Time{iview}(i1(1),j1(1))+SeriesData.Time{iview}(i2(1),j2(1)))/2;
1002            time_last=(SeriesData.Time{iview}(i1(2),j1(2))+SeriesData.Time{iview}(i2(2),j2(2)))/2;
1003        end
1004        TimeTable{iview,2}=time_first; %TODO: take into account pairs
1005        TimeTable{iview,3}=time_last; %TODO: take into account pairs
1006    end
1007end
1008set(handles.TimeTable,'Data',TimeTable)
1009
1010%% set the waitbar position with respect to the min and max in the series
1011for iview=1:numel(SeriesData.i1_series)
1012    pair_max{iview}=squeeze(max(SeriesData.i1_series{iview},[],1)); %max on pair index
1013    if (strcmp(get(handles.num_first_j,'Visible'),'off')&& size(pair_max{iview},2)~=1)
1014        pair_max{iview}=squeeze(max(pair_max{iview},[],1)); % consider only the i index
1015    end
1016    pair_max{iview}=reshape(pair_max{iview},1,[]);
1017    index_min(iview)=find(pair_max{iview}>0, 1 );
1018    index_max(iview)=find(pair_max{iview}>0, 1, 'last' );
1019end
1020[index_min,iview_min]=min(index_min);
1021[index_max,iview_max]=min(index_max);
1022if size(SeriesData.i1_series{iview_min},2)==1% movie
1023    index_first=ref_i(1);
1024    index_last=ref_i(2);
1025else
1026    index_first=(ref_i(1)-1)*(size(SeriesData.i1_series{iview_min},1))+ref_j(1)+1;
1027    index_last=(ref_i(2)-1)*(size(SeriesData.i1_series{iview_max},1))+ref_j(2)+1;
1028end
1029range=index_max-index_min+1;
1030coeff_min=(index_first-index_min)/range;
1031coeff_max=(index_last-index_min+1)/range;
1032Position=get(handles.Waitbar,'Position');% position of the waitbar:= [ x,y, width, height]
1033Position_status=get(handles.FileStatus,'Position');
1034Position(1)=coeff_min*Position_status(3)+Position_status(1);
1035Position(3)=Position_status(3)*(coeff_max-coeff_min);
1036set(handles.Waitbar,'Position',Position)
1037update_waitbar(handles.Waitbar,0)
1038
1039%------------------------------------------------------------------------
1040% --- Executes when selected cell(s) is changed in PairString.
1041function PairString_CellSelectionCallback(hObject, eventdata, handles)
1042%------------------------------------------------------------------------   
1043set(handles.ListView,'Value',eventdata.Indices(1))% detect the selected raw index
1044ListView_Callback ([],[],handles) % update the list of available pairs
1045
1046%------------------------------------------------------------------------
1047%------------------------------------------------------------------------
1048%  III - FUNCTIONS ASSOCIATED TO THE FRAME SET PAIRS
1049%------------------------------------------------------------------------
1050%------------------------------------------------------------------------
1051% --- Executes on selection change in ListView.
1052function ListView_Callback(hObject, eventdata, handles)
1053%------------------------------------------------------------------------   
1054SeriesData=get(handles.series,'UserData');
1055i2_series=[];
1056j2_series=[];
1057iview=get(handles.ListView,'Value');
1058if ~isempty(SeriesData.i2_series{iview})
1059    i2_series=SeriesData.i2_series{iview};
1060end
1061if ~isempty(SeriesData.j2_series{iview})
1062    j2_series=SeriesData.j2_series{iview};
1063end
1064update_mode(handles,SeriesData.i1_series{iview},SeriesData.i2_series{iview},...
1065    SeriesData.j1_series{iview},SeriesData.j2_series{iview},SeriesData.Time{iview})
1066
1067%------------------------------------------------------------------------
1068% --- Executes on button press in mode.
1069function mode_Callback(hObject, eventdata, handles)
1070%------------------------------------------------------------------------       
1071SeriesData=get(handles.series,'UserData');
1072iview=get(handles.ListView,'Value');
1073mode_list=get(handles.mode,'String');
1074mode=mode_list{get(handles.mode,'Value')};
1075if isequal(mode,'bursts')
1076    enable_i(handles,'On')
1077    enable_j(handles,'Off') %do not display j index scanning in burst mode (j is fixed by the burst choice)
1078else
1079    enable_i(handles,'On')
1080    enable_j(handles,'Off')
1081end
1082fill_ListPair(handles,SeriesData.i1_series{iview},SeriesData.i2_series{iview},...
1083    SeriesData.j1_series{iview},SeriesData.j2_series{iview},SeriesData.Time{iview})
1084ListPairs_Callback([],[],handles)
1085
1086%-------------------------------------------------------------
1087% --- Executes on selection in ListPairs.
1088function ListPairs_Callback(hObject,eventdata,handles)
1089%------------------------------------------------------------
1090list_pair=get(handles.ListPairs,'String');%get the menu of image pairs
1091if isempty(list_pair)
1092    string='';
1093else
1094    string=list_pair{get(handles.ListPairs,'Value')};
1095    string=regexprep(string,',.*','');%removes time indication (after ',')
1096end
1097PairString=get(handles.PairString,'Data');
1098iview=get(handles.ListView,'Value');
1099PairString{iview,1}=string;
1100% report the selected pair string to the table PairString
1101set(handles.PairString,'Data',PairString)
1102
1103%------------------------------------------------------------------------
1104function num_ref_i_Callback(hObject, eventdata, handles)
1105%------------------------------------------------------------------------
1106mode_list=get(handles.mode,'String');
1107mode=mode_list{get(handles.mode,'Value')};
1108SeriesData=get(handles.series,'UserData');
1109iview=get(handles.ListView,'Value');
1110fill_ListPair(handles,SeriesData.i1_series{iview},SeriesData.i2_series{iview},...
1111    SeriesData.j1_series{iview},SeriesData.j2_series{iview},SeriesData.Time{iview});% update the menu of pairs depending on the available netcdf files
1112ListPairs_Callback([],[],handles)
1113
1114%------------------------------------------------------------------------
1115function num_ref_j_Callback(hObject, eventdata, handles)
1116%------------------------------------------------------------------------
1117num_ref_i_Callback(hObject, eventdata, handles)
1118
1119%------------------------------------------------------------------------
1120function update_mode(handles,i1_series,i2_series,j1_series,j2_series,time)
1121%------------------------------------------------------------------------   
1122% check_burst=0;
1123if isempty(j2_series)% no j pair
1124    if isempty(i2_series)
1125        set(handles.mode,'Value',1)
1126        set(handles.mode,'String',{''})% no pair menu to display
1127    else   
1128        set(handles.mode,'Value',1)
1129        set(handles.mode,'String',{'series(Di)'}) % pair menu with only option Di
1130    end
1131else %existence of j pairs
1132    pair_max=squeeze(max(i1_series,[],1)); %max on pair index
1133    j_max=max(pair_max,[],1);
1134    MaxIndex_i=max(find(j_max))-1;% max ref index i
1135    MinIndex_i=min(find(j_max))-1;% min ref index i
1136    i_max=max(pair_max,[],2);
1137    MaxIndex_j=max(find(i_max))-1;% max ref index i
1138    MinIndex_j=min(find(i_max))-1;% min ref index i
1139    if MaxIndex_j==MinIndex_j
1140        set(handles.mode,'Value',1);
1141        set(handles.mode,'String',{'bursts'})
1142%         check_burst=1;
1143    elseif MaxIndex_i==MinIndex_i
1144        set(handles.mode,'Value',1);
1145        set(handles.mode,'String',{'series(Dj)'})
1146    else
1147        set(handles.mode,'String',{'bursts';'series(Dj)'})
1148        if (MaxIndex_j-MinIndex_j)>10
1149            set(handles.mode,'Value',2);%set mode to series(Dj) if more than 10 j values
1150        else
1151            set(handles.mode,'Value',1);
1152%             check_burst=1;
1153        end
1154    end
1155end
1156% if check_burst
1157%     enable_i(handles,'On')
1158%     enable_j(handles,'Off') %do not display j index scanning in burst mode (j is fixed by the burst choice)
1159% else
1160%     enable_i(handles,'On')
1161%     if isempty(j1_series)
1162%          enable_j(handles,'Off')
1163%     else
1164%         enable_j(handles,'On')
1165%     end
1166% end
1167fill_ListPair(handles,i1_series,i2_series,j1_series,j2_series,time)
1168ListPairs_Callback([],[],handles)
1169
1170%--------------------------------------------------------------
1171% determine the menu for civ1 pairstring depending on existing netcdf files
1172% with the reference indices num_ref_i and num_ref_j
1173%----------------------------------------------------------------
1174function fill_ListPair(handles,i1_series,i2_series,j1_series,j2_series,time)
1175
1176mode_list=get(handles.mode,'String');
1177mode=mode_list{get(handles.mode,'Value')};
1178ref_i=str2num(get(handles.num_ref_i,'String'));
1179if isempty(ref_i)
1180    ref_i=1;
1181end
1182if strcmp(get(handles.num_ref_j,'Visible'),'on')
1183    ref_j=str2num(get(handles.num_ref_j,'String'));
1184    if isempty(ref_j)
1185        ref_j=1;
1186    end
1187else
1188    ref_j=1;
1189end
1190TimeUnit=get(handles.TimeUnit,'String');
1191if length(TimeUnit)>=1
1192    dtunit=['m' TimeUnit];
1193else
1194    dtunit='e-03';
1195end
1196
1197displ_pair={};
1198if strcmp(mode,'series(Di)')
1199    if isempty(i2_series)
1200        msgbox_uvmat('ERROR','no i1-i2 pair available')
1201        return
1202    end
1203    diff_i=i2_series-i1_series;
1204    min_diff=min(diff_i(diff_i>0));
1205    max_diff=max(diff_i(diff_i>0));
1206    for ipair=min_diff:max_diff
1207        if numel(diff_i(diff_i==ipair))>0
1208            pair_string=['Di= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ];
1209            if ~isempty(time)
1210                if ref_i<=floor(ipair/2)
1211                    ref_i=floor(ipair/2)+1;% shift ref_i to get the first pair
1212                end
1213                Dt=time(ref_i+ceil(ipair/2),ref_j)-time(ref_i-floor(ipair/2),ref_j);
1214                pair_string=[pair_string ', Dt=' num2str(Dt) ' ' dtunit];
1215            end
1216            displ_pair=[displ_pair;{pair_string}];
1217        end
1218    end
1219    if ~isempty(displ_pair)
1220        displ_pair=[displ_pair;{'Di=*|*'}];
1221    end
1222elseif strcmp(mode,'series(Dj)')
1223    if isempty(j2_series)
1224        msgbox_uvmat('ERROR','no j1-j2 pair available')
1225        return
1226    end
1227    diff_j=j2_series-j1_series;
1228    min_diff=min(diff_j(diff_j>0));
1229    max_diff=max(diff_j(diff_j>0));
1230    for ipair=min_diff:max_diff
1231        if numel(diff_j(diff_j==ipair))>0
1232            pair_string=['Dj= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ];
1233            if ~isempty(time)
1234                if ref_j<=floor(ipair/2)
1235                    ref_j=floor(ipair/2)+1;% shift ref_i to get the first pair
1236                end
1237                Dt=time(ref_i,ref_j+ceil(ipair/2))-time(ref_i,ref_j-floor(ipair/2));
1238                pair_string=[pair_string ', Dt=' num2str(Dt) ' ' dtunit];
1239            end
1240            displ_pair=[displ_pair;{pair_string}];
1241        end
1242    end
1243    if ~isempty(displ_pair)
1244        displ_pair=[displ_pair;{'Dj=*|*'}];
1245    end
1246elseif strcmp(mode,'bursts')
1247    if isempty(j2_series)
1248        msgbox_uvmat('ERROR','no j1-j2 pair available')
1249        return
1250    end
1251    diff_j=j2_series-j1_series;
1252    min_j1=min(j1_series(j1_series>0));
1253    max_j1=max(j1_series(j1_series>0));
1254    min_j2=min(j2_series(j2_series>0));
1255    max_j2=max(j2_series(j2_series>0));
1256    for pair1=min_j1:min(max_j1,min_j1+20)
1257        for pair2=min_j2:min(max_j2,min_j2+20)
1258        if numel(j1_series(j1_series==pair1))>0 && numel(j2_series(j2_series==pair2))>0
1259            displ_pair=[displ_pair;{['j= ' num2str(pair1) '-' num2str(pair2)]}];
1260        end
1261        end
1262    end
1263    if ~isempty(displ_pair)
1264        displ_pair=[displ_pair;{'j=*-*'}];
1265    end
1266end
1267set(handles.num_ref_i,'String',num2str(ref_i)) % update ref_i and ref_j
1268set(handles.num_ref_j,'String',num2str(ref_j))
1269
1270%% display list of pairstring
1271displ_pair_list=get(handles.ListPairs,'String');
1272NewVal=[];
1273if ~isempty(displ_pair_list)
1274Val=get(handles.ListPairs,'Value');
1275NewVal=find(strcmp(displ_pair_list{Val},displ_pair),1);% look at the previous display in the new menu displ_pï¿œir
1276end
1277if ~isempty(NewVal)
1278    set(handles.ListPairs,'Value',NewVal)
1279else
1280    set(handles.ListPairs,'Value',1)
1281end
1282set(handles.ListPairs,'String',displ_pair)
1283
1284%-------------------------------------
1285function enable_i(handles,state)
1286set(handles.i_txt,'Visible',state)
1287set(handles.num_first_i,'Visible',state)
1288set(handles.num_last_i,'Visible',state)
1289set(handles.num_incr_i,'Visible',state)
1290% set(handles.num_MaxIndex_i,'Visible',state)
1291set(handles.num_ref_i,'Visible',state)
1292set(handles.ref_i_text,'Visible',state)
1293
1294%-----------------------------------
1295function enable_j(handles,state)
1296set(handles.j_txt,'Visible',state)
1297set(handles.num_first_j,'Visible',state)
1298set(handles.num_last_j,'Visible',state)
1299set(handles.num_incr_j,'Visible',state)
1300set(handles.num_ref_j,'Visible',state)
1301set(handles.ref_j_text,'Visible',state)
1302% if strcmp(state,'off')
1303%     set(handles.MinIndex,'ColumnName',{'imax'})
1304% set(handles.MinIndex,'ColumnEditable',logical(0))
1305% else
1306%         set(handles.MinIndex,'ColumnName',{'imax','jmax'})
1307% end
1308
1309
1310%%%%%%%%%%%%%%%%%%%%
1311%%  MAIN ActionName FUNCTIONS
1312%%%%%%%%%%%%%%%%%%%%
1313%------------------------------------------------------------------------
1314% --- Executes on button press in RUN.
1315function RUN_Callback(hObject, eventdata, handles)
1316%------------------------------------------------------------------------
1317
1318set(handles.RUN,'BusyAction','queue');
1319set(0,'CurrentFigure',handles.series)
1320set(handles.RUN, 'Enable','Off')
1321set(handles.RUN,'BackgroundColor',[0.831 0.816 0.784])
1322drawnow
1323
1324%% read the input parameters and set the output dir and nomenclature
1325[Series,OutputDir,errormsg]=prepare_jobs(handles);% get parameters form the GUI series
1326if ~isempty(errormsg)
1327    if ~strcmp(errormsg,'Cancel')
1328    msgbox_uvmat('ERROR',errormsg)
1329    end
1330    STOP_Callback([],[], handles)
1331    return
1332end
1333OutputNomType=nomtype2pair(Series.InputTable{1,4});% nomenclature for output files
1334DirXml=fullfile(OutputDir,'0_XML');
1335if ~exist(DirXml,'dir')
1336    [tild,msg1]=mkdir(DirXml);
1337    if ~strcmp(msg1,'')
1338        msgbox_uvmat('ERROR',['cannot create ' DirXml ': ' msg1]);%error message for directory creation
1339        return
1340    end
1341end
1342
1343%% select the Action modes
1344RunMode='local';%default
1345if isfield(Series.Action,'RunMode')
1346RunMode=Series.Action.RunMode;
1347end
1348ActionExt='.m';%default
1349if isfield(Series.Action,'ActionExt')
1350    ActionExt=Series.Action.ActionExt;% '.m' or '.sh' (compiled)
1351end
1352ActionName=Series.Action.ActionName;
1353ActionPath=Series.Action.ActionPath;
1354path_series=fileparts(which('series'));
1355
1356%% create the Action fct handle if RunMode option = 'local'
1357if strcmp(RunMode,'local')
1358    if ~isequal(ActionPath,path_series)
1359        eval(['spath=which(''' ActionName ''');']) %spath = current path of the selected function ACTION
1360        if ~exist(ActionPath,'dir')
1361            msgbox_uvmat('ERROR',['The prescribed function path ' ActionPath ' does not exist']);
1362            return
1363        end
1364        if ~isequal(spath,ActionPath)
1365            addpath(ActionPath)% add the prescribed path if not the current one
1366        end
1367    end
1368    eval(['h_fun=@' ActionName ';'])%create a function handle for ACTION
1369    if ~isequal(ActionPath,path_series)
1370        rmpath(ActionPath)% add the prescribed path if not the current one
1371    end
1372end
1373
1374%% Get RunTime code from the file PARAM.xml (needed to run compiled functions)
1375errormsg='';%default error message
1376xmlfile=fullfile(path_series,'PARAM.xml');
1377test_batch=0;%default: ,no batch mode available
1378if ~exist(xmlfile,'file')
1379    [success,message]=copyfile(fullfile(path_series,'PARAM.xml.default'),xmlfile);
1380end
1381RunTime='';
1382if strcmp(ActionExt,'.sh')
1383    if exist(xmlfile,'file')
1384        s=xml2struct(xmlfile);
1385        if strcmp(RunMode,'cluster_oar') && isfield(s,'BatchParam')
1386            if isfield(s.BatchParam,'RunTime')
1387                RunTime=s.BatchParam.RunTime;
1388            end
1389            if isfield(s.BatchParam,'NbCore')
1390                NbCore=s.BatchParam.NbCore;
1391            end
1392        elseif (strcmp(RunMode,'background')||strcmp(RunMode,'local')) && isfield(s,'RunParam')
1393            if isfield(s.RunParam,'RunTime')
1394                RunTime=s.RunParam.RunTime;
1395            end
1396            if isfield(s.RunParam,'NbCore')
1397                NbCore=s.RunParam.NbCore;
1398            end
1399        end
1400    end
1401    if isempty(RunTime) && strcmp(RunMode,'cluster_oar')
1402        msgbox_uvmat('ERROR','RunTime name not found in PARAM.xml, compiled version .sh cannot run on cluster')
1403        return
1404    end
1405%     Series.RunTime=RunTime;
1406end
1407
1408%% set nbre of cluster cores and processes
1409switch RunMode
1410    case {'local','background'}
1411        NbCore=1;% no need to split the calculation
1412    case 'cluster_oar'
1413        if strcmp(Series.Action.ActionExt,'.m')% case of Matlab function (uncompiled)
1414            NbCore=1;% one core used only (limitation of Matlab licences)
1415            msgbox_uvmat('WARNING','Number of cores =1: select the compiled version civ_matlab.sh for multi-core processing');
1416            extra_oar='';
1417        else
1418            answer=inputdlg({'Number of cores (max 36)','extra oar options'},'oarsub parameter',1,{'12',''});
1419            NbCore=str2double(answer{1});
1420            extra_oar=answer{2};
1421        end
1422end
1423if ~isfield(Series.IndexRange,'NbSlice')
1424    Series.IndexRange.NbSlice=[];
1425end
1426if isempty(Series.IndexRange.NbSlice)
1427    NbProcess=NbCore;% choose one process per core
1428else
1429    NbProcess=Series.IndexRange.NbSlice;% the nbre of run processes is equal to the number of slices
1430    NbCore=min(NbCore,NbProcess);% at least one process per core
1431end
1432
1433%% read index ranges
1434first_i=1;
1435last_i=1;
1436incr_i=1;
1437first_j=1;
1438last_j=1;
1439if isfield(Series.IndexRange,'first_i')
1440    first_i=Series.IndexRange.first_i;
1441    incr_i=Series.IndexRange.incr_i;
1442    last_i=Series.IndexRange.last_i;
1443end
1444if isfield(Series.IndexRange,'first_j')
1445    first_j=Series.IndexRange.first_j;
1446    last_j=Series.IndexRange.last_j;
1447end
1448if last_i < first_i || last_j < first_j , msgbox_uvmat('ERROR','last field number must be larger than the first one'),...
1449        set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return
1450else
1451    BlockLength=ceil(numel(first_i:incr_i:last_i)/NbProcess);
1452end
1453
1454%% direct processing on the current Matlab session
1455if strcmp (RunMode,'local')
1456    Series.RUNHandle=handles.RUN;
1457    Series.WaitbarHandle=handles.Waitbar;
1458    for iprocess=1:NbProcess
1459        if isempty(Series.IndexRange.NbSlice)
1460            Series.IndexRange.first_i=first_i+(iprocess-1)*BlockLength*incr_i;
1461            if Series.IndexRange.first_i>last_i
1462                break
1463            end
1464            Series.IndexRange.last_i=min(first_i+(iprocess)*BlockLength*incr_i-1,last_i);
1465        else
1466            Series.IndexRange.first_i= first_i+iprocess-1;
1467            Series.IndexRange.incr_i=incr_i*Series.IndexRange.NbSlice;
1468        end
1469        t=struct2xml(Series);
1470        t=set(t,1,'name','Series');
1471        filexml=fullfile_uvmat(DirXml,'',Series.InputTable{1,3},'.xml',OutputNomType,...
1472            Series.IndexRange.first_i,Series.IndexRange.last_i,first_j,last_j);
1473        save(t,filexml);
1474        switch ActionExt
1475            case '.m'
1476                h_fun(Series);
1477            case '.sh'
1478                switch computer
1479                    case {'PCWIN','PCWIN64'} %Windows system
1480                        filexml=regexprep(filexml,'\\','\\\\');% add '\' so that '\' are left as characters
1481                        system([fullfile(ActionPath,[ActionName '.sh']) ' ' RunTime ' ' filexml]);% TODO: adapt to DOS system
1482                    case {'GLNX86','GLNXA64','MACI64'}%Linux  system
1483                        system([fullfile(ActionPath,[ActionName '.sh']) ' ' RunTime ' ' filexml]);
1484                end
1485        end
1486    end
1487elseif strcmp(get(handles.OutputDirExt,'Visible'),'off')
1488    msgbox_uvmat('ERROR',['no output file for Action ' ActionName ', use run mode = local']);% a output dir is needed for background option
1489    return
1490else
1491    %% processing on a different session of the same computer (background) or cluster, create executable files
1492    batch_file_list=cell(NbProcess,1);% initiate the list of executable files
1493    DirBat=fullfile(OutputDir,'0_BAT');
1494    %create subdirectory for executable files
1495    if ~exist(DirBat,'dir')
1496        [tild,msg1]=mkdir(DirBat);
1497        if ~strcmp(msg1,'')
1498            msgbox_uvmat('ERROR',['cannot create ' DirBat ': ' msg1]);%error message for directory creation
1499            return
1500        end
1501    end
1502    %create subdirectory for log files
1503    DirLog=fullfile(OutputDir,'0_LOG');
1504    if ~exist(DirLog,'dir')
1505        [tild,msg1]=mkdir(DirLog);
1506        if ~strcmp(msg1,'')
1507            msgbox_uvmat('ERROR',['cannot create ' DirLog ': ' msg1]);%error message for directory creation
1508            return
1509        end
1510    end
1511    for iprocess=1:NbProcess
1512        if isempty(Series.IndexRange.NbSlice)% process by blocks of i index
1513            Series.IndexRange.first_i=first_i+(iprocess-1)*BlockLength*incr_i;
1514            if Series.IndexRange.first_i>last_i
1515                NbProcess=iprocess-1;
1516                break% leave the loop, we are at the end of the calculation
1517            end
1518            Series.IndexRange.last_i=min(last_i,first_i+(iprocess)*BlockLength*incr_i-1);
1519        else% process by slices of i index if NbSlice is defined, computation in a single process if NbSlice =1
1520            Series.IndexRange.first_i= first_i+iprocess-1;
1521            Series.IndexRange.incr_i=incr_i*Series.IndexRange.NbSlice;
1522        end
1523       
1524        % create, fill and save the xml parameter file
1525        t=struct2xml(Series);
1526        t=set(t,1,'name','Series');
1527        filexml=fullfile_uvmat(DirXml,'',Series.InputTable{1,3},'.xml',OutputNomType,...
1528            Series.IndexRange.first_i,Series.IndexRange.last_i,first_j,last_j);
1529        save(t,filexml);% save the parameter file
1530       
1531        %create the executable file
1532%         filebat=fullfile_uvmat(DirBat,'',Series.InputTable{1,3},'.bat',OutputNomType,...
1533%             Series.IndexRange.first_i,Series.IndexRange.last_i,first_j,last_j);
1534         filebat=fullfile_uvmat(DirBat,'',Series.InputTable{1,3},'.sh',OutputNomType,...
1535           Series.IndexRange.first_i,Series.IndexRange.last_i,first_j,last_j);
1536        batch_file_list{iprocess}=filebat;
1537        [fid,message]=fopen(filebat,'w');% create the executable file
1538        if isequal(fid,-1)
1539            msgbox_uvmat('ERROR', ['creation of .bat file: ' message]);
1540            return
1541        end
1542       
1543        % set the log file name
1544        filelog=fullfile_uvmat(DirLog,'',Series.InputTable{1,3},'.log',OutputNomType,...
1545            Series.IndexRange.first_i,Series.IndexRange.last_i,first_j,last_j);
1546       
1547        % fill and save the executable file
1548        switch ActionExt
1549            case '.m'% Matlab function
1550                switch computer
1551                    case {'GLNX86','GLNXA64','MACI64'}
1552                        cmd=[...
1553                            '#!/bin/bash \n'...
1554                            '. /etc/sysprofile \n'...
1555                            'matlab -nodisplay -nosplash -nojvm -logfile ''' filelog ''' <<END_MATLAB \n'...
1556                            'addpath(''' path_series '''); \n'...
1557                            'addpath(''' Series.Action.ActionPath '''); \n'...
1558                            '' Series.Action.ActionName  '( ''' filexml '''); \n'...
1559                            'exit \n'...
1560                            'END_MATLAB \n'];
1561                        fprintf(fid,cmd);%fill the executable file with the  char string cmd
1562                        fclose(fid);% close the executable file
1563                        system(['chmod +x ' filebat]);% set the file to executable
1564                    case {'PCWIN','PCWIN64'}
1565                        text_matlabscript=['matlab -automation -logfile ' regexprep(filelog,'\\','\\\\')...
1566                            ' -r "addpath(''' regexprep(path_series,'\\','\\\\') ''');'...
1567                            'addpath(''' regexprep(Series.Action.ActionPath,'\\','\\\\') ''');'...
1568                            '' Series.Action.ActionName  '( ''' regexprep(filexml,'\\','\\\\') ''');exit"'];
1569                        fprintf(fid,text_matlabscript);%fill the executable file with the  char string cmd
1570                        fclose(fid);% close the executable file
1571                end
1572            case '.sh' % compiled Matlab function
1573                switch computer
1574                    case {'GLNX86','GLNXA64','MACI64'}
1575                        cmd=['#!/bin/bash \n '...
1576                            '#$ -cwd \n '...
1577                            'hostname && date \n '...
1578                            'umask 002 \n'...
1579                            fullfile(ActionPath,[ActionName '.sh']) ' ' RunTime ' ' filexml];%allow writting access to created files for user group
1580                        fprintf(fid,cmd);%fill the executable file with the  char string cmd
1581                        fclose(fid);% close the executable file
1582                        system(['chmod +x ' filebat]);% set the file to executable
1583                       
1584                    case {'PCWIN','PCWIN64'}    %       TODO: adapt to Windows system
1585                        %                                 cmd=['matlab -automation -logfile ' regexprep(filelog,'\\','\\\\')...
1586                        %                                     ' -r "addpath(''' regexprep(path_series,'\\','\\\\') ''');'...
1587                        %                                     'addpath(''' regexprep(Series.Action.ActionPath,'\\','\\\\') ''');'...
1588                        %                                     '' Series.Action.ActionName  '( ''' regexprep(filexml,'\\','\\\\') ''');exit"'];
1589                        fprintf(fid,cmd);
1590                        fclose(fid);
1591                        %                               dos([filebat ' &']);
1592                end
1593        end
1594    end
1595end
1596
1597%% launch the executable files for background or cluster processing
1598switch RunMode
1599    case 'background'
1600        for iprocess=1:NbProcess
1601            system(batch_file_list{iprocess})% directly execute the command file for each process
1602        end
1603    case 'cluster_oar' % option 'oar-parexec' used
1604        %create subdirectory for oar command and log files
1605        DirOAR=fullfile(OutputDir,'0_OAR');
1606        if ~exist(DirOAR,'dir')
1607            [tild,msg1]=mkdir(DirOAR);
1608            if ~strcmp(msg1,'')
1609                msgbox_uvmat('ERROR',['cannot create ' DirOAR ': ' msg1]);%error message for directory creation
1610                return
1611            end
1612        end
1613        max_walltime=3600*12; % 12h max
1614        walltime_onejob=600;%seconds
1615        filename_joblist=fullfile(DirOAR,'job_list.txt');%create name of the global executable file
1616        fid=fopen(filename_joblist,'w');
1617        for p=1:length(batch_file_list)
1618            fprintf(fid,[batch_file_list{p} '\n']);% list of exe files
1619        end
1620        fclose(fid);
1621        system(['chmod +x ' filename_joblist]);% set the file to executable
1622        oar_command=['oarsub -n CIVX '...
1623            '-t idempotent --checkpoint ' num2str(walltime_onejob+60) ' '...
1624            '-l /core=' num2str(NbCore) ','...
1625            'walltime=' datestr(min(1.05*walltime_onejob/86400*max(length(batch_file_list),NbCore)/NbCore,max_walltime/86400),13) ' '...
1626            '-E ' regexprep(filename_joblist,'\.txt\>','.stderr') ' '...
1627            '-O ' regexprep(filename_joblist,'\.txt\>','.stdout') ' '...
1628            extra_oar ' '...
1629            '"oar-parexec -s -f ' filename_joblist ' '...
1630            '-l ' filename_joblist '.log"\n'];
1631        filename_oarcommand=fullfile(DirOAR,'oar_command');
1632        fid=fopen(filename_oarcommand,'w');
1633        fprintf(fid,oar_command);
1634        fclose(fid);
1635        fprintf(oar_command);% display in command line
1636        %system(['chmod +x ' oar_command]);% set the file to executable
1637        system(oar_command);     
1638end
1639
1640%% reset the GUI series
1641update_waitbar(handles.Waitbar,1); % put the waitbar to end position to indicate launching is finished
1642set(handles.RUN, 'Enable','On')
1643set(handles.RUN,'BackgroundColor',[1 0 0])
1644set(handles.RUN, 'Value',0)
1645
1646%------------------------------------------------------------------------
1647function STOP_Callback(hObject, eventdata, handles)
1648%------------------------------------------------------------------------
1649set(handles.RUN, 'BusyAction','cancel')
1650set(handles.RUN,'BackgroundColor',[1 0 0])
1651set(handles.RUN,'enable','on')
1652set(handles.RUN, 'Value',0)
1653
1654% %------------------------------------------------------------------------
1655% % --- Executes on button press in BIN.
1656% function BIN_Callback(hObject, eventdata, handles)
1657% %------------------------------------------------------------------------
1658%     cmd=['#!/bin/bash \n '...
1659%         '#$ -cwd \n '...
1660%         'hostname && date \n '...
1661%         'umask 002 \n'...
1662%         Param.xml.CivmBin ' ' Param.xml.RunTime ' ' filename_xml ' ' OutputFile '.nc'];
1663%     
1664%------------------------------------------------------------------------
1665% --- Main launch command, called by RUN and BATCH
1666
1667function [Series,OutputDir,errormsg]=prepare_jobs(handles)
1668%INPUT:
1669% handles: handles of graphic objects on the GUI series
1670
1671%------------------------------------------------------------------------
1672OutputDir='';
1673errormsg='';
1674
1675%% Read parameters from series
1676Series=read_GUI(handles.series);
1677
1678%% get_field GUI
1679% if isfield(Series,'InputFields')&&isfield(Series.InputFields,'Field')
1680%     if strcmp(Series.InputFields.Field,'get_field...')
1681%         hget_field=findobj(allchild(0),'name','get_field');
1682%         Series.GetField=read_GUI(hget_field);
1683%     end
1684% end
1685
1686%% create the output data directory
1687%determine the root file corresponding to the first sub dir
1688if get(handles.RUN,'value') && isfield(Series,'OutputSubDir')
1689    SubDirOut=[get(handles.OutputSubDir,'String') Series.OutputDirExt];
1690    SubDirOutNew=SubDirOut;
1691    SeriesData=get(handles.series,'UserData');
1692    if size(Series.InputTable,1)>1 && isfield(SeriesData,'AllowInputSort') && SeriesData.AllowInputSort
1693        [tild,iview]=sort(Series.InputTable(:,2)); %subdirectories sorted in alphabetical order
1694        Series.InputTable=Series.InputTable(iview,:);
1695    end
1696    detect=exist(fullfile(Series.InputTable{1,1},SubDirOutNew),'dir');% test if  the dir  already exist
1697    check_create=1; %need to create the result directory by default
1698    while detect
1699        answer=msgbox_uvmat('INPUT_Y-N',['use existing ouput directory: ' fullfile(Series.InputTable{1,1},SubDirOutNew) ', possibly delete previous data']);
1700        if strcmp(answer,'Cancel')
1701            errormsg='Cancel';
1702            return
1703        elseif strcmp(answer,'Yes')
1704            detect=0;
1705            check_create=0;
1706        else
1707            r=regexp(SubDirOutNew,'(?<root>.*\D)(?<num1>\d+)$','names');%detect whether name ends by a number
1708            if isempty(r)
1709                r(1).root=[SubDirOutNew '_'];
1710                r(1).num1='0';
1711            end
1712            SubDirOutNew=[r(1).root num2str(str2num(r(1).num1)+1)];%increment the index by 1 or put 1
1713            detect=exist(fullfile(Series.InputTable{1,1},SubDirOutNew),'dir');% test if  the dir  already exists   
1714            check_create=1;
1715        end
1716    end
1717    Series.OutputDirExt=regexprep(SubDirOutNew,Series.OutputSubDir,'');
1718    Series.OutputRootFile=Series.InputTable{1,3};% the first sorted RootFile taken for output
1719    set(handles.OutputDirExt,'String',Series.OutputDirExt)
1720    OutputDir=fullfile(Series.InputTable{1,1},[Series.OutputSubDir Series.OutputDirExt]);% full name (with path) of output directory
1721    if check_create    % create output directory if it does not exist
1722        [tild,msg1]=mkdir(OutputDir);
1723        if ~strcmp(msg1,'')
1724            errormsg=['cannot create ' OutputDir ': ' msg1];%error message for directory creation
1725            return
1726        end
1727    end
1728   % RootOut=fullfile(OutputDir,Series.InputTable{1,3});% name of the parameter xml file set in this directory
1729end
1730
1731%% removes unused information on Series
1732if isfield(Series,'Pairs')
1733    Series=rmfield(Series,'Pairs'); %info Pairs not needed for output
1734end
1735Series.IndexRange=rmfield(Series.IndexRange,'TimeTable');
1736% Series.IndexRange=rmfield(Series.IndexRange,'MinIndex');
1737% Series.IndexRange=rmfield(Series.IndexRange,'MaxIndex');
1738empty_line=false(size(Series.InputTable,1),1);
1739for iline=1:size(Series.InputTable,1)
1740    empty_line(iline)=isequal(Series.InputTable(iline,1:3),{'','',''});
1741end
1742Series.InputTable(empty_line,:)=[];
1743
1744%------------------------------------------------------------------------
1745% --- Executes on selection change in ActionName.
1746function ActionName_Callback(hObject, eventdata, handles)
1747%------------------------------------------------------------------------
1748%% stop any ongoing series processing
1749if isequal(get(handles.RUN,'Value'),1)
1750    answer= msgbox_uvmat('INPUT_Y-N','stop current Action process?');
1751    if strcmp(answer,'Yes')
1752        STOP_Callback(hObject, eventdata, handles)
1753    else
1754        return
1755    end
1756end
1757set(handles.ActionName,'BackgroundColor',[1 1 0])
1758drawnow
1759
1760%% get Action name and path
1761nb_builtin_ACTION=4; %nbre of functions initially proposed in the menu ActionName (as defined in the Opening fct of series)
1762ActionList=get(handles.ActionName,'String');% list menu fields
1763ActionIndex=get(handles.ActionName,'Value');
1764if ~isequal(ActionIndex,1)
1765    InputTable=get(handles.InputTable,'Data');
1766    if isempty(InputTable{1,4})
1767        msgbox_uvmat('ERROR','no input file available: use Open in the menu bar')
1768        return
1769    end
1770end
1771ActionName= ActionList{get(handles.ActionName,'Value')}; % selected function name
1772ActionPathList=get(handles.ActionName,'UserData');%list of recorded paths to functions of the list ActionName
1773
1774%% add a new function to the menu if 'more...' has been selected in the menu ActionName
1775if isequal(ActionName,'more...')
1776    [FileName, PathName] = uigetfile( ...
1777        {'*.m', ' (*.m)';
1778        '*.m',  '.m files '; ...
1779        '*.*', 'All Files (*.*)'}, ...
1780        'Pick a series processing function ',get(handles.ActionPath,'String'));
1781    if length(FileName)<2
1782        return
1783    end
1784    [ActionPath,ActionName,ActionExt]=fileparts(FileName);
1785   
1786    % insert the choice in the menu ActionName
1787    ActionIndex=find(strcmp(ActionName,ActionList),1);% look for the selected function in the menu Action
1788    if isempty(ActionIndex)%the input string does not exist in the menu
1789        ActionIndex= length(ActionList);
1790        ActionList=[ActionList(1:end-1);{ActionName};ActionList(end)];% the selected function is appended in the menu, before the last item 'more...'
1791        set(handles.ActionName,'String',ActionList)
1792    end
1793   
1794    % record the file extension and extend the path list if it is a new extension
1795    ActionExtList=get(handles.ActionExt,'String');
1796    ActionExtIndex=find(strcmp(ActionExt,ActionExtList), 1);
1797    if isempty(ActionExtIndex)
1798        set(handles.ActionExt,'String',[ActionExtList;{ActionExt}])
1799        ActionExtIndex=numel(ActionExtList)+1;
1800        ActionPathNew=cell(size(ActionPathList,1),1);%new column of ActionPath
1801        ActionPathList=[ActionPathList ActionPathNew];
1802    end
1803    set(handles.ActionName,'UserData',ActionPathList);
1804
1805    % remove old Action options in the menu (keeping a menu length <nb_builtin_ACTION+5)
1806    if length(ActionList)>nb_builtin_ACTION+5; %nb_builtin=nbre of functions always remaining in the initial menu
1807        nbremove=length(ActionList)-nb_builtin_ACTION-5;
1808        ActionList(nb_builtin_ACTION+1:end-5)=[];
1809        ActionPathList(nb_builtin_ACTION+1:end-4,:)=[];
1810        ActionIndex=ActionIndex-nbremove;
1811    end
1812   
1813    % record action menu, choice and path
1814    set(handles.ActionName,'Value',ActionIndex)
1815    set(handles.ActionName,'String',ActionList)
1816    set(handles.ActionExt,'Value',ActionExtIndex)
1817    ActionPathList{ActionIndex,ActionExtIndex}=PathName;
1818       
1819    %record the user defined menu additions in personal file profil_perso
1820    dir_perso=prefdir;
1821    profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
1822    if nb_builtin_ACTION+1<=numel(ActionList)-1
1823        ActionListUser=ActionList(nb_builtin_ACTION+1:numel(ActionList)-1);
1824        ActionPathListUser=ActionPathList(nb_builtin_ACTION+1:numel(ActionList)-1,:);
1825        ActionExtListUser={};
1826        if numel(ActionExtList)>2
1827            ActionExtListUser=ActionExtList(3:end);
1828        end
1829        if exist(profil_perso,'file')
1830            save(profil_perso,'ActionListUser','ActionPathListUser','ActionExtListUser','-append')
1831        else
1832            save(profil_perso,'ActionListUser','ActionPathListUser','ActionExtListUser','-V6')
1833        end
1834    end
1835end
1836
1837%% check the current ActionPath to the selected function
1838ActionPath=ActionPathList{ActionIndex};%current recorded path
1839set(handles.ActionPath,'String',ActionPath); %show the path to the senlected function
1840
1841%% reinitialise the waitbar
1842update_waitbar(handles.Waitbar,0)
1843
1844%% default setting for the visibility of the GUI elements
1845% set(handles.FieldTransform,'Visible','off')
1846% set(handles.CheckObject,'Visible','off');
1847% set(handles.ProjObject,'Visible','off');
1848% set(handles.CheckMask,'Visible','off')
1849% set(handles.Mask,'Visible','off')
1850
1851%% create the function handle for Action
1852path_series=which('series');
1853if ~isequal(ActionPath,path_series)
1854    eval(['spath=which(''' ActionName ''');']) %spath = current path of the selected function ACTION
1855    if ~exist(ActionPath,'dir')
1856        errormsg=['The prescribed function path ' ActionPath ' does not exist'];
1857        return
1858    end
1859    if ~isequal(spath,ActionPath)
1860        addpath(ActionPath)% add the prescribed path if not the current one
1861    end
1862end
1863eval(['h_fun=@' ActionName ';'])%create a function handle for ACTION
1864if ~isequal(ActionPath,path_series)
1865        rmpath(ActionPath)% add the prescribed path if not the current one   
1866end
1867
1868%% Activate the Action fct
1869[Series,tild,errormsg]=prepare_jobs(handles);% read the parameters from the GUI series
1870if ~isempty(errormsg)
1871    if ~strcmp(errormsg,'Cancel')
1872    msgbox_uvmat('ERROR',errormsg)
1873    end
1874    return
1875end
1876ParamOut=h_fun(Series);
1877
1878%% Put the first line of the selected Action fct as tooltip help
1879try
1880    [fid,errormsg] =fopen([ActionName '.m']);
1881    InputText=textscan(fid,'%s',1,'delimiter','\n');
1882    fclose(fid);
1883    set(handles.ActionName,'ToolTipString',InputText{1}{1})% put the first line of the selected function as tooltip help
1884end
1885
1886%% Detect the types of input files
1887SeriesData=get(handles.series,'UserData');
1888nb_civ=0;nb_netcdf=0;
1889if ~isempty(SeriesData)
1890    nb_civ=numel(find(strcmp('civx',SeriesData.FileType)|strcmp('civdata',SeriesData.FileType)));
1891    nb_netcdf=numel(find(strcmp('netcdf',SeriesData.FileType)));
1892end
1893
1894%% Check whether alphabetical sorting of input Subdir is alowed by the Action fct  (for multiples series entries)
1895SeriesData.AllowInputSort=0;%default
1896if isfield(ParamOut,'AllowInputSort')&&isequal(ParamOut.AllowInputSort,'on')
1897    SeriesData.AllowInputSort=1;
1898end
1899
1900%% Impose the whole input file index range if requested
1901if isfield(ParamOut,'WholeIndexRange')&&isequal(ParamOut.WholeIndexRange,'on')
1902    MinIndex=get(handles.MinIndex,'Data');
1903    MaxIndex=get(handles.MaxIndex,'Data');
1904    if ~isempty(MinIndex)
1905        set(handles.num_first_i,'String',num2str(MinIndex{1}))
1906        set(handles.num_last_i,'String',num2str(MaxIndex{1}))
1907        set(handles.num_incr_i,'String','1')
1908        if size(MinIndex,2)>=2
1909            set(handles.num_first_j,'String',num2str(MinIndex{1,2}))
1910            set(handles.num_last_j,'String',num2str(MaxIndex{1,2}))
1911            set(handles.num_incr_j,'String','1')
1912        end
1913    end
1914else
1915% check index ranges
1916first_i=1;last_i=1;first_j=1;last_j=1;
1917if isfield(Series.IndexRange,'first_i')
1918    first_i=Series.IndexRange.first_i;
1919    last_i=Series.IndexRange.last_i;
1920end
1921if isfield(Series.IndexRange,'first_j')
1922    first_j=Series.IndexRange.first_j;
1923    last_j=Series.IndexRange.last_j;
1924end
1925if last_i < first_i || last_j < first_j , msgbox_uvmat('ERROR','last field number must be larger than the first one'),...
1926    set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
1927end
1928
1929%% NbSlice visibility
1930NbSliceVisible='off';%default
1931if isfield(ParamOut,'NbSlice') && isequal(ParamOut.NbSlice,'on')
1932    NbSliceVisible='on';
1933    set(handles.num_NbProcess,'String',get(handles.num_NbSlice,'String'))% the nbre of processes is imposed as the nbre of slices
1934else
1935    set(handles.num_NbProcess,'String','')% free nbre of processes
1936end
1937set(handles.num_NbSlice,'Visible',NbSliceVisible)
1938set(handles.NbSlice_title,'Visible',NbSliceVisible)
1939
1940%% Visibility of VelType and VelType_1 menus
1941VelTypeVisible='off';  %hidden by default
1942VelType_1Visible='off';
1943InputFieldsVisible='off';%visibility of the frame Fields
1944if isfield(ParamOut,'VelType')
1945    if strcmp( ParamOut.VelType,'one')||strcmp( ParamOut.VelType,'two')
1946        if nb_civ>=1
1947            VelTypeVisible='on';
1948            InputFieldsVisible='on';
1949        end
1950    end
1951    if strcmp( ParamOut.VelType,'two')
1952        if nb_civ>=2
1953            VelType_1Visible='on';
1954        end
1955    end
1956end
1957set(handles.VelType,'Visible',VelTypeVisible)
1958set(handles.VelType_text,'Visible',VelTypeVisible);
1959set(handles.VelType_1,'Visible',VelType_1Visible)
1960set(handles.VelType_text_1,'Visible',VelType_1Visible);
1961
1962%% Visibility of FieldName and FieldName_1 menus
1963FieldNameVisible='off';  %hidden by default
1964FieldName_1Visible='off';  %hidden by default
1965if isfield(ParamOut,'FieldName')
1966    if strcmp( ParamOut.FieldName,'one')||strcmp( ParamOut.FieldName,'two')
1967        if (nb_civ+nb_netcdf)>=1
1968            InputFieldsVisible='on';
1969            FieldNameVisible='on';
1970        end
1971    end
1972    if strcmp( ParamOut.FieldName,'two')
1973        if (nb_civ+nb_netcdf)>=1
1974            FieldName_1Visible='on';
1975        end
1976    end
1977end
1978set(handles.InputFields,'Visible',InputFieldsVisible)
1979set(handles.FieldName,'Visible',FieldNameVisible) % test for MenuBorser
1980set(handles.FieldName_1,'Visible',FieldName_1Visible)
1981
1982%% Visibility of FieldTransform menu
1983FieldTransformVisible='off';  %hidden by default
1984if isfield(ParamOut,'FieldTransform')
1985    FieldTransformVisible=ParamOut.FieldTransform; 
1986    TransformName_Callback([],[], handles)
1987end
1988set(handles.FieldTransform,'Visible',FieldTransformVisible)
1989
1990%% Visibility of projection object
1991ProjObjectVisible='off';  %hidden by default
1992if isfield(ParamOut,'ProjObject')
1993    ProjObjectVisible=ParamOut.ProjObject;
1994end
1995set(handles.CheckObject,'Visible',ProjObjectVisible)
1996if ~get(handles.CheckObject,'Value')
1997    ProjObjectVisible='off';
1998end
1999set(handles.ProjObject,'Visible',ProjObjectVisible)
2000set(handles.DeleteObject,'Visible',ProjObjectVisible)
2001set(handles.ViewObject,'Visible',ProjObjectVisible)
2002
2003
2004%% Visibility of mask input
2005MaskVisible='off';  %hidden by default
2006if isfield(ParamOut,'Mask')
2007    MaskVisible=ParamOut.Mask;
2008end
2009set(handles.Mask,'Visible',MaskVisible)
2010set(handles.CheckMask,'Visible',MaskVisible);
2011
2012%% definition of the directory containing the output files
2013OutputDirVisible='off';
2014if isfield(ParamOut,'OutputDirExt')&&~isempty(ParamOut.OutputDirExt)
2015    set(handles.OutputDirExt,'String',ParamOut.OutputDirExt)
2016    OutputDirVisible='on';
2017end
2018set(handles.OutputDirExt,'Visible',OutputDirVisible)
2019set(handles.OutputSubDir,'Visible',OutputDirVisible)
2020set(handles.OutputDir_title,'Visible',OutputDirVisible)
2021set(handles.RunMode,'Visible',OutputDirVisible)
2022set(handles.ActionExt,'Visible',OutputDirVisible)
2023set(handles.RunMode_title,'Visible',OutputDirVisible)
2024set(handles.ActionExt_title,'Visible',OutputDirVisible)
2025
2026%% definition of an additional parameter set, determined by an ancillary GUI
2027if isfield(ParamOut,'ActionInput')
2028    set(handles.ActionInput,'Visible','on')
2029    set(handles.ActionInput_title,'Visible','on')
2030    set(handles.ActionInputView,'Visible','on')
2031    set(handles.ActionInputView,'Value',0)
2032    set(handles.ActionInput,'String',ActionName)
2033    ParamOut.ActionInput.Program=ActionName; % record the program in ActionInput
2034    SeriesData.ActionInput=ParamOut.ActionInput;
2035else
2036    set(handles.ActionInput,'Visible','off')
2037    set(handles.ActionInput_title,'Visible','off')
2038    set(handles.ActionInputView,'Visible','off')
2039    if isfield(SeriesData,'ActionInput')
2040    SeriesData=rmfield(SeriesData,'ActionInput');
2041    end
2042end   
2043set(handles.series,'UserData',SeriesData)
2044set(handles.ActionName,'BackgroundColor',[1 1 1])
2045
2046%------------------------------------------------------------------------
2047% --- Executes on button press in ActionInputView.
2048function ActionInputView_Callback(hObject, eventdata, handles)
2049%------------------------------------------------------------------------
2050if get(handles.ActionInputView,'Value')
2051ActionName_Callback(hObject, eventdata, handles)
2052end
2053
2054%------------------------------------------------------------------------
2055% --- Executes on selection change in FieldName.
2056function FieldName_Callback(hObject, eventdata, handles)
2057%------------------------------------------------------------------------
2058field_str=get(handles.FieldName,'String');
2059field_index=get(handles.FieldName,'Value');
2060field=field_str{field_index(1)};
2061if isequal(field,'get_field...')
2062    hget_field=findobj(allchild(0),'name','get_field');
2063    if ~isempty(hget_field)
2064        delete(hget_field)%delete opened versions of get_field
2065    end
2066    Series=read_GUI(handles.series);
2067    Series.InputTable=Series.InputTable(1,:);
2068    filecell=get_file_series(Series);
2069    if exist(filecell{1,1},'file')
2070        GetFieldData=get_field(filecell{1,1});
2071        FieldList={};
2072        XName=GetFieldData.XVarName;
2073        if GetFieldData.CheckVector
2074            UName=GetFieldData.PanelVectors.vector_x;
2075            VName=GetFieldData.PanelVectors.vector_y;
2076            XName=GetFieldData.XVarName;
2077            YName=GetFieldData.YVarName;
2078            CName=GetFieldData.PanelVectors.vec_color;
2079            [FieldList,VecColorList]=set_field_list(UName,VName,CName);
2080        elseif GetFieldData.CheckScalar
2081            AName=GetFieldData.PanelScalar.scalar;
2082            XName=GetFieldData.XVarName;
2083            YName=GetFieldData.YVarName;
2084            FieldList={AName};
2085        elseif GetFieldData.CheckPlot1D;
2086            YName=GetFieldData.CheckPlot1D.ordinate;
2087        end
2088        set(handles.Coord_x,'String',{XName})
2089        set(handles.Coord_y,'String',{YName})
2090        set(handles.FieldName,'Value',1)
2091        set(handles.FieldName,'String',[FieldList; {'get_field...'}]);
2092        %         set(handles.ColorScalar,'Value',1)
2093        %         set(handles.ColorScalar,'String',VecColorList);
2094        %         UvData.FileType{1}='netcdf';
2095        %         set(handles.uvmat,'UserData',UvData)
2096    end
2097    % elseif isequal(field,'more...')
2098    %     str=calc_field;
2099    %     [ind_answer,v] = listdlg('PromptString','Select a file:',...
2100    %                 'SelectionMode','single',...
2101    %                 'ListString',str);
2102    %        % edit the choice in the fields and actionname menu
2103    %      scalar=cell2mat(str(ind_answer));
2104    %      update_menu(handles.FieldName,scalar)
2105end
2106
2107%------------------------------------------------------------------------
2108% --- Executes on selection change in FieldName_1.
2109function FieldName_1_Callback(hObject, eventdata, handles)
2110%------------------------------------------------------------------------
2111field_str=get(handles.FieldName_1,'String');
2112field_index=get(handles.FieldName_1,'Value');
2113field=field_str{field_index};
2114if isequal(field,'get_field...')   
2115     hget_field=findobj(allchild(0),'name','get_field_1');
2116     if ~isempty(hget_field)
2117         delete(hget_field)
2118     end
2119     SeriesData=get(handles.series,'UserData');
2120     filename=SeriesData.CurrentInputFile_1;
2121     if exist(filename,'file')
2122        hget_field=get_field(filename);
2123        set(hget_field,'name','get_field_1')
2124     end
2125% elseif isequal(field,'more...')
2126%     str=calc_field;
2127%     [ind_answer,v] = listdlg('PromptString','Select a file:',...
2128%                 'SelectionMode','single',...
2129%                 'ListString',str);
2130%        % edit the choice in the fields and actionname menu
2131%      scalar=cell2mat(str(ind_answer));
2132%      update_menu(handles.FieldName_1,scalar)
2133end   
2134
2135
2136%%%%%%%%%%%%%
2137function [ind_remove]=find_pairs(dirpair,ind_i,last_i)
2138indsel=ind_i;
2139indiff=diff(ind_i); %test index increment to detect multiplets (several pairs with the same index ind_i) and holes in the series
2140indiff=[1 indiff last_i-ind_i(end)+1];%for testing gaps with the imposed bounds
2141if ~isempty(indiff)
2142    indiff2=diff(indiff);
2143    indiffp=[indiff2 1];
2144    indiffm=[1 indiff2];
2145    ind_multi_m=find((indiff==0)&(indiffm<0))-1;%indices of first members of multiplets
2146    ind_multi_p=find((indiff==0)&(indiffp>0));%indices of last members of multiplets
2147    %for each multiplet, select the most recent file
2148    ind_remove=[];
2149    for i=1:length(ind_multi_m)
2150        ind_pairs=ind_multi_m(i):ind_multi_p(i);
2151        for imulti=1:length(ind_pairs)
2152            datepair(imulti)=datenum(dirpair(ind_pairs(imulti)).date);%dates of creation
2153        end
2154        [datenew,indsort2]=sort(datepair); %sort the multiplet by creation date
2155        ind_s=indsort2(1:end-1);%
2156        ind_remove=[ind_remove ind_pairs(ind_s)];%remove these indices, leave the last one
2157    end
2158end
2159
2160%------------------------------------------------------------------------
2161% --- determine the list of index pairstring of processing file
2162function [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)
2163%------------------------------------------------------------------------
2164num_i1=num_i;% set of first image numbers by default
2165num_i2=num_i;
2166num_j1=num_j;
2167num_j2=num_j;
2168num_i_out=num_i;
2169num_j_out=num_j;
2170% if isequal (NomType,'_1-2_1') || isequal (NomType,'_1-2')
2171if isequal(mode,'series(Di)')
2172    num_i1_line=num_i+ind_shift(3);% set of first image numbers
2173    num_i2_line=num_i+ind_shift(4);
2174    % adjust the first and last field number
2175        indsel=find(num_i1_line >= 1);
2176    num_i_out=num_i(indsel);
2177    num_i1_line=num_i1_line(indsel);
2178    num_i2_line=num_i2_line(indsel);
2179    num_j1=meshgrid(num_j,ones(size(num_i1_line)));
2180    num_j2=meshgrid(num_j,ones(size(num_i1_line)));
2181    [xx,num_i1]=meshgrid(num_j,num_i1_line);
2182    [xx,num_i2]=meshgrid(num_j,num_i2_line);
2183elseif isequal (mode,'series(Dj)')||isequal (mode,'bursts')
2184    if isequal(mode,'bursts') %case of bursts (png_old or png_2D)
2185        num_j1=ind_shift(1)*ones(size(num_i));
2186        num_j2=ind_shift(2)*ones(size(num_i));
2187    else
2188        num_j1_col=num_j+ind_shift(1);% set of first image numbers
2189        num_j2_col=num_j+ind_shift(2);
2190        % adjust the first field number
2191        indsel=find((num_j1_col >= 1));   
2192        num_j_out=num_j(indsel);
2193        num_j1_col=num_j1_col(indsel);
2194        num_j2_col=num_j2_col(indsel);
2195        [num_i1,num_j1]=meshgrid(num_i,num_j1_col);
2196        [num_i2,num_j2]=meshgrid(num_i,num_j2_col);
2197    end   
2198end
2199
2200%------------------------------------------------------------------------
2201% --- Executes on button press in CheckObject.
2202function CheckObject_Callback(hObject, eventdata, handles)
2203%------------------------------------------------------------------------
2204value=get(handles.CheckObject,'Value');
2205if value
2206%      set(handles.CheckObject,'BackgroundColor',[1 1 0])%put unactivated buttons to yellow
2207     hset_object=findobj(allchild(0),'tag','set_object');%find the set_object interface handle
2208     if ishandle(hset_object)
2209         uistack(hset_object,'top')% show the GUI set_object if opened
2210     else
2211         %get the object file
2212         InputTable=get(handles.InputTable,'Data');
2213         defaultname=InputTable{1,1};
2214         if isempty(defaultname)
2215            defaultname={''};
2216         end
2217        [FileName, PathName] = uigetfile( ...
2218       {'*.xml;*.mat', ' (*.xml,*.mat)';
2219       '*.xml',  '.xml files '; ...
2220        '*.mat',  '.mat matlab files '}, ...
2221        'Pick an xml object file (or use uvmat to create it)',defaultname);
2222        fileinput=[PathName FileName];%complete file name
2223        sizf=size(fileinput);
2224        if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end
2225        %read the file
2226        data=xml2struct(fileinput);
2227        if ~isfield(data,'Type')
2228             msgbox_uvmat('ERROR',[fileinput ' is not an object xml file'])
2229             return
2230        end
2231        if ~isfield(data,'ProjMode')
2232             data.ProjMode='none';
2233        end
2234        hset_object=set_object(data);% call the set_object interface
2235     end
2236     ProjObject=read_GUI(hset_object);
2237     set(handles.ProjObject,'String',ProjObject.Name);%display the object name
2238     SeriesData=get(handles.series,'UserData');
2239     SeriesData.ProjObject=ProjObject;
2240     set(handles.series,'UserData',SeriesData);
2241     set(handles.DeleteObject,'Visible','on');
2242     set(handles.ViewObject,'Visible','on');
2243     set(handles.ProjObject,'Visible','on');
2244else
2245         set(handles.DeleteObject,'Visible','off');
2246     set(handles.ViewObject,'Visible','off');
2247     set(handles.ProjObject,'Visible','off');
2248%     set(handles.CheckObject,'BackgroundColor',[0.7 0.7 0.7])%put activated buttons to green
2249end
2250%set(handles.series,'UserData',SeriesData)
2251
2252%--------------------------------------------------------------
2253function CheckMask_Callback(hObject, eventdata, handles)
2254value=get(handles.CheckMask,'Value');
2255if value
2256    msgbox_uvmat('ERROR','not implemented yet')
2257end
2258%--------------------------------------------------------------
2259
2260%-------------------------------------------------------------------
2261%'uv_ncbrowser': interactively calls the netcdf file browser 'get_field.m'
2262function ncbrowser_uvmat(hObject, eventdata)
2263%-------------------------------------------------------------------
2264     bla=get(gcbo,'String');
2265     ind=get(gcbo,'Value');
2266     filename=cell2mat(bla(ind));
2267      blank=find(filename==' ');
2268      filename=filename(1:blank-1);
2269     get_field(filename)
2270
2271% ------------------------------------------------------------------
2272function MenuHelp_Callback(hObject, eventdata, handles)
2273%-------------------------------------------------------------------
2274path_to_uvmat=which ('uvmat');% check the path of uvmat
2275pathelp=fileparts(path_to_uvmat);
2276helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html');
2277if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package')
2278else
2279    addpath (fullfile(pathelp,'uvmat_doc'))
2280    web([helpfile '#series'])
2281end
2282
2283%-------------------------------------------------------------------
2284% --- Executes on selection change in TransformName.
2285function TransformName_Callback(hObject, eventdata, handles)
2286%----------------------------------------------------------------------
2287TransformList=get(handles.TransformName,'String');
2288TransformIndex=get(handles.TransformName,'Value');
2289TransformName=TransformList{TransformIndex};
2290TransformPathList=get(handles.TransformName,'UserData');
2291nb_builtin_transform=4;
2292% ff=functions(list_transform{end});
2293if isequal(TransformName,'more...');
2294%     coord_fct='';
2295%     prompt = {'Enter the name of the transform function'};
2296%     dlg_title = 'user defined transform';
2297%     num_lines= 1;
2298    [FileName, PathName] = uigetfile( ...
2299       {'*.m', ' (*.m)';
2300        '*.m',  '.m files '; ...
2301        '*.*', 'All Files (*.*)'}, ...
2302        'Pick a transform function',get(handles.TransformPath,'String'));
2303    if isequal(FileName,0)
2304        return     %browser closed without choice
2305    end
2306    if isequal(PathName(end),'/')||isequal(PathName(end),'\')
2307        PathName(end)=[];
2308    end
2309    [TransformPath,TransformName,TransformExt]=fileparts(FileName);% removes extension .m
2310    if ~strcmp(TransformExt,'.m')
2311        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
2312        return
2313    end
2314     % insert the choice in the menu
2315    TransformIndex=find(strcmp(TransformName,TransformList),1);% look for the selected function in the menu Action
2316    if isempty(TransformIndex)%the input string does not exist in the menu
2317        TransformIndex= length(TransformList);
2318        TransformList=[TransformList(1:end-1);{TransformnName};TransformList(end)];% the selected function is appended in the menu, before the last item 'more...'
2319        set(handles.TransformName,'String',TransformList)
2320        TransformPathList=[TransformPathList;{TransformPath}];
2321    end
2322   % save the new menu in the personal file 'uvmat_perso.mat'
2323   dir_perso=prefdir;%personal Matalb directory
2324   profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
2325   if exist(profil_perso,'file')
2326       for ilist=nb_builtin_transform+1:numel(TransformPathList)
2327           TransformListUser{ilist-nb_builtin_transform}=TransformList{ilist};
2328           TransformPathListUser{ilist-nb_builtin_transform}=TransformPathList{ilist};
2329       end
2330       save (profil_perso,'TransformPathListUser','TransformListUser','-append'); %store the root name for future opening of uvmat
2331   end
2332end
2333
2334%display the current function path
2335set(handles.TransformPath,'String',TransformPathList{TransformIndex}); %show the path to the senlected function
2336set(handles.TransformName,'UserData',TransformPathList);
2337
2338
2339% --------------------------------------------------------------------
2340function MenuExportConfig_Callback(hObject, eventdata, handles)
2341global Series
2342[Series,errormsg]=prepare_jobs(handles);
2343
2344evalin('base','global Series')%make CurData global in the workspace
2345display('current series config :')
2346evalin('base','Series') %display CurData in the workspace
2347commandwindow; %brings the Matlab command window to the front
2348
2349
2350% --- Executes on selection change in RunMode.
2351function RunMode_Callback(hObject, eventdata, handles)
2352
2353% --- Executes on selection change in Coord_x.
2354function Coord_x_Callback(hObject, eventdata, handles)
2355
2356
2357% --- Executes on selection change in Coord_y.
2358function Coord_y_Callback(hObject, eventdata, handles)
2359
2360
2361
2362% --- Executes when series is resized.
2363function series_ResizeFcn(hObject, eventdata, handles)
2364%% input table
2365set(handles.InputTable,'Unit','pixel')
2366Pos=get(handles.InputTable,'Position');
2367set(handles.InputTable,'Unit','normalized')
2368ColumnWidth=round([0.5 0.14 0.14 0.14 0.08]*(Pos(3)-52));
2369ColumnWidth=num2cell(ColumnWidth);
2370set(handles.InputTable,'ColumnWidth',ColumnWidth)
2371
2372%% MinIndex and MaxIndex
2373set(handles.MinIndex,'Unit','pixel')
2374Pos=get(handles.MinIndex,'Position');
2375set(handles.MinIndex,'Unit','normalized')
2376ColumnWidth=get(handles.MinIndex,'ColumnWidth');
2377if numel(ColumnWidth)==2
2378    ColumnWidth=num2cell(floor([0.5 0.5]*(Pos(3)-20)));
2379else
2380    ColumnWidth={Pos(3)-5};
2381end   
2382set(handles.MinIndex,'ColumnWidth',ColumnWidth)
2383set(handles.MaxIndex,'ColumnWidth',ColumnWidth)
2384
2385%% TimeTable
2386set(handles.TimeTable,'Unit','pixel')
2387Pos=get(handles.TimeTable,'Position');
2388set(handles.TimeTable,'Unit','normalized')
2389ColumnWidth=get(handles.TimeTable,'ColumnWidth');
2390ColumnWidth=num2cell(floor([0.25 0.25 0.25 0.25]*(Pos(3)-20)));
2391set(handles.TimeTable,'ColumnWidth',ColumnWidth)
2392
2393
2394%% PairString
2395set(handles.PairString,'Unit','pixel')
2396Pos=get(handles.PairString,'Position');
2397set(handles.PairString,'Unit','normalized')
2398set(handles.PairString,'ColumnWidth',{Pos(3)-5})
2399
2400
2401% --- Executes on button press in status.
2402function status_Callback(hObject, eventdata, handles)
2403
2404if get(handles.status,'Value')
2405    set(handles.status,'BackgroundColor',[1 1 0])
2406    drawnow
2407    StatusData.time_ref=get(handles.RUN,'UserData');% get the time of launch
2408    Param=read_GUI(handles.series);
2409    RootPath=Param.InputTable{1,1};
2410    if ~isfield(Param,'OutputSubDir')   
2411        msgbox_uvmat('ERROR','no directory defined for output files')
2412        return
2413    end
2414    OutputSubDir=[Param.OutputSubDir Param.OutputDirExt];% subdirectory for output files
2415    OutputDir=fullfile(RootPath,OutputSubDir);
2416    hfig=findobj(allchild(0),'name','series_status');
2417    if isempty(hfig)
2418        hfig=figure('DeleteFcn',@stop_status);
2419        set(hfig,'MenuBar','none')% suppress the menu bar
2420        set(hfig,'NumberTitle','off')%suppress the fig number in the title
2421        set(hfig,'name','series_status')
2422        set(hfig,'tag','series_status')
2423        uicontrol('Style','listbox','Units','normalized', 'Position',[0.05 0.09 0.9 0.71], 'Callback', @view_file,'tag','list','UserData',OutputDir);
2424        uicontrol('Style','edit','Units','normalized', 'Position', [0.05 0.87 0.9 0.1],'tag','titlebox','Max',2,'String',OutputDir);
2425        uicontrol('Style','frame','Units','normalized', 'Position', [0.05 0.81 0.9 0.05]);
2426        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);
2427        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);
2428        set(hrefresh,'UserData',StatusData)
2429        BarPosition=[0.05 0.81 0.01 0.05];
2430        uicontrol('Style','frame','Units','normalized', 'Position',BarPosition ,'BackgroundColor',[1 0 0],'tag','waitbar');
2431        drawnow
2432    end
2433    refresh_GUI(hrefresh,[])
2434else
2435    %% delete current display fig if selection is off
2436    set(handles.status,'BackgroundColor',[0 1 0])
2437    hfig=findobj(allchild(0),'name','series_status');
2438    if ~isempty(hfig)
2439        delete(hfig)
2440    end
2441    return
2442end
2443
2444
2445%------------------------------------------------------------------------   
2446% launched by selecting a file on the list
2447function view_file(hObject, eventdata)
2448list=get(hObject,'String');
2449index=get(hObject,'Value');
2450rootroot=get(hObject,'UserData');
2451selectname=list{index};
2452ind_dot=regexp(selectname,'\.\.\.');
2453if ~isempty(ind_dot)
2454    selectname=selectname(1:ind_dot-1);
2455end
2456FullSelectName=fullfile(rootroot,selectname);
2457if exist(FullSelectName,'dir')% a directory has been selected
2458    ListFiles=dir(FullSelectName);
2459    ListDisplay=cell(numel(ListFiles),1);
2460    for ilist=2:numel(ListDisplay)% suppress the first line '.'
2461        ListDisplay{ilist-1}=ListFiles(ilist).name;
2462    end
2463    set(hObject,'Value',1)
2464    set(hObject,'String',ListDisplay)
2465    if strcmp(selectname,'..')
2466        FullSelectName=fileparts(fileparts(FullSelectName));
2467    end
2468    set(hObject,'UserData',FullSelectName)
2469    hfig=get(hObject,'parent');
2470    htitlebox=findobj(hfig,'tag','titlebox');   
2471    set(htitlebox,'String',FullSelectName)
2472elseif exist(FullSelectName,'file')%visualise the vel field if it exists
2473    FileType=get_file_type(FullSelectName);
2474    if strcmp(FileType,'txt')
2475        edit(FullSelectName)
2476    elseif strcmp(FileType,'xml')
2477        editxml(FullSelectName)
2478    else
2479        uvmat(FullSelectName)
2480    end
2481    set(gcbo,'Value',1)
2482end
2483
2484
2485%------------------------------------------------------------------------
2486
2487%------------------------------------------------------------------------   
2488% launched by refreshing the status figure
2489function refresh_GUI(hObject, eventdata)
2490%------------------------------------------------------------------------
2491hfig=get(hObject,'parent');
2492htitlebox=findobj(hfig,'tag','titlebox');
2493hlist=findobj(hfig,'tag','list');
2494OutputDir=get(htitlebox,'String');
2495ListFiles=dir(OutputDir);
2496ListDisplay=cell(numel(ListFiles),1);
2497for ilist=2:numel(ListDisplay)
2498    ListDisplay{ilist-1}=ListFiles(ilist).name;
2499end
2500set(hlist,'String',ListDisplay)
2501% civ_files=get(hfig,'UserData');
2502
2503% [filepath,filename,ext]=fileparts(civ_files{1});
2504% [tild,SubDir,extdir]=fileparts(filepath);
2505% SubDir=[SubDir extdir];
2506% option_civ=StatusData.option_civ;
2507% nbfiles=numel(civ_files);
2508% testrecent=0;
2509% count=0;
2510% datnum=zeros(1,nbfiles);
2511% filefound=cell(1,nbfiles);
2512% for ifile=1:nbfiles
2513%     detect=exist(civ_files{ifile},'file'); % check the existence of the file
2514%     option=0;
2515%     if detect==0
2516%         option_str='not created';
2517%     else
2518%         datfile=dir(civ_files{ifile});
2519%         if isfield(datfile,'datenum')
2520%             datnum(ifile)=datfile.datenum;%only available in recent matlab versions
2521%             testrecent=1;
2522%         end
2523%         filefound(ifile)={datfile.name};
2524%         
2525%         % check the content  netcdf file
2526%         Data=nc2struct(civ_files{ifile},'ListGlobalAttribute','CivStage','patch2','fix2','civ2','patch','fix');
2527%         option_list={'civ1','fix1','patch1','civ2','fix2','patch2'};
2528%         if ~isempty(Data.CivStage)
2529%             option=Data.CivStage;%case of Matlab civ
2530%         else
2531%             if ~isempty(Data.patch2) && isequal(Data.patch2,1)
2532%                 option=6;
2533%             elseif ~isempty(Data.fix2) && isequal(Data.fix2,1)
2534%                 option=5;
2535%             elseif ~isempty(Data.civ2) && isequal(Data.civ2,1);
2536%                 option=4;
2537%             elseif ~isempty(Data.patch) && isequal(Data.patch,1);
2538%                 option=3;
2539%             elseif ~isempty(Data.fix) && isequal(Data.fix,1);
2540%                 option=2;
2541%             else
2542%                 option=1;
2543%             end
2544%         end
2545%         option_str=option_list{option};
2546%         if datnum(ifile)<StatusData.time_ref
2547%             option_str=[option_str '  --OLD--'];
2548%         end
2549%     end
2550%     if option >= option_civ
2551%         count=count+1;
2552%     end
2553%     [filepath,filename,ext]=fileparts(civ_files{ifile});
2554%     Tabchar{ifile,1}=[fullfile(SubDir,filename) ext  '...' option_str];
2555% end
2556% datnum=datnum(datnum~=0);%keep the non zero values corresponding to existing files
2557% if isempty(datnum)
2558%     if testrecent
2559%         message='no civ result created yet';
2560%     else
2561%         message='';
2562%     end
2563% else
2564%     datnum=datnum(datnum~=0);%keep the non zero values corresponding to existing files
2565%     [first,ind]=min(datnum);
2566%     [last,indlast]=max(datnum);
2567%     message={[num2str(count) ' file(s) done over ' num2str(nbfiles)] ;['oldest modification:  ' cell2mat(filefound(ind)) ' : ' datestr(first)];...
2568%         ['latest modification:  ' cell2mat(filefound(indlast)) ' : ' datestr(last)]};
2569% end
2570% hlist=findobj(hfig,'tag','list');
2571% htitlebox=findobj(hfig,'tag','titlebox');
2572% hwaitbar=findobj(hfig,'tag','waitbar');
2573% set(hlist,'String',Tabchar)
2574% set(htitlebox,'String', message)
2575% if count>0 %&& ~test_new
2576%     BarPosition(3)=0.9*count/nbfiles;
2577%     set(hwaitbar,'Position',BarPosition)
2578% end
2579%------------------------------------------------------------------------   
2580% launched by deleting the status figure
2581function stop_status(hObject, eventdata)
2582%------------------------------------------------------------------------
2583hciv=findobj(allchild(0),'tag','series');
2584hhciv=guidata(hciv);
2585set(hhciv.status,'value',0) %reset the status uicontrol in the GUI civ
2586set(hhciv.status,'BackgroundColor',[0 1 0])
2587delete(gcbf)
2588
2589% --- Executes on selection change in ActionExt.
2590function ActionExt_Callback(hObject, eventdata, handles)
2591ActionExtList=get(handles.ActionExt,'String');
2592ActionExt=ActionExtList{get(handles.ActionExt,'Value')};
2593ActionList=get(handles.ActionName,'String');
2594ActionName=ActionList{get(handles.ActionName,'Value')};
2595if strcmp(ActionExt,'.sh')
2596    ActionFullName=fullfile(get(handles.ActionPath,'String'),[ActionName '.sh']);
2597    if ~exist(ActionFullName,'file')
2598        answer=msgbox_uvmat('INPUT_Y-N','compiled version has not been created: compile now?');
2599        if strcmp(answer,'Yes')
2600            currentdir=pwd;
2601            cd(get(handles.ActionPath,'String'))
2602            compile(ActionName)
2603            cd(currentdir)
2604        end
2605    end
2606    currentdir=pwd;
2607    cd(get(handles.ActionPath,'String'))
2608    sh_file=dir([ActionName '.sh']);
2609    m_file=dir([ActionName '.m']);
2610    if isfield(m_file,'datenum') && m_file.datenum>sh_file.datenum
2611        set(handles.ActionExt,'BackgroundColor',[1 1 0])
2612        drawnow
2613        answer=msgbox_uvmat('INPUT_Y-N',[ActionName '.sh needs to be updated: recompile now?']);
2614        if strcmp(answer,'Yes')
2615            compile(ActionName)
2616        end
2617        set(handles.ActionExt,'BackgroundColor',[1 1 1])
2618    end
2619    cd(currentdir)
2620end
2621
2622
2623function ActionInput_Callback(hObject, eventdata, handles)
2624
2625
2626% --- Executes on button press in DeleteObject.
2627function DeleteObject_Callback(hObject, eventdata, handles)
2628if get(handles.DeleteObject,'Value')
2629        SeriesData=get(handles.series,'UserData');
2630    SeriesData.ProjObject=[];
2631    set(handles.series,'UserData',SeriesData)
2632    set(handles.ProjObject,'String','')
2633    set(handles.CheckObject,'Value',0)
2634    set(handles.DeleteObject,'Visible','off')
2635    set(handles.ViewObject,'Visible','off')
2636end
2637
2638% --- Executes on button press in ViewObject.
2639function ViewObject_Callback(hObject, eventdata, handles)
2640if get(handles.ViewObject,'Value')
2641        UserData=get(handles.series,'UserData');
2642    set_object(UserData.ProjObject)
2643else
2644    hset_object=findobj(allchild(0),'Tag','set_object');
2645    if ~isempty(hset_object)
2646        delete(hset_object)
2647    end
2648end
2649
2650
2651function num_NbProcess_Callback(hObject, eventdata, handles)
2652
2653
2654function num_NbSlice_Callback(hObject, eventdata, handles)
2655NbSlice=str2num(get(handles.num_NbSlice,'String'));
2656set(handles.num_NbProcess,'String',num2str(NbSlice))
2657
2658
Note: See TracBrowser for help on using the repository browser.