source: trunk/src/series.m @ 603

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

bugs corrected, improvement of civ_input GUI

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