source: trunk/src/series.m @ 600

Last change on this file since 600 was 600, checked in by sommeria, 8 years ago

small bug corrected

File size: 107.0 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
1344RunModeList=get(handles.RunMode,'String');
1345RunMode=RunModeList{get(handles.RunMode,'Value')};
1346ActionExt='.m';%default
1347if isfield(Series.Action,'ActionExt')
1348    ActionExt=Series.Action.ActionExt;% '.m' or '.sh' (compiled)
1349end
1350ActionName=Series.Action.ActionName;
1351ActionPath=Series.Action.ActionPath;
1352path_series=fileparts(which('series'));
1353
1354%% create the Action fct handle if RunMode option = 'local'
1355if strcmp(RunMode,'local')
1356    if ~isequal(ActionPath,path_series)
1357        eval(['spath=which(''' ActionName ''');']) %spath = current path of the selected function ACTION
1358        if ~exist(ActionPath,'dir')
1359            msgbox_uvmat('ERROR',['The prescribed function path ' ActionPath ' does not exist']);
1360            return
1361        end
1362        if ~isequal(spath,ActionPath)
1363            addpath(ActionPath)% add the prescribed path if not the current one
1364        end
1365    end
1366    eval(['h_fun=@' ActionName ';'])%create a function handle for ACTION
1367    if ~isequal(ActionPath,path_series)
1368        rmpath(ActionPath)% add the prescribed path if not the current one
1369    end
1370end
1371
1372%% Get RunTime code from the file PARAM.xml (needed to run compiled functions)
1373errormsg='';%default error message
1374xmlfile=fullfile(path_series,'PARAM.xml');
1375test_batch=0;%default: ,no batch mode available
1376if ~exist(xmlfile,'file')
1377    [success,message]=copyfile(fullfile(path_series,'PARAM.xml.default'),xmlfile);
1378end
1379RunTime='';
1380if strcmp(ActionExt,'.sh')
1381    if exist(xmlfile,'file')
1382        s=xml2struct(xmlfile);
1383        if strcmp(RunMode,'cluster_oar') && isfield(s,'BatchParam')
1384            if isfield(s.BatchParam,'RunTime')
1385                RunTime=s.BatchParam.RunTime;
1386            end
1387            if isfield(s.BatchParam,'NbCore')
1388                NbCore=s.BatchParam.NbCore;
1389            end
1390        elseif (strcmp(RunMode,'background')||strcmp(RunMode,'local')) && isfield(s,'RunParam')
1391            if isfield(s.RunParam,'RunTime')
1392                RunTime=s.RunParam.RunTime;
1393            end
1394            if isfield(s.RunParam,'NbCore')
1395                NbCore=s.RunParam.NbCore;
1396            end
1397        end
1398    end
1399    if isempty(RunTime) && strcmp(RunMode,'cluster_oar')
1400        msgbox_uvmat('ERROR','RunTime name not found in PARAM.xml, compiled version .sh cannot run on cluster')
1401        return
1402    end
1403%     Series.RunTime=RunTime;
1404end
1405
1406%% set nbre of cluster cores and processes
1407switch RunMode
1408    case {'local','background'}
1409        NbCore=1;% no need to split the calculation
1410    case 'cluster_oar'
1411        if strcmp(Series.Action.ActionExt,'.m')% case of Matlab function (uncompiled)
1412            NbCore=1;% one core used only (limitation of Matlab licences)
1413            msgbox_uvmat('WARNING','Number of cores =1: select the compiled version civ_matlab.sh for multi-core processing');
1414            extra_oar='';
1415        else
1416            answer=inputdlg({'Number of cores (max 36)','extra oar options'},'oarsub parameter',1,{'12',''});
1417            NbCore=str2double(answer{1});
1418            extra_oar=answer{2};
1419        end
1420end
1421if ~isfield(Series.IndexRange,'NbSlice')
1422    Series.IndexRange.NbSlice=[];
1423end
1424if isempty(Series.IndexRange.NbSlice)
1425    NbProcess=NbCore;% choose one process per core
1426else
1427    NbProcess=Series.IndexRange.NbSlice;% the nbre of run processes is equal to the number of slices
1428    NbCore=min(NbCore,NbProcess);% at least one process per core
1429end
1430
1431%% read index ranges
1432first_i=1;
1433last_i=1;
1434incr_i=1;
1435first_j=1;
1436last_j=1;
1437if isfield(Series.IndexRange,'first_i')
1438    first_i=Series.IndexRange.first_i;
1439    incr_i=Series.IndexRange.incr_i;
1440    last_i=Series.IndexRange.last_i;
1441end
1442if isfield(Series.IndexRange,'first_j')
1443    first_j=Series.IndexRange.first_j;
1444    last_j=Series.IndexRange.last_j;
1445end
1446if last_i < first_i || last_j < first_j , msgbox_uvmat('ERROR','last field number must be larger than the first one'),...
1447        set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return
1448else
1449    BlockLength=ceil(numel(first_i:incr_i:last_i)/NbProcess);
1450end
1451
1452%% direct processing on the current Matlab session
1453if strcmp (RunMode,'local')
1454    Series.RUNHandle=handles.RUN;
1455    Series.WaitbarHandle=handles.Waitbar;
1456    for iprocess=1:NbProcess
1457        if isempty(Series.IndexRange.NbSlice)
1458            Series.IndexRange.first_i=first_i+(iprocess-1)*BlockLength;
1459            if Series.IndexRange.first_i>last_i
1460                break
1461            end
1462            Series.IndexRange.last_i=min(first_i+(iprocess)*BlockLength-1,last_i);
1463        else
1464            Series.IndexRange.first_i= first_i+iprocess-1;
1465            Series.IndexRange.incr_i=incr_i*Series.IndexRange.NbSlice;
1466        end
1467        t=struct2xml(Series);
1468        t=set(t,1,'name','Series');
1469        filexml=fullfile_uvmat(DirXml,'',Series.InputTable{1,3},'.xml',OutputNomType,...
1470            Series.IndexRange.first_i,Series.IndexRange.last_i,first_j,last_j);
1471        save(t,filexml);
1472        switch ActionExt
1473            case '.m'
1474                h_fun(Series);
1475            case '.sh'
1476                switch computer
1477                    case {'PCWIN','PCWIN64'} %Windows system
1478                        filexml=regexprep(filexml,'\\','\\\\');% add '\' so that '\' are left as characters
1479                        system([fullfile(ActionPath,[ActionName '.sh']) ' ' RunTime ' ' filexml]);% TODO: adapt to DOS system
1480                    case {'GLNX86','GLNXA64','MACI64'}%Linux  system
1481                        system([fullfile(ActionPath,[ActionName '.sh']) ' ' RunTime ' ' filexml]);
1482                end
1483        end
1484    end
1485elseif strcmp(get(handles.OutputDirExt,'Visible'),'off')
1486    msgbox_uvmat('ERROR',['no output file for Action ' ActionName ', use run mode = local']);% a output dir is needed for background option
1487    return
1488else
1489    %% processing on a different session of the same computer (background) or cluster, create executable files
1490    batch_file_list=cell(NbProcess,1);% initiate the list of executable files
1491    DirBat=fullfile(OutputDir,'0_BAT');
1492    %create subdirectory for executable files
1493    if ~exist(DirBat,'dir')
1494        [tild,msg1]=mkdir(DirBat);
1495        if ~strcmp(msg1,'')
1496            msgbox_uvmat('ERROR',['cannot create ' DirBat ': ' msg1]);%error message for directory creation
1497            return
1498        end
1499    end
1500    %create subdirectory for log files
1501    DirLog=fullfile(OutputDir,'0_LOG');
1502    if ~exist(DirLog,'dir')
1503        [tild,msg1]=mkdir(DirLog);
1504        if ~strcmp(msg1,'')
1505            msgbox_uvmat('ERROR',['cannot create ' DirLog ': ' msg1]);%error message for directory creation
1506            return
1507        end
1508    end
1509    for iprocess=1:NbProcess
1510        if isempty(Series.IndexRange.NbSlice)% process by blocks of i index
1511            Series.IndexRange.first_i=first_i+(iprocess-1)*BlockLength;
1512            if Series.IndexRange.first_i>last_i
1513                NbProcess=iprocess-1;
1514                break% leave the loop, we are at the end of the calculation
1515            end
1516            Series.IndexRange.last_i=min(last_i,first_i+(iprocess)*BlockLength-1);
1517        else% process by slices of i index if NbSlice is defined, computation in a single process if NbSlice =1
1518            Series.IndexRange.first_i= first_i+iprocess-1;
1519            Series.IndexRange.incr_i=incr_i*Series.IndexRange.NbSlice;
1520        end
1521       
1522        % create, fill and save the xml parameter file
1523        t=struct2xml(Series);
1524        t=set(t,1,'name','Series');
1525        filexml=fullfile_uvmat(DirXml,'',Series.InputTable{1,3},'.xml',OutputNomType,...
1526            Series.IndexRange.first_i,Series.IndexRange.last_i,first_j,last_j);
1527        save(t,filexml);% save the parameter file
1528       
1529        %create the executable file
1530%         filebat=fullfile_uvmat(DirBat,'',Series.InputTable{1,3},'.bat',OutputNomType,...
1531%             Series.IndexRange.first_i,Series.IndexRange.last_i,first_j,last_j);
1532         filebat=fullfile_uvmat(DirBat,'',Series.InputTable{1,3},'.sh',OutputNomType,...
1533           Series.IndexRange.first_i,Series.IndexRange.last_i,first_j,last_j);
1534        batch_file_list{iprocess}=filebat;
1535        [fid,message]=fopen(filebat,'w');% create the executable file
1536        if isequal(fid,-1)
1537            msgbox_uvmat('ERROR', ['creation of .bat file: ' message]);
1538            return
1539        end
1540       
1541        % set the log file name
1542        filelog=fullfile_uvmat(DirLog,'',Series.InputTable{1,3},'.log',OutputNomType,...
1543            Series.IndexRange.first_i,Series.IndexRange.last_i,first_j,last_j);
1544       
1545        % fill and save the executable file
1546        switch ActionExt
1547            case '.m'% Matlab function
1548                switch computer
1549                    case {'GLNX86','GLNXA64','MACI64'}
1550                        cmd=[...
1551                            '#!/bin/bash \n'...
1552                            '. /etc/sysprofile \n'...
1553                            'matlab -nodisplay -nosplash -nojvm -logfile ''' filelog ''' <<END_MATLAB \n'...
1554                            'addpath(''' path_series '''); \n'...
1555                            'addpath(''' Series.Action.ActionPath '''); \n'...
1556                            '' Series.Action.ActionName  '( ''' filexml '''); \n'...
1557                            'exit \n'...
1558                            'END_MATLAB \n'];
1559                        fprintf(fid,cmd);%fill the executable file with the  char string cmd
1560                        fclose(fid);% close the executable file
1561                        system(['chmod +x ' filebat]);% set the file to executable
1562                    case {'PCWIN','PCWIN64'}
1563                        text_matlabscript=['matlab -automation -logfile ' regexprep(filelog,'\\','\\\\')...
1564                            ' -r "addpath(''' regexprep(path_series,'\\','\\\\') ''');'...
1565                            'addpath(''' regexprep(Series.Action.ActionPath,'\\','\\\\') ''');'...
1566                            '' Series.Action.ActionName  '( ''' regexprep(filexml,'\\','\\\\') ''');exit"'];
1567                        fprintf(fid,text_matlabscript);%fill the executable file with the  char string cmd
1568                        fclose(fid);% close the executable file
1569                end
1570            case '.sh' % compiled Matlab function
1571                switch computer
1572                    case {'GLNX86','GLNXA64','MACI64'}
1573                        cmd=['#!/bin/bash \n '...
1574                            '#$ -cwd \n '...
1575                            'hostname && date \n '...
1576                            'umask 002 \n'...
1577                            fullfile(ActionPath,[ActionName '.sh']) ' ' RunTime ' ' filexml];%allow writting access to created files for user group
1578                        fprintf(fid,cmd);%fill the executable file with the  char string cmd
1579                        fclose(fid);% close the executable file
1580                        system(['chmod +x ' filebat]);% set the file to executable
1581                       
1582                    case {'PCWIN','PCWIN64'}    %       TODO: adapt to Windows system
1583                        %                                 cmd=['matlab -automation -logfile ' regexprep(filelog,'\\','\\\\')...
1584                        %                                     ' -r "addpath(''' regexprep(path_series,'\\','\\\\') ''');'...
1585                        %                                     'addpath(''' regexprep(Series.Action.ActionPath,'\\','\\\\') ''');'...
1586                        %                                     '' Series.Action.ActionName  '( ''' regexprep(filexml,'\\','\\\\') ''');exit"'];
1587                        fprintf(fid,cmd);
1588                        fclose(fid);
1589                        %                               dos([filebat ' &']);
1590                end
1591        end
1592    end
1593end
1594
1595%% launch the executable files for background or cluster processing
1596switch RunMode
1597    case 'background'
1598        for iprocess=1:NbProcess
1599            system(batch_file_list{iprocess})% directly execute the command file for each process
1600        end
1601    case 'cluster_oar' % option 'oar-parexec' used
1602        %create subdirectory for oar command and log files
1603        DirOAR=fullfile(OutputDir,'0_OAR');
1604        if ~exist(DirOAR,'dir')
1605            [tild,msg1]=mkdir(DirOAR);
1606            if ~strcmp(msg1,'')
1607                msgbox_uvmat('ERROR',['cannot create ' DirOAR ': ' msg1]);%error message for directory creation
1608                return
1609            end
1610        end
1611        max_walltime=3600*12; % 12h max
1612        walltime_onejob=600;%seconds
1613        filename_joblist=fullfile(DirOAR,'job_list.txt');%create name of the global executable file
1614        fid=fopen(filename_joblist,'w');
1615        for p=1:length(batch_file_list)
1616            fprintf(fid,[batch_file_list{p} '\n']);% list of exe files
1617        end
1618        fclose(fid);
1619        system(['chmod +x ' filename_joblist]);% set the file to executable
1620        oar_command=['oarsub -n CIVX '...
1621            '-t idempotent --checkpoint ' num2str(walltime_onejob+60) ' '...
1622            '-l /core=' num2str(NbCore) ','...
1623            'walltime=' datestr(min(1.05*walltime_onejob/86400*max(length(batch_file_list),NbCore)/NbCore,max_walltime/86400),13) ' '...
1624            '-E ' regexprep(filename_joblist,'\.txt\>','.stderr') ' '...
1625            '-O ' regexprep(filename_joblist,'\.txt\>','.stdout') ' '...
1626            extra_oar ' '...
1627            '"oar-parexec -s -f ' filename_joblist ' '...
1628            '-l ' filename_joblist '.log"\n'];
1629        filename_oarcommand=fullfile(DirOAR,'oar_command');
1630        fid=fopen(filename_oarcommand,'w');
1631        fprintf(fid,oar_command);
1632        fclose(fid);
1633        fprintf(oar_command);% display in command line
1634        %system(['chmod +x ' oar_command]);% set the file to executable
1635        system(oar_command);     
1636end
1637
1638%% reset the GUI series
1639update_waitbar(handles.Waitbar,1); % put the waitbar to end position to indicate launching is finished
1640set(handles.RUN, 'Enable','On')
1641set(handles.RUN,'BackgroundColor',[1 0 0])
1642set(handles.RUN, 'Value',0)
1643
1644%------------------------------------------------------------------------
1645function STOP_Callback(hObject, eventdata, handles)
1646%------------------------------------------------------------------------
1647set(handles.RUN, 'BusyAction','cancel')
1648set(handles.RUN,'BackgroundColor',[1 0 0])
1649set(handles.RUN,'enable','on')
1650set(handles.RUN, 'Value',0)
1651
1652% %------------------------------------------------------------------------
1653% % --- Executes on button press in BIN.
1654% function BIN_Callback(hObject, eventdata, handles)
1655% %------------------------------------------------------------------------
1656%     cmd=['#!/bin/bash \n '...
1657%         '#$ -cwd \n '...
1658%         'hostname && date \n '...
1659%         'umask 002 \n'...
1660%         Param.xml.CivmBin ' ' Param.xml.RunTime ' ' filename_xml ' ' OutputFile '.nc'];
1661%     
1662%------------------------------------------------------------------------
1663% --- Main launch command, called by RUN and BATCH
1664
1665function [Series,OutputDir,errormsg]=prepare_jobs(handles)
1666%INPUT:
1667% handles: handles of graphic objects on the GUI series
1668
1669%------------------------------------------------------------------------
1670OutputDir='';
1671errormsg='';
1672
1673%% Read parameters from series
1674Series=read_GUI(handles.series);
1675
1676%% get_field GUI
1677% if isfield(Series,'InputFields')&&isfield(Series.InputFields,'Field')
1678%     if strcmp(Series.InputFields.Field,'get_field...')
1679%         hget_field=findobj(allchild(0),'name','get_field');
1680%         Series.GetField=read_GUI(hget_field);
1681%     end
1682% end
1683
1684%% create the output data directory
1685%determine the root file corresponding to the first sub dir
1686if get(handles.RUN,'value') && isfield(Series,'OutputSubDir')
1687    SubDirOut=[get(handles.OutputSubDir,'String') Series.OutputDirExt];
1688    SubDirOutNew=SubDirOut;
1689    SeriesData=get(handles.series,'UserData');
1690    if size(Series.InputTable,1)>1 && isfield(SeriesData,'AllowInputSort') && SeriesData.AllowInputSort
1691        [tild,iview]=sort(Series.InputTable(:,2)); %subdirectories sorted in alphabetical order
1692        Series.InputTable=Series.InputTable(iview,:);
1693    end
1694    detect=exist(fullfile(Series.InputTable{1,1},SubDirOutNew),'dir');% test if  the dir  already exist
1695    check_create=1; %need to create the result directory by default
1696    while detect
1697        answer=msgbox_uvmat('INPUT_Y-N',['use existing ouput directory: ' fullfile(Series.InputTable{1,1},SubDirOutNew) ', possibly delete previous data']);
1698        if strcmp(answer,'Cancel')
1699            errormsg='Cancel';
1700            return
1701        elseif strcmp(answer,'Yes')
1702            detect=0;
1703            check_create=0;
1704        else
1705            r=regexp(SubDirOutNew,'(?<root>.*\D)(?<num1>\d+)$','names');%detect whether name ends by a number
1706            if isempty(r)
1707                r(1).root=[SubDirOutNew '_'];
1708                r(1).num1='0';
1709            end
1710            SubDirOutNew=[r(1).root num2str(str2num(r(1).num1)+1)];%increment the index by 1 or put 1
1711            detect=exist(fullfile(Series.InputTable{1,1},SubDirOutNew),'dir');% test if  the dir  already exists   
1712            check_create=1;
1713        end
1714    end
1715    Series.OutputDirExt=regexprep(SubDirOutNew,Series.OutputSubDir,'');
1716    Series.OutputRootFile=Series.InputTable{1,3};% the first sorted RootFile taken for output
1717    set(handles.OutputDirExt,'String',Series.OutputDirExt)
1718    OutputDir=fullfile(Series.InputTable{1,1},[Series.OutputSubDir Series.OutputDirExt]);% full name (with path) of output directory
1719    if check_create    % create output directory if it does not exist
1720        [tild,msg1]=mkdir(OutputDir);
1721        if ~strcmp(msg1,'')
1722            errormsg=['cannot create ' OutputDir ': ' msg1];%error message for directory creation
1723            return
1724        end
1725    end
1726   % RootOut=fullfile(OutputDir,Series.InputTable{1,3});% name of the parameter xml file set in this directory
1727end
1728
1729%% removes unused information on Series
1730if isfield(Series,'Pairs')
1731    Series=rmfield(Series,'Pairs'); %info Pairs not needed for output
1732end
1733Series.IndexRange=rmfield(Series.IndexRange,'TimeTable');
1734% Series.IndexRange=rmfield(Series.IndexRange,'MinIndex');
1735% Series.IndexRange=rmfield(Series.IndexRange,'MaxIndex');
1736empty_line=false(size(Series.InputTable,1),1);
1737for iline=1:size(Series.InputTable,1)
1738    empty_line(iline)=isequal(Series.InputTable(iline,1:3),{'','',''});
1739end
1740Series.InputTable(empty_line,:)=[];
1741
1742%------------------------------------------------------------------------
1743% --- Executes on selection change in ActionName.
1744function ActionName_Callback(hObject, eventdata, handles)
1745%------------------------------------------------------------------------
1746%% stop any ongoing series processing
1747if isequal(get(handles.RUN,'Value'),1)
1748    answer= msgbox_uvmat('INPUT_Y-N','stop current Action process?');
1749    if strcmp(answer,'Yes')
1750        STOP_Callback(hObject, eventdata, handles)
1751    else
1752        return
1753    end
1754end
1755set(handles.ActionName,'BackgroundColor',[1 1 0])
1756drawnow
1757
1758%% get Action name and path
1759nb_builtin_ACTION=4; %nbre of functions initially proposed in the menu ActionName (as defined in the Opening fct of series)
1760ActionList=get(handles.ActionName,'String');% list menu fields
1761ActionIndex=get(handles.ActionName,'Value');
1762if ~isequal(ActionIndex,1)
1763    InputTable=get(handles.InputTable,'Data');
1764    if isempty(InputTable{1,4})
1765        msgbox_uvmat('ERROR','no input file available: use Open in the menu bar')
1766        return
1767    end
1768end
1769ActionName= ActionList{get(handles.ActionName,'Value')}; % selected function name
1770ActionPathList=get(handles.ActionName,'UserData');%list of recorded paths to functions of the list ActionName
1771
1772%% add a new function to the menu if 'more...' has been selected in the menu ActionName
1773if isequal(ActionName,'more...')
1774    [FileName, PathName] = uigetfile( ...
1775        {'*.m', ' (*.m)';
1776        '*.m',  '.m files '; ...
1777        '*.*', 'All Files (*.*)'}, ...
1778        'Pick a series processing function ',get(handles.ActionPath,'String'));
1779    if length(FileName)<2
1780        return
1781    end
1782    [ActionPath,ActionName,ActionExt]=fileparts(FileName);
1783   
1784    % insert the choice in the menu ActionName
1785    ActionIndex=find(strcmp(ActionName,ActionList),1);% look for the selected function in the menu Action
1786    if isempty(ActionIndex)%the input string does not exist in the menu
1787        ActionIndex= length(ActionList);
1788        ActionList=[ActionList(1:end-1);{ActionName};ActionList(end)];% the selected function is appended in the menu, before the last item 'more...'
1789        set(handles.ActionName,'String',ActionList)
1790    end
1791   
1792    % record the file extension and extend the path list if it is a new extension
1793    ActionExtList=get(handles.ActionExt,'String');
1794    ActionExtIndex=find(strcmp(ActionExt,ActionExtList), 1);
1795    if isempty(ActionExtIndex)
1796        set(handles.ActionExt,'String',[ActionExtList;{ActionExt}])
1797        ActionExtIndex=numel(ActionExtList)+1;
1798        ActionPathNew=cell(size(ActionPathList,1),1);%new column of ActionPath
1799        ActionPathList=[ActionPathList ActionPathNew];
1800    end
1801    set(handles.ActionName,'UserData',ActionPathList);
1802
1803    % remove old Action options in the menu (keeping a menu length <nb_builtin_ACTION+5)
1804    if length(ActionList)>nb_builtin_ACTION+5; %nb_builtin=nbre of functions always remaining in the initial menu
1805        nbremove=length(ActionList)-nb_builtin_ACTION-5;
1806        ActionList(nb_builtin_ACTION+1:end-5)=[];
1807        ActionPathList(nb_builtin_ACTION+1:end-4,:)=[];
1808        ActionIndex=ActionIndex-nbremove;
1809    end
1810   
1811    % record action menu, choice and path
1812    set(handles.ActionName,'Value',ActionIndex)
1813    set(handles.ActionName,'String',ActionList)
1814    set(handles.ActionExt,'Value',ActionExtIndex)
1815    ActionPathList{ActionIndex,ActionExtIndex}=PathName;
1816       
1817    %record the user defined menu additions in personal file profil_perso
1818    dir_perso=prefdir;
1819    profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
1820    if nb_builtin_ACTION+1<=numel(ActionList)-1
1821        ActionListUser=ActionList(nb_builtin_ACTION+1:numel(ActionList)-1);
1822        ActionPathListUser=ActionPathList(nb_builtin_ACTION+1:numel(ActionList)-1,:);
1823        ActionExtListUser={};
1824        if numel(ActionExtList)>2
1825            ActionExtListUser=ActionExtList(3:end);
1826        end
1827        if exist(profil_perso,'file')
1828            save(profil_perso,'ActionListUser','ActionPathListUser','ActionExtListUser','-append')
1829        else
1830            save(profil_perso,'ActionListUser','ActionPathListUser','ActionExtListUser','-V6')
1831        end
1832    end
1833end
1834
1835%% check the current ActionPath to the selected function
1836ActionPath=ActionPathList{ActionIndex};%current recorded path
1837set(handles.ActionPath,'String',ActionPath); %show the path to the senlected function
1838
1839%% reinitialise the waitbar
1840update_waitbar(handles.Waitbar,0)
1841
1842%% default setting for the visibility of the GUI elements
1843% set(handles.FieldTransform,'Visible','off')
1844% set(handles.CheckObject,'Visible','off');
1845% set(handles.ProjObject,'Visible','off');
1846% set(handles.CheckMask,'Visible','off')
1847% set(handles.Mask,'Visible','off')
1848
1849%% create the function handle for Action
1850path_series=which('series');
1851if ~isequal(ActionPath,path_series)
1852    eval(['spath=which(''' ActionName ''');']) %spath = current path of the selected function ACTION
1853    if ~exist(ActionPath,'dir')
1854        errormsg=['The prescribed function path ' ActionPath ' does not exist'];
1855        return
1856    end
1857    if ~isequal(spath,ActionPath)
1858        addpath(ActionPath)% add the prescribed path if not the current one
1859    end
1860end
1861eval(['h_fun=@' ActionName ';'])%create a function handle for ACTION
1862if ~isequal(ActionPath,path_series)
1863        rmpath(ActionPath)% add the prescribed path if not the current one   
1864end
1865
1866%% Activate the Action fct
1867[Series,tild,errormsg]=prepare_jobs(handles);% read the parameters from the GUI series
1868if ~isempty(errormsg)
1869    if ~strcmp(errormsg,'Cancel')
1870    msgbox_uvmat('ERROR',errormsg)
1871    end
1872    return
1873end
1874ParamOut=h_fun(Series);
1875
1876%% Put the first line of the selected Action fct as tooltip help
1877try
1878    [fid,errormsg] =fopen([ActionName '.m']);
1879    InputText=textscan(fid,'%s',1,'delimiter','\n');
1880    fclose(fid);
1881    set(handles.ActionName,'ToolTipString',InputText{1}{1})% put the first line of the selected function as tooltip help
1882end
1883
1884%% Detect the types of input files
1885SeriesData=get(handles.series,'UserData');
1886nb_civ=0;nb_netcdf=0;
1887if ~isempty(SeriesData)
1888    nb_civ=numel(find(strcmp('civx',SeriesData.FileType)|strcmp('civdata',SeriesData.FileType)));
1889    nb_netcdf=numel(find(strcmp('netcdf',SeriesData.FileType)));
1890end
1891
1892%% Check whether alphabetical sorting of input Subdir is alowed by the Action fct  (for multiples series entries)
1893SeriesData.AllowInputSort=0;%default
1894if isfield(ParamOut,'AllowInputSort')&&isequal(ParamOut.AllowInputSort,'on')
1895    SeriesData.AllowInputSort=1;
1896end
1897
1898%% Impose the whole input file index range if requested
1899if isfield(ParamOut,'WholeIndexRange')&&isequal(ParamOut.WholeIndexRange,'on')
1900    MinIndex=get(handles.MinIndex,'Data');
1901    MaxIndex=get(handles.MaxIndex,'Data');
1902    if ~isempty(MinIndex)
1903        set(handles.num_first_i,'String',num2str(MinIndex{1}))
1904        set(handles.num_last_i,'String',num2str(MaxIndex{1}))
1905        set(handles.num_incr_i,'String','1')
1906        if size(MinIndex,2)>=2
1907            set(handles.num_first_j,'String',num2str(MinIndex{1,2}))
1908            set(handles.num_last_j,'String',num2str(MaxIndex{1,2}))
1909            set(handles.num_incr_j,'String','1')
1910        end
1911    end
1912else
1913% check index ranges
1914first_i=1;last_i=1;first_j=1;last_j=1;
1915if isfield(Series.IndexRange,'first_i')
1916    first_i=Series.IndexRange.first_i;
1917    last_i=Series.IndexRange.last_i;
1918end
1919if isfield(Series.IndexRange,'first_j')
1920    first_j=Series.IndexRange.first_j;
1921    last_j=Series.IndexRange.last_j;
1922end
1923if last_i < first_i || last_j < first_j , msgbox_uvmat('ERROR','last field number must be larger than the first one'),...
1924    set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
1925end
1926
1927%% NbSlice visibility
1928NbSliceVisible='off';%default
1929if isfield(ParamOut,'NbSlice') && isequal(ParamOut.NbSlice,'on')
1930    NbSliceVisible='on';
1931    set(handles.num_NbProcess,'String',get(handles.num_NbSlice,'String'))% the nbre of processes is imposed as the nbre of slices
1932else
1933    set(handles.num_NbProcess,'String','')% free nbre of processes
1934end
1935set(handles.num_NbSlice,'Visible',NbSliceVisible)
1936set(handles.NbSlice_title,'Visible',NbSliceVisible)
1937
1938%% Visibility of VelType and VelType_1 menus
1939VelTypeVisible='off';  %hidden by default
1940VelType_1Visible='off';
1941InputFieldsVisible='off';%visibility of the frame Fields
1942if isfield(ParamOut,'VelType')
1943    if strcmp( ParamOut.VelType,'one')||strcmp( ParamOut.VelType,'two')
1944        if nb_civ>=1
1945            VelTypeVisible='on';
1946            InputFieldsVisible='on';
1947        end
1948    end
1949    if strcmp( ParamOut.VelType,'two')
1950        if nb_civ>=2
1951            VelType_1Visible='on';
1952        end
1953    end
1954end
1955set(handles.VelType,'Visible',VelTypeVisible)
1956set(handles.VelType_text,'Visible',VelTypeVisible);
1957set(handles.VelType_1,'Visible',VelType_1Visible)
1958set(handles.VelType_text_1,'Visible',VelType_1Visible);
1959
1960%% Visibility of FieldName and FieldName_1 menus
1961FieldNameVisible='off';  %hidden by default
1962FieldName_1Visible='off';  %hidden by default
1963if isfield(ParamOut,'FieldName')
1964    if strcmp( ParamOut.FieldName,'one')||strcmp( ParamOut.FieldName,'two')
1965        if (nb_civ+nb_netcdf)>=1
1966            InputFieldsVisible='on';
1967            FieldNameVisible='on';
1968        end
1969    end
1970    if strcmp( ParamOut.FieldName,'two')
1971        if (nb_civ+nb_netcdf)>=1
1972            FieldName_1Visible='on';
1973        end
1974    end
1975end
1976set(handles.InputFields,'Visible',InputFieldsVisible)
1977set(handles.FieldName,'Visible',FieldNameVisible) % test for MenuBorser
1978set(handles.FieldName_1,'Visible',FieldName_1Visible)
1979
1980%% Visibility of FieldTransform menu
1981FieldTransformVisible='off';  %hidden by default
1982if isfield(ParamOut,'FieldTransform')
1983    FieldTransformVisible=ParamOut.FieldTransform; 
1984    TransformName_Callback([],[], handles)
1985end
1986set(handles.FieldTransform,'Visible',FieldTransformVisible)
1987
1988%% Visibility of projection object
1989ProjObjectVisible='off';  %hidden by default
1990if isfield(ParamOut,'ProjObject')
1991    ProjObjectVisible=ParamOut.ProjObject;
1992end
1993set(handles.CheckObject,'Visible',ProjObjectVisible)
1994if ~get(handles.CheckObject,'Value')
1995    ProjObjectVisible='off';
1996end
1997set(handles.ProjObject,'Visible',ProjObjectVisible)
1998set(handles.DeleteObject,'Visible',ProjObjectVisible)
1999set(handles.ViewObject,'Visible',ProjObjectVisible)
2000
2001
2002%% Visibility of mask input
2003MaskVisible='off';  %hidden by default
2004if isfield(ParamOut,'Mask')
2005    MaskVisible=ParamOut.Mask;
2006end
2007set(handles.Mask,'Visible',MaskVisible)
2008set(handles.CheckMask,'Visible',MaskVisible);
2009
2010%% definition of the directory containing the output files
2011OutputDirVisible='off';
2012if isfield(ParamOut,'OutputDirExt')&&~isempty(ParamOut.OutputDirExt)
2013    set(handles.OutputDirExt,'String',ParamOut.OutputDirExt)
2014    OutputDirVisible='on';
2015end
2016set(handles.OutputDirExt,'Visible',OutputDirVisible)
2017set(handles.OutputSubDir,'Visible',OutputDirVisible)
2018set(handles.OutputDir_title,'Visible',OutputDirVisible)
2019set(handles.RunMode,'Visible',OutputDirVisible)
2020set(handles.ActionExt,'Visible',OutputDirVisible)
2021set(handles.RunMode_title,'Visible',OutputDirVisible)
2022set(handles.ActionExt_title,'Visible',OutputDirVisible)
2023
2024%% definition of an additional parameter set, determined by an ancillary GUI
2025if isfield(ParamOut,'ActionInput')
2026    set(handles.ActionInput,'Visible','on')
2027    set(handles.ActionInput_title,'Visible','on')
2028    set(handles.ActionInputView,'Visible','on')
2029    set(handles.ActionInputView,'Value',0)
2030    set(handles.ActionInput,'String',ActionName)
2031    ParamOut.ActionInput.Program=ActionName; % record the program in ActionInput
2032    SeriesData.ActionInput=ParamOut.ActionInput;
2033else
2034    set(handles.ActionInput,'Visible','off')
2035    set(handles.ActionInput_title,'Visible','off')
2036    set(handles.ActionInputView,'Visible','off')
2037    if isfield(SeriesData,'ActionInput')
2038    SeriesData=rmfield(SeriesData,'ActionInput');
2039    end
2040end   
2041set(handles.series,'UserData',SeriesData)
2042set(handles.ActionName,'BackgroundColor',[1 1 1])
2043
2044%------------------------------------------------------------------------
2045% --- Executes on button press in ActionInputView.
2046function ActionInputView_Callback(hObject, eventdata, handles)
2047%------------------------------------------------------------------------
2048if get(handles.ActionInputView,'Value')
2049ActionName_Callback(hObject, eventdata, handles)
2050end
2051
2052%------------------------------------------------------------------------
2053% --- Executes on selection change in FieldName.
2054function FieldName_Callback(hObject, eventdata, handles)
2055%------------------------------------------------------------------------
2056field_str=get(handles.FieldName,'String');
2057field_index=get(handles.FieldName,'Value');
2058field=field_str{field_index(1)};
2059if isequal(field,'get_field...')
2060    hget_field=findobj(allchild(0),'name','get_field');
2061    if ~isempty(hget_field)
2062        delete(hget_field)%delete opened versions of get_field
2063    end
2064    Series=read_GUI(handles.series);
2065    Series.InputTable=Series.InputTable(1,:);
2066    filecell=get_file_series(Series);
2067    if exist(filecell{1,1},'file')
2068        GetFieldData=get_field(filecell{1,1});
2069        FieldList={};
2070        XName=GetFieldData.XVarName;
2071        if GetFieldData.CheckVector
2072            UName=GetFieldData.PanelVectors.vector_x;
2073            VName=GetFieldData.PanelVectors.vector_y;
2074            XName=GetFieldData.XVarName;
2075            YName=GetFieldData.YVarName;
2076            CName=GetFieldData.PanelVectors.vec_color;
2077            [FieldList,VecColorList]=set_field_list(UName,VName,CName);
2078        elseif GetFieldData.CheckScalar
2079            AName=GetFieldData.PanelScalar.scalar;
2080            XName=GetFieldData.XVarName;
2081            YName=GetFieldData.YVarName;
2082            FieldList={AName};
2083        elseif GetFieldData.CheckPlot1D;
2084            YName=GetFieldData.CheckPlot1D.ordinate;
2085        end
2086        set(handles.Coord_x,'String',{XName})
2087        set(handles.Coord_y,'String',{YName})
2088        set(handles.FieldName,'Value',1)
2089        set(handles.FieldName,'String',[FieldList; {'get_field...'}]);
2090        %         set(handles.ColorScalar,'Value',1)
2091        %         set(handles.ColorScalar,'String',VecColorList);
2092        %         UvData.FileType{1}='netcdf';
2093        %         set(handles.uvmat,'UserData',UvData)
2094    end
2095    % elseif isequal(field,'more...')
2096    %     str=calc_field;
2097    %     [ind_answer,v] = listdlg('PromptString','Select a file:',...
2098    %                 'SelectionMode','single',...
2099    %                 'ListString',str);
2100    %        % edit the choice in the fields and actionname menu
2101    %      scalar=cell2mat(str(ind_answer));
2102    %      update_menu(handles.FieldName,scalar)
2103end
2104
2105%------------------------------------------------------------------------
2106% --- Executes on selection change in FieldName_1.
2107function FieldName_1_Callback(hObject, eventdata, handles)
2108%------------------------------------------------------------------------
2109field_str=get(handles.FieldName_1,'String');
2110field_index=get(handles.FieldName_1,'Value');
2111field=field_str{field_index};
2112if isequal(field,'get_field...')   
2113     hget_field=findobj(allchild(0),'name','get_field_1');
2114     if ~isempty(hget_field)
2115         delete(hget_field)
2116     end
2117     SeriesData=get(handles.series,'UserData');
2118     filename=SeriesData.CurrentInputFile_1;
2119     if exist(filename,'file')
2120        hget_field=get_field(filename);
2121        set(hget_field,'name','get_field_1')
2122     end
2123% elseif isequal(field,'more...')
2124%     str=calc_field;
2125%     [ind_answer,v] = listdlg('PromptString','Select a file:',...
2126%                 'SelectionMode','single',...
2127%                 'ListString',str);
2128%        % edit the choice in the fields and actionname menu
2129%      scalar=cell2mat(str(ind_answer));
2130%      update_menu(handles.FieldName_1,scalar)
2131end   
2132
2133
2134%%%%%%%%%%%%%
2135function [ind_remove]=find_pairs(dirpair,ind_i,last_i)
2136indsel=ind_i;
2137indiff=diff(ind_i); %test index increment to detect multiplets (several pairs with the same index ind_i) and holes in the series
2138indiff=[1 indiff last_i-ind_i(end)+1];%for testing gaps with the imposed bounds
2139if ~isempty(indiff)
2140    indiff2=diff(indiff);
2141    indiffp=[indiff2 1];
2142    indiffm=[1 indiff2];
2143    ind_multi_m=find((indiff==0)&(indiffm<0))-1;%indices of first members of multiplets
2144    ind_multi_p=find((indiff==0)&(indiffp>0));%indices of last members of multiplets
2145    %for each multiplet, select the most recent file
2146    ind_remove=[];
2147    for i=1:length(ind_multi_m)
2148        ind_pairs=ind_multi_m(i):ind_multi_p(i);
2149        for imulti=1:length(ind_pairs)
2150            datepair(imulti)=datenum(dirpair(ind_pairs(imulti)).date);%dates of creation
2151        end
2152        [datenew,indsort2]=sort(datepair); %sort the multiplet by creation date
2153        ind_s=indsort2(1:end-1);%
2154        ind_remove=[ind_remove ind_pairs(ind_s)];%remove these indices, leave the last one
2155    end
2156end
2157
2158%------------------------------------------------------------------------
2159% --- determine the list of index pairstring of processing file
2160function [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)
2161%------------------------------------------------------------------------
2162num_i1=num_i;% set of first image numbers by default
2163num_i2=num_i;
2164num_j1=num_j;
2165num_j2=num_j;
2166num_i_out=num_i;
2167num_j_out=num_j;
2168% if isequal (NomType,'_1-2_1') || isequal (NomType,'_1-2')
2169if isequal(mode,'series(Di)')
2170    num_i1_line=num_i+ind_shift(3);% set of first image numbers
2171    num_i2_line=num_i+ind_shift(4);
2172    % adjust the first and last field number
2173        indsel=find(num_i1_line >= 1);
2174    num_i_out=num_i(indsel);
2175    num_i1_line=num_i1_line(indsel);
2176    num_i2_line=num_i2_line(indsel);
2177    num_j1=meshgrid(num_j,ones(size(num_i1_line)));
2178    num_j2=meshgrid(num_j,ones(size(num_i1_line)));
2179    [xx,num_i1]=meshgrid(num_j,num_i1_line);
2180    [xx,num_i2]=meshgrid(num_j,num_i2_line);
2181elseif isequal (mode,'series(Dj)')||isequal (mode,'bursts')
2182    if isequal(mode,'bursts') %case of bursts (png_old or png_2D)
2183        num_j1=ind_shift(1)*ones(size(num_i));
2184        num_j2=ind_shift(2)*ones(size(num_i));
2185    else
2186        num_j1_col=num_j+ind_shift(1);% set of first image numbers
2187        num_j2_col=num_j+ind_shift(2);
2188        % adjust the first field number
2189        indsel=find((num_j1_col >= 1));   
2190        num_j_out=num_j(indsel);
2191        num_j1_col=num_j1_col(indsel);
2192        num_j2_col=num_j2_col(indsel);
2193        [num_i1,num_j1]=meshgrid(num_i,num_j1_col);
2194        [num_i2,num_j2]=meshgrid(num_i,num_j2_col);
2195    end   
2196end
2197
2198%------------------------------------------------------------------------
2199% --- Executes on button press in CheckObject.
2200function CheckObject_Callback(hObject, eventdata, handles)
2201%------------------------------------------------------------------------
2202value=get(handles.CheckObject,'Value');
2203if value
2204%      set(handles.CheckObject,'BackgroundColor',[1 1 0])%put unactivated buttons to yellow
2205     hset_object=findobj(allchild(0),'tag','set_object');%find the set_object interface handle
2206     if ishandle(hset_object)
2207         uistack(hset_object,'top')% show the GUI set_object if opened
2208     else
2209         %get the object file
2210         InputTable=get(handles.InputTable,'Data');
2211         defaultname=InputTable{1,1};
2212         if isempty(defaultname)
2213            defaultname={''};
2214         end
2215        [FileName, PathName] = uigetfile( ...
2216       {'*.xml;*.mat', ' (*.xml,*.mat)';
2217       '*.xml',  '.xml files '; ...
2218        '*.mat',  '.mat matlab files '}, ...
2219        'Pick an xml object file (or use uvmat to create it)',defaultname);
2220        fileinput=[PathName FileName];%complete file name
2221        sizf=size(fileinput);
2222        if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end
2223        %read the file
2224        data=xml2struct(fileinput);
2225        if ~isfield(data,'Type')
2226             msgbox_uvmat('ERROR',[fileinput ' is not an object xml file'])
2227             return
2228        end
2229        if ~isfield(data,'ProjMode')
2230             data.ProjMode='none';
2231        end
2232        hset_object=set_object(data);% call the set_object interface
2233     end
2234     ProjObject=read_GUI(hset_object);
2235     set(handles.ProjObject,'String',ProjObject.Name);%display the object name
2236     SeriesData=get(handles.series,'UserData');
2237     SeriesData.ProjObject=ProjObject;
2238     set(handles.series,'UserData',SeriesData);
2239     set(handles.DeleteObject,'Visible','on');
2240     set(handles.ViewObject,'Visible','on');
2241     set(handles.ProjObject,'Visible','on');
2242else
2243         set(handles.DeleteObject,'Visible','off');
2244     set(handles.ViewObject,'Visible','off');
2245     set(handles.ProjObject,'Visible','off');
2246%     set(handles.CheckObject,'BackgroundColor',[0.7 0.7 0.7])%put activated buttons to green
2247end
2248%set(handles.series,'UserData',SeriesData)
2249
2250%--------------------------------------------------------------
2251function CheckMask_Callback(hObject, eventdata, handles)
2252value=get(handles.CheckMask,'Value');
2253if value
2254    msgbox_uvmat('ERROR','not implemented yet')
2255end
2256%--------------------------------------------------------------
2257
2258%-------------------------------------------------------------------
2259%'uv_ncbrowser': interactively calls the netcdf file browser 'get_field.m'
2260function ncbrowser_uvmat(hObject, eventdata)
2261%-------------------------------------------------------------------
2262     bla=get(gcbo,'String');
2263     ind=get(gcbo,'Value');
2264     filename=cell2mat(bla(ind));
2265      blank=find(filename==' ');
2266      filename=filename(1:blank-1);
2267     get_field(filename)
2268
2269% ------------------------------------------------------------------
2270function MenuHelp_Callback(hObject, eventdata, handles)
2271%-------------------------------------------------------------------
2272path_to_uvmat=which ('uvmat');% check the path of uvmat
2273pathelp=fileparts(path_to_uvmat);
2274helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html');
2275if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package')
2276else
2277    addpath (fullfile(pathelp,'uvmat_doc'))
2278    web([helpfile '#series'])
2279end
2280
2281%-------------------------------------------------------------------
2282% --- Executes on selection change in TransformName.
2283function TransformName_Callback(hObject, eventdata, handles)
2284%----------------------------------------------------------------------
2285TransformList=get(handles.TransformName,'String');
2286TransformIndex=get(handles.TransformName,'Value');
2287TransformName=TransformList{TransformIndex};
2288TransformPathList=get(handles.TransformName,'UserData');
2289nb_builtin_transform=4;
2290% ff=functions(list_transform{end});
2291if isequal(TransformName,'more...');
2292%     coord_fct='';
2293%     prompt = {'Enter the name of the transform function'};
2294%     dlg_title = 'user defined transform';
2295%     num_lines= 1;
2296    [FileName, PathName] = uigetfile( ...
2297       {'*.m', ' (*.m)';
2298        '*.m',  '.m files '; ...
2299        '*.*', 'All Files (*.*)'}, ...
2300        'Pick a transform function',get(handles.TransformPath,'String'));
2301    if isequal(FileName,0)
2302        return     %browser closed without choice
2303    end
2304    if isequal(PathName(end),'/')||isequal(PathName(end),'\')
2305        PathName(end)=[];
2306    end
2307    [TransformPath,TransformName,TransformExt]=fileparts(FileName);% removes extension .m
2308    if ~strcmp(TransformExt,'.m')
2309        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
2310        return
2311    end
2312     % insert the choice in the menu
2313    TransformIndex=find(strcmp(TransformName,TransformList),1);% look for the selected function in the menu Action
2314    if isempty(TransformIndex)%the input string does not exist in the menu
2315        TransformIndex= length(TransformList);
2316        TransformList=[TransformList(1:end-1);{TransformnName};TransformList(end)];% the selected function is appended in the menu, before the last item 'more...'
2317        set(handles.TransformName,'String',TransformList)
2318        TransformPathList=[TransformPathList;{TransformPath}];
2319    end
2320   % save the new menu in the personal file 'uvmat_perso.mat'
2321   dir_perso=prefdir;%personal Matalb directory
2322   profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
2323   if exist(profil_perso,'file')
2324       for ilist=nb_builtin_transform+1:numel(TransformPathList)
2325           TransformListUser{ilist-nb_builtin_transform}=TransformList{ilist};
2326           TransformPathListUser{ilist-nb_builtin_transform}=TransformPathList{ilist};
2327       end
2328       save (profil_perso,'TransformPathListUser','TransformListUser','-append'); %store the root name for future opening of uvmat
2329   end
2330end
2331
2332%display the current function path
2333set(handles.TransformPath,'String',TransformPathList{TransformIndex}); %show the path to the senlected function
2334set(handles.TransformName,'UserData',TransformPathList);
2335
2336
2337% --------------------------------------------------------------------
2338function MenuExportConfig_Callback(hObject, eventdata, handles)
2339global Series
2340[Series,errormsg]=prepare_jobs(handles);
2341
2342evalin('base','global Series')%make CurData global in the workspace
2343display('current series config :')
2344evalin('base','Series') %display CurData in the workspace
2345commandwindow; %brings the Matlab command window to the front
2346
2347
2348% --- Executes on selection change in RunMode.
2349function RunMode_Callback(hObject, eventdata, handles)
2350
2351% --- Executes on selection change in Coord_x.
2352function Coord_x_Callback(hObject, eventdata, handles)
2353
2354
2355% --- Executes on selection change in Coord_y.
2356function Coord_y_Callback(hObject, eventdata, handles)
2357
2358
2359
2360% --- Executes when series is resized.
2361function series_ResizeFcn(hObject, eventdata, handles)
2362%% input table
2363set(handles.InputTable,'Unit','pixel')
2364Pos=get(handles.InputTable,'Position');
2365set(handles.InputTable,'Unit','normalized')
2366ColumnWidth=round([0.5 0.14 0.14 0.14 0.08]*(Pos(3)-52));
2367ColumnWidth=num2cell(ColumnWidth);
2368set(handles.InputTable,'ColumnWidth',ColumnWidth)
2369
2370%% MinIndex and MaxIndex
2371set(handles.MinIndex,'Unit','pixel')
2372Pos=get(handles.MinIndex,'Position');
2373set(handles.MinIndex,'Unit','normalized')
2374ColumnWidth=get(handles.MinIndex,'ColumnWidth');
2375if numel(ColumnWidth)==2
2376    ColumnWidth=num2cell(floor([0.5 0.5]*(Pos(3)-20)));
2377else
2378    ColumnWidth={Pos(3)-5};
2379end   
2380set(handles.MinIndex,'ColumnWidth',ColumnWidth)
2381set(handles.MaxIndex,'ColumnWidth',ColumnWidth)
2382
2383%% TimeTable
2384set(handles.TimeTable,'Unit','pixel')
2385Pos=get(handles.TimeTable,'Position');
2386set(handles.TimeTable,'Unit','normalized')
2387ColumnWidth=get(handles.TimeTable,'ColumnWidth');
2388ColumnWidth=num2cell(floor([0.25 0.25 0.25 0.25]*(Pos(3)-20)));
2389set(handles.TimeTable,'ColumnWidth',ColumnWidth)
2390
2391
2392%% PairString
2393set(handles.PairString,'Unit','pixel')
2394Pos=get(handles.PairString,'Position');
2395set(handles.PairString,'Unit','normalized')
2396set(handles.PairString,'ColumnWidth',{Pos(3)-5})
2397
2398
2399% --- Executes on button press in status.
2400function status_Callback(hObject, eventdata, handles)
2401
2402if get(handles.status,'Value')
2403    set(handles.status,'BackgroundColor',[1 1 0])
2404    drawnow
2405    StatusData.time_ref=get(handles.RUN,'UserData');% get the time of launch
2406    Param=read_GUI(handles.series);
2407    RootPath=Param.InputTable{1,1};
2408    if ~isfield(Param,'OutputSubDir')   
2409        msgbox_uvmat('ERROR','no directory defined for output files')
2410        return
2411    end
2412    OutputSubDir=[Param.OutputSubDir Param.OutputDirExt];% subdirectory for output files
2413    OutputDir=fullfile(RootPath,OutputSubDir);
2414    hfig=findobj(allchild(0),'name','series_status');
2415    if isempty(hfig)
2416        hfig=figure('DeleteFcn',@stop_status);
2417        set(hfig,'MenuBar','none')% suppress the menu bar
2418        set(hfig,'NumberTitle','off')%suppress the fig number in the title
2419        set(hfig,'name','series_status')
2420        set(hfig,'tag','series_status')
2421        uicontrol('Style','listbox','Units','normalized', 'Position',[0.05 0.09 0.9 0.71], 'Callback', @view_file,'tag','list','UserData',OutputDir);
2422        uicontrol('Style','edit','Units','normalized', 'Position', [0.05 0.87 0.9 0.1],'tag','titlebox','Max',2,'String',OutputDir);
2423        uicontrol('Style','frame','Units','normalized', 'Position', [0.05 0.81 0.9 0.05]);
2424        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);
2425        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);
2426        set(hrefresh,'UserData',StatusData)
2427        BarPosition=[0.05 0.81 0.01 0.05];
2428        uicontrol('Style','frame','Units','normalized', 'Position',BarPosition ,'BackgroundColor',[1 0 0],'tag','waitbar');
2429        drawnow
2430    end
2431    refresh_GUI(hrefresh,[])
2432else
2433    %% delete current display fig if selection is off
2434    set(handles.status,'BackgroundColor',[0 1 0])
2435    hfig=findobj(allchild(0),'name','series_status');
2436    if ~isempty(hfig)
2437        delete(hfig)
2438    end
2439    return
2440end
2441
2442
2443%------------------------------------------------------------------------   
2444% launched by selecting a file on the list
2445function view_file(hObject, eventdata)
2446list=get(hObject,'String');
2447index=get(hObject,'Value');
2448rootroot=get(hObject,'UserData');
2449selectname=list{index};
2450ind_dot=regexp(selectname,'\.\.\.');
2451if ~isempty(ind_dot)
2452    selectname=selectname(1:ind_dot-1);
2453end
2454FullSelectName=fullfile(rootroot,selectname);
2455if exist(FullSelectName,'dir')% a directory has been selected
2456    ListFiles=dir(FullSelectName);
2457    ListDisplay=cell(numel(ListFiles),1);
2458    for ilist=2:numel(ListDisplay)% suppress the first line '.'
2459        ListDisplay{ilist-1}=ListFiles(ilist).name;
2460    end
2461    set(hObject,'Value',1)
2462    set(hObject,'String',ListDisplay)
2463    if strcmp(selectname,'..')
2464        FullSelectName=fileparts(fileparts(FullSelectName));
2465    end
2466    set(hObject,'UserData',FullSelectName)
2467    hfig=get(hObject,'parent');
2468    htitlebox=findobj(hfig,'tag','titlebox');   
2469    set(htitlebox,'String',FullSelectName)
2470elseif exist(FullSelectName,'file')%visualise the vel field if it exists
2471    FileType=get_file_type(FullSelectName);
2472    if strcmp(FileType,'txt')
2473        edit(FullSelectName)
2474    elseif strcmp(FileType,'xml')
2475        editxml(FullSelectName)
2476    else
2477        uvmat(FullSelectName)
2478    end
2479    set(gcbo,'Value',1)
2480end
2481
2482
2483%------------------------------------------------------------------------
2484
2485%------------------------------------------------------------------------   
2486% launched by refreshing the status figure
2487function refresh_GUI(hObject, eventdata)
2488%------------------------------------------------------------------------
2489hfig=get(hObject,'parent');
2490htitlebox=findobj(hfig,'tag','titlebox');
2491hlist=findobj(hfig,'tag','list');
2492OutputDir=get(htitlebox,'String');
2493ListFiles=dir(OutputDir);
2494ListDisplay=cell(numel(ListFiles),1);
2495for ilist=2:numel(ListDisplay)
2496    ListDisplay{ilist-1}=ListFiles(ilist).name;
2497end
2498set(hlist,'String',ListDisplay)
2499% civ_files=get(hfig,'UserData');
2500
2501% [filepath,filename,ext]=fileparts(civ_files{1});
2502% [tild,SubDir,extdir]=fileparts(filepath);
2503% SubDir=[SubDir extdir];
2504% option_civ=StatusData.option_civ;
2505% nbfiles=numel(civ_files);
2506% testrecent=0;
2507% count=0;
2508% datnum=zeros(1,nbfiles);
2509% filefound=cell(1,nbfiles);
2510% for ifile=1:nbfiles
2511%     detect=exist(civ_files{ifile},'file'); % check the existence of the file
2512%     option=0;
2513%     if detect==0
2514%         option_str='not created';
2515%     else
2516%         datfile=dir(civ_files{ifile});
2517%         if isfield(datfile,'datenum')
2518%             datnum(ifile)=datfile.datenum;%only available in recent matlab versions
2519%             testrecent=1;
2520%         end
2521%         filefound(ifile)={datfile.name};
2522%         
2523%         % check the content  netcdf file
2524%         Data=nc2struct(civ_files{ifile},'ListGlobalAttribute','CivStage','patch2','fix2','civ2','patch','fix');
2525%         option_list={'civ1','fix1','patch1','civ2','fix2','patch2'};
2526%         if ~isempty(Data.CivStage)
2527%             option=Data.CivStage;%case of Matlab civ
2528%         else
2529%             if ~isempty(Data.patch2) && isequal(Data.patch2,1)
2530%                 option=6;
2531%             elseif ~isempty(Data.fix2) && isequal(Data.fix2,1)
2532%                 option=5;
2533%             elseif ~isempty(Data.civ2) && isequal(Data.civ2,1);
2534%                 option=4;
2535%             elseif ~isempty(Data.patch) && isequal(Data.patch,1);
2536%                 option=3;
2537%             elseif ~isempty(Data.fix) && isequal(Data.fix,1);
2538%                 option=2;
2539%             else
2540%                 option=1;
2541%             end
2542%         end
2543%         option_str=option_list{option};
2544%         if datnum(ifile)<StatusData.time_ref
2545%             option_str=[option_str '  --OLD--'];
2546%         end
2547%     end
2548%     if option >= option_civ
2549%         count=count+1;
2550%     end
2551%     [filepath,filename,ext]=fileparts(civ_files{ifile});
2552%     Tabchar{ifile,1}=[fullfile(SubDir,filename) ext  '...' option_str];
2553% end
2554% datnum=datnum(datnum~=0);%keep the non zero values corresponding to existing files
2555% if isempty(datnum)
2556%     if testrecent
2557%         message='no civ result created yet';
2558%     else
2559%         message='';
2560%     end
2561% else
2562%     datnum=datnum(datnum~=0);%keep the non zero values corresponding to existing files
2563%     [first,ind]=min(datnum);
2564%     [last,indlast]=max(datnum);
2565%     message={[num2str(count) ' file(s) done over ' num2str(nbfiles)] ;['oldest modification:  ' cell2mat(filefound(ind)) ' : ' datestr(first)];...
2566%         ['latest modification:  ' cell2mat(filefound(indlast)) ' : ' datestr(last)]};
2567% end
2568% hlist=findobj(hfig,'tag','list');
2569% htitlebox=findobj(hfig,'tag','titlebox');
2570% hwaitbar=findobj(hfig,'tag','waitbar');
2571% set(hlist,'String',Tabchar)
2572% set(htitlebox,'String', message)
2573% if count>0 %&& ~test_new
2574%     BarPosition(3)=0.9*count/nbfiles;
2575%     set(hwaitbar,'Position',BarPosition)
2576% end
2577%------------------------------------------------------------------------   
2578% launched by deleting the status figure
2579function stop_status(hObject, eventdata)
2580%------------------------------------------------------------------------
2581hciv=findobj(allchild(0),'tag','series');
2582hhciv=guidata(hciv);
2583set(hhciv.status,'value',0) %reset the status uicontrol in the GUI civ
2584set(hhciv.status,'BackgroundColor',[0 1 0])
2585delete(gcbf)
2586
2587% --- Executes on selection change in ActionExt.
2588function ActionExt_Callback(hObject, eventdata, handles)
2589ActionExtList=get(handles.ActionExt,'String');
2590ActionExt=ActionExtList{get(handles.ActionExt,'Value')};
2591ActionList=get(handles.ActionName,'String');
2592ActionName=ActionList{get(handles.ActionName,'Value')};
2593if strcmp(ActionExt,'.sh')
2594    ActionFullName=fullfile(get(handles.ActionPath,'String'),[ActionName '.sh']);
2595    if ~exist(ActionFullName,'file')
2596        answer=msgbox_uvmat('INPUT_Y-N','compiled version has not been created: compile now?');
2597        if strcmp(answer,'Yes')
2598            currentdir=pwd;
2599            cd(get(handles.ActionPath,'String'))
2600            compile(ActionName)
2601            cd(currentdir)
2602        end
2603    end
2604    currentdir=pwd;
2605    cd(get(handles.ActionPath,'String'))
2606    sh_file=dir([ActionName '.sh']);
2607    m_file=dir([ActionName '.m']);
2608    if isfield(m_file,'datenum') && m_file.datenum>sh_file.datenum
2609        set(handles.ActionExt,'BackgroundColor',[1 1 0])
2610        drawnow
2611        answer=msgbox_uvmat('INPUT_Y-N',[ActionName '.sh needs to be updated: recompile now?']);
2612        if strcmp(answer,'Yes')
2613            compile(ActionName)
2614        end
2615        set(handles.ActionExt,'BackgroundColor',[1 1 1])
2616    end
2617    cd(currentdir)
2618end
2619
2620
2621function ActionInput_Callback(hObject, eventdata, handles)
2622
2623
2624% --- Executes on button press in DeleteObject.
2625function DeleteObject_Callback(hObject, eventdata, handles)
2626if get(handles.DeleteObject,'Value')
2627        SeriesData=get(handles.series,'UserData');
2628    SeriesData.ProjObject=[];
2629    set(handles.series,'UserData',SeriesData)
2630    set(handles.ProjObject,'String','')
2631    set(handles.CheckObject,'Value',0)
2632    set(handles.DeleteObject,'Visible','off')
2633    set(handles.ViewObject,'Visible','off')
2634end
2635
2636% --- Executes on button press in ViewObject.
2637function ViewObject_Callback(hObject, eventdata, handles)
2638if get(handles.ViewObject,'Value')
2639        UserData=get(handles.series,'UserData');
2640    set_object(UserData.ProjObject)
2641else
2642    hset_object=findobj(allchild(0),'Tag','set_object');
2643    if ~isempty(hset_object)
2644        delete(hset_object)
2645    end
2646end
2647
2648
2649function num_NbProcess_Callback(hObject, eventdata, handles)
2650
2651
2652function num_NbSlice_Callback(hObject, eventdata, handles)
2653NbSlice=str2num(get(handles.num_NbSlice,'String'));
2654set(handles.num_NbProcess,'String',num2str(NbSlice))
2655
2656
Note: See TracBrowser for help on using the repository browser.